--- uae/src/disk.c 2018/04/24 17:01:46 1.1.1.12 +++ uae/src/disk.c 2018/04/24 17:14:09 1.1.1.18 @@ -33,9 +33,10 @@ #include "execlib.h" #include "savestate.h" -#define FLOPPY_GAP_LEN 360 /* writable track length with normal 2us bitcell/300RPM motor */ -#define FLOPPY_WRITE_LEN 6250 +#define FLOPPY_WRITE_LEN (12650 / 2) +/* This works out to 341 */ +#define FLOPPY_GAP_LEN (FLOPPY_WRITE_LEN - 11 * 544) /* (cycles/bitcell) << 8, normal = ((2us/280ns)<<8) = ~1830 */ #define NORMAL_FLOPPY_SPEED 1830 @@ -120,11 +121,11 @@ static char *drive_id_name(drive *drv) case DRIVE_ID_525DD: return "5.25DD"; case DRIVE_ID_35DD : return "3.5DD"; } - return "UNKNOWN"; + return "UNKNOWN"; } #endif -/* Simulate exact behaviour of an A3000T 3.5 HD disk drive. +/* Simulate exact behaviour of an A3000T 3.5 HD disk drive. * The drive reports to be a 3.5 DD drive whenever there is no * disk or a 3.5 DD disk is inserted. Only 3.5 HD drive id is reported * when a real 3.5 HD disk is inserted. -Adil @@ -730,10 +731,12 @@ void DISK_check_change (void) for (i = 0; i < 4; i++) { drive *drv = floppy + i; + gui_lock (); if (strcmp (currprefs.df[i], changed_prefs.df[i])) { strcpy (currprefs.df[i], changed_prefs.df[i]); disk_insert (i, currprefs.df[i]); } + gui_unlock (); /* emulate drive motor turn on time */ if (drv->dskready_time) { drv->dskready_time--; @@ -788,7 +791,7 @@ void DISK_select (uae_u8 data) } for (dr = 0; dr < 4; dr++) { /* motor on/off workings tested with small assembler code on real Amiga 1200. */ - /* motor flipflop is set only when drive select goes from high to low */ + /* motor flipflop is set only when drive select goes from high to low */ if (!(selected & (1 << dr)) && (lastselected & (1 << dr)) ) { if (floppy[dr].motoroff) { /* motor off: if motor bit = 0 in prevdata or data -> turn motor on */ @@ -826,7 +829,7 @@ uae_u8 DISK_status (void) st |= 0x20; else st &= ~0x20; -#ifdef DEBUG_DRIVE_ID +#ifdef DEBUG_DRIVE_ID write_log("DISK_status: sel %d id %s [0x%08lx, bit #%02d: %d]\n", dr,drive_id_name(drv), drv->drive_id << drv->drive_id_scnt, 31 - drv->drive_id_scnt, st & 0x20 ? 1:0); #endif @@ -840,7 +843,7 @@ uae_u8 DISK_status (void) st &= ~8; if (drv->dskchange) st &= ~4; - } + } } return st; } @@ -863,11 +866,11 @@ static uae_u32 dskpt; static void disk_dmafinished (void) { INTREQ (0x8002); - dskdmaen = 1; /* surprise, it isn't set to zero! */ + dskdmaen = 0; /* ??? */ #ifdef DISK_DEBUG write_log("disk dma finished %08.8X\n", dskpt); #endif -} +} static void disk_events (int last) { @@ -1034,6 +1037,35 @@ static void dodmafetch (void) dma_tab[0] = 0xffffffff; } +/* this is very unoptimized. DSKBYTR is used very rarely, so it should not matter. */ + +uae_u16 DSKBYTR (int hpos) +{ + uae_u16 v; + int i; + + i = 0; + while (hpos > dskbytr_cycle[i + 1]) + i++; + v = dskbytr_tab[i]; + dskbytr_tab[i] &= ~0x8000; + if (wordsync_cycle[0] != 255) { + i = 0; + while (hpos < wordsync_cycle[i]) + i++; + if (hpos - wordsync_cycle[i] <= WORDSYNC_CYCLES) + v |= 0x1000; + } + if (dskdmaen && (dmacon & 0x210) == 0x210) + v |= 0x4000; + if (dskdmaen == 3) + v |= 0x2000; + + disk_data_used = 0; + + return v; +} + static void DISK_start (void) { int dr; @@ -1065,7 +1097,7 @@ static int linecounter; void DISK_update (void) { int dr; - + for (dr = 0; dr < 4; dr++) { drive *drv = &floppy[dr]; if (drv->steplimit) @@ -1192,35 +1224,6 @@ void DSKLEN (uae_u16 v, int hpos) } } -/* this is very unoptimized. DSKBYTR is used very rarely, so it should not matter. */ - -uae_u16 DSKBYTR (int hpos) -{ - uae_u16 v; - int i; - - i = 0; - while (hpos > dskbytr_cycle[i + 1]) - i++; - v = dskbytr_tab[i]; - dskbytr_tab[i] &= ~0x8000; - if (wordsync_cycle[0] != 255) { - i = 0; - while (hpos < wordsync_cycle[i]) - i++; - if (hpos - wordsync_cycle[i] <= WORDSYNC_CYCLES) - v |= 0x1000; - } - if (dskdmaen && (dmacon & 0x210) == 0x210) - v |= 0x4000; - if (dskdmaen == 3) - v |= 0x2000; - - disk_data_used = 0; - - return v; -} - /* not a real hardware register */ uae_u16 DSKDATR (int hpos) { @@ -1277,6 +1280,10 @@ void DISK_init (void) void DISK_reset (void) { int i; + + if (savestate_state) + return; + disk_hpos = 0; disk_data_used = 0; disabled = 0; @@ -1318,30 +1325,40 @@ void DISK_restore_custom (uae_u32 pdskpt uae_u8 *restore_disk(int num,uae_u8 *src) { drive *drv; + int state; drv = &floppy[num]; + disabled &= ~(1 << num); drv->drive_id = restore_u32 (); - drv->motoroff = restore_u8 () ? 0 : 1; + state = restore_u8 (); + if (state & 2) + disabled |= 1 << num; + else + drv->motoroff = (state & 1) ? 0 : 1; drv->cyl = restore_u8 (); drv->dskready = restore_u8 (); drv->drive_id_scnt = restore_u8 (); drv->mfmpos = restore_u32 (); restore_u32 (); - strncpy(currprefs.df[num],src,255); - src+=strlen(src)+1; + strncpy(changed_prefs.df[num],src,255); + changed_prefs.df[num][255] = 0; + src += strlen(src) + 1; return src; } -uae_u8 *save_disk(int num,int *len) +uae_u8 *save_disk(int num, int *len, uae_u8 *dstptr) { uae_u8 *dstbak,*dst; drive *drv; drv = &floppy[num]; - dstbak = dst = malloc (2+1+1+1+1+4+4+256); + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc (2+1+1+1+1+4+4+256); save_u32 (drv->drive_id); /* drive type ID */ - save_u8 (drv->motoroff ? 0:1); /* motor state */ + save_u8 ((drv->motoroff ? 0:1) | ((disabled & (1 << num)) ? 2 : 0)); /* state */ save_u8 (drv->cyl); /* cylinder */ save_u8 (drv->dskready); /* dskready */ save_u8 (drv->drive_id_scnt); /* id mode position */ @@ -1368,14 +1385,17 @@ uae_u8 *restore_floppy(uae_u8 *src) return src; } -uae_u8 *save_floppy(int *len) +uae_u8 *save_floppy(int *len, uae_u8 *dstptr) { uae_u8 *dstbak, *dst; /* flush dma buffer before saving */ dodmafetch(); - dstbak = dst = malloc(2+1+1+1+1+2); + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc(2+1+1+1+1+2); save_u16 (word); /* current fifo (low word) */ save_u8 (bitoffset); /* dma bit offset */ save_u8 (dma_enable); /* disk sync found */