From beb927aef38e05dc19183288a873ad878d206d39 Mon Sep 17 00:00:00 2001 From: Polprzewodnikowy Date: Fri, 20 May 2022 00:31:45 +0200 Subject: [PATCH] cic 64dd support --- build.sh | 2 +- fw/{ftdi_template.xml => ft232h_config.xml} | Bin sw/bootloader/src/exception.c | 2 - sw/bootloader/src/init.c | 6 +++ sw/bootloader/src/sc64.c | 1 - sw/bootloader/tools/asset_converter.py | 45 +++++++++++--------- sw/controller/src/cic.c | 27 +++++++----- 7 files changed, 47 insertions(+), 36 deletions(-) rename fw/{ftdi_template.xml => ft232h_config.xml} (100%) diff --git a/build.sh b/build.sh index c2fcf82..54aa9eb 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ set -e PACKAGE_FILE_NAME="SC64" FILES=( - "./fw/ftdi-template.xml" + "./fw/ft232h_config.xml" "./fw/project/lcmxo2/impl1/sc64_impl1.bit" "./fw/project/lcmxo2/impl1/sc64_impl1.jed" "./sw/bootloader/build/bootloader.bin" diff --git a/fw/ftdi_template.xml b/fw/ft232h_config.xml similarity index 100% rename from fw/ftdi_template.xml rename to fw/ft232h_config.xml diff --git a/sw/bootloader/src/exception.c b/sw/bootloader/src/exception.c index f0fac11..af678af 100644 --- a/sw/bootloader/src/exception.c +++ b/sw/bootloader/src/exception.c @@ -34,7 +34,6 @@ static const vi_regs_t vi_config[] = {{ VI_CR_PIXEL_ADVANCE_0 | VI_CR_ANTIALIAS_1 | VI_CR_ANTIALIAS_0 | - VI_CR_GAMMA_ON | VI_CR_TYPE_32 ), .H_WIDTH = SCREEN_WIDTH, @@ -55,7 +54,6 @@ static const vi_regs_t vi_config[] = {{ VI_CR_PIXEL_ADVANCE_0 | VI_CR_ANTIALIAS_1 | VI_CR_ANTIALIAS_0 | - VI_CR_GAMMA_ON | VI_CR_TYPE_32 ), .H_WIDTH = SCREEN_WIDTH, diff --git a/sw/bootloader/src/init.c b/sw/bootloader/src/init.c index 84c3cee..270760f 100644 --- a/sw/bootloader/src/init.c +++ b/sw/bootloader/src/init.c @@ -1,3 +1,4 @@ +#include "error.h" #include "exception.h" #include "io.h" #include "sc64.h" @@ -8,6 +9,11 @@ void init (void) { si_io_write((io32_t *) (&PIFRAM[0x3C]), pifram | 0x08); exception_install(); + + if (!sc64_check_presence()) { + error_display("SC64 hardware not detected"); + } + exception_enable_watchdog(); exception_enable_interrupts(); diff --git a/sw/bootloader/src/sc64.c b/sw/bootloader/src/sc64.c index 12044a2..20103d9 100644 --- a/sw/bootloader/src/sc64.c +++ b/sw/bootloader/src/sc64.c @@ -50,7 +50,6 @@ void sc64_get_info (sc64_info_t *info) { } void sc64_init (void) { - while (!sc64_check_presence()); sc64_change_config(CFG_ID_BOOTLOADER_SWITCH, false); } diff --git a/sw/bootloader/tools/asset_converter.py b/sw/bootloader/tools/asset_converter.py index 67c1893..7341eb2 100644 --- a/sw/bootloader/tools/asset_converter.py +++ b/sw/bootloader/tools/asset_converter.py @@ -5,27 +5,30 @@ from PIL import Image -if (len(sys.argv) != 3): - print(f"Usage: python {sys.argv[0]} input_path output_path") - exit(-1) +if __name__ == "__main__": + if (len(sys.argv) != 3): + print(f"Usage: python {sys.argv[0]} input_path output_path") + sys.exit(1) -asset_input = sys.argv[1] -asset_output = sys.argv[2] + asset_input = sys.argv[1] + asset_output = sys.argv[2] -source_asset = None -final_asset = None + source_asset = None + final_asset = None -try: - source_asset = Image.open(asset_input) - converted_asset = source_asset.convert("RGBA") - final_asset = open(asset_output, "wb") - final_asset.write(converted_asset.tobytes()) -except FileNotFoundError: - print(f"Couldn't open file \"{asset_input}\"") -except Exception as e: - print(e) -finally: - if (source_asset): - source_asset.close() - if (final_asset): - final_asset.close() + try: + source_asset = Image.open(asset_input) + converted_asset = source_asset.convert("RGBA") + final_asset = open(asset_output, "wb") + final_asset.write(converted_asset.tobytes()) + except FileNotFoundError: + print(f"Couldn't open file \"{asset_input}\"") + sys.exit(2) + except Exception as e: + print(e) + sys.exit(3) + finally: + if (source_asset): + source_asset.close() + if (final_asset): + final_asset.close() diff --git a/sw/controller/src/cic.c b/sw/controller/src/cic.c index 42bfe9d..2eb696b 100644 --- a/sw/controller/src/cic.c +++ b/sw/controller/src/cic.c @@ -12,6 +12,7 @@ typedef enum { static volatile bool cic_enabled = false; +static volatile bool cic_detect_enabled; static volatile uint8_t cic_next_rd; static volatile uint8_t cic_next_wr; @@ -54,6 +55,12 @@ static void cic_irq_clk_falling (void) { static void cic_irq_clk_rising (void) { hw_gpio_set(GPIO_ID_N64_CIC_DQ); + if (cic_detect_enabled) { + cic_detect_enabled = false; + if (!hw_gpio_get(GPIO_ID_N64_CIC_DQ)) { + cic_enabled = false; + } + } } static uint8_t cic_read (void) { @@ -67,6 +74,10 @@ static void cic_write (uint8_t bit) { task_yield(); } +static void cic_start_detect (void) { + cic_detect_enabled = cic_dd_mode; +} + static uint8_t cic_read_nibble (void) { uint8_t data = 0; for (int i = 0; i < 4; i++) { @@ -97,17 +108,11 @@ static void cic_encode_round (uint8_t index) { } static void cic_write_id (cic_region_t region) { - uint8_t id = 0x01; - - if (cic_dd_mode) { - id |= 0x08; - } - - if (region == REGION_PAL) { - id |= 0x04; - } - - cic_write_nibble(id); + cic_start_detect(); + cic_write(cic_dd_mode ? 1 : 0); + cic_write(region == REGION_PAL ? 1 : 0); + cic_write(0); + cic_write(1); } static void cic_write_id_failed (void) {