--- uae/src/disk.c 2018/04/24 17:08:56 1.1.1.16 +++ uae/src/disk.c 2018/04/24 17:14:09 1.1.1.18 @@ -121,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 @@ -791,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 */ @@ -829,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 @@ -843,7 +843,7 @@ uae_u8 DISK_status (void) st &= ~8; if (drv->dskchange) st &= ~4; - } + } } return st; } @@ -870,7 +870,7 @@ static void disk_dmafinished (void) #ifdef DISK_DEBUG write_log("disk dma finished %08.8X\n", dskpt); #endif -} +} static void disk_events (int last) { @@ -1037,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; @@ -1068,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) @@ -1195,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) { @@ -1347,13 +1347,16 @@ uae_u8 *restore_disk(int num,uae_u8 *src 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) | ((disabled & (1 << num)) ? 2 : 0)); /* state */ save_u8 (drv->cyl); /* cylinder */ @@ -1382,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 */