mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Add tests for saving and restoring Disk II state
These are not exhaustive tests, but they ensure that some basic state is saved and restored.
This commit is contained in:
parent
31a7267619
commit
298ecbf25b
|
@ -338,7 +338,7 @@ export default class DiskII implements Card<State> {
|
|||
|
||||
/**
|
||||
* When `1`, the next nibble will be available for read; when `0`,
|
||||
* the drive is pretending to wait for data to be shifted in by the
|
||||
* the card is pretending to wait for data to be shifted in by the
|
||||
* sequencer.
|
||||
*/
|
||||
private skip = 0;
|
||||
|
@ -742,6 +742,9 @@ export default class DiskII implements Card<State> {
|
|||
}
|
||||
|
||||
getState(): State {
|
||||
// TODO(flan): This does not accurately save state. It's missing
|
||||
// all of the state for WOZ disks and the current status of the
|
||||
// bus.
|
||||
const result = {
|
||||
drives: [] as DriveState[],
|
||||
skip: this.skip,
|
||||
|
|
|
@ -4,7 +4,7 @@ import DiskII, { Callbacks } from 'js/cards/disk2';
|
|||
import CPU6502 from 'js/cpu6502';
|
||||
import { VideoModes } from 'js/videomodes';
|
||||
import { mocked } from 'ts-jest/utils';
|
||||
import { BYTES_BY_TRACK_IMAGE } from '../formats/testdata/16sector';
|
||||
import { BYTES_BY_SECTOR_IMAGE, BYTES_BY_TRACK_IMAGE } from '../formats/testdata/16sector';
|
||||
|
||||
jest.mock('js/apple2io');
|
||||
jest.mock('js/videomodes');
|
||||
|
@ -44,6 +44,57 @@ describe('DiskII', () => {
|
|||
expect(diskII).not.toBeNull();
|
||||
});
|
||||
|
||||
it('round-trips the state when there are no changes', () => {
|
||||
const diskII = new DiskII(mockApple2IO, callbacks);
|
||||
diskII.setBinary(1, 'BYTES_BY_TRACK', 'po', BYTES_BY_TRACK_IMAGE);
|
||||
|
||||
const state = diskII.getState();
|
||||
diskII.setState(state);
|
||||
|
||||
expect(diskII.getState()).toEqual(state);
|
||||
});
|
||||
|
||||
it('round-trips the state when there are changes', () => {
|
||||
const diskII = new DiskII(mockApple2IO, callbacks);
|
||||
diskII.setBinary(1, 'BYTES_BY_TRACK', 'po', BYTES_BY_TRACK_IMAGE);
|
||||
diskII.setBinary(2, 'BYTES_BY_SECTOR', 'po', BYTES_BY_SECTOR_IMAGE);
|
||||
|
||||
const state = diskII.getState();
|
||||
// These are just arbitrary changes, not an exhaustive list of fields.
|
||||
state.drive = 2;
|
||||
state.skip = 1;
|
||||
state.latch = 0x42;
|
||||
state.on = true;
|
||||
state.writeMode = true;
|
||||
state.drives[1].tracks[14][12] = 0x80;
|
||||
state.drives[1].head = 1000;
|
||||
state.drives[1].phase = 3;
|
||||
diskII.setState(state);
|
||||
|
||||
expect(diskII.getState()).toEqual(state);
|
||||
});
|
||||
|
||||
it('calls all of the callbacks when state is restored', () => {
|
||||
const diskII = new DiskII(mockApple2IO, callbacks);
|
||||
diskII.setBinary(1, 'BYTES_BY_TRACK', 'po', BYTES_BY_TRACK_IMAGE);
|
||||
jest.resetAllMocks();
|
||||
|
||||
const state = diskII.getState();
|
||||
diskII.setState(state);
|
||||
|
||||
expect(callbacks.driveLight).toHaveBeenCalledTimes(2);
|
||||
expect(callbacks.driveLight).toHaveBeenCalledWith(1, false);
|
||||
expect(callbacks.driveLight).toHaveBeenCalledWith(2, false);
|
||||
|
||||
expect(callbacks.label).toHaveBeenCalledTimes(2);
|
||||
expect(callbacks.label).toHaveBeenCalledWith(1, 'BYTES_BY_TRACK', undefined);
|
||||
expect(callbacks.label).toHaveBeenCalledWith(2, 'Disk 2', undefined);
|
||||
|
||||
expect(callbacks.dirty).toHaveBeenCalledTimes(2);
|
||||
expect(callbacks.dirty).toHaveBeenCalledWith(1, true);
|
||||
expect(callbacks.dirty).toHaveBeenCalledWith(2, false);
|
||||
});
|
||||
|
||||
describe('drive lights', () => {
|
||||
it('turns on drive light 1 when the motor is turned on', () => {
|
||||
const diskII = new DiskII(mockApple2IO, callbacks);
|
||||
|
|
Loading…
Reference in New Issue
Block a user