From bbe96d7c5b898c1ad0a0c735495b27d163a0a7c4 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 7 Jul 2018 20:27:24 +0100 Subject: [PATCH] trs80m1: initial ChromaTRS bits We don't put a console on it (we could) we just advertise it as a graphics device and support the joystick ports. The code needed to support it in console mode already exists in the MSX1 and MTX512 ports, but really needs a VDP simulation adding to xtrs to debug sanely --- Kernel/include/graphics.h | 2 +- Kernel/platform-trs80m1/devgfx.c | 37 +++++++++++++++++++++++-- Kernel/platform-trs80m1/devgfx.h | 1 + Kernel/platform-trs80m1/devinput.c | 43 +++++++++++++++++++++++++----- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/Kernel/include/graphics.h b/Kernel/include/graphics.h index 1e8325a1..c8ff69f8 100644 --- a/Kernel/include/graphics.h +++ b/Kernel/include/graphics.h @@ -21,7 +21,7 @@ struct display { #define FMT_UBEE 130 /* Microbee 6545 modes */ uint8_t hardware; #define HW_UNACCEL 1 /* Simple display */ -#define HW_VDP_9918 128 /* Not neccessarily MSX... */ +#define HW_VDP_9918A 128 /* Not neccessarily MSX... */ #define HW_VDP_9938 129 #define HW_TRS80GFX 130 /* TRS80 model 4 graphics board */ #define HW_HRG1B 131 /* HRG1B for TRS80 and VidoeGenie */ diff --git a/Kernel/platform-trs80m1/devgfx.c b/Kernel/platform-trs80m1/devgfx.c index 2cfd5879..9a831c42 100644 --- a/Kernel/platform-trs80m1/devgfx.c +++ b/Kernel/platform-trs80m1/devgfx.c @@ -13,15 +13,18 @@ __sfr __at 0x00 hrg_off; __sfr __at 0x04 hrg_data; +__sfr __at 0x79 vdps; +__sfr __at 0x7C chromajs0; __sfr __at 0x82 gfx_data; __sfr __at 0x83 gfx_ctrl; __sfr __at 0xFF ioctrl; uint8_t has_hrg1; +uint8_t has_chroma; /* and thus 2 joystick ports */ uint8_t video_mode; static uint8_t max_mode = 0; -static struct display trsdisplay[4] = { +static struct display trsdisplay[5] = { /* Text mode */ { 0, @@ -69,10 +72,22 @@ static struct display trsdisplay[4] = { GFX_MULTIMODE|GFX_MAPPABLE|GFX_TEXT, 9, 0 + }, + /* CHROMAtrs */ + { + 1, + 256, 192, + 256, 192, + 255, 255, + FMT_VDP, + HW_VDP_9918A, + GFX_MAPPABLE, /* We don't support it as a console yet */ + 16, + 0 } }; -static struct videomap trsmap[4] = { +static struct videomap trsmap[5] = { { 0, 0, @@ -109,6 +124,15 @@ static struct videomap trsmap[4] = { 1, /* Standard spacing */ MAP_PIO }, + /* CHROMAtrs */ + { + 0, + 0x78, /* I/O ports 0x78/79 */ + 0, 0, + 0, 0, + 1, + MAP_PIO /* VDP is I/O mapped */ + } }; static uint8_t displaymap[2] = {0, 0}; @@ -188,4 +212,13 @@ void gfx_init(void) displaymap[1] = 1; } } + /* It's possible to have a CHROMAtrs and other adapters as it fits + on the external bus. 70-7C is also a common location for RTC clocks + which makes detection trickier. The clock will show 0 in the upper + bits, the joystick port will not */ + if (vdps != 0xFF && (chromajs0 & 0xC0) == 0xC0) { + displaymap[++max_mode] = 4; + trsdisplay[4].mode = max_mode; + has_chroma = 1; + } } diff --git a/Kernel/platform-trs80m1/devgfx.h b/Kernel/platform-trs80m1/devgfx.h index f36bd7ba..185c3c5e 100644 --- a/Kernel/platform-trs80m1/devgfx.h +++ b/Kernel/platform-trs80m1/devgfx.h @@ -8,5 +8,6 @@ extern void gfx_init(void); extern uint8_t video_mode; extern uint8_t has_hrg1; +extern uint8_t has_chroma; #endif diff --git a/Kernel/platform-trs80m1/devinput.c b/Kernel/platform-trs80m1/devinput.c index 60bf1f16..83850552 100644 --- a/Kernel/platform-trs80m1/devinput.c +++ b/Kernel/platform-trs80m1/devinput.c @@ -5,7 +5,11 @@ #include __sfr __at 0x00 stick; -uint8_t old_stick; +static uint8_t old_stick; + +__sfr __at 0x7C chroma0; +__sfr __at 0x7E chroma1; +static uint8_t old_cj[2]; static char buf[32]; static struct s_queue kqueue = { @@ -19,6 +23,28 @@ void queue_input(uint8_t c) wakeup(&kqueue); } +/* If both are present number the Chroma joysticks 1 and 2 */ +static int chroma_js(uint8_t *slot, uint8_t n, uint8_t v) +{ + uint8_t k = 0; + if (v == old_cj[n]) + return 0; + old_cj[n] = v; + if (v & 1) + k = STICK_DIGITAL_L; + if (v & 2) + k = STICK_DIGITAL_R; + if (v & 4) + k = STICK_DIGITAL_U; + if (v & 8) + k = STICK_DIGITAL_D; + if (v & 16) + k = BUTTON(0); + *slot++ = STICK_DIGITAL | (n + 1); + *slot = k; + return 2; +} + int platform_input_read(uint8_t *slot) { uint8_t r, k; @@ -29,6 +55,12 @@ int platform_input_read(uint8_t *slot) return 2; } + if (has_chroma) { + if (chroma_js(slot, 0, ~chroma0)) + return 2; + if (chroma_js(slot, 1, ~chroma1)) + return 2; + } /* Clashes with Alpha joystick */ if (has_hrg1) return 0; @@ -56,7 +88,7 @@ int platform_input_read(uint8_t *slot) if (r & 16) k |= BUTTON(0); *slot++ = STICK_DIGITAL; - *slot++ = k; + *slot = k; return 2; } @@ -74,8 +106,7 @@ int platform_input_write(uint8_t flag) void poll_input(void) { - if (has_hrg1) - return; - if (~stick != old_stick) - wakeup(&kqueue); + if ((!has_hrg1 && ~stick != old_stick) || + (has_chroma && (old_cj[0] != ~chroma0 || old_cj[1] != ~chroma1))) + wakeup(&kqueue); } -- 2.34.1