- [FIX] Les interrupcions comencen mirant IE & IF, i després IME. Estava al reves.

- [FIX] En cada interrupció se marcava el exit_from_halt, i sino estaves en halt, el pròxim halt no tenía efecte.
- [FIX] Implementat el halt bug quan va despres de EI
- [FIX] una demanda de interrupció ha de quedar marcada en IF, encara que en IE no estiga habilitada.
- [FIX] durant el pintat se marquen les interrupcions que toque, i al final es quan s'envia tot junt.
- [FIX] estava enviant una interrupcio VBLANK al acabar el pintat total, com en spectrum, adicional a la que toca, i tot anava loco.
- [FIX] Llevats tots els fullrefresh, no funciona be en GameBoy
This commit is contained in:
2025-01-27 22:09:02 +01:00
parent 44f4f1a85b
commit 974251540d
3 changed files with 44 additions and 22 deletions

View File

@@ -46,6 +46,7 @@ namespace sm83
uint8_t *_rIME = &regs[12];
bool halted = false;
bool exit_from_halt = false;
int pending_ei = 0;
@@ -521,12 +522,18 @@ namespace sm83
void processInterrupts()
{
uint8_t *IE = mem::rawPtr(0xffff);
uint8_t *IF = mem::rawPtr(0xff0f);
if ( (*IF & *IE) == 0 ) return;
if (halted) {
//exit_from_halt = true;
halted = false;
rPC++;
}
if (ime==0) return;
if ( (*IF & 0x1f) == 0) return;
DI();
PUSH(rPC);
t+=20;
//t+=20;
if (*IF & INTERRUPT_VBLANK) {
rPC = 0x40;
*IF = *IF & ~INTERRUPT_VBLANK;
@@ -584,12 +591,24 @@ namespace sm83
void HALT()
{
if (exit_from_halt) {
if (!halted) {
uint8_t *IE = mem::rawPtr(0xffff);
uint8_t *IF = mem::rawPtr(0xff0f);
if ( (ime==0) && ((*IF & *IE) != 0) ) {
// [TODO] HALT BUG
if (pending_ei==2) rPC--;
return;
} else {
halted = true;
}
}
/*if (exit_from_halt) {
exit_from_halt = false;
} else {
halted = false;
} else {*/
//printf("HALT\n");
rPC--;
}
//}
}
void STOP()
@@ -600,9 +619,9 @@ namespace sm83
void interrupt(uint8_t type)
{
const uint8_t IE = mem::readMem(0xffff);
if (IE & type) exit_from_halt = true;
//if (IE & type) exit_from_halt = true;
const uint8_t IF = mem::readMem(0xff0f);
mem::writeMem(0xff0f, IF | (IE & type));
mem::writeMem(0xff0f, IF | type);
//processInterrupts();
}