diff --git a/config.c b/config.c index deb721d..5aabc86 100644 --- a/config.c +++ b/config.c @@ -634,7 +634,7 @@ unsigned char SaveConfiguration(char *filename) void EjectAllFloppies() { for(int i=0;idd_hd + 1)) #define LAST_SECTOR (SECTOR_COUNT - 1) -#define GAP_SIZE (TRACK_SIZE - SECTOR_COUNT * SECTOR_SIZE) +#define GAP_SIZE (TRACK_SIZE - 11 * SECTOR_SIZE) // sends the data in the sector buffer to the FPGA, translated into an Amiga floppy format sector // note that we do not insert clock bits because they will be stripped by the Amiga software anyway @@ -325,7 +325,7 @@ unsigned char FindSync(adfTYPE *drive) return 0; } -unsigned char GetHeader(unsigned char *pTrack, unsigned char *pSector) +unsigned char GetHeader(unsigned char *pTrack, unsigned char *pSector, unsigned char dd_hd) // this function reads data from fifo till it finds sync word or dma is inactive { unsigned char c, c1, c2, c3, c4; @@ -402,9 +402,9 @@ unsigned char GetHeader(unsigned char *pTrack, unsigned char *pSector) Error = 22; else if (c2 > 159) // Track number (0-159) Error = 23; - else if (c3 > 10) // Sector number (0-10) + else if (c3 > (11 * (dd_hd + 1) - 1)) // Sector number (DD: 0-10, HD: 0-21) Error = 24; - else if (c4 > 11 || c4 == 0) // Number of sectors to gap (1-11) + else if (c4 > (11 * (dd_hd + 1)) || c4 == 0) // Number of sectors to gap (DD: 1-11, HD: 1-22) Error = 25; if (Error) @@ -603,7 +603,7 @@ void WriteTrack(adfTYPE *drive) while (FindSync(drive)) { - if (GetHeader(&Track, &Sector)) + if (GetHeader(&Track, &Sector, drive->dd_hd)) { if (Track == drive->track) { @@ -642,8 +642,10 @@ void WriteTrack(adfTYPE *drive) void UpdateDriveStatus(void) { EnableFpgaMinimig(); - SPI(0x10); + SPI(CMD_STATUS); SPI(df[0].status | (df[1].status << 1) | (df[2].status << 2) | (df[3].status << 3)); + SPI(CMD_STATUS); + SPI(df[0].dd_hd | (df[1].dd_hd << 1) | (df[2].dd_hd << 2) | (df[3].dd_hd << 3)); DisableFpga(); } diff --git a/fdd.h b/fdd.h index 36e3617..7c90552 100644 --- a/fdd.h +++ b/fdd.h @@ -4,8 +4,11 @@ #include "FatFs/ff.h" // floppy disk interface defs +// from FPGA #define CMD_RDTRK 0x01 #define CMD_WRTRK 0x02 +// to FPGA +#define CMD_STATUS 0x10 // floppy status #define DSK_INSERTED 0x01 /*disk is inserted*/ @@ -21,6 +24,7 @@ typedef struct unsigned char sector_offset; /*sector offset to handle tricky loaders*/ unsigned char track; /*current track*/ unsigned char track_prev; /*previous track*/ + unsigned char dd_hd:1; /*DD 880KB/HD 1760KB*/ char name[22]; /*floppy name*/ } adfTYPE; @@ -29,7 +33,7 @@ void SectorHeaderToFpga(unsigned char n, unsigned char dsksynch, unsigned char d //unsigned short SectorToFpga(unsigned char sector, unsigned char track, unsigned char dsksynch, unsigned char dsksyncl); void ReadTrack(adfTYPE *drive); unsigned char FindSync(adfTYPE *drive); -unsigned char GetHeader(unsigned char *pTrack, unsigned char *pSector); +unsigned char GetHeader(unsigned char *pTrack, unsigned char *pSector, unsigned char dd_hd); unsigned char GetData(void); void WriteTrack(adfTYPE *drive); void UpdateDriveStatus(void); diff --git a/fpga.c b/fpga.c index c39efd6..71d6f87 100644 --- a/fpga.c +++ b/fpga.c @@ -998,10 +998,10 @@ unsigned char fpga_init(const char *name) { ChangeDirectoryName("/"); //eject all disk - df[0].status = 0; - df[1].status = 0; - df[2].status = 0; - df[3].status = 0; + df[0].status = df[0].dd_hd = 0; + df[1].status = df[1].dd_hd = 0; + df[2].status = df[2].dd_hd = 0; + df[3].status = df[3].dd_hd = 0; config.kickstart[0]=0; SetConfigurationFilename(0); // Use default config diff --git a/menu-minimig.c b/menu-minimig.c index cc897cc..0fd1e80 100644 --- a/menu-minimig.c +++ b/menu-minimig.c @@ -93,8 +93,9 @@ static void InsertFloppy(adfTYPE *drive, const unsigned char *name) if (f_open(&drive->file, name, FA_READ) != FR_OK) return; } + drive->dd_hd = f_size(&drive->file) > 512*11*MAX_TRACKS ? 1 : 0; // calculate number of tracks in the ADF image file - tracks = f_size(&drive->file) / (512*11); + tracks = f_size(&drive->file) / (512*11*(drive->dd_hd + 1)); if (tracks > MAX_TRACKS) { iprintf("UNSUPPORTED ADF SIZE!!! Too many tracks: %lu\r", tracks); tracks = MAX_TRACKS; @@ -122,6 +123,7 @@ static void InsertFloppy(adfTYPE *drive, const unsigned char *name) iprintf("Inserting floppy: \"%s\"\r", name); iprintf("file readonly: 0x%u\r", readonly); iprintf("file size: %llu (%llu KB)\r", f_size(&drive->file), f_size(&drive->file) >> 10); + iprintf("floppy type: %s\r", drive->dd_hd ? "HD" : "DD"); iprintf("drive tracks: %u\r", drive->tracks); iprintf("drive status: 0x%02X\r", drive->status); } @@ -376,6 +378,8 @@ static char GetMenuItem_Minimig(uint8_t idx, char action, menu_item_t *item) { item->stipple = 1; } else { strcpy(s, " dfx: "); + if (df[idx].dd_hd) + s[1] = 'h'; s[3] = idx + '0'; if (idx <= drives) { if (df[idx].status & DSK_INSERTED) {// floppy disk is inserted @@ -612,9 +616,9 @@ static char GetMenuItem_Minimig(uint8_t idx, char action, menu_item_t *item) { case 2: case 3: if (df[idx].status & DSK_INSERTED) {// eject selected floppy - df[idx].status = 0; + df[idx].status = df[idx].dd_hd = 0; } else { - df[idx].status = 0; + df[idx].status = df[idx].dd_hd = 0; SelectFileNG("ADF", SCAN_DIR | SCAN_LFN, FloppyFileSelected, 0); } break; @@ -870,7 +874,7 @@ static char GetMenuItem_Minimig(uint8_t idx, char action, menu_item_t *item) { case MENU_ACT_BKSP: if (page_idx == 0) { // eject all floppies for (int i = 0; i <= drives; i++) - df[i].status = 0; + df[i].status = df[i].dd_hd = 0; } break; case MENU_ACT_RIGHT: