diff --git a/menu.cpp b/menu.cpp index decb6b1..654f0d1 100644 --- a/menu.cpp +++ b/menu.cpp @@ -646,7 +646,6 @@ void HandleUI(void) unsigned char m, up, down, select, menu, right, left, plus, minus; uint8_t mod; unsigned long len; - static hardfileTYPE t_hardfile[2]; // temporary copy of former hardfile configuration char enable; static int reboot_req = 0; static long helptext_timer; @@ -2086,8 +2085,6 @@ void HandleUI(void) } else if (menusub == 5) // Go to harddrives page. { - t_hardfile[0] = config.hardfile[0]; - t_hardfile[1] = config.hardfile[1]; menustate = MENU_SETTINGS_HARDFILE1; menusub = 0; } @@ -2656,51 +2653,40 @@ void HandleUI(void) OsdSetTitle("Harddisks", OSD_ARROW_LEFT | OSD_ARROW_RIGHT); parentstate = menustate; - menumask = 0x21; // b00100001 - On/off & exit enabled by default... - if (config.enable_ide) - menumask |= 0x0a; // b00001010 - HD0 and HD1 type + menumask = 0x201; // b001000000001 - On/off & exit enabled by default... + if (config.enable_ide) menumask |= 0xAA; // b010101010 - HD0/1/2/3 type OsdWrite(0, "", 0, 0); - strcpy(s, " A600/A1200 IDE : "); - strcat(s, config.enable_ide ? "on " : "off"); + strcpy(s, " A600/A1200 IDE : "); + strcat(s, config.enable_ide ? "On " : "Off"); OsdWrite(1, s, menusub == 0, 0); OsdWrite(2, "", 0, 0); - strcpy(s, " Master : "); - strcat(s, config.hardfile[0].enabled ? "Enabled" : "Disabled"); - OsdWrite(3, s, config.enable_ide ? (menusub == 1) : 0, config.enable_ide == 0); - if (config.hardfile[0].filename[0]) { - strcpy(s, " "); - strncpy(&s[7], config.hardfile[0].filename, 21); + int n = 3, m = 1, t = 4; + for (int i = 0; i < 4; i++) + { + strcpy(s, (i & 2) ? " Secondary " : " Primary "); + strcat(s, (i & 1) ? "Slave: " : "Master: "); + strcat(s, config.hardfile[i].enabled ? "Enabled" : "Disabled"); + OsdWrite(n++, s, config.enable_ide ? (menusub == m++) : 0, config.enable_ide == 0); + if (config.hardfile[i].filename[0]) + { + strcpy(s, " "); + strncpy(&s[7], config.hardfile[i].filename, 21); + } + else + { + strcpy(s, " ** not selected **"); + } + enable = config.enable_ide && config.hardfile[i].enabled; + if (enable) menumask |= t; // Make hardfile selectable + OsdWrite(n++, s, menusub == m++, enable == 0); + t <<= 2; + OsdWrite(n++, "", 0, 0); + } } - else - { - strcpy(s, " ** not selected **"); - } - enable = config.enable_ide && config.hardfile[0].enabled; - if (enable) menumask |= 0x04; // Make hardfile selectable - OsdWrite(4, s, enable ? (menusub == 2) : 0, enable == 0); - - OsdWrite(5, "", 0, 0); - strcpy(s, " Slave : "); - strcat(s, config.hardfile[1].enabled ? "Enabled" : "Disabled"); - OsdWrite(6, s, config.enable_ide ? (menusub == 3) : 0, config.enable_ide == 0); - if (config.hardfile[1].filename[0]) - { - strcpy(s, " "); - strncpy(&s[7], config.hardfile[1].filename, 21); - } - else - { - strcpy(s, " ** not selected **"); - } - enable = config.enable_ide && config.hardfile[1].enabled; - if (enable) menumask |= 0x10; // Make hardfile selectable - OsdWrite(7, s, enable ? (menusub == 4) : 0, enable == 0); - - for (int i = 8; i < OsdGetSize() - 1; i++) OsdWrite(i, "", 0, 0); - OsdWrite(OsdGetSize() - 1, STD_EXIT, menusub == 5, 0); + OsdWrite(OsdGetSize() - 1, STD_EXIT, menusub == 9, 0); menustate = MENU_SETTINGS_HARDFILE2; break; @@ -2712,25 +2698,20 @@ void HandleUI(void) config.enable_ide = (config.enable_ide == 0); menustate = MENU_SETTINGS_HARDFILE1; } - if (menusub == 1) + else if (menusub < 9) { - config.hardfile[0].enabled = config.hardfile[0].enabled ? 0 : 1; - menustate = MENU_SETTINGS_HARDFILE1; + if(menusub&1) + { + int num = (menusub - 1) / 2; + config.hardfile[num].enabled = config.hardfile[num].enabled ? 0 : 1; + menustate = MENU_SETTINGS_HARDFILE1; + } + else + { + SelectFile("HDFVHDIMGDSK", SCAN_DIR | SCAN_UMOUNT, MENU_HARDFILE_SELECTED, MENU_SETTINGS_HARDFILE1, 1); + } } - else if (menusub == 2) - { - SelectFile("HDFVHDIMGDSK", SCAN_DIR | SCAN_UMOUNT, MENU_HARDFILE_SELECTED, MENU_SETTINGS_HARDFILE1, 1); - } - else if (menusub == 3) - { - config.hardfile[1].enabled = config.hardfile[1].enabled ? 0 : 1; - menustate = MENU_SETTINGS_HARDFILE1; - } - else if (menusub == 4) - { - SelectFile("HDFVHDIMGDSK", SCAN_DIR | SCAN_UMOUNT, MENU_HARDFILE_SELECTED, MENU_SETTINGS_HARDFILE1, 1); - } - else if (menusub == 5) // return to previous menu + else if (menusub == 9) // return to previous menu { menustate = MENU_MAIN1; menusub = 5; @@ -2758,21 +2739,12 @@ void HandleUI(void) /* hardfile selected menu */ /******************************************************************/ case MENU_HARDFILE_SELECTED: - if (menusub == 2) // master drive selected { + int num = (menusub - 2) / 2; int len = strlen(SelectedPath); - if (len > sizeof(config.hardfile[0].filename) - 1) len = sizeof(config.hardfile[0].filename) - 1; - if(len) memcpy(config.hardfile[0].filename, SelectedPath, len); - config.hardfile[0].filename[len] = 0; - menustate = MENU_SETTINGS_HARDFILE1; - } - else - if (menusub == 4) // slave drive selected - { - int len = strlen(SelectedPath); - if (len > sizeof(config.hardfile[1].filename) - 1) len = sizeof(config.hardfile[1].filename) - 1; - if (len) memcpy(config.hardfile[1].filename, SelectedPath, len); - config.hardfile[1].filename[len] = 0; + if (len > sizeof(config.hardfile[num].filename) - 1) len = sizeof(config.hardfile[num].filename) - 1; + if(len) memcpy(config.hardfile[num].filename, SelectedPath, len); + config.hardfile[num].filename[len] = 0; menustate = MENU_SETTINGS_HARDFILE1; } break; diff --git a/minimig_config.cpp b/minimig_config.cpp index 8d6b134..69757d8 100644 --- a/minimig_config.cpp +++ b/minimig_config.cpp @@ -15,6 +15,24 @@ #include "user_io.h" #include "input.h" +typedef struct +{ + char id[8]; + unsigned long version; + char kickstart[1024]; + filterTYPE filter; + unsigned char memory; + unsigned char chipset; + floppyTYPE floppy; + unsigned char disable_ar3; + unsigned char enable_ide; + unsigned char scanlines; + unsigned char audio; + hardfileTYPE hardfile[2]; + unsigned char cpu; + unsigned char autofire; +} configTYPE_old; + configTYPE config = { 0 }; unsigned char romkey[3072]; @@ -257,16 +275,18 @@ static void ApplyConfiguration(char reloadkickstart) printf("\n"); - printf("\nA600/A1200 IDE is %s.\n", config.enable_ide ? "enabled" : "disabled"); + printf("\nIDE state: %s.\n", config.enable_ide ? "enabled" : "disabled"); if (config.enable_ide) { - printf("Master HDD is %s.\n", config.hardfile[0].enabled ? "enabled" : "disabled"); - printf("Slave HDD is %s.\n", config.hardfile[1].enabled ? "enabled" : "disabled"); + printf("Primary Master HDD is %s.\n", config.hardfile[0].enabled ? "enabled" : "disabled"); + printf("Primary Slave HDD is %s.\n", config.hardfile[1].enabled ? "enabled" : "disabled"); + printf("Secondary Master HDD is %s.\n", config.hardfile[2].enabled ? "enabled" : "disabled"); + printf("Secondary Slave HDD is %s.\n", config.hardfile[3].enabled ? "enabled" : "disabled"); } rstval = SPI_CPU_HLT; spi_osd_cmd8(OSD_CMD_RST, rstval); - spi_osd_cmd8(OSD_CMD_HDD, (config.enable_ide ? 1 : 0) | (OpenHardfile(0) ? 2 : 0) | (OpenHardfile(1) ? 4 : 0)); + spi_osd_cmd8(OSD_CMD_HDD, (config.enable_ide ? 1 : 0) | (OpenHardfile(0) ? 2 : 0) | (OpenHardfile(1) ? 4 : 0) | (OpenHardfile(2) ? 8 : 0) | (OpenHardfile(3) ? 16 : 0)); ConfigMemory(config.memory); ConfigCPU(config.cpu); @@ -319,7 +339,6 @@ unsigned char LoadConfiguration(int num) char updatekickstart = 0; char result = 0; unsigned char key, i; - static configTYPE tmpconf; static char filename[256]; SET_CONFIG_NAME(filename, num); @@ -332,6 +351,7 @@ unsigned char LoadConfiguration(int num) printf("Configuration file size: %s, %lu\n", filename, size); if (size == sizeof(config)) { + static configTYPE tmpconf; if (FileLoadConfig(filename, &tmpconf, sizeof(tmpconf))) { // check file id and version @@ -352,6 +372,34 @@ unsigned char LoadConfiguration(int num) } else printf("Cannot load configuration file\n"); } + else if (size == sizeof(configTYPE_old)) + { + static configTYPE_old tmpconf; + printf("Old Configuration file.\n"); + if (FileLoadConfig(filename, &tmpconf, sizeof(tmpconf))) + { + // check file id and version + if (strncmp(tmpconf.id, config_id, sizeof(config.id)) == 0) { + // A few more sanity checks... + if (tmpconf.floppy.drives <= 4) { + // If either the old config and new config have a different kickstart file, + // or this is the first boot, we need to upload a kickstart image. + if (strcmp(tmpconf.kickstart, config.kickstart) != 0) { + updatekickstart = true; + } + memcpy((void*)&config, (void*)&tmpconf, sizeof(config)); + config.cpu = tmpconf.cpu; + config.autofire = tmpconf.autofire; + memset(&config.hardfile[2], 0, sizeof(config.hardfile[2])); + memset(&config.hardfile[3], 0, sizeof(config.hardfile[3])); + result = 1; // We successfully loaded the config. + } + else BootPrint("Config file sanity check failed!\n"); + } + else BootPrint("Wrong configuration file format!\n"); + } + else printf("Cannot load configuration file\n"); + } else printf("Wrong configuration file size: %lu (expected: %lu)\n", size, sizeof(config)); } if (!result) { diff --git a/minimig_config.h b/minimig_config.h index 6dcc8b1..801bf07 100644 --- a/minimig_config.h +++ b/minimig_config.h @@ -36,7 +36,7 @@ typedef struct unsigned char enable_ide; unsigned char scanlines; unsigned char audio; - hardfileTYPE hardfile[2]; + hardfileTYPE hardfile[4]; unsigned char cpu; unsigned char autofire; } configTYPE; diff --git a/minimig_hdd.cpp b/minimig_hdd.cpp index c86c20d..d94f689 100644 --- a/minimig_hdd.cpp +++ b/minimig_hdd.cpp @@ -71,7 +71,7 @@ typedef struct long offset; // if a partition, the lba offset of the partition. Can be negative if we've synthesized an RDB. } hdfTYPE; -hdfTYPE hdf[2] = { 0 }; +static hdfTYPE hdf[4] = { 0 }; static uint8_t sector_buffer[512]; @@ -161,7 +161,8 @@ static void FakeRDB(int unit, int block) pb->pb_Next = 0xffffffff; pb->pb_Flags = 0x1; // bootable pb->pb_DevFlags = 0; - strcpy(pb->pb_DriveName, unit ? "1HD\003" : "0HD\003"); // "DH0"/"DH1" BCPL string + strcpy(pb->pb_DriveName, "0HD\003"); // "DHx" BCPL string + pb->pb_DriveName[0] = unit + '0'; pb->pb_Environment.de_TableSize = 0x10; pb->pb_Environment.de_SizeBlock = 0x80; pb->pb_Environment.de_Surfaces = hdf[unit].heads; @@ -213,7 +214,7 @@ static void IdentifyDevice(unsigned short *pBuffer, unsigned char unit) else { memcpy(p, "MiSTer ", 40); // model name - byte swapped - p += 7; + p += 8; char *s = strrchr(config.hardfile[unit].filename, '/'); if (s) s++; else s = config.hardfile[unit].filename; @@ -618,7 +619,7 @@ void HandleHDD(unsigned char c1, unsigned char c2) { if (c1 & CMD_IDECMD) { - unsigned char unit; + unsigned char unit = 0; unsigned char tfr[8]; DISKLED_ON; @@ -626,11 +627,19 @@ void HandleHDD(unsigned char c1, unsigned char c2) spi_w(CMD_IDE_REGS_RD<<8); // read task file registers spi_w(0); spi_w(0); - for (int i = 0; i < 8; i++) tfr[i] = (uint8_t)spi_w(0); + + //printf("SPI:"); + for (int i = 0; i < 8; i++) + { + uint16_t tmp = spi_w(0); + tfr[i] = (uint8_t)tmp; + if (i == 6) unit = ((tmp >> 7) & 2) | ((tmp >> 4) & 1); + //printf(" %03X", tmp); + } + //printf(" -> unit: %d\n", unit); DisableFpga(); - unit = tfr[6] & 0x10 ? 1 : 0; // master/slave selection - if (0) hdd_debugf("IDE%d: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X", unit, tfr[0], tfr[1], tfr[2], tfr[3], tfr[4], tfr[5], tfr[6], tfr[7]); + //printf("IDE%d: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X\n", unit, tfr[0], tfr[1], tfr[2], tfr[3], tfr[4], tfr[5], tfr[6], tfr[7]); if ((tfr[7] & 0xF0) == ACMD_RECALIBRATE) ATA_Recalibrate(tfr, unit); else if (tfr[7] == ACMD_DIAGNOSTIC) ATA_Diagnostic(tfr); @@ -643,8 +652,7 @@ void HandleHDD(unsigned char c1, unsigned char c2) else if (tfr[7] == ACMD_WRITE_MULTIPLE) ATA_WriteMultiple(tfr, unit); else { - hdd_debugf("Unknown ATA command"); - hdd_debugf("IDE%d: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X", unit, tfr[0], tfr[1], tfr[2], tfr[3], tfr[4], tfr[5], tfr[6], tfr[7]); + printf("Unknown ATA command: IDE%d: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X\n", unit, tfr[0], tfr[1], tfr[2], tfr[3], tfr[4], tfr[5], tfr[6], tfr[7]); WriteTaskFile(0x04, tfr[2], tfr[3], tfr[4], tfr[5], tfr[6]); WriteStatus(IDE_STATUS_END | IDE_STATUS_IRQ | IDE_STATUS_ERR); }