apple2js/js/formats/do.js
Ian Flanigan 72ecce113a
DOS 3.3 image format tests and fixes (#49)
* Adds an initial test for DOS format (.do) files

* Fix physical sector order when nibblizing DOS 3.3 ordered images

Before, when `.dsk` or `.do` images were nibblized, the resulting
track had the sectors in the wrong physical layout.

Now the nibblized track has the correct physical layout (all sectors
in order) which results in the correct DOS 3.3 layout as well.

There is also a test that verifies the order.

* Add another test for a non-zero sector

The new test checks that the values in physical sector 1 are those for
DOS sector 7.

* Add test for all physical sectors on all tracks

This change also removes a few stray console.log calls in the test.
2020-12-29 06:40:40 -08:00

51 lines
1.7 KiB
JavaScript

/* Copyright 2010-2019 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
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
import { explodeSector16, DO } from './format_utils';
import { bytify } from '../util';
/**
* Returns a `Disk` object from DOS-ordered image data.
* @param {*} options the disk image and options
* @returns {import('./format_utils').Disk}
*/
export default function DOS(options) {
var { data, name, rawData, volume, readOnly } = options;
var disk = {
format: 'dsk',
name,
volume,
readOnly,
tracks: [],
trackMap: null,
rawTracks: null
};
for (var t = 0; t < 35; t++) {
var track = [];
for (var physical_sector = 0; physical_sector < 16; physical_sector++) {
const dos_sector = DO[physical_sector];
var sector;
if (rawData) {
const off = (16 * t + dos_sector) * 256;
sector = new Uint8Array(rawData.slice(off, off + 256));
} else {
sector = data[t][dos_sector];
}
track = track.concat(
explodeSector16(volume, t, physical_sector, sector)
);
}
disk.tracks[t] = bytify(track);
}
return disk;
}