Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
feat: cbw
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 committed Jul 15, 2024
1 parent 48b7e03 commit a6341ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/interpreter/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ impl VmIrExecutable for VM {
IR::Dec { dest } => {
self.dec(dest);
}
IR::Cbw => {
self.cbw();
}
_ => panic!("{}: Not implemented", ir),
}
}
Expand Down
25 changes: 17 additions & 8 deletions src/interpreter/vm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub trait OpcodeExecutable {
fn or(&mut self, dest: Operand, src: Operand);
fn sub(&mut self, dest: Operand, src: Operand);
fn dec(&mut self, dest: Operand);
fn cbw(&mut self);
}

impl OpcodeExecutable for VM {
Expand Down Expand Up @@ -61,19 +62,23 @@ impl OpcodeExecutable for VM {
// _sendrec
let content_len = self.data.read_word(message_struct_ea + 6);
let content_ea = self.data.read_word(message_struct_ea + 10);
trace!(
"<write({}, {:#04x}, {})>",
message_source,
content_ea,
content_len
);
// set AX to 0
self.regs.set(Register::AX, 0);
// Return nb of bytes written
self.data.write_word(message_struct_ea + 2, content_len);

let content = self.data.read_bytes(content_ea, content_len as usize);
print!("{}", String::from_utf8_lossy(content));
let content = String::from_utf8_lossy(
self.data.read_bytes(content_ea, content_len as usize),
);
trace!(
"<write({}, {:#04x}, {}){} => {}>",
message_source,
content_ea,
content_len,
content,
content_len
);
print!("{}", content);
}
_ => unimplemented!(),
}
Expand Down Expand Up @@ -275,4 +280,8 @@ impl OpcodeExecutable for VM {
// SF, ZF and PF based on result
self.flags.set_szp(result);
}
fn cbw(&mut self) {
let al = self.regs.get(Register::AL) as i8;
self.regs.set(Register::AX, (al as i16).try_into().unwrap());
}
}

0 comments on commit a6341ef

Please sign in to comment.