From c688bf63ea018b0a9faf6657e1c31f0fc948b6b7 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sat, 6 Jan 2024 13:58:26 -0500 Subject: [PATCH] implement PUTS trap routine --- src/vm/instruction.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/vm/instruction.rs b/src/vm/instruction.rs index c4216d9..cf2541c 100644 --- a/src/vm/instruction.rs +++ b/src/vm/instruction.rs @@ -115,10 +115,23 @@ fn op_trap(vm: &mut VM, instr: u16) { match trap_vector { 0x20 => todo!("GETC"), 0x21 => todo!("OUT"), - 0x22 => todo!("PUTS"), + 0x22 => trap_puts(vm), 0x23 => todo!("IN"), 0x24 => todo!("PUTSP"), 0x25 => vm.running = false, _ => unimplemented!(), } } + +fn trap_puts(vm: &mut VM) { + let mut idx = vm.registers.r0; + loop { + let c = vm.mem.get_mem(idx) as u8 as char; + if c == '\0' { + break; + } + + print!("{}", c); + idx += 1; + } +}