serial terminal
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 4 Aug 2018 01:26:04 +0000 (04:26 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 4 Aug 2018 01:26:04 +0000 (04:26 +0300)
src/amiga/main.c
src/amiga/serial.c [new file with mode: 0644]
src/amiga/serial.h [new file with mode: 0644]
uaeterm [new file with mode: 0755]

index 44112f5..bd66f1c 100644 (file)
@@ -3,8 +3,9 @@
 #include "copper.h"
 #include "gfx.h"
 #include "game.h"
+#include "serial.h"
 
-static uint32_t coplist[64];
+static uint32_t coplist[128];
 
 int main(void)
 {
@@ -13,6 +14,9 @@ int main(void)
        REG_INTENA = SETBITS(INTEN_VERTB | INTEN_MASTER);
        REG_DMACON = CLRBITS(DMA_ALL);
 
+       ser_init(9600);
+       ser_print("retrocrawl amiga starting up...\n");
+
        init_gfx();
 
        REG_COLOR0 = 0x111;
diff --git a/src/amiga/serial.c b/src/amiga/serial.c
new file mode 100644 (file)
index 0000000..dae3a12
--- /dev/null
@@ -0,0 +1,48 @@
+#include "hwregs.h"
+#include "serial.h"
+
+#define CLK            3546895
+#define BVAL(b)        (CLK / (b) - 1)
+
+static inline uint16_t baudval(int baud)
+{
+       switch(baud) {
+       case 110: return BVAL(110);
+       case 300: return BVAL(300);
+       case 600: return BVAL(600);
+       case 1200: return BVAL(1200);
+       case 2400: return BVAL(2400);
+       case 4800: return BVAL(4800);
+       case 9600: return BVAL(9600);
+       case 14400: return BVAL(14400);
+       case 19200: return BVAL(19200);
+       case 38400: return BVAL(38400);
+       case 57600: return BVAL(57600);
+       case 115200: return BVAL(115200);
+       default:
+               break;
+       }
+       return BVAL(baud);
+}
+
+void ser_init(int baud)
+{
+       REG_SERPER = baudval(baud) & 0x7fff;
+}
+
+/*
+void ser_putchar(int c)
+{
+       REG_SERDAT = ((uint16_t)c & 0xff) | 0x100;
+}
+*/
+
+void ser_print(const char *s)
+{
+       while(*s) {
+               if(*s == '\n') {
+                       ser_putchar('\r');
+               }
+               ser_putchar(*s++);
+       }
+}
diff --git a/src/amiga/serial.h b/src/amiga/serial.h
new file mode 100644 (file)
index 0000000..e460c98
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef SERIAL_H_
+#define SERIAL_H_
+
+#include "hwregs.h"
+
+/* dff030 is REG_SERDAT
+ * dff018 is REG_SERDATR
+ * bit 13 of SERDATR is TBE (transmit buffer empty)
+ */
+#define ser_putchar(c) \
+       asm volatile( \
+               "or.w #0x100, %0\n\t" \
+               "0: btst #13, 0xdff018\n\t" \
+               "beq 0b\n\t" \
+               "move.w %0, 0xdff030\n\t" \
+               :: "d"((int16_t)c))
+
+void ser_init(int baud);
+void ser_print(const char *s);
+
+#endif /* SERIAL_H_ */
diff --git a/uaeterm b/uaeterm
new file mode 100755 (executable)
index 0000000..4ea9e2e
--- /dev/null
+++ b/uaeterm
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+port=`cat fs-uae.conf | grep serial_port | awk '{ print $3; }'`
+if [ -z "$port" ]; then
+       echo "fs-uae.conf doesn't include a serial_port config option"
+       exit 1
+fi
+
+socat pty,raw,echo=0,link=$port -,raw,echo=0