Skip to content

Commit

Permalink
Refactor main (#17)
Browse files Browse the repository at this point in the history
* Refactor UI elements.

* Cleanup.

* Refactor core.

* Fix printer.

* Small fixes

* Fix frame counts
  • Loading branch information
whscullin committed Dec 27, 2019
1 parent 1104eeb commit bcbe36d
Show file tree
Hide file tree
Showing 18 changed files with 1,060 additions and 1,939 deletions.
15 changes: 7 additions & 8 deletions css/apple2.css
Original file line number Diff line number Diff line change
Expand Up @@ -593,16 +593,15 @@ button:focus {
list-style-type: none;
}

#printer-modal .feed {
width: 640px;
height: 480px;
overflow: auto;
}

#printer-modal .paper {
min-width: 640px;
min-height: 480px;
width: 70em;
height: 90ch;
overflow: auto;
background-color: white;
color: black;
}

#printer-modal .line {
font-family: monospace;
white-space: pre;
}
1 change: 0 additions & 1 deletion js/.gitignore

This file was deleted.

177 changes: 177 additions & 0 deletions js/apple2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import Apple2IO from './apple2io';
import { HiresPage, LoresPage, VideoModes } from './canvas';
import CPU6502 from './cpu6502';
import MMU from './mmu';
import RAM from './ram';
import { debug } from './util';

import SYMBOLS from './symbols';

export function Apple2(options) {
var stats = {
renderedFrames: 0
};

var kHz = 1023;

var paused = false;

var DEBUG = false;
var TRACE = false;
var MAX_TRACE = 256;
var trace = [];

var runTimer = null;
var cpu = new CPU6502({ '65C02': options.enhanced });

var gr = new LoresPage(1, options.characterRom, options.e, options.screen[0]);
var gr2 = new LoresPage(2, options.characterRom, options.e, options.screen[1]);
var hgr = new HiresPage(1, options.screen[2]);
var hgr2 = new HiresPage(2, options.screen[3]);

var vm = new VideoModes(gr, hgr, gr2, hgr2, options.e);
vm.multiScreen(options.multiScreen);

var io = new Apple2IO(cpu, vm);

if (options.e) {
var mmu = new MMU(cpu, vm, gr, gr2, hgr, hgr2, io, options.rom);
cpu.addPageHandler(mmu);
} else {
var ram1 = new RAM(0x00, 0x03),
ram2 = new RAM(0x0C, 0x1F),
ram3 = new RAM(0x60, 0xBF);

cpu.addPageHandler(ram1);
cpu.addPageHandler(gr);
cpu.addPageHandler(gr2);
cpu.addPageHandler(ram2);
cpu.addPageHandler(hgr);
cpu.addPageHandler(hgr2);
cpu.addPageHandler(ram3);
cpu.addPageHandler(io);
cpu.addPageHandler(options.rom);
}

var _requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;

function run() {
if (runTimer) {
clearInterval(runTimer);
}

var interval = 30;

var now, last = Date.now();
var runFn = function() {
now = Date.now();

var step = (now - last) * kHz, stepMax = kHz * interval;
last = now;
if (step > stepMax) {
step = stepMax;
}

if (DEBUG) {
cpu.stepCyclesDebug(TRACE ? 1 : step, function() {
var line = cpu.dumpRegisters() + ' ' +
cpu.dumpPC(undefined, SYMBOLS);
if (TRACE) {
debug(line);
} else {
trace.push(line);
if (trace.length > MAX_TRACE) {
trace.shift();
}
}
});
} else {
cpu.stepCycles(step);
}
if (io.annunciator(0)) {
if (options.multiScreen) {
vm.blit();
}
if (io.blit()) {
stats.renderedFrames++;
}
} else {
if (vm.blit()) {
stats.renderedFrames++;
}
}
io.tick();
options.tick();

if (!paused && _requestAnimationFrame) {
_requestAnimationFrame(runFn);
}
};
if (_requestAnimationFrame) {
_requestAnimationFrame(runFn);
} else {
runTimer = setInterval(runFn, interval);
}
}

function stop() {
if (runTimer) {
clearInterval(runTimer);
}
runTimer = null;
}

function saveState() {
var state = {
cpu: cpu.getState(),
};

return state;
}

function restoreState(state) {
cpu.setState(state.cpu);
}

return {
reset: function () {
cpu.reset();
},

run: function () {
run();
},

stop: function () {
stop();
},

saveState: function () {
saveState();
},

restoreState: function () {
restoreState();
},

getStats: function () {
return stats;
},

getCPU: function () {
return cpu;
},

getIO: function () {
return io;
},

getVideoModes: function () {
return vm;
}
};
}
8 changes: 8 additions & 0 deletions js/apple2io.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ export default function Apple2IO(cpu, callbacks)
callbacks.reset();
},

blit: function apple2io_blit() {
var card = _slot[3];
if (card && card.blit) {
return card.blit();
}
return false;
},

read: function apple2io_read(page, off) {
var result = 0;
var slot;
Expand Down
2 changes: 1 addition & 1 deletion js/applesoft/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default function ApplesoftCompiler(mem)
if (lookAhead === 'O') {
result.push(lookAhead.charCodeAt(0));
foundToken = 'TO';
tokenIdx++; foundToken = 'TO';
tokenIdx++;
}
}
foundToken = possibleToken;
Expand Down
2 changes: 1 addition & 1 deletion js/applesoft/decompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function ApplesoftDump(mem)
return str;

val = readByte(addr++);
if (val > 0x80) {
if (val >= 0x80) {
line += ' ';
line += TOKENS[val];
line += ' ';
Expand Down
5 changes: 2 additions & 3 deletions js/cards/disk2.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ export const DISK_TYPES = [
'woz'
];

export default function DiskII(io, slot, callbacks, sectors = 16)
export default function DiskII(io, callbacks, sectors = 16)
{
slot = slot || 6;
var _drives = [
{ // Drive 1
format: 'dsk',
Expand Down Expand Up @@ -134,7 +133,7 @@ export default function DiskII(io, slot, callbacks, sectors = 16)
}

function _init() {
debug('Disk ][ in slot', slot);
debug('Disk ][');
}

var _clock = 0;
Expand Down
4 changes: 2 additions & 2 deletions js/cards/langcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import RAM from '../ram';
import { debug } from '../util';

export default function LanguageCard(io, slot, rom) {
export default function LanguageCard(io, rom) {
var _rom = rom;
var _bank1 = null;
var _bank2 = null;
Expand All @@ -30,7 +30,7 @@ export default function LanguageCard(io, slot, rom) {
var _write2 = null;

function _init() {
debug('Language card in slot', slot);
debug('Language card');

_bank1 = new RAM(0xd0, 0xdf);
_bank2 = new RAM(0xd0, 0xdf);
Expand Down
5 changes: 2 additions & 3 deletions js/cards/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import { debug } from '../util';
import { rom } from '../roms/cards/parallel';

export default function Parallel(io, slot, cbs) {
slot = slot || 1;
export default function Parallel(io, cbs) {

debug('Parallel card in slot', slot);
debug('Parallel card');

var LOC = {
IOREG: 0x80
Expand Down
12 changes: 3 additions & 9 deletions js/cards/ramfactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { base64_decode, base64_encode } from '../base64';
import { allocMem, debug } from '../util';
import { rom } from '../roms/cards/ramfactor';

export default function RAMFactor(io, slot, size) {
export default function RAMFactor(io, size) {
var mem = [];

var _firmware = 0;
Expand All @@ -37,7 +37,7 @@ export default function RAMFactor(io, slot, size) {
};

function _init() {
debug('RAMFactor card in slot', slot);
debug('RAMFactor card');

mem = allocMem(size);
for (var off = 0; off < size; off++) {
Expand Down Expand Up @@ -130,13 +130,7 @@ export default function RAMFactor(io, slot, size) {
return _access(off, val);
},
read: function ramfactor_read(page, off) {
var result;
if (page == 0xc0 + slot) {
result = rom[slot << 8 | off];
} else {
result = rom[_firmware << 12 | (page - 0xC0) << 8 | off];
}
return result;
return rom[_firmware << 12 | (page - 0xC0) << 8 | off];
},
write: function ramfactor_write() {},
reset: function ramfactor_reset() {
Expand Down
2 changes: 1 addition & 1 deletion js/cards/smartport.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { base64_decode } from '../base64';
import { debug, toHex } from '../util';

export default function SmartPort(io, slot, cpu) {
export default function SmartPort(io, cpu) {

/*
$Cn01=$20
Expand Down
4 changes: 2 additions & 2 deletions js/cards/thunderclock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { debug, toHex } from '../util';
import { rom } from '../roms/cards/thunderclock';

export default function Thunderclock(io, slot)
export default function Thunderclock()
{
var LOC = {
CONTROL: 0x80,
Expand All @@ -33,7 +33,7 @@ export default function Thunderclock(io, slot)
};

function _init() {
debug('Thunderclock card in slot', slot);
debug('Thunderclock');
}

var _clock = false;
Expand Down
6 changes: 2 additions & 4 deletions js/cards/videoterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import { allocMemPages, debug } from '../util';
import { ROM, VIDEO_ROM } from '../roms/cards/videoterm';

export default function Videoterm(io, slot, context) {
slot = slot || 3;

debug('Videx Videoterm card in slot', slot);
export default function Videoterm(io, context) {
debug('Videx Videoterm');

var LOC = {
IOREG: 0x80,
Expand Down

0 comments on commit bcbe36d

Please sign in to comment.