summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-18 14:28:22 +0200
committerBad Diode <bd@badd10de.dev>2023-04-18 14:28:22 +0200
commitbd523af5fb49ec78073a35ce63d53ba5c32064d0 (patch)
treed95b53f663767177184878c6eeac20225bdda76d
parent04af30b7fcb1abc2702f6b01ccf7f9d9ead86af1 (diff)
downloadgba-link-cable-tester-bd523af5fb49ec78073a35ce63d53ba5c32064d0.tar.gz
gba-link-cable-tester-bd523af5fb49ec78073a35ce63d53ba5c32064d0.zip
Cleanup compile parameters and prepare moving line demo
-rw-r--r--src/main.c107
-rw-r--r--src/renderer_m0.c65
-rw-r--r--src/renderer_m4.c73
3 files changed, 74 insertions, 171 deletions
diff --git a/src/main.c b/src/main.c
index 88ca24e..993ca37 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,7 +11,7 @@ WITH REGARD TO THIS SOFTWARE.
11 11
12#include "gba/gba.h" 12#include "gba/gba.h"
13 13
14#include "renderer_m4.c" 14#include "renderer_m0.c"
15 15
16// 16//
17// Config parameters. 17// Config parameters.
@@ -109,27 +109,14 @@ test_lines(void) {
109 } 109 }
110} 110}
111 111
112int main(void) { 112void
113 // Adjust system wait times. 113test_moving_line(void) {
114 SYSTEM_WAIT = SYSTEM_WAIT_CARTRIDGE;
115
116 // Initialize renderer.
117 renderer_init();
118
119 // Register interrupts.
120 irq_init();
121 irs_set(IRQ_VBLANK, irs_stub);
122
123 // Main loop.
124 PROF_INIT();
125 int x = 0; 114 int x = 0;
126 int y = 0; 115 int y = 0;
127 int inc_x = 1; 116 int inc_x = 1;
128 int inc_y = 0; 117 int inc_y = 0;
129 while (true) { 118 while (true) {
130 bios_vblank_wait(); 119 screen_fill(0);
131
132 PROF(test_clear(), test_clear_cycles);
133 draw_line(x, y, 239 - x, 159 - y, 2); 120 draw_line(x, y, 239 - x, 159 - y, 2);
134 x += inc_x; 121 x += inc_x;
135 y += inc_y; 122 y += inc_y;
@@ -143,68 +130,34 @@ int main(void) {
143 inc_x = 1; 130 inc_x = 1;
144 inc_y = 0; 131 inc_y = 0;
145 } 132 }
133 bios_vblank_wait();
134 flip_buffer();
135 }
136}
137
138int main(void) {
139 // Adjust system wait times.
140 SYSTEM_WAIT = SYSTEM_WAIT_CARTRIDGE;
141
142 // Initialize renderer.
143 renderer_init();
146 144
147 // draw_line(x, 229 - x, y, 129 - y, 2); 145 // Register interrupts.
148 // screen_fill(0); 146 irq_init();
149 // draw_pixel(0, 100 + 0, 5); 147 irs_set(IRQ_VBLANK, irs_stub);
150 // draw_pixel(1, 100 + 0, 6); 148
151 // draw_pixel(2, 100 + 0, 5); 149 // Main loop.
152 // draw_pixel(3, 100 + 0, 6); 150 PROF_INIT();
153 // draw_pixel(4, 100 + 0, 5); 151 while (true) {
154 // draw_pixel(5, 100 + 0, 6); 152 PROF(test_clear(), test_clear_cycles);
155 // draw_pixel(6, 100 + 0, 5); 153 PROF(test_lines(), test_lines_cycles);
156 // draw_pixel(7, 100 + 0, 6); 154 PROF(test_rect(), test_rect_cycles);
157 // draw_pixel(8, 100 + 0, 5); 155 PROF(test_fill_rect(), test_fill_rect_cycles);
158 // draw_pixel(9, 100 + 0, 6); 156 PROF(test_chr(), test_chr_cycles);
159 // draw_pixel(10, 100 + 0, 5); 157 PROF(test_icn(), test_icn_cycles);
160 // draw_pixel(11, 100 + 0, 6); 158 draw_filled_rect(0, 0, 140, 60, 0);
161 // draw_pixel(12, 100 + 0, 5);
162 // draw_pixel(13, 100 + 0, 6);
163 // draw_pixel(14, 100 + 0, 5);
164 // draw_pixel(15, 100 + 0, 6);
165
166 // draw_hline(0, 10 + 4, 100 + 1, 2);
167 // draw_hline(0, 10 + 5, 100 + 2, 2);
168 // draw_hline(1, 10 + 4, 100 + 3, 5);
169 // draw_hline(1, 10 + 5, 100 + 4, 5);
170
171 // DX is bigger
172 // left -> right && top -> bot
173 // PROF(draw_line(0, 0, 64, 32, 1), test_lines_cycles);
174 // PROF(draw_line(0, 0, 239, 159, 1), test_lines_cycles);
175 ////// draw_line(10, 0, 229, 159, 1);
176 ////// left -> right && bot -> top
177 // draw_line(0, 159, 239, 0, 2);
178 ////// draw_line(10, 159, 229, 0, 2);
179 //////
180 ////draw_line(0, 0, 239, 159, 1);
181 ////draw_line(0, 129, 239, 40, 2);
182 ////// right -> left && top -> bot
183 //draw_line(239, 81, 0, 129, 3);
184 ////// right -> left && bot -> top
185 //draw_line(239, 129, 0, 40, 5);
186 // txt_render();
187 // txt_clear();
188
189 // draw_line(239, 149, 0, 10, 3);
190
191 // draw_line(0, 159, 239, 0, 2);
192 // draw_line(0, 0, 100, 50, 2);
193 // draw_line(0, 0, 100, 21, 5);
194 // draw_line(0, 0, 15, 7, 2);
195 // draw_line(0, 31, 100, 0, 5);
196 // draw_line(0, 159, 19, 0, 5);
197 // draw_line(0, 159, 19, 0, 5);
198 // draw_line(0, 0, 19, 159, 6);
199 // txt_render();
200 // txt_clear();
201 // PROF(test_lines(), test_lines_cycles);
202 // PROF(test_rect(), test_rect_cycles);
203 // PROF(test_fill_rect(), test_fill_rect_cycles);
204 // PROF(test_chr(), test_chr_cycles);
205 // PROF(test_icn(), test_icn_cycles);
206 // draw_filled_rect(0, 0, 140, 60, 0);
207 PROF_SHOW(); 159 PROF_SHOW();
160 bios_vblank_wait();
208 PROF(flip_buffer(), flip_cycles); 161 PROF(flip_buffer(), flip_cycles);
209 } 162 }
210 163
diff --git a/src/renderer_m0.c b/src/renderer_m0.c
index c9aa7ae..35e9ceb 100644
--- a/src/renderer_m0.c
+++ b/src/renderer_m0.c
@@ -8,6 +8,13 @@
8#include "renderer.h" 8#include "renderer.h"
9#include "text.h" 9#include "text.h"
10 10
11//
12// Parameters.
13//
14
15#define SUBPIXEL_LINES 0
16#define DEC_BIG_LUT 1
17
11// Front/back buffers for double buffering. 18// Front/back buffers for double buffering.
12#define BUF_0 ((u32*)(MEM_VRAM)) 19#define BUF_0 ((u32*)(MEM_VRAM))
13#define BUF_1 ((u32*)(MEM_VRAM + KB(20))) 20#define BUF_1 ((u32*)(MEM_VRAM + KB(20)))
@@ -179,33 +186,7 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
179 SWAP(y0, y1); 186 SWAP(y0, y1);
180 } 187 }
181 188
182#if 0 189#if SUBPIXEL_LINES == 1
183 int x_step = x0 > x1 ? -1 : 1;
184 int y_step = y0 > y1 ? -1 : 1;
185 if (dx >= dy) {
186 int diff = 2 * dy - dx;
187 for (int i = 0; i < dx + 1; i++) {
188 draw_pixel(x0, y0, clr);
189 if (diff >= 0) {
190 diff -= 2 * dx;
191 y0 += y_step;
192 }
193 diff += 2 * dy;
194 x0 += x_step;
195 }
196 } else {
197 int diff = 2 * dx - dy;
198 for (int i = 0; i < dy + 1; i++) {
199 draw_pixel(x0, y0, clr);
200 if (diff >= 0) {
201 diff -= 2 * dy;
202 x0 += x_step;
203 }
204 diff += 2 * dx;
205 y0 += y_step;
206 }
207 }
208#else
209 int dxf = (dx << fp_bit); 190 int dxf = (dx << fp_bit);
210 int dyf = (dy << fp_bit); 191 int dyf = (dy << fp_bit);
211 int frac_x = x0 > x1 ? FP_NUM(x0 - x1, fp_bit) : FP_NUM(x1 - x0, fp_bit); 192 int frac_x = x0 > x1 ? FP_NUM(x0 - x1, fp_bit) : FP_NUM(x1 - x0, fp_bit);
@@ -259,6 +240,32 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
259 draw_vline(x0, y0, y0 + remaining, clr); 240 draw_vline(x0, y0, y0 + remaining, clr);
260 } 241 }
261 } 242 }
243#else
244 int x_step = x0 > x1 ? -1 : 1;
245 int y_step = y0 > y1 ? -1 : 1;
246 if (dx >= dy) {
247 int diff = 2 * dy - dx;
248 for (int i = 0; i < dx + 1; i++) {
249 draw_pixel(x0, y0, clr);
250 if (diff >= 0) {
251 diff -= 2 * dx;
252 y0 += y_step;
253 }
254 diff += 2 * dy;
255 x0 += x_step;
256 }
257 } else {
258 int diff = 2 * dx - dy;
259 for (int i = 0; i < dy + 1; i++) {
260 draw_pixel(x0, y0, clr);
261 if (diff >= 0) {
262 diff -= 2 * dy;
263 x0 += x_step;
264 }
265 diff += 2 * dx;
266 y0 += y_step;
267 }
268 }
262#endif 269#endif
263 } 270 }
264} 271}
@@ -302,9 +309,7 @@ draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
302// Sprites (chr/icn). 309// Sprites (chr/icn).
303// 310//
304 311
305#define DEC_BIG_LUT 1 312#if DEC_BIG_LUT == 1
306
307#if DEC_BIG_LUT
308static u32 dec_byte_flip_x[256] = { 313static u32 dec_byte_flip_x[256] = {
309 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, 314 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100,
310 0x00000101, 0x00000110, 0x00000111, 0x00001000, 0x00001001, 315 0x00000101, 0x00000110, 0x00000111, 0x00001000, 0x00001001,
diff --git a/src/renderer_m4.c b/src/renderer_m4.c
index de052df..2a5e9fe 100644
--- a/src/renderer_m4.c
+++ b/src/renderer_m4.c
@@ -1,6 +1,13 @@
1#include "renderer.h" 1#include "renderer.h"
2#include "text.h" 2#include "text.h"
3 3
4//
5// Parameters.
6//
7
8#define SUBPIXEL_LINES 0
9#define DEC_BIG_LUT 1
10
4// Front/back buffers for double buffering. 11// Front/back buffers for double buffering.
5#define BUF_0 ((u32*)(MEM_VRAM)) 12#define BUF_0 ((u32*)(MEM_VRAM))
6#define BUF_1 ((u32*)(MEM_VRAM ^ 0x0A000)) 13#define BUF_1 ((u32*)(MEM_VRAM ^ 0x0A000))
@@ -118,7 +125,7 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
118 MAYBE_SWAP(y0, y1); 125 MAYBE_SWAP(y0, y1);
119 draw_vline(x0, y0, y1, clr); 126 draw_vline(x0, y0, y1, clr);
120 } else { 127 } else {
121#if 1 128#if SUBPIXEL_LINES == 1
122 // Fixed Precision constants. 129 // Fixed Precision constants.
123 const int fp_bit = 6; 130 const int fp_bit = 6;
124 const int fp_one = FP_NUM(1, fp_bit); 131 const int fp_one = FP_NUM(1, fp_bit);
@@ -144,66 +151,6 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
144 u32 mask = x0 & 1 ? ~0xFF : 0xFF; 151 u32 mask = x0 & 1 ? ~0xFF : 0xFF;
145 u32 color = (clr & 0xFF) | ((clr & 0xFF) << 8); 152 u32 color = (clr & 0xFF) | ((clr & 0xFF) << 8);
146 if (dx >= dy) { 153 if (dx >= dy) {
147 // u64 *dst = ((u64*)addr);
148 // int step = dxf / dyf;
149 // int remaining = dx;
150 // int y_step = y0 > y1 ? -1 : 1;
151 // y_step /= 8;
152 // while (remaining > (step - 1)) {
153 // distance += step * 2 * dyf;
154 // size_t a = x0;
155 // size_t b;
156 // if (distance >= 0) {
157 // b = a + step - 1;
158 // x0 += step;
159 // remaining -= step;
160 // } else {
161 // if (remaining < step) {
162 // break;
163 // }
164 // b = a + step;
165 // distance += 2 * dyf;
166 // x0 += (step + 1);
167 // remaining -= step + 1;
168 // }
169 // draw_hline(a, b, y0, 8); // DEBUG: reference
170
171 // // size_t tile_x0 = a / 8;
172 // // size_t tile_x1 = b / 8;
173 // // size_t start_col = a % 8;
174 // // size_t end_col = b % 8;
175 // // size_t dtx = tile_x1 - tile_x0;
176 // // size_t shift_left = start_col * 8;
177 // // size_t shift_right = (7 - end_col) * 8;
178 // // // size_t dtx = b/8 - a/8;
179 // // u64 mask = 0xFFFFFFFFFFFFFFFF;
180 // // u64 row = 0x0101010101010101 * clr;
181 // // if (dtx < 1) {
182 // // mask = (mask >> shift_right) & (mask << shift_left);
183 // // *dst = (*dst & ~mask) | (row & mask);
184 // // } else {
185 // // *dst = (*dst & ~(mask << shift_left)) | row << shift_left;
186 // // if (dtx != 1) {
187 // // dma_fill(&dst[1], 0x01010101 * clr, (dtx - 1) * 8, 3);
188 // // }
189 // // dst += dtx;
190 // // *dst = (*dst & ~(mask >> shift_right)) | row >> shift_right;
191 // // }
192 // // if (end_col == 7) {
193 // // dst++;
194 // // }
195
196 // dst += y_step;
197 // distance -= 2 * dxf;
198 // }
199 // if (remaining >= 0) {
200 // draw_hline(x0, x0 + remaining, y0, clr);
201 // }
202 // Subpixel accurate version.
203 // int distance = (frac_y - fp_half) * dx - (frac_x - fp_half) * dy;
204 // int distance = ( dx * ( frac_y - fp_half ) ) - ( dy * ( frac_x - fp_half ) );
205 // distance -= ( dx << ( fp_bit - 1 ) );
206 //
207 int distance = (frac_y - fp_one) * dx - (frac_x - fp_half) * dy; 154 int distance = (frac_y - fp_one) * dx - (frac_x - fp_half) * dy;
208 int remaining = dx; 155 int remaining = dx;
209 while (distance <= 0 && remaining > 0) { 156 while (distance <= 0 && remaining > 0) {
@@ -337,9 +284,7 @@ draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
337// Sprites (chr/icn). 284// Sprites (chr/icn).
338// 285//
339 286
340#define DEC_BIG_LUT 1 287#if DEC_BIG_LUT == 1
341
342#if DEC_BIG_LUT
343 288
344static u64 dec_byte_flip_x[256] = { 289static u64 dec_byte_flip_x[256] = {
345 0x0000000000000000, 0x0000000000000001, 0x0000000000000100, 0x0000000000000101, 0x0000000000010000, 290 0x0000000000000000, 0x0000000000000001, 0x0000000000000100, 0x0000000000000101, 0x0000000000010000,