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
28.word 0 @ Padding for back-compat
29
30swiBase:
31cmp sp, #0
32moveq sp, #0x04000000
33subeq sp, #0x20
34stmfd sp!, {r4, r11-r12, lr}
35ldrb r11, [lr, #-2]
36mov r12, #swiTable
37ldr r11, [r12, r11, lsl #2]
38mov r12, #StallCall
39cmp r12, r11
40swieq 0xF00000 @ Special mGBA-internal call to load the stall count into r4
41mrs r12, spsr
42stmfd sp!, {r12}
43and r12, #0x80
44orr r12, #0x1F
45msr cpsr_c, r12
46stmfd sp!, {lr}
47cmp r11, #0
48nop
49nop
50nop
51nop
52nop
53nop
54mov lr, pc
55bxne r11
56nop
57nop
58nop
59ldmfd sp!, {lr}
60msr cpsr, #0x93
61ldmfd sp!, {r12}
62msr spsr, r12
63ldmfd sp!, {r4, r11-r12, lr}
64movs pc, lr
65.word 0
66.word 0xE3A02004
67
68.word 0 @ Padding for back-compat
69
70swiTable:
71.word SoftReset @ 0x00
72.word RegisterRamReset @ 0x01
73.word Halt @ 0x02
74.word Stop @ 0x03
75.word IntrWait @ 0x04
76.word VBlankIntrWait @ 0x05
77.word Div @ 0x06
78.word DivArm @ 0x07
79.word Sqrt @ 0x08
80.word ArcTan @ 0x09
81.word ArcTan2 @ 0x0A
82.word CpuSet @ 0x0B
83.word CpuFastSet @ 0x0C
84.word GetBiosChecksum @ 0x0D
85.word BgAffineSet @ 0x0E
86.word ObjAffineSet @ 0x0F
87.word BitUnPack @ 0x10
88.word Lz77UnCompWram @ 0x11
89.word Lz77UnCompVram @ 0x12
90.word HuffmanUnComp @ 0x13
91.word RlUnCompWram @ 0x14
92.word RlUnCompVram @ 0x15
93.word Diff8BitUnFilterWram @ 0x16
94.word Diff8BitUnFilterVram @ 0x17
95.word Diff16BitUnFilter @ 0x18
96.word SoundBias @ 0x19
97.word SoundDriverInit @ 0x1A
98.word SoundDriverMode @ 0x1B
99.word SoundDriverMain @ 0x1C
100.word SoundDriverVsync @ 0x1D
101.word SoundChannelClear @ 0x1E
102.word MidiKey2Freq @ 0x1F
103.word MusicPlayerOpen @ 0x20
104.word MusicPlayerStart @ 0x21
105.word MusicPlayerStop @ 0x22
106.word MusicPlayerContinue @ 0x23
107.word MusicPlayerFadeOut @ 0x24
108.word MultiBoot @ 0x25
109.word HardReset @ 0x26
110.word CustomHalt @ 0x27
111.word SoundDriverVsyncOff @ 0x28
112.word SoundDriverVsyncOn @ 0x29
113.word SoundDriverGetJumpList @ 0x2A
114
115.ltorg
116
117irqBase:
118stmfd sp!, {r0-r3, r12, lr}
119mov r0, #0x04000000
120add lr, pc, #0
121ldr pc, [r0, #-4]
122ldmfd sp!, {r0-r3, r12, lr}
123subs pc, lr, #4
124.word 0
125.word 0xE55EC002
126
127undefBase:
128subs pc, lr, #4
129.word 0
130.word 0x03A0E004
131
132@ Unimplemented
133SoftReset:
134RegisterRamReset:
135Stop:
136GetBiosChecksum:
137BgAffineSet:
138ObjAffineSet:
139BitUnPack:
140Lz77UnCompWram:
141Lz77UnCompVram:
142HuffmanUnComp:
143RlUnCompWram:
144RlUnCompVram:
145Diff8BitUnFilterWram:
146Diff8BitUnFilterVram:
147Diff16BitUnFilter:
148SoundBias:
149SoundDriverInit:
150SoundDriverMode:
151SoundDriverMain:
152SoundDriverVsync:
153SoundChannelClear:
154MidiKey2Freq:
155MusicPlayerOpen:
156MusicPlayerStart:
157MusicPlayerStop:
158MusicPlayerContinue:
159MusicPlayerFadeOut:
160MultiBoot:
161HardReset:
162CustomHalt:
163SoundDriverVsyncOff:
164SoundDriverVsyncOn:
165
166NopCall:
167bx lr
168
169Halt:
170mov r11, #0
171mov r12, #0x04000000
172strb r11, [r12, #0x301]
173bx lr
174
175VBlankIntrWait:
176mov r0, #1
177mov r1, #1
178IntrWait:
179stmfd sp!, {r2-r3, lr}
180mov r12, #0x04000000
181@ See if we want to return immediately
182cmp r0, #0
183mov r0, #0
184mov r2, #1
185beq 1f
186ldrh r3, [r12, #-8]
187bic r3, r1
188strh r3, [r12, #-8]
189@ Halt
1900:
191strb r0, [r12, #0x301]
1921:
193@ Check which interrupts were acknowledged
194strb r0, [r12, #0x208]
195ldrh r3, [r12, #-8]
196ands r3, r1
197eorne r3, r1
198strneh r3, [r12, #-8]
199strb r2, [r12, #0x208]
200beq 0b
201ldmfd sp!, {r2-r3, pc}
202
203CpuSet:
204stmfd sp!, {r4, r5, lr}
205mov r4, r2, lsl #12
206mov r12, r0
207mov r5, r1
208tst r2, #0x01000000
209beq 0f
210@ Fill
211tst r2, #0x04000000
212beq 1f
213@ Word
214add r4, r5, r4, lsr #10
215ldmia r12!, {r3}
2162:
217cmp r5, r4
218stmltia r5!, {r3}
219blt 2b
220b 3f
221@ Halfword
2221:
223bic r12, #1
224bic r5, #1
225add r4, r5, r4, lsr #11
226ldrh r3, [r12]
2272:
228cmp r5, r4
229strlth r3, [r5], #2
230blt 2b
231b 3f
232@ Copy
2330:
234tst r2, #0x04000000
235beq 1f
236@ Word
237add r4, r5, r4, lsr #10
2382:
239cmp r5, r4
240ldmltia r12!, {r3}
241stmltia r5!, {r3}
242blt 2b
243b 3f
244@ Halfword
2451:
246add r4, r5, r4, lsr #11
2472:
248cmp r5, r4
249ldrlth r3, [r12], #2
250strlth r3, [r5], #2
251blt 2b
2523:
253mov r3, #0x170 @ Match official BIOS's clobbered r3
254ldmfd sp!, {r4, r5, pc}
255
256CpuFastSet:
257stmfd sp!, {r4-r10, lr}
258tst r2, #0x01000000
259mov r3, r2, lsl #12
260add r2, r1, r3, lsr #10
261beq 0f
262@ Fill
263ldr r3, [r0]
264mov r4, r3
265mov r5, r3
266mov r6, r3
267mov r7, r3
268mov r8, r3
269mov r9, r3
270mov r10, r3
2711:
272cmp r1, r2
273stmltia r1!, {r3-r10}
274blt 1b
275b 2f
276@ Copy
2770:
278cmp r1, r2
279ldmltia r0!, {r3-r10}
280stmltia r1!, {r3-r10}
281blt 0b
2822:
283ldmfd sp!, {r4-r10, pc}
284
285SoundDriverGetJumpList:
286stmfd sp!, {r4-r10}
287ldr r1, =NopCall
288mov r3, r1
289mov r4, r1
290mov r5, r1
291mov r6, r1
292mov r7, r1
293mov r8, r1
294mov r9, r1
295mov r10, r1
296stmia r0!, {r1, r3-r10}
297stmia r0!, {r1, r3-r10}
298stmia r0!, {r1, r3-r10}
299stmia r0!, {r1, r3-r10}
300mov r1, #0
301ldmfd sp!, {r4-r10}
302bx lr
303
304.ltorg
305
306Div:
307DivArm:
308Sqrt:
309ArcTan:
310ArcTan2:
311
312StallCall:
313subs r4, #4
314bhi StallCall
315bx lr