This commit is contained in:
Will Scullin 2021-07-08 21:19:15 -07:00
parent e9cbef6988
commit 6423eacbe3
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
3 changed files with 26 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* Copyright 2010-2019 Will Scullin <scullin@scullinsteel.com>
/* Copyright 2010-2021 Will Scullin <scullin@scullinsteel.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@ -11,7 +11,7 @@
import { debug, toHex } from '../util';
import { DiskOptions, ENCODING_BITSTREAM, WozDisk } from './types';
import { byte, word } from '../types';
import { bit, byte, word } from '../types';
const WOZ_HEADER_START = 0;
const WOZ_HEADER_SIZE = 12;
@ -27,7 +27,7 @@ function stringFromBytes(data: DataView, start: number, end: number): string {
);
}
function grabNibble(bits: number[], offset: number) {
function grabNibble(bits: bit[], offset: number) {
let nibble = 0;
let waitForOne = true;
@ -120,7 +120,7 @@ export class TrksChunk1 extends TrksChunk {
for (let trackNo = 0, idx = 0; idx < data.byteLength; idx += WOZ_TRACK_SIZE, trackNo++) {
let track = [];
const rawTrack = [];
const rawTrack: bit[] = [];
const slice = data.buffer.slice(data.byteOffset + idx, data.byteOffset + idx + WOZ_TRACK_SIZE);
const trackData = new Uint8Array(slice);
const trackInfo = new DataView(slice);
@ -128,7 +128,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) & 0x1;
rawTrack[jdx] = (trackData[byteIndex] >> bitIndex) ? 1 : 0;
}
track = [];
@ -179,7 +179,7 @@ export class TrksChunk2 extends TrksChunk {
const trk = this.trks[trackNo];
let track = [];
const rawTrack = [];
const rawTrack: bit[] = [];
const start = trk.startBlock * 512;
const end = start + trk.blockCount * 512;
const slice = bits.slice(start, end);
@ -187,7 +187,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) & 0x1;
rawTrack[jdx] = (trackData[byteIndex] >> bitIndex) ? 1 : 0;
}
track = [];

View File

@ -51,7 +51,7 @@ export class AppleAudioProcessor extends AudioWorkletProcessor {
}
// Keep alive indefinitely.
return false;
return true;
}
}

View File

@ -41,19 +41,35 @@ export function findBytes(track: memory, bytes: number[], start: number = 0): nu
return -1;
}
/**
* Convert an ASCII character string into an array of bytes, with optional
* padding.
*
* @param val ASCII character string
* @param pad ASCII character to fill reach padded length
* @param padLength padded length
* @returns an array of bytes
*/
export const stringToBytes = (val: string, pad: string = '\0', padLength: number = 0) => {
const result = [];
let idx = 0;
while (idx < val.length) {
result.push(val.charCodeAt(idx) & 0xff);
result.push(val.charCodeAt(idx) & 0x7f);
idx++;
}
while (idx++ < padLength) {
result.push(pad.charCodeAt(0));
result.push(pad.charCodeAt(0) & 0x7f);
}
return result;
};
/**
* Convert a number into a little endian array of bytes.
*
* @param val a number
* @param count number of bytes in result
* @returns an array of bytes
*/
export const numberToBytes = (val: number, count: number) => {
const result = [];
let idx = 0;