#include "shorthand.h" #include "bd-font.c" // // Memory sections. // // Defines for the different memory sections in the GBA. #define MEM_SROM 0x00000000 #define MEM_EW 0x02000000 #define MEM_IW 0x03000000 #define MEM_IO 0x04000000 #define MEM_PAL 0x05000000 #define MEM_VRAM 0x06000000 #define MEM_OAM 0x07000000 #define MEM_PAK 0x08000000 #define MEM_CART 0x0E000000 // // Display modes. // // Display modes. #define DISP_MODE_0 0x0000 #define DISP_MODE_1 0x0001 #define DISP_MODE_2 0x0002 #define DISP_MODE_3 0x0003 #define DISP_MODE_4 0x0004 #define DISP_MODE_5 0x0005 // Layers. #define DISP_BG0 0x0100 #define DISP_BG1 0x0200 #define DISP_BG2 0x0400 #define DISP_BG3 0x0800 #define DISP_OBJ 0x1000 static inline void set_display_mode(u16 value) { *((vu32*)(MEM_IO + 0x0000)) = value; } // Screen settings. #define SCREEN_WIDTH 240 #define SCREEN_HEIGHT 160 // The GBA in mode 3 expects rbg15 colors in the VRAM, where each component // (RGB) have a 0--31 range. For example, pure red would be rgb15(31, 0, 0). typedef u16 Color; // We can treat the screen as a HxW matrix. With the following macro we can // write a pixel to the screen at the (x, y) position using: // // FRAMEBUFFER[y][x] = color; // typedef Color Scanline[SCREEN_WIDTH]; #define FRAMEBUFFER ((Scanline*)MEM_VRAM) // // Colors. // static inline Color rgb15(u32 red, u32 green, u32 blue ) { return (blue << 10) | (green << 5) | red; } // Using bd-font, an 8x8 bitmap font. static inline void put_char(int x, int y, Color clr, u8 chr) { for (size_t i = 0; i < 8; ++i) { for (size_t j = 0; j < 8; ++j) { if ((font[chr][i] >> (7 - j)) & 0x1) { FRAMEBUFFER[y + i][x + j] = clr; } } } } static inline void put_line(int x, int y, Color clr, char *msg) { int count = 0; while (*msg) { put_char(x + count, y, clr, *msg++); count += 8; } } // // Main functions. // int main(void) { set_display_mode(DISP_MODE_3 | DISP_BG2); while(true) { put_line(16, 20 + 16, rgb15(28, 0, 0), "Hello world from the GBA!"); put_line(16, 20 + 32, rgb15(0, 28, 28), "Using my little 8x8 bd-font"); put_line(16, 20 + 64, rgb15(16, 0, 28), "Isn't that neat? :D"); }; return 0; }