From 5d4f3be61974a899a37206c0fecd8456fe2aa66f Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Mon, 6 Feb 2023 20:48:44 +0100 Subject: [PATCH] [SC64][SW] Added option for setting CIC parameters through sc64.py script --- docs/02_usb_commands.md | 2 +- docs/04_config_options.md | 7 +++---- sw/controller/src/cfg.c | 2 +- sw/pc/sc64.py | 13 +++++++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/02_usb_commands.md b/docs/02_usb_commands.md index f104672..6eb64e2 100644 --- a/docs/02_usb_commands.md +++ b/docs/02_usb_commands.md @@ -8,7 +8,7 @@ | --- | ---------------------- | ------------ | ------------ | ---- | ---------------- | --------------------------------------------------- | | `v` | **VERSION_GET** | --- | --- | --- | api_version | Get command API version | | `R` | **STATE_RESET** | --- | --- | --- | --- | Reset entire flashcart state | -| `B` | **CIC_PARAMS_SET** | cic_params_0 | cic_params_1 | --- | --- | Set CIC mode/seed/version/checksum | +| `B` | **CIC_PARAMS_SET** | cic_params_0 | cic_params_1 | --- | --- | Set CIC disable/mode/seed/checksum | | `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option | | `C` | **CONFIG_SET** | config_id | new_value | --- | --- | Set config option | | `t` | **TIME_GET** | --- | --- | --- | time | Get current RTC value | diff --git a/docs/04_config_options.md b/docs/04_config_options.md index 89b5538..62344a6 100644 --- a/docs/04_config_options.md +++ b/docs/04_config_options.md @@ -138,11 +138,10 @@ Any successful write to this config will disable automatic save writeback to SD type: *word* | default: `0xFFFF` -- `0x0000` to `0x01FF` - Specified CIC seed/version value will be used -- `0xFFFF` - CIC seed/version value will be autodetected +- `0x0000` to `0x00FF` - Specified CIC seed value will be used +- `0xFFFF` - CIC seed value will be autodetected -Use this setting to force specific CIC seed/version. -Lower 8 bits represents CIC seed and 9th bit represents CIC version. +Use this setting to force specific CIC seed. By setting value `0xFFFF` bootloader will try to guess needed values from loaded ROM IPL3. This setting is not used when **BOOT_MODE** is set to `3` (direct boot). diff --git a/sw/controller/src/cfg.c b/sw/controller/src/cfg.c index 25eb5a1..3225a5e 100644 --- a/sw/controller/src/cfg.c +++ b/sw/controller/src/cfg.c @@ -320,7 +320,7 @@ bool cfg_update (uint32_t *args) { return cfg_set_save_type((save_type_t) (args[1])); break; case CFG_ID_CIC_SEED: - if ((args[1] != 0xFFFF) && (args[1] > 0x1FF)) { + if ((args[1] != 0xFFFF) && (args[1] > 0xFF)) { return true; } p.cic_seed = (cic_seed_t) (args[1] & 0xFFFF); diff --git a/sw/pc/sc64.py b/sw/pc/sc64.py index d097c43..d0f808c 100755 --- a/sw/pc/sc64.py +++ b/sw/pc/sc64.py @@ -750,6 +750,7 @@ if __name__ == '__main__': parser.add_argument('--boot', type=SC64.BootMode, action=EnumAction, help='set boot mode') parser.add_argument('--tv', type=SC64.TVType, action=EnumAction, help='force TV type to set value') parser.add_argument('--cic', type=SC64.CICSeed, action=EnumAction, help='force CIC seed to set value') + parser.add_argument('--cic-params', metavar='disabled,dd_mode,seed,checksum', help='set CIC emulation parameters') parser.add_argument('--rtc', action='store_true', help='update clock in SC64 to system time') parser.add_argument('--no-shadow', action='store_false', help='do not put last 128 kB of ROM inside flash memory (can corrupt non EEPROM saves)') parser.add_argument('--rom', metavar='file', help='upload ROM from specified file') @@ -841,6 +842,18 @@ if __name__ == '__main__': sc64.upload_ddipl(f.read()) print('done') + if (args.cic_params != None): + # TODO: calculate checksum in script + params = args.cic_params.split(',') + if (len(params) != 4): + raise ValueError('Incorrect number of CIC parameters') + disabled = (params[0] != '0') + dd_mode = (params[1] != '0') + seed = int(params[2]) + checksum = int(params[3]).to_bytes(6, byteorder='big', signed=False) + sc64.set_cic_parameters(disabled, dd_mode, seed, checksum) + print(f'CIC parameters set to [{"DISABLED, " if disabled else ""}{"DDIPL" if dd_mode else "ROM"}, seed: 0x{seed:02X}, checksum: 0x{int(params[3]):12X}]') + if (args.debug): sc64.debug_loop(isv=args.isv, disks=args.disk)