Basic mouse hover support and sprite auto work more properly

This commit is contained in:
JJ Bliss
2026-04-26 11:15:19 -04:00
parent b18dd94a06
commit fc5f41910e
3 changed files with 134 additions and 87 deletions
+44 -45
View File
@@ -10,11 +10,11 @@ use strings;
// let ptr: [2] u8 = [0...];
// let stk: [2][0x100] u8 = [[0...],[0...]];
export type uxn = struct {
pc: u16,
console_vector: u16,
screen_vector: u16,
mouse_vector: u16,
ram: [0x10000] u8,
dev: [0x100] u8,
ptr: [2] u8,
@@ -39,6 +39,7 @@ fn initialize_uxn_mem() *uxn = {
pc = reset_vector,
console_vector = 0,
screen_vector = 0,
mouse_vector = 0,
ram = [0...],
dev = [0...],
ptr = [0...],
@@ -99,6 +100,10 @@ fn emu_deo(port: u8, value: u8, state: *uxn) void = {
draw_pixel(value,state);
case 0x2f =>
draw_sprite(value,state);
case 0x91 =>
let high = state.dev[0x90];
let low = value;
state.mouse_vector = short_from_bytes(high,low);
case =>
if( port == 0x22 ||
port == 0x23 ||
@@ -115,6 +120,13 @@ fn emu_deo(port: u8, value: u8, state: *uxn) void = {
};
};
export fn set_mouse_motion(x: u16, y: u16, state: *uxn) void = {
state.dev[0x92] = (x >> 8): u8;
state.dev[0x93] = (x): u8;
state.dev[0x94] = (y >> 8): u8;
state.dev[0x95] = (y): u8;
};
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]);
@@ -192,7 +204,7 @@ fn draw_sprite(value: u8, state: *uxn) void = {
//TODO handle fill
const colors = value & 0b00001111;
const auto = state.dev[0x26];
let count = ((auto & 0xf0) >> 4): i8;
let count = ((auto & 0xf0) >> 4): u8;
const auto_x = (auto & 0b00000001) != 0;
const auto_y = (auto & 0b00000010) != 0;
const auto_a = (auto & 0b00000100) != 0;
@@ -201,24 +213,13 @@ fn draw_sprite(value: u8, state: *uxn) void = {
const flipy: bool = (value & 0b00100000) != 0;
const flipx: bool = (value & 0b00010000) != 0;
for(let i = 0; i <= count; i+=1){
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){
const addr = short_from_bytes(state.dev[0x2c],state.dev[0x2d]);
const x = short_from_bytes(state.dev[0x28],state.dev[0x29]);
const y = short_from_bytes(state.dev[0x2a],state.dev[0x2b]);
const x = x + i * 8;
copy_sprite_to_screen(bpp2,colors,x,y,addr,flipx,flipy,layer1,state);
if(auto_x) {
const new_x = 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_a){
const new_addr = if(bpp2) { yield addr + 16; } else { yield addr + 8; };
@@ -226,12 +227,26 @@ fn draw_sprite(value: u8, state: *uxn) void = {
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_y) {
const new_y = y + 8;
state.dev[0x2a] = (new_y >> 8): u8;
state.dev[0x2b] = (new_y): 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;
@@ -240,8 +255,10 @@ fn copy_sprite_to_screen(bpp2: bool, colors: u8, x: u16, y: u16, addr: u16, flip
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(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; };
};
xoff += 1;
if(xoff >= 8){
xoff = 0;
@@ -252,40 +269,22 @@ fn copy_sprite_to_screen(bpp2: bool, colors: u8, x: u16, y: u16, addr: u16, flip
const pixels = get_pixels_from_2bpp_sprite(addr,state);
for(let p .. pixels){
const color = p; //TODO use colors bits
if(layer1) { state.screen.1[x+xoff][y+yoff] = color; }
else {state.screen.0[x+xoff][y+yoff] = color; };
// 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; };
};
xoff += 1;
if(xoff >= 8){
xoff = 0;
yoff += 1;
};
// if(yoff >= 8){
// break;
// };
};
};
// fmt::printfln("Drawing Sprite to x: {} y: {}", x, y)!;
// for(let i = 0; i < bytes_per_sprite; i+=1){
// const pixels = get_pixels_from_sprite(bpp2,addr,state);
// for(let p .. pixels){
// const color: u8 = (if (bpp2){
// yield p: u8; // implement real value based on colors value
// }else {
// if( p == 0 ) yield 0: u8;
// yield colors: u8;
// } )& 0b00000011;
// // fmt::printfln("Drawing 2bpp: {} Sprite Pixel to x: {} y: {} color: {}", bpp2, x+xoff, y+yoff, p)!;
// 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;
// };
// };
// };
};
fn get_pixels_from_1bpp_sprite(addr: u16, state: *uxn) []u8 = {