summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-04 10:53:24 +0200
committerBad Diode <bd@badd10de.dev>2021-06-04 10:53:24 +0200
commitaedaa7ade0ed623d09b18a34023f2e02201e67e6 (patch)
tree98af99d9c83c00ba8b1bff64c1cf59380a0df3e4
parent0578a6db65f81f868c527aadfb57a89875d09d94 (diff)
downloadgba-sequencer-aedaa7ade0ed623d09b18a34023f2e02201e67e6.tar.gz
gba-sequencer-aedaa7ade0ed623d09b18a34023f2e02201e67e6.zip
Add slow rect drawing primitive to renderer
-rw-r--r--src/main.c4
-rw-r--r--src/renderer.c26
2 files changed, 29 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 61547c8..ab41915 100644
--- a/src/main.c
+++ b/src/main.c
@@ -64,12 +64,14 @@ int main(void) {
64 irq_init(); 64 irq_init();
65 irs_set(IRQ_VBLANK, irs_stub); 65 irs_set(IRQ_VBLANK, irs_stub);
66 66
67 txt_drawf("Hello world: %d", 4, 4, 6, 10);
68 67
69 // Main loop. 68 // Main loop.
70 PROF_INIT(); 69 PROF_INIT();
71 while (true) { 70 while (true) {
72 bios_vblank_wait(); 71 bios_vblank_wait();
72 txt_drawf("Hello world: %d", 4, 4, 6, 10);
73 draw_rect(30, 30, 45, 45, 1);
74 draw_rect(35, 35, 60, 40, 2);
73 PROF_SHOW(); 75 PROF_SHOW();
74 PROF(flip_buffer(), flip_cycles); 76 PROF(flip_buffer(), flip_cycles);
75 } 77 }
diff --git a/src/renderer.c b/src/renderer.c
index 076d698..4aa583d 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -46,6 +46,32 @@ draw_pixel(u16 x, u16 y, u8 color) {
46 46
47IWRAM_CODE 47IWRAM_CODE
48void 48void
49draw_rect(int x0, int y0, int x1, int y1, u8 clr) {
50 if (x0 > x1) {
51 int tmp = x0;
52 x0 = x1;
53 x1 = tmp;
54 }
55 if (y0 > y1) {
56 int tmp = y0;
57 y0 = y1;
58 y1 = tmp;
59 }
60 int dx = x1 - x0;
61 int dy = y1 - y0;
62 // TODO: SLOW should be vectorized.
63 for (int i = 0; i <= dx; ++i) {
64 draw_pixel(x0 + i, y0, clr);
65 draw_pixel(x0 + i, y1, clr);
66 }
67 for (int i = 0; i <= dy; ++i) {
68 draw_pixel(x0, y0 + i, clr);
69 draw_pixel(x1, y0 + i, clr);
70 }
71}
72
73IWRAM_CODE
74void
49draw_tile(u16 x, u16 y, Tile *tile, bool merge) { 75draw_tile(u16 x, u16 y, Tile *tile, bool merge) {
50 BOUNDCHECK_SCREEN(x, y); 76 BOUNDCHECK_SCREEN(x, y);
51 77