code wiki / _hdl_build / nx_game_raster.nx

nx_game_raster.nx source

↩ module page · 54 lines · 2354 B

1// nx_game_raster.nx -- LIB: shared INTEGER (no-float) raster primitives for the genre playables. Every 2// flagged open-source genre we build renders its state into the games' packed-RGB framebuffer (R|G<<8|B<<16) 3// through these -- the SAME framebuffer SF5 proved flows through both sovereign display paths (the silicon 4// on-fabric display controller + the x86 UEFI GOP sink). So a genre that renders here IS displayable on 5// sovereign hardware. Pure i64, no float, no canvas. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7 8func gr_pack(r: i64, g: i64, b: i64) -> i64 { return (r & 0xff) | ((g & 0xff) << 8) | ((b & 0xff) << 16) } 9 10func gr_clear(fb: *i64, w: i64, h: i64, c: i64) -> i64 { 11 let n: i64 = w*h; var i: i64 = 0 12 while i < n { fb[i] = c; i = i + 1 } 13 return 0 14} 15 16func gr_px(fb: *i64, w: i64, h: i64, x: i64, y: i64, c: i64) -> i64 { 17 if x < 0 { return 0 } if y < 0 { return 0 } if x >= w { return 0 } if y >= h { return 0 } 18 fb[y*w + x] = c 19 return 0 20} 21 22func gr_rect(fb: *i64, w: i64, h: i64, x0: i64, y0: i64, x1: i64, y1: i64, c: i64) -> i64 { 23 var xs: i64=x0; if xs<0 {xs=0} 24 var ys: i64=y0; if ys<0 {ys=0} 25 var xe: i64=x1; if xe>w {xe=w} 26 var ye: i64=y1; if ye>h {ye=h} 27 var yy: i64=ys 28 while yy<ye { var xx: i64=xs; while xx<xe { fb[yy*w+xx]=c; xx=xx+1 } yy=yy+1 } 29 return 0 30} 31 32// integer filled disc (no float: dx*dx + dy*dy <= rad*rad) -- balls, towers, planets. 33func gr_disc(fb: *i64, w: i64, h: i64, cx: i64, cy: i64, rad: i64, c: i64) -> i64 { 34 var dy: i64 = 0 - rad 35 let r2: i64 = rad*rad 36 while dy <= rad { 37 var dx: i64 = 0 - rad 38 while dx <= rad { 39 if dx*dx + dy*dy <= r2 { gr_px(fb, w, h, cx+dx, cy+dy, c) } 40 dx = dx + 1 41 } 42 dy = dy + 1 43 } 44 return 0 45} 46 47// horizontal + vertical lines (tracks, paths, HUD rules). 48func gr_hline(fb: *i64, w: i64, h: i64, x0: i64, x1: i64, y: i64, c: i64) -> i64 { gr_rect(fb, w, h, x0, y, x1, y+1, c); return 0 } 49func gr_vline(fb: *i64, w: i64, h: i64, x: i64, y0: i64, y1: i64, c: i64) -> i64 { gr_rect(fb, w, h, x, y0, x+1, y1, c); return 0 } 50 51// read back a pixel's green/red channel (gate assertions: "the player cell is green", etc.) 52func gr_r(c: i64) -> i64 { return c & 0xff } 53func gr_g(c: i64) -> i64 { return (c >> 8) & 0xff } 54func gr_b(c: i64) -> i64 { return (c >> 16) & 0xff }