passing auto and flip sprite tests

This commit is contained in:
JJ Bliss
2026-04-26 16:00:08 -04:00
parent fc5f41910e
commit 56490a754f
2 changed files with 125 additions and 55 deletions
+85 -44
View File
@@ -127,6 +127,18 @@ export fn set_mouse_motion(x: u16, y: u16, state: *uxn) void = {
state.dev[0x95] = (y): u8;
};
export fn set_mouse_down(button: u8, state: *uxn) void = {
const cur = state.dev[0x96];
const new = cur | button;
state.dev[0x96] = new;
};
export fn set_mouse_up(button: u8, state: *uxn) void = {
const cur = state.dev[0x96];
const invbutton = 0xff ^ button;
const new = cur & invbutton;
state.dev[0x96] = new;
};
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]);
@@ -215,76 +227,105 @@ fn draw_sprite(value: u8, state: *uxn) void = {
const x = short_from_bytes(state.dev[0x28],state.dev[0x29]);
const y = short_from_bytes(state.dev[0x2a],state.dev[0x2b]);
for(let i: u16 = 0; i <= count; i+=1){
if(count == 0){
const addr = short_from_bytes(state.dev[0x2c],state.dev[0x2d]);
const x = x + i * 8;
// const x = if(flipx) { yield x - i * 8; } else { yield x + i * 8; };
copy_sprite_to_screen(bpp2,colors,x,y,addr,flipx,flipy,layer1,state);
if(auto_a){
const new_addr = if(bpp2) { yield addr + 16; } else { yield addr + 8; };
state.dev[0x2c] = (new_addr >> 8): u8;
state.dev[0x2d] = (new_addr): u8;
};
};
if(auto_x) {
const new_x = x + 8;
state.dev[0x28] = (new_x >> 8): u8;
state.dev[0x29] = (new_x): u8;
if(auto_x) {
const new_x = if(flipx) { yield x - 8; } else { yield x + 8; };
state.dev[0x28] = (new_x >> 8): u8;
state.dev[0x29] = (new_x): u8;
};
if(auto_y) {
const new_y = y + 8;
state.dev[0x2a] = (new_y >> 8): u8;
state.dev[0x2b] = (new_y): u8;
};
if(auto_y) {
const new_y = if(flipy) { yield y - 8; } else { yield y + 8; };
state.dev[0x2a] = (new_y >> 8): u8;
state.dev[0x2b] = (new_y): u8;
};
}else {
// fmt::printfln("Multi-Sprite! Auto-x: {} Auto-y: {} Flip-x: {} Flip-y: {}",auto_x,auto_y,flipx,flipy)!;
for(let i: u16 = 0; i <= count; i+=1){
const addr = short_from_bytes(state.dev[0x2c],state.dev[0x2d]);
let x = x;
let y = y;
if(auto_y) {
x = if(flipx) { yield x - i * 8; } else { yield x + i * 8; };
}else if(auto_x) {
y = if(flipy) { yield y - i * 8; } else { yield y + i * 8; };
};
copy_sprite_to_screen(bpp2,colors,x,y,addr,flipx,flipy,layer1,state);
if(auto_a){
const new_addr = if(bpp2) { yield addr + 16; } else { yield addr + 8; };
state.dev[0x2c] = (new_addr >> 8): u8;
state.dev[0x2d] = (new_addr): u8;
};
};
if(auto_y) {
const new_y = if(flipy){ yield y - 8; } else { yield y + 8; };
state.dev[0x2a] = (new_y >> 8): u8;
state.dev[0x2b] = (new_y): u8;
};
if(auto_x) {
const new_x = x + 8;
state.dev[0x28] = (new_x >> 8): u8;
state.dev[0x29] = (new_x): u8;
};
};
state.screen_update = true;
};
fn copy_sprite_to_screen(bpp2: bool, colors: u8, x: u16, y: u16, addr: u16, flipx: bool, flipy: bool, layer1: bool, state: *uxn) void = {
const bytes_per_sprite = if(bpp2) {yield 16;} else {yield 8;};
let dims = get_window_size(state);
let xoff: u16 = 0;
let yoff: u16 = 0;
let xoff: u16 = if(flipx){ yield 7; } else { yield 0; };
let yoff: u16 = if(flipy){ yield 7; } else { yield 0; };
if(!bpp2) {
const pixels = get_pixels_from_1bpp_sprite(addr,state);
for(let p .. pixels){
const color = if(p == 0) { yield 0:u8;} else {yield colors: u8; };
if((x < MAXWIDTH) && (y < MAXHEIGHT)){
if(layer1) { state.screen.1[x+xoff][y+yoff] = color; }
else {state.screen.0[x+xoff][y+yoff] = color; };
};
xoff += 1;
if(xoff >= 8){
xoff = 0;
yoff += 1;
};
const pixels: []u8 = if(bpp2) { yield get_pixels_from_2bpp_sprite(addr,state); }
else {yield get_pixels_from_1bpp_sprite(addr,state);};
for(let p .. pixels){
const color = if(!bpp2){
yield if(p == 0) { yield 0:u8;} else {yield colors: u8; };
} else {
yield p;
};
}else{
const pixels = get_pixels_from_2bpp_sprite(addr,state);
for(let p .. pixels){
const color = p; //TODO use colors bits
// fmt::printfln("x: 0x{:x}, xoff: 0x{:x}, y: 0x{:x}, yoff: 0x{:x}", x,xoff,y,yoff )!;
if((x < MAXWIDTH) && (y < MAXHEIGHT)){
if(layer1) { state.screen.1[x+xoff][y+yoff] = color; }
else {state.screen.0[x+xoff][y+yoff] = color; };
};
if((x < MAXWIDTH) && (y < MAXHEIGHT)){
if(layer1) { state.screen.1[x+xoff][y+yoff] = color; }
else {state.screen.0[x+xoff][y+yoff] = color; };
};
if(flipx){
xoff -= 1;
}else {
xoff += 1;
if(xoff >= 8){
xoff = 0;
yoff += 1;
};
if(xoff >= 8){
xoff = if(flipx){ yield 7; } else { yield 0; };
if(flipy){
yoff -=1;
}else{
yoff += 1;
};
// if(yoff >= 8){
// break;
// };
};
};
};
fn get_pixels_from_1bpp_sprite(addr: u16, state: *uxn) []u8 = {