From 066e9776875d8746d89de62616a0d55ad0dcb452 Mon Sep 17 00:00:00 2001 From: Theron Spiegl Date: Mon, 6 Jan 2020 18:24:52 -0600 Subject: [PATCH] debugging --- src/apu/triangle.rs | 2 +- src/cpu/mod.rs | 66 +++++++++++++++++++++++++++------------------ src/main.rs | 12 ++++++++- 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/src/apu/triangle.rs b/src/apu/triangle.rs index c89fbc9..0afd77f 100644 --- a/src/apu/triangle.rs +++ b/src/apu/triangle.rs @@ -12,7 +12,7 @@ pub struct Triangle { waveform_counter: usize, pub length_counter: u8, - length_counter_halt: bool, // (this bit is also the linear counter's control flag) / (this bit is also the length counter halt flag) + length_counter_halt: bool, // (this bit is also the linear counter's control flag) linear_counter: u8, counter_reload_value: u8, diff --git a/src/cpu/mod.rs b/src/cpu/mod.rs index ddc52b4..c6773ba 100644 --- a/src/cpu/mod.rs +++ b/src/cpu/mod.rs @@ -177,7 +177,7 @@ impl Cpu { // debugging // assert!(self.memory_at(0xAD79, 141) == UNDERGROUND_LEVEL.to_vec() && self.memory_at(0xA133, 45) == UNDERGROUND_ENEMIES.to_vec()); - let pc = self.PC; + // let pc = self.PC; // if address == 0x06D6 { // // let mem = self.memory_at(0xAD79, 141); // // println!("memory at 0xAD79: {:02X?}", mem); @@ -186,31 +186,31 @@ impl Cpu { // self.more += 24; // } // } - if pc == 0xB1E5 { - println!("==========================="); - if self.more == 0 { - self.more += 24; - } - } - if self.more > 0 { - let operands = match num_bytes { - 1 => " ".to_string(), - 2 => format!("{:02X} ", self.read(pc + 1)), - 3 => format!("{:02X} {:02X}", self.read(pc + 1), self.read(pc+2)), - _ => "error".to_string(), - }; - print!("{:04X} {:02X} {} {} A:{:02X} X:{:02X} Y:{:02X} P:{:02X} SP:{:02X}", - pc, self.read(pc), operands, OPCODE_DISPLAY_NAMES[opcode], - self.A, self.X, self.Y, self.P, self.S, - ); - // let mut zpg = Vec::::new(); - // for i in 0..32 { - // zpg.push(self.read(i)); - // } - // print!(" zpg: {:x?}", zpg); - print!("\n"); - self.more -= 1; - } + // if pc == 0xB1E5 { + // println!("==========================="); + // if self.more == 0 { + // self.more += 24; + // } + // } + // if self.more > 0 { + // let operands = match num_bytes { + // 1 => " ".to_string(), + // 2 => format!("{:02X} ", self.read(pc + 1)), + // 3 => format!("{:02X} {:02X}", self.read(pc + 1), self.read(pc+2)), + // _ => "error".to_string(), + // }; + // print!("{:04X} {:02X} {} {} A:{:02X} X:{:02X} Y:{:02X} P:{:02X} SP:{:02X}", + // pc, self.read(pc), operands, OPCODE_DISPLAY_NAMES[opcode], + // self.A, self.X, self.Y, self.P, self.S, + // ); + // // let mut zpg = Vec::::new(); + // // for i in 0..32 { + // // zpg.push(self.read(i)); + // // } + // // print!(" zpg: {:x?}", zpg); + // print!("\n"); + // self.more -= 1; + // } // advance program counter according to how many bytes that instruction operated on self.advance_pc(mode); @@ -252,6 +252,20 @@ impl Cpu { // if address == 0x06D6 { // println!("writing 0x{:02X} to 0x{:04X}", val, address); // } + + let vars = vec![ + ("PlayerEntranceCtrl", 0x0710), + ("AltEntranceControl", 0x0752), + ("EntrancePage", 0x0751), + ("AreaPointer", 0x0750), + ("AreaAddrsLOffset", 0x074f), + ]; + for i in vars.iter() { + if i.1 == address { + println!("writing 0x{:02X} to {}", val, i.0); + } + } + match address { 0x0000..=0x1FFF => self.mem[address % 0x0800] = val, 0x2000..=0x3FFF => self.write_ppu_reg(address % 8, val), diff --git a/src/main.rs b/src/main.rs index 33e28f3..90cc9ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -202,5 +202,15 @@ shows the program counter at 0xB1EF, meaning I was right that the routine's addr Anyway, hook PC == $B1E5. Ok, so, comparing logs with the good emulator down the WORKING pipe in 1-1 shows a divergence in behavior based on loading value 0x6E from $0755 into the accumulator, -and comparing that to 0x50. What's at $0755? Player_Pos_ForScroll. +and comparing that to 0x50. What's at $0755? Player_Pos_ForScroll, which is just Mario's horizontal position on screen. +And that's the only difference, over and over, so doesn't really matter. +Now need to see what's different when we drop into the bad room. 1200 lines in log from one pipe, +25 lines each (24 and a separator) so 48 iterations of VerticalPipeEntry per pipe. +But logs for VerticalPipeEntry for the bad room also seem to match the good emulator except for the Player_Pos_ForScroll... +Other suspicious variables: +PlayerEntranceCtrl +AltEntranceControl +EntrancePage +AreaPointer +AreaAddrsLOffset */