diff options
author | Bad Diode <bd@badd10de.dev> | 2021-04-15 18:18:05 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-04-15 18:18:05 +0200 |
commit | 05f557f302ce566247c37619b130ebebae2a39c8 (patch) | |
tree | 9b80f8a183db8e481f0e4ae8b9e8dc2e98673d97 | |
parent | 3782189c5d9e2e71d3c92fb86830b10d488539f5 (diff) | |
download | gba-experiments-05f557f302ce566247c37619b130ebebae2a39c8.tar.gz gba-experiments-05f557f302ce566247c37619b130ebebae2a39c8.zip |
Add tests for page flipping on mode 4
-rw-r--r-- | src/main.c | 37 |
1 files changed, 26 insertions, 11 deletions
@@ -25,6 +25,9 @@ | |||
25 | #define DISP_STATUS *((vu32*)(MEM_IO + 0x0004)) | 25 | #define DISP_STATUS *((vu32*)(MEM_IO + 0x0004)) |
26 | #define DISP_VCOUNT *((vu32*)(MEM_IO + 0x0006)) | 26 | #define DISP_VCOUNT *((vu32*)(MEM_IO + 0x0006)) |
27 | 27 | ||
28 | // Bits for display control. | ||
29 | #define DISP_CONTROL_PAGE (1 << 4) | ||
30 | |||
28 | // Display modes. | 31 | // Display modes. |
29 | #define DISP_MODE_0 0x0000 | 32 | #define DISP_MODE_0 0x0000 |
30 | #define DISP_MODE_1 0x0001 | 33 | #define DISP_MODE_1 0x0001 |
@@ -40,11 +43,6 @@ | |||
40 | #define DISP_BG3 0x0800 | 43 | #define DISP_BG3 0x0800 |
41 | #define DISP_OBJ 0x1000 | 44 | #define DISP_OBJ 0x1000 |
42 | 45 | ||
43 | static inline void | ||
44 | set_display_mode(u16 value) { | ||
45 | *((vu32*)(MEM_IO + 0x0000)) = value; | ||
46 | } | ||
47 | |||
48 | // Screen settings. | 46 | // Screen settings. |
49 | #define SCREEN_WIDTH 240 | 47 | #define SCREEN_WIDTH 240 |
50 | #define SCREEN_HEIGHT 160 | 48 | #define SCREEN_HEIGHT 160 |
@@ -236,9 +234,9 @@ wait_vsync() { | |||
236 | // memory, instead we need to read a u16 word, mask and or the corresponding | 234 | // memory, instead we need to read a u16 word, mask and or the corresponding |
237 | // bits and wave the updated u16. | 235 | // bits and wave the updated u16. |
238 | static inline void | 236 | static inline void |
239 | put_pixel_m4(int x, int y, u8 col_index) { | 237 | put_pixel_m4(int x, int y, u8 col_index, u16 *buffer) { |
240 | int buffer_index = (y * SCREEN_WIDTH + x) / 2; | 238 | int buffer_index = (y * SCREEN_WIDTH + x) / 2; |
241 | u16 *destination = &SCREEN_BUFFER[buffer_index]; | 239 | u16 *destination = &buffer[buffer_index]; |
242 | // Odd pixels will go to the top 8 bits of the destination. Even pixels to | 240 | // Odd pixels will go to the top 8 bits of the destination. Even pixels to |
243 | // the lower 8 bits. | 241 | // the lower 8 bits. |
244 | int odd = x & 0x1; | 242 | int odd = x & 0x1; |
@@ -250,24 +248,41 @@ put_pixel_m4(int x, int y, u8 col_index) { | |||
250 | } | 248 | } |
251 | 249 | ||
252 | static inline void | 250 | static inline void |
253 | draw_fill_rect_m4(int x0, int y0, int x1, int y1, u8 col_index) { | 251 | draw_fill_rect_m4(int x0, int y0, int x1, int y1, u8 col_index, u16 *buffer) { |
254 | int ix, iy; | 252 | int ix, iy; |
255 | for(iy = y0; iy < y1; iy++) { | 253 | for(iy = y0; iy < y1; iy++) { |
256 | for(ix = x0; ix < x1; ix++) { | 254 | for(ix = x0; ix < x1; ix++) { |
257 | put_pixel_m4(ix, iy, col_index); | 255 | put_pixel_m4(ix, iy, col_index, buffer); |
258 | } | 256 | } |
259 | } | 257 | } |
260 | } | 258 | } |
261 | 259 | ||
260 | static inline u16 | ||
261 | flip_page() { | ||
262 | DISP_CONTROL ^= DISP_CONTROL_PAGE; | ||
263 | } | ||
264 | |||
265 | #define SCREEN_PAGE_1 ((vu16*) MEM_VRAM) | ||
266 | #define SCREEN_PAGE_2 ((vu16*) (MEM_VRAM + 0xa000)) | ||
267 | |||
262 | int main(void) { | 268 | int main(void) { |
263 | set_display_mode(DISP_MODE_4 | DISP_BG2); | 269 | DISP_CONTROL = DISP_MODE_4 | DISP_BG2; |
264 | 270 | ||
265 | PAL_BUFFER[1] = COLOR_RED; | 271 | PAL_BUFFER[1] = COLOR_RED; |
266 | PAL_BUFFER[2] = COLOR_BLUE; | 272 | PAL_BUFFER[2] = COLOR_BLUE; |
267 | draw_fill_rect_m4(0, 0, 20, 20, 1); | ||
268 | 273 | ||
274 | // Prepare the screen buffers by drawing a rectangle with different colors | ||
275 | // to each page. | ||
276 | draw_fill_rect_m4(0, 0, 20, 20, 1, SCREEN_PAGE_1); | ||
277 | draw_fill_rect_m4(0, 0, 20, 20, 2, SCREEN_PAGE_2); | ||
278 | |||
279 | int frame_counter = 0; | ||
269 | while(true) { | 280 | while(true) { |
270 | wait_vsync(); | 281 | wait_vsync(); |
282 | if (frame_counter++ > 30) { | ||
283 | frame_counter = 0; | ||
284 | flip_page(); | ||
285 | } | ||
271 | }; | 286 | }; |
272 | 287 | ||
273 | return 0; | 288 | return 0; |