Add DEC instruction and fix JCZ, JCZR.

This commit is contained in:
abbie 2022-06-14 19:56:33 +01:00
parent 13b3ec4b8d
commit 6d65e73afa
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87

View file

@ -423,6 +423,14 @@ fn execute(opcode: u32, instruction: Instruction, mut cpu: Cpu) -> Cpu {
cpu.regwrite(args[0] as usize, y+1); cpu.regwrite(args[0] as usize, y+1);
} }
cpu.incrementpc(); cpu.incrementpc();
} else if instruction.name == "DEC" {
let y = cpu.regread(args[0] as usize).to_owned();
if y == 0x00 {
cpu.regwrite(args[0] as usize, 0xFF);
} else {
cpu.regwrite(args[0] as usize, y-1);
}
cpu.incrementpc();
} else if instruction.name == "NOT" { } else if instruction.name == "NOT" {
let y = cpu.regread(args[0] as usize).to_owned(); let y = cpu.regread(args[0] as usize).to_owned();
cpu.regwrite(args[0] as usize, !y); cpu.regwrite(args[0] as usize, !y);
@ -463,7 +471,7 @@ fn execute(opcode: u32, instruction: Instruction, mut cpu: Cpu) -> Cpu {
cpu.refreshcache(); cpu.refreshcache();
cpu.setpc(args[0] as u16); cpu.setpc(args[0] as u16);
} else if instruction.name == "JCZ" { } else if instruction.name == "JCZ" {
let y = cpu.regread(args[0] as usize); let y = cpu.regread(args[1] as usize);
if *y == 0 { if *y == 0 {
cpu.setpc(args[0] as u16); cpu.setpc(args[0] as u16);
} else { } else {
@ -471,7 +479,7 @@ fn execute(opcode: u32, instruction: Instruction, mut cpu: Cpu) -> Cpu {
} }
} else if instruction.name == "JCZR" { } else if instruction.name == "JCZR" {
cpu.refreshcache(); cpu.refreshcache();
let y = cpu.regread(args[0] as usize); let y = cpu.regread(args[1] as usize);
if *y == 0 { if *y == 0 {
cpu.setpc(args[0] as u16); cpu.setpc(args[0] as u16);
} else { } else {