Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PUTSP trap #45

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading