Fixed sprites when base coordinate is off-screen

This commit is contained in:
JJ Bliss
2026-05-05 18:25:38 -04:00
parent 9ef1543cd0
commit e8df70a387
+18 -17
View File
@@ -9,6 +9,7 @@ fn draw_pixel(value: u8, state: *uxn) void = {
const flipy: bool = (value & 0b00100000) != 0; const flipy: bool = (value & 0b00100000) != 0;
const flipx: bool = (value & 0b00010000) != 0; const flipx: bool = (value & 0b00010000) != 0;
if(!fill){ if(!fill){
// fmt::printfln("Pixel at x: {:x} y: {:x} color: {:x}", x, y, color)!; // fmt::printfln("Pixel at x: {:x} y: {:x} color: {:x}", x, y, color)!;
const auto = state.dev[0x26]; 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_x = (auto & 0b00000001) != 0;
const auto_y = (auto & 0b00000010) != 0; const auto_y = (auto & 0b00000010) != 0;
const auto_a = (auto & 0b00000100) != 0; const auto_a = (auto & 0b00000100) != 0;
if(!layer1){ set_pixel(layer1,x,y,color,state);
state.screen.0[x][y] = color;
} else {
state.screen.1[x][y] = color;
};
if(auto_x) { if(auto_x) {
const new_x = x + 1; const new_x = x + 1;
state.dev[0x28] = (new_x >> 8): u8; 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 xl = startx; xl < endx; xl+=1){
for(let yl = starty; yl < endy; yl+=1){ for(let yl = starty; yl < endy; yl+=1){
// fmt::printfln("Filling at x: {:x} y: {:x} color: {:x}", xl, yl, color)!; // fmt::printfln("Filling at x: {:x} y: {:x} color: {:x}", xl, yl, color)!;
if(!layer1){ set_pixel(layer1,xl,yl,color,state);
state.screen.0[xl][yl] = color;
} else {
state.screen.1[xl][yl] = color;
};
}; };
}; };
}; };
state.screen_update = true; 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 = { fn regenerate_palettes(state: *uxn) void = {
const r = short_from_bytes(state.dev[0x08],state.dev[0x09]); const r = short_from_bytes(state.dev[0x08],state.dev[0x09]);
const g = short_from_bytes(state.dev[0x0a],state.dev[0x0b]); 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(drawZero || p > 0){
if((x < MAXWIDTH) && (y < MAXHEIGHT)){ set_pixel(layer1,x+xoff,y+yoff,color,state);
if(layer1) {
state.screen.1[x+xoff][y+yoff] = color;
} else {
state.screen.0[x+xoff][y+yoff] = color;
};
};
}; };
if(flipx){ if(flipx){