-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmovement.asm
278 lines (241 loc) · 5.65 KB
/
movement.asm
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# Hello world + movement
# Displays HELLO WORLD at the top of the screen, and there's a character you can move around on the screen with the directional pad
bg_tile_map = 0x9800
alphabet_start_addr = 0x8000 + (0x41 * 16)
lcdc = 0xff40
lcdc_operation_bit = (1 << 7)
lcdc_win_tilemap_bit = (1 << 6) # 0 = 9800 - 9bff, 1 = 9c00 - 9ffff
lcdc_win_on_bit = (1 << 5)
lcdc_bgwin_tiledata_bit = (1 << 4) # 0 = 8800 - 97ff, 1 = 8000 - 8fff
lcdc_bg_tilemap_bit = (1 << 3) # 0 = 9800 - 9bff, 1 = 9c00 - 9fff
lcdc_sprite_size_bit = (1 << 2) #0 = 8*8, 1 = 8*16
lcdc_sprite_on_bit = (1 << 1)
lcdc_bgwin_on_bit = (1 << 0)
ly = 0xff44
dma = 0xff46
bgwin_palette = 0xff47
obj1_palette = 0xff48
obj2_palette = 0xff49
interrupt_enable = 0xffff
ie_time = (1 << 2)
ie_lcdc = (1 << 1)
ie_vblank = (1 << 0)
[org(0x4000)] message: db "HELLO WORLD"
[org(0x4041)]
letter_a: db 0x00, 0x18, 0x24, 0x24, 0x3c, 0x24, 0x24, 0x24
letter_b: db 0x00, 0x38, 0x24, 0x24, 0x24, 0x38, 0x24, 0x38
letter_c: db 0x00, 0x18, 0x24, 0x20, 0x20, 0x20, 0x24, 0x18
letter_d: db 0x00, 0x38, 0x24, 0x24, 0x24, 0x24, 0x24, 0x38
letter_e: db 0x00, 0x3c, 0x20, 0x20, 0x20, 0x38, 0x20, 0x3c
letter_f: db 0x00, 0x3c, 0x20, 0x20, 0x20, 0x38, 0x20, 0x20
letter_g: db 0x00, 0x18, 0x24, 0x20, 0x20, 0x2c, 0x24, 0x1c
letter_h: db 0x00, 0x24, 0x24, 0x24, 0x24, 0x3c, 0x24, 0x24
letter_i: db 0x00, 0x1c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1c
letter_j: db 0x00, 0x0e, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18
letter_k: db 0x00, 0x24, 0x24, 0x28, 0x30, 0x30, 0x28, 0x24
letter_l: db 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c
letter_m: db 0x00, 0x22, 0x36, 0x2a, 0x22, 0x22, 0x22, 0x22
letter_n: db 0x00, 0x22, 0x32, 0x32, 0x2a, 0x26, 0x26, 0x22
letter_o: db 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18
letter_p: db 0x00, 0x38, 0x24, 0x24, 0x38, 0x30, 0x30, 0x30
letter_q: db 0x00, 0x38, 0x24, 0x24, 0x24, 0x24, 0x2c, 0x1e
letter_r: db 0x00, 0x38, 0x24, 0x24, 0x38, 0x24, 0x24, 0x24
letter_s: db 0x00, 0x18, 0x24, 0x20, 0x18, 0x04, 0x24, 0x18
letter_t: db 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
letter_u: db 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18
letter_v: db 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x14, 0x08
letter_w: db 0x00, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x2c
letter_x: db 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22
letter_y: db 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08
letter_z: db 0x00, 0x3c, 0x04, 0x04, 0x18, 0x20, 0x20, 0x3c
sprite: db 0b0001_1000, 0b0001_1000, 0b0111_1110, 0b1011_1101, 0b1011_1101, 0b0001_1000, 0b0010_0100, 0b0110_0110
[org(0x0040)] vblank_interrupt: jp 0xff80
[org(0x100)] start: nop; jp main
[org(0x134)] game_title: db "HELLO WORLD"
[org(0x150)] main:
ld sp, 0xfffe
di
call stopLCD
# Clear 8000 - 8fff
xor a
ld hl, 0x8001
ld de, 0x1fff
call fill_bytes
# Clear c000 - cfff
xor a
ld hl, 0xc000
ld de, 0x1000
call fill_bytes
ld a, 40
ld hl, 0xc000
ld [hl+], a
ld [hl+], a
ld a, 91
ld [hl+], a
ld a, 0
ld [hl+], a
# Copy DMA routine to high RAM
ld hl, 0xff80
ld bc, perform_dma
ld de, (perform_dma_end - perform_dma)
call copy_bytes
ld hl, alphabet_start_addr
ld de, 26 * (8 * 8)
ld bc, 0x4041
call copy_bytes_twice
ld hl, bg_tile_map
ld bc, 0x4000
ld de, 11
call copy_bytes
# Set bg palette data
ld a, 0xe4
ld [bgwin_palette], a
ld [obj1_palette], a
ld [obj2_palette], a
call startLCD
ld a, (ie_vblank)
ld [interrupt_enable], a
ei
ld d, 0
main_loop:
halt
nop
dec d
# jr nz, main_loop
call read_input
jr main_loop
read_input:
ld a, 0x20
ld [0xff00], a
ld a, [0xff00]
ld a, [0xff00]
cpl
and 0x0f
swap a
ld b, a
ld a, 0x10
ld [0xff00], a
ld a, [0xff00]
ld a, [0xff00]
cpl
and 0x0f
or b
ld b, a
check_down:
bit 7, b
jr z, check_up
ld a, [0xc000]
inc a
ld [0xc000], a
jr check_left
check_up:
bit 6, b
jr z, check_left
ld a, [0xc000]
dec a
ld [0xc000], a
check_left:
bit 4, b
jr z, check_right
ld a, [0xc001]
inc a
ld [0xc001], a
jr check_end
check_right:
bit 5, b
jr z, check_end
ld a, [0xc001]
dec a
ld [0xc001], a
check_end:
ret
perform_dma:
push af
ld a, 0xc0
ld [dma], a
ld a, 0x28
perform_dma_wait:
dec a
jr nz, perform_dma_wait
pop af
reti
perform_dma_end:
incsprite:
ld a, [0x8000]
inc a
ld [0x8000], a
ret
# Wait until it's safe to update the screen and then disable LCD operation
stopLCD:
ld a, [ly]
cp 145
jp nc, stopLCD
xor a
ld [lcdc], a
ret
startLCD:
ld a, (lcdc_bgwin_on_bit | lcdc_operation_bit | lcdc_bgwin_tiledata_bit | lcdc_sprite_on_bit)
ld [lcdc], a
ret
# a: byte to fill with
# de: number of bytes
# hl: destination address
fill_bytes:
inc e
inc d
jp fill_bytes_loop
fill_bytes_copy:
ld [hl+], a
fill_bytes_loop:
dec e
jp nz, fill_bytes_copy
dec d
jp nz, fill_bytes_copy
ret
# de: number of bytes
# bc: start address
# hl: destination address
copy_bytes:
inc e
inc d
jp copy_bytes_loop
copy_bytes_copy:
ld a, [bc]
ld [hl+], a
inc bc
copy_bytes_loop:
dec e
jp nz, copy_bytes_copy
dec d
jp nz, copy_bytes_copy
ret
# de: number of bytes
# bc: start address
# hl: destination address
copy_bytes_twice:
inc e
inc d
jp copy_bytes_twice_loop
copy_bytes_twice_copy:
ld a, [bc]
ld [hl+], a
ld [hl+], a
inc bc
copy_bytes_twice_loop:
dec e
jp nz, copy_bytes_twice_copy
dec d
jp nz, copy_bytes_twice_copy
ret
# to_a_1:
# ld a, (bg_tile_map)
# inc a
# ld (bg_tile_map), a
# ret
#
# to_a_2:
# ld a, (bg_tile_map + 1)
# inc a
# ld (bg_tile_map + 1), a
# ret
[org(0x7fff)] pad: db 0x00