diff options
author | Bad Diode <bd@badd10de.dev> | 2022-10-16 10:04:48 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-10-16 10:04:48 +0200 |
commit | c4d74be0b2157b50b324db1f0bf9a871fd066619 (patch) | |
tree | f018dbdf37275724392371aa08214ffdece37558 | |
parent | 0d0e489b6621bf8d998d3aa6e4b02c457c9feefb (diff) | |
download | uxn64-c4d74be0b2157b50b324db1f0bf9a871fd066619.tar.gz uxn64-c4d74be0b2157b50b324db1f0bf9a871fd066619.zip |
Test different framebuffer configurations
For now it seems that using RPD and manually modifying the framebuffer
are not compatible. Perhaps is a cache thing or maybe something else.
Uncomment each drawing line separately to test drawing modes.
-rw-r--r-- | src/main.c | 150 |
1 files changed, 100 insertions, 50 deletions
@@ -3,8 +3,8 @@ | |||
3 | #include "types.h" | 3 | #include "types.h" |
4 | 4 | ||
5 | // Screen size. | 5 | // Screen size. |
6 | #define SCREEN_HEIGHT 240 | ||
7 | #define SCREEN_WIDTH 320 | 6 | #define SCREEN_WIDTH 320 |
7 | #define SCREEN_HEIGHT 240 | ||
8 | 8 | ||
9 | // Get a pointer to the start (top) of a stack. | 9 | // Get a pointer to the start (top) of a stack. |
10 | #define STACK_START(stack) ((stack) + sizeof((stack))) | 10 | #define STACK_START(stack) ((stack) + sizeof((stack))) |
@@ -25,9 +25,9 @@ u64 boot_stack[STACK_SIZE / sizeof(u64)] __attribute__((aligned(8))); | |||
25 | // Framebuffers. | 25 | // Framebuffers. |
26 | // | 26 | // |
27 | 27 | ||
28 | u16 framebuffers[2][SCREEN_WIDTH * SCREEN_HEIGHT]; | 28 | u16 framebuffers[2][SCREEN_WIDTH * SCREEN_HEIGHT] __attribute__((aligned(16))); |
29 | u16 rsp_framebuffer[SCREEN_WIDTH * SCREEN_HEIGHT]; | ||
30 | static int current_fb = 0; | 29 | static int current_fb = 0; |
30 | static u16 pixels[SCREEN_WIDTH * SCREEN_HEIGHT] __attribute__((aligned(16))); | ||
31 | 31 | ||
32 | // | 32 | // |
33 | // Message buffers and queues. | 33 | // Message buffers and queues. |
@@ -43,6 +43,71 @@ static OSMesgQueue retrace_msg_queue; | |||
43 | // Handle for rom memory. | 43 | // Handle for rom memory. |
44 | OSPiHandle *rom_handle; | 44 | OSPiHandle *rom_handle; |
45 | 45 | ||
46 | // DEBUG: animations | ||
47 | static int t = 0; | ||
48 | |||
49 | void | ||
50 | fb_write_test(void) { | ||
51 | for (size_t j = 0; j < SCREEN_HEIGHT; j++) { | ||
52 | for (size_t i = 0; i < SCREEN_WIDTH; i++) { | ||
53 | // u16 shade_x = (float)i / (float)SCREEN_WIDTH * 32; | ||
54 | // u16 shade_y = (float)j / (float)SCREEN_HEIGHT * 32; | ||
55 | // u16 color = shade_x << 11 | shade_y << 1; | ||
56 | u16 shade_x = (float)i / (float)SCREEN_WIDTH * 255; | ||
57 | u16 shade_y = (float)j / (float)SCREEN_HEIGHT * 255; | ||
58 | u16 color = GPACK_RGBA5551(shade_x, t, shade_y, 1); | ||
59 | // u16 color = t; | ||
60 | framebuffers[current_fb][i + j * SCREEN_WIDTH] = color; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | void | ||
66 | fb_copy_test(void) { | ||
67 | for (size_t i = 0; i < SCREEN_HEIGHT * SCREEN_WIDTH; i++) { | ||
68 | framebuffers[current_fb][i] = pixels[i]; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | void | ||
73 | rdp_clearfb(u8 r, u8 g, u8 b) { | ||
74 | Gfx glist[2048]; | ||
75 | Gfx *glistp = glist; | ||
76 | Gfx clearcfb_dl[] = { | ||
77 | gsDPSetCycleType(G_CYC_FILL), | ||
78 | gsDPSetColorImage( | ||
79 | G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, framebuffers[current_fb]), | ||
80 | gsDPSetFillColor(GPACK_RGBA5551(r, g, b, 1)), | ||
81 | gsDPFillRectangle(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1), | ||
82 | gsSPEndDisplayList(), | ||
83 | }; | ||
84 | gSPDisplayList(glistp++, clearcfb_dl); | ||
85 | gDPFullSync(glistp++); | ||
86 | gSPEndDisplayList(glistp++); | ||
87 | |||
88 | // Start up the task list. | ||
89 | OSTask tlist = (OSTask){ | ||
90 | { | ||
91 | .type = M_GFXTASK, | ||
92 | .flags = OS_TASK_DP_WAIT, | ||
93 | .ucode_boot = (u64*)rspbootTextStart, | ||
94 | .ucode_boot_size = (u32)rspbootTextEnd - (u32)rspbootTextStart, | ||
95 | .ucode = (u64*)gspF3DEX2_xbusTextStart, | ||
96 | .ucode_size = SP_UCODE_SIZE, | ||
97 | .ucode_data = (u64*)gspF3DEX2_xbusDataStart, | ||
98 | .ucode_data_size = SP_UCODE_DATA_SIZE, | ||
99 | .data_ptr = (u64*)glist, | ||
100 | .data_size = (u32)((glistp - glist) * sizeof(Gfx)), | ||
101 | .dram_stack = dram_stack, | ||
102 | .dram_stack_size = SP_DRAM_STACK_SIZE8, | ||
103 | }, | ||
104 | }; | ||
105 | osSpTaskStart(&tlist); | ||
106 | |||
107 | // Wait for RDP completion. | ||
108 | osRecvMesg(&rdp_msg_queue, NULL, OS_MESG_BLOCK); | ||
109 | } | ||
110 | |||
46 | static void | 111 | static void |
47 | main_proc(void *arg) { | 112 | main_proc(void *arg) { |
48 | (void)arg; | 113 | (void)arg; |
@@ -65,60 +130,45 @@ main_proc(void *arg) { | |||
65 | // 9. Trasfer digital data to DAC (Video Interface) | 130 | // 9. Trasfer digital data to DAC (Video Interface) |
66 | // 10. Video signal is produced. | 131 | // 10. Video signal is produced. |
67 | 132 | ||
133 | // NOTE: Test image. | ||
134 | for (size_t j = 0; j < SCREEN_HEIGHT; j++) { | ||
135 | for (size_t i = 0; i < SCREEN_WIDTH; i++) { | ||
136 | u16 shade_x = (float)i / (float)SCREEN_WIDTH * 255; | ||
137 | u16 shade_y = (float)j / (float)SCREEN_HEIGHT * 255; | ||
138 | u16 color = GPACK_RGBA5551(shade_x, 0, shade_y, 1); | ||
139 | pixels[i + j * SCREEN_WIDTH] = color; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | // Clear the framebuffer with rdp. | ||
144 | // rdp_clearfb(0, 0, 0); | ||
145 | |||
68 | // Main loop. | 146 | // Main loop. |
69 | int i = 0; | ||
70 | int increment = 4; | 147 | int increment = 4; |
71 | int direction = increment; | 148 | int direction = increment; |
72 | while (true) { | 149 | while (true) { |
73 | if (i >= 255 - increment) { | 150 | if (t >= 255 - increment) { |
74 | direction = -increment; | 151 | direction = -increment; |
75 | } else if (i <= 0) { | 152 | } if (t <= 0 + increment) { |
76 | direction = +increment; | 153 | direction = +increment; |
77 | } | 154 | } |
78 | i += direction; | 155 | t += direction; |
79 | 156 | ||
80 | // Graphics command list. | 157 | // A |
81 | // TODO: Check out of bounds when adding elements to the list. | 158 | // rdp_clearfb(t, t, t); |
82 | Gfx glist[2048]; | 159 | // osWritebackDCacheAll(); |
83 | Gfx *glistp = glist; | 160 | // B |
84 | 161 | // fb_write_test(); | |
85 | // Tell RCP where each segment is. | 162 | // C |
86 | gSPSegment(glistp++, 0, 0x0); // Physical address segment | 163 | for (size_t j = 0; j < SCREEN_HEIGHT; j++) { |
87 | gSPSegment(glistp++, 2, OS_K0_TO_PHYSICAL(framebuffers[current_fb])); | 164 | for (size_t i = 0; i < SCREEN_WIDTH; i++) { |
88 | 165 | u16 shade_x = (float)i / (float)SCREEN_WIDTH * 255; | |
89 | // Clear color framebuffer. | 166 | u16 shade_y = (float)j / (float)SCREEN_HEIGHT * 255; |
90 | Gfx clearcfb_dl[] = { | 167 | u16 color = GPACK_RGBA5551(shade_x, t, shade_y, 1); |
91 | gsDPSetCycleType(G_CYC_FILL), | 168 | pixels[i + j * SCREEN_WIDTH] = color; |
92 | gsDPSetColorImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, rsp_framebuffer), | 169 | } |
93 | gsDPSetFillColor(GPACK_RGBA5551(64, 64, 255, 1) << 16 | GPACK_RGBA5551(i, i, i, 1)), | 170 | } |
94 | gsDPFillRectangle(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1), | 171 | fb_copy_test(); |
95 | gsSPEndDisplayList(), | ||
96 | }; | ||
97 | gSPDisplayList(glistp++, clearcfb_dl); | ||
98 | gDPFullSync(glistp++); | ||
99 | gSPEndDisplayList(glistp++); | ||
100 | |||
101 | // Start up the RSP task list. | ||
102 | OSTask tlist = (OSTask){ | ||
103 | { | ||
104 | .type = M_GFXTASK, | ||
105 | .flags = OS_TASK_DP_WAIT, | ||
106 | .ucode_boot = (u64*) rspbootTextStart, | ||
107 | .ucode_boot_size = (u32)rspbootTextEnd - (u32)rspbootTextStart, | ||
108 | .ucode = (u64*)gspF3DEX2_xbusTextStart, | ||
109 | .ucode_size = SP_UCODE_SIZE, | ||
110 | .ucode_data = (u64*)gspF3DEX2_xbusDataStart, | ||
111 | .ucode_data_size = SP_UCODE_DATA_SIZE, | ||
112 | .data_ptr = (u64*) glist, | ||
113 | .data_size = (u32)((glistp - glist) * sizeof(Gfx)), | ||
114 | .dram_stack = dram_stack, | ||
115 | .dram_stack_size = SP_DRAM_STACK_SIZE8, | ||
116 | }, | ||
117 | }; | ||
118 | osSpTaskStart(&tlist); | ||
119 | |||
120 | // Wait for RDP completion. | ||
121 | osRecvMesg(&rdp_msg_queue, NULL, OS_MESG_BLOCK); | ||
122 | 172 | ||
123 | // Swap buffers. | 173 | // Swap buffers. |
124 | osViSwapBuffer(framebuffers[current_fb]); | 174 | osViSwapBuffer(framebuffers[current_fb]); |