Page 1 of 1

UART support

Posted: Sat Feb 20, 2021 9:19 am
by danboid
It doesn't seem that cuzebox and uzem have any UART support, correct?

I would find such a feature very useful for dev and debugging if I could easily send debug messages from my UB game to cu or similar.

Might this feature get added or is has it not been added for a reason (lack of demand I presume)?

Re: UART support

Posted: Sat Feb 20, 2021 9:14 pm
by CunningFellow
Doing a full proper UART would be a lot of work.

Making Uzem just spit out info to the console anything written to UDR and just ignoring the UART config and status registers would be not terribly hard.

Cuzem supports the UART Interrupt Complete Flag as a pseudo timer for the RLE-mode/1337-Demo. It does not actually support the any of the config/programming of UART things. It just assumes the baud/bit rate settings ar what I wanted for the video mode.

Re: UART support

Posted: Sun Feb 21, 2021 12:25 am
by Artcfox
If you use uzem, you can just define these in your code:

Code: Select all

#define UZEMH _SFR_IO8(25)
#define UZEMC _SFR_IO8(26)
and then when you want to print debug info to the console, UZEMH = hex, UZEMC = char; like this:

Code: Select all

UZEMC = 'H'; UZEMC = 'I'; UZEMC = '\n';
UZEMH = some_8_bit_variable;
You can take a look at my Circuit Puzzle game for more examples, just search for UZEMH and UZEMC inside circuit.c: ... /circuit.c

I don't know what OS you are using, but I wrote a quick and dirty patch to add whisper-console support to cuzebox, the newer better emulator, The Windows version required extra steps, if you are building on Linux, you don't need all of these changes.

Code: Select all

diff --git a/ b/
index a99a8dd..189d28d 100644
--- a/
+++ b/
@@ -37,7 +37,7 @@
 #  windows_mingw
 #  emscripten
 # A few paths in case they would be necessary. Leave them alone unless
@@ -47,17 +47,17 @@ TSYS=linux
 # compile from (Debian) Linux to 32 bit Windows, the followings might work
 # assuming that a development library was downloaded from
 # Note that for Emscripten builds you might also have to define these to
 # compile assets necessary to build the emulator.
 # Version number to use. It should be a BCD date of YYYYMMDD format.
@@ -108,7 +108,7 @@ FLAG_DISPLAY_SMALL=0
 # around limitations) while making the emulation running somewhat slower.
 # The F7 key may toggle it runtime.
 # Perform a self-contained build without filesystem access. This can only be
@@ -123,7 +123,7 @@ FLAG_SELFCONT=0
 # can be very slow, this eliminates all such calls, also reducing the
 # application size (but good bye, debug info!).
 # For an Emscripten build, disable linking with a game (also keep
diff --git a/cu_avr.c b/cu_avr.c
index a5832ab..77172d4 100644
--- a/cu_avr.c
+++ b/cu_avr.c
@@ -597,6 +597,14 @@ static void  cu_avr_write_io(auint port, auint val)
  access_io[port] |= CU_MEM_W;
+ if (port == 0x3A){
+   // emulator-only whisper support
+   printf("%c", cval);
+ }else if (port == 0x39){
+   // emulator-only whisper support
+   printf("%02x", cval);
+ }
  switch (port){
   case CU_IO_PORTA:   /* Controller inputs, SPI RAM Chip Select */
diff --git a/ginput.c b/ginput.c
index f7a0280..571bc0f 100644
--- a/ginput.c
+++ b/ginput.c
@@ -33,7 +33,7 @@
 /* Request Uzem style keymapping */
-static boole ginput_kbuzem = FALSE;
+static boole ginput_kbuzem = TRUE;
 /* Directing keyboard input to Player 2 (for two redirect keys) */
 static boole ginput_kbp2_0 = FALSE;
diff --git a/main.c b/main.c
index cc89f4a..0fad56d 100644
--- a/main.c
+++ b/main.c
@@ -363,6 +363,10 @@ static void main_loop(void)
+#include <stdio.h>
+#include <io.h>
+#include <fcntl.h>
+#include <windows.h>
 ** Main entry point
@@ -379,7 +383,20 @@ int main (int argc, char** argv)
  boole             hasrom;
  boole             bootpri = FALSE;
+    AllocConsole();
+    HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
+    int hCrt = _open_osfhandle((long) handle_out, _O_TEXT);
+    FILE* hf_out = _fdopen(hCrt, "w");
+    setvbuf(hf_out, NULL, _IONBF, 1);
+    *stdout = *hf_out;
+    HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
+    hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
+    FILE* hf_in = _fdopen(hCrt, "r");
+    setvbuf(hf_in, NULL, _IONBF, 128);
+    *stdin = *hf_in;
  print_message(" %08X\n", VER_DATE);

Re: UART support

Posted: Sun Feb 21, 2021 12:31 pm
by danboid
Thanks Artcfox!

I shall try your patch soon. I want to get fonts working for this purpose first but I can see cases where this may be a better option. I'm surprised no-one has added a similar feature until now.

I mainly run (Ubuntu) Linux.

Re: UART support

Posted: Tue Apr 20, 2021 9:40 pm
by danboid
Hi Artcfox

It's only now, 2 months later, that I finally get round to trying your patch so its only now I realise its for the Windows version of cuzebox.

Could you please provide a Linux version of your cuzebox whisper console patch?