gb_test2

view test.asm @ 2:a8b7297e7e2c

corrected comment
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 10 Jan 2019 04:48:34 +0200
parents d63782badb6b
children d7c6e1165028
line source
1 ; vi:ft=rgbasm:
2 include "hw.inc"
4 xoffs_center equ 4
5 yoffs_center equ 12
7 frame_ptr equ $ff80
9 section "hdr", ROM0[$100]
10 nop
11 jp main
13 rept $150 - $104
14 db 0
15 endr
17 section "text", ROM0
19 main:
20 call init
22 xor a, a
23 ldh [frame_ptr], a
24 .mainloop:
25 ldh a, [REG_LY]
26 cp a, 144
27 jr c, .wait_hsync
29 ; we're in vsync, increment frame counter and wait for the next frame
30 ldh a, [frame_ptr]
31 inc a
32 ldh [frame_ptr], a
33 .wait_newframe:
34 ldh a, [REG_LY]
35 cp a, 0
36 jr nz, .wait_newframe
38 ; scanline code
39 .wait_hsync:
40 ldh a, [REG_STAT]
41 and a, STAT_MODE_MASK
42 jr nz, .wait_hsync
44 ldh a, [frame_ptr]
45 ld d, a
47 xor a, a
48 ld b, a
50 ldh a, [REG_LY]
51 add a, d ; add frame number
52 ld c, a
54 ld hl, sintab
55 add hl, bc ; hl now points to the sine value
57 ld a, [hl]
59 ; add a half-octave sine
60 ld e, a ; save first sine to e
61 sla d
62 ld a, [REG_LY]
63 sla a
64 add a, d
65 ld c, a
66 srl d
68 ld hl, sintab
69 add hl, bc
70 ld a, [hl]
71 sra a
72 add a, e ; add previously saved sine
74 add a, yoffs_center
75 ldh [REG_SCY], a
77 ; do something for SCX too
78 ld a, d
79 sla a
80 ld d, a
82 ldh a, [REG_LY]
83 add a, 32
84 add a, d ; add frame number
85 ld c, a
87 ld hl, sintab
88 add hl, bc
90 ld a, [hl]
91 sra a
92 add a, xoffs_center
93 ldh [REG_SCX], a
95 ; done, wait until we're out of hsync
96 .wait_endhsync:
97 ldh a, [REG_STAT]
98 and a, STAT_MODE_MASK
99 jr z, .wait_endhsync
101 jr .mainloop
104 di
105 .end: halt
106 nop
107 jp .end
109 init:
110 call wait_vsync
111 xor a, a
112 ldh [REG_LCDC], a
114 ; setup palette
115 ld a, $1b
116 ldh [REG_BGP], a
118 ; copy tiles
119 ld hl, $8000
120 ld de, tiles
121 ld bc, tiles_end - tiles
122 .copytiles:
123 ld a, [de]
124 ld [hl+], a
125 inc de
126 dec bc
127 ld a, b
128 or c
129 jp nz, .copytiles
131 ; copy tilemap
132 ld hl, $9800
133 ld de, tilemap
134 ld b, 21
135 .copymap:
136 ld c, 21
137 .copymaprow:
138 ld a, [de]
139 inc de
140 ld [hl+], a
141 dec c
142 jr nz, .copymaprow
144 push bc
145 ld bc, 11
146 add hl, bc
147 pop bc
149 dec b
150 jr nz, .copymap
152 ; center viewport
153 ld a, yoffs_center
154 ldh [REG_SCY], a
155 ld a, xoffs_center
156 ldh [REG_SCX], a
158 ; configure LCD
159 ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON
160 ldh [REG_LCDC], a
161 ret
163 wait_vsync:
164 ldh a, [REG_LY]
165 cp a, 144
166 jr c, wait_vsync
167 ret
169 section "data", ROM0, align[8]
170 sintab:
171 include "sin.inc"
173 tiles:
174 incbin "logo.tiles"
175 tiles_end:
176 tilemap:
177 incbin "logo.tilemap"
178 tilemap_end: