emu: show/peek debug instructions

This commit is contained in:
2021-03-09 06:42:12 -08:00
parent 20bfc45dae
commit 49789c74f9

View File

@@ -54,6 +54,16 @@ mod ops {
use emu::dos; use emu::dos;
use emu::i8088::{Bus, LValue, RValue, i8088, segoff_to_addr}; use emu::i8088::{Bus, LValue, RValue, i8088, segoff_to_addr};
pub fn show(cpu: &mut i8088) {
println!("{:#X?}", cpu);
}
pub fn peek(cpu: &mut i8088, bus: &mut Bus, addr: &u16) {
let addr = segoff_to_addr(cpu.ds, *addr);
let val = bus.ram[addr];
println!("PEEK: @{:#X} = {:#X} ({})", addr, val, val);
}
pub fn call(ip: &mut u16, ss: u16, sp: &mut u16, mem: &mut [u8], addr: i16) { pub fn call(ip: &mut u16, ss: u16, sp: &mut u16, mem: &mut [u8], addr: i16) {
let target = ip.wrapping_add(addr as u16); let target = ip.wrapping_add(addr as u16);
push16(ss, sp, mem, *ip); push16(ss, sp, mem, *ip);
@@ -211,6 +221,7 @@ macro_rules! step {
} }; } };
(@r16 $cookie:tt, $cpu:expr, $bus:expr, ($modrm:ident, $modrm16:tt, $modrm8:tt)) => { { (@r16 $cookie:tt, $cpu:expr, $bus:expr, ($modrm:ident, $modrm16:tt, $modrm8:tt)) => { {
// TODO: Should these also be passed into the macro like the modrm specs?
let reg = match $modrm >> 3 & 0x7 { let reg = match $modrm >> 3 & 0x7 {
0 => &mut $cpu.a, 0 => &mut $cpu.a,
1 => &mut $cpu.c, 1 => &mut $cpu.c,
@@ -226,6 +237,7 @@ macro_rules! step {
} }; } };
(@r8 $cookie:tt, $cpu:expr, $bus:expr, ($modrm:ident, $modrm16:tt, $modrm8:tt)) => { (@r8 $cookie:tt, $cpu:expr, $bus:expr, ($modrm:ident, $modrm16:tt, $modrm8:tt)) => {
// TODO: Should these also be passed into the macro like the modrm specs?
match $modrm >> 3 & 0x7 { match $modrm >> 3 & 0x7 {
0 => step!(@arg $cookie, &mut RegHi { reg: &mut $cpu.a } ), 0 => step!(@arg $cookie, &mut RegHi { reg: &mut $cpu.a } ),
1 => step!(@arg $cookie, &mut RegHi { reg: &mut $cpu.c } ), 1 => step!(@arg $cookie, &mut RegHi { reg: &mut $cpu.c } ),
@@ -348,6 +360,8 @@ impl i8088 {
loop { loop {
step!((self, bus) => step!((self, bus) =>
opcodes: { opcodes: {
0x60 => show[cpu] / 0, // Fake opcode for debugging
0x61 => peek[cpu, bus, d16] / 0, // Fake opcode for debugging
//0x8B _ => mov[r16, modrm16] / "2/12+", //0x8B _ => mov[r16, modrm16] / "2/12+",
0x8C: { 0x08 => mov[modrm16, reg=cs] / "2/13+", }, 0x8C: { 0x08 => mov[modrm16, reg=cs] / "2/13+", },
0x8E: { 0x18 => mov[reg=ds, modrm16] / "2/12+", }, 0x8E: { 0x18 => mov[reg=ds, modrm16] / "2/12+", },