fix vrc3 irq handling

This commit is contained in:
zeromus 2012-10-21 03:11:15 +00:00
parent 5f898848e6
commit af36f1f0ad
1 changed files with 74 additions and 19 deletions

View File

@ -20,41 +20,96 @@
#include "mapinc.h"
static uint8 IRQx; //autoenable
static uint8 IRQm; //mode
static uint16 IRQr; //reload
static DECLFW(Mapper73_write)
{
//if(A>=0xd000 && A<=0xdfff)
X6502_IRQEnd(FCEU_IQEXT); /* How are IRQs acknowledged on this chip? */
//printf("$%04x:$%02x\n",A,V);
switch(A&0xF000)
{
//default: printf("$%04x:$%02x\n",A,V);break;
case 0x8000:IRQCount&=0xFFF0;IRQCount|=(V&0xF);break;
case 0x9000:IRQCount&=0xFF0F;IRQCount|=(V&0xF)<<4;break;
case 0xa000:IRQCount&=0xF0FF;IRQCount|=(V&0xF)<<8;break;
case 0xb000:IRQCount&=0x0FFF;IRQCount|=(V&0xF)<<12;break;
case 0xc000:IRQa=V&2;break;
case 0x8000:
IRQr&=0xFFF0;IRQr|=(V&0xF);
break;
case 0x9000:
IRQr&=0xFF0F;IRQr|=(V&0xF)<<4;
break;
case 0xa000:
IRQr&=0xF0FF;IRQr|=(V&0xF)<<8;
break;
case 0xb000:
IRQr&=0x0FFF;IRQr|=(V&0xF)<<12;
break;
case 0xc000:
IRQm=V&4;
IRQx=V&1;
IRQa=V&2;
if(IRQa)
{
if(IRQm)
{
IRQCount&=0xFFFF;
IRQCount|=(IRQr&0xFF);
}
else
{
IRQCount=IRQr;
}
}
X6502_IRQEnd(FCEU_IQEXT);
break;
case 0xd000:
X6502_IRQEnd(FCEU_IQEXT);
IRQa=IRQx;
break;
case 0xf000:ROM_BANK16(0x8000,V);break;
}
}
static void Mapper73IRQHook(int a)
{
if(IRQa)
{
IRQCount+=a;
if(IRQCount>=0xFFFF)
{
IRQCount&=0xFFFF;
IRQa=0;
X6502_IRQBegin(FCEU_IQEXT);
}
}
for(int i=0;i<a;i++)
{
if(!IRQa) return;
if(IRQm)
{
uint16 temp = IRQCount;
temp &= 0xFF;
IRQCount &= 0xFF00;
if (temp == 0xFF)
{
IRQCount = IRQr;
IRQCount |= (uint16)(IRQr & 0xFF);
X6502_IRQBegin(FCEU_IQEXT);
}
else
{
temp++;
IRQCount |= temp;
}
}
else
{
//16 bit mode
if (IRQCount == 0xFFFF)
{
IRQCount = IRQr;
X6502_IRQBegin(FCEU_IQEXT);
}
else
IRQCount++;
}
}
}
void Mapper73_init(void)
{
SetWriteHandler(0x8000,0xffff,Mapper73_write);
MapIRQHook=Mapper73IRQHook;
IRQr = IRQm = IRQx = 0;
}