diff --git a/src/cpu.rs b/src/cpu.rs index ae088c047edab8c2c3722806fb85b00dc8ac1dfd..ff2f4c527d159c9d76208f5a863c0cd9c3801e23 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -73,14 +73,6 @@ impl Cpu { ); } - if pc == 0x0080 { - println!("GOING TO PLAY BOOT SOUND"); - } - - if pc == 0x00e9 { - println!("GOING TO PLAY BOOT 0x00ef"); - } - // calls the current instruction and increments the number of // cycles executed by the instruction time of the instruction // that has just been executed diff --git a/src/mmu.rs b/src/mmu.rs index beb8b3ddd79a80d926a978e15b6c90941694ff33..8b333bd26a411c39fb0f0a4515fe6500261f3c3d 100644 --- a/src/mmu.rs +++ b/src/mmu.rs @@ -53,22 +53,19 @@ impl Mmu { 0x4000 | 0x5000 | 0x6000 | 0x7000 => self.rom[addr as usize], // Graphics: VRAM (8 KB) 0x8000 | 0x9000 => { - println!("READING FROM VRAM"); self.ppu.vram[(addr & 0x1fff) as usize] } // External RAM (8 KB) 0xa000 | 0xb000 => { - println!("READING FROM ERAM"); self.eram[(addr & 0x1fff) as usize] } // Working RAM (8 KB) 0xc000 | 0xd000 => self.ram[(addr & 0x1fff) as usize], - // Working RAM shadow + // Working RAM Shadow 0xe000 => { - println!("READING FROM RAM Shadow"); self.ram[(addr & 0x1fff) as usize] } - // Working RAM shadow, I/O, Zero-page RAM + // Working RAM Shadow, I/O, Zero-page RAM 0xf000 => match addr & 0x0f00 { 0x000 | 0x100 | 0x200 | 0x300 | 0x400 | 0x500 | 0x600 | 0x700 | 0x800 | 0x900 | 0xa00 | 0xb00 | 0xc00 | 0xd00 => self.ram[(addr & 0x1fff) as usize], @@ -118,19 +115,17 @@ impl Mmu { } // External RAM (8 KB) 0xa000 | 0xb000 => { - println!("WRITING TO ERAM"); + self.eram[(addr & 0x1fff) as usize] = value; } // Working RAM (8 KB) 0xc000 | 0xd000 => { - println!("WRITING TO RAM"); self.ram[(addr & 0x1fff) as usize] = value; } - // Working RAM shadow + // Working RAM Shadow 0xe000 => { - println!("WRITING TO RAM Shadow"); self.ram[(addr & 0x1fff) as usize] = value; } - // Working RAM shadow, I/O, Zero-page RAM + // Working RAM Shadow, I/O, Zero-page RAM 0xf000 => match addr & 0x0f00 { 0x000 | 0x100 | 0x200 | 0x300 | 0x400 | 0x500 | 0x600 | 0x700 | 0x800 | 0x900 | 0xa00 | 0xb00 | 0xc00 | 0xd00 => { diff --git a/src/ppu.rs b/src/ppu.rs index 250b1d5e9007be8a4486037a2354edc011b0a6a2..a26556cd66699f2adf88770c56f82816a149e130 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -52,9 +52,18 @@ pub struct Ppu { /// range between 0 (0x00) and 153 (0x99), representing /// the 154 lines plus 10 extra v-blank lines. line: u8, + /// Controls if the background is going to be drawn to screen. switch_bg: bool, + /// Controls if the sprites are going to be drawn to screen. + switch_sprites: bool, + /// Controls the map that is going to be drawn to screen, the + /// offset in VRAM will be adjusted according to this. bg_map: bool, + /// If the background tile set is active meaning that the + /// negative based indexes are going to be used. bg_tile: bool, + /// Flag that controls if the LCD screen is ON and displaying + /// content. switch_lcd: bool, /// The current execution mode of the PPU, should change /// between states over the drawing of a frame. @@ -83,6 +92,7 @@ impl Ppu { scx: 0x0, line: 0x0, switch_bg: false, + switch_sprites: false, bg_map: false, bg_tile: false, switch_lcd: false, @@ -147,6 +157,7 @@ impl Ppu { match addr & 0x00ff { 0x0040 => { let value = if self.switch_bg { 0x01 } else { 0x00 } + | if self.switch_sprites { 0x02 } else { 0x00 } | if self.bg_map { 0x08 } else { 0x00 } | if self.bg_tile { 0x10 } else { 0x00 } | if self.switch_lcd { 0x80 } else { 0x00 }; @@ -163,7 +174,8 @@ impl Ppu { match addr & 0x00ff { 0x0040 => { self.switch_bg = value & 0x01 == 0x01; - self.bg_map = value & 0x08 == 0x08; // @todo o buf pode estar aqui + self.switch_sprites = value & 0x02 == 0x02; + self.bg_map = value & 0x08 == 0x08; self.bg_tile = value & 0x10 == 0x10; self.switch_lcd = value & 0x80 == 0x80; } @@ -267,4 +279,15 @@ impl Ppu { } } } + + /// Prints the tile data information to the stdout, this is + /// useful for debugging purposes. + pub fn draw_tile_stdout(&self, tile_index: usize) { + for y in 0..8 { + for x in 0..8 { + print!("{}", self.tiles[tile_index][y as usize][x as usize]); + } + print!("\n"); + } + } }