2021-01-03 23:01:30 +00:00
|
|
|
import { explodeSector13, D13O } from './format_utils';
|
2021-07-07 00:04:02 +00:00
|
|
|
import { NibbleDisk, DiskOptions, ENCODING_NIBBLE } from './types';
|
2019-10-02 02:56:10 +00:00
|
|
|
|
2021-01-03 23:01:30 +00:00
|
|
|
/**
|
|
|
|
* Returns a `Disk` object from DOS 3.2-ordered image data.
|
2021-07-07 00:04:02 +00:00
|
|
|
* @param options the disk image and options
|
|
|
|
* @returns A nibblized disk
|
2021-01-03 23:01:30 +00:00
|
|
|
*/
|
2021-07-07 00:04:02 +00:00
|
|
|
export default function createDiskFromDOS13(options: DiskOptions) {
|
2021-10-02 18:45:09 +00:00
|
|
|
const { data, name, side, rawData, volume, readOnly } = options;
|
2021-07-07 00:04:02 +00:00
|
|
|
const disk: NibbleDisk = {
|
2019-10-02 02:56:10 +00:00
|
|
|
format: 'd13',
|
2021-07-07 00:04:02 +00:00
|
|
|
encoding: ENCODING_NIBBLE,
|
2019-10-02 02:56:10 +00:00
|
|
|
name,
|
2021-10-02 18:45:09 +00:00
|
|
|
side,
|
2019-10-02 02:56:10 +00:00
|
|
|
volume,
|
|
|
|
readOnly,
|
2021-07-07 00:04:02 +00:00
|
|
|
tracks: []
|
2019-10-02 02:56:10 +00:00
|
|
|
};
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
if (!data && !rawData) {
|
|
|
|
throw new Error('data or rawData required');
|
|
|
|
}
|
|
|
|
|
2021-01-03 23:01:30 +00:00
|
|
|
/*
|
|
|
|
* DOS 13-sector disks have the physical sectors skewed on the track. The skew
|
|
|
|
* between physical sectors is 10 (A), resulting in the following physical order:
|
2021-07-07 00:04:02 +00:00
|
|
|
*
|
2021-01-03 23:01:30 +00:00
|
|
|
* 0 A 7 4 1 B 8 5 2 C 9 6 3
|
2021-07-07 00:04:02 +00:00
|
|
|
*
|
2021-01-03 23:01:30 +00:00
|
|
|
* Note that because physical sector == logical sector, this works slightly
|
|
|
|
* differently from the DOS and ProDOS nibblizers.
|
|
|
|
*/
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
for (let t = 0; t < 35; t++) {
|
|
|
|
let track: number[] = [];
|
|
|
|
for (let disk_sector = 0; disk_sector < 13; disk_sector++) {
|
|
|
|
const physical_sector = D13O[disk_sector];
|
|
|
|
let sector: Uint8Array;
|
2019-10-02 02:56:10 +00:00
|
|
|
if (rawData) {
|
2021-07-07 00:04:02 +00:00
|
|
|
const off = (13 * t + physical_sector) * 256;
|
2019-10-02 02:56:10 +00:00
|
|
|
sector = new Uint8Array(rawData.slice(off, off + 256));
|
2021-07-07 00:04:02 +00:00
|
|
|
} else if (data) {
|
2021-01-03 23:01:30 +00:00
|
|
|
sector = data[t][physical_sector];
|
2021-07-07 00:04:02 +00:00
|
|
|
} else {
|
|
|
|
throw new Error('Requires data or rawData');
|
2019-10-02 02:56:10 +00:00
|
|
|
}
|
|
|
|
track = track.concat(
|
2021-01-03 23:01:30 +00:00
|
|
|
explodeSector13(volume, t, physical_sector, sector)
|
2019-10-02 02:56:10 +00:00
|
|
|
);
|
|
|
|
}
|
2021-07-07 00:04:02 +00:00
|
|
|
disk.tracks.push(new Uint8Array(track));
|
2019-10-02 02:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return disk;
|
|
|
|
}
|