Phase 7a: bitwise operators & | ^ << >> ~ (retire band/bor/shl/…)
First step of the "stop feeling like C" pass. Bitwise ops were functions (`band(x, MASK)`, `shl(a, 3)`); they are now real operators: band -> & bor -> | bxor -> ^ shl -> << shr -> >> bnot -> ~ Precedence is Go-style so the C footgun is gone: `<<`/`>>`/`&` bind like `*`, `|`/`^` like `+`, both tighter than comparison — `flags & MASK == 0` parses as `(flags & MASK) == 0`. `>>` is logical (lshr), matching the old `shr`. Mechanics: lexer tokenizes `<< >> & | ^ ~`; p_mul takes `<< >> &`, p_add takes `| ^`, p_unary takes `~`; emit_bin routes them through the existing int arith path (arith_code gains and/or/xor/shl/lshr) and E_UN handles `~`. The six intrinsics are deleted. Delivered as two reseeds: (A) add the operators keeping the intrinsics, (B) migrate every call site to operator form (85 lines across compiler + runtime, via a balanced-paren call->operator script; two multi-line big-endian reads in image/truetype done by hand) and delete the intrinsics. Vocabulary drops the six from LUDIC_INTRINSICS (ludic_syntax.h, grammar, LudicTokens.kt) and the grammar gains a bitwise-operator rule. LANGUAGE.md precedence table rewritten. Reseeded (21724 lines); C-free fixpoint holds; goldens byte-identical (the PNG and TrueType decoders lean on these ops); 17/17; vocab + doc-fences clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
0e0c58519d
commit
fcada23eba
18 changed files with 3417 additions and 3403 deletions
|
|
@ -197,11 +197,11 @@ fn rt_seed(s: int) -> void {
|
|||
# masked off only when a caller asks for a number.
|
||||
fn rt_next_rand() -> int {
|
||||
var x = rt_rng
|
||||
x = bxor(x, shl(x, 13))
|
||||
x = bxor(x, shr(x, 17))
|
||||
x = bxor(x, shl(x, 5))
|
||||
x = (x ^ (x << 13))
|
||||
x = (x ^ (x >> 17))
|
||||
x = (x ^ (x << 5))
|
||||
rt_rng = x
|
||||
return band(x, 2147483647)
|
||||
return (x & 2147483647)
|
||||
}
|
||||
|
||||
fn rt_rng_range(lo: int, hi: int) -> int {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ fn rt_image_init() -> void {
|
|||
|
||||
# ---- decoding -------------------------------------------------------------
|
||||
fn png_be32(b: ptr, at: int) -> int {
|
||||
return bor(bor(shl(peek8(b, at), 24), shl(peek8(b, at + 1), 16)),
|
||||
bor(shl(peek8(b, at + 2), 8), peek8(b, at + 3)))
|
||||
return (peek8(b, at) << 24) | (peek8(b, at + 1) << 16) | (peek8(b, at + 2) << 8) | peek8(b, at + 3)
|
||||
}
|
||||
|
||||
fn png_tag(b: ptr, at: int, a: int, c: int, d: int, e: int) -> bool {
|
||||
|
|
@ -164,13 +163,13 @@ fn rt_decode_png(path: str) -> bool {
|
|||
if pa <= pb { if pa <= pc { pick = a } }
|
||||
v = v + pick
|
||||
}
|
||||
poke8(raw, cur + x, band(v, 255))
|
||||
poke8(raw, cur + x, (v & 255))
|
||||
}
|
||||
}
|
||||
|
||||
# expand to 0xAARRGGBB
|
||||
let out = mem_alloc(w * h * 4)
|
||||
let maxv = shl(1, bd) - 1
|
||||
let maxv = (1 << bd) - 1
|
||||
for y in 0 .. h {
|
||||
let row = y * (stride + 1) + 1
|
||||
for x in 0 .. w {
|
||||
|
|
@ -197,7 +196,7 @@ fn rt_decode_png(path: str) -> bool {
|
|||
}
|
||||
if ct == 3 {
|
||||
let bp = x * bd
|
||||
let idx = band(shr(peek8(raw, row + bp / 8), 8 - bd - bp % 8), maxv)
|
||||
let idx = ((peek8(raw, row + bp / 8) >> (8 - bd - bp % 8)) & maxv)
|
||||
R = peek8(plte, idx * 3)
|
||||
G = peek8(plte, idx * 3 + 1)
|
||||
B = peek8(plte, idx * 3 + 2)
|
||||
|
|
@ -205,14 +204,14 @@ fn rt_decode_png(path: str) -> bool {
|
|||
}
|
||||
if ct == 0 {
|
||||
let bp = x * bd
|
||||
let s = band(shr(peek8(raw, row + bp / 8), 8 - bd - bp % 8), maxv)
|
||||
let s = ((peek8(raw, row + bp / 8) >> (8 - bd - bp % 8)) & maxv)
|
||||
var g = s
|
||||
if bd != 8 { g = s * 255 / maxv }
|
||||
R = g
|
||||
G = g
|
||||
B = g
|
||||
}
|
||||
poke32(out, y * w + x, bor(bor(shl(A, 24), shl(R, 16)), bor(shl(G, 8), B)))
|
||||
poke32(out, y * w + x, (((A << 24) | (R << 16)) | ((G << 8) | B)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -240,25 +239,25 @@ fn rt_image_load(path: str) -> int {
|
|||
}
|
||||
|
||||
fn rt_blend_px(x: int, y: int, argb: int) -> void {
|
||||
let a = band(shr(argb, 24), 255)
|
||||
let a = ((argb >> 24) & 255)
|
||||
if a == 0 { return }
|
||||
if x < 0 { return }
|
||||
if y < 0 { return }
|
||||
if x >= rt_fbw { return }
|
||||
if y >= rt_fbh { return }
|
||||
var r = band(shr(argb, 16), 255)
|
||||
var g = band(shr(argb, 8), 255)
|
||||
var b = band(argb, 255)
|
||||
var r = ((argb >> 16) & 255)
|
||||
var g = ((argb >> 8) & 255)
|
||||
var b = (argb & 255)
|
||||
if a != 255 {
|
||||
let dst = peek32(rt_fb, y * rt_fbw + x)
|
||||
let dr = band(shr(dst, 16), 255)
|
||||
let dg = band(shr(dst, 8), 255)
|
||||
let db = band(dst, 255)
|
||||
let dr = ((dst >> 16) & 255)
|
||||
let dg = ((dst >> 8) & 255)
|
||||
let db = (dst & 255)
|
||||
r = (r * a + dr * (255 - a)) / 255
|
||||
g = (g * a + dg * (255 - a)) / 255
|
||||
b = (b * a + db * (255 - a)) / 255
|
||||
}
|
||||
poke32(rt_fb, y * rt_fbw + x, bor(bor(shl(r, 16), shl(g, 8)), b))
|
||||
poke32(rt_fb, y * rt_fbw + x, (((r << 16) | (g << 8)) | b))
|
||||
}
|
||||
|
||||
fn rt_draw_image(id: int, dx: int, dy: int) -> void {
|
||||
|
|
@ -328,7 +327,7 @@ fn rt_png_load(path: str) -> int {
|
|||
if x < png_w {
|
||||
if y < png_h {
|
||||
let c = peek32(png_px, y * png_w + x)
|
||||
if band(shr(c, 24), 255) >= 128 { px = bor(shl(255, 24), band(c, 16777215)) }
|
||||
if ((c >> 24) & 255) >= 128 { px = ((255 << 24) | (c & 16777215)) }
|
||||
}
|
||||
}
|
||||
poke32(spr_px, base + y * SPR_SZ + x, px)
|
||||
|
|
@ -346,8 +345,8 @@ fn rt_draw_sprite(id: int, px: int, py: int) -> void {
|
|||
for y in 0 .. SPR_SZ {
|
||||
for x in 0 .. SPR_SZ {
|
||||
let p = peek32(spr_px, base + y * SPR_SZ + x)
|
||||
if band(shr(p, 24), 255) != 0 {
|
||||
rt_put_px(px + x, py + y, band(p, 16777215))
|
||||
if ((p >> 24) & 255) != 0 {
|
||||
rt_put_px(px + x, py + y, (p & 16777215))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -361,8 +360,8 @@ fn rt_draw_sprite_scaled(id: int, px: int, py: int, sc: int) -> void {
|
|||
for y in 0 .. SPR_SZ {
|
||||
for x in 0 .. SPR_SZ {
|
||||
let p = peek32(spr_px, base + y * SPR_SZ + x)
|
||||
if band(shr(p, 24), 255) != 0 {
|
||||
rt_fill_rect(px + x * sc, py + y * sc, sc, sc, band(p, 16777215))
|
||||
if ((p >> 24) & 255) != 0 {
|
||||
rt_fill_rect(px + x * sc, py + y * sc, sc, sc, (p & 16777215))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -401,7 +400,7 @@ fn rt_sprites_load(path: str) -> void {
|
|||
let hv = rt_hexval(peek8(d, start + 6 + k))
|
||||
if hv >= 0 { v = v * 16 + hv }
|
||||
}
|
||||
if ch < 128 { poke32(pal, ch, bor(shl(255, 24), v)) }
|
||||
if ch < 128 { poke32(pal, ch, ((255 << 24) | v)) }
|
||||
}
|
||||
if c0 == 115 { # 's' — "spr" starts a new sprite
|
||||
cur = 0 - 1
|
||||
|
|
@ -420,7 +419,7 @@ fn rt_sprites_load(path: str) -> void {
|
|||
for x in 0 .. SPR_SZ {
|
||||
if x < len {
|
||||
poke32(spr_px, cur * SPR_SZ * SPR_SZ + row * SPR_SZ + x,
|
||||
peek32(pal, band(peek8(d, start + x), 127)))
|
||||
peek32(pal, (peek8(d, start + x) & 127)))
|
||||
}
|
||||
}
|
||||
row = row + 1
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ fn z_bits(need: int) -> int {
|
|||
z_err = 1
|
||||
return 0
|
||||
}
|
||||
val = bor(val, shl(peek8(z_src, z_pos), z_bitcnt))
|
||||
val = (val | (peek8(z_src, z_pos) << z_bitcnt))
|
||||
z_pos = z_pos + 1
|
||||
z_bitcnt = z_bitcnt + 8
|
||||
}
|
||||
z_bitbuf = shr(val, need)
|
||||
z_bitbuf = (val >> need)
|
||||
z_bitcnt = z_bitcnt - need
|
||||
return band(val, shl(1, need) - 1)
|
||||
return (val & ((1 << need) - 1))
|
||||
}
|
||||
|
||||
# ---- Huffman tables -------------------------------------------------------
|
||||
|
|
@ -83,14 +83,14 @@ fn z_decode(table: ptr) -> int {
|
|||
var first = 0
|
||||
var index = 0
|
||||
for len in 1 .. 16 {
|
||||
code = bor(code, z_bits(1))
|
||||
code = (code | z_bits(1))
|
||||
let count = peek32(table, len)
|
||||
if code - first < count {
|
||||
return peek32(table, 16 + index + (code - first))
|
||||
}
|
||||
index = index + count
|
||||
first = shl(first + count, 1)
|
||||
code = shl(code, 1)
|
||||
first = ((first + count) << 1)
|
||||
code = (code << 1)
|
||||
}
|
||||
z_err = 1
|
||||
return -1
|
||||
|
|
@ -101,8 +101,8 @@ fn z_len_base(sym: int) -> int {
|
|||
if sym < 8 { return 3 + sym }
|
||||
if sym == 28 { return 258 }
|
||||
let extra = (sym - 4) / 4
|
||||
let group = shl(1, extra)
|
||||
return 3 + shl(group - 1, 2) + 4 + (sym - 4 - extra * 4) * group
|
||||
let group = (1 << extra)
|
||||
return 3 + ((group - 1) << 2) + 4 + (sym - 4 - extra * 4) * group
|
||||
}
|
||||
|
||||
fn z_len_extra(sym: int) -> int {
|
||||
|
|
@ -114,8 +114,8 @@ fn z_len_extra(sym: int) -> int {
|
|||
fn z_dist_base(sym: int) -> int {
|
||||
if sym < 4 { return 1 + sym }
|
||||
let extra = (sym - 2) / 2
|
||||
let group = shl(1, extra)
|
||||
return 1 + shl(group, 1) + (sym - 2 - extra * 2) * group
|
||||
let group = (1 << extra)
|
||||
return 1 + (group << 1) + (sym - 2 - extra * 2) * group
|
||||
}
|
||||
|
||||
fn z_dist_extra(sym: int) -> int {
|
||||
|
|
@ -129,7 +129,7 @@ fn z_stored(out: ptr, at: int, cap: int) -> int {
|
|||
z_bitbuf = 0
|
||||
z_bitcnt = 0 # stored blocks are byte-aligned
|
||||
if z_pos + 4 > z_len { return -1 }
|
||||
let n = peek8(z_src, z_pos) + shl(peek8(z_src, z_pos + 1), 8)
|
||||
let n = peek8(z_src, z_pos) + (peek8(z_src, z_pos + 1) << 8)
|
||||
z_pos = z_pos + 4 # LEN then its one's complement
|
||||
var w = at
|
||||
for i in 0 .. n {
|
||||
|
|
@ -271,6 +271,6 @@ fn z_inflate(src: ptr, len: int, out: ptr, cap: int) -> int {
|
|||
fn z_uncompress(src: ptr, len: int, out: ptr, cap: int) -> int {
|
||||
if len < 2 { return -1 }
|
||||
let cmf = peek8(src, 0)
|
||||
if band(cmf, 15) != 8 { return -1 }
|
||||
if (cmf & 15) != 8 { return -1 }
|
||||
return z_inflate(ptr_add(src, 2), len - 2, out, cap)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ fn rt_tt_init() -> void {
|
|||
|
||||
# ---- big-endian readers ---------------------------------------------------
|
||||
fn tt_u16(d: ptr, at: int) -> int {
|
||||
return bor(shl(peek8(d, at), 8), peek8(d, at + 1))
|
||||
return ((peek8(d, at) << 8) | peek8(d, at + 1))
|
||||
}
|
||||
fn tt_i16(d: ptr, at: int) -> int {
|
||||
let v = tt_u16(d, at)
|
||||
|
|
@ -114,8 +114,7 @@ fn tt_i16(d: ptr, at: int) -> int {
|
|||
return v
|
||||
}
|
||||
fn tt_u32(d: ptr, at: int) -> int {
|
||||
return bor(bor(shl(peek8(d, at), 24), shl(peek8(d, at + 1), 16)),
|
||||
bor(shl(peek8(d, at + 2), 8), peek8(d, at + 3)))
|
||||
return (peek8(d, at) << 24) | (peek8(d, at + 1) << 16) | (peek8(d, at + 2) << 8) | peek8(d, at + 3)
|
||||
}
|
||||
fn tt_i8(d: ptr, at: int) -> int {
|
||||
let v = peek8(d, at)
|
||||
|
|
@ -232,10 +231,10 @@ fn tt_glyph_index(id: int, cp: int) -> int {
|
|||
let st = tt_u16(d, startp + i * 2)
|
||||
if cp < st { return 0 }
|
||||
let ro = tt_u16(d, rangep + i * 2)
|
||||
if ro == 0 { return band(cp + tt_i16(d, deltap + i * 2), 65535) }
|
||||
if ro == 0 { return ((cp + tt_i16(d, deltap + i * 2)) & 65535) }
|
||||
let g = tt_u16(d, rangep + i * 2 + ro + (cp - st) * 2)
|
||||
if g == 0 { return 0 }
|
||||
return band(g + tt_i16(d, deltap + i * 2), 65535)
|
||||
return ((g + tt_i16(d, deltap + i * 2)) & 65535)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
|
|
@ -318,7 +317,7 @@ fn tt_load_outline(id: int, gid: int, a: fixed, b: fixed, c: fixed, e: fixed, dx
|
|||
p = p + 1
|
||||
poke8(flags, i, fl)
|
||||
i = i + 1
|
||||
if band(fl, 8) != 0 { # REPEAT
|
||||
if (fl & 8) != 0 { # REPEAT
|
||||
var r = peek8(d, p)
|
||||
p = p + 1
|
||||
while r > 0 {
|
||||
|
|
@ -333,24 +332,24 @@ fn tt_load_outline(id: int, gid: int, a: fixed, b: fixed, c: fixed, e: fixed, dx
|
|||
var xv = 0
|
||||
for k in 0 .. npts {
|
||||
let fl = peek8(flags, k)
|
||||
if band(fl, 2) != 0 {
|
||||
if (fl & 2) != 0 {
|
||||
let dxv = peek8(d, p)
|
||||
p = p + 1
|
||||
if band(fl, 16) != 0 { xv = xv + dxv } else { xv = xv - dxv }
|
||||
if (fl & 16) != 0 { xv = xv + dxv } else { xv = xv - dxv }
|
||||
} else {
|
||||
if band(fl, 16) == 0 { xv = xv + tt_i16(d, p); p = p + 2 }
|
||||
if (fl & 16) == 0 { xv = xv + tt_i16(d, p); p = p + 2 }
|
||||
}
|
||||
poke32(xs, k, xv)
|
||||
}
|
||||
var yv = 0
|
||||
for k in 0 .. npts {
|
||||
let fl = peek8(flags, k)
|
||||
if band(fl, 4) != 0 {
|
||||
if (fl & 4) != 0 {
|
||||
let dyv = peek8(d, p)
|
||||
p = p + 1
|
||||
if band(fl, 32) != 0 { yv = yv + dyv } else { yv = yv - dyv }
|
||||
if (fl & 32) != 0 { yv = yv + dyv } else { yv = yv - dyv }
|
||||
} else {
|
||||
if band(fl, 32) == 0 { yv = yv + tt_i16(d, p); p = p + 2 }
|
||||
if (fl & 32) == 0 { yv = yv + tt_i16(d, p); p = p + 2 }
|
||||
}
|
||||
poke32(ys, k, yv)
|
||||
}
|
||||
|
|
@ -361,7 +360,7 @@ fn tt_load_outline(id: int, gid: int, a: fixed, b: fixed, c: fixed, e: fixed, dx
|
|||
for k in start .. last + 1 {
|
||||
let X = fx(peek32(xs, k))
|
||||
let Y = fx(peek32(ys, k))
|
||||
ol_pt(a * X + c * Y + dx, b * X + e * Y + dy, band(peek8(flags, k), 1))
|
||||
ol_pt(a * X + c * Y + dx, b * X + e * Y + dy, (peek8(flags, k) & 1))
|
||||
}
|
||||
if ol_ne < 256 {
|
||||
poke32(ol_ends, ol_ne, ol_n)
|
||||
|
|
@ -382,7 +381,7 @@ fn tt_load_outline(id: int, gid: int, a: fixed, b: fixed, c: fixed, e: fixed, dx
|
|||
p = p + 4
|
||||
var arg1 = 0
|
||||
var arg2 = 0
|
||||
if band(flags, 1) != 0 {
|
||||
if (flags & 1) != 0 {
|
||||
arg1 = tt_i16(d, p)
|
||||
arg2 = tt_i16(d, p + 2)
|
||||
p = p + 4
|
||||
|
|
@ -395,32 +394,32 @@ fn tt_load_outline(id: int, gid: int, a: fixed, b: fixed, c: fixed, e: fixed, dx
|
|||
var cb = 0.0
|
||||
var cc = 0.0
|
||||
var ce = 1.0
|
||||
if band(flags, 8) != 0 {
|
||||
ca = as_fixed(shl(tt_i16(d, p), 2)) # F2Dot14 -> Q16.16
|
||||
if (flags & 8) != 0 {
|
||||
ca = as_fixed((tt_i16(d, p) << 2)) # F2Dot14 -> Q16.16
|
||||
ce = ca
|
||||
p = p + 2
|
||||
}
|
||||
if band(flags, 64) != 0 {
|
||||
ca = as_fixed(shl(tt_i16(d, p), 2))
|
||||
ce = as_fixed(shl(tt_i16(d, p + 2), 2))
|
||||
if (flags & 64) != 0 {
|
||||
ca = as_fixed((tt_i16(d, p) << 2))
|
||||
ce = as_fixed((tt_i16(d, p + 2) << 2))
|
||||
p = p + 4
|
||||
}
|
||||
if band(flags, 128) != 0 {
|
||||
ca = as_fixed(shl(tt_i16(d, p), 2))
|
||||
cb = as_fixed(shl(tt_i16(d, p + 2), 2))
|
||||
cc = as_fixed(shl(tt_i16(d, p + 4), 2))
|
||||
ce = as_fixed(shl(tt_i16(d, p + 6), 2))
|
||||
if (flags & 128) != 0 {
|
||||
ca = as_fixed((tt_i16(d, p) << 2))
|
||||
cb = as_fixed((tt_i16(d, p + 2) << 2))
|
||||
cc = as_fixed((tt_i16(d, p + 4) << 2))
|
||||
ce = as_fixed((tt_i16(d, p + 6) << 2))
|
||||
p = p + 8
|
||||
}
|
||||
var odx = dx
|
||||
var ody = dy
|
||||
if band(flags, 2) != 0 {
|
||||
if (flags & 2) != 0 {
|
||||
odx = a * fx(arg1) + c * fx(arg2) + dx
|
||||
ody = b * fx(arg1) + e * fx(arg2) + dy
|
||||
}
|
||||
tt_load_outline(id, cgid, a * ca + c * cb, b * ca + e * cb, a * cc + c * ce, b * cc + e * ce, odx, ody, depth + 1)
|
||||
more = 0
|
||||
if band(flags, 32) != 0 { more = 1 }
|
||||
if (flags & 32) != 0 { more = 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,13 +232,13 @@ fn tt_raster(id: int, gid: int, px: int) -> ptr {
|
|||
# Rasterizing is far too slow to repeat per frame, so a coverage mask is kept
|
||||
# per (font, codepoint, size). Open addressing, 8 probes, evict on miss.
|
||||
fn gc_hash(font: int, cp: int, px: int) -> int {
|
||||
return band(bxor(bxor(cp * 2654435761, shl(font, 20)), shl(px, 8)), TT_GC - 1)
|
||||
return ((((cp * 2654435761) ^ (font << 20)) ^ (px << 8)) & (TT_GC - 1))
|
||||
}
|
||||
|
||||
fn tt_glyph_get(font: int, cp: int, px: int) -> int {
|
||||
let h = gc_hash(font, cp, px)
|
||||
for k in 0 .. 8 {
|
||||
let s = band(h + k, TT_GC - 1)
|
||||
let s = ((h + k) & (TT_GC - 1))
|
||||
if peek32(gc_used, s) == 1 {
|
||||
if peek32(gc_font, s) == font {
|
||||
if peek32(gc_cp, s) == cp {
|
||||
|
|
@ -273,9 +273,9 @@ fn tt_utf8(s: str, at: int) -> int {
|
|||
let c = peek8(s, at)
|
||||
var extra = 0 - 1
|
||||
if c < 128 { extra = 0 }
|
||||
if shr(c, 5) == 6 { extra = 1 }
|
||||
if shr(c, 4) == 14 { extra = 2 }
|
||||
if shr(c, 3) == 30 { extra = 3 }
|
||||
if (c >> 5) == 6 { extra = 1 }
|
||||
if (c >> 4) == 14 { extra = 2 }
|
||||
if (c >> 3) == 30 { extra = 3 }
|
||||
if extra < 0 {
|
||||
u8_next = at + 1
|
||||
return 65533
|
||||
|
|
@ -284,14 +284,14 @@ fn tt_utf8(s: str, at: int) -> int {
|
|||
u8_next = at + 1
|
||||
return c
|
||||
}
|
||||
var cp = band(c, shr(63, extra))
|
||||
var cp = (c & (63 >> extra))
|
||||
for i in 0 .. extra {
|
||||
let b = peek8(s, at + 1 + i)
|
||||
if band(b, 192) != 128 {
|
||||
if (b & 192) != 128 {
|
||||
u8_next = at + 1 + i
|
||||
return 65533
|
||||
}
|
||||
cp = bor(shl(cp, 6), band(b, 63))
|
||||
cp = ((cp << 6) | (b & 63))
|
||||
}
|
||||
u8_next = at + 1 + extra
|
||||
return cp
|
||||
|
|
@ -300,9 +300,9 @@ fn tt_utf8(s: str, at: int) -> int {
|
|||
# ---- drawing --------------------------------------------------------------
|
||||
fn tt_blit(bmp: ptr, w: int, h: int, dx: int, dy: int, colour: int) -> void {
|
||||
if ptr_is_null(bmp) { return }
|
||||
let cr = band(shr(colour, 16), 255)
|
||||
let cg = band(shr(colour, 8), 255)
|
||||
let cb = band(colour, 255)
|
||||
let cr = ((colour >> 16) & 255)
|
||||
let cg = ((colour >> 8) & 255)
|
||||
let cb = (colour & 255)
|
||||
for y in 0 .. h {
|
||||
let py = dy + y
|
||||
if py >= 0 {
|
||||
|
|
@ -314,10 +314,10 @@ fn tt_blit(bmp: ptr, w: int, h: int, dx: int, dy: int, colour: int) -> void {
|
|||
if pxx >= 0 {
|
||||
if pxx < rt_fbw {
|
||||
let d = peek32(rt_fb, py * rt_fbw + pxx)
|
||||
let rr = (cr * a + band(shr(d, 16), 255) * (255 - a)) / 255
|
||||
let rg = (cg * a + band(shr(d, 8), 255) * (255 - a)) / 255
|
||||
let rb = (cb * a + band(d, 255) * (255 - a)) / 255
|
||||
poke32(rt_fb, py * rt_fbw + pxx, bor(bor(shl(rr, 16), shl(rg, 8)), rb))
|
||||
let rr = (cr * a + ((d >> 16) & 255) * (255 - a)) / 255
|
||||
let rg = (cg * a + ((d >> 8) & 255) * (255 - a)) / 255
|
||||
let rb = (cb * a + (d & 255) * (255 - a)) / 255
|
||||
poke32(rt_fb, py * rt_fbw + pxx, (((rr << 16) | (rg << 8)) | rb))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,13 +75,13 @@ fn ui_layout() -> void {
|
|||
|
||||
# ---- drawing --------------------------------------------------------------
|
||||
fn ui_lighten(c: int) -> int {
|
||||
var r = band(shr(c, 16), 255)
|
||||
var g = band(shr(c, 8), 255)
|
||||
var b = band(c, 255)
|
||||
var r = ((c >> 16) & 255)
|
||||
var g = ((c >> 8) & 255)
|
||||
var b = (c & 255)
|
||||
r = r + (255 - r) * 4 / 10
|
||||
g = g + (255 - g) * 4 / 10
|
||||
b = b + (255 - b) * 4 / 10
|
||||
return bor(bor(shl(r, 16), shl(g, 8)), b)
|
||||
return (((r << 16) | (g << 8)) | b)
|
||||
}
|
||||
|
||||
fn ui_draw_node(i: int) -> void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue