System/wsr rst and state now work

This commit is contained in:
JJ Bliss
2026-04-26 18:35:41 -04:00
parent 1a4408cadf
commit aba1bbb4fd
2 changed files with 54 additions and 8 deletions
+38 -4
View File
@@ -124,7 +124,14 @@ export fn main() void = {
if(state.screen_vector != 0){ if(state.screen_vector != 0){
// fmt::println("Executing screen vector")!; // fmt::println("Executing screen vector")!;
uxn::uxn_eval(state.screen_vector, state)!; match (uxn::uxn_eval(state.screen_vector, state)) {
case done =>
yield;
case uxn::quit =>
run = false;
case let err: uxn::error =>
fmt::fatalf("Error evaluating: {}", uxn::strerror(err));
};
}; };
}; };
if(state.screen_size_changed){ if(state.screen_size_changed){
@@ -223,17 +230,44 @@ export fn main() void = {
const x = ev.motion.x / scale: f32; const x = ev.motion.x / scale: f32;
const y = ev.motion.y / scale: f32; const y = ev.motion.y / scale: f32;
uxn::set_mouse_motion(x: u16,y: u16,state); uxn::set_mouse_motion(x: u16,y: u16,state);
if(state.mouse_vector != 0 ) uxn::uxn_eval(state.mouse_vector,state)!; if(state.mouse_vector != 0 ){
match (uxn::uxn_eval(state.mouse_vector, state)) {
case done =>
yield;
case uxn::quit =>
run = false;
case let err: uxn::error =>
fmt::fatalf("Error evaluating: {}", uxn::strerror(err));
};
};
case sdl3::EventType::MOUSE_BUTTON_DOWN => case sdl3::EventType::MOUSE_BUTTON_DOWN =>
// fmt::printfln("Mouse Down: 0x{:x}", ev.button.button: u8 )!; // fmt::printfln("Mouse Down: 0x{:x}", ev.button.button: u8 )!;
const b = 1 << (ev.button.button: u8 - 1); const b = 1 << (ev.button.button: u8 - 1);
uxn::set_mouse_down(b,state); uxn::set_mouse_down(b,state);
if(state.mouse_vector != 0 ) uxn::uxn_eval(state.mouse_vector,state)!; if(state.mouse_vector != 0 ){
match (uxn::uxn_eval(state.mouse_vector, state)) {
case done =>
yield;
case uxn::quit =>
run = false;
case let err: uxn::error =>
fmt::fatalf("Error evaluating: {}", uxn::strerror(err));
};
};
case sdl3::EventType::MOUSE_BUTTON_UP => case sdl3::EventType::MOUSE_BUTTON_UP =>
// fmt::printfln("Mouse Up: 0x{:x}", ev.button.button: u8 )!; // fmt::printfln("Mouse Up: 0x{:x}", ev.button.button: u8 )!;
const b = 1 << (ev.button.button: u8 - 1); const b = 1 << (ev.button.button: u8 - 1);
uxn::set_mouse_up(b,state); uxn::set_mouse_up(b,state);
if(state.mouse_vector != 0 ) uxn::uxn_eval(state.mouse_vector,state)!; if(state.mouse_vector != 0 ){
match (uxn::uxn_eval(state.mouse_vector, state)) {
case done =>
yield;
case uxn::quit =>
run = false;
case let err: uxn::error =>
fmt::fatalf("Error evaluating: {}", uxn::strerror(err));
};
};
case sdl3::EventType::MOUSE_WHEEL => case sdl3::EventType::MOUSE_WHEEL =>
fmt::printfln("Mouse Wheel!")!; fmt::printfln("Mouse Wheel!")!;
case sdl3::EventType::WINDOW_EXPOSED => case sdl3::EventType::WINDOW_EXPOSED =>
+16 -4
View File
@@ -79,9 +79,15 @@ export fn set_window_size(w: u16, h: u16, state: *uxn) void = {
}; };
fn emu_dei(port: u8, state: *uxn) u8 = { fn emu_dei(port: u8, state: *uxn) u8 = {
let val = state.dev[port]; switch(port) {
case 0x04 =>
return state.ptr[0];
case 0x05 =>
return state.ptr[1];
case =>
return state.dev[port];
// fmt::printfln("Read {:x} from port {:x}", val, port)!; // fmt::printfln("Read {:x} from port {:x}", val, port)!;
return val; };
}; };
@@ -89,6 +95,10 @@ fn emu_deo(port: u8, value: u8, state: *uxn) void = {
// fmt::printfln("Writing {:x} to port {:x}", value, port)!; // fmt::printfln("Writing {:x} to port {:x}", value, port)!;
state.dev[port] = value; state.dev[port] = value;
switch(port) { switch(port) {
case 0x04 =>
state.ptr[0] = value;
case 0x05 =>
state.ptr[1] = value;
case 0x11 => case 0x11 =>
let high = state.dev[0x10]; let high = state.dev[0x10];
let low = value; let low = value;
@@ -375,6 +385,7 @@ export fn get_color(x: u16, y: u16, state: *uxn) u16 = {
export type evalerror = !void; export type evalerror = !void;
export type unhandled = !u8; export type unhandled = !u8;
export type quit = void;
export type error = !(evalerror | unhandled); export type error = !(evalerror | unhandled);
@@ -606,13 +617,14 @@ fn pop_or_get(inst: normal_op, off: u8, state: *uxn) (u8 | u16) = {
yield get_stack_val(inst.ret,inst.short, off,state); yield get_stack_val(inst.ret,inst.short, off,state);
}; };
}; };
export fn uxn_eval(new_pc: u16, state: *uxn) (done | error ) = { export fn uxn_eval(new_pc: u16, state: *uxn) (done | quit | error ) = {
// let a: u16 = 0, b: u16 = 0, c: u16 = 0, x: [2]u16 = [0...], y: [2]u16 = [0...], z: [2]u16 = [0...]; // let a: u16 = 0, b: u16 = 0, c: u16 = 0, x: [2]u16 = [0...], y: [2]u16 = [0...], z: [2]u16 = [0...];
state.pc = new_pc; state.pc = new_pc;
state.running = true; state.running = true;
for(state.running){ for(state.running){
uxn_step(state)?; uxn_step(state)?;
}; };
if(state.dev[0x0f] != 0) return quit;
return done; return done;
}; };
@@ -1007,7 +1019,7 @@ export fn console_input(c: u8, ctype: u8, state: *uxn) (done | error) = {
// Converts an error into a user-friendly string // Converts an error into a user-friendly string
fn strerror(err: error) str = { export fn strerror(err: error) str = {
match (err) { match (err) {
case evalerror => case evalerror =>
return "Reached unexpected part of eval code"; return "Reached unexpected part of eval code";