From 7a86b8465b94a96a5e8c8ef065381708f3686226 Mon Sep 17 00:00:00 2001 From: Troy Schrapel Date: Sat, 8 Jun 2024 19:50:51 +0930 Subject: [PATCH] Removed unused tms9918 code from pico-56 --- src/CMakeLists.txt | 2 +- src/main.c | 27 ++-- src/tms9918/CMakeLists.txt | 19 --- src/tms9918/tms9918.c | 202 --------------------------- src/tms9918/tms9918.h | 27 ---- src/{tms9918 => }/vga/CMakeLists.txt | 0 src/{tms9918 => }/vga/vga-modes.c | 6 +- src/{tms9918 => }/vga/vga-modes.h | 6 +- src/{tms9918 => }/vga/vga.c | 6 +- src/{tms9918 => }/vga/vga.h | 4 +- src/{tms9918 => }/vga/vga.pio | 4 +- 11 files changed, 33 insertions(+), 270 deletions(-) delete mode 100644 src/tms9918/CMakeLists.txt delete mode 100644 src/tms9918/tms9918.c delete mode 100644 src/tms9918/tms9918.h rename src/{tms9918 => }/vga/CMakeLists.txt (100%) rename src/{tms9918 => }/vga/vga-modes.c (94%) rename src/{tms9918 => }/vga/vga-modes.h (69%) rename src/{tms9918 => }/vga/vga.c (96%) rename src/{tms9918 => }/vga/vga.h (90%) rename src/{tms9918 => }/vga/vga.pio (97%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2045efb..a76e43e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,4 +20,4 @@ target_link_libraries(${PROGRAM} PUBLIC vrEmuTms9918Util) add_subdirectory(pio-utils) -add_subdirectory(tms9918) +add_subdirectory(vga) diff --git a/src/main.c b/src/main.c index 0357244..f0d7f5f 100644 --- a/src/main.c +++ b/src/main.c @@ -120,7 +120,6 @@ static uint8_t __aligned(4) tmsScanlineBuffer[TMS9918_PIXELS_X]; */ void __time_critical_func(gpioExclusiveCallbackProc1)() { - sio_hw->gpio_oe_clr = GPIO_CD_MASK; uint32_t gpios = sio_hw->gpio_in; if ((gpios & GPIO_CSR_MASK) == 0) /* read? */ @@ -138,11 +137,11 @@ void __time_critical_func(gpioExclusiveCallbackProc1)() vrEmuTms9918ReadData(tms); } } - else if ((gpios & GPIO_CSW_MASK) == 0) /* write */ + else if ((gpios & GPIO_CSW_MASK) == 0) /* write? */ { uint8_t value = reversed[(sio_hw->gpio_in >> GPIO_CD0) & 0xff]; - if (gpios & GPIO_MODE_MASK) /* write register */ + if (gpios & GPIO_MODE_MASK) /* write register/address */ { vrEmuTms9918WriteAddr(tms, value); @@ -154,9 +153,15 @@ void __time_critical_func(gpioExclusiveCallbackProc1)() vrEmuTms9918WriteData(tms, value); } } + else /* both CSR and CSW are high (inactive). Go High-Z */ + { + sio_hw->gpio_oe_clr = GPIO_CD_MASK; + } + /* update read-ahead */ nextValue = reversed[vrEmuTms9918ReadDataNoInc(tms)] << GPIO_CD0; + /* interrupt handled */ iobank0_hw->intr[GPIO_CSR >> 3u] = iobank0_hw->proc1_irq_ctrl.ints[GPIO_CSR >> 3u]; } @@ -176,8 +181,8 @@ void proc1Entry() // set up gpio interrupts irq_set_exclusive_handler(IO_IRQ_BANK0, gpioExclusiveCallbackProc1); - gpio_set_irq_enabled(GPIO_CSW, GPIO_IRQ_EDGE_FALL, true); - gpio_set_irq_enabled(GPIO_CSR, GPIO_IRQ_EDGE_FALL, true); + gpio_set_irq_enabled(GPIO_CSW, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE, true); + gpio_set_irq_enabled(GPIO_CSR, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE, true); irq_set_enabled(IO_IRQ_BANK0, true); // wait until everything else is ready, then run the vga loop @@ -267,12 +272,18 @@ uint initClock(uint gpio, float freqHz) return clkSm; } - -/* main entry point */ +/* + * main entry point + */ int main(void) { + /* currently, VGA hard-coded to 640x480@60Hz. We want a high clock frequency + * that comes close to being divisible by 25.175MHz. 252.0 is close... enough :) + * I do have code which sets the best clock baased on the chosen VGA mode, + * but this'll do for now. */ set_sys_clock_khz(252000, false); + /* we need one of these. it's the main guy */ tms = vrEmuTms9918New(); /* set up the GPIO pins and interrupt handler */ @@ -282,7 +293,7 @@ int main(void) initClock(GPIO_GROMCL, TMS_CRYSTAL_FREQ_HZ / 24.0f); initClock(GPIO_CPUCL, TMS_CRYSTAL_FREQ_HZ / 3.0f); - /* Then set up VGA output */ + /* then set up VGA output */ VgaInitParams params = { 0 }; params.params = vgaGetParams(VGA_640_480_60HZ, 2); params.scanlineFn = tmsScanline; diff --git a/src/tms9918/CMakeLists.txt b/src/tms9918/CMakeLists.txt deleted file mode 100644 index 99dafad..0000000 --- a/src/tms9918/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -set(LIBRARY pico9918-tms9918) - -add_subdirectory(vga) - -project (${LIBRARY} C) - -set(CMAKE_C_STANDARD 11) - -add_library(${LIBRARY} STATIC tms9918.c) - -target_include_directories (${LIBRARY} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) - -target_link_libraries(${LIBRARY} PUBLIC - pico9918-vga - pico_stdlib - vrEmuTms9918 - vrEmuTms9918Util) \ No newline at end of file diff --git a/src/tms9918/tms9918.c b/src/tms9918/tms9918.c deleted file mode 100644 index 643a4ad..0000000 --- a/src/tms9918/tms9918.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Project: pico9918 - * - * Copyright (c) 2023 Troy Schrapel - * - * This code is licensed under the MIT license - * - * https://github.com/visrealm/pico9918 - * - */ - -#include "tms9918.h" -#include "vrEmuTms9918Util.h" - -#include "vga.h" -#include "vga-modes.h" - -#include "pico/stdlib.h" - -#include "pico/divider.h" - -static VrEmuTms9918* tms = NULL; -static vgaEndOfFrameFn eofCallback = NULL; -static vgaEndOfScanlineFn scanlineCallback = NULL; - -static uint16_t __aligned(4) tmsPal[16]; -static uint8_t __aligned(4) tmsScanlineBuffer[TMS9918_PIXELS_X]; - -/* - * convert 48-bit rgb to 12-bit bgr - */ -static uint16_t colorFromRgb(uint16_t r, uint16_t g, uint16_t b) -{ - return - ((uint16_t)(r / 16.0f) & 0x0f) | - (((uint16_t)(g / 16.0f) & 0x0f) << 4) | - (((uint16_t)(b / 16.0f) & 0x0f) << 8); -} - -/* - * vga scanline callback for tms9918 - */ -static void tmsScanline(uint16_t y, VgaParams* params, uint16_t* pixels) -{ - const uint32_t vBorder = (params->vVirtualPixels - TMS9918_PIXELS_Y) / 2; - const uint32_t hBorder = (params->hVirtualPixels - TMS9918_PIXELS_X) / 2; - - uint16_t bg = tmsPal[vrEmuTms9918RegValue(tms, TMS_REG_FG_BG_COLOR) & 0x0f]; - - // top or bottom border - if (y < vBorder || y >= (vBorder + TMS9918_PIXELS_Y)) - { - for (int x = 0; x < params->hVirtualPixels; ++x) - { - pixels[x] = bg; - } - return; - } - - y -= vBorder; - - // left border - for (int x = 0; x < hBorder; ++x) - { - pixels[x] = bg; - } - - // get scanline data from the tms9918 - vrEmuTms9918ScanLine(tms, y, tmsScanlineBuffer); - - // convert to our 12-bit palette and output to pixels array - int tmsX = 0; - for (int x = hBorder; x < hBorder + TMS9918_PIXELS_X; ++x, ++tmsX) - { - pixels[x] = tmsPal[tmsScanlineBuffer[tmsX]]; - } - - // right border - for (int x = hBorder + TMS9918_PIXELS_X; x < params->hVirtualPixels; ++x) - { - pixels[x] = bg; - } - - // interrupt? - if (y == TMS9918_PIXELS_Y - 1) - { - if ((vrEmuTms9918RegValue(tms, TMS_REG_1) & 0x20)) - { - //raiseInterrupt(1); - } - } -} - -/* - * set callback for end of frame events - */ -void tmsSetFrameCallback(vgaEndOfFrameFn cb) -{ - eofCallback = cb; -} - -/* - * set callback for end of scanline events - */ -void tmsSetHsyncCallback(vgaEndOfScanlineFn cb) -{ - scanlineCallback = cb; -} - -/* - * get vga horizontal frequency in Hz - */ -int tmsGetHsyncFreq() -{ - return vgaCurrentParams().params.hSyncParams.freqHz; -} - -/* - * vga end-of-frame callback for tms9918 - */ -static void tmsEndOfFrame(uint64_t frameNumber) -{ - if (eofCallback) eofCallback(frameNumber); -} - -/* - * vga end-of-scanline callback for tms9918 - */ -static void tmsEndOfScanline() -{ - if (scanlineCallback) scanlineCallback(); -} - -static const uint32_t MAX_CLOCK = 270000; - -void setClosestClockFreqKhz(uint32_t clockKHz) -{ - if (clockKHz > MAX_CLOCK) clockKHz = MAX_CLOCK; - - clockKHz /= 10; - clockKHz *= 10; - - uint32_t offset = 0; - while (!set_sys_clock_khz(clockKHz + offset, false)) { - offset += 10; - if (set_sys_clock_khz(clockKHz - offset, false)) break; - } -} - -/* - * tms9918 initialisation - */ -VrEmuTms9918* tmsInit() -{ - tms = vrEmuTms9918New(); - - // build up tms9918 palette optimized for 12-bit vga - for (int c = 0; c < 16; ++c) - { - uint32_t rgba8 = vrEmuTms9918Palette[c]; - tmsPal[c] = colorFromRgb( - (rgba8 & 0xff000000) >> 24, - (rgba8 & 0x00ff0000) >> 16, - (rgba8 & 0x0000ff00) >> 8); - } - - VgaInitParams params; - params.params = vgaGetParams(VGA_800_600_60HZ, 3); - params.scanlineFn = tmsScanline; - params.endOfFrameFn = tmsEndOfFrame; - params.endOfScanlineFn = tmsEndOfScanline; - - uint32_t minSysClockFreq = vgaMinimumPioClockKHz(¶ms.params); - uint32_t sysClockFreq = minSysClockFreq; - while (sysClockFreq + minSysClockFreq < MAX_CLOCK) - { - sysClockFreq += minSysClockFreq; - } - - setClosestClockFreqKhz(sysClockFreq); - - vgaInit(params); - - return tms; -} - -VrEmuTms9918* getTms9918() -{ - return tms; -} - -/* - * tms9918 destruction - */ -void tmsDestroy() -{ - if (tms) - { - vrEmuTms9918Destroy(tms); - tms = NULL; - } -} diff --git a/src/tms9918/tms9918.h b/src/tms9918/tms9918.h deleted file mode 100644 index 098f543..0000000 --- a/src/tms9918/tms9918.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Project: pico-56 - tms9918 - * - * Copyright (c) 2023 Troy Schrapel - * - * This code is licensed under the MIT license - * - * https://github.com/visrealm/pico-56 - * - */ - -#pragma once - -#include "vrEmuTms9918.h" -#include "vga.h" - -#include - -VrEmuTms9918* tmsInit(); -VrEmuTms9918* getTms9918(); - -void tmsSetFrameCallback(vgaEndOfFrameFn cb); -void tmsSetHsyncCallback(vgaEndOfScanlineFn cb); - -int tmsGetHsyncFreq(); - -void tmsDestroy(); \ No newline at end of file diff --git a/src/tms9918/vga/CMakeLists.txt b/src/vga/CMakeLists.txt similarity index 100% rename from src/tms9918/vga/CMakeLists.txt rename to src/vga/CMakeLists.txt diff --git a/src/tms9918/vga/vga-modes.c b/src/vga/vga-modes.c similarity index 94% rename from src/tms9918/vga/vga-modes.c rename to src/vga/vga-modes.c index dde9b8b..bd05790 100644 --- a/src/tms9918/vga/vga-modes.c +++ b/src/vga/vga-modes.c @@ -1,11 +1,11 @@ /* - * Project: pico-56 - vga + * Project: pico9918 - vga * - * Copyright (c) 2023 Troy Schrapel + * Copyright (c) 2024 Troy Schrapel * * This code is licensed under the MIT license * - * https://github.com/visrealm/pico-56 + * https://github.com/visrealm/pico9918 * */ diff --git a/src/tms9918/vga/vga-modes.h b/src/vga/vga-modes.h similarity index 69% rename from src/tms9918/vga/vga-modes.h rename to src/vga/vga-modes.h index e7f36c9..3fb1114 100644 --- a/src/tms9918/vga/vga-modes.h +++ b/src/vga/vga-modes.h @@ -1,11 +1,11 @@ /* - * Project: pico-56 - vga + * Project: pico9918 - vga * - * Copyright (c) 2023 Troy Schrapel + * Copyright (c) 2024 Troy Schrapel * * This code is licensed under the MIT license * - * https://github.com/visrealm/pico-56 + * https://github.com/visrealm/pico9918 * */ diff --git a/src/tms9918/vga/vga.c b/src/vga/vga.c similarity index 96% rename from src/tms9918/vga/vga.c rename to src/vga/vga.c index 0f4b7e3..b052975 100644 --- a/src/tms9918/vga/vga.c +++ b/src/vga/vga.c @@ -1,11 +1,11 @@ /* - * Project: pico-56 - vga + * Project: pico9918 - vga * - * Copyright (c) 2023 Troy Schrapel + * Copyright (c) 2024 Troy Schrapel * * This code is licensed under the MIT license * - * https://github.com/visrealm/pico-56 + * https://github.com/visrealm/pico9918 * */ diff --git a/src/tms9918/vga/vga.h b/src/vga/vga.h similarity index 90% rename from src/tms9918/vga/vga.h rename to src/vga/vga.h index 7a665f9..94be64c 100644 --- a/src/tms9918/vga/vga.h +++ b/src/vga/vga.h @@ -1,7 +1,7 @@ /* - * Project: pico-56 - vga + * Project: pico9918 - vga * - * Copyright (c) 2023 Troy Schrapel + * Copyright (c) 2024 Troy Schrapel * * This code is licensed under the MIT license * diff --git a/src/tms9918/vga/vga.pio b/src/vga/vga.pio similarity index 97% rename from src/tms9918/vga/vga.pio rename to src/vga/vga.pio index 4c3818d..1aa4dca 100644 --- a/src/tms9918/vga/vga.pio +++ b/src/vga/vga.pio @@ -1,7 +1,7 @@ /* - * Project: pico-56 + * Project: pico9918 * - * Copyright (c) 2023 Troy Schrapel + * Copyright (c) 2024 Troy Schrapel * * This code is licensed under the MIT license *