diskimage.c
/* check if track, sector is free in BAM */
check if track, sector is free in BAM
check if track sector is free in BAM
int di_is_ts_free(DiskImage *di, TrackSector ts) {
  unsigned char mask;
  unsigned char *bam;
  switch (di->type) {
  case D64:
    bam = get_ts_addr(di, di->bam);
    if (bam[ts.track * 4]) {
      mask = 1<<(ts.sector & 7);
      return(bam[ts.track * 4 + ts.sector / 8 + 1] & mask ? 1 : 0);
    } else {
      return(0);
    }
    break;
  case D71:
    mask = 1<<(ts.sector & 7);
    if (ts.track < 36) {
      bam = get_ts_addr(di, di->bam);
      return(bam[ts.track * 4 + ts.sector / 8 + 1] & mask ? 1 : 0);
    } else {
      bam = get_ts_addr(di, di->bam2);
      return(bam[(ts.track - 35) * 3 + ts.sector / 8 - 3] & mask ? 1 : 0);
    }
    break;
  case D81:
    mask = 1<<(ts.sector & 7);
    if (ts.track < 41) {
      bam = get_ts_addr(di, di->bam);
    } else {
      bam = get_ts_addr(di, di->bam2);
      ts.track -= 40;
    }
    return(bam[ts.track * 6 + ts.sector / 8 + 11] & mask ? 1 : 0);
    break;
  }
  return(0);
}
int di_is_ts_free ( DiskImage * di , TrackSector ts ) { unsigned char mask ; unsigned char * bam ; switch ( di -> type ) { case D64 : bam = get_ts_addr ( di , di -> bam ) ; if ( bam [ ts . track * 4 ] ) { mask = 1 << ( ts . sector & 7 ) ; return ( bam [ ts . track * 4 + ts . sector / 8 + 1 ] & mask ? 1 : 0 ) ; } else { return ( 0 ) ; } break ; case D71 : mask = 1 << ( ts . sector & 7 ) ; if ( ts . track < 36 ) { bam = get_ts_addr ( di , di -> bam ) ; return ( bam [ ts . track * 4 + ts . sector / 8 + 1 ] & mask ? 1 : 0 ) ; } else { bam = get_ts_addr ( di , di -> bam2 ) ; return ( bam [ ( ts . track - 35 ) * 3 + ts . sector / 8 - 3 ] & mask ? 1 : 0 ) ; } break ; case D81 : mask = 1 << ( ts . sector & 7 ) ; if ( ts . track < 41 ) { bam = get_ts_addr ( di , di -> bam ) ; } else { bam = get_ts_addr ( di , di -> bam2 ) ; ts . track -= 40 ; } return ( bam [ ts . track * 6 + ts . sector / 8 + 11 ] & mask ? 1 : 0 ) ; break ; } return ( 0 ) ; }
check if track, sector is free in BAM
check if track sector is free in BAM