2961
|
1 /* Copyright (C) 2006 yopyop
|
|
2 yopyop156@ifrance.com
|
|
3 yopyop156.ifrance.com
|
|
4
|
|
5 This file is part of DeSmuME
|
|
6
|
|
7 DeSmuME is free software; you can redistribute it and/or modify
|
|
8 it under the terms of the GNU General Public License as published by
|
|
9 the Free Software Foundation; either version 2 of the License, or
|
|
10 (at your option) any later version.
|
|
11
|
|
12 DeSmuME is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with DeSmuME; if not, write to the Free Software
|
|
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 */
|
|
21
|
|
22 #include "cp15.h"
|
|
23 #include <math.h>
|
|
24 #include "MMU.h"
|
|
25 #include "SPU.h"
|
|
26 #include "debug.h"
|
|
27
|
|
28 extern BOOL execute;
|
|
29
|
|
30 static u16 getsinetbl[] = {
|
|
31 0x0000, 0x0324, 0x0648, 0x096A, 0x0C8C, 0x0FAB, 0x12C8, 0x15E2,
|
|
32 0x18F9, 0x1C0B, 0x1F1A, 0x2223, 0x2528, 0x2826, 0x2B1F, 0x2E11,
|
|
33 0x30FB, 0x33DF, 0x36BA, 0x398C, 0x3C56, 0x3F17, 0x41CE, 0x447A,
|
|
34 0x471C, 0x49B4, 0x4C3F, 0x4EBF, 0x5133, 0x539B, 0x55F5, 0x5842,
|
|
35 0x5A82, 0x5CB3, 0x5ED7, 0x60EB, 0x62F1, 0x64E8, 0x66CF, 0x68A6,
|
|
36 0x6A6D, 0x6C23, 0x6DC9, 0x6F5E, 0x70E2, 0x7254, 0x73B5, 0x7504,
|
|
37 0x7641, 0x776B, 0x7884, 0x7989, 0x7A7C, 0x7B5C, 0x7C29, 0x7CE3,
|
|
38 0x7D89, 0x7E1D, 0x7E9C, 0x7F09, 0x7F61, 0x7FA6, 0x7FD8, 0x7FF5
|
|
39 };
|
|
40
|
|
41 static u16 getpitchtbl[] = {
|
|
42 0x0000, 0x003B, 0x0076, 0x00B2, 0x00ED, 0x0128, 0x0164, 0x019F,
|
|
43 0x01DB, 0x0217, 0x0252, 0x028E, 0x02CA, 0x0305, 0x0341, 0x037D,
|
|
44 0x03B9, 0x03F5, 0x0431, 0x046E, 0x04AA, 0x04E6, 0x0522, 0x055F,
|
|
45 0x059B, 0x05D8, 0x0614, 0x0651, 0x068D, 0x06CA, 0x0707, 0x0743,
|
|
46 0x0780, 0x07BD, 0x07FA, 0x0837, 0x0874, 0x08B1, 0x08EF, 0x092C,
|
|
47 0x0969, 0x09A7, 0x09E4, 0x0A21, 0x0A5F, 0x0A9C, 0x0ADA, 0x0B18,
|
|
48 0x0B56, 0x0B93, 0x0BD1, 0x0C0F, 0x0C4D, 0x0C8B, 0x0CC9, 0x0D07,
|
|
49 0x0D45, 0x0D84, 0x0DC2, 0x0E00, 0x0E3F, 0x0E7D, 0x0EBC, 0x0EFA,
|
|
50 0x0F39, 0x0F78, 0x0FB6, 0x0FF5, 0x1034, 0x1073, 0x10B2, 0x10F1,
|
|
51 0x1130, 0x116F, 0x11AE, 0x11EE, 0x122D, 0x126C, 0x12AC, 0x12EB,
|
|
52 0x132B, 0x136B, 0x13AA, 0x13EA, 0x142A, 0x146A, 0x14A9, 0x14E9,
|
|
53 0x1529, 0x1569, 0x15AA, 0x15EA, 0x162A, 0x166A, 0x16AB, 0x16EB,
|
|
54 0x172C, 0x176C, 0x17AD, 0x17ED, 0x182E, 0x186F, 0x18B0, 0x18F0,
|
|
55 0x1931, 0x1972, 0x19B3, 0x19F5, 0x1A36, 0x1A77, 0x1AB8, 0x1AFA,
|
|
56 0x1B3B, 0x1B7D, 0x1BBE, 0x1C00, 0x1C41, 0x1C83, 0x1CC5, 0x1D07,
|
|
57 0x1D48, 0x1D8A, 0x1DCC, 0x1E0E, 0x1E51, 0x1E93, 0x1ED5, 0x1F17,
|
|
58 0x1F5A, 0x1F9C, 0x1FDF, 0x2021, 0x2064, 0x20A6, 0x20E9, 0x212C,
|
|
59 0x216F, 0x21B2, 0x21F5, 0x2238, 0x227B, 0x22BE, 0x2301, 0x2344,
|
|
60 0x2388, 0x23CB, 0x240E, 0x2452, 0x2496, 0x24D9, 0x251D, 0x2561,
|
|
61 0x25A4, 0x25E8, 0x262C, 0x2670, 0x26B4, 0x26F8, 0x273D, 0x2781,
|
|
62 0x27C5, 0x280A, 0x284E, 0x2892, 0x28D7, 0x291C, 0x2960, 0x29A5,
|
|
63 0x29EA, 0x2A2F, 0x2A74, 0x2AB9, 0x2AFE, 0x2B43, 0x2B88, 0x2BCD,
|
|
64 0x2C13, 0x2C58, 0x2C9D, 0x2CE3, 0x2D28, 0x2D6E, 0x2DB4, 0x2DF9,
|
|
65 0x2E3F, 0x2E85, 0x2ECB, 0x2F11, 0x2F57, 0x2F9D, 0x2FE3, 0x302A,
|
|
66 0x3070, 0x30B6, 0x30FD, 0x3143, 0x318A, 0x31D0, 0x3217, 0x325E,
|
|
67 0x32A5, 0x32EC, 0x3332, 0x3379, 0x33C1, 0x3408, 0x344F, 0x3496,
|
|
68 0x34DD, 0x3525, 0x356C, 0x35B4, 0x35FB, 0x3643, 0x368B, 0x36D3,
|
|
69 0x371A, 0x3762, 0x37AA, 0x37F2, 0x383A, 0x3883, 0x38CB, 0x3913,
|
|
70 0x395C, 0x39A4, 0x39ED, 0x3A35, 0x3A7E, 0x3AC6, 0x3B0F, 0x3B58,
|
|
71 0x3BA1, 0x3BEA, 0x3C33, 0x3C7C, 0x3CC5, 0x3D0E, 0x3D58, 0x3DA1,
|
|
72 0x3DEA, 0x3E34, 0x3E7D, 0x3EC7, 0x3F11, 0x3F5A, 0x3FA4, 0x3FEE,
|
|
73 0x4038, 0x4082, 0x40CC, 0x4116, 0x4161, 0x41AB, 0x41F5, 0x4240,
|
|
74 0x428A, 0x42D5, 0x431F, 0x436A, 0x43B5, 0x4400, 0x444B, 0x4495,
|
|
75 0x44E1, 0x452C, 0x4577, 0x45C2, 0x460D, 0x4659, 0x46A4, 0x46F0,
|
|
76 0x473B, 0x4787, 0x47D3, 0x481E, 0x486A, 0x48B6, 0x4902, 0x494E,
|
|
77 0x499A, 0x49E6, 0x4A33, 0x4A7F, 0x4ACB, 0x4B18, 0x4B64, 0x4BB1,
|
|
78 0x4BFE, 0x4C4A, 0x4C97, 0x4CE4, 0x4D31, 0x4D7E, 0x4DCB, 0x4E18,
|
|
79 0x4E66, 0x4EB3, 0x4F00, 0x4F4E, 0x4F9B, 0x4FE9, 0x5036, 0x5084,
|
|
80 0x50D2, 0x5120, 0x516E, 0x51BC, 0x520A, 0x5258, 0x52A6, 0x52F4,
|
|
81 0x5343, 0x5391, 0x53E0, 0x542E, 0x547D, 0x54CC, 0x551A, 0x5569,
|
|
82 0x55B8, 0x5607, 0x5656, 0x56A5, 0x56F4, 0x5744, 0x5793, 0x57E2,
|
|
83 0x5832, 0x5882, 0x58D1, 0x5921, 0x5971, 0x59C1, 0x5A10, 0x5A60,
|
|
84 0x5AB0, 0x5B01, 0x5B51, 0x5BA1, 0x5BF1, 0x5C42, 0x5C92, 0x5CE3,
|
|
85 0x5D34, 0x5D84, 0x5DD5, 0x5E26, 0x5E77, 0x5EC8, 0x5F19, 0x5F6A,
|
|
86 0x5FBB, 0x600D, 0x605E, 0x60B0, 0x6101, 0x6153, 0x61A4, 0x61F6,
|
|
87 0x6248, 0x629A, 0x62EC, 0x633E, 0x6390, 0x63E2, 0x6434, 0x6487,
|
|
88 0x64D9, 0x652C, 0x657E, 0x65D1, 0x6624, 0x6676, 0x66C9, 0x671C,
|
|
89 0x676F, 0x67C2, 0x6815, 0x6869, 0x68BC, 0x690F, 0x6963, 0x69B6,
|
|
90 0x6A0A, 0x6A5E, 0x6AB1, 0x6B05, 0x6B59, 0x6BAD, 0x6C01, 0x6C55,
|
|
91 0x6CAA, 0x6CFE, 0x6D52, 0x6DA7, 0x6DFB, 0x6E50, 0x6EA4, 0x6EF9,
|
|
92 0x6F4E, 0x6FA3, 0x6FF8, 0x704D, 0x70A2, 0x70F7, 0x714D, 0x71A2,
|
|
93 0x71F7, 0x724D, 0x72A2, 0x72F8, 0x734E, 0x73A4, 0x73FA, 0x7450,
|
|
94 0x74A6, 0x74FC, 0x7552, 0x75A8, 0x75FF, 0x7655, 0x76AC, 0x7702,
|
|
95 0x7759, 0x77B0, 0x7807, 0x785E, 0x78B4, 0x790C, 0x7963, 0x79BA,
|
|
96 0x7A11, 0x7A69, 0x7AC0, 0x7B18, 0x7B6F, 0x7BC7, 0x7C1F, 0x7C77,
|
|
97 0x7CCF, 0x7D27, 0x7D7F, 0x7DD7, 0x7E2F, 0x7E88, 0x7EE0, 0x7F38,
|
|
98 0x7F91, 0x7FEA, 0x8042, 0x809B, 0x80F4, 0x814D, 0x81A6, 0x81FF,
|
|
99 0x8259, 0x82B2, 0x830B, 0x8365, 0x83BE, 0x8418, 0x8472, 0x84CB,
|
|
100 0x8525, 0x857F, 0x85D9, 0x8633, 0x868E, 0x86E8, 0x8742, 0x879D,
|
|
101 0x87F7, 0x8852, 0x88AC, 0x8907, 0x8962, 0x89BD, 0x8A18, 0x8A73,
|
|
102 0x8ACE, 0x8B2A, 0x8B85, 0x8BE0, 0x8C3C, 0x8C97, 0x8CF3, 0x8D4F,
|
|
103 0x8DAB, 0x8E07, 0x8E63, 0x8EBF, 0x8F1B, 0x8F77, 0x8FD4, 0x9030,
|
|
104 0x908C, 0x90E9, 0x9146, 0x91A2, 0x91FF, 0x925C, 0x92B9, 0x9316,
|
|
105 0x9373, 0x93D1, 0x942E, 0x948C, 0x94E9, 0x9547, 0x95A4, 0x9602,
|
|
106 0x9660, 0x96BE, 0x971C, 0x977A, 0x97D8, 0x9836, 0x9895, 0x98F3,
|
|
107 0x9952, 0x99B0, 0x9A0F, 0x9A6E, 0x9ACD, 0x9B2C, 0x9B8B, 0x9BEA,
|
|
108 0x9C49, 0x9CA8, 0x9D08, 0x9D67, 0x9DC7, 0x9E26, 0x9E86, 0x9EE6,
|
|
109 0x9F46, 0x9FA6, 0xA006, 0xA066, 0xA0C6, 0xA127, 0xA187, 0xA1E8,
|
|
110 0xA248, 0xA2A9, 0xA30A, 0xA36B, 0xA3CC, 0xA42D, 0xA48E, 0xA4EF,
|
|
111 0xA550, 0xA5B2, 0xA613, 0xA675, 0xA6D6, 0xA738, 0xA79A, 0xA7FC,
|
|
112 0xA85E, 0xA8C0, 0xA922, 0xA984, 0xA9E7, 0xAA49, 0xAAAC, 0xAB0E,
|
|
113 0xAB71, 0xABD4, 0xAC37, 0xAC9A, 0xACFD, 0xAD60, 0xADC3, 0xAE27,
|
|
114 0xAE8A, 0xAEED, 0xAF51, 0xAFB5, 0xB019, 0xB07C, 0xB0E0, 0xB145,
|
|
115 0xB1A9, 0xB20D, 0xB271, 0xB2D6, 0xB33A, 0xB39F, 0xB403, 0xB468,
|
|
116 0xB4CD, 0xB532, 0xB597, 0xB5FC, 0xB662, 0xB6C7, 0xB72C, 0xB792,
|
|
117 0xB7F7, 0xB85D, 0xB8C3, 0xB929, 0xB98F, 0xB9F5, 0xBA5B, 0xBAC1,
|
|
118 0xBB28, 0xBB8E, 0xBBF5, 0xBC5B, 0xBCC2, 0xBD29, 0xBD90, 0xBDF7,
|
|
119 0xBE5E, 0xBEC5, 0xBF2C, 0xBF94, 0xBFFB, 0xC063, 0xC0CA, 0xC132,
|
|
120 0xC19A, 0xC202, 0xC26A, 0xC2D2, 0xC33A, 0xC3A2, 0xC40B, 0xC473,
|
|
121 0xC4DC, 0xC544, 0xC5AD, 0xC616, 0xC67F, 0xC6E8, 0xC751, 0xC7BB,
|
|
122 0xC824, 0xC88D, 0xC8F7, 0xC960, 0xC9CA, 0xCA34, 0xCA9E, 0xCB08,
|
|
123 0xCB72, 0xCBDC, 0xCC47, 0xCCB1, 0xCD1B, 0xCD86, 0xCDF1, 0xCE5B,
|
|
124 0xCEC6, 0xCF31, 0xCF9C, 0xD008, 0xD073, 0xD0DE, 0xD14A, 0xD1B5,
|
|
125 0xD221, 0xD28D, 0xD2F8, 0xD364, 0xD3D0, 0xD43D, 0xD4A9, 0xD515,
|
|
126 0xD582, 0xD5EE, 0xD65B, 0xD6C7, 0xD734, 0xD7A1, 0xD80E, 0xD87B,
|
|
127 0xD8E9, 0xD956, 0xD9C3, 0xDA31, 0xDA9E, 0xDB0C, 0xDB7A, 0xDBE8,
|
|
128 0xDC56, 0xDCC4, 0xDD32, 0xDDA0, 0xDE0F, 0xDE7D, 0xDEEC, 0xDF5B,
|
|
129 0xDFC9, 0xE038, 0xE0A7, 0xE116, 0xE186, 0xE1F5, 0xE264, 0xE2D4,
|
|
130 0xE343, 0xE3B3, 0xE423, 0xE493, 0xE503, 0xE573, 0xE5E3, 0xE654,
|
|
131 0xE6C4, 0xE735, 0xE7A5, 0xE816, 0xE887, 0xE8F8, 0xE969, 0xE9DA,
|
|
132 0xEA4B, 0xEABC, 0xEB2E, 0xEB9F, 0xEC11, 0xEC83, 0xECF5, 0xED66,
|
|
133 0xEDD9, 0xEE4B, 0xEEBD, 0xEF2F, 0xEFA2, 0xF014, 0xF087, 0xF0FA,
|
|
134 0xF16D, 0xF1E0, 0xF253, 0xF2C6, 0xF339, 0xF3AD, 0xF420, 0xF494,
|
|
135 0xF507, 0xF57B, 0xF5EF, 0xF663, 0xF6D7, 0xF74C, 0xF7C0, 0xF834,
|
|
136 0xF8A9, 0xF91E, 0xF992, 0xFA07, 0xFA7C, 0xFAF1, 0xFB66, 0xFBDC,
|
|
137 0xFC51, 0xFCC7, 0xFD3C, 0xFDB2, 0xFE28, 0xFE9E, 0xFF14, 0xFF8A
|
|
138 };
|
|
139
|
|
140 static u8 getvoltbl[] = {
|
|
141 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
142 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
143 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
144 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
145 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
146 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
147 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
148 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
149 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03,
|
|
150 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
|
|
151 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
|
|
152 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
|
|
153 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
|
|
154 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
|
155 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08,
|
|
156 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
|
|
157 0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
|
|
158 0x0B, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0E,
|
|
159 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x10, 0x10, 0x10, 0x10, 0x10,
|
|
160 0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x14,
|
|
161 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x18,
|
|
162 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, 0x1A, 0x1A, 0x1A, 0x1B, 0x1B, 0x1B, 0x1C, 0x1C, 0x1C,
|
|
163 0x1D, 0x1D, 0x1D, 0x1E, 0x1E, 0x1E, 0x1F, 0x1F, 0x1F, 0x20, 0x20, 0x20, 0x21, 0x21, 0x22, 0x22,
|
|
164 0x22, 0x23, 0x23, 0x24, 0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x27, 0x28, 0x28, 0x29,
|
|
165 0x29, 0x2A, 0x2A, 0x2B, 0x2B, 0x2C, 0x2C, 0x2D, 0x2D, 0x2E, 0x2E, 0x2F, 0x2F, 0x30, 0x31, 0x31,
|
|
166 0x32, 0x32, 0x33, 0x33, 0x34, 0x35, 0x35, 0x36, 0x36, 0x37, 0x38, 0x38, 0x39, 0x3A, 0x3A, 0x3B,
|
|
167 0x3C, 0x3C, 0x3D, 0x3E, 0x3F, 0x3F, 0x40, 0x41, 0x42, 0x42, 0x43, 0x44, 0x45, 0x45, 0x46, 0x47,
|
|
168 0x48, 0x49, 0x4A, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x52, 0x53, 0x54, 0x55,
|
|
169 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x67,
|
|
170 0x68, 0x69, 0x6A, 0x6B, 0x6D, 0x6E, 0x6F, 0x71, 0x72, 0x73, 0x75, 0x76, 0x77, 0x79, 0x7A, 0x7B,
|
|
171 0x7D, 0x7E, 0x7F, 0x20, 0x21, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23, 0x23, 0x24, 0x24, 0x25, 0x25,
|
|
172 0x26, 0x26, 0x26, 0x27, 0x27, 0x28, 0x28, 0x29, 0x29, 0x2A, 0x2A, 0x2B, 0x2B, 0x2C, 0x2C, 0x2D,
|
|
173 0x2D, 0x2E, 0x2E, 0x2F, 0x2F, 0x30, 0x30, 0x31, 0x31, 0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x36,
|
|
174 0x36, 0x37, 0x37, 0x38, 0x39, 0x39, 0x3A, 0x3B, 0x3B, 0x3C, 0x3D, 0x3E, 0x3E, 0x3F, 0x40, 0x40,
|
|
175 0x41, 0x42, 0x43, 0x43, 0x44, 0x45, 0x46, 0x47, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4D,
|
|
176 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D,
|
|
177 0x5E, 0x5F, 0x60, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6F, 0x70,
|
|
178 0x71, 0x73, 0x74, 0x75, 0x77, 0x78, 0x79, 0x7B, 0x7C, 0x7E, 0x7E, 0x40, 0x41, 0x42, 0x43, 0x43,
|
|
179 0x44, 0x45, 0x46, 0x47, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51,
|
|
180 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61,
|
|
181 0x62, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6B, 0x6C, 0x6D, 0x6E, 0x70, 0x71, 0x72, 0x74, 0x75,
|
|
182 0x76, 0x78, 0x79, 0x7B, 0x7C, 0x7D, 0x7E, 0x40, 0x41, 0x42, 0x42, 0x43, 0x44, 0x45, 0x46, 0x46,
|
|
183 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
|
|
184 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x65, 0x66,
|
|
185 0x67, 0x68, 0x69, 0x6A, 0x6C, 0x6D, 0x6E, 0x6F, 0x71, 0x72, 0x73, 0x75, 0x76, 0x77, 0x79, 0x7A,
|
|
186 0x7C, 0x7D, 0x7E, 0x7F
|
|
187 };
|
|
188
|
|
189 u32 bios_nop(armcpu_t * cpu)
|
|
190 {
|
|
191 if (cpu->proc_ID == ARMCPU_ARM9)
|
|
192 {
|
|
193 LOG("Unimplemented bios function %02X(ARM9) was used. R0:%08X\n", (cpu->instruction)&0x1F, cpu->R[0]);
|
|
194 }
|
|
195 else
|
|
196 {
|
|
197 LOG("Unimplemented bios function %02X(ARM7) was used. R0:%08X\n", (cpu->instruction)&0x1F, cpu->R[0]);
|
|
198 }
|
|
199 return 3;
|
|
200 }
|
|
201
|
|
202 u32 delayLoop(armcpu_t * cpu)
|
|
203 {
|
|
204 return cpu->R[0] * 4;
|
|
205 }
|
|
206
|
|
207 //u32 oldmode[2];
|
|
208
|
|
209 u32 intrWaitARM(armcpu_t * cpu)
|
|
210 {
|
|
211 u32 intrFlagAdr;// = (((armcp15_t *)(cpu->coproc[15]))->DTCMRegion&0xFFFFF000)+0x3FF8;
|
|
212 u32 intr;
|
|
213 u32 intrFlag = 0;
|
|
214
|
|
215 //execute = FALSE;
|
|
216 if(cpu->proc_ID)
|
|
217 {
|
|
218 intrFlagAdr = 0x380FFF8;
|
|
219 } else {
|
|
220 intrFlagAdr = (((armcp15_t *)(cpu->coproc[15]))->DTCMRegion&0xFFFFF000)+0x3FF8;
|
|
221 }
|
|
222 intr = MMU_read32(cpu->proc_ID, intrFlagAdr);
|
|
223 intrFlag = cpu->R[1] & intr;
|
|
224
|
|
225 if(intrFlag)
|
|
226 {
|
|
227 // si une(ou plusieurs) des interruptions que l'on attend s'est(se sont) produite(s)
|
|
228 // on efface son(les) occurence(s).
|
|
229 intr ^= intrFlag;
|
|
230 MMU_write32(cpu->proc_ID, intrFlagAdr, intr);
|
|
231 //cpu->switchMode(oldmode[cpu->proc_ID]);
|
|
232 return 1;
|
|
233 }
|
|
234
|
|
235 cpu->R[15] = cpu->instruct_adr;
|
|
236 cpu->next_instruction = cpu->R[15];
|
|
237 cpu->waitIRQ = 1;
|
|
238 //oldmode[cpu->proc_ID] = cpu->switchMode(SVC);
|
|
239
|
|
240 return 1;
|
|
241 }
|
|
242
|
|
243 u32 waitVBlankARM(armcpu_t * cpu)
|
|
244 {
|
|
245 u32 intrFlagAdr;// = (((armcp15_t *)(cpu->coproc[15]))->DTCMRegion&0xFFFFF000)+0x3FF8;
|
|
246 u32 intr;
|
|
247 u32 intrFlag = 0;
|
|
248
|
|
249 //execute = FALSE;
|
|
250 if(cpu->proc_ID)
|
|
251 {
|
|
252 intrFlagAdr = 0x380FFF8;
|
|
253 } else {
|
|
254 intrFlagAdr = (((armcp15_t *)(cpu->coproc[15]))->DTCMRegion&0xFFFFF000)+0x3FF8;
|
|
255 }
|
|
256 intr = MMU_read32(cpu->proc_ID, intrFlagAdr);
|
|
257 intrFlag = 1 & intr;
|
|
258
|
|
259 if(intrFlag)
|
|
260 {
|
|
261 // si une(ou plusieurs) des interruptions que l'on attend s'est(se sont) produite(s)
|
|
262 // on efface son(les) occurence(s).
|
|
263 intr ^= intrFlag;
|
|
264 MMU_write32(cpu->proc_ID, intrFlagAdr, intr);
|
|
265 //cpu->switchMode(oldmode[cpu->proc_ID]);
|
|
266 return 1;
|
|
267 }
|
|
268
|
|
269 cpu->R[15] = cpu->instruct_adr;
|
|
270 cpu->next_instruction = cpu->R[15];
|
|
271 cpu->waitIRQ = 1;
|
|
272 //oldmode[cpu->proc_ID] = cpu->switchMode(SVC);
|
|
273
|
|
274 return 1;
|
|
275 }
|
|
276
|
|
277 u32 wait4IRQ(armcpu_t* cpu)
|
|
278 {
|
|
279 //execute= FALSE;
|
|
280 if(cpu->wirq)
|
|
281 {
|
|
282 if(!cpu->waitIRQ)
|
|
283 {
|
|
284 cpu->waitIRQ = 0;
|
|
285 cpu->wirq = 0;
|
|
286 //cpu->switchMode(oldmode[cpu->proc_ID]);
|
|
287 return 1;
|
|
288 }
|
|
289 cpu->R[15] = cpu->instruct_adr;
|
|
290 cpu->next_instruction = cpu->R[15];
|
|
291 return 1;
|
|
292 }
|
|
293 cpu->waitIRQ = 1;
|
|
294 cpu->wirq = 1;
|
|
295 cpu->R[15] = cpu->instruct_adr;
|
|
296 cpu->next_instruction = cpu->R[15];
|
|
297 //oldmode[cpu->proc_ID] = cpu->switchMode(SVC);
|
|
298 return 1;
|
|
299 }
|
|
300
|
|
301 u32 devide(armcpu_t* cpu)
|
|
302 {
|
|
303 s32 num = (s32)cpu->R[0];
|
|
304 s32 dnum = (s32)cpu->R[1];
|
|
305
|
|
306 if(dnum==0) return 0;
|
|
307
|
|
308 cpu->R[0] = (u32)(num / dnum);
|
|
309 cpu->R[1] = (u32)(num % dnum);
|
|
310 cpu->R[3] = (u32) (((s32)cpu->R[0])<0 ? -cpu->R[0] : cpu->R[0]);
|
|
311
|
|
312 return 6;
|
|
313 }
|
|
314
|
|
315 u32 copy(armcpu_t* cpu)
|
|
316 {
|
|
317 u32 src = cpu->R[0];
|
|
318 u32 dst = cpu->R[1];
|
|
319 u32 cnt = cpu->R[2];
|
|
320
|
|
321 switch(BIT26(cnt))
|
|
322 {
|
|
323 case 0:
|
|
324 src &= 0xFFFFFFFE;
|
|
325 dst &= 0xFFFFFFFE;
|
|
326 switch(BIT24(cnt))
|
|
327 {
|
|
328 case 0:
|
|
329 cnt &= 0x1FFFFF;
|
|
330 while(cnt)
|
|
331 {
|
|
332 MMU_write16(cpu->proc_ID, dst, MMU_read16(cpu->proc_ID, src));
|
|
333 cnt--;
|
|
334 dst+=2;
|
|
335 src+=2;
|
|
336 }
|
|
337 break;
|
|
338 case 1:
|
|
339 {
|
|
340 u32 val = MMU_read16(cpu->proc_ID, src);
|
|
341 cnt &= 0x1FFFFF;
|
|
342 while(cnt)
|
|
343 {
|
|
344 MMU_write16(cpu->proc_ID, dst, val);
|
|
345 cnt--;
|
|
346 dst+=2;
|
|
347 }
|
|
348 }
|
|
349 break;
|
|
350 }
|
|
351 break;
|
|
352 case 1:
|
|
353 src &= 0xFFFFFFFC;
|
|
354 dst &= 0xFFFFFFFC;
|
|
355 switch(BIT24(cnt))
|
|
356 {
|
|
357 case 0:
|
|
358 cnt &= 0x1FFFFF;
|
|
359 while(cnt)
|
|
360 {
|
|
361 MMU_write32(cpu->proc_ID, dst, MMU_read32(cpu->proc_ID, src));
|
|
362 cnt--;
|
|
363 dst+=4;
|
|
364 src+=4;
|
|
365 }
|
|
366 break;
|
|
367 case 1:
|
|
368 {
|
|
369 u32 val = MMU_read32(cpu->proc_ID, src);
|
|
370 cnt &= 0x1FFFFF;
|
|
371 while(cnt)
|
|
372 {
|
|
373 MMU_write32(cpu->proc_ID, dst, val);
|
|
374 cnt--;
|
|
375 dst+=4;
|
|
376 }
|
|
377 }
|
|
378 break;
|
|
379 }
|
|
380 break;
|
|
381 }
|
|
382 return 1;
|
|
383 }
|
|
384
|
|
385 u32 fastCopy(armcpu_t* cpu)
|
|
386 {
|
|
387 u32 src = cpu->R[0] & 0xFFFFFFFC;
|
|
388 u32 dst = cpu->R[1] & 0xFFFFFFFC;
|
|
389 u32 cnt = cpu->R[2];
|
|
390
|
|
391 switch(BIT24(cnt))
|
|
392 {
|
|
393 case 0:
|
|
394 cnt &= 0x1FFFFF;
|
|
395 while(cnt)
|
|
396 {
|
|
397 MMU_write32(cpu->proc_ID, dst, MMU_read32(cpu->proc_ID, src));
|
|
398 cnt--;
|
|
399 dst+=4;
|
|
400 src+=4;
|
|
401 }
|
|
402 break;
|
|
403 case 1:
|
|
404 {
|
|
405 u32 val = MMU_read32(cpu->proc_ID, src);
|
|
406 cnt &= 0x1FFFFF;
|
|
407 while(cnt)
|
|
408 {
|
|
409 MMU_write32(cpu->proc_ID, dst, val);
|
|
410 cnt--;
|
|
411 dst+=4;
|
|
412 }
|
|
413 }
|
|
414 break;
|
|
415 }
|
|
416 return 1;
|
|
417 }
|
|
418
|
|
419 u32 LZ77UnCompVram(armcpu_t* cpu)
|
|
420 {
|
|
421 int i1, i2;
|
|
422 int byteCount;
|
|
423 int byteShift;
|
|
424 u32 writeValue;
|
|
425 int len;
|
|
426 u32 source = cpu->R[0];
|
|
427 u32 dest = cpu->R[1];
|
|
428 u32 header = MMU_read32(cpu->proc_ID, source);
|
|
429 source += 4;
|
|
430
|
|
431 if(((source & 0xe000000) == 0) ||
|
|
432 ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
|
|
433 return 0;
|
|
434
|
|
435 byteCount = 0;
|
|
436 byteShift = 0;
|
|
437 writeValue = 0;
|
|
438
|
|
439 len = header >> 8;
|
|
440
|
|
441 while(len > 0) {
|
|
442 u8 d = MMU_read8(cpu->proc_ID, source++);
|
|
443
|
|
444 if(d) {
|
|
445 for(i1 = 0; i1 < 8; i1++) {
|
|
446 if(d & 0x80) {
|
|
447 int length;
|
|
448 int offset;
|
|
449 u32 windowOffset;
|
|
450 u16 data = MMU_read8(cpu->proc_ID, source++) << 8;
|
|
451 data |= MMU_read8(cpu->proc_ID, source++);
|
|
452 length = (data >> 12) + 3;
|
|
453 offset = (data & 0x0FFF);
|
|
454 windowOffset = dest + byteCount - offset - 1;
|
|
455 for(i2 = 0; i2 < length; i2++) {
|
|
456 writeValue |= (MMU_read8(cpu->proc_ID, windowOffset++) << byteShift);
|
|
457 byteShift += 8;
|
|
458 byteCount++;
|
|
459
|
|
460 if(byteCount == 2) {
|
|
461 MMU_write16(cpu->proc_ID, dest, writeValue);
|
|
462 dest += 2;
|
|
463 byteCount = 0;
|
|
464 byteShift = 0;
|
|
465 writeValue = 0;
|
|
466 }
|
|
467 len--;
|
|
468 if(len == 0)
|
|
469 return 0;
|
|
470 }
|
|
471 } else {
|
|
472 writeValue |= (MMU_read8(cpu->proc_ID, source++) << byteShift);
|
|
473 byteShift += 8;
|
|
474 byteCount++;
|
|
475 if(byteCount == 2) {
|
|
476 MMU_write16(cpu->proc_ID, dest, writeValue);
|
|
477 dest += 2;
|
|
478 byteCount = 0;
|
|
479 byteShift = 0;
|
|
480 writeValue = 0;
|
|
481 }
|
|
482 len--;
|
|
483 if(len == 0)
|
|
484 return 0;
|
|
485 }
|
|
486 d <<= 1;
|
|
487 }
|
|
488 } else {
|
|
489 for(i1 = 0; i1 < 8; i1++) {
|
|
490 writeValue |= (MMU_read8(cpu->proc_ID, source++) << byteShift);
|
|
491 byteShift += 8;
|
|
492 byteCount++;
|
|
493 if(byteCount == 2) {
|
|
494 MMU_write16(cpu->proc_ID, dest, writeValue);
|
|
495 dest += 2;
|
|
496 byteShift = 0;
|
|
497 byteCount = 0;
|
|
498 writeValue = 0;
|
|
499 }
|
|
500 len--;
|
|
501 if(len == 0)
|
|
502 return 0;
|
|
503 }
|
|
504 }
|
|
505 }
|
|
506 return 1;
|
|
507 }
|
|
508
|
|
509 u32 LZ77UnCompWram(armcpu_t* cpu)
|
|
510 {
|
|
511 int i1, i2;
|
|
512 int len;
|
|
513 u32 source = cpu->R[0];
|
|
514 u32 dest = cpu->R[1];
|
|
515
|
|
516 u32 header = MMU_read32(cpu->proc_ID, source);
|
|
517 source += 4;
|
|
518
|
|
519 if(((source & 0xe000000) == 0) ||
|
|
520 ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
|
|
521 return 0;
|
|
522
|
|
523 len = header >> 8;
|
|
524
|
|
525 while(len > 0) {
|
|
526 u8 d = MMU_read8(cpu->proc_ID, source++);
|
|
527
|
|
528 if(d) {
|
|
529 for(i1 = 0; i1 < 8; i1++) {
|
|
530 if(d & 0x80) {
|
|
531 int length;
|
|
532 int offset;
|
|
533 u32 windowOffset;
|
|
534 u16 data = MMU_read8(cpu->proc_ID, source++) << 8;
|
|
535 data |= MMU_read8(cpu->proc_ID, source++);
|
|
536 length = (data >> 12) + 3;
|
|
537 offset = (data & 0x0FFF);
|
|
538 windowOffset = dest - offset - 1;
|
|
539 for(i2 = 0; i2 < length; i2++) {
|
|
540 MMU_write8(cpu->proc_ID, dest++, MMU_read8(cpu->proc_ID, windowOffset++));
|
|
541 len--;
|
|
542 if(len == 0)
|
|
543 return 0;
|
|
544 }
|
|
545 } else {
|
|
546 MMU_write8(cpu->proc_ID, dest++, MMU_read8(cpu->proc_ID, source++));
|
|
547 len--;
|
|
548 if(len == 0)
|
|
549 return 0;
|
|
550 }
|
|
551 d <<= 1;
|
|
552 }
|
|
553 } else {
|
|
554 for(i1 = 0; i1 < 8; i1++) {
|
|
555 MMU_write8(cpu->proc_ID, dest++, MMU_read8(cpu->proc_ID, source++));
|
|
556 len--;
|
|
557 if(len == 0)
|
|
558 return 0;
|
|
559 }
|
|
560 }
|
|
561 }
|
|
562 return 1;
|
|
563 }
|
|
564
|
|
565 u32 RLUnCompVram(armcpu_t* cpu)
|
|
566 {
|
|
567 int i;
|
|
568 int len;
|
|
569 int byteCount;
|
|
570 int byteShift;
|
|
571 u32 writeValue;
|
|
572 u32 source = cpu->R[0];
|
|
573 u32 dest = cpu->R[1];
|
|
574
|
|
575 u32 header = MMU_read32(cpu->proc_ID, source);
|
|
576 source += 4;
|
|
577
|
|
578 if(((source & 0xe000000) == 0) ||
|
|
579 ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
|
|
580 return 0;
|
|
581
|
|
582 len = header >> 8;
|
|
583 byteCount = 0;
|
|
584 byteShift = 0;
|
|
585 writeValue = 0;
|
|
586
|
|
587 while(len > 0) {
|
|
588 u8 d = MMU_read8(cpu->proc_ID, source++);
|
|
589 int l = d & 0x7F;
|
|
590 if(d & 0x80) {
|
|
591 u8 data = MMU_read8(cpu->proc_ID, source++);
|
|
592 l += 3;
|
|
593 for(i = 0;i < l; i++) {
|
|
594 writeValue |= (data << byteShift);
|
|
595 byteShift += 8;
|
|
596 byteCount++;
|
|
597
|
|
598 if(byteCount == 2) {
|
|
599 MMU_write16(cpu->proc_ID, dest, writeValue);
|
|
600 dest += 2;
|
|
601 byteCount = 0;
|
|
602 byteShift = 0;
|
|
603 writeValue = 0;
|
|
604 }
|
|
605 len--;
|
|
606 if(len == 0)
|
|
607 return 0;
|
|
608 }
|
|
609 } else {
|
|
610 l++;
|
|
611 for(i = 0; i < l; i++) {
|
|
612 writeValue |= (MMU_read8(cpu->proc_ID, source++) << byteShift);
|
|
613 byteShift += 8;
|
|
614 byteCount++;
|
|
615 if(byteCount == 2) {
|
|
616 MMU_write16(cpu->proc_ID, dest, writeValue);
|
|
617 dest += 2;
|
|
618 byteCount = 0;
|
|
619 byteShift = 0;
|
|
620 writeValue = 0;
|
|
621 }
|
|
622 len--;
|
|
623 if(len == 0)
|
|
624 return 0;
|
|
625 }
|
|
626 }
|
|
627 }
|
|
628 return 1;
|
|
629 }
|
|
630
|
|
631 u32 RLUnCompWram(armcpu_t* cpu)
|
|
632 {
|
|
633 int i;
|
|
634 int len;
|
|
635 u32 source = cpu->R[0];
|
|
636 u32 dest = cpu->R[1];
|
|
637
|
|
638 u32 header = MMU_read32(cpu->proc_ID, source);
|
|
639 source += 4;
|
|
640
|
|
641 if(((source & 0xe000000) == 0) ||
|
|
642 ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
|
|
643 return 0;
|
|
644
|
|
645 len = header >> 8;
|
|
646
|
|
647 while(len > 0) {
|
|
648 u8 d = MMU_read8(cpu->proc_ID, source++);
|
|
649 int l = d & 0x7F;
|
|
650 if(d & 0x80) {
|
|
651 u8 data = MMU_read8(cpu->proc_ID, source++);
|
|
652 l += 3;
|
|
653 for(i = 0;i < l; i++) {
|
|
654 MMU_write8(cpu->proc_ID, dest++, data);
|
|
655 len--;
|
|
656 if(len == 0)
|
|
657 return 0;
|
|
658 }
|
|
659 } else {
|
|
660 l++;
|
|
661 for(i = 0; i < l; i++) {
|
|
662 MMU_write8(cpu->proc_ID, dest++, MMU_read8(cpu->proc_ID, source++));
|
|
663 len--;
|
|
664 if(len == 0)
|
|
665 return 0;
|
|
666 }
|
|
667 }
|
|
668 }
|
|
669 return 1;
|
|
670 }
|
|
671
|
|
672 u32 UnCompHuffman(armcpu_t* cpu)
|
|
673 {
|
|
674 u32 source, dest, writeValue, header, treeStart, mask;
|
|
675 u32 data;
|
|
676 u8 treeSize, currentNode, rootNode;
|
|
677 int byteCount, byteShift, len, pos;
|
|
678 int writeData;
|
|
679
|
|
680 source = cpu->R[0];
|
|
681 dest = cpu->R[1];
|
|
682
|
|
683 header = MMU_read8(cpu->proc_ID, source);
|
|
684 source += 4;
|
|
685
|
|
686 if(((source & 0xe000000) == 0) ||
|
|
687 ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
|
|
688 return 0;
|
|
689
|
|
690 treeSize = MMU_read8(cpu->proc_ID, source++);
|
|
691
|
|
692 treeStart = source;
|
|
693
|
|
694 source += ((treeSize+1)<<1)-1; // minus because we already skipped one byte
|
|
695
|
|
696 len = header >> 8;
|
|
697
|
|
698 mask = 0x80000000;
|
|
699 data = MMU_read8(cpu->proc_ID, source);
|
|
700 source += 4;
|
|
701
|
|
702 pos = 0;
|
|
703 rootNode = MMU_read8(cpu->proc_ID, treeStart);
|
|
704 currentNode = rootNode;
|
|
705 writeData = 0;
|
|
706 byteShift = 0;
|
|
707 byteCount = 0;
|
|
708 writeValue = 0;
|
|
709
|
|
710 if((header & 0x0F) == 8) {
|
|
711 while(len > 0) {
|
|
712 // take left
|
|
713 if(pos == 0)
|
|
714 pos++;
|
|
715 else
|
|
716 pos += (((currentNode & 0x3F)+1)<<1);
|
|
717
|
|
718 if(data & mask) {
|
|
719 // right
|
|
720 if(currentNode & 0x40)
|
|
721 writeData = 1;
|
|
722 currentNode = MMU_read8(cpu->proc_ID, treeStart+pos+1);
|
|
723 } else {
|
|
724 // left
|
|
725 if(currentNode & 0x80)
|
|
726 writeData = 1;
|
|
727 currentNode = MMU_read8(cpu->proc_ID, treeStart+pos);
|
|
728 }
|
|
729
|
|
730 if(writeData) {
|
|
731 writeValue |= (currentNode << byteShift);
|
|
732 byteCount++;
|
|
733 byteShift += 8;
|
|
734
|
|
735 pos = 0;
|
|
736 currentNode = rootNode;
|
|
737 writeData = 0;
|
|
738
|
|
739 if(byteCount == 4) {
|
|
740 byteCount = 0;
|
|
741 byteShift = 0;
|
|
742 MMU_write8(cpu->proc_ID, dest, writeValue);
|
|
743 writeValue = 0;
|
|
744 dest += 4;
|
|
745 len -= 4;
|
|
746 }
|
|
747 }
|
|
748 mask >>= 1;
|
|
749 if(mask == 0) {
|
|
750 mask = 0x80000000;
|
|
751 data = MMU_read8(cpu->proc_ID, source);
|
|
752 source += 4;
|
|
753 }
|
|
754 }
|
|
755 } else {
|
|
756 int halfLen = 0;
|
|
757 int value = 0;
|
|
758 while(len > 0) {
|
|
759 // take left
|
|
760 if(pos == 0)
|
|
761 pos++;
|
|
762 else
|
|
763 pos += (((currentNode & 0x3F)+1)<<1);
|
|
764
|
|
765 if((data & mask)) {
|
|
766 // right
|
|
767 if(currentNode & 0x40)
|
|
768 writeData = 1;
|
|
769 currentNode = MMU_read8(cpu->proc_ID, treeStart+pos+1);
|
|
770 } else {
|
|
771 // left
|
|
772 if(currentNode & 0x80)
|
|
773 writeData = 1;
|
|
774 currentNode = MMU_read8(cpu->proc_ID, treeStart+pos);
|
|
775 }
|
|
776
|
|
777 if(writeData) {
|
|
778 if(halfLen == 0)
|
|
779 value |= currentNode;
|
|
780 else
|
|
781 value |= (currentNode<<4);
|
|
782
|
|
783 halfLen += 4;
|
|
784 if(halfLen == 8) {
|
|
785 writeValue |= (value << byteShift);
|
|
786 byteCount++;
|
|
787 byteShift += 8;
|
|
788
|
|
789 halfLen = 0;
|
|
790 value = 0;
|
|
791
|
|
792 if(byteCount == 4) {
|
|
793 byteCount = 0;
|
|
794 byteShift = 0;
|
|
795 MMU_write8(cpu->proc_ID, dest, writeValue);
|
|
796 dest += 4;
|
|
797 writeValue = 0;
|
|
798 len -= 4;
|
|
799 }
|
|
800 }
|
|
801 pos = 0;
|
|
802 currentNode = rootNode;
|
|
803 writeData = 0;
|
|
804 }
|
|
805 mask >>= 1;
|
|
806 if(mask == 0) {
|
|
807 mask = 0x80000000;
|
|
808 data = MMU_read8(cpu->proc_ID, source);
|
|
809 source += 4;
|
|
810 }
|
|
811 }
|
|
812 }
|
|
813 return 1;
|
|
814 }
|
|
815
|
|
816 u32 BitUnPack(armcpu_t* cpu)
|
|
817 {
|
|
818 u32 source,dest,header,base,d,temp;
|
|
819 int len,bits,revbits,dataSize,data,bitwritecount,mask,bitcount,addBase;
|
|
820 u8 b;
|
|
821
|
|
822 source = cpu->R[0];
|
|
823 dest = cpu->R[1];
|
|
824 header = cpu->R[2];
|
|
825
|
|
826 len = MMU_read16(cpu->proc_ID, header);
|
|
827 // check address
|
|
828 bits = MMU_read8(cpu->proc_ID, header+2);
|
|
829 revbits = 8 - bits;
|
|
830 // u32 value = 0;
|
|
831 base = MMU_read8(cpu->proc_ID, header+4);
|
|
832 addBase = (base & 0x80000000) ? 1 : 0;
|
|
833 base &= 0x7fffffff;
|
|
834 dataSize = MMU_read8(cpu->proc_ID, header+3);
|
|
835
|
|
836 data = 0;
|
|
837 bitwritecount = 0;
|
|
838 while(1) {
|
|
839 len -= 1;
|
|
840 if(len < 0)
|
|
841 break;
|
|
842 mask = 0xff >> revbits;
|
|
843 b = MMU_read8(cpu->proc_ID, source);
|
|
844 source++;
|
|
845 bitcount = 0;
|
|
846 while(1) {
|
|
847 if(bitcount >= 8)
|
|
848 break;
|
|
849 d = b & mask;
|
|
850 temp = d >> bitcount;
|
|
851 if(!temp && addBase) {
|
|
852 temp += base;
|
|
853 }
|
|
854 data |= temp << bitwritecount;
|
|
855 bitwritecount += dataSize;
|
|
856 if(bitwritecount >= 32) {
|
|
857 MMU_write8(cpu->proc_ID, dest, data);
|
|
858 dest += 4;
|
|
859 data = 0;
|
|
860 bitwritecount = 0;
|
|
861 }
|
|
862 mask <<= bits;
|
|
863 bitcount += bits;
|
|
864 }
|
|
865 }
|
|
866 return 1;
|
|
867 }
|
|
868
|
|
869 u32 Diff8bitUnFilterWram(armcpu_t* cpu)
|
|
870 {
|
|
871 u32 source,dest,header;
|
|
872 u8 data,diff;
|
|
873 int len;
|
|
874
|
|
875 source = cpu->R[0];
|
|
876 dest = cpu->R[1];
|
|
877
|
|
878 header = MMU_read8(cpu->proc_ID, source);
|
|
879 source += 4;
|
|
880
|
|
881 if(((source & 0xe000000) == 0) ||
|
|
882 (( (source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0))
|
|
883 return 0;
|
|
884
|
|
885 len = header >> 8;
|
|
886
|
|
887 data = MMU_read8(cpu->proc_ID, source++);
|
|
888 MMU_write8(cpu->proc_ID, dest++, data);
|
|
889 len--;
|
|
890
|
|
891 while(len > 0) {
|
|
892 diff = MMU_read8(cpu->proc_ID, source++);
|
|
893 data += diff;
|
|
894 MMU_write8(cpu->proc_ID, dest++, data);
|
|
895 len--;
|
|
896 }
|
|
897 return 1;
|
|
898 }
|
|
899
|
|
900 u32 Diff16bitUnFilter(armcpu_t* cpu)
|
|
901 {
|
|
902 u32 source,dest,header;
|
|
903 u16 data;
|
|
904 int len;
|
|
905
|
|
906 source = cpu->R[0];
|
|
907 dest = cpu->R[1];
|
|
908
|
|
909 header = MMU_read8(cpu->proc_ID, source);
|
|
910 source += 4;
|
|
911
|
|
912 if(((source & 0xe000000) == 0) ||
|
|
913 ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
|
|
914 return 0;
|
|
915
|
|
916 len = header >> 8;
|
|
917
|
|
918 data = MMU_read16(cpu->proc_ID, source);
|
|
919 source += 2;
|
|
920 MMU_write16(cpu->proc_ID, dest, data);
|
|
921 dest += 2;
|
|
922 len -= 2;
|
|
923
|
|
924 while(len >= 2) {
|
|
925 u16 diff = MMU_read16(cpu->proc_ID, source);
|
|
926 source += 2;
|
|
927 data += diff;
|
|
928 MMU_write16(cpu->proc_ID, dest, data);
|
|
929 dest += 2;
|
|
930 len -= 2;
|
|
931 }
|
|
932 return 1;
|
|
933 }
|
|
934
|
|
935 u32 bios_sqrt(armcpu_t* cpu)
|
|
936 {
|
|
937 cpu->R[0] = (u32)sqrt((double)(cpu->R[0]));
|
|
938 return 1;
|
|
939 }
|
|
940
|
|
941 u32 setHaltCR(armcpu_t* cpu)
|
|
942 {
|
|
943 MMU_write8(cpu->proc_ID, 0x4000300+cpu->proc_ID, cpu->R[0]);
|
|
944 return 1;
|
|
945 }
|
|
946
|
|
947 u32 getSineTab(armcpu_t* cpu)
|
|
948 {
|
|
949 cpu->R[0] = getsinetbl[cpu->R[0]];
|
|
950 return 1;
|
|
951 }
|
|
952
|
|
953 u32 getPitchTab(armcpu_t* cpu)
|
|
954 {
|
|
955 cpu->R[0] = getpitchtbl[cpu->R[0]];
|
|
956 return 1;
|
|
957 }
|
|
958
|
|
959 u32 getVolumeTab(armcpu_t* cpu)
|
|
960 {
|
|
961 cpu->R[0] = getvoltbl[cpu->R[0]];
|
|
962 return 1;
|
|
963 }
|
|
964
|
|
965 u32 getCRC16(armcpu_t* cpu)
|
|
966 {
|
|
967 unsigned int i,j;
|
|
968
|
|
969 u32 crc = cpu->R[0];
|
|
970 u32 datap = cpu->R[1];
|
|
971 u32 size = cpu->R[2];
|
|
972
|
|
973 static u16 val[] = { 0xC0C1,0xC181,0xC301,0xC601,0xCC01,0xD801,0xF001,0xA001 };
|
|
974 for(i = 0; i < size; i++)
|
|
975 {
|
|
976 crc = crc ^ MMU_read8( cpu->proc_ID, datap + i);
|
|
977
|
|
978 for(j = 0; j < 8; j++) {
|
|
979 int do_bit = 0;
|
|
980
|
|
981 if ( crc & 0x1)
|
|
982 do_bit = 1;
|
|
983
|
|
984 crc = crc >> 1;
|
|
985
|
|
986 if ( do_bit) {
|
|
987 crc = crc ^ (val[j] << (7-j));
|
|
988 }
|
|
989 }
|
|
990 }
|
|
991 cpu->R[0] = crc;
|
|
992 return 1;
|
|
993 }
|
|
994
|
|
995 u32 SoundBias(armcpu_t* cpu)
|
|
996 {
|
|
997 u32 current = SPU_ReadLong(0x4000504);
|
|
998 if (cpu->R[0] > current)
|
|
999 SPU_WriteLong(0x4000504, current + 0x1);
|
|
1000 else
|
|
1001 SPU_WriteLong(0x4000504, current - 0x1);
|
|
1002 return cpu->R[1];
|
|
1003 }
|
|
1004
|
|
1005 u32 (* ARM9_swi_tab[32])(armcpu_t* cpu)={
|
|
1006 bios_nop, // 0x00
|
|
1007 bios_nop, // 0x01
|
|
1008 bios_nop, // 0x02
|
|
1009 delayLoop, // 0x03
|
|
1010 intrWaitARM, // 0x04
|
|
1011 waitVBlankARM, // 0x05
|
|
1012 wait4IRQ, // 0x06
|
|
1013 bios_nop, // 0x07
|
|
1014 bios_nop, // 0x08
|
|
1015 devide, // 0x09
|
|
1016 bios_nop, // 0x0A
|
|
1017 copy, // 0x0B
|
|
1018 fastCopy, // 0x0C
|
|
1019 bios_sqrt, // 0x0D
|
|
1020 getCRC16, // 0x0E
|
|
1021 bios_nop, // 0x0F
|
|
1022 BitUnPack, // 0x10
|
|
1023 LZ77UnCompWram, // 0x11
|
|
1024 LZ77UnCompVram, // 0x12
|
|
1025 UnCompHuffman, // 0x13
|
|
1026 RLUnCompWram, // 0x14
|
|
1027 RLUnCompVram, // 0x15
|
|
1028 Diff8bitUnFilterWram, // 0x16
|
|
1029 bios_nop, // 0x17
|
|
1030 Diff16bitUnFilter, // 0x18
|
|
1031 bios_nop, // 0x19
|
|
1032 bios_nop, // 0x1A
|
|
1033 bios_nop, // 0x1B
|
|
1034 bios_nop, // 0x1C
|
|
1035 bios_nop, // 0x1D
|
|
1036 bios_nop, // 0x1E
|
|
1037 setHaltCR, // 0x1F
|
|
1038 };
|
|
1039
|
|
1040 u32 (* ARM7_swi_tab[32])(armcpu_t* cpu)={
|
|
1041 bios_nop, // 0x00
|
|
1042 bios_nop, // 0x01
|
|
1043 bios_nop, // 0x02
|
|
1044 delayLoop, // 0x03
|
|
1045 intrWaitARM, // 0x04
|
|
1046 waitVBlankARM, // 0x05
|
|
1047 wait4IRQ, // 0x06
|
|
1048 wait4IRQ, // 0x07
|
|
1049 SoundBias, // 0x08
|
|
1050 devide, // 0x09
|
|
1051 bios_nop, // 0x0A
|
|
1052 copy, // 0x0B
|
|
1053 fastCopy, // 0x0C
|
|
1054 bios_sqrt, // 0x0D
|
|
1055 getCRC16, // 0x0E
|
|
1056 bios_nop, // 0x0F
|
|
1057 BitUnPack, // 0x10
|
|
1058 LZ77UnCompWram, // 0x11
|
|
1059 LZ77UnCompVram, // 0x12
|
|
1060 UnCompHuffman, // 0x13
|
|
1061 RLUnCompWram, // 0x14
|
|
1062 RLUnCompVram, // 0x15
|
|
1063 Diff8bitUnFilterWram, // 0x16
|
|
1064 bios_nop, // 0x17
|
|
1065 bios_nop, // 0x18
|
|
1066 bios_nop, // 0x19
|
|
1067 getSineTab, // 0x1A
|
|
1068 getPitchTab, // 0x1B
|
|
1069 getVolumeTab, // 0x1C
|
|
1070 bios_nop, // 0x1D
|
|
1071 bios_nop, // 0x1E
|
|
1072 setHaltCR, // 0x1F
|
|
1073 };
|