UART support

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

UART support

Post 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)?
CunningFellow
Posts: 1445
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: UART support

Post 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.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: UART support

Post 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: https://github.com/artcfox/circuit/blob ... /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/Make_config.mk b/Make_config.mk
index a99a8dd..189d28d 100644
--- a/Make_config.mk
+++ b/Make_config.mk
@@ -37,7 +37,7 @@
 #  windows_mingw
 #  emscripten
 #
-TSYS=linux
+TSYS=windows_mingw
 #
 #
 # 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 libsdl.org:
 #
-#CC_INC=SDL2-2.0.4/i686-w64-mingw32/include
-#CC_LIB=SDL2-2.0.4/i686-w64-mingw32/lib
-#CCOMP=i686-w64-mingw32-gcc
-#CCNAT=gcc
+CC_INC=SDL2-2.0.4/i686-w64-mingw32/include
+CC_LIB=SDL2-2.0.4/i686-w64-mingw32/lib
+CCOMP=i686-w64-mingw32-gcc
+CCNAT=gcc
 #
 # Note that for Emscripten builds you might also have to define these to
 # compile assets necessary to build the emulator.
 #
-CC_BIN=
-CC_INC=
-CC_LIB=
+#CC_BIN=
+#CC_INC=
+#CC_LIB=
 #
 #
 # 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.
 #
-FLAG_DISPLAY_FRAMEMERGE=1
+FLAG_DISPLAY_FRAMEMERGE=0
 #
 #
 # 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!).
 #
-FLAG_NOCONSOLE=0
+FLAG_NOCONSOLE=1
 #
 #
 # 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_unf(main_title);
  print_message(" %08X\n", VER_DATE);
 
User avatar
danboid
Posts: 1882
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

Post 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.
User avatar
danboid
Posts: 1882
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

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

Thanks
User avatar
danboid
Posts: 1882
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

Post by danboid »

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
uze6666
Site Admin
Posts: 4778
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: UART support

Post by uze6666 »

That's strange. I just tested it on my side and it works fine:
whisperport.png
whisperport.png (63.9 KiB) Viewed 6187 times
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: UART support

Post by Artcfox »

Sorry this is way late, but the Linux version should just need the changes to the cu_avr.c file

Code: Select all

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 */
User avatar
danboid
Posts: 1882
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

Post by danboid »

Sorry its took me the best part of a year to reply to you both!

I've finally got round to testing this out under Debian Testing, after getting the UB repo to build.

Uze:

I've tried to replicate your example by adding lines like

```
_SFR_IO8(0X1a)='s';
```

Into exactly the same demo file that you have changed there (Mode5Demo.c) but nothing gets printed to the uzem console under Linux, after recompiling the demo. Maybe Uzem needs a patch to get this working under Linux?

ArtcFox:

Thanks for the cuzebox whisper console patch! It has applied cleanly and cuzebox has built with the patch OK so I presume it should work although I've not tested it just yet, I wanted to try replicating Uze's example first as I thought there was less chance of it not working. Nope!
User avatar
danboid
Posts: 1882
Joined: Sun Jun 14, 2020 12:14 am

Re: UART support

Post by danboid »

Uze:

I've got your example code to work now - I forgot to add the 2 DEFINES - although using uzem would be no use as is as I need the emu to frequently print values out to the whisper console. Seeing them all dumped out in one big splurge only when I quit uzem is no use to me unfortunatey so cuzebox it is.

ArtcFox:

I can see that I will probably want to supress cuzebox's default console output re fps etc so I only see my custom debug output. I should be able to do that myself.
Post Reply