Skip to content

Commit

Permalink
GSU: clear B/SREG/DREG/ALTx after MOVE(S)
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Feb 26, 2024
1 parent ec564fc commit 59eac7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cpu_gsu/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,14 @@ impl CpuGsu {

// SREG/DREG/ALTx are reset after execution, but should persist
// for branch and prefix instructions.
if !(0x05..=0x0F).contains(&instr)
// Special cases for MOVE/MOVES because they use the same opcode
// as TO/FROM.
if (!(0x05..=0x0F).contains(&instr)
&& !(0x3D..=0x3F).contains(&instr)
&& (instr & 0xF0) != 0x10
&& (instr & 0xF0) != 0x20
&& (instr & 0xF0) != 0xB0
&& (instr & 0xF0) != 0xB0)
|| (self.regs.test_flag(Flag::B) && ((instr & 0xF0 == 0x10) || (instr & 0xF0 == 0xB0)))
{
self.sreg = 0;
self.dreg = 0;
Expand Down
20 changes: 20 additions & 0 deletions src/cpu_gsu/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,24 @@ fn op_move() {
let c = cpu_run(&[IWT | 2, 0xBB, 0xAA, WITH | 2, TO | 3, STOP]);
assert_eq!(c.regs.read(Register::R2), 0xAABB);
assert_eq!(c.regs.read(Register::R3), 0xAABB);
assert!(!c.regs.test_flag(Flag::B));
}

#[test]
fn op_move_clears_altx_b() {
let mut c = cpu_steps(&[IWT | 2, 0xBB, 0xAA, WITH | 2, ALT3, TO | 3], 3);
// Before TO R2 (MOVE)
assert!(c.regs.test_flag(Flag::B));
assert!(c.regs.test_flag(Flag::ALT1));
assert!(c.regs.test_flag(Flag::ALT2));
assert_eq!(c.regs.read(Register::R3), 0);

c.step().unwrap();

// After MOVE
assert_eq!(c.regs.read(Register::R2), 0xAABB);
assert_eq!(c.regs.read(Register::R3), 0xAABB);
assert!(!c.regs.test_flag(Flag::B));
assert!(!c.regs.test_flag(Flag::ALT1));
assert!(!c.regs.test_flag(Flag::ALT2));
}

0 comments on commit 59eac7d

Please sign in to comment.