From 10972c4890bdd9075d0e9f1219705290e296edbe Mon Sep 17 00:00:00 2001 From: Dozingfiretruck <1473454180@qq.com> Date: Mon, 29 Jul 2024 22:34:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E9=95=9C=E5=83=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/nes_ppu.h | 1 + src/nes.c | 6 +++--- src/nes_ppu.c | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/inc/nes_ppu.h b/inc/nes_ppu.h index a9cc16c..d028f63 100644 --- a/inc/nes_ppu.h +++ b/inc/nes_ppu.h @@ -120,6 +120,7 @@ typedef struct nes_ppu{ struct { uint8_t* pattern_table[8]; uint8_t* name_table[4]; + uint8_t* name_table_mirrors[4]; }; uint8_t* chr_banks[16]; /* 16k chr_banks,without background_palette and sprite_palette 0 - 3 pattern_table_0 4k diff --git a/src/nes.c b/src/nes.c index b79b796..f56749f 100644 --- a/src/nes.c +++ b/src/nes.c @@ -103,7 +103,7 @@ static void nes_render_background_line(nes_t* nes,uint16_t scanline,nes_color_t* } m = 7; } - nametable_id ^= nes->nes_rom.mirroring_type ? 1:2; + nametable_id ^= 1; for (uint8_t tile_x = 0; tile_x <= dx; tile_x++){ const uint8_t pattern_id = nes->nes_ppu.name_table[nametable_id][tile_x + (tile_y << 5)]; const uint8_t* bit0_p = nes->nes_ppu.pattern_table[nes->nes_ppu.CTRL_B ? 4 : 0] + pattern_id * 16; @@ -251,8 +251,8 @@ static void nes_render_sprite_line(nes_t* nes,uint16_t scanline,nes_color_t* dra void nes_run(nes_t* nes){ nes_printf("mapper:%03d\n",nes->nes_rom.mapper_number); - nes_printf("prg_rom_size:%d*16kb\n",nes->nes_rom.prg_rom_size); - nes_printf("chr_rom_size:%d*8kb\n",nes->nes_rom.chr_rom_size); + nes_printf("prg_rom_size:%d*16kB\n",nes->nes_rom.prg_rom_size); + nes_printf("chr_rom_size:%d*8kB\n",nes->nes_rom.chr_rom_size); nes_printf("mirroring_type:%d\n",nes->nes_rom.mirroring_type); nes_printf("four_screen:%d\n",nes->nes_rom.four_screen); // nes_printf("save_ram:%d\n",nes->nes_rom.save_ram); diff --git a/src/nes_ppu.c b/src/nes_ppu.c index b769d92..9cfa5b2 100644 --- a/src/nes_ppu.c +++ b/src/nes_ppu.c @@ -27,7 +27,7 @@ static inline uint8_t nes_read_ppu_memory(nes_t* nes){ const uint16_t address = nes->nes_ppu.v_reg & (uint16_t)0x3FFF; - const uint16_t index = address >> 10; + const uint8_t index = address >> 10; const uint16_t offset = address & (uint16_t)0x3FF; if (address < (uint16_t)0x3F00) {// BANK uint8_t data = nes->nes_ppu.buffer; @@ -162,9 +162,9 @@ void nes_ppu_init(nes_t *nes){ nes->nes_ppu.name_table[3] = nes->nes_ppu.ppu_vram1; } // mirrors - nes->nes_ppu.chr_banks[12] = nes->nes_ppu.name_table[0]; - nes->nes_ppu.chr_banks[13] = nes->nes_ppu.name_table[1]; - nes->nes_ppu.chr_banks[14] = nes->nes_ppu.name_table[2]; - nes->nes_ppu.chr_banks[15] = nes->nes_ppu.name_table[3]; + nes->nes_ppu.name_table_mirrors[0] = nes->nes_ppu.name_table[0]; + nes->nes_ppu.name_table_mirrors[1] = nes->nes_ppu.name_table[1]; + nes->nes_ppu.name_table_mirrors[2] = nes->nes_ppu.name_table[2]; + nes->nes_ppu.name_table_mirrors[3] = nes->nes_ppu.name_table[3]; }