Skip to content

Commit

Permalink
Merge pull request #45 from dxrcy/impl-putsp
Browse files Browse the repository at this point in the history
Implement `PUTSP` trap
  • Loading branch information
rozukke authored Sep 29, 2024
2 parents cc1a5c6 + d25a64b commit 1d1809d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,14 @@ impl RunState {
// puts
0x22 => {
// could probably rewrite with iterators but idk if worth
let mut addr = *self.reg(0);
let mut string = String::new();
loop {
for addr in *self.reg(0).. {
let chr_raw = *self.mem(addr);
let chr_ascii = (chr_raw & 0xFF) as u8 as char;
if chr_ascii == '\0' {
break;
}
string.push(chr_ascii);
addr += 1;
print!("{}", chr_ascii);
}
print!("{string}");
stdout().flush().unwrap();
}
// in
Expand All @@ -304,8 +300,17 @@ impl RunState {
}
// putsp
0x24 => {
// TODO: impl putsp
todo!("TODO: putsp can be put off until someone needs it")
'string: for addr in *self.reg(0).. {
let chr_raw = *self.mem(addr);
for chr in [chr_raw >> 8, chr_raw & 0xFF] {
let chr_ascii = chr as u8 as char;
if chr_ascii == '\0' {
break 'string;
}
print!("{}", chr_ascii);
}
}
stdout().flush().unwrap();
}
// halt
0x25 => {
Expand Down

0 comments on commit 1d1809d

Please sign in to comment.