summaryrefslogtreecommitdiff
path: root/src/home/script.asm
blob: 229eb65060a08c09973dd692a8cb99b4928ce628 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
HandleMoveModeAPress:
	ldh a, [hBankROM]
	push af
	ld l, MAP_SCRIPT_OBJECTS
	call GetMapScriptPointer
	jr nc, .handleSecondAPressScript
	ld a, BANK(FindPlayerMovementFromDirection)
	call BankswitchROM
	call FindPlayerMovementFromDirection
	ld a, BANK(MapScripts)
	call BankswitchROM
	ld a, [wPlayerDirection]
	ld d, a
.findAPressMatchLoop
	ld a, [hli]
	bit 7, a
	jr nz, .handleSecondAPressScript
	push bc
	push hl
	cp d
	jr nz, .noMatch
	ld a, [hli]
	cp b
	jr nz, .noMatch
	ld a, [hli]
	cp c
	jr nz, .noMatch
	ld a, [hli]
	ld [wNextScript], a
	ld a, [hli]
	ld [wNextScript+1], a
	ld a, [hli]
	ld [wDefaultObjectText], a
	ld a, [hli]
	ld [wDefaultObjectText+1], a
	ld a, [hli]
	ld [wCurrentNPCNameTx], a
	ld a, [hli]
	ld [wCurrentNPCNameTx+1], a
	pop hl
	pop bc
	pop af
	call BankswitchROM
	scf
	ret
.noMatch
	pop hl
	ld bc, MAP_OBJECT_SIZE - 1
	add hl, bc
	pop bc
	jr .findAPressMatchLoop
.handleSecondAPressScript
	pop af
	call BankswitchROM
	ld l, MAP_SCRIPT_PRESSED_A
	call CallMapScriptPointerIfExists
	ret

; returns a map script pointer in hl given
; current map in wCurMap and which sub-script in l
; sets c if pointer is found
GetMapScriptPointer:
	push bc
	push hl
	ld a, [wCurMap]
	ld l, a
	ld h, $0
	add hl, hl
	add hl, hl
	add hl, hl
	add hl, hl
	ld bc, MapScripts
	add hl, bc
	pop bc
	ld b, $0
	add hl, bc
	ldh a, [hBankROM]
	push af
	ld a, BANK(MapScripts)
	call BankswitchROM
	ld a, [hli]
	ld h, [hl]
	ld l, a
	pop af
	call BankswitchROM
	ld a, l
	or h
	jr nz, .asm_3ae5
	scf
.asm_3ae5
	ccf
	pop bc
	ret

; loads some configurations for the duel against
; the NPC whose deck ID is stored in wNPCDuelDeckID
; this includes NPC portrait, his/her name text ID,
; and the number of prize cards
; this was used in testing since these configurations
; are stored in the script-related NPC data for normal gameplay
; returns carry if a duel configuration was found
; for the given NPC deck ID
GetNPCDuelConfigurations:
	farcall _GetNPCDuelConfigurations
	ret

; finds a Script from the first byte and puts the next two bytes (usually arguments?) into cb
RunOverworldScript:
	ld hl, wScriptPointer
	ld a, [hli]
	ld h, [hl]
	ld l, a
	ld a, [hli]
	ld c, [hl]
	inc hl
	ld b, [hl]
	push bc
	rlca
	ld c, a
	ld b, $0
	ld hl, OverworldScriptTable
	add hl, bc
	ldh a, [hBankROM]
	push af
	ld a, BANK(OverworldScriptTable)
	call BankswitchROM
	ld a, [hli]
	ld h, [hl]
	ld l, a
	pop af
	call BankswitchROM
	pop bc
	jp hl

Func_3b11:
	ldh a, [hBankROM]
	push af
	ld a, BANK(_GameLoop)
	call BankswitchROM
	call _GameLoop
	pop af
	call BankswitchROM
	ret

Func_3b21:
	ldh a, [hBankROM]
	push af
	ld a, BANK(Func_1c8bc)
	call BankswitchROM
	call Func_1c8bc
	pop af
	call BankswitchROM
	ret

Func_3b31:
	ldh a, [hBankROM]
	push af
	ld a, BANK(Func_1cb18)
	call BankswitchROM
	call Func_1cb18
	jr c, .asm_3b45
	xor a
	ld [wDoFrameFunction], a
	ld [wDoFrameFunction + 1], a
.asm_3b45
	call ZeroObjectPositions
	ld a, 1
	ld [wVBlankOAMCopyToggle], a
	pop af
	call BankswitchROM
	ret