aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-19 14:26:30 +0200
committerBad Diode <bd@badd10de.dev>2021-05-19 14:26:30 +0200
commit60684bb15f5c68eb8248673da48cc4469537ffc9 (patch)
treefd6901719ab8121b9bf8e0c98700a43eff198652 /src/main.c
parentfd5dede600bcaf8d5c16963544512b2e0ba68586 (diff)
downloaduxngba-60684bb15f5c68eb8248673da48cc4469537ffc9.tar.gz
uxngba-60684bb15f5c68eb8248673da48cc4469537ffc9.zip
Add a new console drawing mode
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index cd991e1..e767d43 100644
--- a/src/main.c
+++ b/src/main.c
@@ -10,8 +10,11 @@
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/dvd.c" 13// #include "uxn/roms/console.c"
14#include "uxn/roms/automata.c" 14// #include "uxn/roms/proportional_fonts.c"
15#include "uxn/roms/dvd.c"
16// #include "uxn/roms/automata.c"
17// #include "uxn/roms/life.c"
15 18
16/* 19/*
17Copyright (c) 2021 Bad Diode 20Copyright (c) 2021 Bad Diode
@@ -24,6 +27,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
24WITH REGARD TO THIS SOFTWARE. 27WITH REGARD TO THIS SOFTWARE.
25*/ 28*/
26 29
30static size_t drawing_cycles = 0;
31
27static Ppu ppu; 32static Ppu ppu;
28u8 reqdraw = 0; 33u8 reqdraw = 0;
29static Device *devscreen; 34static Device *devscreen;
@@ -63,6 +68,7 @@ system_talk(Device *d, Uint8 b0, Uint8 w)
63 68
64void 69void
65screen_talk(Device *d, Uint8 b0, Uint8 w) { 70screen_talk(Device *d, Uint8 b0, Uint8 w) {
71 profile_start();
66 if(w && b0 == 0xe) { 72 if(w && b0 == 0xe) {
67 Uint16 x = mempeek16(d->dat, 0x8); 73 Uint16 x = mempeek16(d->dat, 0x8);
68 Uint16 y = mempeek16(d->dat, 0xa); 74 Uint16 y = mempeek16(d->dat, 0xa);
@@ -78,6 +84,8 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) {
78 } 84 }
79 reqdraw = 1; 85 reqdraw = 1;
80 } 86 }
87 int cycles = profile_stop();
88 drawing_cycles += cycles;
81} 89}
82 90
83void 91void
@@ -90,7 +98,7 @@ init_uxn(Uxn *u) {
90 98
91 // Prepare devices. 99 // Prepare devices.
92 portuxn(u, 0x0, "system", system_talk); 100 portuxn(u, 0x0, "system", system_talk);
93 portuxn(u, 0x1, "---", nil_talk); 101 portuxn(u, 0x1, "console", console_talk);
94 devscreen = portuxn(u, 0x2, "screen", screen_talk); 102 devscreen = portuxn(u, 0x2, "screen", screen_talk);
95 portuxn(u, 0x3, "---", nil_talk); 103 portuxn(u, 0x3, "---", nil_talk);
96 portuxn(u, 0x4, "---", nil_talk); 104 portuxn(u, 0x4, "---", nil_talk);
@@ -114,9 +122,20 @@ int main(void) {
114 irq_init(); 122 irq_init();
115 irs_set(IRQ_VBLANK, irs_stub); 123 irs_set(IRQ_VBLANK, irs_stub);
116 124
125 // Initialize text engine.
126 txt_init_bitmap(
127 TXT_MODE_HYBRID,
128 (Font){
129 .data = bd_font,
130 .char_height = 8,
131 .char_width = 8,
132 });
133 txt_position(0,0);
134
117 // Initialize VM. 135 // Initialize VM.
118 Uxn u = {0}; 136 Uxn u = {0};
119 init_uxn(&u); 137 init_uxn(&u);
138 txt_clear_screen();
120 evaluxn(&u, 0x0100); 139 evaluxn(&u, 0x0100);
121 140
122 // Main loop. 141 // Main loop.
@@ -125,7 +144,13 @@ int main(void) {
125 bios_vblank_wait(); 144 bios_vblank_wait();
126 poll_keys(); 145 poll_keys();
127 evaluxn(&u, mempeek16(devscreen->dat, 0)); 146 evaluxn(&u, mempeek16(devscreen->dat, 0));
128 }; 147 txt_position(0,0);
148 txt_clear_screen();
149 txt_printf("FRAME: %d\n", frame_counter);
150 txt_printf("DRAWING: %d\n", drawing_cycles);
151 drawing_cycles = 0;
152 frame_counter++;
153 }
129 154
130 return 0; 155 return 0;
131} 156}