static int i8271_find_sector(device_t *device) { device_t *img = current_image(device); i8271_t *i8271 = get_safe_token(device); // int track_count_attempt; // track_count_attempt /* find sector within one revolution of the disc - 2 index pulses */ /* number of times we have seen index hole */ int index_count = 0; /* get sector id's */ do { chrn_id id; /* get next id from disc */ if (floppy_drive_get_next_id(img, i8271->side,&id)) { /* tested on Amstrad CPC - All bytes must match, otherwise a NO DATA error is reported */ if (id.R == i8271->ID_R) { /* TODO: Is this correct? What about bad tracks? */ if (id.C == i8271->CurrentTrack[i8271->drive]) { i8271->data_id = id.data_id; return 1; } else { /* TODO: if track doesn't match, the real 8271 does a step */ return 0; } } } /* index set? */ if (floppy_drive_get_flag_state(img, FLOPPY_DRIVE_INDEX)) { index_count++; } } while (index_count!=2); /* completion type: command/drive error */ /* completion code: sector not found */ i8271->ResultRegister |= (3<<3); return 0; }
/* preamble to all sector read / write commands, returns 1 if found */ static int mc6843_address_search( device_t *device, chrn_id* id ) { mc6843_t* mc6843 = get_safe_token( device ); device_t* img = mc6843_floppy_image( device ); int r = 0; while ( 1 ) { if ( ( ! floppy_drive_get_next_id( img, mc6843->side, id ) ) || ( id->flags & ID_FLAG_CRC_ERROR_IN_ID_FIELD ) || ( id->N != 0 ) ) { /* read address error */ LOG(( "%f mc6843_address_search: get_next_id failed\n", device->machine().time().as_double() )); mc6843->STRB |= 0x0a; /* set CRC error & Sector Address Undetected */ mc6843_cmd_end( device ); return 0; } if ( id->C != mc6843->LTAR ) { /* track mismatch */ LOG(( "%f mc6843_address_search: track mismatch: logical=%i real=%i\n", device->machine().time().as_double(), mc6843->LTAR, id->C )); mc6843->data[0] = id->C; /* make the track number available to the CPU */ mc6843->STRA |= 0x20; /* set Track Not Equal */ mc6843_cmd_end( device ); return 0; } if ( id->R == mc6843->SAR ) { /* found! */ LOG(( "%f mc6843_address_search: sector %i found on track %i\n", device->machine().time().as_double(), id->R, id->C )); if ( ! (mc6843->CMR & 0x20) ) { mc6843->ISR |= 0x04; /* if no DMA, set Status Sense */ } return 1; } if ( floppy_drive_get_flag_state( img, FLOPPY_DRIVE_INDEX ) ) { r++; if ( r >= 4 ) { /* time-out after 3 full revolutions */ LOG(( "%f mc6843_address_search: no sector %i found after 3 revolutions\n", device->machine().time().as_double(), mc6843->SAR )); mc6843->STRB |= 0x08; /* set Sector Address Undetected */ mc6843_cmd_end( device ); return 0; } } } return 0; /* unreachable */ }
static void i8271_do_read_id(device_t *device) { chrn_id id; i8271_t *i8271 = get_safe_token(device); /* get next id from disc */ floppy_drive_get_next_id(current_image(device), i8271->side,&id); i8271->pExecutionPhaseData[0] = id.C; i8271->pExecutionPhaseData[1] = id.H; i8271->pExecutionPhaseData[2] = id.R; i8271->pExecutionPhaseData[3] = id.N; i8271_initialise_execution_phase_read(device, 4); }
/* Read the first id field that can be found on the floppy disk. unit: floppy drive index head: selected head cylinder_id: cylinder ID read sector_id: sector ID read Return TRUE if an ID was found */ static int fd800_read_id(int unit, int head, int *cylinder_id, int *sector_id) { /*UINT8 revolution_count;*/ chrn_id id; /*revolution_count = 0;*/ /*while (revolution_count < 2)*/ /*{*/ if (floppy_drive_get_next_id(&fd800.drv[unit].img->device(), head, &id)) { if (cylinder_id) *cylinder_id = id.C; if (sector_id) *sector_id = id.R; return TRUE; } /*}*/ return FALSE; }
/* Find a sector by id. unit: floppy drive index head: selected head sector: sector ID to search data_id: data ID to be used when calling sector read/write functions Return TRUE if the given sector ID was found */ static int fd800_find_sector(int unit, int head, int sector, int *data_id) { UINT8 revolution_count; chrn_id id; revolution_count = 0; while (revolution_count < 2) { if (floppy_drive_get_next_id(&fd800.drv[unit].img->device(), head, &id)) { /* compare id */ if ((id.R == sector) && (id.N == 0)) { *data_id = id.data_id; /* get ddam status */ /*w->ddam = id.flags & ID_FLAG_DELETED_DATA;*/ return TRUE; } } } return FALSE; }