Skip to content

Commit

Permalink
-corrected bug that broke quite a few mappers
Browse files Browse the repository at this point in the history
-corrected bug in cpu and adjusted ppu timings yet again
  • Loading branch information
FIX94 committed Aug 25, 2017
1 parent 584f4fa commit a750001
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
42 changes: 21 additions & 21 deletions cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 1 addition & 1 deletion mapper/p8c8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 19 additions & 5 deletions ppu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,7 +173,9 @@ void ppuInit()
ppuNextHasZSprite = false;
ppuFrameDone = false;
ppuTmpWrite = false;
ppuNMIallowed = false;
ppuNMITriggered = false;
ppuVBlankFlagCleared = false;
ppuCurNMIStat = false;
ppuCurPicOutStat = false;
ppuCurVBlankStat = false;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -893,7 +907,7 @@ uint8_t ppuGet8(uint8_t reg)

bool ppuNMI()
{
if(ppuCurVBlankStat && ppuCurNMIStat)
if(ppuCurNMIStat && ppuNMIallowed)
{
if(ppuNMITriggered == false)
{
Expand Down

0 comments on commit a750001

Please sign in to comment.