#include #include "dos33.h" /* FIXME: this code assumes that we have 16 sectors pretty much everywhere */ static int ones_lookup[16]={ /* 0x0 = 0000 */ 0, /* 0x1 = 0001 */ 1, /* 0x2 = 0010 */ 1, /* 0x3 = 0011 */ 2, /* 0x4 = 0100 */ 1, /* 0x5 = 0101 */ 2, /* 0x6 = 0110 */ 2, /* 0x7 = 0111 */ 3, /* 0x8 = 1000 */ 1, /* 0x9 = 1001 */ 2, /* 0xA = 1010 */ 2, /* 0xB = 1011 */ 3, /* 0xC = 1100 */ 2, /* 0xD = 1101 */ 3, /* 0xE = 1110 */ 3, /* 0xF = 1111 */ 4, }; /* could be replaced by "find leading 1" instruction */ /* if available */ static int find_first_one(unsigned char byte) { int i=0; if (byte==0) return -1; while((byte & (0x1<>4)&0xf]; sectors_free+=ones_lookup[bitmap[1]&0xf]; sectors_free+=ones_lookup[(bitmap[1]>>4)&0xf]; } return sectors_free*BYTES_PER_SECTOR; } /* free a sector from the sector bitmap */ void dos33_vtoc_free_sector(unsigned char *vtoc, int track, int sector) { if (debug) { fprintf(stderr,"vtoc_free: freeing T=%d S=%d\n", track,sector); } /* each bitmap is 32 bits. With 16-sector tracks only first 16 used */ /* 1 indicates free, 0 indicates used */ if (sector<8) { vtoc[VTOC_FREE_BITMAPS+(track*4)+1]|=(0x1<VTOC_TRACK) && (track_dir!=1)) || ((start_track=TRACKS_PER_DISK) { i=VTOC_TRACK; track_dir=-1; } } while (i!=start_track); if (found) { /* clear bit indicating in use */ dos33_vtoc_reserve_sector(vtoc, *found_track, *found_sector); /* update last track used and direction */ vtoc[VTOC_LAST_ALLOC_T]=*found_track; vtoc[VTOC_ALLOC_DIRECT]=track_dir; return 0; } /* no room */ return ERROR_NO_SPACE; }