aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-19 11:05:47 +0200
committerBad Diode <bd@badd10de.dev>2021-05-19 11:05:47 +0200
commita2f89131491a4cf7914becfd98d277544d26579a (patch)
tree311ecb11d3d60f3d7af350b26ac6d62294afea17 /src/main.c
parentec5b9644db2ff26cc6f0cc3d84854b714a25eff9 (diff)
downloaduxngba-a2f89131491a4cf7914becfd98d277544d26579a.tar.gz
uxngba-a2f89131491a4cf7914becfd98d277544d26579a.zip
Set up backgrounds 0 and 1 for fg/bg drawing
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c87
1 files changed, 59 insertions, 28 deletions
diff --git a/src/main.c b/src/main.c
index 9866f19..a2962bf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,7 +3,8 @@
3#include "common.h" 3#include "common.h"
4#include "bitmap.h" 4#include "bitmap.h"
5#include "text.h" 5#include "text.h"
6#include "small-font.c" 6// #include "small-font.c"
7#include "bd-font.c"
7 8
8#include "uxn/uxn.h" 9#include "uxn/uxn.h"
9#include "uxn/uxn.c" 10#include "uxn/uxn.c"
@@ -61,7 +62,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) {
61 Uint8 *layer = d->dat[0xe] >> 4 & 0x1 ? ppu.fg : ppu.bg; 62 Uint8 *layer = d->dat[0xe] >> 4 & 0x1 ? ppu.fg : ppu.bg;
62 Uint8 mode = d->dat[0xe] >> 5; 63 Uint8 mode = d->dat[0xe] >> 5;
63 if(!mode) { 64 if(!mode) {
64 putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3); 65 // putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3);
65 } else if(mode-- & 0x1) { 66 } else if(mode-- & 0x1) {
66 puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); 67 puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4);
67 } else { 68 } else {
@@ -110,45 +111,75 @@ init_uxn(Uxn *u) {
110 111
111int main(void) { 112int main(void) {
112 // Initialize display mode and bg palette. 113 // Initialize display mode and bg palette.
113 DISP_CTRL = DISP_MODE_3 | DISP_BG_2; 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 }
114 140
115 // Initialize text engine. 141 // Initialize text engine.
116 txt_init_bitmap( 142 // txt_init_tile(
117 TXT_MODE_MODE3, 143 // 2,
118 (Font){ 144 // (Font){
119 .data = small_font, 145 // .data = bd_font,
120 .char_width = 4, 146 // .color = COLOR_WHITE,
121 .char_height = 8, 147 // }, 3);
122 .color = COLOR_WHITE, 148 // txt_printf("testing");
123 .char_map = small_font_map, 149
124 }); 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
125 156
126 // Register interrupts. 157 // Register interrupts.
127 irq_init(); 158 irq_init();
128 irs_set(IRQ_VBLANK, irs_stub); 159 irs_set(IRQ_VBLANK, irs_stub);
129 160
130 // Initialize VM. 161// // Initialize VM.
131 Uxn u = {0}; 162// Uxn u = {0};
132 init_uxn(&u); 163// init_uxn(&u);
133 evaluxn(&u, 0x0100); 164// evaluxn(&u, 0x0100);
134 165
135 // Main loop. 166 // Main loop.
136 int frame_counter = 0; 167 int frame_counter = 0;
137 while(true) { 168 while(true) {
138 bios_vblank_wait(); 169 bios_vblank_wait();
139 poll_keys(); 170 poll_keys();
140 profile_start(); 171 // profile_start();
141 evaluxn(&u, mempeek16(devscreen->dat, 0)); 172 // evaluxn(&u, mempeek16(devscreen->dat, 0));
142 int eval_cycles = profile_stop(); 173 // int eval_cycles = profile_stop();
143 profile_start(); 174 // profile_start();
144 if(reqdraw) { 175 // // if(reqdraw) {
145 redraw(ppu.output, &u); 176 // // redraw(ppu.output, &u);
146 } 177 // // }
147 int redraw_cycles = profile_stop(); 178 // int redraw_cycles = profile_stop();
148 txt_position(0, 0); 179 // txt_position(0, 0);
149 txt_printf("EVAL: %d\n", eval_cycles); 180 // txt_printf("EVAL: %d\n", eval_cycles);
150 txt_printf("REDRAW: %d\n", redraw_cycles); 181 // txt_printf("REDRAW: %d\n", redraw_cycles);
151 frame_counter++; 182 // frame_counter++;
152 }; 183 };
153 184
154 return 0; 185 return 0;