summaryrefslogtreecommitdiff
path: root/berry_fix/asm/loader.s
blob: 39e0b768a834deaa2a10505da78bb99f3eed0418 (plain)
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
	.include "../asm/macros/asm.inc"
	.include "../asm/macros/function.inc"
	.include "../constants/gba_constants.inc"

	.set SIO_ERROR,      0x0040
	.set SIO_MULTI_BUSY, 0x0080

	.set EWRAM_ORIG, 0x02000000
	.set gCode,  0x02010000
	.set PROG_ORIG,  0x00008000

	.syntax unified

	.text

	arm_func_start _start
_start: @ 0
	b _entry
	arm_func_end _start

	.include "asm/berry_fix_header.inc"

@ C0
	.word 0

	.global _GPIOPortData
_GPIOPortData: @ C4
	.2byte 0

	.global _GPIOPortDirection
_GPIOPortDirection: @ C6
	.2byte 0

	.global _GPIOPortReadEnable
_GPIOPortReadEnable: @ C8
	.2byte 0

@ CA
	.2byte 0

@ CC
	.space 0x34

	arm_func_start _entry
_entry: @ 100
	b _send
	arm_func_end _entry

	.space 0x1C

	arm_func_start _recv
_recv:
	@ Waits until link cable is no longer busy.
	@ Returns nz if an error has occurred
	@ Otherwise, returns the received short in r1.
	@ Preserves r0
_120:
	ldrh r1, [r0, 0x8] @ SIOCNT
	tst r1, SIO_MULTI_BUSY
	beq _120
_12c:
	ldrh r1, [r0, 0x8] @ SIOCNT
	tst r1, SIO_MULTI_BUSY
	bne _12c
	ldrh r1, [r0, 0x8] @ SIOCNT
	tst r1, SIO_ERROR
	bxne lr
	ldrh r1, [r0] @ SIOMULTI0
	bx lr
	arm_func_end _recv

	arm_func_start _send
_send: @ 14c
	ldr r0, =REG_SIOMULTI0
_150:
	bl _recv
	bne _150
	mov r2, 0
	strh r2, [r0, 0xa] @ SIOMLT_SEND
	cmp r1, 0
	bne _150
	mov r2, 0x8000
_16c:
	mov r1, 0
_170:
	strh r1, [r0, 0xa] @ SIOMLT_SEND
	bl _recv
	bne _150
	cmp r1, r2
	bne _16c
	lsr r2, 5
	cmp r1, 0
	bne _170
	ldr r3, =BerryFixMBHeaderGameCode
	ldrh r2, [r3]
	strh r2, [r0, 0xa] @ SIOMLT_SEND
	bl _recv
_1a0:
	bne _1a0
	cmp r1, r2
	bne _1a0
	ldrh r2, [r3, 0x2]
	strh r2, [r0, 0xa] @ SIOMLT_SEND
	bl _recv
	bne _1a0
	cmp r1, r2
	bne _1a0
	mov r1, 0
	strh r1, [r0, 0xa] @ SIOMLT_SEND
	ldr r0, =_data_2f0
	ldr r1, =gCode
	swi 0x11 << 16
	ldr lr, =gCode
	bx lr
	.pool
	arm_func_end _send
	@ 1f0

	.align 2, 0 @ don't pad with nop