diff options
-rw-r--r-- | src/main.c | 88 |
1 files changed, 54 insertions, 34 deletions
@@ -302,51 +302,71 @@ u32 profile_stop() { | |||
302 | return (TIMER_DATA_3 << 16) | TIMER_DATA_2; | 302 | return (TIMER_DATA_3 << 16) | TIMER_DATA_2; |
303 | } | 303 | } |
304 | 304 | ||
305 | int main(void) { | 305 | // |
306 | DISP_CONTROL = DISP_MODE_3 | DISP_BG_2; | 306 | // Input handling. |
307 | 307 | // | |
308 | draw_fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_GREY); | ||
309 | |||
310 | int side = 60; | ||
311 | int line = 35; | ||
312 | int height = side * 0.5; | ||
313 | int x = SCREEN_WIDTH / 2 - height / 2; | ||
314 | int y = SCREEN_HEIGHT / 2; | ||
315 | |||
316 | // Draw red triangle. | ||
317 | draw_line(x + height - 1, y - side / 2, x, y - 1, COLOR_RED); | ||
318 | draw_line(x + height - 1, y + side / 2, x, y + 1, COLOR_RED); | ||
319 | draw_line(x + height - 1, y - side / 2 + 1, x, y, COLOR_RED); | ||
320 | draw_line(x + height - 1, y + side / 2 - 1, x, y, COLOR_RED); | ||
321 | 308 | ||
322 | // Draw white triangle. | 309 | // Memory address for key input register |
323 | draw_line(x, y - side / 2, x, y + side / 2, COLOR_WHITE); | 310 | #define KEY_INPUTS *((vu16*) 0x04000130) |
324 | draw_line(x + 1, y - side / 2, x + height, y - 1, COLOR_WHITE); | ||
325 | draw_line(x + 1, y + side / 2, x + height, y + 1, COLOR_WHITE); | ||
326 | 311 | ||
327 | // Draw white line at triangle tip. | 312 | // Alias for key pressing bits. |
328 | draw_line(x + height, y - side / 2, x + height, y + side / 2, COLOR_WHITE); | 313 | #define KEY_A (1 << 0) |
329 | draw_line(x + height + 1, y - side / 2, x + height + 1, y + side / 2, COLOR_WHITE); | 314 | #define KEY_B (1 << 1) |
315 | #define KEY_SELECT (1 << 2) | ||
316 | #define KEY_START (1 << 3) | ||
317 | #define KEY_RIGHT (1 << 4) | ||
318 | #define KEY_LEFT (1 << 5) | ||
319 | #define KEY_UP (1 << 6) | ||
320 | #define KEY_DOWN (1 << 7) | ||
321 | #define KEY_R (1 << 8) | ||
322 | #define KEY_L (1 << 9) | ||
330 | 323 | ||
331 | // Double triangle line. | 324 | // Check if the given key/button is currently pressed. |
332 | draw_line(x - 1, y - side / 2, x - 1, y + side / 2, COLOR_WHITE); | 325 | #define KEY_PRESSED(key) (~(KEY_INPUTS) & key) |
333 | draw_line(x + 1, y - side / 2 + 1, x + height, y, COLOR_WHITE); | ||
334 | draw_line(x + 1, y + side / 2 - 1, x + height, y, COLOR_WHITE); | ||
335 | 326 | ||
336 | // Draw white lines. | 327 | int main(void) { |
337 | draw_line(x - line, y, x, y, COLOR_WHITE); | 328 | DISP_CONTROL = DISP_MODE_3 | DISP_BG_2; |
338 | draw_line(x + height, y, x + height + line, y, COLOR_WHITE); | ||
339 | draw_line(x - line, y + 1, x, y + 1, COLOR_WHITE); | ||
340 | draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE); | ||
341 | 329 | ||
342 | put_text(SCREEN_WIDTH / 2 - 8 * 10 / 2, 125, COLOR_RED, "0xbadd10de"); | 330 | draw_fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_GREY); |
343 | 331 | ||
344 | int frame_counter = 0; | 332 | int frame_counter = 0; |
345 | while(true) { | 333 | while(true) { |
346 | wait_vsync(); | 334 | wait_vsync(); |
347 | if (frame_counter++ > 30) { | 335 | if (frame_counter++ > 30) { |
348 | frame_counter = 0; | 336 | frame_counter = 0; |
349 | flip_page(); | 337 | } |
338 | |||
339 | if (KEY_PRESSED(KEY_DOWN)) { | ||
340 | put_text(8, 8, COLOR_RED, "down"); | ||
341 | } | ||
342 | else if (KEY_PRESSED(KEY_UP)) { | ||
343 | put_text(8, 8, COLOR_RED, "up"); | ||
344 | } | ||
345 | else if (KEY_PRESSED(KEY_LEFT)) { | ||
346 | put_text(8, 8, COLOR_RED, "left"); | ||
347 | } | ||
348 | else if (KEY_PRESSED(KEY_RIGHT)) { | ||
349 | put_text(8, 8, COLOR_RED, "right"); | ||
350 | } | ||
351 | else if (KEY_PRESSED(KEY_A)) { | ||
352 | put_text(8, 8, COLOR_RED, "A"); | ||
353 | } | ||
354 | else if (KEY_PRESSED(KEY_B)) { | ||
355 | put_text(8, 8, COLOR_RED, "B"); | ||
356 | } | ||
357 | else if (KEY_PRESSED(KEY_START)) { | ||
358 | put_text(8, 8, COLOR_RED, "start"); | ||
359 | } | ||
360 | else if (KEY_PRESSED(KEY_SELECT)) { | ||
361 | put_text(8, 8, COLOR_RED, "select"); | ||
362 | } | ||
363 | else if (KEY_PRESSED(KEY_L)) { | ||
364 | put_text(8, 8, COLOR_RED, "L"); | ||
365 | } | ||
366 | else if (KEY_PRESSED(KEY_R)) { | ||
367 | put_text(8, 8, COLOR_RED, "R"); | ||
368 | } else { | ||
369 | draw_fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_GREY); | ||
350 | } | 370 | } |
351 | }; | 371 | }; |
352 | 372 | ||