summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-21 19:05:59 +0200
committerBad Diode <bd@badd10de.dev>2023-04-21 19:05:59 +0200
commit9db4c23d3c8c7d2cbf6b65ff123a25dc48ae51eb (patch)
tree3cc1916235fdaa463c235cbdb6dae6190dec4abe
parent7ee1424be26f8f35e30b04ea4e078dbe12688487 (diff)
downloadgba-link-cable-tester-9db4c23d3c8c7d2cbf6b65ff123a25dc48ae51eb.tar.gz
gba-link-cable-tester-9db4c23d3c8c7d2cbf6b65ff123a25dc48ae51eb.zip
Add growing rectangle demo
-rw-r--r--src/main.c82
1 files changed, 80 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 2ad4877..dcefc30 100644
--- a/src/main.c
+++ b/src/main.c
@@ -139,6 +139,83 @@ test_all_static(void) {
139} 139}
140 140
141void 141void
142test_growing_rects(void) {
143 typedef struct Rect {
144 int x0;
145 int y0;
146 int x1;
147 int y1;
148 } Rect;
149 Rect rects[] = {
150 {
151 SCREEN_WIDTH / 2 - 60,
152 SCREEN_HEIGHT / 2 - 30,
153 SCREEN_WIDTH / 2 + 60,
154 SCREEN_HEIGHT / 2 + 30,
155 },
156 {
157 SCREEN_WIDTH / 2 - 30,
158 SCREEN_HEIGHT / 2 - 60,
159 SCREEN_WIDTH / 2 + 30,
160 SCREEN_HEIGHT / 2 + 60,
161 },
162 };
163 while (true) {
164 poll_keys();
165 if (key_tap(KEY_A)) {
166 break;
167 }
168 if (key_pressed(KEY_B)) {
169 if (key_pressed(KEY_LEFT)) {
170 rects[0].x0 = CLAMP(rects[0].x0 - 1, 0, SCREEN_WIDTH - 1);
171 rects[0].x1 = CLAMP(rects[0].x1 + 1, 0, SCREEN_WIDTH - 1);
172 } else if (key_pressed(KEY_RIGHT)){
173 rects[0].x0 = CLAMP(rects[0].x0 + 1, 0, SCREEN_WIDTH - 1);
174 rects[0].x1 = CLAMP(rects[0].x1 - 1, 0, SCREEN_WIDTH - 1);
175 } else if (key_pressed(KEY_UP)){
176 rects[0].y0 = CLAMP(rects[0].y0 - 1, 0, SCREEN_HEIGHT - 1);
177 rects[0].y1 = CLAMP(rects[0].y1 + 1, 0, SCREEN_HEIGHT - 1);
178 } else if (key_pressed(KEY_DOWN)){
179 rects[0].y0 = CLAMP(rects[0].y0 + 1, 0, SCREEN_HEIGHT - 1);
180 rects[0].y1 = CLAMP(rects[0].y1 - 1, 0, SCREEN_HEIGHT - 1);
181 }
182 } else {
183 if (key_pressed(KEY_LEFT)) {
184 rects[1].x0 = CLAMP(rects[1].x0 - 1, 0, SCREEN_WIDTH - 1);
185 rects[1].x1 = CLAMP(rects[1].x1 + 1, 0, SCREEN_WIDTH - 1);
186 } else if (key_pressed(KEY_RIGHT)){
187 rects[1].x0 = CLAMP(rects[1].x0 + 1, 0, SCREEN_WIDTH - 1);
188 rects[1].x1 = CLAMP(rects[1].x1 - 1, 0, SCREEN_WIDTH - 1);
189 } else if (key_pressed(KEY_UP)){
190 rects[1].y0 = CLAMP(rects[1].y0 - 1, 0, SCREEN_HEIGHT - 1);
191 rects[1].y1 = CLAMP(rects[1].y1 + 1, 0, SCREEN_HEIGHT - 1);
192 } else if (key_pressed(KEY_DOWN)){
193 rects[1].y0 = CLAMP(rects[1].y0 + 1, 0, SCREEN_HEIGHT - 1);
194 rects[1].y1 = CLAMP(rects[1].y1 - 1, 0, SCREEN_HEIGHT - 1);
195 }
196 }
197 bios_vblank_wait();
198 FRAME_START();
199 PROF(flip_buffer(), flip_cycles);
200 PROF(screen_fill(0), clear_cycles);
201 PROF(draw_filled_rect(
202 rects[0].x0,
203 rects[0].y0,
204 rects[0].x1,
205 rects[0].y1,
206 2), rect_cycles);
207 PROF(draw_rect(
208 rects[1].x0,
209 rects[1].y0,
210 rects[1].x1,
211 rects[1].y1,
212 3), fill_rect_cycles);
213 FRAME_END();
214 PROF_SHOW();
215 }
216}
217
218void
142test_sprites_bounce(void) { 219test_sprites_bounce(void) {
143 u8 sprite_icn[8] = { 220 u8 sprite_icn[8] = {
144 0xf8, 0xf8, 0xf8, 0xf8 | 0x3e, 0xf8 | 0x3e, 0x3e, 0x3e, 0x00, 221 0xf8, 0xf8, 0xf8, 0xf8 | 0x3e, 0xf8 | 0x3e, 0x3e, 0x3e, 0x00,
@@ -226,9 +303,10 @@ int main(void) {
226 irs_set(IRQ_VBLANK, irs_stub); 303 irs_set(IRQ_VBLANK, irs_stub);
227 304
228 // TODO: Test for text rendering. 305 // TODO: Test for text rendering.
229 // TODO: Verify all works well, there were some modifications and 306 // TODO: Add a clear mode for chr that inverts non zero values to become
230 // bugfixes on the ppu of the uxngba branch. 307 // zero, thus clearing the sprite if it was in the same position.
231 while (true) { 308 while (true) {
309 test_growing_rects();
232 test_sprites_bounce(); 310 test_sprites_bounce();
233 test_moving_line(); 311 test_moving_line();
234 test_all_static(); 312 test_all_static();