mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
troubleshoot, fix localStorage loading
This commit is contained in:
parent
0a9b15f93e
commit
ee1faafeb3
|
@ -363,6 +363,9 @@ export default class DiskII implements Card {
|
|||
/** Current drive object. */
|
||||
private cur = this.drives[this.drive - 1];
|
||||
|
||||
/** Nibbles read this on cycle */
|
||||
private nibbleCount = 0;
|
||||
|
||||
/** Q0-Q3: Coil states. */
|
||||
private q = [false, false, false, false];
|
||||
|
||||
|
@ -587,6 +590,7 @@ export default class DiskII implements Card {
|
|||
this.debug('Drive Off');
|
||||
this.on = false;
|
||||
this.callbacks.driveLight(this.drive, false);
|
||||
this.debug('nibbles read', this.nibbleCount);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
@ -599,6 +603,7 @@ export default class DiskII implements Card {
|
|||
}
|
||||
if (!this.on) {
|
||||
this.debug('Drive On');
|
||||
this.nibbleCount = 0;
|
||||
this.on = true;
|
||||
this.lastCycles = this.io.cycles();
|
||||
this.callbacks.driveLight(this.drive, true);
|
||||
|
@ -675,6 +680,9 @@ export default class DiskII implements Card {
|
|||
// also cause conflicts with the disk controller commands.
|
||||
if ((off & 0x01) === 0) {
|
||||
result = this.latch;
|
||||
if (result & 0x80) {
|
||||
this.nibbleCount++;
|
||||
}
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
|
@ -868,15 +876,16 @@ export default class DiskII implements Card {
|
|||
this.worker.addEventListener('message', (message: MessageEvent<FormatWorkerResponse>) => {
|
||||
const { data } = message;
|
||||
switch (data.type) {
|
||||
case DISK_PROCESSED: {
|
||||
const { drive, disk } = data.payload;
|
||||
if (disk) {
|
||||
const cur = this.drives[drive - 1];
|
||||
Object.assign(cur, disk);
|
||||
this.updateDirty(drive, true);
|
||||
this.callbacks.label(this.drive, disk.name);
|
||||
case DISK_PROCESSED:
|
||||
{
|
||||
const { drive, disk } = data.payload;
|
||||
if (disk) {
|
||||
const cur = this.drives[drive - 1];
|
||||
Object.assign(cur, disk);
|
||||
this.updateDirty(drive, true);
|
||||
this.callbacks.label(drive, disk.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -470,8 +470,7 @@ export function jsonEncode(disk: NibbleDisk, pretty: boolean): string {
|
|||
/**
|
||||
* Convert a JSON string into a nibblized disk.
|
||||
*
|
||||
* @param data JSON string representing a disk image, created by disk2json or
|
||||
* [jsonEncode].
|
||||
* @param data JSON string representing a disk image, created by [jsonEncode].
|
||||
* @returns A nibblized disk
|
||||
*/
|
||||
|
||||
|
@ -483,14 +482,14 @@ export function jsonDecode(data: string): NibbleDisk {
|
|||
for (let t = 0; t < json.data.length; t++) {
|
||||
let track: byte[] = [];
|
||||
for (let s = 0; s < json.data[t].length; s++) {
|
||||
const _s = 15 - s;
|
||||
const _s = json.type == 'po' ? PO[s] : DO[s];
|
||||
const sector: string = json.data[t][_s];
|
||||
const d = base64_decode(sector);
|
||||
track = track.concat(explodeSector16(v, t, s, d));
|
||||
}
|
||||
tracks[t] = bytify(track);
|
||||
}
|
||||
const cur: NibbleDisk = {
|
||||
const disk: NibbleDisk = {
|
||||
volume: v,
|
||||
format: json.type,
|
||||
encoding: ENCODING_NIBBLE,
|
||||
|
@ -499,5 +498,62 @@ export function jsonDecode(data: string): NibbleDisk {
|
|||
readOnly,
|
||||
};
|
||||
|
||||
return cur;
|
||||
return disk;
|
||||
}
|
||||
|
||||
export function analyseDisk(disk: NibbleDisk) {
|
||||
for (let track = 0; track < 35; track++) {
|
||||
let outStr = `${toHex(track)}: `;
|
||||
let val, state = 0;
|
||||
let idx = 0;
|
||||
const cur = disk.tracks[track];
|
||||
|
||||
const _readNext = () => {
|
||||
const result = cur[idx++];
|
||||
return result;
|
||||
};
|
||||
|
||||
const _skipBytes = (count: number) => {
|
||||
idx += count;
|
||||
};
|
||||
|
||||
let t = 0, s = 0, v = 0, checkSum;
|
||||
while (idx < cur.length) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
val = _readNext();
|
||||
state = (val === 0xd5) ? 1 : 0;
|
||||
break;
|
||||
case 1:
|
||||
val = _readNext();
|
||||
state = (val === 0xaa) ? 2 : 0;
|
||||
break;
|
||||
case 2:
|
||||
val = _readNext();
|
||||
state = (val === 0x96) ? 3 : (val === 0xad ? 4 : 0);
|
||||
break;
|
||||
case 3: // Address
|
||||
v = defourXfour(_readNext(), _readNext()); // Volume
|
||||
t = defourXfour(_readNext(), _readNext());
|
||||
s = defourXfour(_readNext(), _readNext());
|
||||
checkSum = defourXfour(_readNext(), _readNext());
|
||||
if (checkSum != (v ^ t ^ s)) {
|
||||
debug('Invalid header checksum:', toHex(v), toHex(t), toHex(s), toHex(checkSum));
|
||||
} else {
|
||||
outStr += toHex(s, 1);
|
||||
}
|
||||
_skipBytes(3); // Skip footer
|
||||
state = 0;
|
||||
break;
|
||||
case 4: // Valid header
|
||||
_skipBytes(0x159); // Skip data, checksum and footer
|
||||
state = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
debug(outStr);
|
||||
}
|
||||
return new Uint8Array();
|
||||
}
|
||||
|
|
|
@ -105,9 +105,10 @@ export function compileAppleSoftProgram(program: string) {
|
|||
}
|
||||
|
||||
export function openLoad(driveString: string, event: MouseEvent) {
|
||||
const drive = parseInt(driveString, 10);
|
||||
const drive = parseInt(driveString, 10) as DriveNumber;
|
||||
_currentDrive = drive;
|
||||
if (event.metaKey && includes(DRIVE_NUMBERS, drive)) {
|
||||
openLoadHTTP(drive);
|
||||
openLoadHTTP();
|
||||
} else {
|
||||
if (disk_cur_cat[drive]) {
|
||||
const element = document.querySelector<HTMLSelectElement>('#category_select')!;
|
||||
|
@ -485,8 +486,7 @@ export function doLoadHTTP(drive: DriveNumber, url?: string) {
|
|||
}
|
||||
}
|
||||
|
||||
function openLoadHTTP(drive: DriveNumber) {
|
||||
_currentDrive = drive;
|
||||
function openLoadHTTP() {
|
||||
MicroModal.show('http-modal');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user