2021-07-07 00:04:02 +00:00
|
|
|
import { includes, memory } from '../types';
|
|
|
|
import { base64_decode } from '../base64';
|
2021-07-10 00:54:27 +00:00
|
|
|
import { DiskOptions, FloppyDisk, JSONDisk, NibbleFormat, NIBBLE_FORMATS } from './types';
|
2021-07-07 00:04:02 +00:00
|
|
|
import createDiskFrom2MG from './2mg';
|
|
|
|
import createDiskFromD13 from './d13';
|
|
|
|
import createDiskFromDOS from './do';
|
|
|
|
import createDiskFromProDOS from './po';
|
|
|
|
import createDiskFromWoz from './woz';
|
|
|
|
import createDiskFromNibble from './nib';
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fmt Type of
|
|
|
|
* @param options
|
|
|
|
* @returns A nibblized disk
|
|
|
|
*/
|
2021-07-10 00:54:27 +00:00
|
|
|
export function createDisk(fmt: NibbleFormat, options: DiskOptions): FloppyDisk | null {
|
|
|
|
let disk: FloppyDisk | null = null;
|
2021-07-07 00:04:02 +00:00
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case '2mg':
|
|
|
|
disk = createDiskFrom2MG(options);
|
|
|
|
break;
|
|
|
|
case 'd13':
|
|
|
|
disk = createDiskFromD13(options);
|
|
|
|
break;
|
|
|
|
case 'do':
|
|
|
|
case 'dsk':
|
|
|
|
disk = createDiskFromDOS(options);
|
|
|
|
break;
|
|
|
|
case 'nib':
|
|
|
|
disk = createDiskFromNibble(options);
|
|
|
|
break;
|
|
|
|
case 'po':
|
|
|
|
disk = createDiskFromProDOS(options);
|
|
|
|
break;
|
|
|
|
case 'woz':
|
|
|
|
disk = createDiskFromWoz(options);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return disk;
|
|
|
|
}
|
|
|
|
|
2021-07-10 00:54:27 +00:00
|
|
|
export function createDiskFromJsonDisk(disk: JSONDisk): FloppyDisk | null {
|
2021-07-07 00:04:02 +00:00
|
|
|
const fmt = disk.type;
|
|
|
|
const readOnly = disk.readOnly;
|
|
|
|
const name = disk.name;
|
2021-10-02 18:45:09 +00:00
|
|
|
const side = disk.disk;
|
2021-07-07 00:04:02 +00:00
|
|
|
|
|
|
|
if (includes(NIBBLE_FORMATS, fmt)) {
|
|
|
|
let trackData: memory[][];
|
2022-05-18 15:19:45 +00:00
|
|
|
if (disk.encoding === 'base64') {
|
2021-07-07 00:04:02 +00:00
|
|
|
trackData = [];
|
|
|
|
for (let t = 0; t < disk.data.length; t++) {
|
|
|
|
trackData[t] = [];
|
2021-10-02 18:45:09 +00:00
|
|
|
if (disk.type === 'nib') {
|
|
|
|
trackData[t][0] = base64_decode(disk.data[t]);
|
2021-07-07 00:04:02 +00:00
|
|
|
} else {
|
|
|
|
for (let s = 0; s < disk.data[t].length; s++) {
|
2021-10-02 18:45:09 +00:00
|
|
|
trackData[t][s] = base64_decode(disk.data[t][s]);
|
2021-07-07 00:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
trackData = disk.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const volume = disk.volume || 0xfe;
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
volume,
|
|
|
|
readOnly,
|
|
|
|
name,
|
2021-10-02 18:45:09 +00:00
|
|
|
side,
|
2021-07-07 00:04:02 +00:00
|
|
|
data: trackData
|
|
|
|
} as DiskOptions;
|
|
|
|
|
|
|
|
return createDisk(fmt, options);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|