summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 88f4f4e..fd5d21a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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
41static inline void 42static inline void
42set_display_mode(u16 value) { 43set_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
59static inline void 60static inline void
60put_pixel(int x, int y, Color clr) { 61put_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.
66static inline void
67put_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
77static inline void
78put_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) {
68int main(void) { 90int 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}