-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.inc
150 lines (125 loc) · 2.6 KB
/
macros.inc
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
set_sprite: MACRO ; \1 \2\3\4\5
ld a, \2
ld [wShadowOam + \1*4], a
ld a, \3
ld [wShadowOam + 1 + \1*4], a
ld a, \4
ld [wShadowOam + 2 + \1*4], a
ld a, \5
ld [wShadowOam + 3 + \1*4], a
ENDM
set_sprite_addr: MACRO ; \1 \2\3\4\5
ld a, \2
ld [\1], a
ld a, \3
ld [\1 + 1], a
ld a, \4
ld [\1 + 2], a
ld a, \5
ld [\1 + 3], a
ENDM
clear_sprite: MACRO ; \1
xor a
ld [wShadowOam + \1*4], a
ENDM
ld16: MACRO ; r, hi, lo
ld \1, ((\2) & $ff) << 8 + ((\3) & $ff)
ENDM
; @param \1 The keycode defined in the KEY enum.
; @result Z flag
is_key_pressed : MACRO
ld a, [wInputState]
and \1
ld b, a
ld a, [wInputChanged]
and b
ENDM
; @param \1 The keycode defined in the KEY enum.
; @result Z flag
is_key_released : MACRO
ld a, [wInputChanged]
and \1
ld b, a
ld a, [wInputState]
xor a, $ff
and b
ENDM
; @param \1 The keycode defined in the KEY enum.
; @result Z flag
is_key_held : MACRO
ld a, [wInputState]
and \1
ENDM
; Calls the Load-Function of the Scene set in the jump table
; @param \1 The scene number to load. (use SCENE enum)
switch_scene : MACRO
xor a
ld [wInputState], a
ld a, \1
call GameLoadScene
ENDM
; Copies data to the shadow-map and queues the update
; @param \1 Label of the data to copy
; @param \2 2-byte size (w/h) of the area to copy
load_shadow_map : MACRO
ld de, \1
ld hl, wShadowMap
ld bc, \2
call MemCopyBlock
call QueueShadowUpdate
ENDM
; Copies data to the map vram
; @param \1 Label of the data to copy
; @param \2 2-byte size (w/h) of the area to copy
load_map : MACRO
ld de, \1
ld hl, _SCRN0
ld bc, \2
call MemCopyBlock
ENDM
; Copies data to the window vram
; @param \1 Label of the data to copy
; @param \2 2-byte size (w/h) of the area to copy
load_win : MACRO
ld de, \1
ld hl, _SCRN1
ld bc, \2
call MemCopyBlock
ENDM
; @param \1 The label of the jumptable
; @param bc The offset into the jumptable (Index*2 because of 16bit width)
lookup_jump : MACRO ; Requires offset (index *2) in BC \1 table-address
; load hl with the jump table address and add the offset
ld hl, \1
add hl, bc
; read the address from the jump table (HL) and store it into bc
ld a, [hli]
ld b, [hl]
; copy the address to hl
ld h, b
ld l, a
; jump
jp hl
ENDM
; @param \1 Address of Songdata
; @param \2 Speed
music_play : MACRO
ld hl, \1
ld a, \2
call MusicStartSong
ENDM
music_stop : MACRO
xor a
ld [wMusicStatus], a
ENDM
; @param \1 Address of Songdata
; @param \2 Speed
music_switch : MACRO
ld a, [wMusicStatus]
and a
jr nz,.noSwitch\@
ld hl, \1
ld a, \2
call MusicStartSong
.noSwitch\@:
ENDM