UART support

The Uzebox now have a fully functional emulator! Download and discuss it here.
Post Reply
User avatar
Posts: 184
Joined: Sun Jun 14, 2020 12:14 am

UART support

Post by danboid » Sat Feb 20, 2021 9:19 am

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)?

Posts: 1265
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: UART support

Post by CunningFellow » Sat Feb 20, 2021 9:14 pm

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.

User avatar
Posts: 1060
Joined: Thu Jun 04, 2015 5:35 pm

Re: UART support

Post by Artcfox » Sun Feb 21, 2021 12:25 am

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);

User avatar
Posts: 184
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

Post by danboid » Sun Feb 21, 2021 12:31 pm

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.

User avatar
Posts: 184
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

Post by danboid » Tue Apr 20, 2021 9:40 pm

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?


User avatar
Posts: 184
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

Post by danboid » Sun Dec 05, 2021 6:03 pm

I have tried using

#define UZEMC _SFR_IO8(26)

With Uzem but it doesn't print the characters assigned to UZEMC to the console until I quit uzem.

Would it be possible to have have uzem output to the console and have it print the output instantly?

User avatar
Site Admin
Posts: 4530
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada

Re: UART support

Post by uze6666 » Sat Jan 15, 2022 1:55 am

That's strange. I just tested it on my side and it works fine:
whisperport.png (63.9 KiB) Viewed 1845 times

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests