From e8df70a387559c1595c6e9fa3cde1e5bec0a7f6f Mon Sep 17 00:00:00 2001 From: JJ Bliss Date: Tue, 5 May 2026 18:25:38 -0400 Subject: [PATCH] Fixed sprites when base coordinate is off-screen --- uxn/screen.ha | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/uxn/screen.ha b/uxn/screen.ha index 2248b12..22e70a3 100644 --- a/uxn/screen.ha +++ b/uxn/screen.ha @@ -9,6 +9,7 @@ fn draw_pixel(value: u8, state: *uxn) void = { const flipy: bool = (value & 0b00100000) != 0; const flipx: bool = (value & 0b00010000) != 0; + if(!fill){ // fmt::printfln("Pixel at x: {:x} y: {:x} color: {:x}", x, y, color)!; const auto = state.dev[0x26]; @@ -16,11 +17,7 @@ fn draw_pixel(value: u8, state: *uxn) void = { const auto_x = (auto & 0b00000001) != 0; const auto_y = (auto & 0b00000010) != 0; const auto_a = (auto & 0b00000100) != 0; - if(!layer1){ - state.screen.0[x][y] = color; - } else { - state.screen.1[x][y] = color; - }; + set_pixel(layer1,x,y,color,state); if(auto_x) { const new_x = x + 1; state.dev[0x28] = (new_x >> 8): u8; @@ -46,17 +43,27 @@ fn draw_pixel(value: u8, state: *uxn) void = { for(let xl = startx; xl < endx; xl+=1){ for(let yl = starty; yl < endy; yl+=1){ // fmt::printfln("Filling at x: {:x} y: {:x} color: {:x}", xl, yl, color)!; - if(!layer1){ - state.screen.0[xl][yl] = color; - } else { - state.screen.1[xl][yl] = color; - }; + set_pixel(layer1,xl,yl,color,state); }; }; }; state.screen_update = true; }; + +fn set_pixel(layer1: bool,x: u16, y: u16,color: u8, state: *uxn) void = { + + if(x > MAXWIDTH || y > MAXHEIGHT){ + return; + }; + + if(!layer1){ + state.screen.0[x][y] = color; + } else { + state.screen.1[x][y] = color; + }; +}; + fn regenerate_palettes(state: *uxn) void = { const r = short_from_bytes(state.dev[0x08],state.dev[0x09]); const g = short_from_bytes(state.dev[0x0a],state.dev[0x0b]); @@ -162,13 +169,7 @@ fn copy_sprite_to_screen(bpp2: bool, colors: u8, x: u16, y: u16, addr: u16, flip if(drawZero || p > 0){ - if((x < MAXWIDTH) && (y < MAXHEIGHT)){ - if(layer1) { - state.screen.1[x+xoff][y+yoff] = color; - } else { - state.screen.0[x+xoff][y+yoff] = color; - }; - }; + set_pixel(layer1,x+xoff,y+yoff,color,state); }; if(flipx){