Skip to content

Commit

Permalink
allow late timer interrupts
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfloogle committed Jan 9, 2024
1 parent e92cbbd commit 32eb2c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/v810_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void v810_exit();
void v810_reset();

// Generate Interupt #n
void v810_int(WORD iNum, WORD PC);
bool v810_int(WORD iNum, WORD PC);

// Generate Exception #n
void v810_exp(WORD iNum, WORD eCode);
Expand Down
24 changes: 14 additions & 10 deletions source/common/v810_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,17 @@ int serviceInt(unsigned int cycles, WORD PC) {
if (tHReg.tCount <= 0) {
tHReg.tCount += tHReg.tTHW; //reset counter
tHReg.TCR |= 0x02; //Zero Status
if (tHReg.TCR & 0x08) {
v810_int(1, PC);
return 1;
}
}
tHReg.TLB = (tHReg.tCount&0xFF);
tHReg.THB = ((tHReg.tCount>>8)&0xFF);
}
if ((tHReg.TCR & 0x02) && (tHReg.TCR & 0x08)) {
// zero & interrupt enabled
return v810_int(1, PC);
}
} else {
// don't get too overzealous if we turn it off and on again
lasttime = cycles;
}

return 0;
Expand Down Expand Up @@ -332,12 +335,12 @@ int serviceDisplayInt(unsigned int cycles, WORD PC) {
}

// Generate Interupt #n
void v810_int(WORD iNum, WORD PC) {
if (iNum > 0x0F) return; // Invalid Interupt number...
if((v810_state->S_REG[PSW] & PSW_NP)) return;
if((v810_state->S_REG[PSW] & PSW_EP)) return; // Exception pending?
if((v810_state->S_REG[PSW] & PSW_ID)) return; // Interupt disabled
if(iNum < ((v810_state->S_REG[PSW] & PSW_IA)>>16)) return; // Interupt to low on the chain
bool v810_int(WORD iNum, WORD PC) {
if (iNum > 0x0F) return false; // Invalid Interupt number...
if((v810_state->S_REG[PSW] & PSW_NP)) return false;
if((v810_state->S_REG[PSW] & PSW_EP)) return false; // Exception pending?
if((v810_state->S_REG[PSW] & PSW_ID)) return false; // Interupt disabled
if(iNum < ((v810_state->S_REG[PSW] & PSW_IA)>>16)) return false; // Interupt to low on the chain

dprintf(1, "[INT]: iNum=0x%lx\n", iNum);

Expand All @@ -354,6 +357,7 @@ void v810_int(WORD iNum, WORD PC) {
if((iNum+=1) > 0x0F)
(iNum = 0x0F);
v810_state->S_REG[PSW] = v810_state->S_REG[PSW] | (iNum << 16); //Set the Interupt
return true;
}

// Generate exception #n
Expand Down
2 changes: 1 addition & 1 deletion source/common/v810_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ void hcreg_wbyte(WORD addr, BYTE data) {
}

tHReg.TCR = (((data|0xE4)&0xFD)|(tHReg.TCR&0x02));
if ((data & 0x04) && (!(tHReg.TCR & 0x01))) { //cannot clear ZStat if timer is enabled...
if ((data & 0x05) == 0x04 || !(data & 0x08)) {
tHReg.TCR &= 0xFD; // Clear the ZStat Flag...
}
break;
Expand Down

0 comments on commit 32eb2c8

Please sign in to comment.