[bios] Fix lz77 and add BIOS_SndDriverVsyncOn
The lz77 uncompresssion software BIOS implementation was exiting early when uncompressing data, if the overall length was larger than advertised in the function parameter. However, real GBA BIOS does read further than the advertised length, so we do here too. This fixes Advance Wars title screen. This also adds a SoundDriverVSyncOn implementation, silencing an error for some Shrek games, though they still cannot properly boot with an emulated BIOS. Fixes #789
This commit is contained in:
parent
4c8b54de89
commit
e26f807355
|
@ -2083,8 +2083,8 @@ void CPUSoftwareInterrupt(int comment)
|
|||
case 0x02:
|
||||
#ifdef GBA_LOGGING
|
||||
if (systemVerbose & VERBOSE_SWI) {
|
||||
/*log("Halt: (VCOUNT = %2d)\n",
|
||||
VCOUNT);*/
|
||||
log("Halt: (VCOUNT = %2d)\n",
|
||||
VCOUNT);
|
||||
}
|
||||
#endif
|
||||
holdState = true;
|
||||
|
@ -2094,8 +2094,8 @@ void CPUSoftwareInterrupt(int comment)
|
|||
case 0x03:
|
||||
#ifdef GBA_LOGGING
|
||||
if (systemVerbose & VERBOSE_SWI) {
|
||||
/*log("Stop: (VCOUNT = %2d)\n",
|
||||
VCOUNT);*/
|
||||
log("Stop: (VCOUNT = %2d)\n",
|
||||
VCOUNT);
|
||||
}
|
||||
#endif
|
||||
holdState = true;
|
||||
|
@ -2271,11 +2271,14 @@ void CPUSoftwareInterrupt(int comment)
|
|||
case 0x1E:
|
||||
BIOS_SndChannelClear();
|
||||
break;
|
||||
case 0x1F:
|
||||
BIOS_MidiKey2Freq();
|
||||
break;
|
||||
case 0x28:
|
||||
BIOS_SndDriverVSyncOff();
|
||||
break;
|
||||
case 0x1F:
|
||||
BIOS_MidiKey2Freq();
|
||||
case 0x29:
|
||||
BIOS_SndDriverVSyncOn();
|
||||
break;
|
||||
case 0xE0:
|
||||
case 0xE1:
|
||||
|
|
|
@ -688,7 +688,6 @@ void BIOS_LZ77UnCompVram()
|
|||
while (len > 0) {
|
||||
uint8_t d = CPUReadByte(source++);
|
||||
|
||||
if (d) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (d & 0x80) {
|
||||
uint16_t data = CPUReadByte(source++) << 8;
|
||||
|
@ -709,8 +708,6 @@ void BIOS_LZ77UnCompVram()
|
|||
writeValue = 0;
|
||||
}
|
||||
len--;
|
||||
if (len == 0)
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
writeValue |= (CPUReadByte(source++) << byteShift);
|
||||
|
@ -724,29 +721,21 @@ void BIOS_LZ77UnCompVram()
|
|||
writeValue = 0;
|
||||
}
|
||||
len--;
|
||||
if (len == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
d <<= 1;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
writeValue |= (CPUReadByte(source++) << byteShift);
|
||||
byteShift += 8;
|
||||
byteCount++;
|
||||
if (byteCount == 2) {
|
||||
CPUWriteHalfWord(dest, DowncastU16(writeValue));
|
||||
dest += 2;
|
||||
byteShift = 0;
|
||||
byteCount = 0;
|
||||
writeValue = 0;
|
||||
}
|
||||
len--;
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
if (len <= 0) {
|
||||
// This can happen if the parameter was incorrectly set. Real
|
||||
// hardware does a buffer overflow so we do it here too.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reg[0].I = source;
|
||||
reg[1].I = dest;
|
||||
reg[3].I = 0;
|
||||
}
|
||||
|
||||
void BIOS_LZ77UnCompWram()
|
||||
|
@ -772,7 +761,6 @@ void BIOS_LZ77UnCompWram()
|
|||
while (len > 0) {
|
||||
uint8_t d = CPUReadByte(source++);
|
||||
|
||||
if (d) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (d & 0x80) {
|
||||
uint16_t data = CPUReadByte(source++) << 8;
|
||||
|
@ -783,26 +771,25 @@ void BIOS_LZ77UnCompWram()
|
|||
for (int i2 = 0; i2 < length; i2++) {
|
||||
CPUWriteByte(dest++, CPUReadByte(windowOffset++));
|
||||
len--;
|
||||
if (len == 0)
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
CPUWriteByte(dest++, CPUReadByte(source++));
|
||||
len--;
|
||||
if (len == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
d <<= 1;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
CPUWriteByte(dest++, CPUReadByte(source++));
|
||||
len--;
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
if (len <= 0) {
|
||||
// This can happen if the parameter was incorrectly set. Real
|
||||
// hardware does a buffer overflow so we do it here too.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reg[0].I = source;
|
||||
reg[1].I = dest;
|
||||
reg[3].I = 0;
|
||||
}
|
||||
|
||||
void BIOS_ObjAffineSet()
|
||||
|
@ -1695,6 +1682,13 @@ void BIOS_SndDriverVSync()
|
|||
|
||||
void BIOS_SndDriverVSyncOff() // 0x1878
|
||||
{
|
||||
#ifdef GBA_LOGGING
|
||||
if (systemVerbose & VERBOSE_SWI) {
|
||||
log("SndDriverVSyncOff: (VCOUNT = %2d)\n",
|
||||
VCOUNT);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t const puser1 = CPUReadMemory(0x3007FF0); // 7FC0 + 0x30
|
||||
uint32_t user1 = CPUReadMemory(puser1);
|
||||
|
||||
|
@ -1718,6 +1712,20 @@ void BIOS_SndDriverVSyncOff() // 0x1878
|
|||
//0x18b0
|
||||
}
|
||||
|
||||
void BIOS_SndDriverVSyncOn()
|
||||
{
|
||||
#ifdef GBA_LOGGING
|
||||
if (systemVerbose & VERBOSE_SWI) {
|
||||
log("SndDriverVSyncOn: (VCOUNT = %2d)\n",
|
||||
VCOUNT);
|
||||
}
|
||||
#endif
|
||||
|
||||
const uint16_t r1 = 0x8600; // 91 << 9
|
||||
CPUWriteHalfWord(base1 + 0x6, r1);
|
||||
CPUWriteHalfWord(base1 + 0x12, r1);
|
||||
}
|
||||
|
||||
// This functions is verified but lacks proper register settings before calling user func
|
||||
// it might be that user func modifies or uses those?
|
||||
// r7 should be puser1, r6 should be flags, ....
|
||||
|
|
|
@ -30,6 +30,7 @@ extern void BIOS_SndDriverMode();
|
|||
extern void BIOS_SndDriverMain();
|
||||
extern void BIOS_SndDriverVSync();
|
||||
extern void BIOS_SndDriverVSyncOff();
|
||||
extern void BIOS_SndDriverVSyncOn();
|
||||
extern void BIOS_SndChannelClear();
|
||||
|
||||
#endif // BIOS_H
|
||||
|
|
Loading…
Reference in New Issue