Keep track of disk sides

This commit is contained in:
Will Scullin 2021-09-28 20:28:30 -07:00
parent 198cf74c75
commit 3c86264ca7
8 changed files with 44 additions and 16 deletions

View File

@ -165,7 +165,7 @@ const PHASE_DELTA = [
export interface Callbacks {
driveLight: (drive: DriveNumber, on: boolean) => void;
dirty: (drive: DriveNumber, dirty: boolean) => void;
label: (drive: DriveNumber, name: string) => void;
label: (drive: DriveNumber, name?: string, side?: string) => void;
}
/** Common information for Nibble and WOZ disks. */
@ -177,6 +177,8 @@ interface BaseDrive {
volume: byte,
/** Displayed disk name */
name: string,
/** (Optional) Disk side (Front/Back, A/B) */
side?: string,
/** Quarter track position of read/write head. */
track: byte,
/** Position of the head on the track. */
@ -222,6 +224,7 @@ interface DriveState {
encoding: typeof ENCODING_BITSTREAM | typeof ENCODING_NIBBLE
volume: byte,
name: string,
side?: string,
tracks: memory[],
track: byte,
head: byte,
@ -247,6 +250,7 @@ function getDriveState(drive: Drive): DriveState {
encoding: drive.encoding,
volume: drive.volume,
name: drive.name,
side: drive.side,
tracks: [],
track: drive.track,
head: drive.head,
@ -279,6 +283,7 @@ function setDriveState(state: DriveState) {
encoding: ENCODING_NIBBLE,
volume: state.volume,
name: state.name,
side: state.side,
tracks: [],
track: state.track,
head: state.head,
@ -295,6 +300,7 @@ function setDriveState(state: DriveState) {
encoding: ENCODING_BITSTREAM,
volume: state.volume,
name: state.name,
side: state.side,
track: state.track,
head: state.head,
phase: state.phase,
@ -752,9 +758,10 @@ export default class DiskII implements Card {
for (const d of DRIVE_NUMBERS) {
const idx = d - 1;
this.drives[idx] = setDriveState(state.drives[idx]);
this.callbacks.label(d, state.drives[idx].name);
const { name, side, dirty } = state.drives[idx];
this.callbacks.label(d, name, side);
this.callbacks.driveLight(d, this.on);
this.callbacks.dirty(d, this.drives[idx].dirty);
this.callbacks.dirty(d, dirty);
}
this.cur = this.drives[this.drive - 1];
}
@ -800,7 +807,7 @@ export default class DiskII implements Card {
const cur = this.drives[drive - 1];
Object.assign(cur, disk);
this.updateDirty(drive, false);
this.callbacks.label(drive, disk.name);
this.callbacks.label(drive, disk.name, disk.side);
return true;
}
}
@ -858,9 +865,10 @@ export default class DiskII implements Card {
const disk = createDisk(fmt, options);
if (disk) {
const cur = this.drives[drive - 1];
const { name, side } = cur;
Object.assign(cur, disk);
this.updateDirty(drive, true);
this.callbacks.label(drive, name);
this.callbacks.label(drive, name, side);
return true;
}
@ -880,8 +888,9 @@ export default class DiskII implements Card {
if (disk) {
const cur = this.drives[drive - 1];
Object.assign(cur, disk);
const { name, side } = cur;
this.updateDirty(drive, true);
this.callbacks.label(drive, disk.name);
this.callbacks.label(drive, name, side);
}
}
break;

View File

@ -46,6 +46,7 @@ export function createDiskFromJsonDisk(disk: JSONDisk): FloppyDisk | null {
const fmt = disk.type;
const readOnly = disk.readOnly;
const name = disk.name;
const side = disk.disk;
if (includes(NIBBLE_FORMATS, fmt)) {
let trackData: memory[][];
@ -71,6 +72,7 @@ export function createDiskFromJsonDisk(disk: JSONDisk): FloppyDisk | null {
volume,
readOnly,
name,
side,
data: trackData
} as DiskOptions;

View File

@ -18,11 +18,12 @@ import { NibbleDisk, DiskOptions, ENCODING_NIBBLE } from './types';
* @returns A nibblized disk
*/
export default function createDiskFromDOS13(options: DiskOptions) {
const { data, name, rawData, volume, readOnly } = options;
const { data, name, side, rawData, volume, readOnly } = options;
const disk: NibbleDisk = {
format: 'd13',
encoding: ENCODING_NIBBLE,
name,
side,
volume,
readOnly,
tracks: []

View File

@ -20,11 +20,12 @@ import { NibbleDisk, DiskOptions, ENCODING_NIBBLE } from './types';
* @returns A nibblized disk
*/
export default function createDiskFromDOS(options: DiskOptions): NibbleDisk {
const { data, name, rawData, volume, readOnly } = options;
const { data, name, side, rawData, volume, readOnly } = options;
const disk: NibbleDisk = {
format: 'dsk',
encoding: ENCODING_NIBBLE,
name,
side,
volume,
readOnly,
tracks: [],

View File

@ -18,11 +18,12 @@ import { memory } from '../types';
* @returns A nibblized disk
*/
export default function createDiskFromNibble(options: DiskOptions): NibbleDisk {
const { data, name, rawData, volume, readOnly } = options;
const { data, name, side, rawData, volume, readOnly } = options;
const disk: NibbleDisk = {
format: 'nib',
encoding: ENCODING_NIBBLE,
name,
side,
volume: volume || 254,
readOnly: readOnly || false,
tracks: []

View File

@ -21,6 +21,7 @@ export type DriveNumber = MemberOf<typeof DRIVE_NUMBERS>;
export interface DiskOptions {
name: string
side?: string
volume: byte
readOnly: boolean
data?: memory[][]
@ -35,6 +36,7 @@ export interface DiskOptions {
export interface Disk {
name: string
side?: string
readOnly: boolean
}
@ -97,7 +99,7 @@ export type DiskFormat = MemberOf<typeof DISK_FORMATS>;
export class JSONDiskBase {
type: DiskFormat
name: string
disk?: number
disk?: string
category?: string
writeProtected?: boolean
volume: byte

View File

@ -14,11 +14,11 @@ export default class DriveLights implements Callbacks {
// document.querySelector('#disksave' + drive).disabled = !dirty;
}
public label(drive: DriveNumber, label?: string) {
public label(drive: DriveNumber, label?: string, side?: string) {
const labelElement =
document.querySelector('#disk-label' + drive)! as HTMLElement;
if (label) {
labelElement.innerText = label;
labelElement.innerText = label + (side ? ` - ${side}` : '');
}
return labelElement.innerText;
}

View File

@ -1,8 +1,15 @@
disk_index = [
{
"filename": "json/disks/audit.json",
"name": "Apple II Audit",
"category": "Utility"
"filename": "json/disks/shell-shock-game.json",
"name": "Shell Shock",
"disk": "Game",
"category": "Game"
},
{
"filename": "json/disks/shell-shock-maps.json",
"name": "Shell Shock",
"disk": "Maps",
"category": "Game"
},
{
"filename": "json/disks/dos33master.json",
@ -13,5 +20,10 @@ disk_index = [
"filename": "json/disks/prodos.json",
"name": "ProDOS",
"category": "System"
},
{
"filename": "json/disks/audit.json",
"name": "Apple II Audit",
"category": "Utility"
}
];
];