Skip to content
Snippets Groups Projects
Verified Commit fbecab72 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: support for draw tile to stdout

parent 07f5ff07
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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 => {
......
......@@ -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");
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment