From c9d5551c24b742b9704da409ce349ae93ded802e Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sat, 17 Apr 2021 12:32:25 +0200 Subject: Rename DISP_CONTROL to DISP_CTRL --- Makefile | 2 +- src/main.c | 43 +++++++++++++++++++++++++++++++++++++------ 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) WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) # Output library names and executables. -TARGET := first +TARGET := experiments BUILD_DIR := build ELF := $(BUILD_DIR)/$(TARGET).elf BIN := $(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 @@ // // Display registers. -#define DISP_CONTROL *((vu32*)(MEM_IO + 0x0000)) -#define DISP_STATUS *((vu32*)(MEM_IO + 0x0004)) -#define DISP_VCOUNT *((vu32*)(MEM_IO + 0x0006)) +#define DISP_CTRL *((vu32*)(MEM_IO + 0x0000)) +#define DISP_STATUS *((vu32*)(MEM_IO + 0x0004)) +#define DISP_VCOUNT *((vu32*)(MEM_IO + 0x0006)) // Bits for display control. -#define DISP_CONTROL_PAGE (1 << 4) +#define DISP_CTRL_PAGE (1 << 4) // Display modes. #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) { static inline void flip_page() { - DISP_CONTROL ^= DISP_CONTROL_PAGE; + DISP_CTRL ^= DISP_CTRL_PAGE; } #define SCREEN_PAGE_1 ((vu16*) MEM_VRAM) @@ -352,10 +352,41 @@ key_hold(u32 key) { #define KEY_PRESSED(key) (~(KEY_INPUTS) & key) int main(void) { - DISP_CONTROL = DISP_MODE_3 | DISP_BG_2; + DISP_CTRL = DISP_MODE_3 | DISP_BG_2; draw_fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_GREY); + int side = 60; + int line = 35; + int height = side * 0.5; + int x = SCREEN_WIDTH / 2 - height / 2; + int y = SCREEN_HEIGHT / 2; + + // Draw red triangle. + draw_line(x + height - 1, y - side / 2, x, y - 1, COLOR_RED); + draw_line(x + height - 1, y + side / 2, x, y + 1, COLOR_RED); + draw_line(x + height - 1, y - side / 2 + 1, x, y, COLOR_RED); + draw_line(x + height - 1, y + side / 2 - 1, x, y, COLOR_RED); + + // Draw white triangle. + draw_line(x, y - side / 2, x, y + side / 2, COLOR_WHITE); + draw_line(x + 1, y - side / 2, x + height, y - 1, COLOR_WHITE); + draw_line(x + 1, y + side / 2, x + height, y + 1, COLOR_WHITE); + + // Draw white line at triangle tip. + draw_line(x + height, y - side / 2, x + height, y + side / 2, COLOR_WHITE); + draw_line(x + height + 1, y - side / 2, x + height + 1, y + side / 2, COLOR_WHITE); + + // Double triangle line. + draw_line(x - 1, y - side / 2, x - 1, y + side / 2, COLOR_WHITE); + draw_line(x + 1, y - side / 2 + 1, x + height, y, COLOR_WHITE); + draw_line(x + 1, y + side / 2 - 1, x + height, y, COLOR_WHITE); + + // Draw white lines. + draw_line(x - line, y, x, y, COLOR_WHITE); + draw_line(x + height, y, x + height + line, y, COLOR_WHITE); + draw_line(x - line, y + 1, x, y + 1, COLOR_WHITE); + draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE); int frame_counter = 0; bool toggle_key_down = false; while(true) { -- cgit v1.2.1