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
## 1.6
* 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 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
lss_mode : 4; // WRITE/LOAD/SHIFT/QA/RP etc
uint8_t lss_prev_state; // for write bit
@ -248,6 +248,8 @@ _mii_disk2_command(
if (!file)
return -1;
}
// reinit all tracks, bits, maps etc
mii_floppy_init(&c->floppy[drive]);
mii_dd_drive_load(&c->drive[drive], file);
mii_floppy_load(&c->floppy[drive], file);
break;
@ -347,7 +349,9 @@ _mii_disk2_lss_tick(
c->lss_mode = (c->lss_mode & ~(1 << 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];
uint32_t byte_index = f->bit_position >> 3;
@ -360,6 +364,8 @@ _mii_disk2_lss_tick(
if ((c->head & 0xf) == 0) {
bit = f->tracks[MII_FLOPPY_RANDOM_TRACK_ID].data[byte_index];
bit = (bit >> bit_index) & 1;
// printf("RANDOM TRACK %2d %2d %2d : %d\n",
// track_id, byte_index, bit_index, bit);
} else {
bit = (c->head >> 1) & 1;
}

View File

@ -20,8 +20,12 @@ mii_floppy_init(
{
f->motor = 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->bit_position = 0;
f->tracks_dirty = 0;
f->write_protected &= ~MII_FLOPPY_WP_MANUAL;// keep the manual WP bit
/* this will look like this; ie half tracks are 'random'
0: 0 1: 0 2:35 3: 1
@ -164,6 +168,13 @@ mii_floppy_write_track_woz(
}
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;
if (version == 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;
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].dirty = 0;
}
} else {
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 +
le32toh(tmap->chunk.size_le) + sizeof(mii_woz_chunk_t));
#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,
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: track map %4.4s size %d\n",
(char*)&tmap->chunk.id_le,
@ -249,16 +260,16 @@ mii_floppy_load_woz(
printf("WOZ: Track chunk %4.4s size %d\n",
(char*)&trks->chunk.id_le, le32toh(trks->chunk.size_le));
#endif
/* TODO: this doesn't work yet... */
// f->bit_timing = info->optimal_bit_timing;
for (int i = 0; i < 35; i++) {
uint8_t *track = file->map +
(le16toh(trks->track[i].start_block_le) << 9);
uint32_t byte_count = (le32toh(trks->track[i].bit_count_le) + 7) >> 3;
memcpy(f->tracks[i].data, track, byte_count);
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
for (int ti = 0; ti < (int)sizeof(f->track_id); ti++) {
f->track_id[ti] = tmap->track_id[ti] == 0xff ?
@ -268,7 +279,6 @@ mii_floppy_load_woz(
__func__, ti, f->track_id[ti]);
}
}
#endif
return version;
}

View File

@ -23,13 +23,14 @@ enum {
};
typedef struct mii_floppy_track_t {
uint8_t dirty : 1; // track has been written to
uint32_t bit_count;
uint8_t data[6680]; // max suggested by WOZ spec
uint8_t dirty : 1; // track has been written to
uint32_t bit_count;
uint8_t data[6680]; // max suggested by WOZ spec
} mii_floppy_track_t;
typedef struct mii_floppy_t {
uint8_t write_protected : 3, id : 2;
uint8_t bit_timing; // 0=32 (default)
uint8_t motor; // motor is on
uint8_t stepper; // last step we did...
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_mui_1mb_t;
static void
// TODO: Dedup that with mii_mui_2dsk.c
void
_size_string(
size_t s,
char *out,

View File

@ -355,12 +355,18 @@ mii_emu_load(
cl = mii_config_get(cf, section, "flags0");
if (cl)
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");
if (cl)
strcpy(config->slot[i].conf.disk2.drive[1].disk, cl->value);
cl = mii_config_get(cf, section, "flags1");
if (cl)
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;
case MII_SLOT_DRIVER_SUPERSERIAL:
cl = mii_config_get(cf, section, "device");
@ -378,4 +384,4 @@ mii_emu_load(
}
}
return 0;
}
}

View File

@ -38,7 +38,8 @@ typedef struct mii_config_file_t {
} mii_config_file_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];
} mii_drive_conf_t;