-
Notifications
You must be signed in to change notification settings - Fork 2
/
mio0-editor22.asm
169 lines (147 loc) · 3.02 KB
/
mio0-editor22.asm
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
; both mio0 and regular load are served by the same function
.orga 0x108694
.dw 0x80402000
.dw 0x80402000
.orga 0x1202000
.area 0x100, 0x01
ADDIU SP, SP, -0x20
SW RA, 0x14(SP)
LUI T0, 0x8039
LW T0, 0xBE28(T0)
; load data from commands
; A0 is either bank/ram address
LBU V0, 0x0(T0)
LBU A0, 0x3(T0)
LW A1, 0x4(T0)
LW A2, 0x8(T0)
; detect if static or dynamic
; 2nd byte tells
; if dynamic, we have done everything already
LBU T1, 0x2(T0)
ADDIU T0, R0, 1
BNE T1, T0, dynamic
NOP
; static
;bug check
; could be removed if wanted
static:
SLTIU AT, A0, 0x14
BEQ AT, R0, bugon
NOP
; prepare ptr in segment list
LUI T0, 0x8034
SLL T1, A0, 2
ADDU T9, T0, T1
SW T9, 0x18(SP)
; prepare ptr in static ram
SLL T1, A0, 2
LUI T0, 0x8040
ADDU T0, T0, T1
LW A0, 0x2220(T0)
SW A0, 0x1C(SP)
BEQ A0, R0, bugon
NOP
; do it
LI T0, 0x18
BEQ T0, V0, mio0
NOP
JAL 0x80278504
NOP
B enddyn
NOP
mio0:
; cmd is 18 which is mio0 static
JAL 0x80402100
NOP
enddyn:
; set the new segment ptr
LW T9, 0x18(SP)
LW A0, 0x1C(SP)
LI T0, 0x00FFFFFF
AND A0, A0, T0
B end
SW A0, 0xB400(T9)
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
dynamic:
JAL 0x8027868C
ADDIU A3, R0, 0
end:
LUI T0, 0x8039
LW T1, 0xBE28(T0)
LB T2, 0x1(T1)
ADDU T1, T1, T2
SW T1, 0xBE28(T0)
LW RA, 0x14(SP)
JR RA
ADDIU SP, SP, 0x20
bugon:
J 0
NOP
.endarea
; mio0 static loader, matched interface of cmd17 static loader
; A0 = ram address
; A1 = rom start
; A2 = rom end
.orga 0x1202100
.area 0x130, 0x01
ADDIU SP, SP, -0x30
SW RA, 0x14 (SP)
SW A0, 0x0024 (SP) ; 0x28 - bank // static ram = 0x24
SW A1, 0x002C (SP) ; 0x2C - rom start
SW A2, 0x0020 (SP) ; 0x30 - rom end
LI A0, 0x80530000 ; collision data, have like 0xB0000 space
SW A0, 0x001C (SP) ; 0x1C - alloced temp mio0
LW A1, 0x002C (SP)
JAL 0x80278504 ; dmacopy(ram mio0, rom start, rom end)
LW A2, 0x0020 (SP)
LW A0, 0x001C (SP)
JAL 0x8027F4E0 ; unpack(mio0 packed, mio0 unpacked)
LW A1, 0x0024 (SP)
LW RA, 0x14(SP)
JR RA
ADDIU SP, SP, 0x30
.endarea
.if readu32(outputname(), 0x1202000) == 0xD0FFBD27
; ptr load table
; this should be filled in from the target rom
.orga 0x1202220
.dw 0x00000000 ;0
.dw 0x00000000 ;1
.dw 0x00000000 ;2
.dw 0x00000000 ;3
.dw 0x00000000 ;4
.db readu8(outputname(), 0x1202172)
.db readu8(outputname(), 0x1202173)
.dh 0x0000 ;80 40 21 58 ;5
.db readu8(outputname(), 0x120213A)
.db readu8(outputname(), 0x120213B)
.dh 0x0000 ;80 40 21 20 ;6
.db readu8(outputname(), 0x1202102)
.db readu8(outputname(), 0x1202103)
.dh 0x0000 ;80 40 20 E8 ;7
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.db readu16(outputname(), 0x12020CA)
.db readu16(outputname(), 0x12020CB)
.dh 0x0000 ;80 40 20 B0 ;E
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.dw 0x00000000 ;80 40 22 00
.db readu16(outputname(), 0x12021AA)
.db readu16(outputname(), 0x12021AB)
.dh 0x0000 ;80 40 21 90
.endif