Skip to content

Commit

Permalink
Amiga HD Floppy
Browse files Browse the repository at this point in the history
  • Loading branch information
retrofun committed Oct 10, 2024
1 parent 28821d0 commit 69aae13
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ unsigned char SaveConfiguration(char *filename)

void EjectAllFloppies() {
for(int i=0;i<drives;i++)
df[i].status = 0;
df[i].status = df[i].dd_hd = 0;

// harddisk
config.hardfile[0].present = 0;
Expand Down
16 changes: 9 additions & 7 deletions fdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ adfTYPE df[4]; // drive 0 information structure
#define HEADER_SIZE 0x40
#define DATA_SIZE 0x400
#define SECTOR_SIZE (HEADER_SIZE + DATA_SIZE)
#define SECTOR_COUNT 11
#define SECTOR_COUNT (11 * (drive->dd_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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 5 additions & 1 deletion fdd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand All @@ -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;

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions menu-minimig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 69aae13

Please sign in to comment.