1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-04-24 19:50:31 +00:00

IDE: add secondary channel, support up to 4 drives

This commit is contained in:
Gyorgy Szombathelyi
2021-06-06 00:35:15 +02:00
parent be6258aeb2
commit 848848ba3c
8 changed files with 104 additions and 86 deletions

View File

@@ -215,7 +215,7 @@ char UploadActionReplay()
data = 0xff; // key, 1 byte
SPI((data>>0)&0xff);
SPIN(); SPIN(); SPIN(); SPIN();
data = config.enable_ide ? 0xff : 0; // ide, 1 byte
data = config.enable_ide[0] ? 0xff : 0; // ide, 1 byte
SPI((data>>0)&0xff);
SPIN(); SPIN(); SPIN(); SPIN();
data = 0xff; // a1200, 1 byte
@@ -312,7 +312,7 @@ unsigned char LoadConfiguration(char *filename, int printconfig)
// load configuration data
if (FileOpenCompat(&file, filename, FA_READ) == FR_OK) {
BootPrint("Opened configuration file\n");
iprintf("Configuration file size: %lu\r", f_size(&file));
iprintf("Configuration file size: %llu\r", f_size(&file));
if (f_size(&file) == sizeof(config)) {
FileReadBlock(&file, sector_buffer);
configTYPE *tmpconf=(configTYPE *)&sector_buffer;
@@ -350,7 +350,8 @@ unsigned char LoadConfiguration(char *filename, int printconfig)
config.chipset = 0;
config.floppy.speed=CONFIG_FLOPPY2X;
config.floppy.drives=1;
config.enable_ide=0;
config.enable_ide[0]=0;
config.enable_ide[1]=0;
config.hardfile[0].enabled = 1;
strncpy(config.hardfile[0].name, "HARDFILE", sizeof(config.hardfile[0].name));
strncpy(config.hardfile[1].name, "HARDFILE", sizeof(config.hardfile[1].name));
@@ -440,11 +441,11 @@ static void ApplyConfiguration(char reloadkickstart)
char idxfail = 0;
hardfile[0] = &config.hardfile[0];
hardfile[1] = &config.hardfile[1];
for (int i = 0; i < HARDFILES; i++)
hardfile[i] = &config.hardfile[i];
// Whether or not we uploaded a kickstart image we now need to set various parameters from the config.
for (int i = 0; i <= 1; i++) {
for (int i = 0; i < HARDFILES; i++) {
if(OpenHardfile(i)) {
switch(hdf[i].type) {
// Customise message for SD card acces
@@ -474,7 +475,8 @@ static void ApplyConfiguration(char reloadkickstart)
if (idxfail)
BootPrintEx("Warning! Indexing failed for a hardfile, continuing without indices.");
ConfigIDE(config.enable_ide, config.hardfile[0].present && config.hardfile[0].enabled, config.hardfile[1].present && config.hardfile[1].enabled);
ConfigIDE(config.enable_ide[0], config.hardfile[0].present && config.hardfile[0].enabled, config.hardfile[1].present && config.hardfile[1].enabled);
ConfigIDE(config.enable_ide[1] | 0x02, config.hardfile[2].present && config.hardfile[2].enabled, config.hardfile[3].present && config.hardfile[3].enabled);
siprintf(s, "CPU clock : %s", config.chipset & 0x01 ? "turbo" : "normal");
BootPrint(s);
@@ -492,12 +494,14 @@ static void ApplyConfiguration(char reloadkickstart)
BootPrint("");
siprintf(s, "\nA600 IDE HDC is %s.", config.enable_ide ? "enabled" : "disabled");
BootPrint(s);
siprintf(s, "Master HDD is %s.", config.hardfile[0].present ? config.hardfile[0].enabled ? "enabled" : "disabled" : "not present");
BootPrint(s);
siprintf(s, "Slave HDD is %s.", config.hardfile[1].present ? config.hardfile[1].enabled ? "enabled" : "disabled" : "not present");
siprintf(s, "\nA600 IDE HDC is %s/%s.", config.enable_ide[0] ? "enabled" : "disabled", config.enable_ide[1] ? "enabled" : "disabled");
BootPrint(s);
for (int i = 0; i < HARDFILES; i++) {
siprintf(s, "%s %s HDD is %s.",
(i & 0x02) ? "Secondary" : "Primary", (i & 0x01) ? "Slave" : "Master",
config.hardfile[i].present ? config.hardfile[i].enabled ? "enabled" : "disabled" : "not present");
BootPrint(s);
}
#if 0
if (cluster_size < 64) {

View File

@@ -23,10 +23,10 @@ typedef struct
unsigned char chipset;
floppyTYPE floppy;
unsigned char disable_ar3;
unsigned char enable_ide;
unsigned char enable_ide[2];
unsigned char scanlines;
unsigned char pad1;
hardfileTYPE hardfile[2];
hardfileTYPE hardfile[HARDFILES];
unsigned char cpu;
unsigned char autofire;
} configTYPE;

10
hdd.c
View File

@@ -44,10 +44,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define SWAP(a) ((((a)&0x000000ff)<<24)|(((a)&0x0000ff00)<<8)|(((a)&0x00ff0000)>>8)|(((a)&0xff000000)>>24))
hardfileTYPE *hardfile[2];
hardfileTYPE *hardfile[HARDFILES];
// hardfile structure
hdfTYPE hdf[2];
hdfTYPE hdf[HARDFILES];
static void SwapBytes(char *c, unsigned int len)
{
@@ -581,6 +581,7 @@ void HandleHDD(unsigned char c1, unsigned char c2)
unsigned char unit;
unsigned short sector_count;
unsigned char lbamode;
unsigned char cs1;
if (c1 & CMD_IDECMD) {
DISKLED_ON;
@@ -592,11 +593,12 @@ void HandleHDD(unsigned char c1, unsigned char c2)
SPI(0x00);
SPI(0x00);
for (i = 0; i < 8; i++) {
SPI(0);
tfr[i] = SPI(0);
if (i == 6) cs1 = tfr[i] & 0x01;
tfr[i] = SPI(0);
}
DisableFpga();
unit = tfr[6] & 0x10 ? 1 : 0; // master/slave selection
unit = (cs1 << 1) | ((tfr[6] & 0x10) >> 4); // primary/secondary/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]);
if (!hardfile[unit]->present) {

6
hdd.h
View File

@@ -47,6 +47,8 @@
#define HDF_FILETYPE_RDB 2
#define HDF_FILETYPE_DOS 3
#define HARDFILES 4
// types
typedef struct
{
@@ -68,8 +70,8 @@ typedef struct
} hdfTYPE;
// variables
extern hardfileTYPE *hardfile[2];
extern hdfTYPE hdf[2];
extern hardfileTYPE *hardfile[HARDFILES];
extern hdfTYPE hdf[HARDFILES];
// functions
void HandleHDD(unsigned char c1, unsigned char c2);

2
main.c
View File

@@ -66,8 +66,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
const char version[] = {"$VER:ATH" VDATE};
extern hdfTYPE hdf[2];
unsigned char Error;
char s[FF_LFN_BUF + 1];

133
menu.c
View File

@@ -437,8 +437,9 @@ void HandleUI(void)
unsigned char i, c, m, up, down, select, backsp, menu, right, left, plus, minus;
uint8_t mod;
unsigned long len;
static hardfileTYPE t_hardfile[2]; // temporary copy of former hardfile configuration
static unsigned char t_enable_ide; // temporary copy of former IDE configuration
static hardfileTYPE t_hardfile[HARDFILES]; // temporary copy of former hardfile configuration
static unsigned char t_enable_ide[2]; // temporary copy of former IDE configuration
static unsigned char t_ide_idx;
static unsigned char ctrl = false;
static unsigned char lalt = false;
char enable;
@@ -2072,7 +2073,7 @@ void HandleUI(void)
/* minimig main menu */
/******************************************************************/
case MENU_MAIN1 :
menumask=0x70; // b01110000 Floppy turbo, Harddisk options & Exit.
menumask=0xF0; // b11110000 Floppy turbo, Harddisk options & Exit.
OsdSetTitle("Minimig",OSD_ARROW_RIGHT);
// set helptext with core display on top of basic info
siprintf(helptext_custom, HELPTEXT_SPACER);
@@ -2122,9 +2123,9 @@ void HandleUI(void)
}
siprintf(s," Floppy disk turbo : %s",config.floppy.speed ? "on" : "off");
OsdWrite(4, s, menusub==4,0);
OsdWrite(5, " Hard disk settings \x16", menusub == 5,0);
OsdWrite(6, "", 0,0);
OsdWrite(7, STD_EXIT, menusub == 6,0);
OsdWrite(5, " Primary hard disks \x16", menusub == 5,0);
OsdWrite(6, " Secondary hard disks \x16", menusub == 6,0);
OsdWrite(7, STD_EXIT, menusub == 7,0);
menustate = MENU_MAIN2;
parentstate=MENU_MAIN1;
@@ -2166,15 +2167,25 @@ void HandleUI(void)
ConfigFloppy(config.floppy.drives,config.floppy.speed);
menustate = MENU_MAIN1;
}
else if (menusub == 5) // Go to harddrives page.
else if (menusub == 5) // Go to primary harddrives page.
{
t_hardfile[0] = config.hardfile[0];
t_hardfile[1] = config.hardfile[1];
t_enable_ide = config.enable_ide;
memcpy(t_hardfile, config.hardfile, sizeof(config.hardfile));
t_enable_ide[0] = config.enable_ide[0];
t_enable_ide[1] = config.enable_ide[1];
t_ide_idx = 0;
menustate = MENU_SETTINGS_HARDFILE1;
menusub=0;
}
else if (menusub == 6)
else if (menusub == 6) // Go to primary harddrives page.
{
memcpy(t_hardfile, config.hardfile, sizeof(config.hardfile));
t_enable_ide[0] = config.enable_ide[0];
t_enable_ide[1] = config.enable_ide[1];
t_ide_idx = 1;
menustate = MENU_SETTINGS_HARDFILE1;
menusub=0;
}
else if (menusub == 7)
menustate = MENU_NONE1;
}
else if (c == KEY_BACK) // eject all floppies
@@ -2829,45 +2840,46 @@ void HandleUI(void)
parentstate = menustate;
menumask=0x21; // b00100001 - On/off & exit enabled by default...
if(config.enable_ide)
if(config.enable_ide[t_ide_idx])
menumask|=0x0a; // b00001010 - HD0 and HD1 type
strcpy(s, " A600 IDE : ");
strcat(s, config.enable_ide ? "on " : "off");
siprintf(s, " A600 %s IDE : %s",
t_ide_idx ? "Secondary" : "Primary",
config.enable_ide[t_ide_idx] ? "on " : "off");
OsdWrite(0, s, menusub == 0,0);
OsdWrite(1, "", 0,0);
strcpy(s, " Master : ");
if(config.hardfile[0].enabled==(HDF_FILE|HDF_SYNTHRDB))
if(config.hardfile[t_ide_idx << 1].enabled==(HDF_FILE|HDF_SYNTHRDB))
strcat(s,"Hardfile (filesys)");
else
strcat(s, config_hdf_msg[config.hardfile[0].enabled & HDF_TYPEMASK]);
OsdWrite(2, s, config.enable_ide ? (menusub == 1) : 0 ,config.enable_ide==0);
if (config.hardfile[0].present)
strcat(s, config_hdf_msg[config.hardfile[t_ide_idx << 1].enabled & HDF_TYPEMASK]);
OsdWrite(2, s, config.enable_ide[t_ide_idx] ? (menusub == 1) : 0 ,config.enable_ide[t_ide_idx]==0);
if (config.hardfile[t_ide_idx << 1].present)
{
strcpy(s, " ");
strncpy(&s[14], config.hardfile[0].name, sizeof(config.hardfile[0].name));
strncpy(&s[14], config.hardfile[t_ide_idx << 1].name, sizeof(config.hardfile[0].name));
}
else
strcpy(s, " ** file not found **");
enable=config.enable_ide && ((config.hardfile[0].enabled&HDF_TYPEMASK)==HDF_FILE);
enable=config.enable_ide[t_ide_idx] && ((config.hardfile[t_ide_idx << 1].enabled&HDF_TYPEMASK)==HDF_FILE);
if(enable)
menumask|=0x04; // Make hardfile selectable
OsdWrite(3, s, enable ? (menusub == 2) : 0 , enable==0);
strcpy(s, " Slave : ");
if(config.hardfile[1].enabled==(HDF_FILE|HDF_SYNTHRDB))
if(config.hardfile[(t_ide_idx << 1) + 1].enabled==(HDF_FILE|HDF_SYNTHRDB))
strcat(s,"Hardfile (filesys)");
else
strcat(s, config_hdf_msg[config.hardfile[1].enabled & HDF_TYPEMASK]);
OsdWrite(4, s, config.enable_ide ? (menusub == 3) : 0 ,config.enable_ide==0);
if (config.hardfile[1].present) {
strcat(s, config_hdf_msg[config.hardfile[(t_ide_idx << 1) + 1].enabled & HDF_TYPEMASK]);
OsdWrite(4, s, config.enable_ide[t_ide_idx] ? (menusub == 3) : 0 ,config.enable_ide[t_ide_idx]==0);
if (config.hardfile[(t_ide_idx << 1) + 1].present) {
strcpy(s, " ");
strncpy(&s[14], config.hardfile[1].name, sizeof(config.hardfile[0].name));
strncpy(&s[14], config.hardfile[(t_ide_idx << 1) + 1].name, sizeof(config.hardfile[0].name));
}
else
strcpy(s, " ** file not found **");
enable=config.enable_ide && ((config.hardfile[1].enabled&HDF_TYPEMASK)==HDF_FILE);
enable=config.enable_ide[t_ide_idx] && ((config.hardfile[(t_ide_idx << 1) + 1].enabled&HDF_TYPEMASK)==HDF_FILE);
if(enable)
menumask|=0x10; // Make hardfile selectable
OsdWrite(5, s, enable ? (menusub == 4) : 0 ,enable==0);
@@ -2884,24 +2896,25 @@ void HandleUI(void)
{
if (menusub == 0)
{
config.enable_ide=(config.enable_ide==0);
config.enable_ide[t_ide_idx]=(config.enable_ide[t_ide_idx]==0);
menustate = MENU_SETTINGS_HARDFILE1;
}
if (menusub == 1)
{
if(config.hardfile[0].enabled==HDF_FILE)
char idx = t_ide_idx << 1;
if(config.hardfile[idx].enabled==HDF_FILE)
{
config.hardfile[0].enabled|=HDF_SYNTHRDB;
config.hardfile[idx].enabled|=HDF_SYNTHRDB;
}
else if(config.hardfile[0].enabled==(HDF_FILE|HDF_SYNTHRDB))
else if(config.hardfile[idx].enabled==(HDF_FILE|HDF_SYNTHRDB))
{
config.hardfile[0].enabled&=~HDF_SYNTHRDB;
config.hardfile[0].enabled +=1;
config.hardfile[idx].enabled&=~HDF_SYNTHRDB;
config.hardfile[idx].enabled +=1;
}
else
{
config.hardfile[0].enabled +=1;
config.hardfile[0].enabled %=HDF_CARDPART0+partitioncount;
config.hardfile[idx].enabled +=1;
config.hardfile[idx].enabled %=HDF_CARDPART0+partitioncount;
}
menustate = MENU_SETTINGS_HARDFILE1;
}
@@ -2911,19 +2924,20 @@ void HandleUI(void)
}
else if (menusub == 3)
{
if(config.hardfile[1].enabled==HDF_FILE)
char idx = (t_ide_idx << 1) + 1;
if(config.hardfile[idx].enabled==HDF_FILE)
{
config.hardfile[1].enabled|=HDF_SYNTHRDB;
config.hardfile[idx].enabled|=HDF_SYNTHRDB;
}
else if(config.hardfile[1].enabled==(HDF_FILE|HDF_SYNTHRDB))
else if(config.hardfile[idx].enabled==(HDF_FILE|HDF_SYNTHRDB))
{
config.hardfile[1].enabled&=~HDF_SYNTHRDB;
config.hardfile[1].enabled +=1;
config.hardfile[idx].enabled&=~HDF_SYNTHRDB;
config.hardfile[idx].enabled +=1;
}
else
{
config.hardfile[1].enabled +=1;
config.hardfile[1].enabled %=HDF_CARDPART0+partitioncount;
config.hardfile[idx].enabled +=1;
config.hardfile[idx].enabled %=HDF_CARDPART0+partitioncount;
}
menustate = MENU_SETTINGS_HARDFILE1;
}
@@ -2949,9 +2963,9 @@ void HandleUI(void)
case MENU_HARDFILE_SELECTED : {
char idx;
if (menusub == 2) // master drive selected
idx = 0;
idx = t_ide_idx << 1;
else if (menusub == 4) // slave drive selected
idx = 1;
idx = (t_ide_idx << 1) + 1;
else // invalid
break;
@@ -2989,7 +3003,9 @@ void HandleUI(void)
// check if hardfile configuration has changed
case MENU_HARDFILE_EXIT :
if ((memcmp(config.hardfile, t_hardfile, sizeof(t_hardfile)) != 0) || (config.enable_ide != t_enable_ide))
if ((memcmp(config.hardfile, t_hardfile, sizeof(t_hardfile)) != 0) ||
(config.enable_ide[0] != t_enable_ide[0]) ||
(config.enable_ide[1] != t_enable_ide[1]))
{
menustate = MENU_HARDFILE_CHANGED1;
menusub = 1;
@@ -2997,7 +3013,7 @@ void HandleUI(void)
else
{
menustate = MENU_MAIN1;
menusub = 5;
menusub = 5 + t_ide_idx;
}
break;
@@ -3026,25 +3042,20 @@ void HandleUI(void)
if (menusub == 0) // yes
{
// FIXME - waiting for user-confirmation increases the window of opportunity for file corruption!
if ((config.hardfile[0].enabled != t_hardfile[0].enabled)
|| (strncmp(config.hardfile[0].name, t_hardfile[0].name, sizeof(t_hardfile[0].name)) != 0))
{
OpenHardfile(0);
for (int i = 0; i < HARDFILES; i++) {
if ((config.hardfile[i].enabled != t_hardfile[i].enabled)
|| (strncmp(config.hardfile[i].name, t_hardfile[i].name, sizeof(t_hardfile[0].name)) != 0))
{
OpenHardfile(i);
//if((config.hardfile[0].enabled == HDF_FILE) && !FindRDB(0))
// menustate = MENU_SYNTHRDB1;
}
if (config.hardfile[1].enabled != t_hardfile[1].enabled
|| (strncmp(config.hardfile[1].name, t_hardfile[1].name, sizeof(t_hardfile[1].name)) != 0))
{
OpenHardfile(1);
//if((config.hardfile[1].enabled == HDF_FILE) && !FindRDB(1))
// menustate = MENU_SYNTHRDB2_1;
}
}
if(menustate==MENU_HARDFILE_CHANGED2)
{
ConfigIDE(config.enable_ide, config.hardfile[0].present && config.hardfile[0].enabled, config.hardfile[1].present && config.hardfile[1].enabled);
ConfigIDE(config.enable_ide[0], config.hardfile[0].present && config.hardfile[0].enabled, config.hardfile[1].present && config.hardfile[1].enabled);
ConfigIDE(config.enable_ide[1] | 0x02, config.hardfile[2].present && config.hardfile[2].enabled, config.hardfile[3].present && config.hardfile[3].enabled);
OsdReset(RESET_NORMAL);
menustate = MENU_NONE1;
@@ -3053,17 +3064,17 @@ void HandleUI(void)
else if (menusub == 1) // no
{
memcpy(config.hardfile, t_hardfile, sizeof(t_hardfile)); // restore configuration
config.enable_ide = t_enable_ide;
config.enable_ide[t_ide_idx] = t_enable_ide[t_ide_idx];
menustate = MENU_MAIN1;
menusub = 5;
menusub = 5 + t_ide_idx;
}
}
if (menu)
{
memcpy(config.hardfile, t_hardfile, sizeof(t_hardfile)); // restore configuration
config.enable_ide = t_enable_ide;
config.enable_ide[t_ide_idx] = t_enable_ide[t_ide_idx];
menustate = MENU_MAIN1;
menusub = 5;

4
osd.c
View File

@@ -568,8 +568,8 @@ void ConfigIDE(unsigned char gayle, unsigned char master, unsigned char slave)
{
if(minimig_v1())
spi_osd_cmd(MM1_OSDCMDCFGIDE | (slave ? 4 : 0) | (master ? 2 : 0) | (gayle ? 1 : 0));
else
spi_osd_cmd8(OSD_CMD_HDD, (slave ? 4 : 0) | (master ? 2 : 0) | (gayle ? 1 : 0));
else
spi_osd_cmd8(OSD_CMD_HDD0 + ((gayle >> 1) << 2), (slave ? 4 : 0) | (master ? 2 : 0) | ((gayle & 0x01)));
}
void ConfigAutofire(unsigned char autofire)

3
osd.h
View File

@@ -38,7 +38,8 @@
#define OSD_CMD_MEM 0x24
#define OSD_CMD_VID 0x34
#define OSD_CMD_FLP 0x44
#define OSD_CMD_HDD 0x54
#define OSD_CMD_HDD0 0x54
#define OSD_CMD_HDD1 0x58
#define OSD_CMD_JOY 0x64
#define OSD_CMD_OSD_WR 0x0c
#define OSD_CMD_WR 0x1c