From a75000177b823fa39acf20cff58fbf6b4ede827f Mon Sep 17 00:00:00 2001 From: FIX94 Date: Sat, 26 Aug 2017 00:43:04 +0200 Subject: [PATCH] -corrected bug that broke quite a few mappers -corrected bug in cpu and adjusted ppu timings yet again --- cpu.c | 42 +++++++++++++++++++++--------------------- main.c | 2 +- mapper/p8c8.c | 2 +- ppu.c | 24 +++++++++++++++++++----- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/cpu.c b/cpu.c index a494d57..df6c803 100644 --- a/cpu.c +++ b/cpu.c @@ -724,6 +724,27 @@ static bool ppu_nmi_handler_req = false; bool mapper_interrupt = false; static bool cpuHandleIrqUpdates() { + //update irq flag if requested + if(p_irq_req) + { + if(p_irq_req == 1) + { + #if DEBUG_INTR + printf("Setting irq disable %02x %02x %d %d %d %d\n", p, P_FLAG_IRQ_DISABLE, cpu_interrupt_req, apu_interrupt, + !(p & P_FLAG_IRQ_DISABLE), (p & P_FLAG_IRQ_DISABLE) == 0); + #endif + p |= P_FLAG_IRQ_DISABLE; + } + else + { + #if DEBUG_INTR + printf("Clearing irq disable %02x %02x %d %d %d %d\n", p, P_FLAG_IRQ_DISABLE, cpu_interrupt_req, apu_interrupt, + !(p & P_FLAG_IRQ_DISABLE), (p & P_FLAG_IRQ_DISABLE) == 0); + #endif + p &= ~P_FLAG_IRQ_DISABLE; + } + p_irq_req = 0; + } //handle incoming IRQs if(reset) { @@ -758,27 +779,6 @@ static bool cpuHandleIrqUpdates() fds_transfer_interrupt = false; return true; } - //update irq flag if requested - if(p_irq_req) - { - if(p_irq_req == 1) - { - #if DEBUG_INTR - printf("Setting irq disable %02x %02x %d %d %d %d\n", p, P_FLAG_IRQ_DISABLE, cpu_interrupt_req, apu_interrupt, - !(p & P_FLAG_IRQ_DISABLE), (p & P_FLAG_IRQ_DISABLE) == 0); - #endif - p |= P_FLAG_IRQ_DISABLE; - } - else - { - #if DEBUG_INTR - printf("Clearing irq disable %02x %02x %d %d %d %d\n", p, P_FLAG_IRQ_DISABLE, cpu_interrupt_req, apu_interrupt, - !(p & P_FLAG_IRQ_DISABLE), (p & P_FLAG_IRQ_DISABLE) == 0); - #endif - p &= ~P_FLAG_IRQ_DISABLE; - } - p_irq_req = 0; - } //acts similar to an irq if(nsf_startPlayback) { diff --git a/main.c b/main.c index d186ca0..7adeaed 100644 --- a/main.c +++ b/main.c @@ -35,7 +35,7 @@ #define DEBUG_KEY 0 #define DEBUG_LOAD_INFO 1 -static const char *VERSION_STRING = "fixNES Alpha v0.9.7"; +static const char *VERSION_STRING = "fixNES Alpha v0.9.8"; static char window_title[256]; static char window_title_pause[256]; diff --git a/mapper/p8c8.c b/mapper/p8c8.c index 1795dbc..5687e38 100644 --- a/mapper/p8c8.c +++ b/mapper/p8c8.c @@ -29,7 +29,7 @@ void p8c8init(uint8_t *prgROMin, uint32_t prgROMsizeIn, { p8c8_prgROM = prgROMin; p8c8_prgROMsize = prgROMsizeIn; - p8c8_prgROMand = mapperGetAndValue(p8c8_prgROMand); + p8c8_prgROMand = mapperGetAndValue(p8c8_prgROMsize); p8c8_prgRAM = prgRAMin; p8c8_prgRAMsize = prgRAMsizeIn; p8c8_chrROM = chrROMin; diff --git a/ppu.c b/ppu.c index 5d383a9..9dcb0cb 100644 --- a/ppu.c +++ b/ppu.c @@ -124,7 +124,9 @@ static bool ppuHasZSprite; static bool ppuNextHasZSprite; static bool ppuFrameDone; static bool ppuTmpWrite; +static bool ppuNMIallowed; static bool ppuNMITriggered; +static bool ppuVBlankFlagCleared; static bool ppuCurNMIStat; static bool ppuCurPicOutStat; static bool ppuCurVBlankStat; @@ -171,7 +173,9 @@ void ppuInit() ppuNextHasZSprite = false; ppuFrameDone = false; ppuTmpWrite = false; + ppuNMIallowed = false; ppuNMITriggered = false; + ppuVBlankFlagCleared = false; ppuCurNMIStat = false; ppuCurPicOutStat = false; ppuCurVBlankStat = false; @@ -616,7 +620,7 @@ bool ppuCycle() ppuSprite0hit--; /* VBlank start at first dot after post-render line */ /* Though results are better when starting it a bit later */ - if(curDot == 4 && curLine == 241) + if(curDot == 3 && curLine == 241) { ppuNMITriggered = false; if(!ppuReadReg2) @@ -625,16 +629,25 @@ bool ppuCycle() printf("PPU Start VBlank\n"); #endif } + if(curDot == 5 && curLine == 241 && ppuCurVBlankStat) + ppuNMIallowed = true; + else if(ppuVBlankFlagCleared) + { + ppuVBlankFlagCleared = false; + ppuNMIallowed = false; + } ppuReadReg2 = false; /* VBlank ends at first dot of the pre-render line */ /* Though results are better when clearing it a bit later */ - if(curDot == 4 && curLine == ppuPreRenderLine) + if(curDot == 3 && curLine == ppuPreRenderLine) { #if PPU_DEBUG_VSYNC printf("PPU End VBlank\n"); #endif PPU_Reg[2] &= ~(PPU_FLAG_VBLANK | PPU_FLAG_SPRITEZERO | PPU_FLAG_OVERFLOW); } + if(curDot == 8 && curLine == ppuPreRenderLine) + ppuNMIallowed = false; /* Wrap back down after pre-render line */ if(curLine == ppuLinesTotal) { @@ -696,7 +709,7 @@ static uint8_t ppuDoSprites(uint8_t color, uint8_t dot) sprCol |= 2; if(i == 0 && ppuHasZSprite && dot < 255 && ((color&3) != 0) && (sprCol != 0) && !(PPU_Reg[2] & PPU_FLAG_SPRITEZERO) && !ppuSprite0hit) { - ppuSprite0hit = 5; + ppuSprite0hit = 1; #if PPU_DEBUG_ULTRA printf("Zero sprite hit at x %i y %i cSpriteDot %i " "table %04x color %02x sprCol %02x\n", dot, curLine, cSpriteDot, ppuGetVramTbl((PPU_Reg[0]&3)<<10), color, sprCol); @@ -832,7 +845,7 @@ void ppuSet8(uint8_t reg, uint8_t val) else if(reg != 2) { PPU_Reg[reg] = val; - //printf("ppuSet8 %04x %02x\n", reg, val); + //printf("ppuSet8 odd %d curDot %i curLine %i %04x %02x\n", ppuOddFrame, curDot, curLine, reg, val); } } @@ -843,6 +856,7 @@ uint8_t ppuGet8(uint8_t reg) { ret = PPU_Reg[reg]; PPU_Reg[reg] &= ~PPU_FLAG_VBLANK; + ppuVBlankFlagCleared = true; ppuTmpWrite = false; ppuReadReg2 = true; } @@ -893,7 +907,7 @@ uint8_t ppuGet8(uint8_t reg) bool ppuNMI() { - if(ppuCurVBlankStat && ppuCurNMIStat) + if(ppuCurNMIStat && ppuNMIallowed) { if(ppuNMITriggered == false) {