diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 35 |
1 files changed, 29 insertions, 6 deletions
@@ -1,4 +1,5 @@ | |||
1 | #include "shorthand.h" | 1 | #include "shorthand.h" |
2 | #include "bd-font.c" | ||
2 | 3 | ||
3 | // | 4 | // |
4 | // Memory sections. | 5 | // Memory sections. |
@@ -40,7 +41,7 @@ | |||
40 | 41 | ||
41 | static inline void | 42 | static inline void |
42 | set_display_mode(u16 value) { | 43 | set_display_mode(u16 value) { |
43 | *((volatile u32*)(MEM_IO + 0x0000)) = value; | 44 | *((vu32*)(MEM_IO + 0x0000)) = value; |
44 | } | 45 | } |
45 | 46 | ||
46 | // | 47 | // |
@@ -58,7 +59,28 @@ rgb15(u32 red, u32 green, u32 blue ) { | |||
58 | 59 | ||
59 | static inline void | 60 | static inline void |
60 | put_pixel(int x, int y, Color clr) { | 61 | put_pixel(int x, int y, Color clr) { |
61 | ((volatile u16*)MEM_VRAM)[x + y * SCREEN_WIDTH] = clr; | 62 | ((vu16*)MEM_VRAM)[x + y * SCREEN_WIDTH] = clr; |
63 | } | ||
64 | |||
65 | // Using bd-font, an 8x8 bitmap font. | ||
66 | static inline void | ||
67 | put_char(int x, int y, Color clr, u8 chr) { | ||
68 | for (size_t i = 0; i < 8; ++i) { | ||
69 | for (size_t j = 0; j < 8; ++j) { | ||
70 | if ((font[chr][i] >> (7 - j)) & 0x1) { | ||
71 | put_pixel(x + j, y + i, clr); | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | static inline void | ||
78 | put_line(int x, int y, Color clr, char *msg) { | ||
79 | int count = 0; | ||
80 | while (*msg) { | ||
81 | put_char(x + count, y, clr, *msg++); | ||
82 | count += 8; | ||
83 | } | ||
62 | } | 84 | } |
63 | 85 | ||
64 | // | 86 | // |
@@ -68,11 +90,12 @@ put_pixel(int x, int y, Color clr) { | |||
68 | int main(void) { | 90 | int main(void) { |
69 | set_display_mode(DISP_MODE_3 | DISP_BG2); | 91 | set_display_mode(DISP_MODE_3 | DISP_BG2); |
70 | 92 | ||
71 | put_pixel(120 , 80, rgb15(31, 0, 0)); | ||
72 | put_pixel(136 , 80, rgb15(0, 31, 0)); | ||
73 | put_pixel(120 , 96, rgb15(0, 0, 31)); | ||
74 | 93 | ||
75 | while(true); | 94 | while(true) { |
95 | put_line(16, 20 + 16, rgb15(28, 0, 0), "Hello world from the GBA!"); | ||
96 | put_line(16, 20 + 32, rgb15(0, 28, 28), "Using my little 8x8 bd-font"); | ||
97 | put_line(16, 20 + 64, rgb15(16, 0, 28), "Isn't that neat? :D"); | ||
98 | }; | ||
76 | 99 | ||
77 | return 0; | 100 | return 0; |
78 | } | 101 | } |