src/gba/hle-bios.s (view raw)
1# Copyright (c) 2013-2014 Jeffrey Pfau
2#
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6#define nop andeq r0, r0
7
8.text
9
10b resetBase
11b undefBase
12b swiBase
13b pabtBase
14b dabtBase
15nop
16b irqBase
17b fiqBase
18
19resetBase:
20mov r0, #0x8000000
21ldrb r1, [r0, #3]
22cmp r1, #0xEA
23ldrne r0, =0x20000C0
24bx r0
25.word 0
26.word 0xE129F000
27
28swiBase:
29cmp sp, #0
30moveq sp, #0x04000000
31subeq sp, #0x20
32stmfd sp!, {r11-r12, lr}
33ldrb r11, [lr, #-2]
34mov r12, #swiTable
35ldr r11, [r12, r11, lsl #2]
36cmp r11, #0
37mrs r12, spsr
38stmfd sp!, {r12}
39and r12, #0x80
40orr r12, #0x1F
41msr cpsr, r12
42stmfd sp!, {lr}
43nop
44nop
45nop
46nop
47nop
48nop
49nop
50nop
51nop
52nop
53mov lr, pc
54bxne r11
55nop
56nop
57nop
58nop
59ldmfd sp!, {lr}
60msr cpsr, #0x93
61ldmfd sp!, {r12}
62msr spsr, r12
63ldmfd sp!, {r11-r12, lr}
64movs pc, lr
65.word 0
66.word 0xE3A02004
67
68swiTable:
69.word SoftReset @ 0x00
70.word RegisterRamReset @ 0x01
71.word Halt @ 0x02
72.word Stop @ 0x03
73.word IntrWait @ 0x04
74.word VBlankIntrWait @ 0x05
75.word Div @ 0x06
76.word DivArm @ 0x07
77.word Sqrt @ 0x08
78.word ArcTan @ 0x09
79.word ArcTan2 @ 0x0A
80.word CpuSet @ 0x0B
81.word CpuFastSet @ 0x0C
82.word GetBiosChecksum @ 0x0D
83.word BgAffineSet @ 0x0E
84.word ObjAffineSet @ 0x0F
85.word BitUnPack @ 0x10
86.word Lz77UnCompWram @ 0x11
87.word Lz77UnCompVram @ 0x12
88.word HuffmanUnComp @ 0x13
89.word RlUnCompWram @ 0x14
90.word RlUnCompVram @ 0x15
91.word Diff8BitUnFilterWram @ 0x16
92.word Diff8BitUnFilterVram @ 0x17
93.word Diff16BitUnFilter @ 0x18
94.word SoundBias @ 0x19
95.word SoundDriverInit @ 0x1A
96.word SoundDriverMode @ 0x1B
97.word SoundDriverMain @ 0x1C
98.word SoundDriverVsync @ 0x1D
99.word SoundChannelClear @ 0x1E
100.word MidiKey2Freq @ 0x1F
101.word MusicPlayerOpen @ 0x20
102.word MusicPlayerStart @ 0x21
103.word MusicPlayerStop @ 0x22
104.word MusicPlayerContinue @ 0x23
105.word MusicPlayerFadeOut @ 0x24
106.word MultiBoot @ 0x25
107.word HardReset @ 0x26
108.word CustomHalt @ 0x27
109.word SoundDriverVsyncOff @ 0x28
110.word SoundDriverVsyncOn @ 0x29
111.word SoundDriverGetJumpList @ 0x2A
112
113.ltorg
114
115irqBase:
116stmfd sp!, {r0-r3, r12, lr}
117mov r0, #0x04000000
118add lr, pc, #0
119ldr pc, [r0, #-4]
120ldmfd sp!, {r0-r3, r12, lr}
121subs pc, lr, #4
122.word 0
123.word 0xE55EC002
124
125undefBase:
126subs pc, lr, #4
127.word 0
128.word 0x03A0E004
129
130@ Unimplemented
131SoftReset:
132RegisterRamReset:
133Stop:
134Div:
135DivArm:
136Sqrt:
137ArcTan:
138ArcTan2:
139GetBiosChecksum:
140BgAffineSet:
141ObjAffineSet:
142BitUnPack:
143Lz77UnCompWram:
144Lz77UnCompVram:
145HuffmanUnComp:
146RlUnCompWram:
147RlUnCompVram:
148Diff8BitUnFilterWram:
149Diff8BitUnFilterVram:
150Diff16BitUnFilter:
151SoundBias:
152SoundDriverInit:
153SoundDriverMode:
154SoundDriverMain:
155SoundDriverVsync:
156SoundChannelClear:
157MidiKey2Freq:
158MusicPlayerOpen:
159MusicPlayerStart:
160MusicPlayerStop:
161MusicPlayerContinue:
162MusicPlayerFadeOut:
163MultiBoot:
164HardReset:
165CustomHalt:
166SoundDriverVsyncOff:
167SoundDriverVsyncOn:
168
169NopCall:
170bx lr
171
172Halt:
173mov r11, #0
174mov r12, #0x04000000
175strb r11, [r12, #0x301]
176bx lr
177
178VBlankIntrWait:
179mov r0, #1
180mov r1, #1
181IntrWait:
182stmfd sp!, {r2-r3, lr}
183mov r12, #0x04000000
184@ See if we want to return immediately
185cmp r0, #0
186mov r0, #0
187mov r2, #1
188beq 1f
189ldrh r3, [r12, #-8]
190bic r3, r1
191strh r3, [r12, #-8]
192@ Halt
1930:
194strb r0, [r12, #0x301]
1951:
196@ Check which interrupts were acknowledged
197strb r0, [r12, #0x208]
198ldrh r3, [r12, #-8]
199ands r3, r1
200eorne r3, r1
201strneh r3, [r12, #-8]
202strb r2, [r12, #0x208]
203beq 0b
204ldmfd sp!, {r2-r3, pc}
205
206CpuSet:
207stmfd sp!, {r4, r5, lr}
208mov r4, r2, lsl #12
209mov r12, r0
210mov r5, r1
211tst r2, #0x01000000
212beq 0f
213@ Fill
214tst r2, #0x04000000
215beq 1f
216@ Word
217add r4, r5, r4, lsr #10
218ldmia r12!, {r3}
2192:
220cmp r5, r4
221stmltia r5!, {r3}
222blt 2b
223b 3f
224@ Halfword
2251:
226bic r12, #1
227bic r5, #1
228add r4, r5, r4, lsr #11
229ldrh r3, [r12]
2302:
231cmp r5, r4
232strlth r3, [r5], #2
233blt 2b
234b 3f
235@ Copy
2360:
237tst r2, #0x04000000
238beq 1f
239@ Word
240add r4, r5, r4, lsr #10
2412:
242cmp r5, r4
243ldmltia r12!, {r3}
244stmltia r5!, {r3}
245blt 2b
246b 3f
247@ Halfword
2481:
249add r4, r5, r4, lsr #11
2502:
251cmp r5, r4
252ldrlth r3, [r12], #2
253strlth r3, [r5], #2
254blt 2b
2553:
256mov r3, #0x170 @ Match official BIOS's clobbered r3
257ldmfd sp!, {r4, r5, pc}
258
259CpuFastSet:
260stmfd sp!, {r4-r10, lr}
261tst r2, #0x01000000
262mov r3, r2, lsl #12
263add r2, r1, r3, lsr #10
264beq 0f
265@ Fill
266ldr r3, [r0]
267mov r4, r3
268mov r5, r3
269mov r6, r3
270mov r7, r3
271mov r8, r3
272mov r9, r3
273mov r10, r3
2741:
275cmp r1, r2
276stmltia r1!, {r3-r10}
277blt 1b
278b 2f
279@ Copy
2800:
281cmp r1, r2
282ldmltia r0!, {r3-r10}
283stmltia r1!, {r3-r10}
284blt 0b
2852:
286ldmfd sp!, {r4-r10, pc}
287
288SoundDriverGetJumpList:
289stmfd sp!, {r4-r10}
290ldr r1, =NopCall
291mov r3, r1
292mov r4, r1
293mov r5, r1
294mov r6, r1
295mov r7, r1
296mov r8, r1
297mov r9, r1
298mov r10, r1
299stmia r0!, {r1, r3-r10}
300stmia r0!, {r1, r3-r10}
301stmia r0!, {r1, r3-r10}
302stmia r0!, {r1, r3-r10}
303mov r1, #0
304ldmfd sp!, {r4-r10}
305bx lr
306
307.ltorg