* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).
* [2SF] Used more up-to-date asmjit, despite the ugly looking code.
| ... | ... |
@@ -4,6 +4,7 @@ |
| 4 | 4 |
#include "bios.h" |
| 5 | 5 |
#include "GBAinline.h" |
| 6 | 6 |
#include "Globals.h" |
| 7 |
+#include "XSFCommon.h" |
|
| 7 | 8 |
|
| 8 | 9 |
int32_t sineTable[] = |
| 9 | 10 |
{
|
| ... | ... |
@@ -64,7 +65,7 @@ void BIOS_ArcTan2() |
| 64 | 65 |
res = (x >> 16) & 0x8000; |
| 65 | 66 |
else if (!x) |
| 66 | 67 |
res = ((y >> 16) & 0x8000) + 0x4000; |
| 67 |
- else if (std::abs(x) > std::abs(y) || (std::abs(x) == std::abs(y) && !(x < 0 && y < 0))) |
|
| 68 |
+ else if (std::abs(x) > std::abs(y) || (fEqual(std::abs(x), std::abs(y)) && !(x < 0 && y < 0))) |
|
| 68 | 69 |
{
|
| 69 | 70 |
reg[1].I = x; |
| 70 | 71 |
reg[0].I = y << 14; |
| ... | ... |
@@ -62,31 +62,25 @@ void BIOS_ArcTan2() |
| 62 | 62 |
uint32_t res = 0; |
| 63 | 63 |
if (!y) |
| 64 | 64 |
res = (x >> 16) & 0x8000; |
| 65 |
- else |
|
| 65 |
+ else if (!x) |
|
| 66 |
+ res = ((y >> 16) & 0x8000) + 0x4000; |
|
| 67 |
+ else if (std::abs(x) > std::abs(y) || (std::abs(x) == std::abs(y) && !(x < 0 && y < 0))) |
|
| 66 | 68 |
{
|
| 67 |
- if (!x) |
|
| 68 |
- res = ((y >> 16) & 0x8000) + 0x4000; |
|
| 69 |
+ reg[1].I = x; |
|
| 70 |
+ reg[0].I = y << 14; |
|
| 71 |
+ BIOS_Div(); |
|
| 72 |
+ BIOS_ArcTan(); |
|
| 73 |
+ if (x < 0) |
|
| 74 |
+ res = 0x8000 + reg[0].I; |
|
| 69 | 75 |
else |
| 70 |
- {
|
|
| 71 |
- if (std::abs(x) > std::abs(y) || (std::abs(x) == std::abs(y) && !(x < 0 && y < 0))) |
|
| 72 |
- {
|
|
| 73 |
- reg[1].I = x; |
|
| 74 |
- reg[0].I = y << 14; |
|
| 75 |
- BIOS_Div(); |
|
| 76 |
- BIOS_ArcTan(); |
|
| 77 |
- if (x < 0) |
|
| 78 |
- res = 0x8000 + reg[0].I; |
|
| 79 |
- else |
|
| 80 |
- res = (((y >> 16) & 0x8000) << 1) + reg[0].I; |
|
| 81 |
- } |
|
| 82 |
- else |
|
| 83 |
- {
|
|
| 84 |
- reg[0].I = x << 14; |
|
| 85 |
- BIOS_Div(); |
|
| 86 |
- BIOS_ArcTan(); |
|
| 87 |
- res = (0x4000 + ((y >> 16) & 0x8000)) - reg[0].I; |
|
| 88 |
- } |
|
| 89 |
- } |
|
| 76 |
+ res = (((y >> 16) & 0x8000) << 1) + reg[0].I; |
|
| 77 |
+ } |
|
| 78 |
+ else |
|
| 79 |
+ {
|
|
| 80 |
+ reg[0].I = x << 14; |
|
| 81 |
+ BIOS_Div(); |
|
| 82 |
+ BIOS_ArcTan(); |
|
| 83 |
+ res = (0x4000 + ((y >> 16) & 0x8000)) - reg[0].I; |
|
| 90 | 84 |
} |
| 91 | 85 |
reg[0].I = res; |
| 92 | 86 |
} |
| ... | ... |
@@ -118,8 +112,7 @@ void BIOS_BitUnPack() |
| 118 | 112 |
if (len < 0) |
| 119 | 113 |
break; |
| 120 | 114 |
int mask = 0xff >> revbits; |
| 121 |
- uint8_t b = CPUReadByte(source); |
|
| 122 |
- ++source; |
|
| 115 |
+ uint8_t b = CPUReadByte(source++); |
|
| 123 | 116 |
int bitcount = 0; |
| 124 | 117 |
while (1) |
| 125 | 118 |
{
|
| ... | ... |
@@ -629,6 +622,7 @@ void BIOS_LZ77UnCompVram() |
| 629 | 622 |
writeValue |= CPUReadByte(source++) << byteShift; |
| 630 | 623 |
byteShift += 8; |
| 631 | 624 |
++byteCount; |
| 625 |
+ |
|
| 632 | 626 |
if (byteCount == 2) |
| 633 | 627 |
{
|
| 634 | 628 |
CPUWriteHalfWord(dest, writeValue); |
| ... | ... |
@@ -990,7 +984,7 @@ void BIOS_Sqrt() |
| 990 | 984 |
void BIOS_MidiKey2Freq() |
| 991 | 985 |
{
|
| 992 | 986 |
int freq = CPUReadMemory(reg[0].I + 4); |
| 993 |
- double tmp = (180 - reg[1].I) - (reg[2].I / 256.0); |
|
| 987 |
+ double tmp = (180.0 - reg[1].I) - (reg[2].I / 256.0); |
|
| 994 | 988 |
tmp = std::pow(2.0, tmp / 12.0); |
| 995 | 989 |
reg[0].I = static_cast<int>(freq / tmp); |
| 996 | 990 |
} |
| ... | ... |
@@ -104,7 +104,7 @@ void BIOS_BitUnPack() |
| 104 | 104 |
|
| 105 | 105 |
int bits = CPUReadByte(header + 2); |
| 106 | 106 |
int revbits = 8 - bits; |
| 107 |
- // u32 value = 0; |
|
| 107 |
+ //uint32_t value = 0; |
|
| 108 | 108 |
uint32_t base = CPUReadMemory(header + 4); |
| 109 | 109 |
bool addBase = !!(base & 0x80000000); |
| 110 | 110 |
base &= 0x7fffffff; |
| ... | ... |
@@ -346,7 +346,7 @@ void BIOS_Diff8bitUnFilterVram() |
| 346 | 346 |
uint32_t header = CPUReadMemory(source); |
| 347 | 347 |
source += 4; |
| 348 | 348 |
|
| 349 |
- if (!(source & 0xe000000) | !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 349 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 350 | 350 |
return; |
| 351 | 351 |
|
| 352 | 352 |
int len = header >> 8; |
| ... | ... |
@@ -416,7 +416,7 @@ void BIOS_Div() |
| 416 | 416 |
reg[1].I = number % denom; |
| 417 | 417 |
int32_t temp = static_cast<int32_t>(reg[0].I); |
| 418 | 418 |
reg[3].I = static_cast<uint32_t>(temp < 0 ? -temp : temp); |
| 419 |
- } |
|
| 419 |
+ } |
|
| 420 | 420 |
} |
| 421 | 421 |
|
| 422 | 422 |
void BIOS_HuffUnComp() |
(As an aside, blargg's code style makes me go blarg myself.)
| ... | ... |
@@ -1,1147 +1,1005 @@ |
| 1 |
-#include <math.h> |
|
| 2 |
-#include <memory.h> |
|
| 3 |
-#include <stdlib.h> |
|
| 4 |
- |
|
| 1 |
+#include <cmath> |
|
| 2 |
+#include <cstring> |
|
| 5 | 3 |
#include "GBA.h" |
| 6 | 4 |
#include "bios.h" |
| 7 | 5 |
#include "GBAinline.h" |
| 8 | 6 |
#include "Globals.h" |
| 9 | 7 |
|
| 10 |
-int16_t sineTable[256] = {
|
|
| 11 |
- (int16_t)0x0000, (int16_t)0x0192, (int16_t)0x0323, (int16_t)0x04B5, (int16_t)0x0645, (int16_t)0x07D5, (int16_t)0x0964, (int16_t)0x0AF1, |
|
| 12 |
- (int16_t)0x0C7C, (int16_t)0x0E05, (int16_t)0x0F8C, (int16_t)0x1111, (int16_t)0x1294, (int16_t)0x1413, (int16_t)0x158F, (int16_t)0x1708, |
|
| 13 |
- (int16_t)0x187D, (int16_t)0x19EF, (int16_t)0x1B5D, (int16_t)0x1CC6, (int16_t)0x1E2B, (int16_t)0x1F8B, (int16_t)0x20E7, (int16_t)0x223D, |
|
| 14 |
- (int16_t)0x238E, (int16_t)0x24DA, (int16_t)0x261F, (int16_t)0x275F, (int16_t)0x2899, (int16_t)0x29CD, (int16_t)0x2AFA, (int16_t)0x2C21, |
|
| 15 |
- (int16_t)0x2D41, (int16_t)0x2E5A, (int16_t)0x2F6B, (int16_t)0x3076, (int16_t)0x3179, (int16_t)0x3274, (int16_t)0x3367, (int16_t)0x3453, |
|
| 16 |
- (int16_t)0x3536, (int16_t)0x3612, (int16_t)0x36E5, (int16_t)0x37AF, (int16_t)0x3871, (int16_t)0x392A, (int16_t)0x39DA, (int16_t)0x3A82, |
|
| 17 |
- (int16_t)0x3B20, (int16_t)0x3BB6, (int16_t)0x3C42, (int16_t)0x3CC5, (int16_t)0x3D3E, (int16_t)0x3DAE, (int16_t)0x3E14, (int16_t)0x3E71, |
|
| 18 |
- (int16_t)0x3EC5, (int16_t)0x3F0E, (int16_t)0x3F4E, (int16_t)0x3F84, (int16_t)0x3FB1, (int16_t)0x3FD3, (int16_t)0x3FEC, (int16_t)0x3FFB, |
|
| 19 |
- (int16_t)0x4000, (int16_t)0x3FFB, (int16_t)0x3FEC, (int16_t)0x3FD3, (int16_t)0x3FB1, (int16_t)0x3F84, (int16_t)0x3F4E, (int16_t)0x3F0E, |
|
| 20 |
- (int16_t)0x3EC5, (int16_t)0x3E71, (int16_t)0x3E14, (int16_t)0x3DAE, (int16_t)0x3D3E, (int16_t)0x3CC5, (int16_t)0x3C42, (int16_t)0x3BB6, |
|
| 21 |
- (int16_t)0x3B20, (int16_t)0x3A82, (int16_t)0x39DA, (int16_t)0x392A, (int16_t)0x3871, (int16_t)0x37AF, (int16_t)0x36E5, (int16_t)0x3612, |
|
| 22 |
- (int16_t)0x3536, (int16_t)0x3453, (int16_t)0x3367, (int16_t)0x3274, (int16_t)0x3179, (int16_t)0x3076, (int16_t)0x2F6B, (int16_t)0x2E5A, |
|
| 23 |
- (int16_t)0x2D41, (int16_t)0x2C21, (int16_t)0x2AFA, (int16_t)0x29CD, (int16_t)0x2899, (int16_t)0x275F, (int16_t)0x261F, (int16_t)0x24DA, |
|
| 24 |
- (int16_t)0x238E, (int16_t)0x223D, (int16_t)0x20E7, (int16_t)0x1F8B, (int16_t)0x1E2B, (int16_t)0x1CC6, (int16_t)0x1B5D, (int16_t)0x19EF, |
|
| 25 |
- (int16_t)0x187D, (int16_t)0x1708, (int16_t)0x158F, (int16_t)0x1413, (int16_t)0x1294, (int16_t)0x1111, (int16_t)0x0F8C, (int16_t)0x0E05, |
|
| 26 |
- (int16_t)0x0C7C, (int16_t)0x0AF1, (int16_t)0x0964, (int16_t)0x07D5, (int16_t)0x0645, (int16_t)0x04B5, (int16_t)0x0323, (int16_t)0x0192, |
|
| 27 |
- (int16_t)0x0000, (int16_t)0xFE6E, (int16_t)0xFCDD, (int16_t)0xFB4B, (int16_t)0xF9BB, (int16_t)0xF82B, (int16_t)0xF69C, (int16_t)0xF50F, |
|
| 28 |
- (int16_t)0xF384, (int16_t)0xF1FB, (int16_t)0xF074, (int16_t)0xEEEF, (int16_t)0xED6C, (int16_t)0xEBED, (int16_t)0xEA71, (int16_t)0xE8F8, |
|
| 29 |
- (int16_t)0xE783, (int16_t)0xE611, (int16_t)0xE4A3, (int16_t)0xE33A, (int16_t)0xE1D5, (int16_t)0xE075, (int16_t)0xDF19, (int16_t)0xDDC3, |
|
| 30 |
- (int16_t)0xDC72, (int16_t)0xDB26, (int16_t)0xD9E1, (int16_t)0xD8A1, (int16_t)0xD767, (int16_t)0xD633, (int16_t)0xD506, (int16_t)0xD3DF, |
|
| 31 |
- (int16_t)0xD2BF, (int16_t)0xD1A6, (int16_t)0xD095, (int16_t)0xCF8A, (int16_t)0xCE87, (int16_t)0xCD8C, (int16_t)0xCC99, (int16_t)0xCBAD, |
|
| 32 |
- (int16_t)0xCACA, (int16_t)0xC9EE, (int16_t)0xC91B, (int16_t)0xC851, (int16_t)0xC78F, (int16_t)0xC6D6, (int16_t)0xC626, (int16_t)0xC57E, |
|
| 33 |
- (int16_t)0xC4E0, (int16_t)0xC44A, (int16_t)0xC3BE, (int16_t)0xC33B, (int16_t)0xC2C2, (int16_t)0xC252, (int16_t)0xC1EC, (int16_t)0xC18F, |
|
| 34 |
- (int16_t)0xC13B, (int16_t)0xC0F2, (int16_t)0xC0B2, (int16_t)0xC07C, (int16_t)0xC04F, (int16_t)0xC02D, (int16_t)0xC014, (int16_t)0xC005, |
|
| 35 |
- (int16_t)0xC000, (int16_t)0xC005, (int16_t)0xC014, (int16_t)0xC02D, (int16_t)0xC04F, (int16_t)0xC07C, (int16_t)0xC0B2, (int16_t)0xC0F2, |
|
| 36 |
- (int16_t)0xC13B, (int16_t)0xC18F, (int16_t)0xC1EC, (int16_t)0xC252, (int16_t)0xC2C2, (int16_t)0xC33B, (int16_t)0xC3BE, (int16_t)0xC44A, |
|
| 37 |
- (int16_t)0xC4E0, (int16_t)0xC57E, (int16_t)0xC626, (int16_t)0xC6D6, (int16_t)0xC78F, (int16_t)0xC851, (int16_t)0xC91B, (int16_t)0xC9EE, |
|
| 38 |
- (int16_t)0xCACA, (int16_t)0xCBAD, (int16_t)0xCC99, (int16_t)0xCD8C, (int16_t)0xCE87, (int16_t)0xCF8A, (int16_t)0xD095, (int16_t)0xD1A6, |
|
| 39 |
- (int16_t)0xD2BF, (int16_t)0xD3DF, (int16_t)0xD506, (int16_t)0xD633, (int16_t)0xD767, (int16_t)0xD8A1, (int16_t)0xD9E1, (int16_t)0xDB26, |
|
| 40 |
- (int16_t)0xDC72, (int16_t)0xDDC3, (int16_t)0xDF19, (int16_t)0xE075, (int16_t)0xE1D5, (int16_t)0xE33A, (int16_t)0xE4A3, (int16_t)0xE611, |
|
| 41 |
- (int16_t)0xE783, (int16_t)0xE8F8, (int16_t)0xEA71, (int16_t)0xEBED, (int16_t)0xED6C, (int16_t)0xEEEF, (int16_t)0xF074, (int16_t)0xF1FB, |
|
| 42 |
- (int16_t)0xF384, (int16_t)0xF50F, (int16_t)0xF69C, (int16_t)0xF82B, (int16_t)0xF9BB, (int16_t)0xFB4B, (int16_t)0xFCDD, (int16_t)0xFE6E |
|
| 8 |
+int32_t sineTable[] = |
|
| 9 |
+{
|
|
| 10 |
+ 0x0000, 0x0192, 0x0323, 0x04B5, 0x0645, 0x07D5, 0x0964, 0x0AF1, |
|
| 11 |
+ 0x0C7C, 0x0E05, 0x0F8C, 0x1111, 0x1294, 0x1413, 0x158F, 0x1708, |
|
| 12 |
+ 0x187D, 0x19EF, 0x1B5D, 0x1CC6, 0x1E2B, 0x1F8B, 0x20E7, 0x223D, |
|
| 13 |
+ 0x238E, 0x24DA, 0x261F, 0x275F, 0x2899, 0x29CD, 0x2AFA, 0x2C21, |
|
| 14 |
+ 0x2D41, 0x2E5A, 0x2F6B, 0x3076, 0x3179, 0x3274, 0x3367, 0x3453, |
|
| 15 |
+ 0x3536, 0x3612, 0x36E5, 0x37AF, 0x3871, 0x392A, 0x39DA, 0x3A82, |
|
| 16 |
+ 0x3B20, 0x3BB6, 0x3C42, 0x3CC5, 0x3D3E, 0x3DAE, 0x3E14, 0x3E71, |
|
| 17 |
+ 0x3EC5, 0x3F0E, 0x3F4E, 0x3F84, 0x3FB1, 0x3FD3, 0x3FEC, 0x3FFB, |
|
| 18 |
+ 0x4000, 0x3FFB, 0x3FEC, 0x3FD3, 0x3FB1, 0x3F84, 0x3F4E, 0x3F0E, |
|
| 19 |
+ 0x3EC5, 0x3E71, 0x3E14, 0x3DAE, 0x3D3E, 0x3CC5, 0x3C42, 0x3BB6, |
|
| 20 |
+ 0x3B20, 0x3A82, 0x39DA, 0x392A, 0x3871, 0x37AF, 0x36E5, 0x3612, |
|
| 21 |
+ 0x3536, 0x3453, 0x3367, 0x3274, 0x3179, 0x3076, 0x2F6B, 0x2E5A, |
|
| 22 |
+ 0x2D41, 0x2C21, 0x2AFA, 0x29CD, 0x2899, 0x275F, 0x261F, 0x24DA, |
|
| 23 |
+ 0x238E, 0x223D, 0x20E7, 0x1F8B, 0x1E2B, 0x1CC6, 0x1B5D, 0x19EF, |
|
| 24 |
+ 0x187D, 0x1708, 0x158F, 0x1413, 0x1294, 0x1111, 0x0F8C, 0x0E05, |
|
| 25 |
+ 0x0C7C, 0x0AF1, 0x0964, 0x07D5, 0x0645, 0x04B5, 0x0323, 0x0192, |
|
| 26 |
+ 0x0000, 0xFE6E, 0xFCDD, 0xFB4B, 0xF9BB, 0xF82B, 0xF69C, 0xF50F, |
|
| 27 |
+ 0xF384, 0xF1FB, 0xF074, 0xEEEF, 0xED6C, 0xEBED, 0xEA71, 0xE8F8, |
|
| 28 |
+ 0xE783, 0xE611, 0xE4A3, 0xE33A, 0xE1D5, 0xE075, 0xDF19, 0xDDC3, |
|
| 29 |
+ 0xDC72, 0xDB26, 0xD9E1, 0xD8A1, 0xD767, 0xD633, 0xD506, 0xD3DF, |
|
| 30 |
+ 0xD2BF, 0xD1A6, 0xD095, 0xCF8A, 0xCE87, 0xCD8C, 0xCC99, 0xCBAD, |
|
| 31 |
+ 0xCACA, 0xC9EE, 0xC91B, 0xC851, 0xC78F, 0xC6D6, 0xC626, 0xC57E, |
|
| 32 |
+ 0xC4E0, 0xC44A, 0xC3BE, 0xC33B, 0xC2C2, 0xC252, 0xC1EC, 0xC18F, |
|
| 33 |
+ 0xC13B, 0xC0F2, 0xC0B2, 0xC07C, 0xC04F, 0xC02D, 0xC014, 0xC005, |
|
| 34 |
+ 0xC000, 0xC005, 0xC014, 0xC02D, 0xC04F, 0xC07C, 0xC0B2, 0xC0F2, |
|
| 35 |
+ 0xC13B, 0xC18F, 0xC1EC, 0xC252, 0xC2C2, 0xC33B, 0xC3BE, 0xC44A, |
|
| 36 |
+ 0xC4E0, 0xC57E, 0xC626, 0xC6D6, 0xC78F, 0xC851, 0xC91B, 0xC9EE, |
|
| 37 |
+ 0xCACA, 0xCBAD, 0xCC99, 0xCD8C, 0xCE87, 0xCF8A, 0xD095, 0xD1A6, |
|
| 38 |
+ 0xD2BF, 0xD3DF, 0xD506, 0xD633, 0xD767, 0xD8A1, 0xD9E1, 0xDB26, |
|
| 39 |
+ 0xDC72, 0xDDC3, 0xDF19, 0xE075, 0xE1D5, 0xE33A, 0xE4A3, 0xE611, |
|
| 40 |
+ 0xE783, 0xE8F8, 0xEA71, 0xEBED, 0xED6C, 0xEEEF, 0xF074, 0xF1FB, |
|
| 41 |
+ 0xF384, 0xF50F, 0xF69C, 0xF82B, 0xF9BB, 0xFB4B, 0xFCDD, 0xFE6E |
|
| 43 | 42 |
}; |
| 44 | 43 |
|
| 45 | 44 |
void BIOS_ArcTan() |
| 46 | 45 |
{
|
| 47 |
-#ifdef GBA_LOGGING |
|
| 48 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 49 |
- log("ArcTan: %08x (VCOUNT=%2d)\n",
|
|
| 50 |
- reg[0].I, |
|
| 51 |
- VCOUNT); |
|
| 52 |
- } |
|
| 53 |
-#endif |
|
| 54 |
- |
|
| 55 |
- int32_t a = -(((int32_t)(reg[0].I*reg[0].I)) >> 14); |
|
| 56 |
- int32_t b = ((0xA9 * a) >> 14) + 0x390; |
|
| 57 |
- b = ((b * a) >> 14) + 0x91C; |
|
| 58 |
- b = ((b * a) >> 14) + 0xFB6; |
|
| 59 |
- b = ((b * a) >> 14) + 0x16AA; |
|
| 60 |
- b = ((b * a) >> 14) + 0x2081; |
|
| 61 |
- b = ((b * a) >> 14) + 0x3651; |
|
| 62 |
- b = ((b * a) >> 14) + 0xA2F9; |
|
| 63 |
- a = ((int32_t)reg[0].I * b) >> 16; |
|
| 64 |
- reg[0].I = a; |
|
| 65 |
- |
|
| 66 |
-#ifdef GBA_LOGGING |
|
| 67 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 68 |
- log("ArcTan: return=%08x\n",
|
|
| 69 |
- reg[0].I); |
|
| 70 |
- } |
|
| 71 |
-#endif |
|
| 46 |
+ int32_t a = -(static_cast<int32_t>(reg[0].I * reg[0].I) >> 14); |
|
| 47 |
+ int32_t b = ((0xA9 * a) >> 14) + 0x390; |
|
| 48 |
+ b = ((b * a) >> 14) + 0x91C; |
|
| 49 |
+ b = ((b * a) >> 14) + 0xFB6; |
|
| 50 |
+ b = ((b * a) >> 14) + 0x16AA; |
|
| 51 |
+ b = ((b * a) >> 14) + 0x2081; |
|
| 52 |
+ b = ((b * a) >> 14) + 0x3651; |
|
| 53 |
+ b = ((b * a) >> 14) + 0xA2F9; |
|
| 54 |
+ a = (static_cast<int32_t>(reg[0].I) * b) >> 16; |
|
| 55 |
+ reg[0].I = a; |
|
| 72 | 56 |
} |
| 73 | 57 |
|
| 74 | 58 |
void BIOS_ArcTan2() |
| 75 | 59 |
{
|
| 76 |
-#ifdef GBA_LOGGING |
|
| 77 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 78 |
- log("ArcTan2: %08x,%08x (VCOUNT=%2d)\n",
|
|
| 79 |
- reg[0].I, |
|
| 80 |
- reg[1].I, |
|
| 81 |
- VCOUNT); |
|
| 82 |
- } |
|
| 83 |
-#endif |
|
| 84 |
- |
|
| 85 |
- int32_t x = reg[0].I; |
|
| 86 |
- int32_t y = reg[1].I; |
|
| 87 |
- uint32_t res = 0; |
|
| 88 |
- if (y == 0) {
|
|
| 89 |
- res = ((x>>16) & 0x8000); |
|
| 90 |
- } else {
|
|
| 91 |
- if (x == 0) {
|
|
| 92 |
- res = ((y>>16) & 0x8000) + 0x4000; |
|
| 93 |
- } else {
|
|
| 94 |
- if ((abs(x) > abs(y)) || ((abs(x) == abs(y)) && (!((x<0) && (y<0))))) {
|
|
| 95 |
- reg[1].I = x; |
|
| 96 |
- reg[0].I = y << 14; |
|
| 97 |
- BIOS_Div(); |
|
| 98 |
- BIOS_ArcTan(); |
|
| 99 |
- if (x < 0) |
|
| 100 |
- res = 0x8000 + reg[0].I; |
|
| 101 |
- else |
|
| 102 |
- res = (((y>>16) & 0x8000)<<1) + reg[0].I; |
|
| 103 |
- } else {
|
|
| 104 |
- reg[0].I = x << 14; |
|
| 105 |
- BIOS_Div(); |
|
| 106 |
- BIOS_ArcTan(); |
|
| 107 |
- res = (0x4000 + ((y>>16) & 0x8000)) - reg[0].I; |
|
| 108 |
- } |
|
| 109 |
- } |
|
| 110 |
- } |
|
| 111 |
- reg[0].I = res; |
|
| 112 |
- |
|
| 113 |
-#ifdef GBA_LOGGING |
|
| 114 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 115 |
- log("ArcTan2: return=%08x\n",
|
|
| 116 |
- reg[0].I); |
|
| 117 |
- } |
|
| 118 |
-#endif |
|
| 60 |
+ int32_t x = reg[0].I; |
|
| 61 |
+ int32_t y = reg[1].I; |
|
| 62 |
+ uint32_t res = 0; |
|
| 63 |
+ if (!y) |
|
| 64 |
+ res = (x >> 16) & 0x8000; |
|
| 65 |
+ else |
|
| 66 |
+ {
|
|
| 67 |
+ if (!x) |
|
| 68 |
+ res = ((y >> 16) & 0x8000) + 0x4000; |
|
| 69 |
+ else |
|
| 70 |
+ {
|
|
| 71 |
+ if (std::abs(x) > std::abs(y) || (std::abs(x) == std::abs(y) && !(x < 0 && y < 0))) |
|
| 72 |
+ {
|
|
| 73 |
+ reg[1].I = x; |
|
| 74 |
+ reg[0].I = y << 14; |
|
| 75 |
+ BIOS_Div(); |
|
| 76 |
+ BIOS_ArcTan(); |
|
| 77 |
+ if (x < 0) |
|
| 78 |
+ res = 0x8000 + reg[0].I; |
|
| 79 |
+ else |
|
| 80 |
+ res = (((y >> 16) & 0x8000) << 1) + reg[0].I; |
|
| 81 |
+ } |
|
| 82 |
+ else |
|
| 83 |
+ {
|
|
| 84 |
+ reg[0].I = x << 14; |
|
| 85 |
+ BIOS_Div(); |
|
| 86 |
+ BIOS_ArcTan(); |
|
| 87 |
+ res = (0x4000 + ((y >> 16) & 0x8000)) - reg[0].I; |
|
| 88 |
+ } |
|
| 89 |
+ } |
|
| 90 |
+ } |
|
| 91 |
+ reg[0].I = res; |
|
| 119 | 92 |
} |
| 120 | 93 |
|
| 121 | 94 |
void BIOS_BitUnPack() |
| 122 | 95 |
{
|
| 123 |
-#ifdef GBA_LOGGING |
|
| 124 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 125 |
- log("BitUnPack: %08x,%08x,%08x (VCOUNT=%2d)\n",
|
|
| 126 |
- reg[0].I, |
|
| 127 |
- reg[1].I, |
|
| 128 |
- reg[2].I, |
|
| 129 |
- VCOUNT); |
|
| 130 |
- } |
|
| 131 |
-#endif |
|
| 132 |
- |
|
| 133 |
- uint32_t source = reg[0].I; |
|
| 134 |
- uint32_t dest = reg[1].I; |
|
| 135 |
- uint32_t header = reg[2].I; |
|
| 136 |
- |
|
| 137 |
- int len = CPUReadHalfWord(header); |
|
| 138 |
- // check address |
|
| 139 |
- if(((source & 0xe000000) == 0) || |
|
| 140 |
- ((source + len) & 0xe000000) == 0) |
|
| 141 |
- return; |
|
| 142 |
- |
|
| 143 |
- int bits = CPUReadByte(header+2); |
|
| 144 |
- int revbits = 8 - bits; |
|
| 145 |
- // u32 value = 0; |
|
| 146 |
- uint32_t base = CPUReadMemory(header+4); |
|
| 147 |
- bool addBase = (base & 0x80000000) ? true : false; |
|
| 148 |
- base &= 0x7fffffff; |
|
| 149 |
- int dataSize = CPUReadByte(header+3); |
|
| 150 |
- |
|
| 151 |
- int data = 0; |
|
| 152 |
- int bitwritecount = 0; |
|
| 153 |
- while(1) {
|
|
| 154 |
- len -= 1; |
|
| 155 |
- if(len < 0) |
|
| 156 |
- break; |
|
| 157 |
- int mask = 0xff >> revbits; |
|
| 158 |
- uint8_t b = CPUReadByte(source); |
|
| 159 |
- source++; |
|
| 160 |
- int bitcount = 0; |
|
| 161 |
- while(1) {
|
|
| 162 |
- if(bitcount >= 8) |
|
| 163 |
- break; |
|
| 164 |
- uint32_t d = b & mask; |
|
| 165 |
- uint32_t temp = d >> bitcount; |
|
| 166 |
- if(d || addBase) {
|
|
| 167 |
- temp += base; |
|
| 168 |
- } |
|
| 169 |
- data |= temp << bitwritecount; |
|
| 170 |
- bitwritecount += dataSize; |
|
| 171 |
- if(bitwritecount >= 32) {
|
|
| 172 |
- CPUWriteMemory(dest, data); |
|
| 173 |
- dest += 4; |
|
| 174 |
- data = 0; |
|
| 175 |
- bitwritecount = 0; |
|
| 176 |
- } |
|
| 177 |
- mask <<= bits; |
|
| 178 |
- bitcount += bits; |
|
| 179 |
- } |
|
| 180 |
- } |
|
| 96 |
+ uint32_t source = reg[0].I; |
|
| 97 |
+ uint32_t dest = reg[1].I; |
|
| 98 |
+ uint32_t header = reg[2].I; |
|
| 99 |
+ |
|
| 100 |
+ int len = CPUReadHalfWord(header); |
|
| 101 |
+ // check address |
|
| 102 |
+ if (!(source & 0xe000000) || !((source + len) & 0xe000000)) |
|
| 103 |
+ return; |
|
| 104 |
+ |
|
| 105 |
+ int bits = CPUReadByte(header + 2); |
|
| 106 |
+ int revbits = 8 - bits; |
|
| 107 |
+ // u32 value = 0; |
|
| 108 |
+ uint32_t base = CPUReadMemory(header + 4); |
|
| 109 |
+ bool addBase = !!(base & 0x80000000); |
|
| 110 |
+ base &= 0x7fffffff; |
|
| 111 |
+ int dataSize = CPUReadByte(header + 3); |
|
| 112 |
+ |
|
| 113 |
+ int data = 0; |
|
| 114 |
+ int bitwritecount = 0; |
|
| 115 |
+ while (1) |
|
| 116 |
+ {
|
|
| 117 |
+ --len; |
|
| 118 |
+ if (len < 0) |
|
| 119 |
+ break; |
|
| 120 |
+ int mask = 0xff >> revbits; |
|
| 121 |
+ uint8_t b = CPUReadByte(source); |
|
| 122 |
+ ++source; |
|
| 123 |
+ int bitcount = 0; |
|
| 124 |
+ while (1) |
|
| 125 |
+ {
|
|
| 126 |
+ if (bitcount >= 8) |
|
| 127 |
+ break; |
|
| 128 |
+ uint32_t d = b & mask; |
|
| 129 |
+ uint32_t temp = d >> bitcount; |
|
| 130 |
+ if (d || addBase) |
|
| 131 |
+ temp += base; |
|
| 132 |
+ data |= temp << bitwritecount; |
|
| 133 |
+ bitwritecount += dataSize; |
|
| 134 |
+ if (bitwritecount >= 32) |
|
| 135 |
+ {
|
|
| 136 |
+ CPUWriteMemory(dest, data); |
|
| 137 |
+ dest += 4; |
|
| 138 |
+ data = 0; |
|
| 139 |
+ bitwritecount = 0; |
|
| 140 |
+ } |
|
| 141 |
+ mask <<= bits; |
|
| 142 |
+ bitcount += bits; |
|
| 143 |
+ } |
|
| 144 |
+ } |
|
| 181 | 145 |
} |
| 182 | 146 |
|
| 183 | 147 |
void BIOS_GetBiosChecksum() |
| 184 | 148 |
{
|
| 185 |
- reg[0].I=0xBAAE187F; |
|
| 149 |
+ reg[0].I = 0xBAAE187F; |
|
| 186 | 150 |
} |
| 187 | 151 |
|
| 188 | 152 |
void BIOS_BgAffineSet() |
| 189 | 153 |
{
|
| 190 |
-#ifdef GBA_LOGGING |
|
| 191 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 192 |
- log("BgAffineSet: %08x,%08x,%08x (VCOUNT=%2d)\n",
|
|
| 193 |
- reg[0].I, |
|
| 194 |
- reg[1].I, |
|
| 195 |
- reg[2].I, |
|
| 196 |
- VCOUNT); |
|
| 197 |
- } |
|
| 198 |
-#endif |
|
| 199 |
- |
|
| 200 |
- uint32_t src = reg[0].I; |
|
| 201 |
- uint32_t dest = reg[1].I; |
|
| 202 |
- int num = reg[2].I; |
|
| 203 |
- |
|
| 204 |
- for(int i = 0; i < num; i++) {
|
|
| 205 |
- int32_t cx = CPUReadMemory(src); |
|
| 206 |
- src+=4; |
|
| 207 |
- int32_t cy = CPUReadMemory(src); |
|
| 208 |
- src+=4; |
|
| 209 |
- int16_t dispx = CPUReadHalfWord(src); |
|
| 210 |
- src+=2; |
|
| 211 |
- int16_t dispy = CPUReadHalfWord(src); |
|
| 212 |
- src+=2; |
|
| 213 |
- int16_t rx = CPUReadHalfWord(src); |
|
| 214 |
- src+=2; |
|
| 215 |
- int16_t ry = CPUReadHalfWord(src); |
|
| 216 |
- src+=2; |
|
| 217 |
- uint16_t theta = CPUReadHalfWord(src)>>8; |
|
| 218 |
- src+=4; // keep structure alignment |
|
| 219 |
- int32_t a = sineTable[(theta+0x40)&255]; |
|
| 220 |
- int32_t b = sineTable[theta]; |
|
| 221 |
- |
|
| 222 |
- int16_t dx = (rx * a)>>14; |
|
| 223 |
- int16_t dmx = (rx * b)>>14; |
|
| 224 |
- int16_t dy = (ry * b)>>14; |
|
| 225 |
- int16_t dmy = (ry * a)>>14; |
|
| 226 |
- |
|
| 227 |
- CPUWriteHalfWord(dest, dx); |
|
| 228 |
- dest += 2; |
|
| 229 |
- CPUWriteHalfWord(dest, -dmx); |
|
| 230 |
- dest += 2; |
|
| 231 |
- CPUWriteHalfWord(dest, dy); |
|
| 232 |
- dest += 2; |
|
| 233 |
- CPUWriteHalfWord(dest, dmy); |
|
| 234 |
- dest += 2; |
|
| 235 |
- |
|
| 236 |
- int32_t startx = cx - dx * dispx + dmx * dispy; |
|
| 237 |
- int32_t starty = cy - dy * dispx - dmy * dispy; |
|
| 238 |
- |
|
| 239 |
- CPUWriteMemory(dest, startx); |
|
| 240 |
- dest += 4; |
|
| 241 |
- CPUWriteMemory(dest, starty); |
|
| 242 |
- dest += 4; |
|
| 243 |
- } |
|
| 154 |
+ uint32_t src = reg[0].I; |
|
| 155 |
+ uint32_t dest = reg[1].I; |
|
| 156 |
+ int num = reg[2].I; |
|
| 157 |
+ |
|
| 158 |
+ for (int i = 0; i < num; ++i) |
|
| 159 |
+ {
|
|
| 160 |
+ int32_t cx = CPUReadMemory(src); |
|
| 161 |
+ src += 4; |
|
| 162 |
+ int32_t cy = CPUReadMemory(src); |
|
| 163 |
+ src += 4; |
|
| 164 |
+ int16_t dispx = CPUReadHalfWord(src); |
|
| 165 |
+ src += 2; |
|
| 166 |
+ int16_t dispy = CPUReadHalfWord(src); |
|
| 167 |
+ src += 2; |
|
| 168 |
+ int16_t rx = CPUReadHalfWord(src); |
|
| 169 |
+ src += 2; |
|
| 170 |
+ int16_t ry = CPUReadHalfWord(src); |
|
| 171 |
+ src += 2; |
|
| 172 |
+ uint16_t theta = CPUReadHalfWord(src) >> 8; |
|
| 173 |
+ src += 4; // keep structure alignment |
|
| 174 |
+ int32_t a = sineTable[(theta + 0x40) & 255]; |
|
| 175 |
+ int32_t b = sineTable[theta]; |
|
| 176 |
+ |
|
| 177 |
+ int16_t dx = (rx * a) >> 14; |
|
| 178 |
+ int16_t dmx = (rx * b) >> 14; |
|
| 179 |
+ int16_t dy = (ry * b) >> 14; |
|
| 180 |
+ int16_t dmy = (ry * a) >> 14; |
|
| 181 |
+ |
|
| 182 |
+ CPUWriteHalfWord(dest, dx); |
|
| 183 |
+ dest += 2; |
|
| 184 |
+ CPUWriteHalfWord(dest, -dmx); |
|
| 185 |
+ dest += 2; |
|
| 186 |
+ CPUWriteHalfWord(dest, dy); |
|
| 187 |
+ dest += 2; |
|
| 188 |
+ CPUWriteHalfWord(dest, dmy); |
|
| 189 |
+ dest += 2; |
|
| 190 |
+ |
|
| 191 |
+ int32_t startx = cx - dx * dispx + dmx * dispy; |
|
| 192 |
+ int32_t starty = cy - dy * dispx - dmy * dispy; |
|
| 193 |
+ |
|
| 194 |
+ CPUWriteMemory(dest, startx); |
|
| 195 |
+ dest += 4; |
|
| 196 |
+ CPUWriteMemory(dest, starty); |
|
| 197 |
+ dest += 4; |
|
| 198 |
+ } |
|
| 244 | 199 |
} |
| 245 | 200 |
|
| 246 | 201 |
void BIOS_CpuSet() |
| 247 | 202 |
{
|
| 248 |
-#ifdef GBA_LOGGING |
|
| 249 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 250 |
- log("CpuSet: 0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
|
|
| 251 |
- reg[2].I, VCOUNT); |
|
| 252 |
- } |
|
| 253 |
-#endif |
|
| 254 |
- |
|
| 255 |
- uint32_t source = reg[0].I; |
|
| 256 |
- uint32_t dest = reg[1].I; |
|
| 257 |
- uint32_t cnt = reg[2].I; |
|
| 258 |
- |
|
| 259 |
- if(((source & 0xe000000) == 0) || |
|
| 260 |
- ((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0) |
|
| 261 |
- return; |
|
| 262 |
- |
|
| 263 |
- int count = cnt & 0x1FFFFF; |
|
| 264 |
- |
|
| 265 |
- // 32-bit ? |
|
| 266 |
- if((cnt >> 26) & 1) {
|
|
| 267 |
- // needed for 32-bit mode! |
|
| 268 |
- source &= 0xFFFFFFFC; |
|
| 269 |
- dest &= 0xFFFFFFFC; |
|
| 270 |
- // fill ? |
|
| 271 |
- if((cnt >> 24) & 1) {
|
|
| 272 |
- uint32_t value = (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source)); |
|
| 273 |
- while(count) {
|
|
| 274 |
- CPUWriteMemory(dest, value); |
|
| 275 |
- dest += 4; |
|
| 276 |
- count--; |
|
| 277 |
- } |
|
| 278 |
- } else {
|
|
| 279 |
- // copy |
|
| 280 |
- while(count) {
|
|
| 281 |
- CPUWriteMemory(dest, (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source))); |
|
| 282 |
- source += 4; |
|
| 283 |
- dest += 4; |
|
| 284 |
- count--; |
|
| 285 |
- } |
|
| 286 |
- } |
|
| 287 |
- } else {
|
|
| 288 |
- // 16-bit fill? |
|
| 289 |
- if((cnt >> 24) & 1) {
|
|
| 290 |
- uint16_t value = (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source)); |
|
| 291 |
- while(count) {
|
|
| 292 |
- CPUWriteHalfWord(dest, value); |
|
| 293 |
- dest += 2; |
|
| 294 |
- count--; |
|
| 295 |
- } |
|
| 296 |
- } else {
|
|
| 297 |
- // copy |
|
| 298 |
- while(count) {
|
|
| 299 |
- CPUWriteHalfWord(dest, (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source))); |
|
| 300 |
- source += 2; |
|
| 301 |
- dest += 2; |
|
| 302 |
- count--; |
|
| 303 |
- } |
|
| 304 |
- } |
|
| 305 |
- } |
|
| 203 |
+ uint32_t source = reg[0].I; |
|
| 204 |
+ uint32_t dest = reg[1].I; |
|
| 205 |
+ uint32_t cnt = reg[2].I; |
|
| 206 |
+ |
|
| 207 |
+ if (!(source & 0xe000000) || !((source + (((cnt << 11) >> 9) & 0x1fffff)) & 0xe000000)) |
|
| 208 |
+ return; |
|
| 209 |
+ |
|
| 210 |
+ int count = cnt & 0x1FFFFF; |
|
| 211 |
+ |
|
| 212 |
+ // 32-bit ? |
|
| 213 |
+ if ((cnt >> 26) & 1) |
|
| 214 |
+ {
|
|
| 215 |
+ // needed for 32-bit mode! |
|
| 216 |
+ source &= 0xFFFFFFFC; |
|
| 217 |
+ dest &= 0xFFFFFFFC; |
|
| 218 |
+ // fill ? |
|
| 219 |
+ if ((cnt >> 24) & 1) |
|
| 220 |
+ {
|
|
| 221 |
+ uint32_t value = source > 0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source); |
|
| 222 |
+ while (count) |
|
| 223 |
+ {
|
|
| 224 |
+ CPUWriteMemory(dest, value); |
|
| 225 |
+ dest += 4; |
|
| 226 |
+ --count; |
|
| 227 |
+ } |
|
| 228 |
+ } |
|
| 229 |
+ else |
|
| 230 |
+ {
|
|
| 231 |
+ // copy |
|
| 232 |
+ while (count) |
|
| 233 |
+ {
|
|
| 234 |
+ CPUWriteMemory(dest, source > 0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source)); |
|
| 235 |
+ source += 4; |
|
| 236 |
+ dest += 4; |
|
| 237 |
+ --count; |
|
| 238 |
+ } |
|
| 239 |
+ } |
|
| 240 |
+ } |
|
| 241 |
+ else |
|
| 242 |
+ {
|
|
| 243 |
+ // 16-bit fill? |
|
| 244 |
+ if ((cnt >> 24) & 1) |
|
| 245 |
+ {
|
|
| 246 |
+ uint16_t value = source > 0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source); |
|
| 247 |
+ while (count) |
|
| 248 |
+ {
|
|
| 249 |
+ CPUWriteHalfWord(dest, value); |
|
| 250 |
+ dest += 2; |
|
| 251 |
+ --count; |
|
| 252 |
+ } |
|
| 253 |
+ } |
|
| 254 |
+ else |
|
| 255 |
+ {
|
|
| 256 |
+ // copy |
|
| 257 |
+ while (count) |
|
| 258 |
+ {
|
|
| 259 |
+ CPUWriteHalfWord(dest, source > 0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source)); |
|
| 260 |
+ source += 2; |
|
| 261 |
+ dest += 2; |
|
| 262 |
+ --count; |
|
| 263 |
+ } |
|
| 264 |
+ } |
|
| 265 |
+ } |
|
| 306 | 266 |
} |
| 307 | 267 |
|
| 308 | 268 |
void BIOS_CpuFastSet() |
| 309 | 269 |
{
|
| 310 |
-#ifdef GBA_LOGGING |
|
| 311 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 312 |
- log("CpuFastSet: 0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
|
|
| 313 |
- reg[2].I, VCOUNT); |
|
| 314 |
- } |
|
| 315 |
-#endif |
|
| 316 |
- |
|
| 317 |
- uint32_t source = reg[0].I; |
|
| 318 |
- uint32_t dest = reg[1].I; |
|
| 319 |
- uint32_t cnt = reg[2].I; |
|
| 320 |
- |
|
| 321 |
- if(((source & 0xe000000) == 0) || |
|
| 322 |
- ((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0) |
|
| 323 |
- return; |
|
| 324 |
- |
|
| 325 |
- // needed for 32-bit mode! |
|
| 326 |
- source &= 0xFFFFFFFC; |
|
| 327 |
- dest &= 0xFFFFFFFC; |
|
| 328 |
- |
|
| 329 |
- int count = cnt & 0x1FFFFF; |
|
| 330 |
- |
|
| 331 |
- // fill? |
|
| 332 |
- if((cnt >> 24) & 1) {
|
|
| 333 |
- while(count > 0) {
|
|
| 334 |
- // BIOS always transfers 32 bytes at a time |
|
| 335 |
- uint32_t value = (source>0x0EFFFFFF ? 0xBAFFFFFB : CPUReadMemory(source)); |
|
| 336 |
- for(int i = 0; i < 8; i++) {
|
|
| 337 |
- CPUWriteMemory(dest, value); |
|
| 338 |
- dest += 4; |
|
| 339 |
- } |
|
| 340 |
- count -= 8; |
|
| 341 |
- } |
|
| 342 |
- } else {
|
|
| 343 |
- // copy |
|
| 344 |
- while(count > 0) {
|
|
| 345 |
- // BIOS always transfers 32 bytes at a time |
|
| 346 |
- for(int i = 0; i < 8; i++) {
|
|
| 347 |
- CPUWriteMemory(dest, (source>0x0EFFFFFF ? 0xBAFFFFFB :CPUReadMemory(source))); |
|
| 348 |
- source += 4; |
|
| 349 |
- dest += 4; |
|
| 350 |
- } |
|
| 351 |
- count -= 8; |
|
| 352 |
- } |
|
| 353 |
- } |
|
| 270 |
+ uint32_t source = reg[0].I; |
|
| 271 |
+ uint32_t dest = reg[1].I; |
|
| 272 |
+ uint32_t cnt = reg[2].I; |
|
| 273 |
+ |
|
| 274 |
+ if (!(source & 0xe000000) || !((source + (((cnt << 11) >> 9) & 0x1fffff)) & 0xe000000)) |
|
| 275 |
+ return; |
|
| 276 |
+ |
|
| 277 |
+ // needed for 32-bit mode! |
|
| 278 |
+ source &= 0xFFFFFFFC; |
|
| 279 |
+ dest &= 0xFFFFFFFC; |
|
| 280 |
+ |
|
| 281 |
+ int count = cnt & 0x1FFFFF; |
|
| 282 |
+ |
|
| 283 |
+ // fill? |
|
| 284 |
+ if ((cnt >> 24) & 1) |
|
| 285 |
+ {
|
|
| 286 |
+ while (count > 0) |
|
| 287 |
+ {
|
|
| 288 |
+ // BIOS always transfers 32 bytes at a time |
|
| 289 |
+ uint32_t value = source > 0x0EFFFFFF ? 0xBAFFFFFB : CPUReadMemory(source); |
|
| 290 |
+ for (int i = 0; i < 8; ++i) |
|
| 291 |
+ {
|
|
| 292 |
+ CPUWriteMemory(dest, value); |
|
| 293 |
+ dest += 4; |
|
| 294 |
+ } |
|
| 295 |
+ count -= 8; |
|
| 296 |
+ } |
|
| 297 |
+ } |
|
| 298 |
+ else |
|
| 299 |
+ {
|
|
| 300 |
+ // copy |
|
| 301 |
+ while (count > 0) |
|
| 302 |
+ {
|
|
| 303 |
+ // BIOS always transfers 32 bytes at a time |
|
| 304 |
+ for (int i = 0; i < 8; ++i) |
|
| 305 |
+ {
|
|
| 306 |
+ CPUWriteMemory(dest, source > 0x0EFFFFFF ? 0xBAFFFFFB :CPUReadMemory(source)); |
|
| 307 |
+ source += 4; |
|
| 308 |
+ dest += 4; |
|
| 309 |
+ } |
|
| 310 |
+ count -= 8; |
|
| 311 |
+ } |
|
| 312 |
+ } |
|
| 354 | 313 |
} |
| 355 | 314 |
|
| 356 | 315 |
void BIOS_Diff8bitUnFilterWram() |
| 357 | 316 |
{
|
| 358 |
-#ifdef GBA_LOGGING |
|
| 359 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 360 |
- log("Diff8bitUnFilterWram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
|
|
| 361 |
- reg[1].I, VCOUNT); |
|
| 362 |
- } |
|
| 363 |
-#endif |
|
| 317 |
+ uint32_t source = reg[0].I; |
|
| 318 |
+ uint32_t dest = reg[1].I; |
|
| 364 | 319 |
|
| 365 |
- uint32_t source = reg[0].I; |
|
| 366 |
- uint32_t dest = reg[1].I; |
|
| 320 |
+ uint32_t header = CPUReadMemory(source); |
|
| 321 |
+ source += 4; |
|
| 367 | 322 |
|
| 368 |
- uint32_t header = CPUReadMemory(source); |
|
| 369 |
- source += 4; |
|
| 323 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 324 |
+ return; |
|
| 370 | 325 |
|
| 371 |
- if(((source & 0xe000000) == 0) || |
|
| 372 |
- (((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)) |
|
| 373 |
- return; |
|
| 326 |
+ int len = header >> 8; |
|
| 374 | 327 |
|
| 375 |
- int len = header >> 8; |
|
| 328 |
+ uint8_t data = CPUReadByte(source++); |
|
| 329 |
+ CPUWriteByte(dest++, data); |
|
| 330 |
+ --len; |
|
| 376 | 331 |
|
| 377 |
- uint8_t data = CPUReadByte(source++); |
|
| 378 |
- CPUWriteByte(dest++, data); |
|
| 379 |
- len--; |
|
| 380 |
- |
|
| 381 |
- while(len > 0) {
|
|
| 382 |
- uint8_t diff = CPUReadByte(source++); |
|
| 383 |
- data += diff; |
|
| 384 |
- CPUWriteByte(dest++, data); |
|
| 385 |
- len--; |
|
| 386 |
- } |
|
| 332 |
+ while (len > 0) |
|
| 333 |
+ {
|
|
| 334 |
+ uint8_t diff = CPUReadByte(source++); |
|
| 335 |
+ data += diff; |
|
| 336 |
+ CPUWriteByte(dest++, data); |
|
| 337 |
+ --len; |
|
| 338 |
+ } |
|
| 387 | 339 |
} |
| 388 | 340 |
|
| 389 | 341 |
void BIOS_Diff8bitUnFilterVram() |
| 390 | 342 |
{
|
| 391 |
-#ifdef GBA_LOGGING |
|
| 392 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 393 |
- log("Diff8bitUnFilterVram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
|
|
| 394 |
- reg[1].I, VCOUNT); |
|
| 395 |
- } |
|
| 396 |
-#endif |
|
| 397 |
- |
|
| 398 |
- uint32_t source = reg[0].I; |
|
| 399 |
- uint32_t dest = reg[1].I; |
|
| 400 |
- |
|
| 401 |
- uint32_t header = CPUReadMemory(source); |
|
| 402 |
- source += 4; |
|
| 403 |
- |
|
| 404 |
- if(((source & 0xe000000) == 0) || |
|
| 405 |
- ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 406 |
- return; |
|
| 407 |
- |
|
| 408 |
- int len = header >> 8; |
|
| 409 |
- |
|
| 410 |
- uint8_t data = CPUReadByte(source++); |
|
| 411 |
- uint16_t writeData = data; |
|
| 412 |
- int shift = 8; |
|
| 413 |
- int bytes = 1; |
|
| 414 |
- |
|
| 415 |
- while(len >= 2) {
|
|
| 416 |
- uint8_t diff = CPUReadByte(source++); |
|
| 417 |
- data += diff; |
|
| 418 |
- writeData |= (data << shift); |
|
| 419 |
- bytes++; |
|
| 420 |
- shift += 8; |
|
| 421 |
- if(bytes == 2) {
|
|
| 422 |
- CPUWriteHalfWord(dest, writeData); |
|
| 423 |
- dest += 2; |
|
| 424 |
- len -= 2; |
|
| 425 |
- bytes = 0; |
|
| 426 |
- writeData = 0; |
|
| 427 |
- shift = 0; |
|
| 428 |
- } |
|
| 429 |
- } |
|
| 343 |
+ uint32_t source = reg[0].I; |
|
| 344 |
+ uint32_t dest = reg[1].I; |
|
| 345 |
+ |
|
| 346 |
+ uint32_t header = CPUReadMemory(source); |
|
| 347 |
+ source += 4; |
|
| 348 |
+ |
|
| 349 |
+ if (!(source & 0xe000000) | !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 350 |
+ return; |
|
| 351 |
+ |
|
| 352 |
+ int len = header >> 8; |
|
| 353 |
+ |
|
| 354 |
+ uint8_t data = CPUReadByte(source++); |
|
| 355 |
+ uint16_t writeData = data; |
|
| 356 |
+ int shift = 8; |
|
| 357 |
+ int bytes = 1; |
|
| 358 |
+ |
|
| 359 |
+ while (len >= 2) |
|
| 360 |
+ {
|
|
| 361 |
+ uint8_t diff = CPUReadByte(source++); |
|
| 362 |
+ data += diff; |
|
| 363 |
+ writeData |= data << shift; |
|
| 364 |
+ ++bytes; |
|
| 365 |
+ shift += 8; |
|
| 366 |
+ if (bytes == 2) |
|
| 367 |
+ {
|
|
| 368 |
+ CPUWriteHalfWord(dest, writeData); |
|
| 369 |
+ dest += 2; |
|
| 370 |
+ len -= 2; |
|
| 371 |
+ bytes = 0; |
|
| 372 |
+ writeData = 0; |
|
| 373 |
+ shift = 0; |
|
| 374 |
+ } |
|
| 375 |
+ } |
|
| 430 | 376 |
} |
| 431 | 377 |
|
| 432 | 378 |
void BIOS_Diff16bitUnFilter() |
| 433 | 379 |
{
|
| 434 |
-#ifdef GBA_LOGGING |
|
| 435 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 436 |
- log("Diff16bitUnFilter: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
|
|
| 437 |
- reg[1].I, VCOUNT); |
|
| 438 |
- } |
|
| 439 |
-#endif |
|
| 440 |
- |
|
| 441 |
- uint32_t source = reg[0].I; |
|
| 442 |
- uint32_t dest = reg[1].I; |
|
| 443 |
- |
|
| 444 |
- uint32_t header = CPUReadMemory(source); |
|
| 445 |
- source += 4; |
|
| 446 |
- |
|
| 447 |
- if(((source & 0xe000000) == 0) || |
|
| 448 |
- ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 449 |
- return; |
|
| 450 |
- |
|
| 451 |
- int len = header >> 8; |
|
| 452 |
- |
|
| 453 |
- uint16_t data = CPUReadHalfWord(source); |
|
| 454 |
- source += 2; |
|
| 455 |
- CPUWriteHalfWord(dest, data); |
|
| 456 |
- dest += 2; |
|
| 457 |
- len -= 2; |
|
| 458 |
- |
|
| 459 |
- while(len >= 2) {
|
|
| 460 |
- uint16_t diff = CPUReadHalfWord(source); |
|
| 461 |
- source += 2; |
|
| 462 |
- data += diff; |
|
| 463 |
- CPUWriteHalfWord(dest, data); |
|
| 464 |
- dest += 2; |
|
| 465 |
- len -= 2; |
|
| 466 |
- } |
|
| 380 |
+ uint32_t source = reg[0].I; |
|
| 381 |
+ uint32_t dest = reg[1].I; |
|
| 382 |
+ |
|
| 383 |
+ uint32_t header = CPUReadMemory(source); |
|
| 384 |
+ source += 4; |
|
| 385 |
+ |
|
| 386 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 387 |
+ return; |
|
| 388 |
+ |
|
| 389 |
+ int len = header >> 8; |
|
| 390 |
+ |
|
| 391 |
+ uint16_t data = CPUReadHalfWord(source); |
|
| 392 |
+ source += 2; |
|
| 393 |
+ CPUWriteHalfWord(dest, data); |
|
| 394 |
+ dest += 2; |
|
| 395 |
+ len -= 2; |
|
| 396 |
+ |
|
| 397 |
+ while (len >= 2) |
|
| 398 |
+ {
|
|
| 399 |
+ uint16_t diff = CPUReadHalfWord(source); |
|
| 400 |
+ source += 2; |
|
| 401 |
+ data += diff; |
|
| 402 |
+ CPUWriteHalfWord(dest, data); |
|
| 403 |
+ dest += 2; |
|
| 404 |
+ len -= 2; |
|
| 405 |
+ } |
|
| 467 | 406 |
} |
| 468 | 407 |
|
| 469 | 408 |
void BIOS_Div() |
| 470 | 409 |
{
|
| 471 |
-#ifdef GBA_LOGGING |
|
| 472 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 473 |
- log("Div: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 474 |
- reg[0].I, |
|
| 475 |
- reg[1].I, |
|
| 476 |
- VCOUNT); |
|
| 477 |
- } |
|
| 478 |
-#endif |
|
| 410 |
+ int number = reg[0].I; |
|
| 411 |
+ int denom = reg[1].I; |
|
| 479 | 412 |
|
| 480 |
- int number = reg[0].I; |
|
| 481 |
- int denom = reg[1].I; |
|
| 482 |
- |
|
| 483 |
- if(denom != 0) {
|
|
| 484 |
- reg[0].I = number / denom; |
|
| 485 |
- reg[1].I = number % denom; |
|
| 486 |
- int32_t temp = (int32_t)reg[0].I; |
|
| 487 |
- reg[3].I = temp < 0 ? (uint32_t)-temp : (uint32_t)temp; |
|
| 488 |
- } |
|
| 489 |
-#ifdef GBA_LOGGING |
|
| 490 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 491 |
- log("Div: return=0x%08x,0x%08x,0x%08x\n",
|
|
| 492 |
- reg[0].I, |
|
| 493 |
- reg[1].I, |
|
| 494 |
- reg[3].I); |
|
| 495 |
- } |
|
| 496 |
-#endif |
|
| 497 |
-} |
|
| 498 |
- |
|
| 499 |
-void BIOS_DivARM() |
|
| 500 |
-{
|
|
| 501 |
-#ifdef GBA_LOGGING |
|
| 502 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 503 |
- log("DivARM: 0x%08x, (VCOUNT=%d)\n",
|
|
| 504 |
- reg[0].I, |
|
| 505 |
- VCOUNT); |
|
| 413 |
+ if (denom) |
|
| 414 |
+ {
|
|
| 415 |
+ reg[0].I = number / denom; |
|
| 416 |
+ reg[1].I = number % denom; |
|
| 417 |
+ int32_t temp = static_cast<int32_t>(reg[0].I); |
|
| 418 |
+ reg[3].I = static_cast<uint32_t>(temp < 0 ? -temp : temp); |
|
| 506 | 419 |
} |
| 507 |
-#endif |
|
| 508 |
- |
|
| 509 |
- uint32_t temp = reg[0].I; |
|
| 510 |
- reg[0].I = reg[1].I; |
|
| 511 |
- reg[1].I = temp; |
|
| 512 |
- BIOS_Div(); |
|
| 513 | 420 |
} |
| 514 | 421 |
|
| 515 | 422 |
void BIOS_HuffUnComp() |
| 516 | 423 |
{
|
| 517 |
-#ifdef GBA_LOGGING |
|
| 518 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 519 |
- log("HuffUnComp: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 520 |
- reg[0].I, |
|
| 521 |
- reg[1].I, |
|
| 522 |
- VCOUNT); |
|
| 523 |
- } |
|
| 524 |
-#endif |
|
| 525 |
- |
|
| 526 |
- uint32_t source = reg[0].I; |
|
| 527 |
- uint32_t dest = reg[1].I; |
|
| 528 |
- |
|
| 529 |
- uint32_t header = CPUReadMemory(source); |
|
| 530 |
- source += 4; |
|
| 531 |
- |
|
| 532 |
- if(((source & 0xe000000) == 0) || |
|
| 533 |
- ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 534 |
- return; |
|
| 535 |
- |
|
| 536 |
- uint8_t treeSize = CPUReadByte(source++); |
|
| 537 |
- |
|
| 538 |
- uint32_t treeStart = source; |
|
| 539 |
- |
|
| 540 |
- source += ((treeSize+1)<<1)-1; // minus because we already skipped one byte |
|
| 541 |
- |
|
| 542 |
- int len = header >> 8; |
|
| 543 |
- |
|
| 544 |
- uint32_t mask = 0x80000000; |
|
| 545 |
- uint32_t data = CPUReadMemory(source); |
|
| 546 |
- source += 4; |
|
| 547 |
- |
|
| 548 |
- int pos = 0; |
|
| 549 |
- uint8_t rootNode = CPUReadByte(treeStart); |
|
| 550 |
- uint8_t currentNode = rootNode; |
|
| 551 |
- bool writeData = false; |
|
| 552 |
- int byteShift = 0; |
|
| 553 |
- int byteCount = 0; |
|
| 554 |
- uint32_t writeValue = 0; |
|
| 555 |
- |
|
| 556 |
- if((header & 0x0F) == 8) {
|
|
| 557 |
- while(len > 0) {
|
|
| 558 |
- // take left |
|
| 559 |
- if(pos == 0) |
|
| 560 |
- pos++; |
|
| 561 |
- else |
|
| 562 |
- pos += (((currentNode & 0x3F)+1)<<1); |
|
| 563 |
- |
|
| 564 |
- if(data & mask) {
|
|
| 565 |
- // right |
|
| 566 |
- if(currentNode & 0x40) |
|
| 567 |
- writeData = true; |
|
| 568 |
- currentNode = CPUReadByte(treeStart+pos+1); |
|
| 569 |
- } else {
|
|
| 570 |
- // left |
|
| 571 |
- if(currentNode & 0x80) |
|
| 572 |
- writeData = true; |
|
| 573 |
- currentNode = CPUReadByte(treeStart+pos); |
|
| 574 |
- } |
|
| 575 |
- |
|
| 576 |
- if(writeData) {
|
|
| 577 |
- writeValue |= (currentNode << byteShift); |
|
| 578 |
- byteCount++; |
|
| 579 |
- byteShift += 8; |
|
| 580 |
- |
|
| 581 |
- pos = 0; |
|
| 582 |
- currentNode = rootNode; |
|
| 583 |
- writeData = false; |
|
| 584 |
- |
|
| 585 |
- if(byteCount == 4) {
|
|
| 586 |
- byteCount = 0; |
|
| 587 |
- byteShift = 0; |
|
| 588 |
- CPUWriteMemory(dest, writeValue); |
|
| 589 |
- writeValue = 0; |
|
| 590 |
- dest += 4; |
|
| 591 |
- len -= 4; |
|
| 592 |
- } |
|
| 593 |
- } |
|
| 594 |
- mask >>= 1; |
|
| 595 |
- if(mask == 0) {
|
|
| 596 |
- mask = 0x80000000; |
|
| 597 |
- data = CPUReadMemory(source); |
|
| 598 |
- source += 4; |
|
| 599 |
- } |
|
| 600 |
- } |
|
| 601 |
- } else {
|
|
| 602 |
- int halfLen = 0; |
|
| 603 |
- int value = 0; |
|
| 604 |
- while(len > 0) {
|
|
| 605 |
- // take left |
|
| 606 |
- if(pos == 0) |
|
| 607 |
- pos++; |
|
| 608 |
- else |
|
| 609 |
- pos += (((currentNode & 0x3F)+1)<<1); |
|
| 610 |
- |
|
| 611 |
- if((data & mask)) {
|
|
| 612 |
- // right |
|
| 613 |
- if(currentNode & 0x40) |
|
| 614 |
- writeData = true; |
|
| 615 |
- currentNode = CPUReadByte(treeStart+pos+1); |
|
| 616 |
- } else {
|
|
| 617 |
- // left |
|
| 618 |
- if(currentNode & 0x80) |
|
| 619 |
- writeData = true; |
|
| 620 |
- currentNode = CPUReadByte(treeStart+pos); |
|
| 621 |
- } |
|
| 622 |
- |
|
| 623 |
- if(writeData) {
|
|
| 624 |
- if(halfLen == 0) |
|
| 625 |
- value |= currentNode; |
|
| 626 |
- else |
|
| 627 |
- value |= (currentNode<<4); |
|
| 628 |
- |
|
| 629 |
- halfLen += 4; |
|
| 630 |
- if(halfLen == 8) {
|
|
| 631 |
- writeValue |= (value << byteShift); |
|
| 632 |
- byteCount++; |
|
| 633 |
- byteShift += 8; |
|
| 634 |
- |
|
| 635 |
- halfLen = 0; |
|
| 636 |
- value = 0; |
|
| 637 |
- |
|
| 638 |
- if(byteCount == 4) {
|
|
| 639 |
- byteCount = 0; |
|
| 640 |
- byteShift = 0; |
|
| 641 |
- CPUWriteMemory(dest, writeValue); |
|
| 642 |
- dest += 4; |
|
| 643 |
- writeValue = 0; |
|
| 644 |
- len -= 4; |
|
| 645 |
- } |
|
| 646 |
- } |
|
| 647 |
- pos = 0; |
|
| 648 |
- currentNode = rootNode; |
|
| 649 |
- writeData = false; |
|
| 650 |
- } |
|
| 651 |
- mask >>= 1; |
|
| 652 |
- if(mask == 0) {
|
|
| 653 |
- mask = 0x80000000; |
|
| 654 |
- data = CPUReadMemory(source); |
|
| 655 |
- source += 4; |
|
| 656 |
- } |
|
| 657 |
- } |
|
| 658 |
- } |
|
| 424 |
+ uint32_t source = reg[0].I; |
|
| 425 |
+ uint32_t dest = reg[1].I; |
|
| 426 |
+ |
|
| 427 |
+ uint32_t header = CPUReadMemory(source); |
|
| 428 |
+ source += 4; |
|
| 429 |
+ |
|
| 430 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 431 |
+ return; |
|
| 432 |
+ |
|
| 433 |
+ uint8_t treeSize = CPUReadByte(source++); |
|
| 434 |
+ |
|
| 435 |
+ uint32_t treeStart = source; |
|
| 436 |
+ |
|
| 437 |
+ source += ((treeSize + 1) << 1) - 1; // minus because we already skipped one byte |
|
| 438 |
+ |
|
| 439 |
+ int len = header >> 8; |
|
| 440 |
+ |
|
| 441 |
+ uint32_t mask = 0x80000000; |
|
| 442 |
+ uint32_t data = CPUReadMemory(source); |
|
| 443 |
+ source += 4; |
|
| 444 |
+ |
|
| 445 |
+ int pos = 0; |
|
| 446 |
+ uint8_t rootNode = CPUReadByte(treeStart); |
|
| 447 |
+ uint8_t currentNode = rootNode; |
|
| 448 |
+ bool writeData = false; |
|
| 449 |
+ int byteShift = 0; |
|
| 450 |
+ int byteCount = 0; |
|
| 451 |
+ uint32_t writeValue = 0; |
|
| 452 |
+ |
|
| 453 |
+ if ((header & 0x0F) == 8) |
|
| 454 |
+ {
|
|
| 455 |
+ while (len > 0) |
|
| 456 |
+ {
|
|
| 457 |
+ // take left |
|
| 458 |
+ if (!pos) |
|
| 459 |
+ ++pos; |
|
| 460 |
+ else |
|
| 461 |
+ pos += ((currentNode & 0x3F) + 1) << 1; |
|
| 462 |
+ |
|
| 463 |
+ if (data & mask) |
|
| 464 |
+ {
|
|
| 465 |
+ // right |
|
| 466 |
+ if (currentNode & 0x40) |
|
| 467 |
+ writeData = true; |
|
| 468 |
+ currentNode = CPUReadByte(treeStart + pos + 1); |
|
| 469 |
+ } |
|
| 470 |
+ else |
|
| 471 |
+ {
|
|
| 472 |
+ // left |
|
| 473 |
+ if (currentNode & 0x80) |
|
| 474 |
+ writeData = true; |
|
| 475 |
+ currentNode = CPUReadByte(treeStart + pos); |
|
| 476 |
+ } |
|
| 477 |
+ |
|
| 478 |
+ if (writeData) |
|
| 479 |
+ {
|
|
| 480 |
+ writeValue |= currentNode << byteShift; |
|
| 481 |
+ ++byteCount; |
|
| 482 |
+ byteShift += 8; |
|
| 483 |
+ |
|
| 484 |
+ pos = 0; |
|
| 485 |
+ currentNode = rootNode; |
|
| 486 |
+ writeData = false; |
|
| 487 |
+ |
|
| 488 |
+ if (byteCount == 4) |
|
| 489 |
+ {
|
|
| 490 |
+ byteCount = 0; |
|
| 491 |
+ byteShift = 0; |
|
| 492 |
+ CPUWriteMemory(dest, writeValue); |
|
| 493 |
+ writeValue = 0; |
|
| 494 |
+ dest += 4; |
|
| 495 |
+ len -= 4; |
|
| 496 |
+ } |
|
| 497 |
+ } |
|
| 498 |
+ mask >>= 1; |
|
| 499 |
+ if (!mask) |
|
| 500 |
+ {
|
|
| 501 |
+ mask = 0x80000000; |
|
| 502 |
+ data = CPUReadMemory(source); |
|
| 503 |
+ source += 4; |
|
| 504 |
+ } |
|
| 505 |
+ } |
|
| 506 |
+ } |
|
| 507 |
+ else |
|
| 508 |
+ {
|
|
| 509 |
+ int halfLen = 0; |
|
| 510 |
+ int value = 0; |
|
| 511 |
+ while (len > 0) |
|
| 512 |
+ {
|
|
| 513 |
+ // take left |
|
| 514 |
+ if (!pos) |
|
| 515 |
+ ++pos; |
|
| 516 |
+ else |
|
| 517 |
+ pos += ((currentNode & 0x3F) + 1) << 1; |
|
| 518 |
+ |
|
| 519 |
+ if (data & mask) |
|
| 520 |
+ {
|
|
| 521 |
+ // right |
|
| 522 |
+ if (currentNode & 0x40) |
|
| 523 |
+ writeData = true; |
|
| 524 |
+ currentNode = CPUReadByte(treeStart + pos + 1); |
|
| 525 |
+ } |
|
| 526 |
+ else |
|
| 527 |
+ {
|
|
| 528 |
+ // left |
|
| 529 |
+ if (currentNode & 0x80) |
|
| 530 |
+ writeData = true; |
|
| 531 |
+ currentNode = CPUReadByte(treeStart + pos); |
|
| 532 |
+ } |
|
| 533 |
+ |
|
| 534 |
+ if (writeData) |
|
| 535 |
+ {
|
|
| 536 |
+ if (!halfLen) |
|
| 537 |
+ value |= currentNode; |
|
| 538 |
+ else |
|
| 539 |
+ value |= currentNode << 4; |
|
| 540 |
+ |
|
| 541 |
+ halfLen += 4; |
|
| 542 |
+ if (halfLen == 8) |
|
| 543 |
+ {
|
|
| 544 |
+ writeValue |= value << byteShift; |
|
| 545 |
+ ++byteCount; |
|
| 546 |
+ byteShift += 8; |
|
| 547 |
+ |
|
| 548 |
+ halfLen = 0; |
|
| 549 |
+ value = 0; |
|
| 550 |
+ |
|
| 551 |
+ if (byteCount == 4) |
|
| 552 |
+ {
|
|
| 553 |
+ byteCount = 0; |
|
| 554 |
+ byteShift = 0; |
|
| 555 |
+ CPUWriteMemory(dest, writeValue); |
|
| 556 |
+ dest += 4; |
|
| 557 |
+ writeValue = 0; |
|
| 558 |
+ len -= 4; |
|
| 559 |
+ } |
|
| 560 |
+ } |
|
| 561 |
+ pos = 0; |
|
| 562 |
+ currentNode = rootNode; |
|
| 563 |
+ writeData = false; |
|
| 564 |
+ } |
|
| 565 |
+ mask >>= 1; |
|
| 566 |
+ if (!mask) |
|
| 567 |
+ {
|
|
| 568 |
+ mask = 0x80000000; |
|
| 569 |
+ data = CPUReadMemory(source); |
|
| 570 |
+ source += 4; |
|
| 571 |
+ } |
|
| 572 |
+ } |
|
| 573 |
+ } |
|
| 659 | 574 |
} |
| 660 | 575 |
|
| 661 | 576 |
void BIOS_LZ77UnCompVram() |
| 662 | 577 |
{
|
| 663 |
-#ifdef GBA_LOGGING |
|
| 664 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 665 |
- log("LZ77UnCompVram: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 666 |
- reg[0].I, |
|
| 667 |
- reg[1].I, |
|
| 668 |
- VCOUNT); |
|
| 669 |
- } |
|
| 670 |
-#endif |
|
| 671 |
- |
|
| 672 |
- uint32_t source = reg[0].I; |
|
| 673 |
- uint32_t dest = reg[1].I; |
|
| 674 |
- |
|
| 675 |
- uint32_t header = CPUReadMemory(source); |
|
| 676 |
- source += 4; |
|
| 677 |
- |
|
| 678 |
- if(((source & 0xe000000) == 0) || |
|
| 679 |
- ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 680 |
- return; |
|
| 681 |
- |
|
| 682 |
- int byteCount = 0; |
|
| 683 |
- int byteShift = 0; |
|
| 684 |
- uint32_t writeValue = 0; |
|
| 685 |
- |
|
| 686 |
- int len = header >> 8; |
|
| 687 |
- |
|
| 688 |
- while(len > 0) {
|
|
| 689 |
- uint8_t d = CPUReadByte(source++); |
|
| 690 |
- |
|
| 691 |
- if(d) {
|
|
| 692 |
- for(int i = 0; i < 8; i++) {
|
|
| 693 |
- if(d & 0x80) {
|
|
| 694 |
- uint16_t data = CPUReadByte(source++) << 8; |
|
| 695 |
- data |= CPUReadByte(source++); |
|
| 696 |
- int length = (data >> 12) + 3; |
|
| 697 |
- int offset = (data & 0x0FFF); |
|
| 698 |
- uint32_t windowOffset = dest + byteCount - offset - 1; |
|
| 699 |
- for(int i2 = 0; i2 < length; i2++) {
|
|
| 700 |
- writeValue |= (CPUReadByte(windowOffset++) << byteShift); |
|
| 701 |
- byteShift += 8; |
|
| 702 |
- byteCount++; |
|
| 703 |
- |
|
| 704 |
- if(byteCount == 2) {
|
|
| 705 |
- CPUWriteHalfWord(dest, writeValue); |
|
| 706 |
- dest += 2; |
|
| 707 |
- byteCount = 0; |
|
| 708 |
- byteShift = 0; |
|
| 709 |
- writeValue = 0; |
|
| 710 |
- } |
|
| 711 |
- len--; |
|
| 712 |
- if(len == 0) |
|
| 713 |
- return; |
|
| 714 |
- } |
|
| 715 |
- } else {
|
|
| 716 |
- writeValue |= (CPUReadByte(source++) << byteShift); |
|
| 717 |
- byteShift += 8; |
|
| 718 |
- byteCount++; |
|
| 719 |
- if(byteCount == 2) {
|
|
| 720 |
- CPUWriteHalfWord(dest, writeValue); |
|
| 721 |
- dest += 2; |
|
| 722 |
- byteCount = 0; |
|
| 723 |
- byteShift = 0; |
|
| 724 |
- writeValue = 0; |
|
| 725 |
- } |
|
| 726 |
- len--; |
|
| 727 |
- if(len == 0) |
|
| 728 |
- return; |
|
| 729 |
- } |
|
| 730 |
- d <<= 1; |
|
| 731 |
- } |
|
| 732 |
- } else {
|
|
| 733 |
- for(int i = 0; i < 8; i++) {
|
|
| 734 |
- writeValue |= (CPUReadByte(source++) << byteShift); |
|
| 735 |
- byteShift += 8; |
|
| 736 |
- byteCount++; |
|
| 737 |
- if(byteCount == 2) {
|
|
| 738 |
- CPUWriteHalfWord(dest, writeValue); |
|
| 739 |
- dest += 2; |
|
| 740 |
- byteShift = 0; |
|
| 741 |
- byteCount = 0; |
|
| 742 |
- writeValue = 0; |
|
| 743 |
- } |
|
| 744 |
- len--; |
|
| 745 |
- if(len == 0) |
|
| 746 |
- return; |
|
| 747 |
- } |
|
| 748 |
- } |
|
| 749 |
- } |
|
| 578 |
+ uint32_t source = reg[0].I; |
|
| 579 |
+ uint32_t dest = reg[1].I; |
|
| 580 |
+ |
|
| 581 |
+ uint32_t header = CPUReadMemory(source); |
|
| 582 |
+ source += 4; |
|
| 583 |
+ |
|
| 584 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 585 |
+ return; |
|
| 586 |
+ |
|
| 587 |
+ int byteCount = 0; |
|
| 588 |
+ int byteShift = 0; |
|
| 589 |
+ uint32_t writeValue = 0; |
|
| 590 |
+ |
|
| 591 |
+ int len = header >> 8; |
|
| 592 |
+ |
|
| 593 |
+ while (len > 0) |
|
| 594 |
+ {
|
|
| 595 |
+ uint8_t d = CPUReadByte(source++); |
|
| 596 |
+ |
|
| 597 |
+ if (d) |
|
| 598 |
+ {
|
|
| 599 |
+ for (int i = 0; i < 8; ++i) |
|
| 600 |
+ {
|
|
| 601 |
+ if (d & 0x80) |
|
| 602 |
+ {
|
|
| 603 |
+ uint16_t data = CPUReadByte(source++) << 8; |
|
| 604 |
+ data |= CPUReadByte(source++); |
|
| 605 |
+ int length = (data >> 12) + 3; |
|
| 606 |
+ int offset = data & 0x0FFF; |
|
| 607 |
+ uint32_t windowOffset = dest + byteCount - offset - 1; |
|
| 608 |
+ for (int i2 = 0; i2 < length; ++i2) |
|
| 609 |
+ {
|
|
| 610 |
+ writeValue |= CPUReadByte(windowOffset++) << byteShift; |
|
| 611 |
+ byteShift += 8; |
|
| 612 |
+ ++byteCount; |
|
| 613 |
+ |
|
| 614 |
+ if (byteCount == 2) |
|
| 615 |
+ {
|
|
| 616 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 617 |
+ dest += 2; |
|
| 618 |
+ byteCount = 0; |
|
| 619 |
+ byteShift = 0; |
|
| 620 |
+ writeValue = 0; |
|
| 621 |
+ } |
|
| 622 |
+ --len; |
|
| 623 |
+ if (!len) |
|
| 624 |
+ return; |
|
| 625 |
+ } |
|
| 626 |
+ } |
|
| 627 |
+ else |
|
| 628 |
+ {
|
|
| 629 |
+ writeValue |= CPUReadByte(source++) << byteShift; |
|
| 630 |
+ byteShift += 8; |
|
| 631 |
+ ++byteCount; |
|
| 632 |
+ if (byteCount == 2) |
|
| 633 |
+ {
|
|
| 634 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 635 |
+ dest += 2; |
|
| 636 |
+ byteCount = 0; |
|
| 637 |
+ byteShift = 0; |
|
| 638 |
+ writeValue = 0; |
|
| 639 |
+ } |
|
| 640 |
+ --len; |
|
| 641 |
+ if (!len) |
|
| 642 |
+ return; |
|
| 643 |
+ } |
|
| 644 |
+ d <<= 1; |
|
| 645 |
+ } |
|
| 646 |
+ } |
|
| 647 |
+ else |
|
| 648 |
+ {
|
|
| 649 |
+ for (int i = 0; i < 8; ++i) |
|
| 650 |
+ {
|
|
| 651 |
+ writeValue |= CPUReadByte(source++) << byteShift; |
|
| 652 |
+ byteShift += 8; |
|
| 653 |
+ ++byteCount; |
|
| 654 |
+ if (byteCount == 2) |
|
| 655 |
+ {
|
|
| 656 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 657 |
+ dest += 2; |
|
| 658 |
+ byteShift = 0; |
|
| 659 |
+ byteCount = 0; |
|
| 660 |
+ writeValue = 0; |
|
| 661 |
+ } |
|
| 662 |
+ --len; |
|
| 663 |
+ if (!len) |
|
| 664 |
+ return; |
|
| 665 |
+ } |
|
| 666 |
+ } |
|
| 667 |
+ } |
|
| 750 | 668 |
} |
| 751 | 669 |
|
| 752 | 670 |
void BIOS_LZ77UnCompWram() |
| 753 | 671 |
{
|
| 754 |
-#ifdef GBA_LOGGING |
|
| 755 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 756 |
- log("LZ77UnCompWram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
|
|
| 757 |
- VCOUNT); |
|
| 758 |
- } |
|
| 759 |
-#endif |
|
| 760 |
- |
|
| 761 |
- uint32_t source = reg[0].I; |
|
| 762 |
- uint32_t dest = reg[1].I; |
|
| 763 |
- |
|
| 764 |
- uint32_t header = CPUReadMemory(source); |
|
| 765 |
- source += 4; |
|
| 766 |
- |
|
| 767 |
- if(((source & 0xe000000) == 0) || |
|
| 768 |
- ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 769 |
- return; |
|
| 770 |
- |
|
| 771 |
- int len = header >> 8; |
|
| 772 |
- |
|
| 773 |
- while(len > 0) {
|
|
| 774 |
- uint8_t d = CPUReadByte(source++); |
|
| 775 |
- |
|
| 776 |
- if(d) {
|
|
| 777 |
- for(int i = 0; i < 8; i++) {
|
|
| 778 |
- if(d & 0x80) {
|
|
| 779 |
- uint16_t data = CPUReadByte(source++) << 8; |
|
| 780 |
- data |= CPUReadByte(source++); |
|
| 781 |
- int length = (data >> 12) + 3; |
|
| 782 |
- int offset = (data & 0x0FFF); |
|
| 783 |
- uint32_t windowOffset = dest - offset - 1; |
|
| 784 |
- for(int i2 = 0; i2 < length; i2++) {
|
|
| 785 |
- CPUWriteByte(dest++, CPUReadByte(windowOffset++)); |
|
| 786 |
- len--; |
|
| 787 |
- if(len == 0) |
|
| 788 |
- return; |
|
| 789 |
- } |
|
| 790 |
- } else {
|
|
| 791 |
- CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 792 |
- len--; |
|
| 793 |
- if(len == 0) |
|
| 794 |
- return; |
|
| 795 |
- } |
|
| 796 |
- d <<= 1; |
|
| 797 |
- } |
|
| 798 |
- } else {
|
|
| 799 |
- for(int i = 0; i < 8; i++) {
|
|
| 800 |
- CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 801 |
- len--; |
|
| 802 |
- if(len == 0) |
|
| 803 |
- return; |
|
| 804 |
- } |
|
| 805 |
- } |
|
| 806 |
- } |
|
| 672 |
+ uint32_t source = reg[0].I; |
|
| 673 |
+ uint32_t dest = reg[1].I; |
|
| 674 |
+ |
|
| 675 |
+ uint32_t header = CPUReadMemory(source); |
|
| 676 |
+ source += 4; |
|
| 677 |
+ |
|
| 678 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 679 |
+ return; |
|
| 680 |
+ |
|
| 681 |
+ int len = header >> 8; |
|
| 682 |
+ |
|
| 683 |
+ while (len > 0) |
|
| 684 |
+ {
|
|
| 685 |
+ uint8_t d = CPUReadByte(source++); |
|
| 686 |
+ |
|
| 687 |
+ if (d) |
|
| 688 |
+ {
|
|
| 689 |
+ for (int i = 0; i < 8; ++i) |
|
| 690 |
+ {
|
|
| 691 |
+ if (d & 0x80) |
|
| 692 |
+ {
|
|
| 693 |
+ uint16_t data = CPUReadByte(source++) << 8; |
|
| 694 |
+ data |= CPUReadByte(source++); |
|
| 695 |
+ int length = (data >> 12) + 3; |
|
| 696 |
+ int offset = data & 0x0FFF; |
|
| 697 |
+ uint32_t windowOffset = dest - offset - 1; |
|
| 698 |
+ for (int i2 = 0; i2 < length; ++i2) |
|
| 699 |
+ {
|
|
| 700 |
+ CPUWriteByte(dest++, CPUReadByte(windowOffset++)); |
|
| 701 |
+ --len; |
|
| 702 |
+ if (!len) |
|
| 703 |
+ return; |
|
| 704 |
+ } |
|
| 705 |
+ } |
|
| 706 |
+ else |
|
| 707 |
+ {
|
|
| 708 |
+ CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 709 |
+ --len; |
|
| 710 |
+ if (!len) |
|
| 711 |
+ return; |
|
| 712 |
+ } |
|
| 713 |
+ d <<= 1; |
|
| 714 |
+ } |
|
| 715 |
+ } |
|
| 716 |
+ else |
|
| 717 |
+ {
|
|
| 718 |
+ for (int i = 0; i < 8; ++i) |
|
| 719 |
+ {
|
|
| 720 |
+ CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 721 |
+ --len; |
|
| 722 |
+ if (!len) |
|
| 723 |
+ return; |
|
| 724 |
+ } |
|
| 725 |
+ } |
|
| 726 |
+ } |
|
| 807 | 727 |
} |
| 808 | 728 |
|
| 809 | 729 |
void BIOS_ObjAffineSet() |
| 810 | 730 |
{
|
| 811 |
-#ifdef GBA_LOGGING |
|
| 812 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 813 |
- log("ObjAffineSet: 0x%08x,0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 814 |
- reg[0].I, |
|
| 815 |
- reg[1].I, |
|
| 816 |
- reg[2].I, |
|
| 817 |
- reg[3].I, |
|
| 818 |
- VCOUNT); |
|
| 819 |
- } |
|
| 820 |
-#endif |
|
| 821 |
- |
|
| 822 |
- uint32_t src = reg[0].I; |
|
| 823 |
- uint32_t dest = reg[1].I; |
|
| 824 |
- int num = reg[2].I; |
|
| 825 |
- int offset = reg[3].I; |
|
| 826 |
- |
|
| 827 |
- for(int i = 0; i < num; i++) {
|
|
| 828 |
- int16_t rx = CPUReadHalfWord(src); |
|
| 829 |
- src+=2; |
|
| 830 |
- int16_t ry = CPUReadHalfWord(src); |
|
| 831 |
- src+=2; |
|
| 832 |
- uint16_t theta = CPUReadHalfWord(src)>>8; |
|
| 833 |
- src+=4; // keep structure alignment |
|
| 834 |
- |
|
| 835 |
- int32_t a = (int32_t)sineTable[(theta+0x40)&255]; |
|
| 836 |
- int32_t b = (int32_t)sineTable[theta]; |
|
| 837 |
- |
|
| 838 |
- int16_t dx = ((int32_t)rx * a)>>14; |
|
| 839 |
- int16_t dmx = ((int32_t)rx * b)>>14; |
|
| 840 |
- int16_t dy = ((int32_t)ry * b)>>14; |
|
| 841 |
- int16_t dmy = ((int32_t)ry * a)>>14; |
|
| 842 |
- |
|
| 843 |
- CPUWriteHalfWord(dest, dx); |
|
| 844 |
- dest += offset; |
|
| 845 |
- CPUWriteHalfWord(dest, -dmx); |
|
| 846 |
- dest += offset; |
|
| 847 |
- CPUWriteHalfWord(dest, dy); |
|
| 848 |
- dest += offset; |
|
| 849 |
- CPUWriteHalfWord(dest, dmy); |
|
| 850 |
- dest += offset; |
|
| 851 |
- } |
|
| 731 |
+ uint32_t src = reg[0].I; |
|
| 732 |
+ uint32_t dest = reg[1].I; |
|
| 733 |
+ int num = reg[2].I; |
|
| 734 |
+ int offset = reg[3].I; |
|
| 735 |
+ |
|
| 736 |
+ for (int i = 0; i < num; ++i) |
|
| 737 |
+ {
|
|
| 738 |
+ int16_t rx = CPUReadHalfWord(src); |
|
| 739 |
+ src += 2; |
|
| 740 |
+ int16_t ry = CPUReadHalfWord(src); |
|
| 741 |
+ src += 2; |
|
| 742 |
+ uint16_t theta = CPUReadHalfWord(src) >> 8; |
|
| 743 |
+ src += 4; // keep structure alignment |
|
| 744 |
+ |
|
| 745 |
+ int32_t a = sineTable[(theta + 0x40) & 255]; |
|
| 746 |
+ int32_t b = sineTable[theta]; |
|
| 747 |
+ |
|
| 748 |
+ int16_t dx = (static_cast<int32_t>(rx) * a) >> 14; |
|
| 749 |
+ int16_t dmx = (static_cast<int32_t>(rx) * b) >> 14; |
|
| 750 |
+ int16_t dy = (static_cast<int32_t>(ry) * b) >> 14; |
|
| 751 |
+ int16_t dmy = (static_cast<int32_t>(ry) * a) >> 14; |
|
| 752 |
+ |
|
| 753 |
+ CPUWriteHalfWord(dest, dx); |
|
| 754 |
+ dest += offset; |
|
| 755 |
+ CPUWriteHalfWord(dest, -dmx); |
|
| 756 |
+ dest += offset; |
|
| 757 |
+ CPUWriteHalfWord(dest, dy); |
|
| 758 |
+ dest += offset; |
|
| 759 |
+ CPUWriteHalfWord(dest, dmy); |
|
| 760 |
+ dest += offset; |
|
| 761 |
+ } |
|
| 852 | 762 |
} |
| 853 | 763 |
|
| 854 | 764 |
void BIOS_RegisterRamReset(uint32_t flags) |
| 855 | 765 |
{
|
| 856 |
- // no need to trace here. this is only called directly from GBA.cpp |
|
| 857 |
- // to emulate bios initialization |
|
| 858 |
- |
|
| 859 |
- CPUUpdateRegister(0x0, 0x80); |
|
| 860 |
- |
|
| 861 |
- if(flags) {
|
|
| 862 |
- if(flags & 0x01) {
|
|
| 863 |
- // clear work RAM |
|
| 864 |
- memset(workRAM, 0, 0x40000); |
|
| 865 |
- } |
|
| 866 |
- if(flags & 0x02) {
|
|
| 867 |
- // clear internal RAM |
|
| 868 |
- memset(internalRAM, 0, 0x7e00); // don't clear 0x7e00-0x7fff |
|
| 869 |
- } |
|
| 870 |
- if(flags & 0x04) {
|
|
| 871 |
- // clear palette RAM |
|
| 872 |
- memset(paletteRAM, 0, 0x400); |
|
| 873 |
- } |
|
| 874 |
- if(flags & 0x08) {
|
|
| 875 |
- // clear VRAM |
|
| 876 |
- memset(vram, 0, 0x18000); |
|
| 877 |
- } |
|
| 878 |
- if(flags & 0x10) {
|
|
| 879 |
- // clean OAM |
|
| 880 |
- memset(oam, 0, 0x400); |
|
| 881 |
- } |
|
| 882 |
- |
|
| 883 |
- if(flags & 0x80) {
|
|
| 884 |
- int i; |
|
| 885 |
- for(i = 0; i < 0x10; i++) |
|
| 886 |
- CPUUpdateRegister(0x200+i*2, 0); |
|
| 887 |
- |
|
| 888 |
- for(i = 0; i < 0xF; i++) |
|
| 889 |
- CPUUpdateRegister(0x4+i*2, 0); |
|
| 890 |
- |
|
| 891 |
- for(i = 0; i < 0x20; i++) |
|
| 892 |
- CPUUpdateRegister(0x20+i*2, 0); |
|
| 893 |
- |
|
| 894 |
- for(i = 0; i < 0x18; i++) |
|
| 895 |
- CPUUpdateRegister(0xb0+i*2, 0); |
|
| 896 |
- |
|
| 897 |
- CPUUpdateRegister(0x130, 0); |
|
| 898 |
- CPUUpdateRegister(0x20, 0x100); |
|
| 899 |
- CPUUpdateRegister(0x30, 0x100); |
|
| 900 |
- CPUUpdateRegister(0x26, 0x100); |
|
| 901 |
- CPUUpdateRegister(0x36, 0x100); |
|
| 902 |
- } |
|
| 903 |
- |
|
| 904 |
- if(flags & 0x20) {
|
|
| 905 |
- int i; |
|
| 906 |
- for(i = 0; i < 8; i++) |
|
| 907 |
- CPUUpdateRegister(0x110+i*2, 0); |
|
| 908 |
- CPUUpdateRegister(0x134, 0x8000); |
|
| 909 |
- for(i = 0; i < 7; i++) |
|
| 910 |
- CPUUpdateRegister(0x140+i*2, 0); |
|
| 911 |
- } |
|
| 912 |
- |
|
| 913 |
- if(flags & 0x40) {
|
|
| 914 |
- int i; |
|
| 915 |
- CPUWriteByte(0x4000084, 0); |
|
| 916 |
- CPUWriteByte(0x4000084, 0x80); |
|
| 917 |
- CPUWriteMemory(0x4000080, 0x880e0000); |
|
| 918 |
- CPUUpdateRegister(0x88, CPUReadHalfWord(0x4000088)&0x3ff); |
|
| 919 |
- CPUWriteByte(0x4000070, 0x70); |
|
| 920 |
- for(i = 0; i < 8; i++) |
|
| 921 |
- CPUUpdateRegister(0x90+i*2, 0); |
|
| 922 |
- CPUWriteByte(0x4000070, 0); |
|
| 923 |
- for(i = 0; i < 8; i++) |
|
| 924 |
- CPUUpdateRegister(0x90+i*2, 0); |
|
| 925 |
- CPUWriteByte(0x4000084, 0); |
|
| 926 |
- } |
|
| 927 |
- } |
|
| 766 |
+ // no need to trace here. this is only called directly from GBA.cpp |
|
| 767 |
+ // to emulate bios initialization |
|
| 768 |
+ |
|
| 769 |
+ CPUUpdateRegister(0x0, 0x80); |
|
| 770 |
+ |
|
| 771 |
+ if (flags) |
|
| 772 |
+ {
|
|
| 773 |
+ if (flags & 0x01) |
|
| 774 |
+ // clear work RAM |
|
| 775 |
+ memset(&workRAM[0], 0, 0x40000); |
|
| 776 |
+ if (flags & 0x02) |
|
| 777 |
+ // clear internal RAM |
|
| 778 |
+ memset(&internalRAM[0], 0, 0x7e00); // don't clear 0x7e00-0x7fff |
|
| 779 |
+ if (flags & 0x04) |
|
| 780 |
+ // clear palette RAM |
|
| 781 |
+ memset(&paletteRAM[0], 0, 0x400); |
|
| 782 |
+ if (flags & 0x08) |
|
| 783 |
+ // clear VRAM |
|
| 784 |
+ memset(&vram[0], 0, 0x18000); |
|
| 785 |
+ if (flags & 0x10) |
|
| 786 |
+ // clean OAM |
|
| 787 |
+ memset(&oam[0], 0, 0x400); |
|
| 788 |
+ |
|
| 789 |
+ if (flags & 0x80) |
|
| 790 |
+ {
|
|
| 791 |
+ int i; |
|
| 792 |
+ for (i = 0; i < 0x10; ++i) |
|
| 793 |
+ CPUUpdateRegister(0x200 + i * 2, 0); |
|
| 794 |
+ |
|
| 795 |
+ for (i = 0; i < 0xF; ++i) |
|
| 796 |
+ CPUUpdateRegister(0x4 + i * 2, 0); |
|
| 797 |
+ |
|
| 798 |
+ for (i = 0; i < 0x20; ++i) |
|
| 799 |
+ CPUUpdateRegister(0x20 + i * 2, 0); |
|
| 800 |
+ |
|
| 801 |
+ for (i = 0; i < 0x18; ++i) |
|
| 802 |
+ CPUUpdateRegister(0xb0 + i * 2, 0); |
|
| 803 |
+ |
|
| 804 |
+ CPUUpdateRegister(0x130, 0); |
|
| 805 |
+ CPUUpdateRegister(0x20, 0x100); |
|
| 806 |
+ CPUUpdateRegister(0x30, 0x100); |
|
| 807 |
+ CPUUpdateRegister(0x26, 0x100); |
|
| 808 |
+ CPUUpdateRegister(0x36, 0x100); |
|
| 809 |
+ } |
|
| 810 |
+ |
|
| 811 |
+ if (flags & 0x20) |
|
| 812 |
+ {
|
|
| 813 |
+ int i; |
|
| 814 |
+ for (i = 0; i < 8; ++i) |
|
| 815 |
+ CPUUpdateRegister(0x110 + i * 2, 0); |
|
| 816 |
+ CPUUpdateRegister(0x134, 0x8000); |
|
| 817 |
+ for (i = 0; i < 7; ++i) |
|
| 818 |
+ CPUUpdateRegister(0x140 + i * 2, 0); |
|
| 819 |
+ } |
|
| 820 |
+ |
|
| 821 |
+ if (flags & 0x40) |
|
| 822 |
+ {
|
|
| 823 |
+ CPUWriteByte(0x4000084, 0); |
|
| 824 |
+ CPUWriteByte(0x4000084, 0x80); |
|
| 825 |
+ CPUWriteMemory(0x4000080, 0x880e0000); |
|
| 826 |
+ CPUUpdateRegister(0x88, CPUReadHalfWord(0x4000088) & 0x3ff); |
|
| 827 |
+ CPUWriteByte(0x4000070, 0x70); |
|
| 828 |
+ int i; |
|
| 829 |
+ for (i = 0; i < 8; ++i) |
|
| 830 |
+ CPUUpdateRegister(0x90 + i * 2, 0); |
|
| 831 |
+ CPUWriteByte(0x4000070, 0); |
|
| 832 |
+ for (i = 0; i < 8; ++i) |
|
| 833 |
+ CPUUpdateRegister(0x90 + i * 2, 0); |
|
| 834 |
+ CPUWriteByte(0x4000084, 0); |
|
| 835 |
+ } |
|
| 836 |
+ } |
|
| 928 | 837 |
} |
| 929 | 838 |
|
| 930 | 839 |
void BIOS_RegisterRamReset() |
| 931 | 840 |
{
|
| 932 |
-#ifdef GBA_LOGGING |
|
| 933 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 934 |
- log("RegisterRamReset: 0x%08x (VCOUNT=%d)\n",
|
|
| 935 |
- reg[0].I, |
|
| 936 |
- VCOUNT); |
|
| 937 |
- } |
|
| 938 |
-#endif |
|
| 939 |
- |
|
| 940 |
- BIOS_RegisterRamReset(reg[0].I); |
|
| 841 |
+ BIOS_RegisterRamReset(reg[0].I); |
|
| 941 | 842 |
} |
| 942 | 843 |
|
| 943 | 844 |
void BIOS_RLUnCompVram() |
| 944 | 845 |
{
|
| 945 |
-#ifdef GBA_LOGGING |
|
| 946 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 947 |
- log("RLUnCompVram: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 948 |
- reg[0].I, |
|
| 949 |
- reg[1].I, |
|
| 950 |
- VCOUNT); |
|
| 951 |
- } |
|
| 952 |
-#endif |
|
| 953 |
- |
|
| 954 |
- uint32_t source = reg[0].I; |
|
| 955 |
- uint32_t dest = reg[1].I; |
|
| 956 |
- |
|
| 957 |
- uint32_t header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 958 |
- source += 4; |
|
| 959 |
- |
|
| 960 |
- if(((source & 0xe000000) == 0) || |
|
| 961 |
- ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 962 |
- return; |
|
| 963 |
- |
|
| 964 |
- int len = header >> 8; |
|
| 965 |
- int byteCount = 0; |
|
| 966 |
- int byteShift = 0; |
|
| 967 |
- uint32_t writeValue = 0; |
|
| 968 |
- |
|
| 969 |
- while(len > 0) {
|
|
| 970 |
- uint8_t d = CPUReadByte(source++); |
|
| 971 |
- int l = d & 0x7F; |
|
| 972 |
- if(d & 0x80) {
|
|
| 973 |
- uint8_t data = CPUReadByte(source++); |
|
| 974 |
- l += 3; |
|
| 975 |
- for(int i = 0;i < l; i++) {
|
|
| 976 |
- writeValue |= (data << byteShift); |
|
| 977 |
- byteShift += 8; |
|
| 978 |
- byteCount++; |
|
| 979 |
- |
|
| 980 |
- if(byteCount == 2) {
|
|
| 981 |
- CPUWriteHalfWord(dest, writeValue); |
|
| 982 |
- dest += 2; |
|
| 983 |
- byteCount = 0; |
|
| 984 |
- byteShift = 0; |
|
| 985 |
- writeValue = 0; |
|
| 986 |
- } |
|
| 987 |
- len--; |
|
| 988 |
- if(len == 0) |
|
| 989 |
- return; |
|
| 990 |
- } |
|
| 991 |
- } else {
|
|
| 992 |
- l++; |
|
| 993 |
- for(int i = 0; i < l; i++) {
|
|
| 994 |
- writeValue |= (CPUReadByte(source++) << byteShift); |
|
| 995 |
- byteShift += 8; |
|
| 996 |
- byteCount++; |
|
| 997 |
- if(byteCount == 2) {
|
|
| 998 |
- CPUWriteHalfWord(dest, writeValue); |
|
| 999 |
- dest += 2; |
|
| 1000 |
- byteCount = 0; |
|
| 1001 |
- byteShift = 0; |
|
| 1002 |
- writeValue = 0; |
|
| 1003 |
- } |
|
| 1004 |
- len--; |
|
| 1005 |
- if(len == 0) |
|
| 1006 |
- return; |
|
| 1007 |
- } |
|
| 1008 |
- } |
|
| 1009 |
- } |
|
| 846 |
+ uint32_t source = reg[0].I; |
|
| 847 |
+ uint32_t dest = reg[1].I; |
|
| 848 |
+ |
|
| 849 |
+ uint32_t header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 850 |
+ source += 4; |
|
| 851 |
+ |
|
| 852 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 853 |
+ return; |
|
| 854 |
+ |
|
| 855 |
+ int len = header >> 8; |
|
| 856 |
+ int byteCount = 0; |
|
| 857 |
+ int byteShift = 0; |
|
| 858 |
+ uint32_t writeValue = 0; |
|
| 859 |
+ |
|
| 860 |
+ while (len > 0) |
|
| 861 |
+ {
|
|
| 862 |
+ uint8_t d = CPUReadByte(source++); |
|
| 863 |
+ int l = d & 0x7F; |
|
| 864 |
+ if (d & 0x80) |
|
| 865 |
+ {
|
|
| 866 |
+ uint8_t data = CPUReadByte(source++); |
|
| 867 |
+ l += 3; |
|
| 868 |
+ for (int i = 0;i < l; ++i) |
|
| 869 |
+ {
|
|
| 870 |
+ writeValue |= data << byteShift; |
|
| 871 |
+ byteShift += 8; |
|
| 872 |
+ ++byteCount; |
|
| 873 |
+ |
|
| 874 |
+ if (byteCount == 2) |
|
| 875 |
+ {
|
|
| 876 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 877 |
+ dest += 2; |
|
| 878 |
+ byteCount = 0; |
|
| 879 |
+ byteShift = 0; |
|
| 880 |
+ writeValue = 0; |
|
| 881 |
+ } |
|
| 882 |
+ --len; |
|
| 883 |
+ if (!len) |
|
| 884 |
+ return; |
|
| 885 |
+ } |
|
| 886 |
+ } |
|
| 887 |
+ else |
|
| 888 |
+ {
|
|
| 889 |
+ ++l; |
|
| 890 |
+ for (int i = 0; i < l; ++i) |
|
| 891 |
+ {
|
|
| 892 |
+ writeValue |= CPUReadByte(source++) << byteShift; |
|
| 893 |
+ byteShift += 8; |
|
| 894 |
+ ++byteCount; |
|
| 895 |
+ if (byteCount == 2) |
|
| 896 |
+ {
|
|
| 897 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 898 |
+ dest += 2; |
|
| 899 |
+ byteCount = 0; |
|
| 900 |
+ byteShift = 0; |
|
| 901 |
+ writeValue = 0; |
|
| 902 |
+ } |
|
| 903 |
+ --len; |
|
| 904 |
+ if (!len) |
|
| 905 |
+ return; |
|
| 906 |
+ } |
|
| 907 |
+ } |
|
| 908 |
+ } |
|
| 1010 | 909 |
} |
| 1011 | 910 |
|
| 1012 | 911 |
void BIOS_RLUnCompWram() |
| 1013 | 912 |
{
|
| 1014 |
-#ifdef GBA_LOGGING |
|
| 1015 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 1016 |
- log("RLUnCompWram: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 1017 |
- reg[0].I, |
|
| 1018 |
- reg[1].I, |
|
| 1019 |
- VCOUNT); |
|
| 1020 |
- } |
|
| 1021 |
-#endif |
|
| 1022 |
- |
|
| 1023 |
- uint32_t source = reg[0].I; |
|
| 1024 |
- uint32_t dest = reg[1].I; |
|
| 1025 |
- |
|
| 1026 |
- uint32_t header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 1027 |
- source += 4; |
|
| 1028 |
- |
|
| 1029 |
- if(((source & 0xe000000) == 0) || |
|
| 1030 |
- ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 1031 |
- return; |
|
| 1032 |
- |
|
| 1033 |
- int len = header >> 8; |
|
| 1034 |
- |
|
| 1035 |
- while(len > 0) {
|
|
| 1036 |
- uint8_t d = CPUReadByte(source++); |
|
| 1037 |
- int l = d & 0x7F; |
|
| 1038 |
- if(d & 0x80) {
|
|
| 1039 |
- uint8_t data = CPUReadByte(source++); |
|
| 1040 |
- l += 3; |
|
| 1041 |
- for(int i = 0;i < l; i++) {
|
|
| 1042 |
- CPUWriteByte(dest++, data); |
|
| 1043 |
- len--; |
|
| 1044 |
- if(len == 0) |
|
| 1045 |
- return; |
|
| 1046 |
- } |
|
| 1047 |
- } else {
|
|
| 1048 |
- l++; |
|
| 1049 |
- for(int i = 0; i < l; i++) {
|
|
| 1050 |
- CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 1051 |
- len--; |
|
| 1052 |
- if(len == 0) |
|
| 1053 |
- return; |
|
| 1054 |
- } |
|
| 1055 |
- } |
|
| 1056 |
- } |
|
| 913 |
+ uint32_t source = reg[0].I; |
|
| 914 |
+ uint32_t dest = reg[1].I; |
|
| 915 |
+ |
|
| 916 |
+ uint32_t header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 917 |
+ source += 4; |
|
| 918 |
+ |
|
| 919 |
+ if (!(source & 0xe000000) || !((source + ((header >> 8) & 0x1fffff)) & 0xe000000)) |
|
| 920 |
+ return; |
|
| 921 |
+ |
|
| 922 |
+ int len = header >> 8; |
|
| 923 |
+ |
|
| 924 |
+ while (len > 0) |
|
| 925 |
+ {
|
|
| 926 |
+ uint8_t d = CPUReadByte(source++); |
|
| 927 |
+ int l = d & 0x7F; |
|
| 928 |
+ if (d & 0x80) |
|
| 929 |
+ {
|
|
| 930 |
+ uint8_t data = CPUReadByte(source++); |
|
| 931 |
+ l += 3; |
|
| 932 |
+ for (int i = 0; i < l; ++i) |
|
| 933 |
+ {
|
|
| 934 |
+ CPUWriteByte(dest++, data); |
|
| 935 |
+ --len; |
|
| 936 |
+ if (!len) |
|
| 937 |
+ return; |
|
| 938 |
+ } |
|
| 939 |
+ } |
|
| 940 |
+ else |
|
| 941 |
+ {
|
|
| 942 |
+ ++l; |
|
| 943 |
+ for (int i = 0; i < l; ++i) |
|
| 944 |
+ {
|
|
| 945 |
+ CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 946 |
+ --len; |
|
| 947 |
+ if (!len) |
|
| 948 |
+ return; |
|
| 949 |
+ } |
|
| 950 |
+ } |
|
| 951 |
+ } |
|
| 1057 | 952 |
} |
| 1058 | 953 |
|
| 1059 | 954 |
void BIOS_SoftReset() |
| 1060 | 955 |
{
|
| 1061 |
-#ifdef GBA_LOGGING |
|
| 1062 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 1063 |
- log("SoftReset: (VCOUNT=%d)\n", VCOUNT);
|
|
| 1064 |
- } |
|
| 1065 |
-#endif |
|
| 1066 |
- |
|
| 1067 |
- armState = true; |
|
| 1068 |
- armMode = 0x1F; |
|
| 1069 |
- armIrqEnable = false; |
|
| 1070 |
- C_FLAG = V_FLAG = N_FLAG = Z_FLAG = false; |
|
| 1071 |
- reg[13].I = 0x03007F00; |
|
| 1072 |
- reg[14].I = 0x00000000; |
|
| 1073 |
- reg[16].I = 0x00000000; |
|
| 1074 |
- reg[R13_IRQ].I = 0x03007FA0; |
|
| 1075 |
- reg[R14_IRQ].I = 0x00000000; |
|
| 1076 |
- reg[SPSR_IRQ].I = 0x00000000; |
|
| 1077 |
- reg[R13_SVC].I = 0x03007FE0; |
|
| 1078 |
- reg[R14_SVC].I = 0x00000000; |
|
| 1079 |
- reg[SPSR_SVC].I = 0x00000000; |
|
| 1080 |
- uint8_t b = internalRAM[0x7ffa]; |
|
| 1081 |
- |
|
| 1082 |
- memset(&internalRAM[0x7e00], 0, 0x200); |
|
| 1083 |
- |
|
| 1084 |
- if(b) {
|
|
| 1085 |
- armNextPC = 0x02000000; |
|
| 1086 |
- reg[15].I = 0x02000004; |
|
| 1087 |
- } else {
|
|
| 1088 |
- armNextPC = 0x08000000; |
|
| 1089 |
- reg[15].I = 0x08000004; |
|
| 1090 |
- } |
|
| 956 |
+ armState = true; |
|
| 957 |
+ armMode = 0x1F; |
|
| 958 |
+ armIrqEnable = false; |
|
| 959 |
+ C_FLAG = V_FLAG = N_FLAG = Z_FLAG = false; |
|
| 960 |
+ reg[13].I = 0x03007F00; |
|
| 961 |
+ reg[14].I = 0x00000000; |
|
| 962 |
+ reg[16].I = 0x00000000; |
|
| 963 |
+ reg[R13_IRQ].I = 0x03007FA0; |
|
| 964 |
+ reg[R14_IRQ].I = 0x00000000; |
|
| 965 |
+ reg[SPSR_IRQ].I = 0x00000000; |
|
| 966 |
+ reg[R13_SVC].I = 0x03007FE0; |
|
| 967 |
+ reg[R14_SVC].I = 0x00000000; |
|
| 968 |
+ reg[SPSR_SVC].I = 0x00000000; |
|
| 969 |
+ uint8_t b = internalRAM[0x7ffa]; |
|
| 970 |
+ |
|
| 971 |
+ memset(&internalRAM[0x7e00], 0, 0x200); |
|
| 972 |
+ |
|
| 973 |
+ if (b) |
|
| 974 |
+ {
|
|
| 975 |
+ armNextPC = 0x02000000; |
|
| 976 |
+ reg[15].I = 0x02000004; |
|
| 977 |
+ } |
|
| 978 |
+ else |
|
| 979 |
+ {
|
|
| 980 |
+ armNextPC = 0x08000000; |
|
| 981 |
+ reg[15].I = 0x08000004; |
|
| 982 |
+ } |
|
| 1091 | 983 |
} |
| 1092 | 984 |
|
| 1093 | 985 |
void BIOS_Sqrt() |
| 1094 | 986 |
{
|
| 1095 |
-#ifdef GBA_LOGGING |
|
| 1096 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 1097 |
- log("Sqrt: %08x (VCOUNT=%2d)\n",
|
|
| 1098 |
- reg[0].I, |
|
| 1099 |
- VCOUNT); |
|
| 1100 |
- } |
|
| 1101 |
-#endif |
|
| 1102 |
- reg[0].I = (uint32_t)sqrt((double)reg[0].I); |
|
| 1103 |
-#ifdef GBA_LOGGING |
|
| 1104 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 1105 |
- log("Sqrt: return=%08x\n",
|
|
| 1106 |
- reg[0].I); |
|
| 1107 |
- } |
|
| 1108 |
-#endif |
|
| 987 |
+ reg[0].I = static_cast<uint32_t>(std::sqrt(static_cast<double>(reg[0].I))); |
|
| 1109 | 988 |
} |
| 1110 | 989 |
|
| 1111 | 990 |
void BIOS_MidiKey2Freq() |
| 1112 | 991 |
{
|
| 1113 |
-#ifdef GBA_LOGGING |
|
| 1114 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 1115 |
- log("MidiKey2Freq: WaveData=%08x mk=%08x fp=%08x\n",
|
|
| 1116 |
- reg[0].I, |
|
| 1117 |
- reg[1].I, |
|
| 1118 |
- reg[2].I); |
|
| 1119 |
- } |
|
| 1120 |
-#endif |
|
| 1121 |
- int freq = CPUReadMemory(reg[0].I+4); |
|
| 1122 |
- double tmp; |
|
| 1123 |
- tmp = ((double)(180 - reg[1].I)) - ((double)reg[2].I / 256.f); |
|
| 1124 |
- tmp = pow((double)2.f, tmp / 12.f); |
|
| 1125 |
- reg[0].I = (int)((double)freq / tmp); |
|
| 1126 |
- |
|
| 1127 |
-#ifdef GBA_LOGGING |
|
| 1128 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 1129 |
- log("MidiKey2Freq: return %08x\n",
|
|
| 1130 |
- reg[0].I); |
|
| 1131 |
- } |
|
| 1132 |
-#endif |
|
| 992 |
+ int freq = CPUReadMemory(reg[0].I + 4); |
|
| 993 |
+ double tmp = (180 - reg[1].I) - (reg[2].I / 256.0); |
|
| 994 |
+ tmp = std::pow(2.0, tmp / 12.0); |
|
| 995 |
+ reg[0].I = static_cast<int>(freq / tmp); |
|
| 1133 | 996 |
} |
| 1134 | 997 |
|
| 1135 | 998 |
void BIOS_SndDriverJmpTableCopy() |
| 1136 | 999 |
{
|
| 1137 |
-#ifdef GBA_LOGGING |
|
| 1138 |
- if(systemVerbose & VERBOSE_SWI) {
|
|
| 1139 |
- log("SndDriverJmpTableCopy: dest=%08x\n",
|
|
| 1140 |
- reg[0].I); |
|
| 1141 |
- } |
|
| 1142 |
-#endif |
|
| 1143 |
- for(int i = 0; i < 0x24; i++) {
|
|
| 1144 |
- CPUWriteMemory(reg[0].I, 0x9c); |
|
| 1145 |
- reg[0].I += 4; |
|
| 1146 |
- } |
|
| 1000 |
+ for (int i = 0; i < 0x24; ++i) |
|
| 1001 |
+ {
|
|
| 1002 |
+ CPUWriteMemory(reg[0].I, 0x9c); |
|
| 1003 |
+ reg[0].I += 4; |
|
| 1004 |
+ } |
|
| 1147 | 1005 |
} |
| ... | ... |
@@ -7,39 +7,39 @@ |
| 7 | 7 |
#include "GBAinline.h" |
| 8 | 8 |
#include "Globals.h" |
| 9 | 9 |
|
| 10 |
-s16 sineTable[256] = {
|
|
| 11 |
- (s16)0x0000, (s16)0x0192, (s16)0x0323, (s16)0x04B5, (s16)0x0645, (s16)0x07D5, (s16)0x0964, (s16)0x0AF1, |
|
| 12 |
- (s16)0x0C7C, (s16)0x0E05, (s16)0x0F8C, (s16)0x1111, (s16)0x1294, (s16)0x1413, (s16)0x158F, (s16)0x1708, |
|
| 13 |
- (s16)0x187D, (s16)0x19EF, (s16)0x1B5D, (s16)0x1CC6, (s16)0x1E2B, (s16)0x1F8B, (s16)0x20E7, (s16)0x223D, |
|
| 14 |
- (s16)0x238E, (s16)0x24DA, (s16)0x261F, (s16)0x275F, (s16)0x2899, (s16)0x29CD, (s16)0x2AFA, (s16)0x2C21, |
|
| 15 |
- (s16)0x2D41, (s16)0x2E5A, (s16)0x2F6B, (s16)0x3076, (s16)0x3179, (s16)0x3274, (s16)0x3367, (s16)0x3453, |
|
| 16 |
- (s16)0x3536, (s16)0x3612, (s16)0x36E5, (s16)0x37AF, (s16)0x3871, (s16)0x392A, (s16)0x39DA, (s16)0x3A82, |
|
| 17 |
- (s16)0x3B20, (s16)0x3BB6, (s16)0x3C42, (s16)0x3CC5, (s16)0x3D3E, (s16)0x3DAE, (s16)0x3E14, (s16)0x3E71, |
|
| 18 |
- (s16)0x3EC5, (s16)0x3F0E, (s16)0x3F4E, (s16)0x3F84, (s16)0x3FB1, (s16)0x3FD3, (s16)0x3FEC, (s16)0x3FFB, |
|
| 19 |
- (s16)0x4000, (s16)0x3FFB, (s16)0x3FEC, (s16)0x3FD3, (s16)0x3FB1, (s16)0x3F84, (s16)0x3F4E, (s16)0x3F0E, |
|
| 20 |
- (s16)0x3EC5, (s16)0x3E71, (s16)0x3E14, (s16)0x3DAE, (s16)0x3D3E, (s16)0x3CC5, (s16)0x3C42, (s16)0x3BB6, |
|
| 21 |
- (s16)0x3B20, (s16)0x3A82, (s16)0x39DA, (s16)0x392A, (s16)0x3871, (s16)0x37AF, (s16)0x36E5, (s16)0x3612, |
|
| 22 |
- (s16)0x3536, (s16)0x3453, (s16)0x3367, (s16)0x3274, (s16)0x3179, (s16)0x3076, (s16)0x2F6B, (s16)0x2E5A, |
|
| 23 |
- (s16)0x2D41, (s16)0x2C21, (s16)0x2AFA, (s16)0x29CD, (s16)0x2899, (s16)0x275F, (s16)0x261F, (s16)0x24DA, |
|
| 24 |
- (s16)0x238E, (s16)0x223D, (s16)0x20E7, (s16)0x1F8B, (s16)0x1E2B, (s16)0x1CC6, (s16)0x1B5D, (s16)0x19EF, |
|
| 25 |
- (s16)0x187D, (s16)0x1708, (s16)0x158F, (s16)0x1413, (s16)0x1294, (s16)0x1111, (s16)0x0F8C, (s16)0x0E05, |
|
| 26 |
- (s16)0x0C7C, (s16)0x0AF1, (s16)0x0964, (s16)0x07D5, (s16)0x0645, (s16)0x04B5, (s16)0x0323, (s16)0x0192, |
|
| 27 |
- (s16)0x0000, (s16)0xFE6E, (s16)0xFCDD, (s16)0xFB4B, (s16)0xF9BB, (s16)0xF82B, (s16)0xF69C, (s16)0xF50F, |
|
| 28 |
- (s16)0xF384, (s16)0xF1FB, (s16)0xF074, (s16)0xEEEF, (s16)0xED6C, (s16)0xEBED, (s16)0xEA71, (s16)0xE8F8, |
|
| 29 |
- (s16)0xE783, (s16)0xE611, (s16)0xE4A3, (s16)0xE33A, (s16)0xE1D5, (s16)0xE075, (s16)0xDF19, (s16)0xDDC3, |
|
| 30 |
- (s16)0xDC72, (s16)0xDB26, (s16)0xD9E1, (s16)0xD8A1, (s16)0xD767, (s16)0xD633, (s16)0xD506, (s16)0xD3DF, |
|
| 31 |
- (s16)0xD2BF, (s16)0xD1A6, (s16)0xD095, (s16)0xCF8A, (s16)0xCE87, (s16)0xCD8C, (s16)0xCC99, (s16)0xCBAD, |
|
| 32 |
- (s16)0xCACA, (s16)0xC9EE, (s16)0xC91B, (s16)0xC851, (s16)0xC78F, (s16)0xC6D6, (s16)0xC626, (s16)0xC57E, |
|
| 33 |
- (s16)0xC4E0, (s16)0xC44A, (s16)0xC3BE, (s16)0xC33B, (s16)0xC2C2, (s16)0xC252, (s16)0xC1EC, (s16)0xC18F, |
|
| 34 |
- (s16)0xC13B, (s16)0xC0F2, (s16)0xC0B2, (s16)0xC07C, (s16)0xC04F, (s16)0xC02D, (s16)0xC014, (s16)0xC005, |
|
| 35 |
- (s16)0xC000, (s16)0xC005, (s16)0xC014, (s16)0xC02D, (s16)0xC04F, (s16)0xC07C, (s16)0xC0B2, (s16)0xC0F2, |
|
| 36 |
- (s16)0xC13B, (s16)0xC18F, (s16)0xC1EC, (s16)0xC252, (s16)0xC2C2, (s16)0xC33B, (s16)0xC3BE, (s16)0xC44A, |
|
| 37 |
- (s16)0xC4E0, (s16)0xC57E, (s16)0xC626, (s16)0xC6D6, (s16)0xC78F, (s16)0xC851, (s16)0xC91B, (s16)0xC9EE, |
|
| 38 |
- (s16)0xCACA, (s16)0xCBAD, (s16)0xCC99, (s16)0xCD8C, (s16)0xCE87, (s16)0xCF8A, (s16)0xD095, (s16)0xD1A6, |
|
| 39 |
- (s16)0xD2BF, (s16)0xD3DF, (s16)0xD506, (s16)0xD633, (s16)0xD767, (s16)0xD8A1, (s16)0xD9E1, (s16)0xDB26, |
|
| 40 |
- (s16)0xDC72, (s16)0xDDC3, (s16)0xDF19, (s16)0xE075, (s16)0xE1D5, (s16)0xE33A, (s16)0xE4A3, (s16)0xE611, |
|
| 41 |
- (s16)0xE783, (s16)0xE8F8, (s16)0xEA71, (s16)0xEBED, (s16)0xED6C, (s16)0xEEEF, (s16)0xF074, (s16)0xF1FB, |
|
| 42 |
- (s16)0xF384, (s16)0xF50F, (s16)0xF69C, (s16)0xF82B, (s16)0xF9BB, (s16)0xFB4B, (s16)0xFCDD, (s16)0xFE6E |
|
| 10 |
+int16_t sineTable[256] = {
|
|
| 11 |
+ (int16_t)0x0000, (int16_t)0x0192, (int16_t)0x0323, (int16_t)0x04B5, (int16_t)0x0645, (int16_t)0x07D5, (int16_t)0x0964, (int16_t)0x0AF1, |
|
| 12 |
+ (int16_t)0x0C7C, (int16_t)0x0E05, (int16_t)0x0F8C, (int16_t)0x1111, (int16_t)0x1294, (int16_t)0x1413, (int16_t)0x158F, (int16_t)0x1708, |
|
| 13 |
+ (int16_t)0x187D, (int16_t)0x19EF, (int16_t)0x1B5D, (int16_t)0x1CC6, (int16_t)0x1E2B, (int16_t)0x1F8B, (int16_t)0x20E7, (int16_t)0x223D, |
|
| 14 |
+ (int16_t)0x238E, (int16_t)0x24DA, (int16_t)0x261F, (int16_t)0x275F, (int16_t)0x2899, (int16_t)0x29CD, (int16_t)0x2AFA, (int16_t)0x2C21, |
|
| 15 |
+ (int16_t)0x2D41, (int16_t)0x2E5A, (int16_t)0x2F6B, (int16_t)0x3076, (int16_t)0x3179, (int16_t)0x3274, (int16_t)0x3367, (int16_t)0x3453, |
|
| 16 |
+ (int16_t)0x3536, (int16_t)0x3612, (int16_t)0x36E5, (int16_t)0x37AF, (int16_t)0x3871, (int16_t)0x392A, (int16_t)0x39DA, (int16_t)0x3A82, |
|
| 17 |
+ (int16_t)0x3B20, (int16_t)0x3BB6, (int16_t)0x3C42, (int16_t)0x3CC5, (int16_t)0x3D3E, (int16_t)0x3DAE, (int16_t)0x3E14, (int16_t)0x3E71, |
|
| 18 |
+ (int16_t)0x3EC5, (int16_t)0x3F0E, (int16_t)0x3F4E, (int16_t)0x3F84, (int16_t)0x3FB1, (int16_t)0x3FD3, (int16_t)0x3FEC, (int16_t)0x3FFB, |
|
| 19 |
+ (int16_t)0x4000, (int16_t)0x3FFB, (int16_t)0x3FEC, (int16_t)0x3FD3, (int16_t)0x3FB1, (int16_t)0x3F84, (int16_t)0x3F4E, (int16_t)0x3F0E, |
|
| 20 |
+ (int16_t)0x3EC5, (int16_t)0x3E71, (int16_t)0x3E14, (int16_t)0x3DAE, (int16_t)0x3D3E, (int16_t)0x3CC5, (int16_t)0x3C42, (int16_t)0x3BB6, |
|
| 21 |
+ (int16_t)0x3B20, (int16_t)0x3A82, (int16_t)0x39DA, (int16_t)0x392A, (int16_t)0x3871, (int16_t)0x37AF, (int16_t)0x36E5, (int16_t)0x3612, |
|
| 22 |
+ (int16_t)0x3536, (int16_t)0x3453, (int16_t)0x3367, (int16_t)0x3274, (int16_t)0x3179, (int16_t)0x3076, (int16_t)0x2F6B, (int16_t)0x2E5A, |
|
| 23 |
+ (int16_t)0x2D41, (int16_t)0x2C21, (int16_t)0x2AFA, (int16_t)0x29CD, (int16_t)0x2899, (int16_t)0x275F, (int16_t)0x261F, (int16_t)0x24DA, |
|
| 24 |
+ (int16_t)0x238E, (int16_t)0x223D, (int16_t)0x20E7, (int16_t)0x1F8B, (int16_t)0x1E2B, (int16_t)0x1CC6, (int16_t)0x1B5D, (int16_t)0x19EF, |
|
| 25 |
+ (int16_t)0x187D, (int16_t)0x1708, (int16_t)0x158F, (int16_t)0x1413, (int16_t)0x1294, (int16_t)0x1111, (int16_t)0x0F8C, (int16_t)0x0E05, |
|
| 26 |
+ (int16_t)0x0C7C, (int16_t)0x0AF1, (int16_t)0x0964, (int16_t)0x07D5, (int16_t)0x0645, (int16_t)0x04B5, (int16_t)0x0323, (int16_t)0x0192, |
|
| 27 |
+ (int16_t)0x0000, (int16_t)0xFE6E, (int16_t)0xFCDD, (int16_t)0xFB4B, (int16_t)0xF9BB, (int16_t)0xF82B, (int16_t)0xF69C, (int16_t)0xF50F, |
|
| 28 |
+ (int16_t)0xF384, (int16_t)0xF1FB, (int16_t)0xF074, (int16_t)0xEEEF, (int16_t)0xED6C, (int16_t)0xEBED, (int16_t)0xEA71, (int16_t)0xE8F8, |
|
| 29 |
+ (int16_t)0xE783, (int16_t)0xE611, (int16_t)0xE4A3, (int16_t)0xE33A, (int16_t)0xE1D5, (int16_t)0xE075, (int16_t)0xDF19, (int16_t)0xDDC3, |
|
| 30 |
+ (int16_t)0xDC72, (int16_t)0xDB26, (int16_t)0xD9E1, (int16_t)0xD8A1, (int16_t)0xD767, (int16_t)0xD633, (int16_t)0xD506, (int16_t)0xD3DF, |
|
| 31 |
+ (int16_t)0xD2BF, (int16_t)0xD1A6, (int16_t)0xD095, (int16_t)0xCF8A, (int16_t)0xCE87, (int16_t)0xCD8C, (int16_t)0xCC99, (int16_t)0xCBAD, |
|
| 32 |
+ (int16_t)0xCACA, (int16_t)0xC9EE, (int16_t)0xC91B, (int16_t)0xC851, (int16_t)0xC78F, (int16_t)0xC6D6, (int16_t)0xC626, (int16_t)0xC57E, |
|
| 33 |
+ (int16_t)0xC4E0, (int16_t)0xC44A, (int16_t)0xC3BE, (int16_t)0xC33B, (int16_t)0xC2C2, (int16_t)0xC252, (int16_t)0xC1EC, (int16_t)0xC18F, |
|
| 34 |
+ (int16_t)0xC13B, (int16_t)0xC0F2, (int16_t)0xC0B2, (int16_t)0xC07C, (int16_t)0xC04F, (int16_t)0xC02D, (int16_t)0xC014, (int16_t)0xC005, |
|
| 35 |
+ (int16_t)0xC000, (int16_t)0xC005, (int16_t)0xC014, (int16_t)0xC02D, (int16_t)0xC04F, (int16_t)0xC07C, (int16_t)0xC0B2, (int16_t)0xC0F2, |
|
| 36 |
+ (int16_t)0xC13B, (int16_t)0xC18F, (int16_t)0xC1EC, (int16_t)0xC252, (int16_t)0xC2C2, (int16_t)0xC33B, (int16_t)0xC3BE, (int16_t)0xC44A, |
|
| 37 |
+ (int16_t)0xC4E0, (int16_t)0xC57E, (int16_t)0xC626, (int16_t)0xC6D6, (int16_t)0xC78F, (int16_t)0xC851, (int16_t)0xC91B, (int16_t)0xC9EE, |
|
| 38 |
+ (int16_t)0xCACA, (int16_t)0xCBAD, (int16_t)0xCC99, (int16_t)0xCD8C, (int16_t)0xCE87, (int16_t)0xCF8A, (int16_t)0xD095, (int16_t)0xD1A6, |
|
| 39 |
+ (int16_t)0xD2BF, (int16_t)0xD3DF, (int16_t)0xD506, (int16_t)0xD633, (int16_t)0xD767, (int16_t)0xD8A1, (int16_t)0xD9E1, (int16_t)0xDB26, |
|
| 40 |
+ (int16_t)0xDC72, (int16_t)0xDDC3, (int16_t)0xDF19, (int16_t)0xE075, (int16_t)0xE1D5, (int16_t)0xE33A, (int16_t)0xE4A3, (int16_t)0xE611, |
|
| 41 |
+ (int16_t)0xE783, (int16_t)0xE8F8, (int16_t)0xEA71, (int16_t)0xEBED, (int16_t)0xED6C, (int16_t)0xEEEF, (int16_t)0xF074, (int16_t)0xF1FB, |
|
| 42 |
+ (int16_t)0xF384, (int16_t)0xF50F, (int16_t)0xF69C, (int16_t)0xF82B, (int16_t)0xF9BB, (int16_t)0xFB4B, (int16_t)0xFCDD, (int16_t)0xFE6E |
|
| 43 | 43 |
}; |
| 44 | 44 |
|
| 45 | 45 |
void BIOS_ArcTan() |
| ... | ... |
@@ -52,15 +52,15 @@ void BIOS_ArcTan() |
| 52 | 52 |
} |
| 53 | 53 |
#endif |
| 54 | 54 |
|
| 55 |
- s32 a = -(((s32)(reg[0].I*reg[0].I)) >> 14); |
|
| 56 |
- s32 b = ((0xA9 * a) >> 14) + 0x390; |
|
| 55 |
+ int32_t a = -(((int32_t)(reg[0].I*reg[0].I)) >> 14); |
|
| 56 |
+ int32_t b = ((0xA9 * a) >> 14) + 0x390; |
|
| 57 | 57 |
b = ((b * a) >> 14) + 0x91C; |
| 58 | 58 |
b = ((b * a) >> 14) + 0xFB6; |
| 59 | 59 |
b = ((b * a) >> 14) + 0x16AA; |
| 60 | 60 |
b = ((b * a) >> 14) + 0x2081; |
| 61 | 61 |
b = ((b * a) >> 14) + 0x3651; |
| 62 | 62 |
b = ((b * a) >> 14) + 0xA2F9; |
| 63 |
- a = ((s32)reg[0].I * b) >> 16; |
|
| 63 |
+ a = ((int32_t)reg[0].I * b) >> 16; |
|
| 64 | 64 |
reg[0].I = a; |
| 65 | 65 |
|
| 66 | 66 |
#ifdef GBA_LOGGING |
| ... | ... |
@@ -82,9 +82,9 @@ void BIOS_ArcTan2() |
| 82 | 82 |
} |
| 83 | 83 |
#endif |
| 84 | 84 |
|
| 85 |
- s32 x = reg[0].I; |
|
| 86 |
- s32 y = reg[1].I; |
|
| 87 |
- u32 res = 0; |
|
| 85 |
+ int32_t x = reg[0].I; |
|
| 86 |
+ int32_t y = reg[1].I; |
|
| 87 |
+ uint32_t res = 0; |
|
| 88 | 88 |
if (y == 0) {
|
| 89 | 89 |
res = ((x>>16) & 0x8000); |
| 90 | 90 |
} else {
|
| ... | ... |
@@ -130,9 +130,9 @@ void BIOS_BitUnPack() |
| 130 | 130 |
} |
| 131 | 131 |
#endif |
| 132 | 132 |
|
| 133 |
- u32 source = reg[0].I; |
|
| 134 |
- u32 dest = reg[1].I; |
|
| 135 |
- u32 header = reg[2].I; |
|
| 133 |
+ uint32_t source = reg[0].I; |
|
| 134 |
+ uint32_t dest = reg[1].I; |
|
| 135 |
+ uint32_t header = reg[2].I; |
|
| 136 | 136 |
|
| 137 | 137 |
int len = CPUReadHalfWord(header); |
| 138 | 138 |
// check address |
| ... | ... |
@@ -143,7 +143,7 @@ void BIOS_BitUnPack() |
| 143 | 143 |
int bits = CPUReadByte(header+2); |
| 144 | 144 |
int revbits = 8 - bits; |
| 145 | 145 |
// u32 value = 0; |
| 146 |
- u32 base = CPUReadMemory(header+4); |
|
| 146 |
+ uint32_t base = CPUReadMemory(header+4); |
|
| 147 | 147 |
bool addBase = (base & 0x80000000) ? true : false; |
| 148 | 148 |
base &= 0x7fffffff; |
| 149 | 149 |
int dataSize = CPUReadByte(header+3); |
| ... | ... |
@@ -155,14 +155,14 @@ void BIOS_BitUnPack() |
| 155 | 155 |
if(len < 0) |
| 156 | 156 |
break; |
| 157 | 157 |
int mask = 0xff >> revbits; |
| 158 |
- u8 b = CPUReadByte(source); |
|
| 158 |
+ uint8_t b = CPUReadByte(source); |
|
| 159 | 159 |
source++; |
| 160 | 160 |
int bitcount = 0; |
| 161 | 161 |
while(1) {
|
| 162 | 162 |
if(bitcount >= 8) |
| 163 | 163 |
break; |
| 164 |
- u32 d = b & mask; |
|
| 165 |
- u32 temp = d >> bitcount; |
|
| 164 |
+ uint32_t d = b & mask; |
|
| 165 |
+ uint32_t temp = d >> bitcount; |
|
| 166 | 166 |
if(d || addBase) {
|
| 167 | 167 |
temp += base; |
| 168 | 168 |
} |
| ... | ... |
@@ -197,32 +197,32 @@ void BIOS_BgAffineSet() |
| 197 | 197 |
} |
| 198 | 198 |
#endif |
| 199 | 199 |
|
| 200 |
- u32 src = reg[0].I; |
|
| 201 |
- u32 dest = reg[1].I; |
|
| 200 |
+ uint32_t src = reg[0].I; |
|
| 201 |
+ uint32_t dest = reg[1].I; |
|
| 202 | 202 |
int num = reg[2].I; |
| 203 | 203 |
|
| 204 | 204 |
for(int i = 0; i < num; i++) {
|
| 205 |
- s32 cx = CPUReadMemory(src); |
|
| 205 |
+ int32_t cx = CPUReadMemory(src); |
|
| 206 | 206 |
src+=4; |
| 207 |
- s32 cy = CPUReadMemory(src); |
|
| 207 |
+ int32_t cy = CPUReadMemory(src); |
|
| 208 | 208 |
src+=4; |
| 209 |
- s16 dispx = CPUReadHalfWord(src); |
|
| 209 |
+ int16_t dispx = CPUReadHalfWord(src); |
|
| 210 | 210 |
src+=2; |
| 211 |
- s16 dispy = CPUReadHalfWord(src); |
|
| 211 |
+ int16_t dispy = CPUReadHalfWord(src); |
|
| 212 | 212 |
src+=2; |
| 213 |
- s16 rx = CPUReadHalfWord(src); |
|
| 213 |
+ int16_t rx = CPUReadHalfWord(src); |
|
| 214 | 214 |
src+=2; |
| 215 |
- s16 ry = CPUReadHalfWord(src); |
|
| 215 |
+ int16_t ry = CPUReadHalfWord(src); |
|
| 216 | 216 |
src+=2; |
| 217 |
- u16 theta = CPUReadHalfWord(src)>>8; |
|
| 217 |
+ uint16_t theta = CPUReadHalfWord(src)>>8; |
|
| 218 | 218 |
src+=4; // keep structure alignment |
| 219 |
- s32 a = sineTable[(theta+0x40)&255]; |
|
| 220 |
- s32 b = sineTable[theta]; |
|
| 219 |
+ int32_t a = sineTable[(theta+0x40)&255]; |
|
| 220 |
+ int32_t b = sineTable[theta]; |
|
| 221 | 221 |
|
| 222 |
- s16 dx = (rx * a)>>14; |
|
| 223 |
- s16 dmx = (rx * b)>>14; |
|
| 224 |
- s16 dy = (ry * b)>>14; |
|
| 225 |
- s16 dmy = (ry * a)>>14; |
|
| 222 |
+ int16_t dx = (rx * a)>>14; |
|
| 223 |
+ int16_t dmx = (rx * b)>>14; |
|
| 224 |
+ int16_t dy = (ry * b)>>14; |
|
| 225 |
+ int16_t dmy = (ry * a)>>14; |
|
| 226 | 226 |
|
| 227 | 227 |
CPUWriteHalfWord(dest, dx); |
| 228 | 228 |
dest += 2; |
| ... | ... |
@@ -233,8 +233,8 @@ void BIOS_BgAffineSet() |
| 233 | 233 |
CPUWriteHalfWord(dest, dmy); |
| 234 | 234 |
dest += 2; |
| 235 | 235 |
|
| 236 |
- s32 startx = cx - dx * dispx + dmx * dispy; |
|
| 237 |
- s32 starty = cy - dy * dispx - dmy * dispy; |
|
| 236 |
+ int32_t startx = cx - dx * dispx + dmx * dispy; |
|
| 237 |
+ int32_t starty = cy - dy * dispx - dmy * dispy; |
|
| 238 | 238 |
|
| 239 | 239 |
CPUWriteMemory(dest, startx); |
| 240 | 240 |
dest += 4; |
| ... | ... |
@@ -252,9 +252,9 @@ void BIOS_CpuSet() |
| 252 | 252 |
} |
| 253 | 253 |
#endif |
| 254 | 254 |
|
| 255 |
- u32 source = reg[0].I; |
|
| 256 |
- u32 dest = reg[1].I; |
|
| 257 |
- u32 cnt = reg[2].I; |
|
| 255 |
+ uint32_t source = reg[0].I; |
|
| 256 |
+ uint32_t dest = reg[1].I; |
|
| 257 |
+ uint32_t cnt = reg[2].I; |
|
| 258 | 258 |
|
| 259 | 259 |
if(((source & 0xe000000) == 0) || |
| 260 | 260 |
((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0) |
| ... | ... |
@@ -269,7 +269,7 @@ void BIOS_CpuSet() |
| 269 | 269 |
dest &= 0xFFFFFFFC; |
| 270 | 270 |
// fill ? |
| 271 | 271 |
if((cnt >> 24) & 1) {
|
| 272 |
- u32 value = (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source)); |
|
| 272 |
+ uint32_t value = (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source)); |
|
| 273 | 273 |
while(count) {
|
| 274 | 274 |
CPUWriteMemory(dest, value); |
| 275 | 275 |
dest += 4; |
| ... | ... |
@@ -287,7 +287,7 @@ void BIOS_CpuSet() |
| 287 | 287 |
} else {
|
| 288 | 288 |
// 16-bit fill? |
| 289 | 289 |
if((cnt >> 24) & 1) {
|
| 290 |
- u16 value = (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source)); |
|
| 290 |
+ uint16_t value = (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source)); |
|
| 291 | 291 |
while(count) {
|
| 292 | 292 |
CPUWriteHalfWord(dest, value); |
| 293 | 293 |
dest += 2; |
| ... | ... |
@@ -314,9 +314,9 @@ void BIOS_CpuFastSet() |
| 314 | 314 |
} |
| 315 | 315 |
#endif |
| 316 | 316 |
|
| 317 |
- u32 source = reg[0].I; |
|
| 318 |
- u32 dest = reg[1].I; |
|
| 319 |
- u32 cnt = reg[2].I; |
|
| 317 |
+ uint32_t source = reg[0].I; |
|
| 318 |
+ uint32_t dest = reg[1].I; |
|
| 319 |
+ uint32_t cnt = reg[2].I; |
|
| 320 | 320 |
|
| 321 | 321 |
if(((source & 0xe000000) == 0) || |
| 322 | 322 |
((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0) |
| ... | ... |
@@ -332,7 +332,7 @@ void BIOS_CpuFastSet() |
| 332 | 332 |
if((cnt >> 24) & 1) {
|
| 333 | 333 |
while(count > 0) {
|
| 334 | 334 |
// BIOS always transfers 32 bytes at a time |
| 335 |
- u32 value = (source>0x0EFFFFFF ? 0xBAFFFFFB : CPUReadMemory(source)); |
|
| 335 |
+ uint32_t value = (source>0x0EFFFFFF ? 0xBAFFFFFB : CPUReadMemory(source)); |
|
| 336 | 336 |
for(int i = 0; i < 8; i++) {
|
| 337 | 337 |
CPUWriteMemory(dest, value); |
| 338 | 338 |
dest += 4; |
| ... | ... |
@@ -362,10 +362,10 @@ void BIOS_Diff8bitUnFilterWram() |
| 362 | 362 |
} |
| 363 | 363 |
#endif |
| 364 | 364 |
|
| 365 |
- u32 source = reg[0].I; |
|
| 366 |
- u32 dest = reg[1].I; |
|
| 365 |
+ uint32_t source = reg[0].I; |
|
| 366 |
+ uint32_t dest = reg[1].I; |
|
| 367 | 367 |
|
| 368 |
- u32 header = CPUReadMemory(source); |
|
| 368 |
+ uint32_t header = CPUReadMemory(source); |
|
| 369 | 369 |
source += 4; |
| 370 | 370 |
|
| 371 | 371 |
if(((source & 0xe000000) == 0) || |
| ... | ... |
@@ -374,12 +374,12 @@ void BIOS_Diff8bitUnFilterWram() |
| 374 | 374 |
|
| 375 | 375 |
int len = header >> 8; |
| 376 | 376 |
|
| 377 |
- u8 data = CPUReadByte(source++); |
|
| 377 |
+ uint8_t data = CPUReadByte(source++); |
|
| 378 | 378 |
CPUWriteByte(dest++, data); |
| 379 | 379 |
len--; |
| 380 | 380 |
|
| 381 | 381 |
while(len > 0) {
|
| 382 |
- u8 diff = CPUReadByte(source++); |
|
| 382 |
+ uint8_t diff = CPUReadByte(source++); |
|
| 383 | 383 |
data += diff; |
| 384 | 384 |
CPUWriteByte(dest++, data); |
| 385 | 385 |
len--; |
| ... | ... |
@@ -395,10 +395,10 @@ void BIOS_Diff8bitUnFilterVram() |
| 395 | 395 |
} |
| 396 | 396 |
#endif |
| 397 | 397 |
|
| 398 |
- u32 source = reg[0].I; |
|
| 399 |
- u32 dest = reg[1].I; |
|
| 398 |
+ uint32_t source = reg[0].I; |
|
| 399 |
+ uint32_t dest = reg[1].I; |
|
| 400 | 400 |
|
| 401 |
- u32 header = CPUReadMemory(source); |
|
| 401 |
+ uint32_t header = CPUReadMemory(source); |
|
| 402 | 402 |
source += 4; |
| 403 | 403 |
|
| 404 | 404 |
if(((source & 0xe000000) == 0) || |
| ... | ... |
@@ -407,13 +407,13 @@ void BIOS_Diff8bitUnFilterVram() |
| 407 | 407 |
|
| 408 | 408 |
int len = header >> 8; |
| 409 | 409 |
|
| 410 |
- u8 data = CPUReadByte(source++); |
|
| 411 |
- u16 writeData = data; |
|
| 410 |
+ uint8_t data = CPUReadByte(source++); |
|
| 411 |
+ uint16_t writeData = data; |
|
| 412 | 412 |
int shift = 8; |
| 413 | 413 |
int bytes = 1; |
| 414 | 414 |
|
| 415 | 415 |
while(len >= 2) {
|
| 416 |
- u8 diff = CPUReadByte(source++); |
|
| 416 |
+ uint8_t diff = CPUReadByte(source++); |
|
| 417 | 417 |
data += diff; |
| 418 | 418 |
writeData |= (data << shift); |
| 419 | 419 |
bytes++; |
| ... | ... |
@@ -438,10 +438,10 @@ void BIOS_Diff16bitUnFilter() |
| 438 | 438 |
} |
| 439 | 439 |
#endif |
| 440 | 440 |
|
| 441 |
- u32 source = reg[0].I; |
|
| 442 |
- u32 dest = reg[1].I; |
|
| 441 |
+ uint32_t source = reg[0].I; |
|
| 442 |
+ uint32_t dest = reg[1].I; |
|
| 443 | 443 |
|
| 444 |
- u32 header = CPUReadMemory(source); |
|
| 444 |
+ uint32_t header = CPUReadMemory(source); |
|
| 445 | 445 |
source += 4; |
| 446 | 446 |
|
| 447 | 447 |
if(((source & 0xe000000) == 0) || |
| ... | ... |
@@ -450,14 +450,14 @@ void BIOS_Diff16bitUnFilter() |
| 450 | 450 |
|
| 451 | 451 |
int len = header >> 8; |
| 452 | 452 |
|
| 453 |
- u16 data = CPUReadHalfWord(source); |
|
| 453 |
+ uint16_t data = CPUReadHalfWord(source); |
|
| 454 | 454 |
source += 2; |
| 455 | 455 |
CPUWriteHalfWord(dest, data); |
| 456 | 456 |
dest += 2; |
| 457 | 457 |
len -= 2; |
| 458 | 458 |
|
| 459 | 459 |
while(len >= 2) {
|
| 460 |
- u16 diff = CPUReadHalfWord(source); |
|
| 460 |
+ uint16_t diff = CPUReadHalfWord(source); |
|
| 461 | 461 |
source += 2; |
| 462 | 462 |
data += diff; |
| 463 | 463 |
CPUWriteHalfWord(dest, data); |
| ... | ... |
@@ -483,8 +483,8 @@ void BIOS_Div() |
| 483 | 483 |
if(denom != 0) {
|
| 484 | 484 |
reg[0].I = number / denom; |
| 485 | 485 |
reg[1].I = number % denom; |
| 486 |
- s32 temp = (s32)reg[0].I; |
|
| 487 |
- reg[3].I = temp < 0 ? (u32)-temp : (u32)temp; |
|
| 486 |
+ int32_t temp = (int32_t)reg[0].I; |
|
| 487 |
+ reg[3].I = temp < 0 ? (uint32_t)-temp : (uint32_t)temp; |
|
| 488 | 488 |
} |
| 489 | 489 |
#ifdef GBA_LOGGING |
| 490 | 490 |
if(systemVerbose & VERBOSE_SWI) {
|
| ... | ... |
@@ -506,7 +506,7 @@ void BIOS_DivARM() |
| 506 | 506 |
} |
| 507 | 507 |
#endif |
| 508 | 508 |
|
| 509 |
- u32 temp = reg[0].I; |
|
| 509 |
+ uint32_t temp = reg[0].I; |
|
| 510 | 510 |
reg[0].I = reg[1].I; |
| 511 | 511 |
reg[1].I = temp; |
| 512 | 512 |
BIOS_Div(); |
| ... | ... |
@@ -523,35 +523,35 @@ void BIOS_HuffUnComp() |
| 523 | 523 |
} |
| 524 | 524 |
#endif |
| 525 | 525 |
|
| 526 |
- u32 source = reg[0].I; |
|
| 527 |
- u32 dest = reg[1].I; |
|
| 526 |
+ uint32_t source = reg[0].I; |
|
| 527 |
+ uint32_t dest = reg[1].I; |
|
| 528 | 528 |
|
| 529 |
- u32 header = CPUReadMemory(source); |
|
| 529 |
+ uint32_t header = CPUReadMemory(source); |
|
| 530 | 530 |
source += 4; |
| 531 | 531 |
|
| 532 | 532 |
if(((source & 0xe000000) == 0) || |
| 533 | 533 |
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
| 534 | 534 |
return; |
| 535 | 535 |
|
| 536 |
- u8 treeSize = CPUReadByte(source++); |
|
| 536 |
+ uint8_t treeSize = CPUReadByte(source++); |
|
| 537 | 537 |
|
| 538 |
- u32 treeStart = source; |
|
| 538 |
+ uint32_t treeStart = source; |
|
| 539 | 539 |
|
| 540 | 540 |
source += ((treeSize+1)<<1)-1; // minus because we already skipped one byte |
| 541 | 541 |
|
| 542 | 542 |
int len = header >> 8; |
| 543 | 543 |
|
| 544 |
- u32 mask = 0x80000000; |
|
| 545 |
- u32 data = CPUReadMemory(source); |
|
| 544 |
+ uint32_t mask = 0x80000000; |
|
| 545 |
+ uint32_t data = CPUReadMemory(source); |
|
| 546 | 546 |
source += 4; |
| 547 | 547 |
|
| 548 | 548 |
int pos = 0; |
| 549 |
- u8 rootNode = CPUReadByte(treeStart); |
|
| 550 |
- u8 currentNode = rootNode; |
|
| 549 |
+ uint8_t rootNode = CPUReadByte(treeStart); |
|
| 550 |
+ uint8_t currentNode = rootNode; |
|
| 551 | 551 |
bool writeData = false; |
| 552 | 552 |
int byteShift = 0; |
| 553 | 553 |
int byteCount = 0; |
| 554 |
- u32 writeValue = 0; |
|
| 554 |
+ uint32_t writeValue = 0; |
|
| 555 | 555 |
|
| 556 | 556 |
if((header & 0x0F) == 8) {
|
| 557 | 557 |
while(len > 0) {
|
| ... | ... |
@@ -669,10 +669,10 @@ void BIOS_LZ77UnCompVram() |
| 669 | 669 |
} |
| 670 | 670 |
#endif |
| 671 | 671 |
|
| 672 |
- u32 source = reg[0].I; |
|
| 673 |
- u32 dest = reg[1].I; |
|
| 672 |
+ uint32_t source = reg[0].I; |
|
| 673 |
+ uint32_t dest = reg[1].I; |
|
| 674 | 674 |
|
| 675 |
- u32 header = CPUReadMemory(source); |
|
| 675 |
+ uint32_t header = CPUReadMemory(source); |
|
| 676 | 676 |
source += 4; |
| 677 | 677 |
|
| 678 | 678 |
if(((source & 0xe000000) == 0) || |
| ... | ... |
@@ -681,21 +681,21 @@ void BIOS_LZ77UnCompVram() |
| 681 | 681 |
|
| 682 | 682 |
int byteCount = 0; |
| 683 | 683 |
int byteShift = 0; |
| 684 |
- u32 writeValue = 0; |
|
| 684 |
+ uint32_t writeValue = 0; |
|
| 685 | 685 |
|
| 686 | 686 |
int len = header >> 8; |
| 687 | 687 |
|
| 688 | 688 |
while(len > 0) {
|
| 689 |
- u8 d = CPUReadByte(source++); |
|
| 689 |
+ uint8_t d = CPUReadByte(source++); |
|
| 690 | 690 |
|
| 691 | 691 |
if(d) {
|
| 692 | 692 |
for(int i = 0; i < 8; i++) {
|
| 693 | 693 |
if(d & 0x80) {
|
| 694 |
- u16 data = CPUReadByte(source++) << 8; |
|
| 694 |
+ uint16_t data = CPUReadByte(source++) << 8; |
|
| 695 | 695 |
data |= CPUReadByte(source++); |
| 696 | 696 |
int length = (data >> 12) + 3; |
| 697 | 697 |
int offset = (data & 0x0FFF); |
| 698 |
- u32 windowOffset = dest + byteCount - offset - 1; |
|
| 698 |
+ uint32_t windowOffset = dest + byteCount - offset - 1; |
|
| 699 | 699 |
for(int i2 = 0; i2 < length; i2++) {
|
| 700 | 700 |
writeValue |= (CPUReadByte(windowOffset++) << byteShift); |
| 701 | 701 |
byteShift += 8; |
| ... | ... |
@@ -758,10 +758,10 @@ void BIOS_LZ77UnCompWram() |
| 758 | 758 |
} |
| 759 | 759 |
#endif |
| 760 | 760 |
|
| 761 |
- u32 source = reg[0].I; |
|
| 762 |
- u32 dest = reg[1].I; |
|
| 761 |
+ uint32_t source = reg[0].I; |
|
| 762 |
+ uint32_t dest = reg[1].I; |
|
| 763 | 763 |
|
| 764 |
- u32 header = CPUReadMemory(source); |
|
| 764 |
+ uint32_t header = CPUReadMemory(source); |
|
| 765 | 765 |
source += 4; |
| 766 | 766 |
|
| 767 | 767 |
if(((source & 0xe000000) == 0) || |
| ... | ... |
@@ -771,16 +771,16 @@ void BIOS_LZ77UnCompWram() |
| 771 | 771 |
int len = header >> 8; |
| 772 | 772 |
|
| 773 | 773 |
while(len > 0) {
|
| 774 |
- u8 d = CPUReadByte(source++); |
|
| 774 |
+ uint8_t d = CPUReadByte(source++); |
|
| 775 | 775 |
|
| 776 | 776 |
if(d) {
|
| 777 | 777 |
for(int i = 0; i < 8; i++) {
|
| 778 | 778 |
if(d & 0x80) {
|
| 779 |
- u16 data = CPUReadByte(source++) << 8; |
|
| 779 |
+ uint16_t data = CPUReadByte(source++) << 8; |
|
| 780 | 780 |
data |= CPUReadByte(source++); |
| 781 | 781 |
int length = (data >> 12) + 3; |
| 782 | 782 |
int offset = (data & 0x0FFF); |
| 783 |
- u32 windowOffset = dest - offset - 1; |
|
| 783 |
+ uint32_t windowOffset = dest - offset - 1; |
|
| 784 | 784 |
for(int i2 = 0; i2 < length; i2++) {
|
| 785 | 785 |
CPUWriteByte(dest++, CPUReadByte(windowOffset++)); |
| 786 | 786 |
len--; |
| ... | ... |
@@ -819,26 +819,26 @@ void BIOS_ObjAffineSet() |
| 819 | 819 |
} |
| 820 | 820 |
#endif |
| 821 | 821 |
|
| 822 |
- u32 src = reg[0].I; |
|
| 823 |
- u32 dest = reg[1].I; |
|
| 822 |
+ uint32_t src = reg[0].I; |
|
| 823 |
+ uint32_t dest = reg[1].I; |
|
| 824 | 824 |
int num = reg[2].I; |
| 825 | 825 |
int offset = reg[3].I; |
| 826 | 826 |
|
| 827 | 827 |
for(int i = 0; i < num; i++) {
|
| 828 |
- s16 rx = CPUReadHalfWord(src); |
|
| 828 |
+ int16_t rx = CPUReadHalfWord(src); |
|
| 829 | 829 |
src+=2; |
| 830 |
- s16 ry = CPUReadHalfWord(src); |
|
| 830 |
+ int16_t ry = CPUReadHalfWord(src); |
|
| 831 | 831 |
src+=2; |
| 832 |
- u16 theta = CPUReadHalfWord(src)>>8; |
|
| 832 |
+ uint16_t theta = CPUReadHalfWord(src)>>8; |
|
| 833 | 833 |
src+=4; // keep structure alignment |
| 834 | 834 |
|
| 835 |
- s32 a = (s32)sineTable[(theta+0x40)&255]; |
|
| 836 |
- s32 b = (s32)sineTable[theta]; |
|
| 835 |
+ int32_t a = (int32_t)sineTable[(theta+0x40)&255]; |
|
| 836 |
+ int32_t b = (int32_t)sineTable[theta]; |
|
| 837 | 837 |
|
| 838 |
- s16 dx = ((s32)rx * a)>>14; |
|
| 839 |
- s16 dmx = ((s32)rx * b)>>14; |
|
| 840 |
- s16 dy = ((s32)ry * b)>>14; |
|
| 841 |
- s16 dmy = ((s32)ry * a)>>14; |
|
| 838 |
+ int16_t dx = ((int32_t)rx * a)>>14; |
|
| 839 |
+ int16_t dmx = ((int32_t)rx * b)>>14; |
|
| 840 |
+ int16_t dy = ((int32_t)ry * b)>>14; |
|
| 841 |
+ int16_t dmy = ((int32_t)ry * a)>>14; |
|
| 842 | 842 |
|
| 843 | 843 |
CPUWriteHalfWord(dest, dx); |
| 844 | 844 |
dest += offset; |
| ... | ... |
@@ -851,7 +851,7 @@ void BIOS_ObjAffineSet() |
| 851 | 851 |
} |
| 852 | 852 |
} |
| 853 | 853 |
|
| 854 |
-void BIOS_RegisterRamReset(u32 flags) |
|
| 854 |
+void BIOS_RegisterRamReset(uint32_t flags) |
|
| 855 | 855 |
{
|
| 856 | 856 |
// no need to trace here. this is only called directly from GBA.cpp |
| 857 | 857 |
// to emulate bios initialization |
| ... | ... |
@@ -951,10 +951,10 @@ void BIOS_RLUnCompVram() |
| 951 | 951 |
} |
| 952 | 952 |
#endif |
| 953 | 953 |
|
| 954 |
- u32 source = reg[0].I; |
|
| 955 |
- u32 dest = reg[1].I; |
|
| 954 |
+ uint32_t source = reg[0].I; |
|
| 955 |
+ uint32_t dest = reg[1].I; |
|
| 956 | 956 |
|
| 957 |
- u32 header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 957 |
+ uint32_t header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 958 | 958 |
source += 4; |
| 959 | 959 |
|
| 960 | 960 |
if(((source & 0xe000000) == 0) || |
| ... | ... |
@@ -964,13 +964,13 @@ void BIOS_RLUnCompVram() |
| 964 | 964 |
int len = header >> 8; |
| 965 | 965 |
int byteCount = 0; |
| 966 | 966 |
int byteShift = 0; |
| 967 |
- u32 writeValue = 0; |
|
| 967 |
+ uint32_t writeValue = 0; |
|
| 968 | 968 |
|
| 969 | 969 |
while(len > 0) {
|
| 970 |
- u8 d = CPUReadByte(source++); |
|
| 970 |
+ uint8_t d = CPUReadByte(source++); |
|
| 971 | 971 |
int l = d & 0x7F; |
| 972 | 972 |
if(d & 0x80) {
|
| 973 |
- u8 data = CPUReadByte(source++); |
|
| 973 |
+ uint8_t data = CPUReadByte(source++); |
|
| 974 | 974 |
l += 3; |
| 975 | 975 |
for(int i = 0;i < l; i++) {
|
| 976 | 976 |
writeValue |= (data << byteShift); |
| ... | ... |
@@ -1020,10 +1020,10 @@ void BIOS_RLUnCompWram() |
| 1020 | 1020 |
} |
| 1021 | 1021 |
#endif |
| 1022 | 1022 |
|
| 1023 |
- u32 source = reg[0].I; |
|
| 1024 |
- u32 dest = reg[1].I; |
|
| 1023 |
+ uint32_t source = reg[0].I; |
|
| 1024 |
+ uint32_t dest = reg[1].I; |
|
| 1025 | 1025 |
|
| 1026 |
- u32 header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 1026 |
+ uint32_t header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 1027 | 1027 |
source += 4; |
| 1028 | 1028 |
|
| 1029 | 1029 |
if(((source & 0xe000000) == 0) || |
| ... | ... |
@@ -1033,10 +1033,10 @@ void BIOS_RLUnCompWram() |
| 1033 | 1033 |
int len = header >> 8; |
| 1034 | 1034 |
|
| 1035 | 1035 |
while(len > 0) {
|
| 1036 |
- u8 d = CPUReadByte(source++); |
|
| 1036 |
+ uint8_t d = CPUReadByte(source++); |
|
| 1037 | 1037 |
int l = d & 0x7F; |
| 1038 | 1038 |
if(d & 0x80) {
|
| 1039 |
- u8 data = CPUReadByte(source++); |
|
| 1039 |
+ uint8_t data = CPUReadByte(source++); |
|
| 1040 | 1040 |
l += 3; |
| 1041 | 1041 |
for(int i = 0;i < l; i++) {
|
| 1042 | 1042 |
CPUWriteByte(dest++, data); |
| ... | ... |
@@ -1077,7 +1077,7 @@ void BIOS_SoftReset() |
| 1077 | 1077 |
reg[R13_SVC].I = 0x03007FE0; |
| 1078 | 1078 |
reg[R14_SVC].I = 0x00000000; |
| 1079 | 1079 |
reg[SPSR_SVC].I = 0x00000000; |
| 1080 |
- u8 b = internalRAM[0x7ffa]; |
|
| 1080 |
+ uint8_t b = internalRAM[0x7ffa]; |
|
| 1081 | 1081 |
|
| 1082 | 1082 |
memset(&internalRAM[0x7e00], 0, 0x200); |
| 1083 | 1083 |
|
| ... | ... |
@@ -1099,7 +1099,7 @@ void BIOS_Sqrt() |
| 1099 | 1099 |
VCOUNT); |
| 1100 | 1100 |
} |
| 1101 | 1101 |
#endif |
| 1102 |
- reg[0].I = (u32)sqrt((double)reg[0].I); |
|
| 1102 |
+ reg[0].I = (uint32_t)sqrt((double)reg[0].I); |
|
| 1103 | 1103 |
#ifdef GBA_LOGGING |
| 1104 | 1104 |
if(systemVerbose & VERBOSE_SWI) {
|
| 1105 | 1105 |
log("Sqrt: return=%08x\n",
|
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,1147 @@ |
| 1 |
+#include <math.h> |
|
| 2 |
+#include <memory.h> |
|
| 3 |
+#include <stdlib.h> |
|
| 4 |
+ |
|
| 5 |
+#include "GBA.h" |
|
| 6 |
+#include "bios.h" |
|
| 7 |
+#include "GBAinline.h" |
|
| 8 |
+#include "Globals.h" |
|
| 9 |
+ |
|
| 10 |
+s16 sineTable[256] = {
|
|
| 11 |
+ (s16)0x0000, (s16)0x0192, (s16)0x0323, (s16)0x04B5, (s16)0x0645, (s16)0x07D5, (s16)0x0964, (s16)0x0AF1, |
|
| 12 |
+ (s16)0x0C7C, (s16)0x0E05, (s16)0x0F8C, (s16)0x1111, (s16)0x1294, (s16)0x1413, (s16)0x158F, (s16)0x1708, |
|
| 13 |
+ (s16)0x187D, (s16)0x19EF, (s16)0x1B5D, (s16)0x1CC6, (s16)0x1E2B, (s16)0x1F8B, (s16)0x20E7, (s16)0x223D, |
|
| 14 |
+ (s16)0x238E, (s16)0x24DA, (s16)0x261F, (s16)0x275F, (s16)0x2899, (s16)0x29CD, (s16)0x2AFA, (s16)0x2C21, |
|
| 15 |
+ (s16)0x2D41, (s16)0x2E5A, (s16)0x2F6B, (s16)0x3076, (s16)0x3179, (s16)0x3274, (s16)0x3367, (s16)0x3453, |
|
| 16 |
+ (s16)0x3536, (s16)0x3612, (s16)0x36E5, (s16)0x37AF, (s16)0x3871, (s16)0x392A, (s16)0x39DA, (s16)0x3A82, |
|
| 17 |
+ (s16)0x3B20, (s16)0x3BB6, (s16)0x3C42, (s16)0x3CC5, (s16)0x3D3E, (s16)0x3DAE, (s16)0x3E14, (s16)0x3E71, |
|
| 18 |
+ (s16)0x3EC5, (s16)0x3F0E, (s16)0x3F4E, (s16)0x3F84, (s16)0x3FB1, (s16)0x3FD3, (s16)0x3FEC, (s16)0x3FFB, |
|
| 19 |
+ (s16)0x4000, (s16)0x3FFB, (s16)0x3FEC, (s16)0x3FD3, (s16)0x3FB1, (s16)0x3F84, (s16)0x3F4E, (s16)0x3F0E, |
|
| 20 |
+ (s16)0x3EC5, (s16)0x3E71, (s16)0x3E14, (s16)0x3DAE, (s16)0x3D3E, (s16)0x3CC5, (s16)0x3C42, (s16)0x3BB6, |
|
| 21 |
+ (s16)0x3B20, (s16)0x3A82, (s16)0x39DA, (s16)0x392A, (s16)0x3871, (s16)0x37AF, (s16)0x36E5, (s16)0x3612, |
|
| 22 |
+ (s16)0x3536, (s16)0x3453, (s16)0x3367, (s16)0x3274, (s16)0x3179, (s16)0x3076, (s16)0x2F6B, (s16)0x2E5A, |
|
| 23 |
+ (s16)0x2D41, (s16)0x2C21, (s16)0x2AFA, (s16)0x29CD, (s16)0x2899, (s16)0x275F, (s16)0x261F, (s16)0x24DA, |
|
| 24 |
+ (s16)0x238E, (s16)0x223D, (s16)0x20E7, (s16)0x1F8B, (s16)0x1E2B, (s16)0x1CC6, (s16)0x1B5D, (s16)0x19EF, |
|
| 25 |
+ (s16)0x187D, (s16)0x1708, (s16)0x158F, (s16)0x1413, (s16)0x1294, (s16)0x1111, (s16)0x0F8C, (s16)0x0E05, |
|
| 26 |
+ (s16)0x0C7C, (s16)0x0AF1, (s16)0x0964, (s16)0x07D5, (s16)0x0645, (s16)0x04B5, (s16)0x0323, (s16)0x0192, |
|
| 27 |
+ (s16)0x0000, (s16)0xFE6E, (s16)0xFCDD, (s16)0xFB4B, (s16)0xF9BB, (s16)0xF82B, (s16)0xF69C, (s16)0xF50F, |
|
| 28 |
+ (s16)0xF384, (s16)0xF1FB, (s16)0xF074, (s16)0xEEEF, (s16)0xED6C, (s16)0xEBED, (s16)0xEA71, (s16)0xE8F8, |
|
| 29 |
+ (s16)0xE783, (s16)0xE611, (s16)0xE4A3, (s16)0xE33A, (s16)0xE1D5, (s16)0xE075, (s16)0xDF19, (s16)0xDDC3, |
|
| 30 |
+ (s16)0xDC72, (s16)0xDB26, (s16)0xD9E1, (s16)0xD8A1, (s16)0xD767, (s16)0xD633, (s16)0xD506, (s16)0xD3DF, |
|
| 31 |
+ (s16)0xD2BF, (s16)0xD1A6, (s16)0xD095, (s16)0xCF8A, (s16)0xCE87, (s16)0xCD8C, (s16)0xCC99, (s16)0xCBAD, |
|
| 32 |
+ (s16)0xCACA, (s16)0xC9EE, (s16)0xC91B, (s16)0xC851, (s16)0xC78F, (s16)0xC6D6, (s16)0xC626, (s16)0xC57E, |
|
| 33 |
+ (s16)0xC4E0, (s16)0xC44A, (s16)0xC3BE, (s16)0xC33B, (s16)0xC2C2, (s16)0xC252, (s16)0xC1EC, (s16)0xC18F, |
|
| 34 |
+ (s16)0xC13B, (s16)0xC0F2, (s16)0xC0B2, (s16)0xC07C, (s16)0xC04F, (s16)0xC02D, (s16)0xC014, (s16)0xC005, |
|
| 35 |
+ (s16)0xC000, (s16)0xC005, (s16)0xC014, (s16)0xC02D, (s16)0xC04F, (s16)0xC07C, (s16)0xC0B2, (s16)0xC0F2, |
|
| 36 |
+ (s16)0xC13B, (s16)0xC18F, (s16)0xC1EC, (s16)0xC252, (s16)0xC2C2, (s16)0xC33B, (s16)0xC3BE, (s16)0xC44A, |
|
| 37 |
+ (s16)0xC4E0, (s16)0xC57E, (s16)0xC626, (s16)0xC6D6, (s16)0xC78F, (s16)0xC851, (s16)0xC91B, (s16)0xC9EE, |
|
| 38 |
+ (s16)0xCACA, (s16)0xCBAD, (s16)0xCC99, (s16)0xCD8C, (s16)0xCE87, (s16)0xCF8A, (s16)0xD095, (s16)0xD1A6, |
|
| 39 |
+ (s16)0xD2BF, (s16)0xD3DF, (s16)0xD506, (s16)0xD633, (s16)0xD767, (s16)0xD8A1, (s16)0xD9E1, (s16)0xDB26, |
|
| 40 |
+ (s16)0xDC72, (s16)0xDDC3, (s16)0xDF19, (s16)0xE075, (s16)0xE1D5, (s16)0xE33A, (s16)0xE4A3, (s16)0xE611, |
|
| 41 |
+ (s16)0xE783, (s16)0xE8F8, (s16)0xEA71, (s16)0xEBED, (s16)0xED6C, (s16)0xEEEF, (s16)0xF074, (s16)0xF1FB, |
|
| 42 |
+ (s16)0xF384, (s16)0xF50F, (s16)0xF69C, (s16)0xF82B, (s16)0xF9BB, (s16)0xFB4B, (s16)0xFCDD, (s16)0xFE6E |
|
| 43 |
+}; |
|
| 44 |
+ |
|
| 45 |
+void BIOS_ArcTan() |
|
| 46 |
+{
|
|
| 47 |
+#ifdef GBA_LOGGING |
|
| 48 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 49 |
+ log("ArcTan: %08x (VCOUNT=%2d)\n",
|
|
| 50 |
+ reg[0].I, |
|
| 51 |
+ VCOUNT); |
|
| 52 |
+ } |
|
| 53 |
+#endif |
|
| 54 |
+ |
|
| 55 |
+ s32 a = -(((s32)(reg[0].I*reg[0].I)) >> 14); |
|
| 56 |
+ s32 b = ((0xA9 * a) >> 14) + 0x390; |
|
| 57 |
+ b = ((b * a) >> 14) + 0x91C; |
|
| 58 |
+ b = ((b * a) >> 14) + 0xFB6; |
|
| 59 |
+ b = ((b * a) >> 14) + 0x16AA; |
|
| 60 |
+ b = ((b * a) >> 14) + 0x2081; |
|
| 61 |
+ b = ((b * a) >> 14) + 0x3651; |
|
| 62 |
+ b = ((b * a) >> 14) + 0xA2F9; |
|
| 63 |
+ a = ((s32)reg[0].I * b) >> 16; |
|
| 64 |
+ reg[0].I = a; |
|
| 65 |
+ |
|
| 66 |
+#ifdef GBA_LOGGING |
|
| 67 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 68 |
+ log("ArcTan: return=%08x\n",
|
|
| 69 |
+ reg[0].I); |
|
| 70 |
+ } |
|
| 71 |
+#endif |
|
| 72 |
+} |
|
| 73 |
+ |
|
| 74 |
+void BIOS_ArcTan2() |
|
| 75 |
+{
|
|
| 76 |
+#ifdef GBA_LOGGING |
|
| 77 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 78 |
+ log("ArcTan2: %08x,%08x (VCOUNT=%2d)\n",
|
|
| 79 |
+ reg[0].I, |
|
| 80 |
+ reg[1].I, |
|
| 81 |
+ VCOUNT); |
|
| 82 |
+ } |
|
| 83 |
+#endif |
|
| 84 |
+ |
|
| 85 |
+ s32 x = reg[0].I; |
|
| 86 |
+ s32 y = reg[1].I; |
|
| 87 |
+ u32 res = 0; |
|
| 88 |
+ if (y == 0) {
|
|
| 89 |
+ res = ((x>>16) & 0x8000); |
|
| 90 |
+ } else {
|
|
| 91 |
+ if (x == 0) {
|
|
| 92 |
+ res = ((y>>16) & 0x8000) + 0x4000; |
|
| 93 |
+ } else {
|
|
| 94 |
+ if ((abs(x) > abs(y)) || ((abs(x) == abs(y)) && (!((x<0) && (y<0))))) {
|
|
| 95 |
+ reg[1].I = x; |
|
| 96 |
+ reg[0].I = y << 14; |
|
| 97 |
+ BIOS_Div(); |
|
| 98 |
+ BIOS_ArcTan(); |
|
| 99 |
+ if (x < 0) |
|
| 100 |
+ res = 0x8000 + reg[0].I; |
|
| 101 |
+ else |
|
| 102 |
+ res = (((y>>16) & 0x8000)<<1) + reg[0].I; |
|
| 103 |
+ } else {
|
|
| 104 |
+ reg[0].I = x << 14; |
|
| 105 |
+ BIOS_Div(); |
|
| 106 |
+ BIOS_ArcTan(); |
|
| 107 |
+ res = (0x4000 + ((y>>16) & 0x8000)) - reg[0].I; |
|
| 108 |
+ } |
|
| 109 |
+ } |
|
| 110 |
+ } |
|
| 111 |
+ reg[0].I = res; |
|
| 112 |
+ |
|
| 113 |
+#ifdef GBA_LOGGING |
|
| 114 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 115 |
+ log("ArcTan2: return=%08x\n",
|
|
| 116 |
+ reg[0].I); |
|
| 117 |
+ } |
|
| 118 |
+#endif |
|
| 119 |
+} |
|
| 120 |
+ |
|
| 121 |
+void BIOS_BitUnPack() |
|
| 122 |
+{
|
|
| 123 |
+#ifdef GBA_LOGGING |
|
| 124 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 125 |
+ log("BitUnPack: %08x,%08x,%08x (VCOUNT=%2d)\n",
|
|
| 126 |
+ reg[0].I, |
|
| 127 |
+ reg[1].I, |
|
| 128 |
+ reg[2].I, |
|
| 129 |
+ VCOUNT); |
|
| 130 |
+ } |
|
| 131 |
+#endif |
|
| 132 |
+ |
|
| 133 |
+ u32 source = reg[0].I; |
|
| 134 |
+ u32 dest = reg[1].I; |
|
| 135 |
+ u32 header = reg[2].I; |
|
| 136 |
+ |
|
| 137 |
+ int len = CPUReadHalfWord(header); |
|
| 138 |
+ // check address |
|
| 139 |
+ if(((source & 0xe000000) == 0) || |
|
| 140 |
+ ((source + len) & 0xe000000) == 0) |
|
| 141 |
+ return; |
|
| 142 |
+ |
|
| 143 |
+ int bits = CPUReadByte(header+2); |
|
| 144 |
+ int revbits = 8 - bits; |
|
| 145 |
+ // u32 value = 0; |
|
| 146 |
+ u32 base = CPUReadMemory(header+4); |
|
| 147 |
+ bool addBase = (base & 0x80000000) ? true : false; |
|
| 148 |
+ base &= 0x7fffffff; |
|
| 149 |
+ int dataSize = CPUReadByte(header+3); |
|
| 150 |
+ |
|
| 151 |
+ int data = 0; |
|
| 152 |
+ int bitwritecount = 0; |
|
| 153 |
+ while(1) {
|
|
| 154 |
+ len -= 1; |
|
| 155 |
+ if(len < 0) |
|
| 156 |
+ break; |
|
| 157 |
+ int mask = 0xff >> revbits; |
|
| 158 |
+ u8 b = CPUReadByte(source); |
|
| 159 |
+ source++; |
|
| 160 |
+ int bitcount = 0; |
|
| 161 |
+ while(1) {
|
|
| 162 |
+ if(bitcount >= 8) |
|
| 163 |
+ break; |
|
| 164 |
+ u32 d = b & mask; |
|
| 165 |
+ u32 temp = d >> bitcount; |
|
| 166 |
+ if(d || addBase) {
|
|
| 167 |
+ temp += base; |
|
| 168 |
+ } |
|
| 169 |
+ data |= temp << bitwritecount; |
|
| 170 |
+ bitwritecount += dataSize; |
|
| 171 |
+ if(bitwritecount >= 32) {
|
|
| 172 |
+ CPUWriteMemory(dest, data); |
|
| 173 |
+ dest += 4; |
|
| 174 |
+ data = 0; |
|
| 175 |
+ bitwritecount = 0; |
|
| 176 |
+ } |
|
| 177 |
+ mask <<= bits; |
|
| 178 |
+ bitcount += bits; |
|
| 179 |
+ } |
|
| 180 |
+ } |
|
| 181 |
+} |
|
| 182 |
+ |
|
| 183 |
+void BIOS_GetBiosChecksum() |
|
| 184 |
+{
|
|
| 185 |
+ reg[0].I=0xBAAE187F; |
|
| 186 |
+} |
|
| 187 |
+ |
|
| 188 |
+void BIOS_BgAffineSet() |
|
| 189 |
+{
|
|
| 190 |
+#ifdef GBA_LOGGING |
|
| 191 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 192 |
+ log("BgAffineSet: %08x,%08x,%08x (VCOUNT=%2d)\n",
|
|
| 193 |
+ reg[0].I, |
|
| 194 |
+ reg[1].I, |
|
| 195 |
+ reg[2].I, |
|
| 196 |
+ VCOUNT); |
|
| 197 |
+ } |
|
| 198 |
+#endif |
|
| 199 |
+ |
|
| 200 |
+ u32 src = reg[0].I; |
|
| 201 |
+ u32 dest = reg[1].I; |
|
| 202 |
+ int num = reg[2].I; |
|
| 203 |
+ |
|
| 204 |
+ for(int i = 0; i < num; i++) {
|
|
| 205 |
+ s32 cx = CPUReadMemory(src); |
|
| 206 |
+ src+=4; |
|
| 207 |
+ s32 cy = CPUReadMemory(src); |
|
| 208 |
+ src+=4; |
|
| 209 |
+ s16 dispx = CPUReadHalfWord(src); |
|
| 210 |
+ src+=2; |
|
| 211 |
+ s16 dispy = CPUReadHalfWord(src); |
|
| 212 |
+ src+=2; |
|
| 213 |
+ s16 rx = CPUReadHalfWord(src); |
|
| 214 |
+ src+=2; |
|
| 215 |
+ s16 ry = CPUReadHalfWord(src); |
|
| 216 |
+ src+=2; |
|
| 217 |
+ u16 theta = CPUReadHalfWord(src)>>8; |
|
| 218 |
+ src+=4; // keep structure alignment |
|
| 219 |
+ s32 a = sineTable[(theta+0x40)&255]; |
|
| 220 |
+ s32 b = sineTable[theta]; |
|
| 221 |
+ |
|
| 222 |
+ s16 dx = (rx * a)>>14; |
|
| 223 |
+ s16 dmx = (rx * b)>>14; |
|
| 224 |
+ s16 dy = (ry * b)>>14; |
|
| 225 |
+ s16 dmy = (ry * a)>>14; |
|
| 226 |
+ |
|
| 227 |
+ CPUWriteHalfWord(dest, dx); |
|
| 228 |
+ dest += 2; |
|
| 229 |
+ CPUWriteHalfWord(dest, -dmx); |
|
| 230 |
+ dest += 2; |
|
| 231 |
+ CPUWriteHalfWord(dest, dy); |
|
| 232 |
+ dest += 2; |
|
| 233 |
+ CPUWriteHalfWord(dest, dmy); |
|
| 234 |
+ dest += 2; |
|
| 235 |
+ |
|
| 236 |
+ s32 startx = cx - dx * dispx + dmx * dispy; |
|
| 237 |
+ s32 starty = cy - dy * dispx - dmy * dispy; |
|
| 238 |
+ |
|
| 239 |
+ CPUWriteMemory(dest, startx); |
|
| 240 |
+ dest += 4; |
|
| 241 |
+ CPUWriteMemory(dest, starty); |
|
| 242 |
+ dest += 4; |
|
| 243 |
+ } |
|
| 244 |
+} |
|
| 245 |
+ |
|
| 246 |
+void BIOS_CpuSet() |
|
| 247 |
+{
|
|
| 248 |
+#ifdef GBA_LOGGING |
|
| 249 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 250 |
+ log("CpuSet: 0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
|
|
| 251 |
+ reg[2].I, VCOUNT); |
|
| 252 |
+ } |
|
| 253 |
+#endif |
|
| 254 |
+ |
|
| 255 |
+ u32 source = reg[0].I; |
|
| 256 |
+ u32 dest = reg[1].I; |
|
| 257 |
+ u32 cnt = reg[2].I; |
|
| 258 |
+ |
|
| 259 |
+ if(((source & 0xe000000) == 0) || |
|
| 260 |
+ ((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0) |
|
| 261 |
+ return; |
|
| 262 |
+ |
|
| 263 |
+ int count = cnt & 0x1FFFFF; |
|
| 264 |
+ |
|
| 265 |
+ // 32-bit ? |
|
| 266 |
+ if((cnt >> 26) & 1) {
|
|
| 267 |
+ // needed for 32-bit mode! |
|
| 268 |
+ source &= 0xFFFFFFFC; |
|
| 269 |
+ dest &= 0xFFFFFFFC; |
|
| 270 |
+ // fill ? |
|
| 271 |
+ if((cnt >> 24) & 1) {
|
|
| 272 |
+ u32 value = (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source)); |
|
| 273 |
+ while(count) {
|
|
| 274 |
+ CPUWriteMemory(dest, value); |
|
| 275 |
+ dest += 4; |
|
| 276 |
+ count--; |
|
| 277 |
+ } |
|
| 278 |
+ } else {
|
|
| 279 |
+ // copy |
|
| 280 |
+ while(count) {
|
|
| 281 |
+ CPUWriteMemory(dest, (source>0x0EFFFFFF ? 0x1CAD1CAD : CPUReadMemory(source))); |
|
| 282 |
+ source += 4; |
|
| 283 |
+ dest += 4; |
|
| 284 |
+ count--; |
|
| 285 |
+ } |
|
| 286 |
+ } |
|
| 287 |
+ } else {
|
|
| 288 |
+ // 16-bit fill? |
|
| 289 |
+ if((cnt >> 24) & 1) {
|
|
| 290 |
+ u16 value = (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source)); |
|
| 291 |
+ while(count) {
|
|
| 292 |
+ CPUWriteHalfWord(dest, value); |
|
| 293 |
+ dest += 2; |
|
| 294 |
+ count--; |
|
| 295 |
+ } |
|
| 296 |
+ } else {
|
|
| 297 |
+ // copy |
|
| 298 |
+ while(count) {
|
|
| 299 |
+ CPUWriteHalfWord(dest, (source>0x0EFFFFFF ? 0x1CAD : CPUReadHalfWord(source))); |
|
| 300 |
+ source += 2; |
|
| 301 |
+ dest += 2; |
|
| 302 |
+ count--; |
|
| 303 |
+ } |
|
| 304 |
+ } |
|
| 305 |
+ } |
|
| 306 |
+} |
|
| 307 |
+ |
|
| 308 |
+void BIOS_CpuFastSet() |
|
| 309 |
+{
|
|
| 310 |
+#ifdef GBA_LOGGING |
|
| 311 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 312 |
+ log("CpuFastSet: 0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
|
|
| 313 |
+ reg[2].I, VCOUNT); |
|
| 314 |
+ } |
|
| 315 |
+#endif |
|
| 316 |
+ |
|
| 317 |
+ u32 source = reg[0].I; |
|
| 318 |
+ u32 dest = reg[1].I; |
|
| 319 |
+ u32 cnt = reg[2].I; |
|
| 320 |
+ |
|
| 321 |
+ if(((source & 0xe000000) == 0) || |
|
| 322 |
+ ((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0) |
|
| 323 |
+ return; |
|
| 324 |
+ |
|
| 325 |
+ // needed for 32-bit mode! |
|
| 326 |
+ source &= 0xFFFFFFFC; |
|
| 327 |
+ dest &= 0xFFFFFFFC; |
|
| 328 |
+ |
|
| 329 |
+ int count = cnt & 0x1FFFFF; |
|
| 330 |
+ |
|
| 331 |
+ // fill? |
|
| 332 |
+ if((cnt >> 24) & 1) {
|
|
| 333 |
+ while(count > 0) {
|
|
| 334 |
+ // BIOS always transfers 32 bytes at a time |
|
| 335 |
+ u32 value = (source>0x0EFFFFFF ? 0xBAFFFFFB : CPUReadMemory(source)); |
|
| 336 |
+ for(int i = 0; i < 8; i++) {
|
|
| 337 |
+ CPUWriteMemory(dest, value); |
|
| 338 |
+ dest += 4; |
|
| 339 |
+ } |
|
| 340 |
+ count -= 8; |
|
| 341 |
+ } |
|
| 342 |
+ } else {
|
|
| 343 |
+ // copy |
|
| 344 |
+ while(count > 0) {
|
|
| 345 |
+ // BIOS always transfers 32 bytes at a time |
|
| 346 |
+ for(int i = 0; i < 8; i++) {
|
|
| 347 |
+ CPUWriteMemory(dest, (source>0x0EFFFFFF ? 0xBAFFFFFB :CPUReadMemory(source))); |
|
| 348 |
+ source += 4; |
|
| 349 |
+ dest += 4; |
|
| 350 |
+ } |
|
| 351 |
+ count -= 8; |
|
| 352 |
+ } |
|
| 353 |
+ } |
|
| 354 |
+} |
|
| 355 |
+ |
|
| 356 |
+void BIOS_Diff8bitUnFilterWram() |
|
| 357 |
+{
|
|
| 358 |
+#ifdef GBA_LOGGING |
|
| 359 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 360 |
+ log("Diff8bitUnFilterWram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
|
|
| 361 |
+ reg[1].I, VCOUNT); |
|
| 362 |
+ } |
|
| 363 |
+#endif |
|
| 364 |
+ |
|
| 365 |
+ u32 source = reg[0].I; |
|
| 366 |
+ u32 dest = reg[1].I; |
|
| 367 |
+ |
|
| 368 |
+ u32 header = CPUReadMemory(source); |
|
| 369 |
+ source += 4; |
|
| 370 |
+ |
|
| 371 |
+ if(((source & 0xe000000) == 0) || |
|
| 372 |
+ (((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)) |
|
| 373 |
+ return; |
|
| 374 |
+ |
|
| 375 |
+ int len = header >> 8; |
|
| 376 |
+ |
|
| 377 |
+ u8 data = CPUReadByte(source++); |
|
| 378 |
+ CPUWriteByte(dest++, data); |
|
| 379 |
+ len--; |
|
| 380 |
+ |
|
| 381 |
+ while(len > 0) {
|
|
| 382 |
+ u8 diff = CPUReadByte(source++); |
|
| 383 |
+ data += diff; |
|
| 384 |
+ CPUWriteByte(dest++, data); |
|
| 385 |
+ len--; |
|
| 386 |
+ } |
|
| 387 |
+} |
|
| 388 |
+ |
|
| 389 |
+void BIOS_Diff8bitUnFilterVram() |
|
| 390 |
+{
|
|
| 391 |
+#ifdef GBA_LOGGING |
|
| 392 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 393 |
+ log("Diff8bitUnFilterVram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
|
|
| 394 |
+ reg[1].I, VCOUNT); |
|
| 395 |
+ } |
|
| 396 |
+#endif |
|
| 397 |
+ |
|
| 398 |
+ u32 source = reg[0].I; |
|
| 399 |
+ u32 dest = reg[1].I; |
|
| 400 |
+ |
|
| 401 |
+ u32 header = CPUReadMemory(source); |
|
| 402 |
+ source += 4; |
|
| 403 |
+ |
|
| 404 |
+ if(((source & 0xe000000) == 0) || |
|
| 405 |
+ ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 406 |
+ return; |
|
| 407 |
+ |
|
| 408 |
+ int len = header >> 8; |
|
| 409 |
+ |
|
| 410 |
+ u8 data = CPUReadByte(source++); |
|
| 411 |
+ u16 writeData = data; |
|
| 412 |
+ int shift = 8; |
|
| 413 |
+ int bytes = 1; |
|
| 414 |
+ |
|
| 415 |
+ while(len >= 2) {
|
|
| 416 |
+ u8 diff = CPUReadByte(source++); |
|
| 417 |
+ data += diff; |
|
| 418 |
+ writeData |= (data << shift); |
|
| 419 |
+ bytes++; |
|
| 420 |
+ shift += 8; |
|
| 421 |
+ if(bytes == 2) {
|
|
| 422 |
+ CPUWriteHalfWord(dest, writeData); |
|
| 423 |
+ dest += 2; |
|
| 424 |
+ len -= 2; |
|
| 425 |
+ bytes = 0; |
|
| 426 |
+ writeData = 0; |
|
| 427 |
+ shift = 0; |
|
| 428 |
+ } |
|
| 429 |
+ } |
|
| 430 |
+} |
|
| 431 |
+ |
|
| 432 |
+void BIOS_Diff16bitUnFilter() |
|
| 433 |
+{
|
|
| 434 |
+#ifdef GBA_LOGGING |
|
| 435 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 436 |
+ log("Diff16bitUnFilter: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I,
|
|
| 437 |
+ reg[1].I, VCOUNT); |
|
| 438 |
+ } |
|
| 439 |
+#endif |
|
| 440 |
+ |
|
| 441 |
+ u32 source = reg[0].I; |
|
| 442 |
+ u32 dest = reg[1].I; |
|
| 443 |
+ |
|
| 444 |
+ u32 header = CPUReadMemory(source); |
|
| 445 |
+ source += 4; |
|
| 446 |
+ |
|
| 447 |
+ if(((source & 0xe000000) == 0) || |
|
| 448 |
+ ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 449 |
+ return; |
|
| 450 |
+ |
|
| 451 |
+ int len = header >> 8; |
|
| 452 |
+ |
|
| 453 |
+ u16 data = CPUReadHalfWord(source); |
|
| 454 |
+ source += 2; |
|
| 455 |
+ CPUWriteHalfWord(dest, data); |
|
| 456 |
+ dest += 2; |
|
| 457 |
+ len -= 2; |
|
| 458 |
+ |
|
| 459 |
+ while(len >= 2) {
|
|
| 460 |
+ u16 diff = CPUReadHalfWord(source); |
|
| 461 |
+ source += 2; |
|
| 462 |
+ data += diff; |
|
| 463 |
+ CPUWriteHalfWord(dest, data); |
|
| 464 |
+ dest += 2; |
|
| 465 |
+ len -= 2; |
|
| 466 |
+ } |
|
| 467 |
+} |
|
| 468 |
+ |
|
| 469 |
+void BIOS_Div() |
|
| 470 |
+{
|
|
| 471 |
+#ifdef GBA_LOGGING |
|
| 472 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 473 |
+ log("Div: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 474 |
+ reg[0].I, |
|
| 475 |
+ reg[1].I, |
|
| 476 |
+ VCOUNT); |
|
| 477 |
+ } |
|
| 478 |
+#endif |
|
| 479 |
+ |
|
| 480 |
+ int number = reg[0].I; |
|
| 481 |
+ int denom = reg[1].I; |
|
| 482 |
+ |
|
| 483 |
+ if(denom != 0) {
|
|
| 484 |
+ reg[0].I = number / denom; |
|
| 485 |
+ reg[1].I = number % denom; |
|
| 486 |
+ s32 temp = (s32)reg[0].I; |
|
| 487 |
+ reg[3].I = temp < 0 ? (u32)-temp : (u32)temp; |
|
| 488 |
+ } |
|
| 489 |
+#ifdef GBA_LOGGING |
|
| 490 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 491 |
+ log("Div: return=0x%08x,0x%08x,0x%08x\n",
|
|
| 492 |
+ reg[0].I, |
|
| 493 |
+ reg[1].I, |
|
| 494 |
+ reg[3].I); |
|
| 495 |
+ } |
|
| 496 |
+#endif |
|
| 497 |
+} |
|
| 498 |
+ |
|
| 499 |
+void BIOS_DivARM() |
|
| 500 |
+{
|
|
| 501 |
+#ifdef GBA_LOGGING |
|
| 502 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 503 |
+ log("DivARM: 0x%08x, (VCOUNT=%d)\n",
|
|
| 504 |
+ reg[0].I, |
|
| 505 |
+ VCOUNT); |
|
| 506 |
+ } |
|
| 507 |
+#endif |
|
| 508 |
+ |
|
| 509 |
+ u32 temp = reg[0].I; |
|
| 510 |
+ reg[0].I = reg[1].I; |
|
| 511 |
+ reg[1].I = temp; |
|
| 512 |
+ BIOS_Div(); |
|
| 513 |
+} |
|
| 514 |
+ |
|
| 515 |
+void BIOS_HuffUnComp() |
|
| 516 |
+{
|
|
| 517 |
+#ifdef GBA_LOGGING |
|
| 518 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 519 |
+ log("HuffUnComp: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 520 |
+ reg[0].I, |
|
| 521 |
+ reg[1].I, |
|
| 522 |
+ VCOUNT); |
|
| 523 |
+ } |
|
| 524 |
+#endif |
|
| 525 |
+ |
|
| 526 |
+ u32 source = reg[0].I; |
|
| 527 |
+ u32 dest = reg[1].I; |
|
| 528 |
+ |
|
| 529 |
+ u32 header = CPUReadMemory(source); |
|
| 530 |
+ source += 4; |
|
| 531 |
+ |
|
| 532 |
+ if(((source & 0xe000000) == 0) || |
|
| 533 |
+ ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 534 |
+ return; |
|
| 535 |
+ |
|
| 536 |
+ u8 treeSize = CPUReadByte(source++); |
|
| 537 |
+ |
|
| 538 |
+ u32 treeStart = source; |
|
| 539 |
+ |
|
| 540 |
+ source += ((treeSize+1)<<1)-1; // minus because we already skipped one byte |
|
| 541 |
+ |
|
| 542 |
+ int len = header >> 8; |
|
| 543 |
+ |
|
| 544 |
+ u32 mask = 0x80000000; |
|
| 545 |
+ u32 data = CPUReadMemory(source); |
|
| 546 |
+ source += 4; |
|
| 547 |
+ |
|
| 548 |
+ int pos = 0; |
|
| 549 |
+ u8 rootNode = CPUReadByte(treeStart); |
|
| 550 |
+ u8 currentNode = rootNode; |
|
| 551 |
+ bool writeData = false; |
|
| 552 |
+ int byteShift = 0; |
|
| 553 |
+ int byteCount = 0; |
|
| 554 |
+ u32 writeValue = 0; |
|
| 555 |
+ |
|
| 556 |
+ if((header & 0x0F) == 8) {
|
|
| 557 |
+ while(len > 0) {
|
|
| 558 |
+ // take left |
|
| 559 |
+ if(pos == 0) |
|
| 560 |
+ pos++; |
|
| 561 |
+ else |
|
| 562 |
+ pos += (((currentNode & 0x3F)+1)<<1); |
|
| 563 |
+ |
|
| 564 |
+ if(data & mask) {
|
|
| 565 |
+ // right |
|
| 566 |
+ if(currentNode & 0x40) |
|
| 567 |
+ writeData = true; |
|
| 568 |
+ currentNode = CPUReadByte(treeStart+pos+1); |
|
| 569 |
+ } else {
|
|
| 570 |
+ // left |
|
| 571 |
+ if(currentNode & 0x80) |
|
| 572 |
+ writeData = true; |
|
| 573 |
+ currentNode = CPUReadByte(treeStart+pos); |
|
| 574 |
+ } |
|
| 575 |
+ |
|
| 576 |
+ if(writeData) {
|
|
| 577 |
+ writeValue |= (currentNode << byteShift); |
|
| 578 |
+ byteCount++; |
|
| 579 |
+ byteShift += 8; |
|
| 580 |
+ |
|
| 581 |
+ pos = 0; |
|
| 582 |
+ currentNode = rootNode; |
|
| 583 |
+ writeData = false; |
|
| 584 |
+ |
|
| 585 |
+ if(byteCount == 4) {
|
|
| 586 |
+ byteCount = 0; |
|
| 587 |
+ byteShift = 0; |
|
| 588 |
+ CPUWriteMemory(dest, writeValue); |
|
| 589 |
+ writeValue = 0; |
|
| 590 |
+ dest += 4; |
|
| 591 |
+ len -= 4; |
|
| 592 |
+ } |
|
| 593 |
+ } |
|
| 594 |
+ mask >>= 1; |
|
| 595 |
+ if(mask == 0) {
|
|
| 596 |
+ mask = 0x80000000; |
|
| 597 |
+ data = CPUReadMemory(source); |
|
| 598 |
+ source += 4; |
|
| 599 |
+ } |
|
| 600 |
+ } |
|
| 601 |
+ } else {
|
|
| 602 |
+ int halfLen = 0; |
|
| 603 |
+ int value = 0; |
|
| 604 |
+ while(len > 0) {
|
|
| 605 |
+ // take left |
|
| 606 |
+ if(pos == 0) |
|
| 607 |
+ pos++; |
|
| 608 |
+ else |
|
| 609 |
+ pos += (((currentNode & 0x3F)+1)<<1); |
|
| 610 |
+ |
|
| 611 |
+ if((data & mask)) {
|
|
| 612 |
+ // right |
|
| 613 |
+ if(currentNode & 0x40) |
|
| 614 |
+ writeData = true; |
|
| 615 |
+ currentNode = CPUReadByte(treeStart+pos+1); |
|
| 616 |
+ } else {
|
|
| 617 |
+ // left |
|
| 618 |
+ if(currentNode & 0x80) |
|
| 619 |
+ writeData = true; |
|
| 620 |
+ currentNode = CPUReadByte(treeStart+pos); |
|
| 621 |
+ } |
|
| 622 |
+ |
|
| 623 |
+ if(writeData) {
|
|
| 624 |
+ if(halfLen == 0) |
|
| 625 |
+ value |= currentNode; |
|
| 626 |
+ else |
|
| 627 |
+ value |= (currentNode<<4); |
|
| 628 |
+ |
|
| 629 |
+ halfLen += 4; |
|
| 630 |
+ if(halfLen == 8) {
|
|
| 631 |
+ writeValue |= (value << byteShift); |
|
| 632 |
+ byteCount++; |
|
| 633 |
+ byteShift += 8; |
|
| 634 |
+ |
|
| 635 |
+ halfLen = 0; |
|
| 636 |
+ value = 0; |
|
| 637 |
+ |
|
| 638 |
+ if(byteCount == 4) {
|
|
| 639 |
+ byteCount = 0; |
|
| 640 |
+ byteShift = 0; |
|
| 641 |
+ CPUWriteMemory(dest, writeValue); |
|
| 642 |
+ dest += 4; |
|
| 643 |
+ writeValue = 0; |
|
| 644 |
+ len -= 4; |
|
| 645 |
+ } |
|
| 646 |
+ } |
|
| 647 |
+ pos = 0; |
|
| 648 |
+ currentNode = rootNode; |
|
| 649 |
+ writeData = false; |
|
| 650 |
+ } |
|
| 651 |
+ mask >>= 1; |
|
| 652 |
+ if(mask == 0) {
|
|
| 653 |
+ mask = 0x80000000; |
|
| 654 |
+ data = CPUReadMemory(source); |
|
| 655 |
+ source += 4; |
|
| 656 |
+ } |
|
| 657 |
+ } |
|
| 658 |
+ } |
|
| 659 |
+} |
|
| 660 |
+ |
|
| 661 |
+void BIOS_LZ77UnCompVram() |
|
| 662 |
+{
|
|
| 663 |
+#ifdef GBA_LOGGING |
|
| 664 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 665 |
+ log("LZ77UnCompVram: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 666 |
+ reg[0].I, |
|
| 667 |
+ reg[1].I, |
|
| 668 |
+ VCOUNT); |
|
| 669 |
+ } |
|
| 670 |
+#endif |
|
| 671 |
+ |
|
| 672 |
+ u32 source = reg[0].I; |
|
| 673 |
+ u32 dest = reg[1].I; |
|
| 674 |
+ |
|
| 675 |
+ u32 header = CPUReadMemory(source); |
|
| 676 |
+ source += 4; |
|
| 677 |
+ |
|
| 678 |
+ if(((source & 0xe000000) == 0) || |
|
| 679 |
+ ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 680 |
+ return; |
|
| 681 |
+ |
|
| 682 |
+ int byteCount = 0; |
|
| 683 |
+ int byteShift = 0; |
|
| 684 |
+ u32 writeValue = 0; |
|
| 685 |
+ |
|
| 686 |
+ int len = header >> 8; |
|
| 687 |
+ |
|
| 688 |
+ while(len > 0) {
|
|
| 689 |
+ u8 d = CPUReadByte(source++); |
|
| 690 |
+ |
|
| 691 |
+ if(d) {
|
|
| 692 |
+ for(int i = 0; i < 8; i++) {
|
|
| 693 |
+ if(d & 0x80) {
|
|
| 694 |
+ u16 data = CPUReadByte(source++) << 8; |
|
| 695 |
+ data |= CPUReadByte(source++); |
|
| 696 |
+ int length = (data >> 12) + 3; |
|
| 697 |
+ int offset = (data & 0x0FFF); |
|
| 698 |
+ u32 windowOffset = dest + byteCount - offset - 1; |
|
| 699 |
+ for(int i2 = 0; i2 < length; i2++) {
|
|
| 700 |
+ writeValue |= (CPUReadByte(windowOffset++) << byteShift); |
|
| 701 |
+ byteShift += 8; |
|
| 702 |
+ byteCount++; |
|
| 703 |
+ |
|
| 704 |
+ if(byteCount == 2) {
|
|
| 705 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 706 |
+ dest += 2; |
|
| 707 |
+ byteCount = 0; |
|
| 708 |
+ byteShift = 0; |
|
| 709 |
+ writeValue = 0; |
|
| 710 |
+ } |
|
| 711 |
+ len--; |
|
| 712 |
+ if(len == 0) |
|
| 713 |
+ return; |
|
| 714 |
+ } |
|
| 715 |
+ } else {
|
|
| 716 |
+ writeValue |= (CPUReadByte(source++) << byteShift); |
|
| 717 |
+ byteShift += 8; |
|
| 718 |
+ byteCount++; |
|
| 719 |
+ if(byteCount == 2) {
|
|
| 720 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 721 |
+ dest += 2; |
|
| 722 |
+ byteCount = 0; |
|
| 723 |
+ byteShift = 0; |
|
| 724 |
+ writeValue = 0; |
|
| 725 |
+ } |
|
| 726 |
+ len--; |
|
| 727 |
+ if(len == 0) |
|
| 728 |
+ return; |
|
| 729 |
+ } |
|
| 730 |
+ d <<= 1; |
|
| 731 |
+ } |
|
| 732 |
+ } else {
|
|
| 733 |
+ for(int i = 0; i < 8; i++) {
|
|
| 734 |
+ writeValue |= (CPUReadByte(source++) << byteShift); |
|
| 735 |
+ byteShift += 8; |
|
| 736 |
+ byteCount++; |
|
| 737 |
+ if(byteCount == 2) {
|
|
| 738 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 739 |
+ dest += 2; |
|
| 740 |
+ byteShift = 0; |
|
| 741 |
+ byteCount = 0; |
|
| 742 |
+ writeValue = 0; |
|
| 743 |
+ } |
|
| 744 |
+ len--; |
|
| 745 |
+ if(len == 0) |
|
| 746 |
+ return; |
|
| 747 |
+ } |
|
| 748 |
+ } |
|
| 749 |
+ } |
|
| 750 |
+} |
|
| 751 |
+ |
|
| 752 |
+void BIOS_LZ77UnCompWram() |
|
| 753 |
+{
|
|
| 754 |
+#ifdef GBA_LOGGING |
|
| 755 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 756 |
+ log("LZ77UnCompWram: 0x%08x,0x%08x (VCOUNT=%d)\n", reg[0].I, reg[1].I,
|
|
| 757 |
+ VCOUNT); |
|
| 758 |
+ } |
|
| 759 |
+#endif |
|
| 760 |
+ |
|
| 761 |
+ u32 source = reg[0].I; |
|
| 762 |
+ u32 dest = reg[1].I; |
|
| 763 |
+ |
|
| 764 |
+ u32 header = CPUReadMemory(source); |
|
| 765 |
+ source += 4; |
|
| 766 |
+ |
|
| 767 |
+ if(((source & 0xe000000) == 0) || |
|
| 768 |
+ ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 769 |
+ return; |
|
| 770 |
+ |
|
| 771 |
+ int len = header >> 8; |
|
| 772 |
+ |
|
| 773 |
+ while(len > 0) {
|
|
| 774 |
+ u8 d = CPUReadByte(source++); |
|
| 775 |
+ |
|
| 776 |
+ if(d) {
|
|
| 777 |
+ for(int i = 0; i < 8; i++) {
|
|
| 778 |
+ if(d & 0x80) {
|
|
| 779 |
+ u16 data = CPUReadByte(source++) << 8; |
|
| 780 |
+ data |= CPUReadByte(source++); |
|
| 781 |
+ int length = (data >> 12) + 3; |
|
| 782 |
+ int offset = (data & 0x0FFF); |
|
| 783 |
+ u32 windowOffset = dest - offset - 1; |
|
| 784 |
+ for(int i2 = 0; i2 < length; i2++) {
|
|
| 785 |
+ CPUWriteByte(dest++, CPUReadByte(windowOffset++)); |
|
| 786 |
+ len--; |
|
| 787 |
+ if(len == 0) |
|
| 788 |
+ return; |
|
| 789 |
+ } |
|
| 790 |
+ } else {
|
|
| 791 |
+ CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 792 |
+ len--; |
|
| 793 |
+ if(len == 0) |
|
| 794 |
+ return; |
|
| 795 |
+ } |
|
| 796 |
+ d <<= 1; |
|
| 797 |
+ } |
|
| 798 |
+ } else {
|
|
| 799 |
+ for(int i = 0; i < 8; i++) {
|
|
| 800 |
+ CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 801 |
+ len--; |
|
| 802 |
+ if(len == 0) |
|
| 803 |
+ return; |
|
| 804 |
+ } |
|
| 805 |
+ } |
|
| 806 |
+ } |
|
| 807 |
+} |
|
| 808 |
+ |
|
| 809 |
+void BIOS_ObjAffineSet() |
|
| 810 |
+{
|
|
| 811 |
+#ifdef GBA_LOGGING |
|
| 812 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 813 |
+ log("ObjAffineSet: 0x%08x,0x%08x,0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 814 |
+ reg[0].I, |
|
| 815 |
+ reg[1].I, |
|
| 816 |
+ reg[2].I, |
|
| 817 |
+ reg[3].I, |
|
| 818 |
+ VCOUNT); |
|
| 819 |
+ } |
|
| 820 |
+#endif |
|
| 821 |
+ |
|
| 822 |
+ u32 src = reg[0].I; |
|
| 823 |
+ u32 dest = reg[1].I; |
|
| 824 |
+ int num = reg[2].I; |
|
| 825 |
+ int offset = reg[3].I; |
|
| 826 |
+ |
|
| 827 |
+ for(int i = 0; i < num; i++) {
|
|
| 828 |
+ s16 rx = CPUReadHalfWord(src); |
|
| 829 |
+ src+=2; |
|
| 830 |
+ s16 ry = CPUReadHalfWord(src); |
|
| 831 |
+ src+=2; |
|
| 832 |
+ u16 theta = CPUReadHalfWord(src)>>8; |
|
| 833 |
+ src+=4; // keep structure alignment |
|
| 834 |
+ |
|
| 835 |
+ s32 a = (s32)sineTable[(theta+0x40)&255]; |
|
| 836 |
+ s32 b = (s32)sineTable[theta]; |
|
| 837 |
+ |
|
| 838 |
+ s16 dx = ((s32)rx * a)>>14; |
|
| 839 |
+ s16 dmx = ((s32)rx * b)>>14; |
|
| 840 |
+ s16 dy = ((s32)ry * b)>>14; |
|
| 841 |
+ s16 dmy = ((s32)ry * a)>>14; |
|
| 842 |
+ |
|
| 843 |
+ CPUWriteHalfWord(dest, dx); |
|
| 844 |
+ dest += offset; |
|
| 845 |
+ CPUWriteHalfWord(dest, -dmx); |
|
| 846 |
+ dest += offset; |
|
| 847 |
+ CPUWriteHalfWord(dest, dy); |
|
| 848 |
+ dest += offset; |
|
| 849 |
+ CPUWriteHalfWord(dest, dmy); |
|
| 850 |
+ dest += offset; |
|
| 851 |
+ } |
|
| 852 |
+} |
|
| 853 |
+ |
|
| 854 |
+void BIOS_RegisterRamReset(u32 flags) |
|
| 855 |
+{
|
|
| 856 |
+ // no need to trace here. this is only called directly from GBA.cpp |
|
| 857 |
+ // to emulate bios initialization |
|
| 858 |
+ |
|
| 859 |
+ CPUUpdateRegister(0x0, 0x80); |
|
| 860 |
+ |
|
| 861 |
+ if(flags) {
|
|
| 862 |
+ if(flags & 0x01) {
|
|
| 863 |
+ // clear work RAM |
|
| 864 |
+ memset(workRAM, 0, 0x40000); |
|
| 865 |
+ } |
|
| 866 |
+ if(flags & 0x02) {
|
|
| 867 |
+ // clear internal RAM |
|
| 868 |
+ memset(internalRAM, 0, 0x7e00); // don't clear 0x7e00-0x7fff |
|
| 869 |
+ } |
|
| 870 |
+ if(flags & 0x04) {
|
|
| 871 |
+ // clear palette RAM |
|
| 872 |
+ memset(paletteRAM, 0, 0x400); |
|
| 873 |
+ } |
|
| 874 |
+ if(flags & 0x08) {
|
|
| 875 |
+ // clear VRAM |
|
| 876 |
+ memset(vram, 0, 0x18000); |
|
| 877 |
+ } |
|
| 878 |
+ if(flags & 0x10) {
|
|
| 879 |
+ // clean OAM |
|
| 880 |
+ memset(oam, 0, 0x400); |
|
| 881 |
+ } |
|
| 882 |
+ |
|
| 883 |
+ if(flags & 0x80) {
|
|
| 884 |
+ int i; |
|
| 885 |
+ for(i = 0; i < 0x10; i++) |
|
| 886 |
+ CPUUpdateRegister(0x200+i*2, 0); |
|
| 887 |
+ |
|
| 888 |
+ for(i = 0; i < 0xF; i++) |
|
| 889 |
+ CPUUpdateRegister(0x4+i*2, 0); |
|
| 890 |
+ |
|
| 891 |
+ for(i = 0; i < 0x20; i++) |
|
| 892 |
+ CPUUpdateRegister(0x20+i*2, 0); |
|
| 893 |
+ |
|
| 894 |
+ for(i = 0; i < 0x18; i++) |
|
| 895 |
+ CPUUpdateRegister(0xb0+i*2, 0); |
|
| 896 |
+ |
|
| 897 |
+ CPUUpdateRegister(0x130, 0); |
|
| 898 |
+ CPUUpdateRegister(0x20, 0x100); |
|
| 899 |
+ CPUUpdateRegister(0x30, 0x100); |
|
| 900 |
+ CPUUpdateRegister(0x26, 0x100); |
|
| 901 |
+ CPUUpdateRegister(0x36, 0x100); |
|
| 902 |
+ } |
|
| 903 |
+ |
|
| 904 |
+ if(flags & 0x20) {
|
|
| 905 |
+ int i; |
|
| 906 |
+ for(i = 0; i < 8; i++) |
|
| 907 |
+ CPUUpdateRegister(0x110+i*2, 0); |
|
| 908 |
+ CPUUpdateRegister(0x134, 0x8000); |
|
| 909 |
+ for(i = 0; i < 7; i++) |
|
| 910 |
+ CPUUpdateRegister(0x140+i*2, 0); |
|
| 911 |
+ } |
|
| 912 |
+ |
|
| 913 |
+ if(flags & 0x40) {
|
|
| 914 |
+ int i; |
|
| 915 |
+ CPUWriteByte(0x4000084, 0); |
|
| 916 |
+ CPUWriteByte(0x4000084, 0x80); |
|
| 917 |
+ CPUWriteMemory(0x4000080, 0x880e0000); |
|
| 918 |
+ CPUUpdateRegister(0x88, CPUReadHalfWord(0x4000088)&0x3ff); |
|
| 919 |
+ CPUWriteByte(0x4000070, 0x70); |
|
| 920 |
+ for(i = 0; i < 8; i++) |
|
| 921 |
+ CPUUpdateRegister(0x90+i*2, 0); |
|
| 922 |
+ CPUWriteByte(0x4000070, 0); |
|
| 923 |
+ for(i = 0; i < 8; i++) |
|
| 924 |
+ CPUUpdateRegister(0x90+i*2, 0); |
|
| 925 |
+ CPUWriteByte(0x4000084, 0); |
|
| 926 |
+ } |
|
| 927 |
+ } |
|
| 928 |
+} |
|
| 929 |
+ |
|
| 930 |
+void BIOS_RegisterRamReset() |
|
| 931 |
+{
|
|
| 932 |
+#ifdef GBA_LOGGING |
|
| 933 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 934 |
+ log("RegisterRamReset: 0x%08x (VCOUNT=%d)\n",
|
|
| 935 |
+ reg[0].I, |
|
| 936 |
+ VCOUNT); |
|
| 937 |
+ } |
|
| 938 |
+#endif |
|
| 939 |
+ |
|
| 940 |
+ BIOS_RegisterRamReset(reg[0].I); |
|
| 941 |
+} |
|
| 942 |
+ |
|
| 943 |
+void BIOS_RLUnCompVram() |
|
| 944 |
+{
|
|
| 945 |
+#ifdef GBA_LOGGING |
|
| 946 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 947 |
+ log("RLUnCompVram: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 948 |
+ reg[0].I, |
|
| 949 |
+ reg[1].I, |
|
| 950 |
+ VCOUNT); |
|
| 951 |
+ } |
|
| 952 |
+#endif |
|
| 953 |
+ |
|
| 954 |
+ u32 source = reg[0].I; |
|
| 955 |
+ u32 dest = reg[1].I; |
|
| 956 |
+ |
|
| 957 |
+ u32 header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 958 |
+ source += 4; |
|
| 959 |
+ |
|
| 960 |
+ if(((source & 0xe000000) == 0) || |
|
| 961 |
+ ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 962 |
+ return; |
|
| 963 |
+ |
|
| 964 |
+ int len = header >> 8; |
|
| 965 |
+ int byteCount = 0; |
|
| 966 |
+ int byteShift = 0; |
|
| 967 |
+ u32 writeValue = 0; |
|
| 968 |
+ |
|
| 969 |
+ while(len > 0) {
|
|
| 970 |
+ u8 d = CPUReadByte(source++); |
|
| 971 |
+ int l = d & 0x7F; |
|
| 972 |
+ if(d & 0x80) {
|
|
| 973 |
+ u8 data = CPUReadByte(source++); |
|
| 974 |
+ l += 3; |
|
| 975 |
+ for(int i = 0;i < l; i++) {
|
|
| 976 |
+ writeValue |= (data << byteShift); |
|
| 977 |
+ byteShift += 8; |
|
| 978 |
+ byteCount++; |
|
| 979 |
+ |
|
| 980 |
+ if(byteCount == 2) {
|
|
| 981 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 982 |
+ dest += 2; |
|
| 983 |
+ byteCount = 0; |
|
| 984 |
+ byteShift = 0; |
|
| 985 |
+ writeValue = 0; |
|
| 986 |
+ } |
|
| 987 |
+ len--; |
|
| 988 |
+ if(len == 0) |
|
| 989 |
+ return; |
|
| 990 |
+ } |
|
| 991 |
+ } else {
|
|
| 992 |
+ l++; |
|
| 993 |
+ for(int i = 0; i < l; i++) {
|
|
| 994 |
+ writeValue |= (CPUReadByte(source++) << byteShift); |
|
| 995 |
+ byteShift += 8; |
|
| 996 |
+ byteCount++; |
|
| 997 |
+ if(byteCount == 2) {
|
|
| 998 |
+ CPUWriteHalfWord(dest, writeValue); |
|
| 999 |
+ dest += 2; |
|
| 1000 |
+ byteCount = 0; |
|
| 1001 |
+ byteShift = 0; |
|
| 1002 |
+ writeValue = 0; |
|
| 1003 |
+ } |
|
| 1004 |
+ len--; |
|
| 1005 |
+ if(len == 0) |
|
| 1006 |
+ return; |
|
| 1007 |
+ } |
|
| 1008 |
+ } |
|
| 1009 |
+ } |
|
| 1010 |
+} |
|
| 1011 |
+ |
|
| 1012 |
+void BIOS_RLUnCompWram() |
|
| 1013 |
+{
|
|
| 1014 |
+#ifdef GBA_LOGGING |
|
| 1015 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 1016 |
+ log("RLUnCompWram: 0x%08x,0x%08x (VCOUNT=%d)\n",
|
|
| 1017 |
+ reg[0].I, |
|
| 1018 |
+ reg[1].I, |
|
| 1019 |
+ VCOUNT); |
|
| 1020 |
+ } |
|
| 1021 |
+#endif |
|
| 1022 |
+ |
|
| 1023 |
+ u32 source = reg[0].I; |
|
| 1024 |
+ u32 dest = reg[1].I; |
|
| 1025 |
+ |
|
| 1026 |
+ u32 header = CPUReadMemory(source & 0xFFFFFFFC); |
|
| 1027 |
+ source += 4; |
|
| 1028 |
+ |
|
| 1029 |
+ if(((source & 0xe000000) == 0) || |
|
| 1030 |
+ ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) |
|
| 1031 |
+ return; |
|
| 1032 |
+ |
|
| 1033 |
+ int len = header >> 8; |
|
| 1034 |
+ |
|
| 1035 |
+ while(len > 0) {
|
|
| 1036 |
+ u8 d = CPUReadByte(source++); |
|
| 1037 |
+ int l = d & 0x7F; |
|
| 1038 |
+ if(d & 0x80) {
|
|
| 1039 |
+ u8 data = CPUReadByte(source++); |
|
| 1040 |
+ l += 3; |
|
| 1041 |
+ for(int i = 0;i < l; i++) {
|
|
| 1042 |
+ CPUWriteByte(dest++, data); |
|
| 1043 |
+ len--; |
|
| 1044 |
+ if(len == 0) |
|
| 1045 |
+ return; |
|
| 1046 |
+ } |
|
| 1047 |
+ } else {
|
|
| 1048 |
+ l++; |
|
| 1049 |
+ for(int i = 0; i < l; i++) {
|
|
| 1050 |
+ CPUWriteByte(dest++, CPUReadByte(source++)); |
|
| 1051 |
+ len--; |
|
| 1052 |
+ if(len == 0) |
|
| 1053 |
+ return; |
|
| 1054 |
+ } |
|
| 1055 |
+ } |
|
| 1056 |
+ } |
|
| 1057 |
+} |
|
| 1058 |
+ |
|
| 1059 |
+void BIOS_SoftReset() |
|
| 1060 |
+{
|
|
| 1061 |
+#ifdef GBA_LOGGING |
|
| 1062 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 1063 |
+ log("SoftReset: (VCOUNT=%d)\n", VCOUNT);
|
|
| 1064 |
+ } |
|
| 1065 |
+#endif |
|
| 1066 |
+ |
|
| 1067 |
+ armState = true; |
|
| 1068 |
+ armMode = 0x1F; |
|
| 1069 |
+ armIrqEnable = false; |
|
| 1070 |
+ C_FLAG = V_FLAG = N_FLAG = Z_FLAG = false; |
|
| 1071 |
+ reg[13].I = 0x03007F00; |
|
| 1072 |
+ reg[14].I = 0x00000000; |
|
| 1073 |
+ reg[16].I = 0x00000000; |
|
| 1074 |
+ reg[R13_IRQ].I = 0x03007FA0; |
|
| 1075 |
+ reg[R14_IRQ].I = 0x00000000; |
|
| 1076 |
+ reg[SPSR_IRQ].I = 0x00000000; |
|
| 1077 |
+ reg[R13_SVC].I = 0x03007FE0; |
|
| 1078 |
+ reg[R14_SVC].I = 0x00000000; |
|
| 1079 |
+ reg[SPSR_SVC].I = 0x00000000; |
|
| 1080 |
+ u8 b = internalRAM[0x7ffa]; |
|
| 1081 |
+ |
|
| 1082 |
+ memset(&internalRAM[0x7e00], 0, 0x200); |
|
| 1083 |
+ |
|
| 1084 |
+ if(b) {
|
|
| 1085 |
+ armNextPC = 0x02000000; |
|
| 1086 |
+ reg[15].I = 0x02000004; |
|
| 1087 |
+ } else {
|
|
| 1088 |
+ armNextPC = 0x08000000; |
|
| 1089 |
+ reg[15].I = 0x08000004; |
|
| 1090 |
+ } |
|
| 1091 |
+} |
|
| 1092 |
+ |
|
| 1093 |
+void BIOS_Sqrt() |
|
| 1094 |
+{
|
|
| 1095 |
+#ifdef GBA_LOGGING |
|
| 1096 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 1097 |
+ log("Sqrt: %08x (VCOUNT=%2d)\n",
|
|
| 1098 |
+ reg[0].I, |
|
| 1099 |
+ VCOUNT); |
|
| 1100 |
+ } |
|
| 1101 |
+#endif |
|
| 1102 |
+ reg[0].I = (u32)sqrt((double)reg[0].I); |
|
| 1103 |
+#ifdef GBA_LOGGING |
|
| 1104 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 1105 |
+ log("Sqrt: return=%08x\n",
|
|
| 1106 |
+ reg[0].I); |
|
| 1107 |
+ } |
|
| 1108 |
+#endif |
|
| 1109 |
+} |
|
| 1110 |
+ |
|
| 1111 |
+void BIOS_MidiKey2Freq() |
|
| 1112 |
+{
|
|
| 1113 |
+#ifdef GBA_LOGGING |
|
| 1114 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 1115 |
+ log("MidiKey2Freq: WaveData=%08x mk=%08x fp=%08x\n",
|
|
| 1116 |
+ reg[0].I, |
|
| 1117 |
+ reg[1].I, |
|
| 1118 |
+ reg[2].I); |
|
| 1119 |
+ } |
|
| 1120 |
+#endif |
|
| 1121 |
+ int freq = CPUReadMemory(reg[0].I+4); |
|
| 1122 |
+ double tmp; |
|
| 1123 |
+ tmp = ((double)(180 - reg[1].I)) - ((double)reg[2].I / 256.f); |
|
| 1124 |
+ tmp = pow((double)2.f, tmp / 12.f); |
|
| 1125 |
+ reg[0].I = (int)((double)freq / tmp); |
|
| 1126 |
+ |
|
| 1127 |
+#ifdef GBA_LOGGING |
|
| 1128 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 1129 |
+ log("MidiKey2Freq: return %08x\n",
|
|
| 1130 |
+ reg[0].I); |
|
| 1131 |
+ } |
|
| 1132 |
+#endif |
|
| 1133 |
+} |
|
| 1134 |
+ |
|
| 1135 |
+void BIOS_SndDriverJmpTableCopy() |
|
| 1136 |
+{
|
|
| 1137 |
+#ifdef GBA_LOGGING |
|
| 1138 |
+ if(systemVerbose & VERBOSE_SWI) {
|
|
| 1139 |
+ log("SndDriverJmpTableCopy: dest=%08x\n",
|
|
| 1140 |
+ reg[0].I); |
|
| 1141 |
+ } |
|
| 1142 |
+#endif |
|
| 1143 |
+ for(int i = 0; i < 0x24; i++) {
|
|
| 1144 |
+ CPUWriteMemory(reg[0].I, 0x9c); |
|
| 1145 |
+ reg[0].I += 4; |
|
| 1146 |
+ } |
|
| 1147 |
+} |