forked from BreavyTF2/sm64-tjp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ique_support.patch
executable file
·312 lines (294 loc) · 8.74 KB
/
ique_support.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
diff --git a/include/PR/console_type.h b/include/PR/console_type.h
new file mode 100644
index 00000000..e60550ab
--- /dev/null
+++ b/include/PR/console_type.h
@@ -0,0 +1,7 @@
+enum ConsoleType {
+ CONSOLE_N64,
+ CONSOLE_IQUE
+};
+
+extern enum ConsoleType gConsoleType;
+extern enum ConsoleType get_console_type(void);
diff --git a/lib/asm/skGetId.s b/lib/asm/skGetId.s
new file mode 100644
index 00000000..8fb4c449
--- /dev/null
+++ b/lib/asm/skGetId.s
@@ -0,0 +1,18 @@
+# Code by stuckpixel
+
+.set noreorder
+.set gp=64
+
+.include "macros.inc"
+
+glabel skGetId
+ li $v0, 0
+ li $t0, 0xA4300014
+ lw $t1, 0x00($t0)
+ nop
+ jr $ra
+ nop
+ nop
+ nop
+ nop
+ nop
diff --git a/lib/src/__osViSwapContext.c b/lib/src/__osViSwapContext.c
index d7741994..9aced7cf 100644
--- a/lib/src/__osViSwapContext.c
+++ b/lib/src/__osViSwapContext.c
@@ -52,7 +52,9 @@ void __osViSwapContext() {
HW_REG(VI_INTR_REG, u32) = s0->fldRegs[field].vIntr;
HW_REG(VI_X_SCALE_REG, u32) = s1->unk20;
HW_REG(VI_Y_SCALE_REG, u32) = s1->unk2c;
- HW_REG(VI_CONTROL_REG, u32) = s1->features;
+ /* Make sure bit 13 is cleared. Otherwise, graphics will be corrupted on
+ * iQue Player. This has no effect on N64. */
+ HW_REG(VI_CONTROL_REG, u32) = s1->features & ~(1 << 13);
D_80334914 = D_80334910;
D_80334910 = s1;
*D_80334914 = *D_80334910;
diff --git a/lib/src/consoleType.c b/lib/src/consoleType.c
new file mode 100644
index 00000000..ef08d1ef
--- /dev/null
+++ b/lib/src/consoleType.c
@@ -0,0 +1,12 @@
+#include "libultra_internal.h"
+#include <PR/console_type.h>
+
+enum ConsoleType gConsoleType;
+
+void skGetId(u32 *out);
+
+enum ConsoleType get_console_type(void) {
+ u32 id = 0;
+ skGetId(&id);
+ return (id == 0) ? CONSOLE_N64 : CONSOLE_IQUE;
+}
diff --git a/lib/src/osEepromProbe.c b/lib/src/osEepromProbe.c
index d550b846..bbaf2bcc 100644
--- a/lib/src/osEepromProbe.c
+++ b/lib/src/osEepromProbe.c
@@ -1,4 +1,5 @@
#include "libultra_internal.h"
+#include <PR/console_type.h>
// TODO: merge with osEepromWrite
typedef struct {
@@ -13,11 +14,23 @@ s32 osEepromProbe(OSMesgQueue *mq) {
unkStruct sp18;
__osSiGetAccess();
- status = __osEepStatus(mq, &sp18);
- if (status == 0 && (sp18.unk00 & 0x8000) != 0) {
- status = 1;
- } else {
- status = 0;
+ if (gConsoleType == CONSOLE_N64) {
+ status = __osEepStatus(mq, &sp18);
+ if (status == 0 && (sp18.unk00 & 0x8000) != 0) {
+ status = 1;
+ } else {
+ status = 0;
+ }
+ } else if (gConsoleType == CONSOLE_IQUE) {
+ s32 __osBbEepromSize = * (s32*) 0x80000360;
+
+ if (__osBbEepromSize == 0x200) {
+ status = 1;
+ }
+
+ if (__osBbEepromSize == 0x800) {
+ status = 2;
+ }
}
__osSiRelAccess();
return status;
diff --git a/lib/src/osEepromRead.c b/lib/src/osEepromRead.c
index ea784b2c..116dae2d 100644
--- a/lib/src/osEepromRead.c
+++ b/lib/src/osEepromRead.c
@@ -1,4 +1,5 @@
#include "libultra_internal.h"
+#include <PR/console_type.h>
extern u8 _osLastSentSiCmd;
@@ -42,33 +43,44 @@ s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer) {
return -1;
}
__osSiGetAccess();
- sp34 = __osEepStatus(mq, &sp28);
- if (sp34 != 0 || sp28.unk00 != 0x8000) {
+ if (gConsoleType == CONSOLE_N64) {
+ sp34 = __osEepStatus(mq, &sp28);
+ if (sp34 != 0 || sp28.unk00 != 0x8000) {
- return 8;
- }
- while (sp28.unk02 & 0x80) {
- __osEepStatus(mq, &sp28);
- }
- __osPackEepReadData(address);
- sp34 = __osSiRawStartDma(OS_WRITE, &D_80365E00);
- osRecvMesg(mq, NULL, OS_MESG_BLOCK);
- for (sp30 = 0; sp30 < 0x10; sp30++) {
- (D_80365E00)[sp30] = 255;
- }
- D_80365E3C = 0;
- sp34 = __osSiRawStartDma(OS_READ, D_80365E00);
- _osLastSentSiCmd = 4;
- osRecvMesg(mq, NULL, OS_MESG_BLOCK);
- for (sp30 = 0; sp30 < 4; sp30++) {
- sp2c++;
- }
- sp20 = *(unkStruct2 *) sp2c;
- sp34 = (sp20.unk01 & 0xc0) >> 4;
- if (sp34 == 0) {
- for (sp30 = 0; sp30 < 8; sp30++) {
- *buffer++ = ((u8 *) &sp20.unk04)[sp30];
+ return 8;
+ }
+ while (sp28.unk02 & 0x80) {
+ __osEepStatus(mq, &sp28);
+ }
+ __osPackEepReadData(address);
+ sp34 = __osSiRawStartDma(OS_WRITE, &D_80365E00);
+ osRecvMesg(mq, NULL, OS_MESG_BLOCK);
+ for (sp30 = 0; sp30 < 0x10; sp30++) {
+ (D_80365E00)[sp30] = 255;
}
+ D_80365E3C = 0;
+ sp34 = __osSiRawStartDma(OS_READ, D_80365E00);
+ _osLastSentSiCmd = 4;
+ osRecvMesg(mq, NULL, OS_MESG_BLOCK);
+ for (sp30 = 0; sp30 < 4; sp30++) {
+ sp2c++;
+ }
+ sp20 = *(unkStruct2 *) sp2c;
+ sp34 = (sp20.unk01 & 0xc0) >> 4;
+ if (sp34 == 0) {
+ for (sp30 = 0; sp30 < 8; sp30++) {
+ *buffer++ = ((u8 *) &sp20.unk04)[sp30];
+ }
+ }
+ } else if (gConsoleType == CONSOLE_IQUE) {
+ u8 *__osBbEepromAddress = * (u8**) 0x8000035C;
+ s32 i;
+
+ for (i = 0; i < 8; i++) {
+ buffer[i] = __osBbEepromAddress[(address << 3) + i];
+ }
+
+ sp34 = 0;
}
__osSiRelAccess();
return sp34;
diff --git a/lib/src/osEepromWrite.c b/lib/src/osEepromWrite.c
index 1a86477b..52a23e5e 100644
--- a/lib/src/osEepromWrite.c
+++ b/lib/src/osEepromWrite.c
@@ -1,5 +1,6 @@
#include "libultra_internal.h"
#include "osContInternal.h"
+#include <PR/console_type.h>
#ifndef AVOID_UB
ALIGNED8 u32 D_80365E00[15];
@@ -52,36 +53,47 @@ s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer) {
}
__osSiGetAccess();
- sp34 = __osEepStatus(mq, &sp1c);
+ if (gConsoleType == CONSOLE_N64) {
+ sp34 = __osEepStatus(mq, &sp1c);
- if (sp34 != 0 || sp1c.unk00 != 0x8000) {
- return 8;
- }
+ if (sp34 != 0 || sp1c.unk00 != 0x8000) {
+ return 8;
+ }
- while (sp1c.unk02 & 0x80) {
- __osEepStatus(mq, &sp1c);
- }
+ while (sp1c.unk02 & 0x80) {
+ __osEepStatus(mq, &sp1c);
+ }
- __osPackEepWriteData(address, buffer);
+ __osPackEepWriteData(address, buffer);
- sp34 = __osSiRawStartDma(OS_WRITE, &D_80365E00);
- osRecvMesg(mq, NULL, OS_MESG_BLOCK);
+ sp34 = __osSiRawStartDma(OS_WRITE, &D_80365E00);
+ osRecvMesg(mq, NULL, OS_MESG_BLOCK);
- for (sp30 = 0; sp30 < 0x10; sp30++) {
- (D_80365E00)[sp30] = 255;
- }
+ for (sp30 = 0; sp30 < 0x10; sp30++) {
+ (D_80365E00)[sp30] = 255;
+ }
- D_80365E3C = 0;
- sp34 = __osSiRawStartDma(OS_READ, D_80365E00);
- _osLastSentSiCmd = 5;
- osRecvMesg(mq, NULL, OS_MESG_BLOCK);
+ D_80365E3C = 0;
+ sp34 = __osSiRawStartDma(OS_READ, D_80365E00);
+ _osLastSentSiCmd = 5;
+ osRecvMesg(mq, NULL, OS_MESG_BLOCK);
- for (sp30 = 0; sp30 < 4; sp30++) {
- sp2c++;
- }
+ for (sp30 = 0; sp30 < 4; sp30++) {
+ sp2c++;
+ }
+
+ sp20 = *(unkStruct2 *) sp2c;
+ sp34 = (sp20.unk01 & 0xc0) >> 4;
+ } else if (gConsoleType == CONSOLE_N64) {
+ u8 *__osBbEepromAddress = * (u8**) 0x8000035C;
+ s32 i;
- sp20 = *(unkStruct2 *) sp2c;
- sp34 = (sp20.unk01 & 0xc0) >> 4;
+ for (i = 0; i < 8; i++) {
+ __osBbEepromAddress[(address << 3) + i] = buffer[i];
+ }
+
+ sp34 = 0;
+ }
__osSiRelAccess();
return sp34;
}
diff --git a/lib/src/osInitialize.c b/lib/src/osInitialize.c
index 3cbca8ea..20723b2f 100644
--- a/lib/src/osInitialize.c
+++ b/lib/src/osInitialize.c
@@ -1,6 +1,7 @@
#include "libultra_internal.h"
#include "hardware.h"
#include <macros.h>
+#include <PR/console_type.h>
#define PIF_ADDR_START (void *) 0x1FC007FC
@@ -46,6 +47,7 @@ void osInitialize(void) {
UNUSED u32 eu_sp30;
#endif
UNUSED u32 sp2c;
+ gConsoleType = get_console_type();
D_80365CD0 = TRUE;
__osSetSR(__osGetSR() | 0x20000000);
__osSetFpcCsr(0x01000800);
diff --git a/sm64.ld b/sm64.ld
index 3275819f..6f97698f 100755
--- a/sm64.ld
+++ b/sm64.ld
@@ -261,6 +261,8 @@ SECTIONS
BUILD_DIR/libultra.a:func_802F7140.o(.text)
BUILD_DIR/libultra.a:func_802F71A0.o(.text)
BUILD_DIR/libultra.a:func_802F71F0.o(.text)
+ BUILD_DIR/libultra.a:consoleType.o(.text)
+ BUILD_DIR/libultra.a:skGetId.o(.text)
BUILD_DIR/lib/rsp.o(.text);
#else
BUILD_DIR/src/game*.o(.text);
@@ -371,6 +373,8 @@ SECTIONS
BUILD_DIR/libultra.a:__osGetCause.o(.text);
BUILD_DIR/libultra.a:__osAtomicDec.o(.text);
BUILD_DIR/libultra.a:guLookAtRef.o(.text); /* Fast3DEX2 only */
+ BUILD_DIR/libultra.a:consoleType.o(.text);
+ BUILD_DIR/libultra.a:skGetId.o(.text);
BUILD_DIR/lib/rsp.o(.text);
#endif