Base6502Platform, RTS button, run backwards, c fixes

This commit is contained in:
Steven Hugg 2017-01-07 13:05:02 -05:00
parent 2949a35167
commit 6c8d52e64a
7 changed files with 272 additions and 235 deletions

View File

@ -20,5 +20,9 @@ TODO:
- some units test maybe
- can't step after reset (or when funky frame; TIA frame is out of sync)
- break on BRK/illegal opcode?
- start analysis from vector address
- last used filename for each platform
- skeleton for each platform/tool
- disassembler/debugger
- multiple breakpoints, expression breakpoints

View File

@ -187,6 +187,12 @@ a.dropdown-toggle {
<li><a class="dropdown-item" href="?platform=exidy" id="item_platform_exidy">Exidy</a></li>
</ul>
</li>
<li class="dropdown dropdown-submenu">
<a tabindex="-1" href="#">Debug</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" id="item_debug_expr">Break Expression...</a></li>
</ul>
</li>
</ul>
</span>
<select id="preset_select" name="">
@ -197,7 +203,8 @@ a.dropdown-toggle {
<button id="dbg_step" type="submit" title="Step"><img src="images/singlestep.png"></button>
<button id="dbg_toline" type="submit" title="Run To Line"><img src="images/runtoline.png"></button>
<button id="dbg_reset" type="submit" title="Reset and Run To Line"><img src="images/resetandrun.png"></button>
<!-- <button id="dbg_stepout" type="submit" title="Step Out of Subroutine">O</button>-->
<button id="dbg_stepout" type="submit" title="Step Out of Subroutine">RTS</button>
<button id="dbg_stepback" type="submit" title="Step Backwards">&lt;&lt;</button>
<button id="dbg_timing" type="submit" title="See Timing" style="display:none"><img src="images/timing.png"></button>
<button id="dbg_disasm" type="submit" title="Toggle Disassembly">#</button>
</span>

View File

@ -302,3 +302,112 @@ var SampleAudio = function(clockfreq) {
}
}
}
var Base6502Platform = function() {
this.getOpcodeMetadata = function(opcode, offset) {
return Javatari.getOpcodeMetadata(opcode, offset); // TODO
}
this.getOriginPC = function() {
return (this.readAddress(0xfffc) | (this.readAddress(0xfffd) << 8)) & 0xffff;
}
var onBreakpointHit;
var debugCondition;
var debugSavedState = null;
var debugBreakState = null;
var debugTargetClock = 0;
var debugClock = 0;
var debugFrameStartClock = 0;
this.setDebugCondition = function(debugCond) {
if (debugSavedState) {
this.loadState(debugSavedState);
} else {
debugSavedState = this.saveState();
}
debugClock = 0;
debugCondition = debugCond;
this.resume();
}
this.getDebugCallback = function() {
return debugCondition;
}
this.setupDebug = function(callback) {
onBreakpointHit = callback;
}
this.clearDebug = function() {
debugSavedState = null;
debugTargetClock = 0;
debugClock = 0;
debugFrameStartClock = 0;
onBreakpointHit = null;
debugCondition = null;
}
this.breakpointHit = function() {
debugBreakState = this.saveState();
debugBreakState.c.PC = (debugBreakState.c.PC-1) & 0xffff;
console.log("Breakpoint at clk", debugClock, "PC", debugBreakState.c.PC.toString(16));
this.pause();
if (onBreakpointHit) {
onBreakpointHit(debugBreakState);
}
}
this.step = function() {
var self = this;
var previousPC = -1;
this.setDebugCondition(function() {
if (debugClock++ > debugTargetClock) {
var thisState = self.getCPUState();
if (previousPC < 0) {
previousPC = thisState.PC;
} else {
if (thisState.PC != previousPC && thisState.T == 0) {
//console.log(previousPC.toString(16), thisPC.toString(16));
debugTargetClock = debugClock-1;
self.breakpointHit();
return true;
}
}
}
return false;
});
}
this.stepBack = function() {
var self = this;
var prevState;
var prevClock;
this.setDebugCondition(function() {
if (debugClock++ >= debugTargetClock && prevState) {
self.loadState(prevState);
debugTargetClock = prevClock-1;
self.breakpointHit();
return true;
} else if (debugClock > debugTargetClock-10 && debugClock < debugTargetClock) {
if (self.getCPUState().T == 0) {
console.log(debugClock, self.getCPUState());
prevState = self.saveState();
prevClock = debugClock;
}
}
return false;
});
}
this.runEval = function(evalfunc) {
var self = this;
this.setDebugCondition(function() {
if (debugClock++ > debugTargetClock) {
var cpuState = self.getCPUState();
cpuState.PC = (cpuState.PC-1)&0xffff;
if (evalfunc(cpuState)) {
self.breakpointHit();
debugTargetClock = debugClock-1;
return true;
} else {
return false;
}
}
});
}
}

View File

@ -1,5 +1,5 @@
"use strict";
"use strict";
var APPLE2_PRESETS = [
];
@ -18,7 +18,9 @@ var Apple2Platform = function(mainElement) {
var grswitch = GR_TXMODE;
var kbdlatch = 0;
var soundstate = 0;
var PGM_BASE = 0x6000; // where to JMP after pr#6
var pgmbin;
var VM_BASE = 0x6000; // where to JMP after pr#6
var PGM_BASE = 0x6000; // where to load ROM
// language card switches
var auxRAMselected = false;
var auxRAMbank = 1;
@ -27,6 +29,8 @@ var Apple2Platform = function(mainElement) {
// bank 1 is E000-FFFF, bank 2 is D000-DFFF
var bank2rdoffset=0, bank2wroffset=0;
this.__proto__ = new Base6502Platform();
this.getPresets = function() {
return APPLE2_PRESETS;
}
@ -40,8 +44,9 @@ var Apple2Platform = function(mainElement) {
ram = new RAM(0x13000); // 64K + 16K LC RAM - 4K hardware
// ROM
var rom = new lzgmini().decode(APPLEIIGO_LZG).slice(0,0x3000);
//var rom = new lzgmini().decode(APPLEII_ROM).slice(0,0x3000);
ram.mem.set(rom, 0xd000);
ram.mem[0xbf00] = 0x4c; // fake DOS detect for C
ram.mem[0xbf6f] = 0x01; // fake DOS detect for C
// bus
bus = {
read: function(address) {
@ -104,10 +109,10 @@ var Apple2Platform = function(mainElement) {
}
} else {
switch (address) {
// JMP $c600
// JMP VM_BASE
case 0xc600: return 0x4c;
case 0xc601: return PGM_BASE&0xff;
case 0xc602: return (PGM_BASE>>8)&0xff;
case 0xc601: return VM_BASE&0xff;
case 0xc602: return (VM_BASE>>8)&0xff;
default: return noise();
}
}
@ -155,11 +160,11 @@ var Apple2Platform = function(mainElement) {
// 262.5 scanlines per frame
var iaddr = 0x2000;
var iofs = 0;
breakClock = -1;
var clock = 0;
var debugCond = self.getDebugCallback();
for (var sl=0; sl<262; sl++) {
for (var i=0; i<cpuCyclesPerLine; i++) {
if (debugCondition && breakClock < 0 && debugCondition()) { breakClock = clock; }
if (debugCond && debugCond()) { debugCond = null; }
clock++;
cpu.clockPulse();
audio.feedSample(soundstate, 1);
@ -243,20 +248,9 @@ var Apple2Platform = function(mainElement) {
bank2wroffset = 0x3000; // map 0xd000-0xdfff -> 0x10000-0x10fff
}
this.getOpcodeMetadata = function(opcode, offset) {
return Javatari.getOpcodeMetadata(opcode, offset); // TODO
}
this.loadROM = function(title, data) {
pgmbin = data;
this.reset();
//console.log('loadROM',hex(data.length));
ram.mem.set(data, PGM_BASE);
/*
if(data.length != 0x3000) {
throw "ROM length must be == 0x3000";
}
rom = data;
*/
}
this.getRasterPosition = function() {
@ -276,89 +270,13 @@ var Apple2Platform = function(mainElement) {
}
this.reset = function() {
cpu.reset();
}
this.getOriginPC = function() {
return (this.readAddress(0xfffc) | (this.readAddress(0xfffd) << 8)) & 0xffff;
if (pgmbin)
ram.mem.set(pgmbin, PGM_BASE);
}
this.readAddress = function(addr) {
return bus.read(addr);
}
var onBreakpointHit;
var debugCondition;
var debugSavedState = null;
var debugBreakState = null;
var debugTargetClock = 0;
var debugClock = 0;
var debugFrameStartClock = 0;
var breakClock;
this.setDebugCondition = function(debugCond) {
if (debugSavedState) {
self.loadState(debugSavedState);
} else {
debugSavedState = self.saveState();
}
debugClock = 0;
debugCondition = debugCond;
self.resume();
}
this.setupDebug = function(callback) {
onBreakpointHit = callback;
}
this.clearDebug = function() {
debugSavedState = null;
debugTargetClock = 0;
debugClock = 0;
debugFrameStartClock = 0;
onBreakpointHit = null;
debugCondition = null;
}
this.breakpointHit = function() {
debugBreakState = self.saveState();
debugBreakState.c.PC = (debugBreakState.c.PC-1) & 0xffff;
console.log("Breakpoint at clk", debugClock, "PC", debugBreakState.c.PC.toString(16));
this.pause();
if (onBreakpointHit) {
onBreakpointHit(debugBreakState);
}
}
this.step = function() {
var previousPC = -1;
self.setDebugCondition(function() {
if (debugClock++ > debugTargetClock) {
var thisState = cpu.saveState();
if (previousPC < 0) {
previousPC = thisState.PC;
} else {
if (thisState.PC != previousPC && thisState.T == 0) {
//console.log(previousPC.toString(16), thisPC.toString(16));
debugTargetClock = debugClock-1;
self.breakpointHit();
return true;
}
}
}
return false;
});
}
this.runEval = function(evalfunc) {
var self = this;
self.setDebugCondition(function() {
if (debugClock++ > debugTargetClock) {
var cpuState = cpu.saveState();
cpuState.PC = (cpuState.PC-1)&0xffff;
if (evalfunc(cpuState)) {
self.breakpointHit();
debugTargetClock = debugClock;
return true;
} else {
return false;
}
}
});
}
this.loadState = function(state) {
cpu.loadState(state.c);
ram.mem.set(state.b);
@ -381,6 +299,9 @@ var Apple2Platform = function(mainElement) {
this.getRAMForState = function(state) {
return ram.mem;
}
this.getCPUState = function() {
return cpu.saveState();
}
};
var Apple2Display = function(pixels, apple) {
@ -960,52 +881,90 @@ var apple2_charset = [
// public domain ROM
var APPLEIIGO_LZG = [
76,90,71,0,0,48,0,0,0,5,231,30,202,84,84,1,21,25,30,52,65,80,80,76,69,73,73,71,79,32,82,79,
77,49,46,49,255,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,3,133,109,132,110,56,165,150,229,155,133,94,
168,165,151,229,156,170,232,152,240,35,165,150,56,229,94,133,150,176,3,198,151,56,165,148,30,3,148,176,8,198,149,144,
4,177,150,145,148,136,208,249,52,194,198,151,198,149,202,208,242,96,25,30,128,52,27,255,255,32,0,224,25,30,67,52,
30,52,28,25,31,174,52,31,52,30,52,28,52,4,25,63,105,52,31,52,30,52,28,52,2,25,63,103,52,15,25,31,
137,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,26,160,32,52,28,32,
32,160,0,52,5,25,6,40,1,16,16,12,5,19,15,6,20,32,14,15,20,32,1,22,1,9,12,1,2,12,5,25,
16,40,198,207,210,160,205,207,210,197,160,201,206,30,3,205,193,212,201,207,206,160,208,204,197,193,211,197,160,195,204,201,
195,203,160,30,8,160,25,8,40,212,200,197,160,193,208,30,25,201,201,199,207,160,204,207,52,129,194,197,204,207,215,30,
28,52,10,25,6,40,52,29,52,14,76,3,224,32,88,252,162,39,189,0,223,157,128,4,202,16,247,30,3,48,223,157,
0,5,30,195,30,78,25,5,3,96,30,3,6,30,195,144,30,25,7,30,3,76,64,224,52,65,25,30,131,52,31,52,
31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,
31,52,31,52,31,52,31,52,31,52,24,201,206,176,238,201,201,144,234,201,204,240,230,208,232,234,52,11,72,74,41,3,
9,4,133,41,104,41,24,144,2,105,127,133,40,10,10,5,40,133,40,96,25,30,116,0,165,37,32,193,251,101,32,25,
29,75,52,21,165,34,72,32,36,252,165,40,133,42,165,41,133,43,164,33,136,104,105,1,197,35,176,13,30,78,177,40,
145,42,136,16,249,48,225,160,0,32,158,252,176,134,164,36,169,160,145,40,200,196,33,144,249,25,30,199,52,27,164,36,
177,40,72,41,63,9,64,145,40,104,108,56,25,19,27,32,12,253,32,165,251,52,161,201,155,240,243,25,28,141,52,6,
32,142,253,165,51,32,237,253,162,1,138,240,243,202,32,53,253,201,149,208,2,177,40,201,224,144,2,41,223,157,0,2,
201,141,208,178,32,156,252,169,141,208,91,164,61,166,60,30,39,32,64,249,160,0,169,173,76,237,253,25,28,87,52,31,
52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,31,52,28,52,7,169,0,133,28,165,230,
133,27,160,0,132,26,165,28,145,26,32,126,244,200,208,246,230,27,165,27,41,31,208,238,96,133,226,134,224,132,225,72,
41,192,133,38,74,74,5,38,133,38,104,133,39,10,10,10,38,39,52,66,102,38,165,39,41,31,5,230,133,39,138,192,
0,240,5,160,35,105,4,200,233,7,176,251,132,229,170,189,185,244,133,48,152,74,165,228,133,28,176,21,28,0,35,52,
4,10,201,192,16,6,165,28,73,127,133,28,25,254,218,52,31,52,31,52,31,52,31,52,31,52,31,52,28,52,10,74,
8,32,71,248,40,169,15,144,2,105,224,133,46,177,38,69,48,37,46,81,38,145,38,96,32,0,248,196,44,176,17,200,
32,14,248,144,246,105,1,72,30,8,104,197,45,144,245,96,160,47,208,2,160,39,132,45,160,39,169,0,133,48,32,40,
248,136,16,246,96,21,5,4,126,39,21,6,4,126,38,10,10,25,130,52,96,165,48,24,105,3,41,15,133,48,10,52,
1,5,48,133,48,25,103,223,144,4,74,52,1,41,15,25,107,240,168,74,144,9,106,176,16,201,162,240,12,41,135,74,
170,189,98,249,32,121,248,208,4,160,128,169,0,170,189,166,249,133,46,41,3,133,47,152,41,143,170,152,160,3,224,138,
240,11,74,144,8,74,74,9,32,136,208,250,200,136,208,242,25,159,59,52,31,52,31,52,20,216,32,132,254,32,47,251,
32,147,254,32,137,254,173,88,192,173,90,192,173,93,192,173,95,192,173,255,207,44,16,192,216,32,58,255,32,96,251,169,
0,133,0,169,198,133,1,108,25,30,111,52,29,21,3,19,108,221,219,199,207,25,10,13,173,112,192,160,0,234,234,189,
100,192,16,4,200,208,248,136,96,169,0,133,72,173,86,192,173,84,192,173,81,192,169,0,240,11,173,80,192,173,83,192,
32,54,248,169,20,133,34,30,22,32,169,40,133,33,169,24,133,35,169,23,133,37,76,34,252,32,88,252,160,9,185,8,
251,153,14,4,136,208,247,96,173,243,3,73,165,141,244,3,96,201,141,208,24,172,0,192,16,19,192,147,208,15,44,16,
192,30,68,251,192,131,240,3,30,4,76,253,251,25,12,148,21,29,7,248,40,133,40,96,201,135,208,18,169,64,32,168,
252,160,192,169,12,52,193,173,48,192,136,208,245,96,164,36,145,40,230,36,165,36,197,33,176,102,96,201,160,176,239,168,
16,236,201,141,240,90,201,138,52,97,136,208,201,198,36,16,232,165,33,133,36,198,36,165,34,197,37,176,11,198,37,21,
28,7,248,0,72,32,36,252,32,158,252,160,0,104,105,0,197,35,144,240,176,202,165,34,133,37,160,0,132,36,240,228,
169,0,133,36,230,30,62,30,16,182,198,37,21,29,7,248,21,6,7,248,56,72,233,1,208,252,104,52,129,246,96,230,
66,208,2,230,67,165,60,197,62,165,61,229,63,230,60,30,6,61,25,125,244,52,18,21,13,7,248,230,78,208,2,230,
79,44,0,192,16,245,145,40,173,0,192,44,16,192,96,21,10,7,248,254,96,165,50,72,169,255,133,50,189,0,2,32,
237,253,104,30,129,201,136,240,29,201,152,240,10,224,248,144,3,32,58,255,232,208,19,169,220,30,21,21,10,7,248,254,
21,30,7,248,52,27,0,72,25,162,88,32,229,253,104,41,15,9,176,201,186,144,2,105,6,108,54,0,201,160,144,2,
37,50,132,53,72,32,120,251,104,164,53,25,49,47,64,25,10,5,25,11,24,177,60,145,66,32,180,252,144,247,25,190,
97,52,1,160,63,208,2,160,255,132,50,25,98,82,62,162,56,160,27,208,8,30,130,54,160,240,165,62,41,15,240,6,
9,192,160,0,240,2,169,253,148,0,149,1,96,234,234,76,0,21,31,22,104,52,6,169,135,76,237,253,165,72,72,165,
69,166,70,164,71,25,110,22,25,62,27,52,30,52,14,245,3,251,3,98,250,98,250
76,90,71,0,0,48,0,0,0,10,171,116,213,197,126,1,25,52,55,59,65,80,80,76,69,73,73,71,79,32,82,79,
77,49,46,49,255,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,3,133,109,132,110,56,165,150,229,155,133,94,
168,165,151,229,156,170,232,152,240,35,165,150,56,229,94,133,150,176,3,198,151,56,165,148,55,3,148,176,8,198,149,144,
4,177,150,145,148,136,208,249,59,194,198,151,198,149,202,208,242,96,52,30,128,59,27,255,255,32,0,224,52,30,67,59,
30,59,28,52,31,174,59,31,59,30,59,28,59,4,52,63,105,59,31,59,30,59,28,59,2,52,63,103,59,15,52,31,
137,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,26,160,32,59,28,32,
32,160,0,59,5,52,6,40,1,16,16,12,5,19,15,6,20,32,14,15,20,32,1,22,1,9,12,1,2,12,5,52,
16,40,198,207,210,160,205,207,210,197,160,201,206,55,3,205,193,212,201,207,206,160,208,204,197,193,211,197,160,195,204,201,
195,203,160,55,8,160,52,8,40,212,200,197,160,193,208,55,25,201,201,199,207,160,204,207,59,129,194,197,204,207,215,55,
28,59,10,52,6,40,59,29,59,14,76,3,224,32,88,252,162,39,189,0,223,157,128,4,202,16,247,55,3,48,223,157,
0,5,55,195,55,78,52,5,3,96,55,3,6,55,195,144,55,25,7,55,3,76,64,224,59,65,0,32,190,224,76,74,
224,104,24,105,1,133,244,104,105,0,133,245,165,226,72,165,225,72,165,227,133,225,165,228,133,226,160,0,169,225,133,250,
76,243,0,104,133,230,104,133,231,160,2,177,230,133,245,136,59,129,244,136,52,12,33,52,28,31,55,159,226,133,250,120,
141,3,192,55,35,160,16,185,127,225,153,238,0,136,208,247,132,225,169,128,133,226,162,16,96,234,59,28,59,8,115,228,
128,226,145,226,182,226,90,227,100,227,118,227,127,227,74,227,138,227,153,227,169,227,185,227,201,227,235,227,162,226,24,228,
63,228,41,228,142,228,102,229,125,59,161,164,228,239,0,83,228,95,228,105,228,96,232,109,232,66,232,81,232,151,231,173,
231,211,231,243,231,195,231,227,231,23,232,3,232,30,232,122,232,139,232,235,232,60,233,110,233,133,233,240,0,248,228,15,
229,124,229,148,229,234,229,12,230,228,230,247,230,132,230,155,230,183,230,203,230,15,231,47,231,84,231,115,231,232,200,240,
8,185,255,255,133,249,108,0,225,230,245,208,244,52,28,171,59,30,59,3,52,28,248,52,9,248,193,52,28,248,122,232,
183,232,14,233,60,233,106,233,129,233,240,0,41,229,70,229,173,229,203,229,49,230,89,52,19,248,181,192,24,117,193,149,
193,181,208,117,209,149,209,232,76,240,0,181,193,56,245,192,55,9,209,245,208,52,5,9,192,10,54,208,52,13,29,132,
229,160,16,181,193,73,255,133,230,181,209,59,161,231,169,0,149,193,70,231,102,230,176,12,149,209,181,192,52,6,36,22,
192,54,208,136,208,231,55,43,164,229,55,45,169,0,52,2,82,192,169,0,245,208,149,208,96,55,59,17,169,0,133,230,
133,231,181,208,41,128,133,224,16,5,32,235,226,230,224,181,209,16,9,232,55,2,202,230,224,208,4,21,193,240,37,22,
193,54,209,136,144,249,38,230,38,231,165,230,213,192,165,231,245,208,144,9,133,55,4,245,192,133,230,56,54,55,86,208,
226,232,164,229,96,52,11,87,76,240,0,32,249,226,70,224,176,233,55,194,165,230,149,55,51,149,208,165,224,48,215,55,
10,246,192,208,2,246,55,93,181,55,1,214,208,214,192,55,3,169,255,85,55,119,255,85,55,247,181,193,53,52,3,255,
53,52,6,255,193,21,55,136,21,52,7,8,55,39,55,8,55,39,52,37,11,181,192,201,8,144,10,180,193,148,209,160,
0,148,193,233,8,168,240,7,52,3,181,208,249,52,4,248,52,5,26,16,180,209,148,193,192,128,160,0,144,1,136,148,
209,56,55,96,12,181,209,201,128,106,118,193,136,208,248,52,38,37,181,192,21,208,240,2,169,255,73,255,149,192,52,5,
136,21,209,55,33,52,5,15,149,193,52,38,149,21,208,21,55,82,6,52,8,12,202,181,193,149,192,181,209,55,238,192,
72,181,208,72,55,142,104,149,208,104,149,52,2,225,202,169,0,52,5,76,202,200,208,2,230,245,177,244,52,34,46,52,
13,9,52,6,1,52,8,14,152,24,101,244,133,55,163,168,101,245,133,245,149,208,177,244,168,52,13,21,52,5,19,55,
17,73,255,24,101,227,133,227,55,38,255,101,228,133,228,55,101,145,227,136,192,255,208,247,200,55,239,181,192,133,230,181,
208,133,231,132,229,160,0,177,230,149,192,148,208,52,5,239,52,12,15,200,59,129,52,14,18,141,2,192,52,8,44,52,
130,128,52,19,21,52,5,50,55,216,52,5,198,202,24,101,225,52,2,185,101,226,52,3,208,52,5,14,132,229,168,202,
177,55,144,52,5,99,52,13,16,200,59,129,52,15,17,141,2,192,52,6,44,141,3,192,52,21,22,55,178,52,13,23,
133,230,52,6,1,52,5,221,202,52,7,245,52,25,26,52,40,0,52,18,29,52,5,237,52,3,66,52,26,103,52,8,
32,52,3,72,52,6,35,181,193,52,98,192,133,231,181,192,52,2,104,145,230,232,52,69,123,52,5,15,55,77,181,192,
145,230,200,181,208,52,7,20,52,8,228,55,18,225,52,18,12,55,102,52,19,17,52,22,36,52,21,174,52,7,141,52,
57,27,52,8,150,52,27,29,145,230,52,28,60,55,220,181,192,213,193,208,28,181,208,213,209,208,22,169,255,232,52,102,
124,55,78,240,55,142,234,169,0,52,7,14,193,213,192,52,162,39,80,2,73,128,16,210,48,230,55,94,181,208,245,209,
55,72,48,194,16,214,52,10,8,16,178,48,198,52,10,40,48,162,16,182,232,181,207,21,191,208,20,52,3,134,59,131,
76,240,0,55,204,236,165,245,133,231,165,244,55,141,24,113,244,133,230,165,231,55,132,55,3,245,165,52,226,145,136,55,
163,191,213,192,208,193,181,207,213,208,240,207,208,185,55,199,198,55,135,172,208,190,55,135,181,207,245,208,48,179,16,157,
232,181,192,213,191,181,208,245,207,48,166,16,144,165,244,24,117,192,133,244,165,245,117,208,133,245,52,130,26,52,48,16,
165,245,72,165,244,72,152,72,32,57,233,104,168,104,133,244,104,133,245,25,3,0,28,52,26,36,141,2,192,88,55,40,
120,141,3,192,52,7,44,226,55,172,52,102,157,232,52,24,79,52,15,27,52,24,70,108,230,0,200,177,244,72,73,255,
56,52,130,97,133,225,52,132,97,133,226,55,13,10,168,240,13,181,208,136,145,225,181,192,232,59,161,208,243,160,2,55,
41,52,2,67,104,24,101,225,133,227,52,98,249,133,228,104,133,225,104,133,226,96,55,79,165,55,13,165,52,8,11,25,
30,1,212,59,31,59,31,59,31,59,30,0,201,206,176,238,201,201,144,234,201,204,240,230,208,232,25,12,1,185,72,74,
41,3,9,4,133,41,104,41,24,144,2,105,127,133,40,10,10,5,40,133,40,52,94,61,0,0,165,37,32,193,251,101,
32,52,29,75,59,21,165,34,72,32,36,252,165,40,133,42,165,41,133,43,164,33,136,104,105,1,197,35,176,13,55,78,
177,40,145,42,136,16,249,48,225,160,0,32,158,252,176,134,164,36,169,160,145,40,200,196,33,144,249,52,30,199,59,27,
164,36,177,40,72,41,63,9,64,145,40,104,108,56,52,19,27,32,12,253,32,165,251,59,161,201,155,240,243,52,28,141,
59,6,32,142,253,165,51,32,237,253,162,1,138,240,243,202,32,53,253,201,149,208,2,177,40,201,224,144,2,41,223,157,
0,2,201,141,208,178,32,156,252,169,141,208,91,164,61,166,60,55,39,32,64,249,160,0,169,173,76,237,253,52,28,87,
59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,31,59,28,59,7,169,0,133,28,
165,230,133,27,160,0,132,26,165,28,145,26,32,126,244,200,208,246,230,27,165,27,41,31,208,238,96,133,226,134,224,132,
225,72,41,192,133,38,74,74,5,38,133,38,104,133,39,10,10,10,38,39,59,66,102,38,165,39,41,31,5,230,133,39,
138,192,0,240,5,160,35,105,4,200,233,7,176,251,132,229,170,189,185,244,133,48,152,74,165,228,133,28,176,25,28,0,
35,59,4,10,201,192,16,6,165,28,73,127,133,28,52,254,218,59,31,59,31,59,31,59,31,59,31,59,31,59,28,59,
10,74,8,32,71,248,40,169,15,144,2,105,224,133,46,177,38,69,48,37,46,81,38,145,38,96,32,0,248,196,44,176,
17,200,32,14,248,144,246,105,1,72,55,8,104,197,45,144,245,96,160,47,208,2,160,39,132,45,160,39,169,0,133,48,
32,40,248,136,16,246,96,25,5,4,126,39,25,6,4,126,38,10,10,52,130,52,96,165,48,24,105,3,41,15,133,48,
10,59,1,5,48,133,48,52,103,223,144,4,74,59,1,41,15,52,107,240,168,74,144,9,106,176,16,201,162,240,12,41,
135,74,170,189,98,249,32,121,248,208,4,160,128,169,0,170,189,166,249,133,46,41,3,133,47,152,41,143,170,152,160,3,
224,138,240,11,74,144,8,74,74,9,32,136,208,250,200,136,208,242,52,159,59,59,31,59,31,59,20,216,32,132,254,32,
47,251,32,147,254,32,137,254,173,88,192,173,90,192,173,93,192,173,95,192,173,255,207,44,16,192,216,32,58,255,32,96,
251,169,0,133,0,169,198,133,1,108,52,30,111,59,29,25,3,19,108,221,219,199,207,52,10,13,173,112,192,160,0,234,
234,189,100,192,16,4,200,208,248,136,96,169,0,133,72,173,86,192,173,84,192,173,81,192,169,0,240,11,173,80,192,173,
83,192,32,54,248,169,20,133,34,55,22,32,169,40,133,33,169,24,133,35,169,23,133,37,76,34,252,32,88,252,160,9,
185,8,251,153,14,4,136,208,247,96,173,243,3,73,165,141,244,3,96,201,141,208,24,172,0,192,16,19,192,147,208,15,
44,16,192,55,68,251,192,131,240,3,55,4,76,253,251,52,12,148,25,29,7,248,40,133,40,96,201,135,208,18,169,64,
32,168,252,160,192,169,12,59,193,173,48,192,136,208,245,96,164,36,145,40,230,36,165,36,197,33,176,102,96,201,160,176,
239,168,16,236,201,141,240,90,201,138,59,97,136,208,201,198,36,16,232,165,33,133,36,198,36,165,34,197,37,176,11,198,
37,25,28,7,248,0,72,32,36,252,32,158,252,160,0,104,105,0,197,35,144,240,176,202,165,34,133,37,160,0,132,36,
240,228,169,0,133,36,230,55,62,55,16,182,198,37,25,29,7,248,25,6,7,248,56,72,233,1,208,252,104,59,129,246,
96,230,66,208,2,230,67,165,60,197,62,165,61,229,63,230,60,55,6,61,52,125,244,59,18,25,13,7,248,230,78,208,
2,230,79,44,0,192,16,245,145,40,173,0,192,44,16,192,96,25,10,7,248,254,96,165,50,72,169,255,133,50,189,0,
2,32,237,253,104,55,129,201,136,240,29,201,152,240,10,224,248,144,3,32,58,255,232,208,19,169,220,55,21,25,10,7,
248,254,25,30,7,248,59,27,0,72,52,162,88,32,229,253,104,41,15,9,176,201,186,144,2,105,6,108,54,0,201,160,
144,2,37,50,132,53,72,32,120,251,104,164,53,52,49,47,64,52,10,5,52,11,24,177,60,145,66,32,180,252,144,247,
52,190,97,59,1,160,63,208,2,160,255,132,50,52,98,82,62,162,56,160,27,208,8,55,130,54,160,240,165,62,41,15,
240,6,9,192,160,0,240,2,169,253,148,0,149,1,96,234,234,76,0,224,52,30,115,59,29,59,13,169,135,76,237,253,
165,72,72,165,69,166,70,164,71,52,110,22,52,62,27,59,30,59,14,245,3,251,3,98,250,98,250
];

View File

@ -14,6 +14,8 @@ var AtariVectorPlatform = function(mainElement) {
var switches = new RAM(16).mem;
var nmicount = cpuCyclesPerNMI;
this.__proto__ = new Base6502Platform();
this.getPresets = function() {
return ATARIVEC_PRESETS;
}
@ -70,10 +72,10 @@ var AtariVectorPlatform = function(mainElement) {
// 262.5 scanlines per frame
var iaddr = 0x4000;
var iofs = 0;
breakClock = -1;
var debugCond = self.getDebugCallback();
clock = 0;
for (var i=0; i<cpuCyclesPerFrame; i++) {
if (debugCondition && breakClock < 0 && debugCondition()) { breakClock = clock; }
if (debugCond && debugCond()) { debugCond = null; }
clock++;
if (--nmicount == 0) {
//console.log("NMI", cpu.saveState());
@ -100,17 +102,13 @@ var AtariVectorPlatform = function(mainElement) {
37: 8+7,
};
var addr = KEY2ADDR[key];
console.log(key,flags,addr);
//console.log(key,flags,addr);
if (addr >= 0) {
switches[addr] = (flags&1) ? 0xff : 0x00;
}
});
}
this.getOpcodeMetadata = function(opcode, offset) {
return Javatari.getOpcodeMetadata(opcode, offset); // TODO
}
this.loadROM = function(title, data) {
if(data.length != 0x2000) {
throw "ROM length must be == 0x2000";
@ -137,87 +135,10 @@ var AtariVectorPlatform = function(mainElement) {
this.clearDebug();
cpu.reset();
}
this.getOriginPC = function() {
return (this.readAddress(0xfffc) | (this.readAddress(0xfffd) << 8)) & 0xffff;
}
this.readAddress = function(addr) {
return bus.read(addr);
}
var onBreakpointHit;
var debugCondition;
var debugSavedState = null;
var debugBreakState = null;
var debugTargetClock = 0;
var debugClock = 0;
var debugFrameStartClock = 0;
var breakClock;
this.setDebugCondition = function(debugCond) {
if (debugSavedState) {
self.loadState(debugSavedState);
} else {
debugSavedState = self.saveState();
}
debugClock = 0;
debugCondition = debugCond;
self.resume();
}
this.setupDebug = function(callback) {
onBreakpointHit = callback;
}
this.clearDebug = function() {
debugSavedState = null;
debugTargetClock = 0;
debugClock = 0;
debugFrameStartClock = 0;
onBreakpointHit = null;
debugCondition = null;
}
this.breakpointHit = function() {
debugBreakState = self.saveState();
console.log("Breakpoint at clk", debugClock, "PC", debugBreakState.c.PC.toString(16));
this.pause();
if (onBreakpointHit) {
onBreakpointHit(debugBreakState);
}
}
this.step = function() {
var previousPC = -1;
self.setDebugCondition(function() {
if (debugClock++ >= debugTargetClock) {
var thisState = cpu.saveState();
if (previousPC < 0) {
previousPC = thisState.PC;
} else {
if (thisState.PC != previousPC && thisState.T == 0) {
//console.log(previousPC.toString(16), thisPC.toString(16));
debugTargetClock = debugClock-1;
self.breakpointHit();
return true;
}
}
}
return false;
});
}
this.runEval = function(evalfunc) {
var self = this;
self.setDebugCondition(function() {
if (debugClock++ > debugTargetClock) {
var cpuState = cpu.saveState();
cpuState.PC = (cpuState.PC-1)&0xffff;
if (evalfunc(cpuState)) {
self.breakpointHit();
debugTargetClock = debugClock;
return true;
} else {
return false;
}
}
});
}
this.loadState = function(state) {
cpu.loadState(state.c);
cpuram.mem.set(state.cb);
@ -235,6 +156,9 @@ var AtariVectorPlatform = function(mainElement) {
this.getRAMForState = function(state) {
return state.cb;
}
this.getCPUState = function() {
return cpu.saveState();
}
}
var DVGStateMachine = function(bus, video) {

View File

@ -417,9 +417,11 @@ function showMemory(state) {
s = cpuStateToLongString(state.c);
s += "\n";
var ram = platform.getRAMForState(state);
var ramlen = ram.length <= 128 ? 128 : 256; // TODO
var ramofs = ram.length == 128 ? 0x80 : 0;
// TODO: show scrollable RAM for other platforms
for (var ofs=0; ofs<0x80; ofs+=0x10) {
s += '$' + hex(ofs+0x80) + ':';
for (var ofs=0; ofs<ramlen; ofs+=0x10) {
s += '$' + hex(ofs+ramofs) + ':';
for (var i=0; i<0x10; i++) {
if (i == 8) s += " ";
s += " " + hex(ram[ofs+i]);
@ -487,6 +489,25 @@ function runToCursor() {
}
}
function runUntilReturn() {
setupBreakpoint();
var depth = 1;
platform.runEval(function(c) {
if (depth <= 0 && c.T == 0)
return true;
if (c.o == 0x20)
depth++;
else if (c.o == 0x60 || c.o == 0x40)
--depth;
return false;
});
}
function runStepBackwards() {
setupBreakpoint();
platform.stepBack();
}
function clearBreakpoint() {
lastDebugState = null;
platform.clearDebug();
@ -710,12 +731,23 @@ function resetAndDebug() {
runToCursor();
}
function _breakExpression() {
var exprs = window.prompt("Enter break expression", "c.PC == 0x6000");
if (exprs) {
var fn = new Function('c', 'return (' + exprs + ');');
setupBreakpoint();
platform.runEval(fn);
}
}
function setupDebugControls(){
$("#dbg_reset").click(resetAndDebug);
$("#dbg_pause").click(pause);
$("#dbg_go").click(resume);
$("#dbg_step").click(singleStep);
$("#dbg_toline").click(runToCursor);
$("#dbg_stepout").click(runUntilReturn);
$("#dbg_stepback").click(runStepBackwards);
$("#dbg_timing").click(traceTiming);
$("#dbg_disasm").click(toggleDisassembly);
$("#disassembly").hide();
@ -723,6 +755,7 @@ function setupDebugControls(){
$("#item_new_file").click(_createNewFile);
$("#item_share_file").click(_shareFile);
$("#item_reset_file").click(_resetPreset);
$("#item_debug_expr").click(_breakExpression);
}
function showWelcomeMessage() {

View File

@ -157,10 +157,11 @@ function assembleACME(code) {
var alst = FS.readFile("a.rpt", {'encoding':'utf8'}); // TODO
var asym = FS.readFile("a.sym", {'encoding':'utf8'}); // TODO
console.log("acme", code.length, "->", aout.length);
//console.log(aout);
console.log(alst);
console.log(asym);
var listing = parseDASMListing(alst, unresolved);
return {exitstatus:Module.EXITSTATUS, output:aout.slice(2), listing:listing};
return {exitstatus:Module.EXITSTATUS, output:aout, listing:listing};
}
function compilePLASMA(code) {