From 9ef1543cd06c772f711e8086bfa9540af3c1f0c2 Mon Sep 17 00:00:00 2001 From: JJ Bliss Date: Tue, 5 May 2026 16:13:46 -0400 Subject: [PATCH] Fixed keycode issue and cleaned up code --- src/main.ha | 4 ++-- uxn/uxn.ha | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main.ha b/src/main.ha index 72f1529..b5fced6 100644 --- a/src/main.ha +++ b/src/main.ha @@ -13,7 +13,7 @@ use uxn; def WIDTH = 640; def HEIGHT = 480; -def DEFAULT_SCALE = 3; +def DEFAULT_SCALE = 1; def MAX_CONSOLE_INPUT = 0x1000; export fn main() void = { @@ -284,7 +284,7 @@ export fn main() void = { const scancode = ev.key.scancode; const mods = ev.key.mod; const sym = sdl3::GetKeyFromScancode(scancode,mods,false); - if( sym < sdl3::K_F13){ + if( sym < 0xFF){ uxn::set_key_down(sym: u8,state); }; // Handle F Keys diff --git a/uxn/uxn.ha b/uxn/uxn.ha index 8a5d10b..6372434 100644 --- a/uxn/uxn.ha +++ b/uxn/uxn.ha @@ -634,7 +634,7 @@ export fn uxn_step(state: *uxn) (done | error) = { return done; // /* JCI */ case 0x20: if(DEC(0)) { IMM state.pc += a; } else pc += 2; break; case JCI => - let val: u8 = pop_from_stack(false, false, false, state): u8; + const val: u8 = pop_from_stack(false, false, false, state): u8; if(val != 0) { state.pc += 2 + short_from_bytes(state.ram[state.pc],state.ram[state.pc+1]); //TODO, is this signed? }else{ @@ -658,7 +658,7 @@ export fn uxn_step(state: *uxn) (done | error) = { }; // /* INC */ OPC(0x01,POx(a,d),PUx(a + 1,d,r)) case let inc_inst: INC => - let val = match(pop_from_stack(inc_inst.keep,inc_inst.ret,inc_inst.short,state)) { + const val = match(pop_from_stack(inc_inst.keep,inc_inst.ret,inc_inst.short,state)) { //TODO this whole match statement seems unnecessary case let byte: u8 => yield byte + 1; @@ -674,42 +674,42 @@ export fn uxn_step(state: *uxn) (done | error) = { }; // /* NIP */ OPC(0x03,GOT(x) ptr[r] -= 1 + d;,PUT(x,r)) case let nip_inst: NIP => - let top = pop_or_get(nip_inst,0,state); - let bot = pop_or_get(nip_inst,1,state); + const top = pop_or_get(nip_inst,0,state); + const bot = pop_or_get(nip_inst,1,state); push_to_stack(nip_inst.ret, top, state); // /* SWP */ OPC(0x04,GOT(x) GOT(y),PUT(x,r) PUT(y,r)) case let swp_inst: SWP => - let top = pop_or_get(swp_inst,0,state); - let bot = pop_or_get(swp_inst,1,state); + const top = pop_or_get(swp_inst,0,state); + const bot = pop_or_get(swp_inst,1,state); push_to_stack(swp_inst.ret, top, state); push_to_stack(swp_inst.ret, bot, state); // /* ROT */ OPC(0x05,GOT(x) GOT(y) GOT(z),PUT(y,r) PUT(x,r) PUT(z,r)) case let rot_inst: ROT => - let top = pop_or_get(rot_inst,0,state); - let mid = pop_or_get(rot_inst,1,state); - let bot = pop_or_get(rot_inst,2,state); + const top = pop_or_get(rot_inst,0,state); + const mid = pop_or_get(rot_inst,1,state); + const bot = pop_or_get(rot_inst,2,state); push_to_stack(rot_inst.ret, mid, state); push_to_stack(rot_inst.ret, top, state); push_to_stack(rot_inst.ret, bot, state); // /* DUP */ OPC(0x06,GOT(x),PUT(x,r) PUT(x,r)) case let dup_inst: DUP => - let val = pop_from_stack(dup_inst.keep, dup_inst.ret, dup_inst.short, state); + const val = pop_from_stack(dup_inst.keep, dup_inst.ret, dup_inst.short, state); push_to_stack(dup_inst.ret, val, state); push_to_stack(dup_inst.ret, val, state); // /* OVR */ OPC(0x07,GOT(x) GOT(y),PUT(y,r) PUT(x,r) PUT(y,r)) case let ovr_inst: OVR => - let top = pop_or_get(ovr_inst,0,state); - let bot = pop_or_get(ovr_inst,1,state); + const top = pop_or_get(ovr_inst,0,state); + const bot = pop_or_get(ovr_inst,1,state); push_to_stack(ovr_inst.ret, bot, state); push_to_stack(ovr_inst.ret, top, state); push_to_stack(ovr_inst.ret, bot, state); // /* EQU */ OPC(0x08,POx(a,d) POx(b,d),PUx(b == a,0,r)) case let equ_inst: EQU => - let top = pop_or_get(equ_inst,0,state); - let bot = pop_or_get(equ_inst,1,state); + const top = pop_or_get(equ_inst,0,state); + const bot = pop_or_get(equ_inst,1,state); //TODO, I think this works, but it feels unclean with the casting let val: u8 = if(top: u16 == bot: u16){ @@ -733,8 +733,8 @@ export fn uxn_step(state: *uxn) (done | error) = { push_to_stack(equ_inst.ret, val, state); // /* NEQ */ OPC(0x09,POx(a,d) POx(b,d),PUx(b != a,0,r)) case let neq_inst: NEQ => - let top = pop_or_get(neq_inst,0,state); - let bot = pop_or_get(neq_inst,1,state); + const top = pop_or_get(neq_inst,0,state); + const bot = pop_or_get(neq_inst,1,state); //TODO, I think this works, but it feels unclean with the casting let val: u8 = if(top: u16 != bot: u16){ @@ -758,8 +758,8 @@ export fn uxn_step(state: *uxn) (done | error) = { push_to_stack(neq_inst.ret, val, state); // /* GTH */ OPC(0x0a,POx(a,d) POx(b,d),PUx(b > a,0,r)) case let gth_inst: GTH => - let top = pop_or_get(gth_inst,0,state); - let bot = pop_or_get(gth_inst,1,state); + const top = pop_or_get(gth_inst,0,state); + const bot = pop_or_get(gth_inst,1,state); //TODO, I think this works, but it feels unclean with the casting let val: u8 = if(bot: u16 > top: u16){ @@ -783,8 +783,8 @@ export fn uxn_step(state: *uxn) (done | error) = { push_to_stack(gth_inst.ret, val, state); // /* LTH */ OPC(0x0b,POx(a,d) POx(b,d),PUx(b < a,0,r)) case let lth_inst: LTH => - let top = pop_or_get(lth_inst,0,state); - let bot = pop_or_get(lth_inst,1,state); + const top = pop_or_get(lth_inst,0,state); + const bot = pop_or_get(lth_inst,1,state); //TODO, I think this works, but it feels unclean with the casting let val: u8 = if(bot: u16 < top: u16){ @@ -808,7 +808,7 @@ export fn uxn_step(state: *uxn) (done | error) = { push_to_stack(lth_inst.ret, val, state); // /* JMP */ OPC(0x0c,POx(a,d),MOV) case let jmp_inst: JMP => - let addr = pop_or_get(jmp_inst,0,state); + const addr = pop_or_get(jmp_inst,0,state); match(addr) { case let b: u8 => let off = b: i8: i32; @@ -820,8 +820,8 @@ export fn uxn_step(state: *uxn) (done | error) = { // /* JCN */ OPC(0x0d,POx(a,d) POx(b,0),if(b) MOV) case let jcn_inst: JCN => - let addr = pop_or_get(jcn_inst,0,state); - let cond: u8 = pop_or_peek(normal_op {keep = jcn_inst.keep, + const addr = pop_or_get(jcn_inst,0,state); + const cond: u8 = pop_or_peek(normal_op {keep = jcn_inst.keep, ret = jcn_inst.ret, short = false}, if(jcn_inst.short){ yield 2;} else { yield 1; }, state ): u8; @@ -987,7 +987,7 @@ export fn uxn_step(state: *uxn) (done | error) = { case let sft_inst: SFT => let shifts: u8 = pop_or_peek(normal_op{short = false, keep = sft_inst.keep, ret = sft_inst.ret}, 0, state): u8; let rightshifts = shifts & 0b00001111; - let leftshifts = (shifts & 0b11110000) >> 4; + let leftshifts = ((shifts & 0b11110000) >> 4) & 0b00001111; let val = pop_or_peek(sft_inst,1,state); let res = match(val) { case let s: u16 =>