started williams games

This commit is contained in:
Steven Hugg 2017-01-19 22:42:58 -05:00
parent c5e4622480
commit 17370248ee
8 changed files with 2894 additions and 66 deletions

View File

@ -273,12 +273,15 @@ canvas.pixelated {
<script src="javatari.js/release/javatari/javatari.js"></script>
<script src="src/cpu/z80.js"></script>
<script src="src/cpu/6809.js"></script>
<script src="tss/js/tss/PsgDeviceChannel.js"></script>
<script src="tss/js/tss/MasterChannel.js"></script>
<script src="tss/js/tss/AudioLooper.js"></script>
<script src="tss/js/Log.js"></script>
<script src="local/williams/defender.js"></script>
<script src="src/emu.js"></script>
<script src="src/util.js"></script>
<script src="src/disasm.js"></script>

2451
src/cpu/6809.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2444,13 +2444,13 @@ window.buildZ80 = (opts) ->
regPairs[#{rpSP}] = snapRegs['SP'];
regPairs[#{rpPC}] = snapRegs['PC'];
regPairs[#{rpIR}] = snapRegs['IR'];
iff1 = snapRegs['iff1'];
iff2 = snapRegs['iff2'];
im = snapRegs['im'];
halted = snapRegs['halted'];
tstates = snapRegs['tstates'];
interruptPending = snapRegs['intp'];
interruptDataBus = snapRegs['intd'];
iff1 = snapRegs['iff1'] & 1;
iff2 = snapRegs['iff2'] & 1;
im = snapRegs['im'] & 1;
halted = !!snapRegs['halted'];
tstates = snapRegs['T'] * 1;
interruptPending = !!snapRegs['intp'];
interruptDataBus = snapRegs['intd'] & 0xffff;
};
self.saveState = function() {
@ -2472,7 +2472,7 @@ window.buildZ80 = (opts) ->
iff2: iff2,
im: im,
halted: halted,
tstates: tstates,
T: tstates,
intp: interruptPending,
intd: interruptDataBus,
};
@ -2577,23 +2577,23 @@ window.buildZ80 = (opts) ->
regPairs[#{rpPC}] = val;
}
self.setIFF1 = function(val) {
iff1 = val;
iff1 = val & 1;
}
self.setIFF2 = function(val) {
iff2 = val;
iff2 = val & 1;
}
self.setIM = function(val) {
im = val;
im = val & 1;
}
self.setHalted = function(val) {
halted = val;
halted = !!val;
}
self.getTstates = function() {
return tstates;
}
self.setTstates = function(val) {
tstates = val;
tstates = val * 1;
}
self.getCarry_ = function() {

File diff suppressed because one or more lines are too long

View File

@ -45,6 +45,8 @@ var RasterVideo = function(mainElement, width, height, options) {
canvas.style.transform = "rotate("+options.rotate+"deg)";
if (canvas.width > canvas.height)
canvas.style.paddingTop = canvas.style.paddingBottom = "10%";
else
canvas.style.paddingLeft = canvas.style.paddingRight = "10%";
}
ctx = canvas.getContext('2d');
imageData = ctx.createImageData(width, height);
@ -332,7 +334,7 @@ function cpuStateToLongString_6502(c) {
// s += c.I ? " I" : " -";
return s;
}
return "PC " + hex(c.PC,4) + " " + decodeFlags(c) + " " + getTIAPosString() + "\n"
return "PC " + hex(c.PC,4) + " " + decodeFlags(c) + "\n"
+ " A " + hex(c.A) + " " + (c.R ? "" : "BUSY") + "\n"
+ " X " + hex(c.X) + "\n"
+ " Y " + hex(c.Y) + " " + "SP " + hex(c.SP) + "\n";
@ -389,7 +391,8 @@ var Base6502Platform = function() {
onBreakpointHit = null;
debugCondition = null;
}
this.breakpointHit = function() {
this.breakpointHit = function(targetClock) {
debugTargetClock = targetClock;
debugBreakState = this.saveState();
debugBreakState.c.PC = (debugBreakState.c.PC-1) & 0xffff;
console.log("Breakpoint at clk", debugClock, "PC", debugBreakState.c.PC.toString(16));
@ -410,8 +413,7 @@ var Base6502Platform = function() {
} else {
if (thisState.PC != previousPC && thisState.T == 0) {
//console.log(previousPC.toString(16), thisPC.toString(16));
debugTargetClock = debugClock-1;
self.breakpointHit();
self.breakpointHit(debugClock-1);
return true;
}
}
@ -426,12 +428,10 @@ var Base6502Platform = function() {
this.setDebugCondition(function() {
if (debugClock++ >= debugTargetClock && prevState) {
self.loadState(prevState);
debugTargetClock = prevClock-1;
self.breakpointHit();
self.breakpointHit(prevClock-1);
return true;
} else if (debugClock > debugTargetClock-10 && debugClock < debugTargetClock) {
if (self.getCPUState().T == 0) {
console.log(debugClock, self.getCPUState());
prevState = self.saveState();
prevClock = debugClock;
}
@ -446,8 +446,7 @@ var Base6502Platform = function() {
var cpuState = self.getCPUState();
cpuState.PC = (cpuState.PC-1)&0xffff;
if (evalfunc(cpuState)) {
self.breakpointHit();
debugTargetClock = debugClock-1;
self.breakpointHit(debugClock-1);
return true;
} else {
return false;
@ -497,6 +496,8 @@ function dumpRAM(ram, ramofs, ramlen) {
return s;
}
////// Z80
function cpuStateToLongString_Z80(c) {
function decodeFlags(flags) {
var flagspec = "SZ-H-VNC";
@ -505,7 +506,7 @@ function cpuStateToLongString_Z80(c) {
s += (flags & (128>>i)) ? flagspec.slice(i,i+1) : "-";
return s; // TODO
}
return "PC " + hex(c.PC,4) + " " + decodeFlags(c.AF) + " " + getTIAPosString() + "\n"
return "PC " + hex(c.PC,4) + " " + decodeFlags(c.AF) + "\n"
+ "SP " + hex(c.SP,4) + " IR " + hex(c.IR,4) + "\n"
+ "IX " + hex(c.IX,4) + " IY " + hex(c.IY,4) + "\n"
+ "AF " + hex(c.AF,4) + " BC " + hex(c.BC,4) + "\n"
@ -513,8 +514,6 @@ function cpuStateToLongString_Z80(c) {
;
}
////// Z80
var BaseZ80Platform = function() {
var onBreakpointHit;
@ -536,8 +535,8 @@ var BaseZ80Platform = function() {
this.restartDebugState = function() {
if (debugCondition && !debugBreakState && debugTargetClock > 0) {
debugSavedState = this.saveState();
debugTargetClock -= debugSavedState.c.tstates;
debugSavedState.c.tstates = 0;
debugTargetClock -= debugSavedState.c.T;
debugSavedState.c.T = 0;
this.loadState(debugSavedState);
}
}
@ -554,10 +553,11 @@ var BaseZ80Platform = function() {
onBreakpointHit = null;
debugCondition = null;
}
this.breakpointHit = function() {
this.breakpointHit = function(targetClock) {
debugTargetClock = targetClock;
debugBreakState = this.saveState();
//debugBreakState.c.PC = (debugBreakState.c.PC-1) & 0xffff;
console.log("Breakpoint at clk", debugBreakState.c.tstates, "PC", debugBreakState.c.PC.toString(16));
console.log("Breakpoint at clk", debugBreakState.c.T, "PC", debugBreakState.c.PC.toString(16));
this.pause();
if (onBreakpointHit) {
onBreakpointHit(debugBreakState);
@ -568,9 +568,8 @@ var BaseZ80Platform = function() {
var self = this;
this.setDebugCondition(function() {
var cpuState = self.getCPUState();
if (cpuState.tstates > debugTargetClock) {
debugTargetClock = cpuState.tstates;
self.breakpointHit();
if (cpuState.T > debugTargetClock) {
self.breakpointHit(cpuState.T);
return true;
}
return false;
@ -582,11 +581,10 @@ var BaseZ80Platform = function() {
var prevClock;
this.setDebugCondition(function() {
var cpuState = self.getCPUState();
var debugClock = cpuState.tstates;
var debugClock = cpuState.T;
if (debugClock >= debugTargetClock && prevState) {
self.loadState(prevState);
debugTargetClock = prevClock;
self.breakpointHit();
self.breakpointHit(prevClock);
return true;
} else if (debugClock > debugTargetClock-20 && debugClock < debugTargetClock) {
prevState = self.saveState();
@ -599,10 +597,9 @@ var BaseZ80Platform = function() {
var self = this;
this.setDebugCondition(function() {
var cpuState = self.getCPUState();
if (cpuState.tstates > debugTargetClock) {
if (cpuState.T > debugTargetClock) {
if (evalfunc(cpuState)) {
debugTargetClock = cpuState.tstates;
self.breakpointHit();
self.breakpointHit(cpuState.T);
return true;
}
}
@ -622,9 +619,6 @@ var BaseZ80Platform = function() {
--depth;
return false;
});
}
this.disassemble = function(mem, start, end, pcvisits) {
return new Disassembler6502().disassemble(mem, start, end, pcvisits);
}
this.cpuStateToLongString = function(c) {
return cpuStateToLongString_Z80(c);
@ -638,6 +632,171 @@ var BaseZ80Platform = function() {
//this.getOpcodeMetadata = function() { }
}
////// 6809
function cpuStateToLongString_6809(c) {
function decodeFlags(flags) {
var flagspec = "SZ-H-VNC";
var s = "";
for (var i=0; i<8; i++)
s += (flags & (128>>i)) ? flagspec.slice(i,i+1) : "-";
return s; // TODO
}
return "PC " + hex(c.PC,4) + " " + decodeFlags(c.CC) + "\n"
+ "SP " + hex(c.SP,4) + "\n"
;
}
var Base6809Platform = function() {
this.__proto__ = new BaseZ80Platform();
this.runUntilReturn = function() {
var self = this;
var depth = 1;
self.runEval(function(c) {
if (depth <= 0)
return true;
var op = self.readAddress(c.PC);
// TODO: 6809 opcodes
if (op == 0xcd) // CALL
depth++;
else if (op == 0xc0 || op == 0xc8 || op == 0xc9 || op == 0xd0) // RET (TODO?)
--depth;
return false;
});
}
this.cpuStateToLongString = function(c) {
return cpuStateToLongString_6809(c);
}
this.getToolForFilename = function(fn) {
if (fn.endsWith(".c")) return "sdcc";
if (fn.endsWith(".s")) return "sdasz80";
return "z80asm";
}
// TODO
this.disassemble = function(pc, read) {
// TODO: don't create new CPU
return new CPU6809().disasm(read(pc), read(pc+1), read(pc+2), read(pc+3), read(pc+4), pc);
}
//this.getOpcodeMetadata = function() { }
}
//////////
var Keys = {
VK_ESCAPE: {c: 27, n: "Esc"},
VK_F1: {c: 112, n: "F1"},
VK_F2: {c: 113, n: "F2"},
VK_F3: {c: 114, n: "F3"},
VK_F4: {c: 115, n: "F4"},
VK_F5: {c: 116, n: "F5"},
VK_F6: {c: 117, n: "F6"},
VK_F7: {c: 118, n: "F7"},
VK_F8: {c: 119, n: "F8"},
VK_F9: {c: 120, n: "F9"},
VK_F10: {c: 121, n: "F10"},
VK_F11: {c: 122, n: "F11"},
VK_F12: {c: 123, n: "F12"},
VK_SCROLL_LOCK: {c: 145, n: "ScrLck"},
VK_PAUSE: {c: 19, n: "Pause"},
VK_QUOTE: {c: 192, n: "'"},
VK_TILDE: {c: 222, n: "~"},
VK_1: {c: 49, n: "1"},
VK_2: {c: 50, n: "2"},
VK_3: {c: 51, n: "3"},
VK_4: {c: 52, n: "4"},
VK_5: {c: 53, n: "5"},
VK_6: {c: 54, n: "6"},
VK_7: {c: 55, n: "7"},
VK_8: {c: 56, n: "8"},
VK_9: {c: 57, n: "9"},
VK_0: {c: 48, n: "0"},
VK_MINUS: {c: 189, n: "-"},
VK_MINUS2: {c: 173, n: "-"},
VK_EQUALS: {c: 187, n: "="},
VK_EQUALS2: {c: 61, n: "="},
VK_BACK_SPACE: {c: 8, n: "Bkspc"},
VK_TAB: {c: 9, n: "Tab"},
VK_Q: {c: 81, n: "Q"},
VK_W: {c: 87, n: "W"},
VK_E: {c: 69, n: "E"},
VK_R: {c: 82, n: "R"},
VK_T: {c: 84, n: "T"},
VK_Y: {c: 89, n: "Y"},
VK_U: {c: 85, n: "U"},
VK_I: {c: 73, n: "I"},
VK_O: {c: 79, n: "O"},
VK_P: {c: 80, n: "P"},
VK_ACUTE: {c: 219, n: "´"},
VK_OPEN_BRACKET: {c: 221, n: "["},
VK_CLOSE_BRACKET: {c: 220, n: "]"},
VK_CAPS_LOCK: {c: 20, n: "CpsLck"},
VK_A: {c: 65, n: "A"},
VK_S: {c: 83, n: "S"},
VK_D: {c: 68, n: "D"},
VK_F: {c: 70, n: "F"},
VK_G: {c: 71, n: "G"},
VK_H: {c: 72, n: "H"},
VK_J: {c: 74, n: "J"},
VK_K: {c: 75, n: "K"},
VK_L: {c: 76, n: "L"},
VK_CEDILLA: {c: 186, n: "Ç"},
VK_TILDE: {c: 222, n: "~"},
VK_ENTER: {c: 13, n: "Enter"},
VK_SHIFT: {c: 16, n: "Shift"},
VK_BACK_SLASH: {c: 226, n: "\\"},
VK_Z: {c: 90, n: "Z"},
VK_X: {c: 88, n: "X"},
VK_C: {c: 67, n: "C"},
VK_V: {c: 86, n: "V"},
VK_B: {c: 66, n: "B"},
VK_N: {c: 78, n: "N"},
VK_M: {c: 77, n: "M"},
VK_COMMA: {c: 188, n: "] ="},
VK_PERIOD: {c: 190, n: "."},
VK_SEMICOLON: {c: 191, n: ";"},
VK_SLASH: {c: 193, n: "/"},
VK_CONTROL: {c: 17, n: "Ctrl"},
VK_ALT: {c: 18, n: "Alt"},
VK_SPACE: {c: 32, n: "Space"},
VK_INSERT: {c: 45, n: "Ins"},
VK_DELETE: {c: 46, n: "Del"},
VK_HOME: {c: 36, n: "Home"},
VK_END: {c: 35, n: "End"},
VK_PAGE_UP: {c: 33, n: "PgUp"},
VK_PAGE_DOWN: {c: 34, n: "PgDown"},
VK_UP: {c: 38, n: "Up"},
VK_DOWN: {c: 40, n: "Down"},
VK_LEFT: {c: 37, n: "Left"},
VK_RIGHT: {c: 39, n: "Right"},
VK_NUM_LOCK: {c: 144, n: "Num"},
VK_DIVIDE: {c: 111, n: "Num /"},
VK_MULTIPLY: {c: 106, n: "Num *"},
VK_SUBTRACT: {c: 109, n: "Num -"},
VK_ADD: {c: 107, n: "Num +"},
VK_DECIMAL: {c: 194, n: "Num ."},
VK_NUMPAD0: {c: 96, n: "Num 0"},
VK_NUMPAD1: {c: 97, n: "Num 1"},
VK_NUMPAD2: {c: 98, n: "Num 2"},
VK_NUMPAD3: {c: 99, n: "Num 3"},
VK_NUMPAD4: {c: 100, n: "Num 4"},
VK_NUMPAD5: {c: 101, n: "Num 5"},
VK_NUMPAD6: {c: 102, n: "Num 6"},
VK_NUMPAD7: {c: 103, n: "Num 7"},
VK_NUMPAD8: {c: 104, n: "Num 8"},
VK_NUMPAD9: {c: 105, n: "Num 9"},
VK_NUMPAD_CENTER: {c: 12, n: "Num Cntr"}
};
function makeKeycodeMap(table) {
var map = {};
for (var i=0; i<table.length; i++) {
var entry = table[i];
map[entry[0].c] = {index:entry[1], mask:entry[2]};
}
return map;
}
function padBytes(data, len) {
var r = new RAM(len);
r.mem.set(data);
@ -657,7 +816,7 @@ function AddressDecoder(table) {
var func = entry[3];
self['__fn'+i] = func;
s += "if (a>=" + start + " && a<="+end + "){";
s += "a&="+(mask?mask:0xffff)+";";
if (mask) s += "a&="+mask+";";
s += "return this.__fn"+i+"(a,v)&0xff;}\n";
}
s += "return 0;"; // TODO: noise()?

View File

@ -206,12 +206,6 @@ var SpaceInvadersPlatform = function(mainElement) {
}
this.readAddress = function(addr) {
return membus.read(addr);
}
this.ramStateToLongString = function(state) {
return "";
//var stack = state.b.slice(state.c.SP & 0x1fff, 0x400);
//return "\n" + dumpRAM(stack, state.c.SP, stack.length);
}
}

224
src/platform/williams.js Normal file
View File

@ -0,0 +1,224 @@
"use strict";
var WILLIAMS_PRESETS = [
];
var WilliamsPlatform = function(mainElement) {
var self = this;
this.__proto__ = new Base6809Platform();
var cpu, ram, membus, iobus, rom, nvram;
var video, timer, pixels, displayPCs;
var banksel = 0;
var watchdog_counter;
var video_counter;
var pia6821 = [0,0,0,0,0,0,0,0];
var screenNeedsRefresh = false;
var xtal = 12000000;
var cpuFrequency = xtal/3/4;
var cpuCyclesPerFrame = cpuFrequency/60; // TODO
var INITIAL_WATCHDOG = 64;
var PIXEL_ON = 0xffeeeeee;
var PIXEL_OFF = 0xff000000;
var KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_SPACE, 4, 0x1],
[Keys.VK_RIGHT, 4, 0x2],
[Keys.VK_Z, 4, 0x4],
[Keys.VK_X, 4, 0x8],
[Keys.VK_2, 4, 0x10],
[Keys.VK_1, 4, 0x20],
[Keys.VK_LEFT, 4, 0x40],
[Keys.VK_DOWN, 4, 0x80],
[Keys.VK_UP, 6, 0x1],
[Keys.VK_5, 0, 0x4],
[Keys.VK_7, 0, 0x1],
[Keys.VK_8, 0, 0x2],
[Keys.VK_9, 0, 0x8],
]);
var palette = [];
for (var ii=0; ii<16; ii++)
palette[ii] = 0xff000000;
this.getPresets = function() {
return WILLIAMS_PRESETS;
}
var ioread = new AddressDecoder([
[0x400, 0x5ff, 0x1ff, function(a) { return nvram.mem[a]; }],
[0x800, 0x800, 0, function(a) { return video_counter; }],
[0xc00, 0xc07, 0x7, function(a) { return pia6821[a]; }],
[0x0, 0xfff, 0, function(a) { console.log('ioread',hex(a)); }],
]);
var iowrite = new AddressDecoder([
[0x0, 0xf, 0xf, function(a,v) {
// RRRGGGBB
var color = 0xff000000 | ((v&7)<<5) | (((v>>3)&7)<<13) | (((v>>6)<<22));
if (color != palette[a]) {
palette[a] = color;
screenNeedsRefresh = true;
}
}],
[0x3fc, 0x3ff, 0, function(a,v) { if (v == 56) watchdog_counter = INITIAL_WATCHDOG; }], // TODO: check value?
[0x400, 0x5ff, 0x1ff, function(a,v) { nvram.mem[a] = v; }],
[0xc00, 0xc07, 0x7, function(a,v) { pia6821[a] = v; }],
[0x0, 0xfff, 0, function(a,v) { console.log('iowrite',hex(a),hex(v)); }],
]);
function drawDisplayByte(a,v) {
var ofs = ((a&0xff00)<<1) | ((a&0xff)^0xff);
pixels[ofs] = palette[v>>4];
pixels[ofs+256] = palette[v&0xf];
}
this.start = function() {
ram = new RAM(0xc000);
nvram = new RAM(0x200);
// TODO: save in browser storage?
nvram.mem.set([240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,242,241,242,247,240,244,244,245,242,244,250,240,241,248,243,241,245,245,243,244,241,244,253,240,241,245,249,242,240,244,252,244,245,244,244,240,241,244,242,248,245,245,240,244,247,244,244,240,241,242,245,242,240,244,243,245,242,244,242,240,241,241,240,243,245,244,253,245,242,245,243,240,240,248,242,246,245,245,243,245,243,245,242,240,240,246,240,241,240,245,244,244,253,244,248,240,240,245,250,240,241,240,240,240,243,240,243,240,241,240,244,240,241,240,241,240,240,240,240,240,240,240,245,241,245,240,241,240,245,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240]);
displayPCs = new Uint16Array(new ArrayBuffer(0x9800*2));
rom = padBytes(new lzgmini().decode(DEFENDER_ROM).slice(0), 0x7000);
membus = {
read: new AddressDecoder([
[0x0000, 0xbfff, 0xffff, function(a) { return ram.mem[a]; }],
[0xc000, 0xcfff, 0x0fff, function(a) {
switch (banksel) {
case 0: return ioread(a);
case 1: return rom[a+0x3000];
case 2: return rom[a+0x4000];
case 3: return rom[a+0x5000];
case 4:
case 5:
case 6:
case 7: return rom[a+0x6000];
default: return 0; // TODO: error light
}
}],
[0xd000, 0xffff, 0xffff, function(a) { return rom ? rom[a-0xd000] : 0; }],
]),
write: new AddressDecoder([
[0x9800, 0xbfff, 0, function(a,v) { ram.mem[a] = v; }],
[0x0000, 0x97ff, 0, function(a,v) {
ram.mem[a] = v;
drawDisplayByte(a, v);
displayPCs[a] = cpu.getPC(); // save program counter
}],
[0xc000, 0xcfff, 0x0fff, iowrite],
[0xd000, 0xdfff, 0, function(a,v) { banksel = v&0x7; }],
[0, 0xffff, 0, function(a,v) { console.log(hex(a), hex(v)); }],
]),
};
cpu = new CPU6809();
cpu.init(membus.write, membus.read, 0);
video = new RasterVideo(mainElement,256,304,{rotate:-90});
video.create();
$(video.canvas).click(function(e) {
var x = Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width());
var y = Math.floor(e.offsetY * video.canvas.height / $(video.canvas).height());
var addr = (x>>3) + (y*32) + 0x400;
console.log(x, y, hex(addr,4), "PC", hex(displayPCs[addr],4));
});
var idata = video.getFrameData();
video.setKeyboardEvents(function(key,code,flags) {
var o = KEYCODE_MAP[key];
if (o) {
console.log(key,code,flags,o);
if (flags & 1) {
pia6821[o.index] |= o.mask;
} else {
pia6821[o.index] &= ~o.mask;
}
}
});
pixels = video.getFrameData();
timer = new AnimationTimer(60, function() {
if (!self.isRunning())
return;
var debugCond = self.getDebugCallback();
// interrupts happen every 1/4 of the screen
for (var quarter=0; quarter<4; quarter++) {
video_counter = (quarter & 1) ? 0xff : 0x00;
if (pia6821[7] == 0x3c) { // TODO?
cpu.interrupt();
//console.log(cpu.getPC());
}
var targetTstates = cpu.T() + cpuCyclesPerFrame/4;
if (debugCond) {
while (cpu.T() < targetTstates) {
if (debugCond && debugCond()) {
debugCond = null;
break;
}
cpu.steps(1);
}
} else {
cpu.steps(cpuCyclesPerFrame);
}
}
if (screenNeedsRefresh) {
for (var i=0; i<0x9800; i++)
drawDisplayByte(i, ram.mem[i]);
screenNeedsRefresh = false;
}
video.updateFrame();
if (watchdog_counter-- <= 0) {
console.log("WATCHDOG FIRED, PC =", cpu.getPC().toString(16)); // TODO: alert on video
// TODO: self.breakpointHit(cpu.T());
self.reset();
}
self.restartDebugState();
});
}
this.loadROM = function(title, data) {
// TODO
self.reset();
}
this.loadState = function(state) {
cpu.loadState(state.c);
ram.mem.set(state.b);
nvram.mem.set(state.nvram);
watchdog_counter = state.wdc;
banksel = state.bs;
pia6821 = state.pia;
}
this.saveState = function() {
return {
c:self.getCPUState(),
b:ram.mem.slice(0),
nvram:nvram.mem.slice(0),
wdc:watchdog_counter,
bs:banksel,
pia:pia6821,
};
}
this.getRAMForState = function(state) {
return ram.mem;
}
this.getCPUState = function() {
return cpu.saveState();
}
this.isRunning = function() {
return timer.isRunning();
}
this.pause = function() {
timer.stop();
}
this.resume = function() {
timer.start();
}
this.reset = function() {
cpu.reset();
watchdog_counter = INITIAL_WATCHDOG;
}
this.readAddress = function(addr) {
return membus.read(addr);
}
}
PLATFORMS['williams'] = WilliamsPlatform;

View File

@ -418,13 +418,6 @@ function setCurrentLine(line) {
editor.setSelection({line:line,ch:0}, {line:line-1,ch:0}, {scroll:true});
}
function getTIAPosString() {
if (platform.getRasterPosition) {
var pos = platform.getRasterPosition();
return "V" + pos.y + " H" + pos.x;
} else return "";
}
var lastDebugInfo;
var lastDebugState;
@ -458,6 +451,10 @@ function showMemory(state) {
var s = "";
if (state) {
s = platform.cpuStateToLongString(state.c);
if (platform.getRasterPosition) {
var pos = platform.getRasterPosition();
s += "H:" + pos.x + " V:" + pos.y + "\n"; // TODO: padding
}
if (platform.ramStateToLongString) {
s += platform.ramStateToLongString(state);
}
@ -739,7 +736,6 @@ function updateDisassembly() {
var div = $("#disassembly");
if (div.is(':visible')) {
var state = lastDebugState || platform.saveState();
var mem = state.b;
var pc = state.c.PC;
if (assemblyfile && assemblyfile.text) {
disasmview.setValue(assemblyfile.text);
@ -752,28 +748,29 @@ function updateDisassembly() {
}
return;
}
var gutters = [];
var curline = 0;
var selline = 0;
// TODO: not perfect disassembler
function disassemble(start, end) {
if (start < 0) start = 0;
if (end > mem.length) end = mem.length;
// TODO: use platform.readMemory()
var disasm = platform.disassemble(mem, start, end, pcvisits);
if (end > 0xffff) end = 0xffff;
// TODO: use pc2visits
var a = start;
var s = "";
for (a in disasm) {
while (a < end) {
var disasm = platform.disassemble(a, platform.readAddress);
var srclinenum = sourcefile.offset2line[a];
if (srclinenum) {
var srcline = editor.getLine(srclinenum-1);
if (srcline && srcline.trim().length) {
s += "; " + srclinenum + ":\t" + srcline + "\n";
gutters.push([a]);
}
}
var dline = hex(parseInt(a)) + "\t" + disasm[a] + "\n";
var dline = hex(parseInt(a)) + "\t" + disasm.line + "\n";
s += dline;
if (a == pc) selline = gutters.length;
gutters.push([]);
if (a == pc) selline = curline;
curline++;
a += disasm.nbytes;
}
return s;
}