This commit is contained in:
Will Scullin 2021-07-09 06:56:13 -07:00
parent 6423eacbe3
commit ed327c0770
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
2 changed files with 54 additions and 32 deletions

View File

@ -9,7 +9,7 @@
* implied warranty.
*/
import { byte, memory } from '../types';
import { bit, byte, memory } from '../types';
import { base64_decode, base64_encode } from '../base64';
import { bytify, debug, toHex } from '../util';
import { NibbleDisk, ENCODING_NIBBLE } from './types';
@ -501,6 +501,12 @@ export function jsonDecode(data: string): NibbleDisk {
return disk;
}
/**
* Debugging method that displays the logical sector ordering of a nibblized disk
*
* @param disk
*/
export function analyseDisk(disk: NibbleDisk) {
for (let track = 0; track < 35; track++) {
let outStr = `${toHex(track)}: `;
@ -555,5 +561,38 @@ export function analyseDisk(disk: NibbleDisk) {
}
debug(outStr);
}
return new Uint8Array();
}
/**
*
* @param bits Bitstream containing nibbles
* @param offset Offset into bitstream to start nibblizing
* @returns The next nibble in the bitstream
*/
export function grabNibble(bits: bit[], offset: number) {
let nibble = 0;
let waitForOne = true;
while (offset < bits.length) {
const bit = bits[offset];
if (bit) {
nibble = (nibble << 1) | 0x01;
waitForOne = false;
} else {
if (!waitForOne) {
nibble = nibble << 1;
}
}
if (nibble & 0x80) {
// nibble complete return it
break;
}
offset += 1;
}
return {
nibble: nibble,
offset: offset
};
}

View File

@ -10,8 +10,9 @@
*/
import { debug, toHex } from '../util';
import { DiskOptions, ENCODING_BITSTREAM, WozDisk } from './types';
import { bit, byte, word } from '../types';
import { grabNibble } from './format_utils';
import { DiskOptions, ENCODING_BITSTREAM, WozDisk } from './types';
const WOZ_HEADER_START = 0;
const WOZ_HEADER_SIZE = 12;
@ -20,6 +21,15 @@ const WOZ1_SIGNATURE = 0x315A4F57;
const WOZ2_SIGNATURE = 0x325A4F57;
const WOZ_INTEGRITY_CHECK = 0x0a0d0aff;
/**
* Converts a range of bytes from a DataView into an ASCII string
*
* @param data DataView containing string
* @param start start index of string
* @param end end index of string
* @returns ASCII string
*/
function stringFromBytes(data: DataView, start: number, end: number): string {
return String.fromCharCode.apply(
null,
@ -27,33 +37,6 @@ function stringFromBytes(data: DataView, start: number, end: number): string {
);
}
function grabNibble(bits: bit[], offset: number) {
let nibble = 0;
let waitForOne = true;
while (offset < bits.length) {
const bit = bits[offset];
if (bit) {
nibble = (nibble << 1) | 0x01;
waitForOne = false;
} else {
if (!waitForOne) {
nibble = nibble << 1;
}
}
if (nibble & 0x80) {
// nibble complete return it
break;
}
offset += 1;
}
return {
nibble: nibble,
offset: offset
};
}
export class InfoChunk {
version: byte
@ -128,7 +111,7 @@ export class TrksChunk1 extends TrksChunk {
for (let jdx = 0; jdx < trackBitCount; jdx++) {
const byteIndex = jdx >> 3;
const bitIndex = 7 - (jdx & 0x07);
rawTrack[jdx] = (trackData[byteIndex] >> bitIndex) ? 1 : 0;
rawTrack[jdx] = (trackData[byteIndex] >> bitIndex) & 0x01 ? 1 : 0;
}
track = [];
@ -187,7 +170,7 @@ export class TrksChunk2 extends TrksChunk {
for (let jdx = 0; jdx < trk.bitCount; jdx++) {
const byteIndex = jdx >> 3;
const bitIndex = 7 - (jdx & 0x07);
rawTrack[jdx] = (trackData[byteIndex] >> bitIndex) ? 1 : 0;
rawTrack[jdx] = (trackData[byteIndex] >> bitIndex) & 0x01 ? 1 : 0;
}
track = [];