cleanup bios Diff functions a little bit and fix some errors

This commit is contained in:
zeromus 2013-08-10 17:25:12 +00:00
parent d9fd89c4f8
commit b64746f7a4
1 changed files with 141 additions and 129 deletions

View File

@ -1,6 +1,6 @@
/*
Copyright (C) 2006 yopyop
Copyright (C) 2008-2012 DeSmuME team
Copyright (C) 2008-2013 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -25,6 +25,17 @@
#define cpu (&ARMPROC)
#define TEMPLATE template<int PROCNUM>
struct CompressionHeader
{
public:
CompressionHeader(u32 _value) : value(_value) {}
u32 DataSize() const { return value&15; }
u32 Type() const { return (value>>4)&15; }
u32 DecompressedSize() const { return value>>24; }
private:
u32 value;
};
static const u16 getsinetbl[] = {
0x0000, 0x0324, 0x0648, 0x096A, 0x0C8C, 0x0FAB, 0x12C8, 0x15E2,
0x18F9, 0x1C0B, 0x1F1A, 0x2223, 0x2528, 0x2826, 0x2B1F, 0x2E11,
@ -890,32 +901,34 @@ TEMPLATE static u32 BitUnPack()
return 1;
}
TEMPLATE static u32 Diff8bitUnFilterWram()
TEMPLATE static u32 Diff8bitUnFilterWram() //this one might be different on arm7 and needs checking
{
u32 source,dest,header;
u8 data,diff;
int len;
source = cpu->R[0];
dest = cpu->R[1];
header = _MMU_read08<PROCNUM>(source);
source += 4;
//INFO("swi diff8bitunfilterwram\n");
if(((source & 0xe000000) == 0) ||
(( (source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0))
u32 source = cpu->R[0];
u32 dest = cpu->R[1];
CompressionHeader header(_MMU_read32<PROCNUM>(source));
source += 4;
if(header.DataSize() != 1) printf("WARNING: incorrect header passed to Diff8bitUnFilterWram\n");
if(header.Type() != 8) printf("WARNING: incorrect header passed to Diff8bitUnFilterWram\n");
u32 len = header.DecompressedSize();
if(PROCNUM == ARMCPU_ARM7)
{
//can someone double check whether arm7 actually does this? arm9 definitely doesnt)
if(((source & 0x0E000000) == 0) ||
(( (source + (len & 0x001fffff)) & 0x0E000000) == 0))
return 0;
}
len = header >> 8;
data = _MMU_read08<PROCNUM>(source++);
u8 data = _MMU_read08<PROCNUM>(source++);
_MMU_write08<PROCNUM>(dest++, data);
len--;
while(len > 0) {
diff = _MMU_read08<PROCNUM>(source++);
u8 diff = _MMU_read08<PROCNUM>(source++);
data += diff;
_MMU_write08<PROCNUM>(dest++, data);
len--;
@ -925,25 +938,21 @@ TEMPLATE static u32 Diff8bitUnFilterWram()
TEMPLATE static u32 Diff16bitUnFilter()
{
u32 source,dest,header;
u16 data;
int len;
//INFO("swi diff8bitunfilterwram\n");
source = cpu->R[0];
dest = cpu->R[1];
u32 source = cpu->R[0];
u32 dest = cpu->R[1];
//INFO("swi diff16bitunfilter\n");
header = _MMU_read08<PROCNUM>(source);
CompressionHeader header(_MMU_read32<PROCNUM>(source));
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return 0;
if(header.DataSize() != 2) printf("WARNING: incorrect header passed to Diff16bitUnFilter\n");
if(header.Type() != 8) printf("WARNING: incorrect header passed to Diff16bitUnFilter\n");
u32 len = header.DecompressedSize();
len = header >> 8;
//no arm7 version, so no range checks
data = _MMU_read16<PROCNUM>(source);
u16 data = _MMU_read16<PROCNUM>(source);
source += 2;
_MMU_write16<PROCNUM>(dest, data);
dest += 2;
@ -972,6 +981,7 @@ TEMPLATE static u32 setHaltCR()
return 1;
}
//ARM7 only
TEMPLATE static u32 getSineTab()
{
//ds returns garbage according to gbatek, but we must protect ourselves
@ -986,6 +996,7 @@ TEMPLATE static u32 getSineTab()
return 1;
}
//ARM7 only
TEMPLATE static u32 getPitchTab()
{
//ds returns garbage according to gbatek, but we must protect ourselves
@ -999,6 +1010,7 @@ TEMPLATE static u32 getPitchTab()
return 1;
}
//ARM7 only
TEMPLATE static u32 getVolumeTab()
{
//ds returns garbage according to gbatek, but we must protect ourselves
@ -1007,14 +1019,12 @@ TEMPLATE static u32 getVolumeTab()
printf("Invalid SWI getVolumeTab: %08X\n",cpu->R[0]);
return 1;
}
cpu->R[0] = getvoltbl[cpu->R[0]];
return 1;
}
//TEMPLATE static u32 getCRC16_old(u32 crc, u32 datap, u32 size)
//TEMPLATE static u32 getCRC16_old_and_broken(u32 crc, u32 datap, u32 size)
//{
// unsigned int i,j;
//
@ -1041,7 +1051,8 @@ TEMPLATE static u32 getVolumeTab()
TEMPLATE static u32 getCRC16()
{
//gbatek is wrong.
//gbatek is wrong.. for ARM9, at least.
//someone should check how the ARM7 version works.
//dawn of sorrow uses this to checksum its save data;
//if this implementation is wrong, then it won't match what the real bios returns,
@ -1098,6 +1109,7 @@ TEMPLATE static u32 SoundBias()
return cpu->R[1] * delay;
}
//ARM7 only
TEMPLATE static u32 getBootProcs()
{
cpu->R[0] = 0x00000A2E;