From fa6997608f790933b3d4bb9f55d17084f77dfc16 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 4 Aug 2018 04:26:04 +0300 Subject: [PATCH] serial terminal --- src/amiga/main.c | 6 +++++- src/amiga/serial.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/amiga/serial.h | 21 +++++++++++++++++++++ uaeterm | 9 +++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/amiga/serial.c create mode 100644 src/amiga/serial.h create mode 100755 uaeterm diff --git a/src/amiga/main.c b/src/amiga/main.c index 44112f5..bd66f1c 100644 --- a/src/amiga/main.c +++ b/src/amiga/main.c @@ -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 index 0000000..dae3a12 --- /dev/null +++ b/src/amiga/serial.c @@ -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 index 0000000..e460c98 --- /dev/null +++ b/src/amiga/serial.h @@ -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 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 -- 1.7.10.4