sim_imd: Properly calculate IMD sectsize.

The ImageDisk sectsize field was incorrectly set to the number of
bytes in the sector, when it should be an index as follows:

00 =  128 bytes/sector
01 =  256 bytes/sector
02 =  512 bytes/sector
03 = 1024 bytes/sector
04 = 2048 bytes/sector
05 = 4096 bytes/sector
06 = 8192 bytes/sector

Tested disk formatting on MS-DOS 1.25, Cromemco CP/M 2.2,
Cromemco CDOS, OASIS 5.6.
This commit is contained in:
Howard M. Harte 2020-12-13 15:26:04 -08:00
parent 898d7cbdbb
commit 313d71b73e
2 changed files with 19 additions and 3 deletions

View file

@ -655,7 +655,11 @@ t_stat sectWrite(DISK_INFO *myDisk,
* Cromemco CDOS "INIT.COM" * Cromemco CDOS "INIT.COM"
* ADC Super-Six (CP/M-80) "FMT8.COM" * ADC Super-Six (CP/M-80) "FMT8.COM"
* 86-DOS "INIT.COM" * 86-DOS "INIT.COM"
* * MS-DOS 1.25 "FORMAT.COM" - SSSD 8"
* MS-DOS 1.25 "FORMAT.COM /D" - DSDD 8"
* OASIS-80 v5.6 "INITDISK A (FORMAT,SECTOR 13)" - SSSD 8"
* OASIS-80 v5.6 "INITDISK A (FORMAT)" - SSDD 8"
* OASIS-80 v5.6 "INITDISK A (FORMAT,HEAD 2)" - DSDD 8"
*/ */
t_stat trackWrite(DISK_INFO *myDisk, t_stat trackWrite(DISK_INFO *myDisk,
uint32 Cyl, uint32 Cyl,
@ -668,10 +672,11 @@ t_stat trackWrite(DISK_INFO *myDisk,
uint32 *flags) uint32 *flags)
{ {
FILE *fileref; FILE *fileref;
IMD_HEADER track_header; IMD_HEADER track_header = { 0 };
uint8 *sectorData; uint8 *sectorData;
unsigned long i; unsigned long i;
unsigned long dataLen; unsigned long dataLen;
uint8 sectsize = 0;
*flags = 0; *flags = 0;
@ -719,7 +724,16 @@ t_stat trackWrite(DISK_INFO *myDisk,
track_header.cyl = Cyl; track_header.cyl = Cyl;
track_header.head = Head; track_header.head = Head;
track_header.nsects = numSectors; track_header.nsects = numSectors;
track_header.sectsize = sectorLen;
for (i = (sectorLen >> 8); i; i >>= 1) {
sectsize++;
}
if (sectsize > IMD_MAX_SECTSIZE) {
sim_printf("SIM_IMD: ERROR: Invalid sectsize %d\n", sectsize);
return(SCPE_IERR);
}
track_header.sectsize = sectsize;
/* Forward to end of the file, write track header and sector map. */ /* Forward to end of the file, write track header and sector map. */
sim_fseek(myDisk->file, 0, SEEK_END); sim_fseek(myDisk->file, 0, SEEK_END);

View file

@ -86,6 +86,8 @@ typedef struct {
#define IMD_MODE_300K_MFM 4 #define IMD_MODE_300K_MFM 4
#define IMD_MODE_250K_MFM 5 #define IMD_MODE_250K_MFM 5
#define IMD_MAX_SECTSIZE 6
#define IMD_MODE_FM(x) (x <= IMD_MODE_250K_FM) #define IMD_MODE_FM(x) (x <= IMD_MODE_250K_FM)
#define IMD_MODE_MFM(x) (x >= IMD_MODE_500K_MFM) #define IMD_MODE_MFM(x) (x >= IMD_MODE_500K_MFM)