Fix for some crashing WOZ, uncommented code!

I had left a block of code commented out, and that was crashing some
disks with 'special' track mapping.

Also now clear the CRC field on the woz, if any, when writing tracks.

Signed-off-by: Michel Pollet <buserror@gmail.com>
This commit is contained in:
Michel Pollet 2024-02-13 08:46:09 +00:00
parent 34e6bd299c
commit 01619cfe53
No known key found for this signature in database
7 changed files with 43 additions and 14 deletions

View File

@ -1,3 +1,7 @@
<p align="center">
<img src="contrib/mii-icon-64.png" alt="MII Logo">
</p>
# MII Version Changelog # MII Version Changelog
## 1.6 ## 1.6
* Another big update, yanked the old DiskII driver, and replaced it with a * Another big update, yanked the old DiskII driver, and replaced it with a

View File

@ -36,7 +36,7 @@ typedef struct mii_card_disk2_t {
uint8_t write_register; uint8_t write_register;
uint8_t head : 4; // bits are shifted in there uint8_t head : 4; // bits are shifted in there
uint8_t clock : 3; // LSS clock cycles, read a bit when 0 uint16_t clock; // LSS clock cycles, read a bit when 0
uint8_t lss_state : 4, // Sequence state uint8_t lss_state : 4, // Sequence state
lss_mode : 4; // WRITE/LOAD/SHIFT/QA/RP etc lss_mode : 4; // WRITE/LOAD/SHIFT/QA/RP etc
uint8_t lss_prev_state; // for write bit uint8_t lss_prev_state; // for write bit
@ -248,6 +248,8 @@ _mii_disk2_command(
if (!file) if (!file)
return -1; return -1;
} }
// reinit all tracks, bits, maps etc
mii_floppy_init(&c->floppy[drive]);
mii_dd_drive_load(&c->drive[drive], file); mii_dd_drive_load(&c->drive[drive], file);
mii_floppy_load(&c->floppy[drive], file); mii_floppy_load(&c->floppy[drive], file);
break; break;
@ -347,7 +349,9 @@ _mii_disk2_lss_tick(
c->lss_mode = (c->lss_mode & ~(1 << QA_BIT)) | c->lss_mode = (c->lss_mode & ~(1 << QA_BIT)) |
(!!(c->data_register & 0x80) << QA_BIT); (!!(c->data_register & 0x80) << QA_BIT);
if (c->clock++ == 0) { // clock is clipped to 3 bits c->clock += 4; // 4 is 0.5us.. we run at 2MHz
if (c->clock >= f->bit_timing) {
c->clock -= f->bit_timing;
uint8_t track_id = f->track_id[f->qtrack]; uint8_t track_id = f->track_id[f->qtrack];
uint32_t byte_index = f->bit_position >> 3; uint32_t byte_index = f->bit_position >> 3;
@ -360,6 +364,8 @@ _mii_disk2_lss_tick(
if ((c->head & 0xf) == 0) { if ((c->head & 0xf) == 0) {
bit = f->tracks[MII_FLOPPY_RANDOM_TRACK_ID].data[byte_index]; bit = f->tracks[MII_FLOPPY_RANDOM_TRACK_ID].data[byte_index];
bit = (bit >> bit_index) & 1; bit = (bit >> bit_index) & 1;
// printf("RANDOM TRACK %2d %2d %2d : %d\n",
// track_id, byte_index, bit_index, bit);
} else { } else {
bit = (c->head >> 1) & 1; bit = (c->head >> 1) & 1;
} }

View File

@ -20,8 +20,12 @@ mii_floppy_init(
{ {
f->motor = 0; f->motor = 0;
f->stepper = 0; f->stepper = 0;
// see spec for this.. 32 is the default for 4us.
f->bit_timing = 32;
f->qtrack = 15; // just to see something at seek time f->qtrack = 15; // just to see something at seek time
f->bit_position = 0; f->bit_position = 0;
f->tracks_dirty = 0;
f->write_protected &= ~MII_FLOPPY_WP_MANUAL;// keep the manual WP bit f->write_protected &= ~MII_FLOPPY_WP_MANUAL;// keep the manual WP bit
/* this will look like this; ie half tracks are 'random' /* this will look like this; ie half tracks are 'random'
0: 0 1: 0 2:35 3: 1 0: 0 1: 0 2:35 3: 1
@ -164,6 +168,13 @@ mii_floppy_write_track_woz(
} }
version += !strncmp((char*)header, "WOZ2", 4); version += !strncmp((char*)header, "WOZ2", 4);
/* I don't really want to recalculate the CRC. Seems pointless in a file
like this, and i'd have to walk 250KB+ of data each time I update
anything.
Mark is as cleared, perhapps I need a tool to 'fix' it later, or JUST
at closing time ?*/
header->crc_le = 0;
mii_woz_tmap_t *tmap = NULL; mii_woz_tmap_t *tmap = NULL;
if (version == 1) { if (version == 1) {
mii_woz1_info_t *info = (mii_woz1_info_t *)(header + 1); mii_woz1_info_t *info = (mii_woz1_info_t *)(header + 1);
@ -230,7 +241,6 @@ mii_floppy_load_woz(
uint8_t *track = trks->track[i].bits; uint8_t *track = trks->track[i].bits;
memcpy(f->tracks[i].data, track, le16toh(trks->track[i].byte_count_le)); memcpy(f->tracks[i].data, track, le16toh(trks->track[i].byte_count_le));
f->tracks[i].bit_count = le32toh(trks->track[i].bit_count_le); f->tracks[i].bit_count = le32toh(trks->track[i].bit_count_le);
f->tracks[i].dirty = 0;
} }
} else { } else {
mii_woz2_info_t *info = (mii_woz2_info_t *)(header + 1); mii_woz2_info_t *info = (mii_woz2_info_t *)(header + 1);
@ -239,9 +249,10 @@ mii_floppy_load_woz(
mii_woz2_trks_t *trks = (mii_woz2_trks_t *)((uint8_t *)tmap + mii_woz2_trks_t *trks = (mii_woz2_trks_t *)((uint8_t *)tmap +
le32toh(tmap->chunk.size_le) + sizeof(mii_woz_chunk_t)); le32toh(tmap->chunk.size_le) + sizeof(mii_woz_chunk_t));
#if 1 #if 1
printf("WOZ: version %d, type %d, sides %d, largest track %d\n", printf("WOZ: version %d, type %d, sides %d, largest track %d, optimal bit timing: %d\n",
info->version, info->disk_type, info->sides, info->version, info->disk_type, info->sides,
le16toh(info->largest_track_le) * 512); le16toh(info->largest_track_le) * 512,
info->optimal_bit_timing);
printf("WOZ: creator '%s'\n", info->creator); printf("WOZ: creator '%s'\n", info->creator);
printf("WOZ: track map %4.4s size %d\n", printf("WOZ: track map %4.4s size %d\n",
(char*)&tmap->chunk.id_le, (char*)&tmap->chunk.id_le,
@ -249,16 +260,16 @@ mii_floppy_load_woz(
printf("WOZ: Track chunk %4.4s size %d\n", printf("WOZ: Track chunk %4.4s size %d\n",
(char*)&trks->chunk.id_le, le32toh(trks->chunk.size_le)); (char*)&trks->chunk.id_le, le32toh(trks->chunk.size_le));
#endif #endif
/* TODO: this doesn't work yet... */
// f->bit_timing = info->optimal_bit_timing;
for (int i = 0; i < 35; i++) { for (int i = 0; i < 35; i++) {
uint8_t *track = file->map + uint8_t *track = file->map +
(le16toh(trks->track[i].start_block_le) << 9); (le16toh(trks->track[i].start_block_le) << 9);
uint32_t byte_count = (le32toh(trks->track[i].bit_count_le) + 7) >> 3; uint32_t byte_count = (le32toh(trks->track[i].bit_count_le) + 7) >> 3;
memcpy(f->tracks[i].data, track, byte_count); memcpy(f->tracks[i].data, track, byte_count);
f->tracks[i].bit_count = le32toh(trks->track[i].bit_count_le); f->tracks[i].bit_count = le32toh(trks->track[i].bit_count_le);
f->tracks[i].dirty = 0;
} }
} }
#if 0
// copy the track map from the file to the floppy // copy the track map from the file to the floppy
for (int ti = 0; ti < (int)sizeof(f->track_id); ti++) { for (int ti = 0; ti < (int)sizeof(f->track_id); ti++) {
f->track_id[ti] = tmap->track_id[ti] == 0xff ? f->track_id[ti] = tmap->track_id[ti] == 0xff ?
@ -268,7 +279,6 @@ mii_floppy_load_woz(
__func__, ti, f->track_id[ti]); __func__, ti, f->track_id[ti]);
} }
} }
#endif
return version; return version;
} }

View File

@ -30,6 +30,7 @@ typedef struct mii_floppy_track_t {
typedef struct mii_floppy_t { typedef struct mii_floppy_t {
uint8_t write_protected : 3, id : 2; uint8_t write_protected : 3, id : 2;
uint8_t bit_timing; // 0=32 (default)
uint8_t motor; // motor is on uint8_t motor; // motor is on
uint8_t stepper; // last step we did... uint8_t stepper; // last step we did...
uint8_t qtrack; // quarter track we are on uint8_t qtrack; // quarter track we are on

View File

@ -38,7 +38,8 @@ typedef struct mii_mui_1mb_t {
mii_1mb_conf_t config; mii_1mb_conf_t config;
} mii_mui_1mb_t; } mii_mui_1mb_t;
static void // TODO: Dedup that with mii_mui_2dsk.c
void
_size_string( _size_string(
size_t s, size_t s,
char *out, char *out,

View File

@ -355,12 +355,18 @@ mii_emu_load(
cl = mii_config_get(cf, section, "flags0"); cl = mii_config_get(cf, section, "flags0");
if (cl) if (cl)
config->slot[i].conf.disk2.drive[0].flags = strtoul(cl->value, NULL, 0); config->slot[i].conf.disk2.drive[0].flags = strtoul(cl->value, NULL, 0);
cl = mii_config_get(cf, section, "wp0");
if (cl)
config->slot[i].conf.disk2.drive[0].wp = !!strtoul(cl->value, NULL, 0);
cl = mii_config_get(cf, section, "image1"); cl = mii_config_get(cf, section, "image1");
if (cl) if (cl)
strcpy(config->slot[i].conf.disk2.drive[1].disk, cl->value); strcpy(config->slot[i].conf.disk2.drive[1].disk, cl->value);
cl = mii_config_get(cf, section, "flags1"); cl = mii_config_get(cf, section, "flags1");
if (cl) if (cl)
config->slot[i].conf.disk2.drive[1].flags = strtoul(cl->value, NULL, 0); config->slot[i].conf.disk2.drive[1].flags = strtoul(cl->value, NULL, 0);
cl = mii_config_get(cf, section, "wp1");
if (cl)
config->slot[i].conf.disk2.drive[1].wp = !!strtoul(cl->value, NULL, 0);
break; break;
case MII_SLOT_DRIVER_SUPERSERIAL: case MII_SLOT_DRIVER_SUPERSERIAL:
cl = mii_config_get(cf, section, "device"); cl = mii_config_get(cf, section, "device");

View File

@ -38,7 +38,8 @@ typedef struct mii_config_file_t {
} mii_config_file_t; } mii_config_file_t;
typedef struct mii_drive_conf_t { typedef struct mii_drive_conf_t {
unsigned long flags; unsigned long wp : 1, ro_file : 1, ro_format : 1,
flags;
char disk[MII_PATH_SIZE_MAX]; char disk[MII_PATH_SIZE_MAX];
} mii_drive_conf_t; } mii_drive_conf_t;