diff options
author | Bad Diode <bd@badd10de.dev> | 2021-05-19 12:13:29 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-05-19 12:13:29 +0200 |
commit | 9873680f9d24e30afc1962987fac2c3ad1612f7b (patch) | |
tree | 5135bd3bd1d0e41c8725d51c7a56c1b0a1e2f904 /src/main.c | |
parent | a2f89131491a4cf7914becfd98d277544d26579a (diff) | |
download | uxngba-9873680f9d24e30afc1962987fac2c3ad1612f7b.tar.gz uxngba-9873680f9d24e30afc1962987fac2c3ad1612f7b.zip |
Update screen rendering to use 2 backgrounds
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 90 |
1 files changed, 17 insertions, 73 deletions
@@ -10,11 +10,18 @@ | |||
10 | #include "uxn/uxn.c" | 10 | #include "uxn/uxn.c" |
11 | #include "uxn/devices/ppu.h" | 11 | #include "uxn/devices/ppu.h" |
12 | #include "uxn/devices/ppu.c" | 12 | #include "uxn/devices/ppu.c" |
13 | // #include "uxn/roms/console.c" | ||
14 | #include "uxn/roms/dvd.c" | 13 | #include "uxn/roms/dvd.c" |
15 | // #include "uxn/roms/proportional_fonts.c" | 14 | |
16 | // #include "uxn/roms/automata.c" | 15 | /* |
17 | // #include "uxn/roms/life.c" | 16 | Copyright (c) 2021 Bad Diode |
17 | |||
18 | Permission to use, copy, modify, and distribute this software for any | ||
19 | purpose with or without fee is hereby granted, provided that the above | ||
20 | copyright notice and this permission notice appear in all copies. | ||
21 | |||
22 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
23 | WITH REGARD TO THIS SOFTWARE. | ||
24 | */ | ||
18 | 25 | ||
19 | static Ppu ppu; | 26 | static Ppu ppu; |
20 | u8 reqdraw = 0; | 27 | u8 reqdraw = 0; |
@@ -73,14 +80,6 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) { | |||
73 | } | 80 | } |
74 | 81 | ||
75 | void | 82 | void |
76 | redraw(Uint16 *dst, Uxn *u) { | ||
77 | // TODO: The screen will flicker but using Mode4 for double buffering would | ||
78 | // be way too slow. | ||
79 | drawppu(&ppu); | ||
80 | reqdraw = 0; | ||
81 | } | ||
82 | |||
83 | void | ||
84 | init_uxn(Uxn *u) { | 83 | init_uxn(Uxn *u) { |
85 | // Initialize PPU. | 84 | // Initialize PPU. |
86 | initppu(&ppu, 30, 20, 0); | 85 | initppu(&ppu, 30, 20, 0); |
@@ -90,7 +89,7 @@ init_uxn(Uxn *u) { | |||
90 | 89 | ||
91 | // Prepare devices. | 90 | // Prepare devices. |
92 | portuxn(u, 0x0, "system", system_talk); | 91 | portuxn(u, 0x0, "system", system_talk); |
93 | portuxn(u, 0x1, "console", console_talk); | 92 | portuxn(u, 0x1, "---", nil_talk); |
94 | devscreen = portuxn(u, 0x2, "screen", screen_talk); | 93 | devscreen = portuxn(u, 0x2, "screen", screen_talk); |
95 | portuxn(u, 0x3, "---", nil_talk); | 94 | portuxn(u, 0x3, "---", nil_talk); |
96 | portuxn(u, 0x4, "---", nil_talk); | 95 | portuxn(u, 0x4, "---", nil_talk); |
@@ -110,76 +109,21 @@ init_uxn(Uxn *u) { | |||
110 | } | 109 | } |
111 | 110 | ||
112 | int main(void) { | 111 | int main(void) { |
113 | // Initialize display mode and bg palette. | ||
114 | DISP_CTRL = DISP_MODE_0 | DISP_BG_0 | DISP_BG_1; | ||
115 | |||
116 | // WORKS | ||
117 | u8 cb_fg = 0; | ||
118 | u8 sb_fg = 10; | ||
119 | u8 cb_bg = 2; | ||
120 | u8 sb_bg = 26; | ||
121 | BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_fg) | BG_PRIORITY(1); | ||
122 | BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_bg) | BG_PRIORITY(2); | ||
123 | Tile *fg = &TILE_MEM[cb_fg]; | ||
124 | Tile *bg = &TILE_MEM[cb_bg]; | ||
125 | for (size_t i = 0; i < 30 * 20; ++i) { | ||
126 | fg[i] = (Tile){0}; | ||
127 | bg[i] = (Tile){0}; | ||
128 | } | ||
129 | |||
130 | // Initialize memory map. | ||
131 | u16 *fg_mem = SCREENBLOCK_MEM[sb_fg]; | ||
132 | u16 *bg_mem = SCREENBLOCK_MEM[sb_bg]; | ||
133 | size_t k = 0; | ||
134 | for (size_t j = 0; j < 20; ++j) { | ||
135 | for (size_t i = 0; i < 30; ++i, ++k) { | ||
136 | fg_mem[i + j * 32] = k; | ||
137 | bg_mem[i + j * 32] = k; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | // Initialize text engine. | ||
142 | // txt_init_tile( | ||
143 | // 2, | ||
144 | // (Font){ | ||
145 | // .data = bd_font, | ||
146 | // .color = COLOR_WHITE, | ||
147 | // }, 3); | ||
148 | // txt_printf("testing"); | ||
149 | |||
150 | PAL_BUFFER_BG[0] = COLOR_RED; | ||
151 | PAL_BUFFER_BG[1] = COLOR_BLUE; | ||
152 | PAL_BUFFER_BG[2] = COLOR_CYAN; | ||
153 | PAL_BUFFER_BG[3] = COLOR_WHITE; | ||
154 | PAL_BUFFER_BG[4] = COLOR_GREY; | ||
155 | |||
156 | |||
157 | // Register interrupts. | 112 | // Register interrupts. |
158 | irq_init(); | 113 | irq_init(); |
159 | irs_set(IRQ_VBLANK, irs_stub); | 114 | irs_set(IRQ_VBLANK, irs_stub); |
160 | 115 | ||
161 | // // Initialize VM. | 116 | // Initialize VM. |
162 | // Uxn u = {0}; | 117 | Uxn u = {0}; |
163 | // init_uxn(&u); | 118 | init_uxn(&u); |
164 | // evaluxn(&u, 0x0100); | 119 | evaluxn(&u, 0x0100); |
165 | 120 | ||
166 | // Main loop. | 121 | // Main loop. |
167 | int frame_counter = 0; | 122 | int frame_counter = 0; |
168 | while(true) { | 123 | while(true) { |
169 | bios_vblank_wait(); | 124 | bios_vblank_wait(); |
170 | poll_keys(); | 125 | poll_keys(); |
171 | // profile_start(); | 126 | evaluxn(&u, mempeek16(devscreen->dat, 0)); |
172 | // evaluxn(&u, mempeek16(devscreen->dat, 0)); | ||
173 | // int eval_cycles = profile_stop(); | ||
174 | // profile_start(); | ||
175 | // // if(reqdraw) { | ||
176 | // // redraw(ppu.output, &u); | ||
177 | // // } | ||
178 | // int redraw_cycles = profile_stop(); | ||
179 | // txt_position(0, 0); | ||
180 | // txt_printf("EVAL: %d\n", eval_cycles); | ||
181 | // txt_printf("REDRAW: %d\n", redraw_cycles); | ||
182 | // frame_counter++; | ||
183 | }; | 127 | }; |
184 | 128 | ||
185 | return 0; | 129 | return 0; |