| 1 |
IROM_BASE: equ 0x8000 |
| 2 |
|
| 3 |
lri $CR, #0x00ff |
| 4 |
lri $SR, #0x2000 |
| 5 |
si @DMBH, #0x8071 |
| 6 |
si @DMBL, #0xfeed |
| 7 |
|
| 8 |
mainloop: |
| 9 |
clr $ACC1 |
| 10 |
clr $ACC0 |
| 11 |
call wait_for_cpu_mbox+#IROM_BASE |
| 12 |
|
| 13 |
;mmem-addr |
| 14 |
param1: |
| 15 |
lr $AC1.M, @CMBL |
| 16 |
lri $AC0.M, #0xa001 |
| 17 |
cmp |
| 18 |
jnz param2+#IROM_BASE |
| 19 |
call wait_for_cpu_mbox+#IROM_BASE |
| 20 |
lr $IX0, @CMBH |
| 21 |
lr $IX1, @CMBL |
| 22 |
jmp mainloop+#IROM_BASE |
| 23 |
|
| 24 |
;iram-addr |
| 25 |
param2: |
| 26 |
lri $AC0.M, #0xc002 |
| 27 |
cmp |
| 28 |
jnz param3+#IROM_BASE |
| 29 |
call wait_for_cpu_mbox+#IROM_BASE |
| 30 |
lr $IX2, @CMBL |
| 31 |
jmp mainloop+#IROM_BASE |
| 32 |
|
| 33 |
;iram-length |
| 34 |
param3: |
| 35 |
lri $AC0.M, #0xa002 |
| 36 |
cmp |
| 37 |
jnz param4+#IROM_BASE |
| 38 |
call wait_for_cpu_mbox+#IROM_BASE |
| 39 |
lr $IX3, @CMBL |
| 40 |
jmp mainloop+#IROM_BASE |
| 41 |
|
| 42 |
;dram-length |
| 43 |
param4: |
| 44 |
lri $AC0.M, #0xb002 |
| 45 |
cmp |
| 46 |
jnz param5+#IROM_BASE |
| 47 |
call wait_for_cpu_mbox+#IROM_BASE |
| 48 |
lr $AX0.L, @CMBL |
| 49 |
jmp mainloop+#IROM_BASE |
| 50 |
|
| 51 |
;iram-start-addr |
| 52 |
param5: |
| 53 |
lri $AC0.M, #0xd001 |
| 54 |
cmp |
| 55 |
jnz mainloop+#IROM_BASE |
| 56 |
call wait_for_cpu_mbox+#IROM_BASE |
| 57 |
lr $AR0, @CMBL |
| 58 |
; skip the branch of bootucode that uses the AX registers |
| 59 |
jmp bootucode_ix+#IROM_BASE |
| 60 |
|
| 61 |
wait_dma: |
| 62 |
lrs $AC0.M, @DSCR |
| 63 |
andcf $AC0.M, #0x0004 |
| 64 |
jlz wait_dma+#IROM_BASE |
| 65 |
ret |
| 66 |
|
| 67 |
WARNPC 0x78 |
| 68 |
ORG 0x78 |
| 69 |
; called by GBA ucode |
| 70 |
wait_for_cpu_mbox: |
| 71 |
lrs $AC0.M, @CMBH |
| 72 |
andcf $AC0.M, #0x8000 |
| 73 |
jlnz wait_for_cpu_mbox+#IROM_BASE |
| 74 |
ret |
| 75 |
|
| 76 |
WARNPC 0x7e |
| 77 |
ORG 0x7e |
| 78 |
; called by GBA ucode |
| 79 |
wait_for_dsp_mbox: |
| 80 |
lrs $AC0.M, @DMBH |
| 81 |
andcf $AC0.M, #0x8000 |
| 82 |
jlz wait_for_dsp_mbox+#IROM_BASE |
| 83 |
ret |
| 84 |
|
| 85 |
WARNPC 0x8b |
| 86 |
ORG 0x8b |
| 87 |
; called by GBA ucode |
| 88 |
dram_to_cpu: |
| 89 |
sr @DSMAH, $AX0.H |
| 90 |
sr @DSMAL, $AX0.L |
| 91 |
si @DSCR, #0x1 |
| 92 |
sr @DSPA, $AX1.H |
| 93 |
sr @DSBL, $AX1.L |
| 94 |
call wait_dma+#IROM_BASE |
| 95 |
ret |
| 96 |
|
| 97 |
WARNPC 0xb5 |
| 98 |
ORG 0xb5 |
| 99 |
bootucode: |
| 100 |
set16 |
| 101 |
clr $ACC0 |
| 102 |
mrr $AC0.M, $AX1.L |
| 103 |
andi $AC0.M, #0xffff |
| 104 |
jz bootucode_ix+#IROM_BASE |
| 105 |
|
| 106 |
WARNPC 0xbc |
| 107 |
ORG 0xbc |
| 108 |
; called by GBA ucode |
| 109 |
bootucode_ax: |
| 110 |
lris $AC0.M, #0 |
| 111 |
srs @DSCR, $AC0.M |
| 112 |
sr @DSMAH, $AX0.H |
| 113 |
sr @DSMAL, $AX0.L |
| 114 |
sr @DSPA, $AX1.H |
| 115 |
sr @DSBL, $AX1.L |
| 116 |
call wait_dma+#IROM_BASE |
| 117 |
|
| 118 |
bootucode_ix: |
| 119 |
mrr $AC0.M, $IX3 |
| 120 |
andi $AC0.M, #0xffff |
| 121 |
jz bootucode_epilogue+#IROM_BASE |
| 122 |
lris $AC0.M, #0x2 |
| 123 |
srs @DSCR, $AC0.M |
| 124 |
sr @DSMAH, $IX0 |
| 125 |
sr @DSMAL, $IX1 |
| 126 |
sr @DSPA, $IX2 |
| 127 |
sr @DSBL, $IX3 |
| 128 |
call wait_dma+#IROM_BASE |
| 129 |
|
| 130 |
bootucode_epilogue: |
| 131 |
clr $ACC1 |
| 132 |
lr $AC1.M, @DSBL |
| 133 |
jmpr $AR0 |
| 134 |
|
| 135 |
WARNPC 0xe7 |
| 136 |
ORG 0xe7 |
| 137 |
; Args: |
| 138 |
; AR0 points to the 32 input 1 samples (s16) |
| 139 |
; AR1 points to the volume data (init1, delta1, init2, delta2) |
| 140 |
; AR2 points to the already mixed samples for output 1 (s32) |
| 141 |
; AR3 points to where the output 1 should be stored (s32) |
| 142 |
; IX0 points to the 32 input 2 samples (s16) |
| 143 |
; IX1 points to where the output 2 should be stored (s32) |
| 144 |
; |
| 145 |
; Returns: |
| 146 |
; AX0.L is the value of the last sample from input 1 |
| 147 |
; AX1.H is the value of the last sample from input 2 |
| 148 |
; |
| 149 |
; for i = 0..31: |
| 150 |
; ar3[i] = ((ar2[i] << 16) + ar0[i] * ar1[0]) >> 16 |
| 151 |
; for i = 0..31: |
| 152 |
; ix1[i] = ((ix1[i] << 16) + ix0[i] * ar1[2]) >> 16 |
| 153 |
; ax0.l = ar0[31] * ar1[0] |
| 154 |
; ax1.h = ix0[31] * ar1[2] |
| 155 |
mix_two_add: |
| 156 |
call mix_add+#IROM_BASE |
| 157 |
mrr $AR0, $IX0 |
| 158 |
mrr $AR2, $IX1 |
| 159 |
mrr $AR3, $IX1 |
| 160 |
mrr $IX0, $AX0.L |
| 161 |
call mix_add+#IROM_BASE |
| 162 |
mrr $AX1.H, $AX0.L |
| 163 |
mrr $AX0.L, $IX0 |
| 164 |
ret |
| 165 |
|
| 166 |
WARNPC 0x1f4 |
| 167 |
ORG 0x1f4 |
| 168 |
; used by GBA ucode for joyboot length and is the end of some mixing function |
| 169 |
; (for an example of hitting the full function, try running the main menu of |
| 170 |
; Metroid Prime using the Nintendo DSP ROM). |
| 171 |
sub_81f4: |
| 172 |
asr16'ir $ACC1 : $AR1 |
| 173 |
clr's $ACC0 : @$AR3, $AC1.M ; AC1.M is always #0x0 here. |
| 174 |
; necessary both to match register state of official ROM, and for the |
| 175 |
; following mul. could also be mrr $AX1.H, $AC0.M (before clearing ACC0). |
| 176 |
mrr $AX1.H, $AX0.H |
| 177 |
; make the product register match. |
| 178 |
mul's $AX1.L, $AX1.H : @$AR3, $AC1.L |
| 179 |
ret |
| 180 |
|
| 181 |
WARNPC 0x1f9 |
| 182 |
ORG 0x1f9 |
| 183 |
; Args: |
| 184 |
; AR0 points to the 32 input samples (s16) |
| 185 |
; AR1 points to the volume data (init, delta) |
| 186 |
; AR2 points to the already mixed samples (s32) |
| 187 |
; AR3 points to where the output should be stored (s32) |
| 188 |
; |
| 189 |
; Returns: |
| 190 |
; AX0.L is the value of the last sample |
| 191 |
; AX1.H is the first address after the output |
| 192 |
; |
| 193 |
; for i = 0..31: |
| 194 |
; ar3[i] = ((ar2[i] << 16) + ar0[i] * ar1[0]) >> 16 |
| 195 |
; ax0.l = ar0[31] * ar1[0] |
| 196 |
; ax1.h = ar3 + 32 // assuming ar3 is a s32 pointer |
| 197 |
mix_add: |
| 198 |
lrri $AX1.L, @$AR1 |
| 199 |
iar $AR1 |
| 200 |
bloopi #32, ____mix_add_end_loop+#IROM_BASE |
| 201 |
lrri $AC0.M, @$AR2 |
| 202 |
lrri $AC0.L, @$AR2 |
| 203 |
lsl16 $ACC0 |
| 204 |
lrri $AX0.H, @$AR0 |
| 205 |
mulx $AX0.H, $AX1.L |
| 206 |
addp $ACC0 |
| 207 |
asr16 $ACC0 |
| 208 |
srri @$AR3, $AC0.M |
| 209 |
____mix_add_end_loop: |
| 210 |
srri @$AR3, $AC0.L |
| 211 |
movp $ACC0 |
| 212 |
mrr $AX0.L, $AC0.M |
| 213 |
mrr $AX1.H, $AR3 |
| 214 |
ret |
| 215 |
|
| 216 |
WARNPC 0x282 |
| 217 |
ORG 0x282 |
| 218 |
; for i = 0..31: |
| 219 |
; ar3[i] = ar1[0] + i * ar1[1] |
| 220 |
; ar2[i] = ((ar2[i] << 16) + ar0[i] * ar3[i]) >> 16 |
| 221 |
; ar3[i+32] = ar1[2] + i * ar1[3] |
| 222 |
; ix1[i] = ((ix1[i] << 16) + ix0[i] * ar3[i+32]) >> 16 |
| 223 |
; ax0.l = ar0[31] * ar3[31] |
| 224 |
; ax1.h = ix0[31] * ar3[63] |
| 225 |
mix_two_add_ramp: |
| 226 |
call mix_add_ramp+#IROM_BASE |
| 227 |
mrr $AR0, $IX0 |
| 228 |
mrr $AR2, $IX1 |
| 229 |
mrr $IX1, $AX0.L |
| 230 |
call mix_add_ramp+#IROM_BASE |
| 231 |
mrr $AX1.H, $AX0.L |
| 232 |
mrr $AX0.L, $IX1 |
| 233 |
ret |
| 234 |
|
| 235 |
WARNPC 0x458 |
| 236 |
ORG 0x458 |
| 237 |
; used by GBA ucode for joyboot length |
| 238 |
sub_8458: |
| 239 |
; AC1.L after = AC1.M before + 7. this looks really stupid, but matches |
| 240 |
; captured traces and seems to work. |
| 241 |
addis $AC1.M, #0x7 |
| 242 |
asr16 $ACC1 |
| 243 |
srri @$AR3, $AC1.M ; or just #0x0. |
| 244 |
srri @$AR3, $AC1.L |
| 245 |
ret |
| 246 |
|
| 247 |
WARNPC 0x45d |
| 248 |
ORG 0x45d |
| 249 |
; for i = 0..31: |
| 250 |
; ar3[i] = ar1[0] + i * ar1[1] |
| 251 |
; ar2[i] = ((ar2[i] << 16) + ar0[i] * ar3[i]) >> 16 |
| 252 |
; ax0.l = ar0[31] * ar3[31] |
| 253 |
mix_add_ramp: |
| 254 |
clr $ACC0 |
| 255 |
clr $ACC1 |
| 256 |
lrri $AC0.L, @$AR1 |
| 257 |
lrrd $AC1.L, @$AR1 |
| 258 |
mrr $IX2, $AR3 |
| 259 |
|
| 260 |
bloopi #32, ____mix_add_ramp_end_ramp+#IROM_BASE |
| 261 |
srri @$AR3, $AC0.L |
| 262 |
____mix_add_ramp_end_ramp: |
| 263 |
add $ACC0, $ACC1 |
| 264 |
|
| 265 |
srri @$AR1, $AC0.L |
| 266 |
iar $AR1 |
| 267 |
mrr $IX3, $AR1 |
| 268 |
mrr $AR1, $IX2 |
| 269 |
mrr $AR3, $AR2 |
| 270 |
|
| 271 |
bloopi #32, ____mix_add_ramp_end_loop+#IROM_BASE |
| 272 |
lrri $AC0.M, @$AR2 |
| 273 |
lrri $AC0.L, @$AR2 |
| 274 |
lsl16 $ACC0 |
| 275 |
lrri $AX0.H, @$AR0 |
| 276 |
lrri $AX1.L, @$AR1 |
| 277 |
mulx $AX0.H, $AX1.L |
| 278 |
addp $ACC0 |
| 279 |
asr16 $ACC0 |
| 280 |
srri @$AR3, $AC0.M |
| 281 |
____mix_add_ramp_end_loop: |
| 282 |
srri @$AR3, $AC0.L |
| 283 |
movp $ACC0 |
| 284 |
mrr $AX0.L, $AC0.M |
| 285 |
mrr $AR1, $IX3 |
| 286 |
mrr $AR3, $IX2 |
| 287 |
ret |
| 288 |
|
| 289 |
WARNPC 0x723 |
| 290 |
ORG 0x723 |
| 291 |
; called by GBA ucode |
| 292 |
sub_8723: |
| 293 |
; in GBA-HLE, the nonce challenge is XOR'd with 0x6f646573, which happens |
| 294 |
; to match the values of the AX1.H register across these two calls. |
| 295 |
xorr $AC1.M, $AX1.H |
| 296 |
; the value of @AR2 is always the same as AC1.M after |
| 297 |
srrd @$AR2, $AC1.M |
| 298 |
ret |
| 299 |
|
| 300 |
WARNPC 0x809 |
| 301 |
ORG 0x809 |
| 302 |
; called by GBA ucode |
| 303 |
sub_8809: |
| 304 |
; AR2 is the only addressing register that corresponds to the dmem writes |
| 305 |
; could be AC1.L or AX0.L in the second call, but can't be AX0.L in the |
| 306 |
; third call. |
| 307 |
srr @$AR2, $AC1.L |
| 308 |
; AC1.M after calling always look like either AC1.M | AC0.M or |
| 309 |
; AC1.M | AX0.H. TODO: Why pick AX0.H? |
| 310 |
orr $AC1.M, $AX0.H |
| 311 |
; the second dmem write is incremented only in calls #3A and #3B. There, |
| 312 |
; IX2 is the only register set to 1, and it's specifically set to 1 in the |
| 313 |
; ucode. It's set to 0 in the first two calls. |
| 314 |
addarn $AR2, $IX2 |
| 315 |
; obvious |
| 316 |
srri @$AR2, $AC1.M |
| 317 |
ret |
| 318 |
|
| 319 |
WARNPC 0x8e5 |
| 320 |
ORG 0x8e5 |
| 321 |
; used by GBA ucode for challenge nonce, logo palette/speed, and joyboot length |
| 322 |
sub_88e5: |
| 323 |
dar $AR1 ; always gets decremented, no effect on rest of function |
| 324 |
lrri $AC1.M, @$AR2 |
| 325 |
lrrd $AC1.L, @$AR2 |
| 326 |
add $ACC0, $ACC1 ; signed addition |
| 327 |
orr $AC0.M, $AX0.H |
| 328 |
srri @$AR2, $AC0.M |
| 329 |
srr @$AR2, $AC0.L |
| 330 |
ret |
| 331 |
|
| 332 |
WARNPC 0x1000 |
| 333 |
ORG 0x1000 |