2021-07-10 00:54:27 +00:00
|
|
|
import { memory } from 'js/types';
|
2022-06-07 01:10:06 +00:00
|
|
|
import { concat } from 'js/util';
|
2020-12-29 14:40:40 +00:00
|
|
|
|
|
|
|
function generateBytesInOrder() {
|
2021-07-07 00:04:02 +00:00
|
|
|
const data: memory[][] = [];
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let t = 0; t < 35; t++) {
|
2021-07-07 00:04:02 +00:00
|
|
|
const track: memory[] = [];
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let s = 0; s < 16; s++) {
|
2021-07-07 00:04:02 +00:00
|
|
|
const sector = new Uint8Array(256);
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let b = 0; b < 256; b++) {
|
|
|
|
sector[b] = b;
|
|
|
|
}
|
|
|
|
track[s] = sector;
|
|
|
|
}
|
|
|
|
data[t] = track;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
export const BYTES_IN_ORDER: memory[][] = generateBytesInOrder();
|
2020-12-29 14:40:40 +00:00
|
|
|
|
|
|
|
function generateBytesBySector() {
|
2021-07-07 00:04:02 +00:00
|
|
|
const data: memory[][] = [];
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let t = 0; t < 35; t++) {
|
2021-07-07 00:04:02 +00:00
|
|
|
const track: memory[] = [];
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let s = 0; s < 16; s++) {
|
2021-07-07 00:04:02 +00:00
|
|
|
const sector = new Uint8Array(256);
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let b = 0; b < 256; b++) {
|
|
|
|
sector[b] = s;
|
|
|
|
}
|
|
|
|
track[s] = sector;
|
|
|
|
}
|
|
|
|
data[t] = track;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
export const BYTES_BY_SECTOR: memory[][] = generateBytesBySector();
|
2020-12-29 14:40:40 +00:00
|
|
|
|
|
|
|
function generateBytesByTrack() {
|
2021-07-07 00:04:02 +00:00
|
|
|
const data: memory[][] = [];
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let t = 0; t < 35; t++) {
|
2021-07-07 00:04:02 +00:00
|
|
|
const track: memory[] = [];
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let s = 0; s < 16; s++) {
|
2021-07-07 00:04:02 +00:00
|
|
|
const sector = new Uint8Array(256);
|
2020-12-29 14:40:40 +00:00
|
|
|
for (let b = 0; b < 256; b++) {
|
|
|
|
sector[b] = t;
|
|
|
|
}
|
|
|
|
track[s] = sector;
|
|
|
|
}
|
|
|
|
data[t] = track;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-07-07 00:04:02 +00:00
|
|
|
export const BYTES_BY_TRACK: memory[][] = generateBytesByTrack();
|
2022-06-07 01:10:06 +00:00
|
|
|
|
|
|
|
function toImage(disk: memory[][]) {
|
|
|
|
const tracks: Uint8Array[] = [];
|
|
|
|
for (let t = 0; t < disk.length; t++) {
|
|
|
|
const track = concat(...disk[t]);
|
|
|
|
tracks.push(track);
|
|
|
|
}
|
|
|
|
return concat(...tracks);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const BYTES_BY_SECTOR_IMAGE = toImage(BYTES_BY_SECTOR);
|
|
|
|
export const BYTES_BY_TRACK_IMAGE = toImage(BYTES_BY_TRACK);
|
|
|
|
|
|
|
|
function randomImage() {
|
|
|
|
const result = new Uint8Array(35 * 16 * 256);
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
result[i] = Math.floor(Math.random() * 256);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const RANDOM_IMAGE = randomImage();
|