summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-04-17 12:32:25 +0200
committerBad Diode <bd@badd10de.dev>2021-04-17 12:32:25 +0200
commitc9d5551c24b742b9704da409ce349ae93ded802e (patch)
tree03e8f63eeda88aae14b8a0d378f0984188ae1fe5
parentafc0e9d93285b5bd2db808f3c5d735b566c2f8a6 (diff)
downloadgba-experiments-c9d5551c24b742b9704da409ce349ae93ded802e.tar.gz
gba-experiments-c9d5551c24b742b9704da409ce349ae93ded802e.zip
Rename DISP_CONTROL to DISP_CTRL
-rw-r--r--Makefile2
-rw-r--r--src/main.c43
2 files changed, 38 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index fbd5fe3..ae1e158 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ WATCH_SRC := $(wildcard $(SRC_DIR)/*.c)
18WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) 18WATCH_SRC += $(wildcard $(SRC_DIR)/*.h)
19 19
20# Output library names and executables. 20# Output library names and executables.
21TARGET := first 21TARGET := experiments
22BUILD_DIR := build 22BUILD_DIR := build
23ELF := $(BUILD_DIR)/$(TARGET).elf 23ELF := $(BUILD_DIR)/$(TARGET).elf
24BIN := $(BUILD_DIR)/$(TARGET).gba 24BIN := $(BUILD_DIR)/$(TARGET).gba
diff --git a/src/main.c b/src/main.c
index f684530..2a445de 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,12 +21,12 @@
21// 21//
22 22
23// Display registers. 23// Display registers.
24#define DISP_CONTROL *((vu32*)(MEM_IO + 0x0000)) 24#define DISP_CTRL *((vu32*)(MEM_IO + 0x0000))
25#define DISP_STATUS *((vu32*)(MEM_IO + 0x0004)) 25#define DISP_STATUS *((vu32*)(MEM_IO + 0x0004))
26#define DISP_VCOUNT *((vu32*)(MEM_IO + 0x0006)) 26#define DISP_VCOUNT *((vu32*)(MEM_IO + 0x0006))
27 27
28// Bits for display control. 28// Bits for display control.
29#define DISP_CONTROL_PAGE (1 << 4) 29#define DISP_CTRL_PAGE (1 << 4)
30 30
31// Display modes. 31// Display modes.
32#define DISP_MODE_0 0x0000 32#define DISP_MODE_0 0x0000
@@ -255,7 +255,7 @@ draw_fill_rect_m4(int x0, int y0, int x1, int y1, u8 col_index, vu16 *buffer) {
255 255
256static inline void 256static inline void
257flip_page() { 257flip_page() {
258 DISP_CONTROL ^= DISP_CONTROL_PAGE; 258 DISP_CTRL ^= DISP_CTRL_PAGE;
259} 259}
260 260
261#define SCREEN_PAGE_1 ((vu16*) MEM_VRAM) 261#define SCREEN_PAGE_1 ((vu16*) MEM_VRAM)
@@ -352,10 +352,41 @@ key_hold(u32 key) {
352#define KEY_PRESSED(key) (~(KEY_INPUTS) & key) 352#define KEY_PRESSED(key) (~(KEY_INPUTS) & key)
353 353
354int main(void) { 354int main(void) {
355 DISP_CONTROL = DISP_MODE_3 | DISP_BG_2; 355 DISP_CTRL = DISP_MODE_3 | DISP_BG_2;
356 356
357 draw_fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_GREY); 357 draw_fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_GREY);
358 358
359 int side = 60;
360 int line = 35;
361 int height = side * 0.5;
362 int x = SCREEN_WIDTH / 2 - height / 2;
363 int y = SCREEN_HEIGHT / 2;
364
365 // Draw red triangle.
366 draw_line(x + height - 1, y - side / 2, x, y - 1, COLOR_RED);
367 draw_line(x + height - 1, y + side / 2, x, y + 1, COLOR_RED);
368 draw_line(x + height - 1, y - side / 2 + 1, x, y, COLOR_RED);
369 draw_line(x + height - 1, y + side / 2 - 1, x, y, COLOR_RED);
370
371 // Draw white triangle.
372 draw_line(x, y - side / 2, x, y + side / 2, COLOR_WHITE);
373 draw_line(x + 1, y - side / 2, x + height, y - 1, COLOR_WHITE);
374 draw_line(x + 1, y + side / 2, x + height, y + 1, COLOR_WHITE);
375
376 // Draw white line at triangle tip.
377 draw_line(x + height, y - side / 2, x + height, y + side / 2, COLOR_WHITE);
378 draw_line(x + height + 1, y - side / 2, x + height + 1, y + side / 2, COLOR_WHITE);
379
380 // Double triangle line.
381 draw_line(x - 1, y - side / 2, x - 1, y + side / 2, COLOR_WHITE);
382 draw_line(x + 1, y - side / 2 + 1, x + height, y, COLOR_WHITE);
383 draw_line(x + 1, y + side / 2 - 1, x + height, y, COLOR_WHITE);
384
385 // Draw white lines.
386 draw_line(x - line, y, x, y, COLOR_WHITE);
387 draw_line(x + height, y, x + height + line, y, COLOR_WHITE);
388 draw_line(x - line, y + 1, x, y + 1, COLOR_WHITE);
389 draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE);
359 int frame_counter = 0; 390 int frame_counter = 0;
360 bool toggle_key_down = false; 391 bool toggle_key_down = false;
361 while(true) { 392 while(true) {