gb_test2

view test.asm @ 1:d63782badb6b

nicer distortion
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 10 Jan 2019 04:47:42 +0200
parents cacfa0888410
children a8b7297e7e2c
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 identity palette
115 ld a, $1b
116 ldh [REG_BGP], a
119 ; copy tiles
120 ld hl, $8000
121 ld de, tiles
122 ld bc, tiles_end - tiles
123 .copytiles:
124 ld a, [de]
125 ld [hl+], a
126 inc de
127 dec bc
128 ld a, b
129 or c
130 jp nz, .copytiles
132 ; copy tilemap
133 ld hl, $9800
134 ld de, tilemap
135 ld b, 21
136 .copymap:
137 ld c, 21
138 .copymaprow:
139 ld a, [de]
140 inc de
141 ld [hl+], a
142 dec c
143 jr nz, .copymaprow
145 push bc
146 ld bc, 11
147 add hl, bc
148 pop bc
150 dec b
151 jr nz, .copymap
153 ; center viewport
154 ld a, yoffs_center
155 ldh [REG_SCY], a
156 ld a, xoffs_center
157 ldh [REG_SCX], a
159 ; configure LCD
160 ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON
161 ldh [REG_LCDC], a
162 ret
164 wait_vsync:
165 ldh a, [REG_LY]
166 cp a, 144
167 jr c, wait_vsync
168 ret
170 section "data", ROM0, align[8]
171 sintab:
172 include "sin.inc"
174 tiles:
175 incbin "logo.tiles"
176 tiles_end:
177 tilemap:
178 incbin "logo.tilemap"
179 tilemap_end: