summaryrefslogtreecommitdiff
path: root/agbx/source/gfx/getvbnk.s
blob: f2e22ae574acf51ad72b665e15aef449541f29c5 (plain) (blame)
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
@ Copyright 2022 Gabriel Jensen.
@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
@ If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

.syntax unified

.cpu arm7tdmi
.thumb

.globl __agbx_getvbnk
.globl agbx_getvbnk

.func
.thumb_func

agbx_getvbnk:
	@ Get the current value of dispcnt:
	ldr r0,.dispcntaddr @ agbx_i20 dispcntaddr = 0x4000000u;
	ldrh r1,[r0]        @ agbx_i10 dispcnt = *(agbx_i10 *)dispcntaddr;

	@ Get the address:
	b __agbx_getvbnk    @ agbx_i20 vaddr = __agbx_getvbnk();
	
	bx lr               @ return vaddr;

.endfunc

.func
.thumb_func

__agbx_getvbnk: @ Takes the value of dispcnt in r1.
	@ Check if the fifth bit is set:
	movs r0,0b10000
	tst r1,r0
	beq .vbnk1

.vbnk0:
	@ Return the address of the first video bank:
	ldr r0,.vbnk0addr
	bx lr

.vbnk1:
	@ Return the address of the second video bank:
	ldr r0,.vbnk1addr
	bx lr

.endfunc

.align

.dispcntaddr:
	.long 0x4000000

.align

.vbnk0addr:
	.long 0x6000000

.align

.vbnk1addr:
	.long 0x600A000