bugzmanov / nes_ebook

A mini book on writing NES emulator using rust lang
https://bugzmanov.github.io/nes_ebook/index.html
385 stars 68 forks source link

Typo in chapter 6.4? #21

Closed pherrymason closed 1 year ago

pherrymason commented 2 years ago

Isn't upper and lower flipped in the render function?

pub fn render(ppu: &NesPPU, frame: &mut Frame) {
   let bank = ppu.ctrl.bknd_pattern_addr();

   for i in 0..0x03c0 { // just for now, lets use the first nametable
       let tile = ppu.vram[i] as u16;
       let tile_x = i % 32;
       let tile_y = i / 32;
       let tile = &ppu.chr_rom[(bank + tile * 16) as usize..=(bank + tile * 16 + 15) as usize];

       for y in 0..=7 {
           let mut upper = tile[y];           //<--- Shouldn't this be lower?
           let mut lower = tile[y + 8];     //<---  Shouldn't this be upper?

I did the same in my emulator, and had wrong colors because bits from upper and lower end up in the wrong positions.