mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-16 17:30:27 +00:00
robotron driver
This commit is contained in:
parent
17370248ee
commit
f696f22b5a
@ -281,6 +281,7 @@ canvas.pixelated {
|
||||
<script src="tss/js/Log.js"></script>
|
||||
|
||||
<script src="local/williams/defender.js"></script>
|
||||
<script src="local/williams/robotron.js"></script>
|
||||
|
||||
<script src="src/emu.js"></script>
|
||||
<script src="src/util.js"></script>
|
||||
|
@ -107,7 +107,7 @@ var flagsNZ = [
|
||||
|
||||
var setV8 = function(a,b,r) {CC |= (((a^b^r^(r>>1))&0x80)>>6);};
|
||||
var setV16 = function(a,b,r) {CC |= (((a^b^r^(r>>1))&0x8000)>>14);};
|
||||
var getD = function() {return rA*256+rB;};
|
||||
var getD = function() {return (rA<<8)+rB;};
|
||||
var setD = function(v) {rA = (v>>8)& 0xff;rB=v&0xff;};
|
||||
var PUSHB = function(b) {
|
||||
byteTo(--rS, b & 0xff);
|
||||
@ -595,6 +595,7 @@ var oCOM = function(b) {
|
||||
CC &= ~(F_ZERO | F_NEGATIVE | F_OVERFLOW);
|
||||
b ^= 0xff;
|
||||
CC |= flagsNZ[b];
|
||||
CC |= F_CARRY;
|
||||
return b;
|
||||
};
|
||||
|
||||
@ -607,10 +608,6 @@ var dpadd = function() {
|
||||
var step = function() {
|
||||
var oldT = T;
|
||||
|
||||
if (IRQs) {
|
||||
//;;;
|
||||
}
|
||||
|
||||
var addr = null;
|
||||
var pb = null;
|
||||
|
||||
@ -819,7 +816,7 @@ var step = function() {
|
||||
break;
|
||||
case 0x3B: //RTI
|
||||
CC = PULLB();
|
||||
if (cc & F_ENTIRE) {
|
||||
if (CC & F_ENTIRE) {
|
||||
T+=9;
|
||||
rA = PULLB();
|
||||
rB = PULLB();
|
||||
@ -1437,7 +1434,7 @@ var step = function() {
|
||||
case 0xDE: //LDU direct
|
||||
addr = dpadd();
|
||||
rU = ReadWord(addr);
|
||||
flagsNZ16(rX);
|
||||
flagsNZ16(rU);
|
||||
CC&=~F_OVERFLOW;
|
||||
break;
|
||||
case 0xDF: //STU direct
|
||||
@ -2248,17 +2245,17 @@ var disasm = function(i,a,b,c,d,pc) {
|
||||
case 0: //invalid
|
||||
break;
|
||||
case 1: //direct page
|
||||
mnemo+=" $"+toHex2(a); break;
|
||||
mnemo+="\t$"+toHex2(a); break;
|
||||
case 2: // inherent
|
||||
break;
|
||||
case 3: //brel16
|
||||
mnemo+=" #$"+toHex4((a*256+b)<32768 ? (a*256+b+pc):(a*256+b+pc-65536)); break;
|
||||
mnemo+="\t#$"+toHex4((a*256+b)<32768 ? (a*256+b+pc):(a*256+b+pc-65536)); break;
|
||||
case 4: //imm8
|
||||
mnemo+=" #$"+toHex2(a); break;
|
||||
mnemo+="\t#$"+toHex2(a); break;
|
||||
case 5: //brel8
|
||||
mnemo+=" #$"+toHex4((a)<128 ? (a+pc+2):(a+pc-254)); break;
|
||||
mnemo+="\t#$"+toHex4((a)<128 ? (a+pc+2):(a+pc-254)); break;
|
||||
case 6: //indexed, postbyte etc.
|
||||
mnemo+=' ';
|
||||
mnemo+='\t';
|
||||
var pb = a;
|
||||
var ixr = ["X","Y","U","S"][(pb & 0x60)>>5];
|
||||
if (!(pb & 0x80)) {
|
||||
@ -2314,9 +2311,9 @@ var disasm = function(i,a,b,c,d,pc) {
|
||||
|
||||
break;
|
||||
case 7: //extended
|
||||
mnemo+=" $"+toHex4(a*256+b); break;
|
||||
mnemo+="\t$"+toHex4(a*256+b); break;
|
||||
case 8: //imm16
|
||||
mnemo+=" #$"+toHex4(a*256+b); break;
|
||||
mnemo+="\t#$"+toHex4(a*256+b); break;
|
||||
|
||||
case 10: //pshs, puls
|
||||
rx = ['PC','U','Y','X','DP','B','A','CC'];
|
||||
@ -2325,7 +2322,7 @@ var disasm = function(i,a,b,c,d,pc) {
|
||||
if ((a & 1)!==0) {ro.push(rx[7-j]);}
|
||||
a>>=1;
|
||||
}
|
||||
mnemo += ' '+ro.join(',');
|
||||
mnemo += '\t'+ro.join(',');
|
||||
break;
|
||||
case 11: //pshs, puls
|
||||
rx = ['PC','S','Y','X','DP','B','A','CC'];
|
||||
@ -2334,11 +2331,11 @@ var disasm = function(i,a,b,c,d,pc) {
|
||||
if ((a & 1)!==0) {ro.push(rx[7-j]);}
|
||||
a>>=1;
|
||||
}
|
||||
mnemo += ' '+ro.join(',');
|
||||
mnemo += '\t'+ro.join(',');
|
||||
break;
|
||||
case 20: //TFR etc
|
||||
rx = ['D','X','Y','U','S','PC','?','?','A','B','CC','DP','?','?','?','?'];
|
||||
mnemo += ' '+rx[a>>4]+','+rx[a&0x0f];
|
||||
mnemo += '\t'+rx[a>>4]+','+rx[a&0x0f];
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2397,6 +2394,7 @@ return {
|
||||
PUSHB(CC);
|
||||
CC |= F_IRQMASK | F_FIRQMASK;
|
||||
PC = ReadWord(vecFIRQ);
|
||||
T += 9;
|
||||
},
|
||||
interrupt: function() {
|
||||
if (CC & F_IRQMASK) return;
|
||||
@ -2411,6 +2409,7 @@ return {
|
||||
PUSHB(CC);
|
||||
CC |= F_IRQMASK;
|
||||
PC = ReadWord(vecIRQ);
|
||||
T += 18;
|
||||
},
|
||||
nmi: function() {
|
||||
PUSHW(PC);
|
||||
@ -2424,6 +2423,7 @@ return {
|
||||
PUSHB(CC);
|
||||
CC |= F_IRQMASK | F_FIRQMASK;
|
||||
PC = ReadWord(vecNMI);
|
||||
T += 18;
|
||||
},
|
||||
set:function(reg,value) {
|
||||
switch (reg.toUpperCase()) {
|
||||
@ -2445,7 +2445,7 @@ return {
|
||||
}
|
||||
return f;
|
||||
},
|
||||
disasm: disasm,
|
||||
disasm: disasm
|
||||
};
|
||||
|
||||
};
|
||||
|
16
src/emu.js
16
src/emu.js
@ -533,9 +533,10 @@ var BaseZ80Platform = function() {
|
||||
this.resume();
|
||||
}
|
||||
this.restartDebugState = function() {
|
||||
if (debugCondition && !debugBreakState && debugTargetClock > 0) {
|
||||
if (debugCondition && !debugBreakState) {
|
||||
debugSavedState = this.saveState();
|
||||
debugTargetClock -= debugSavedState.c.T;
|
||||
if (debugTargetClock > 0)
|
||||
debugTargetClock -= debugSavedState.c.T;
|
||||
debugSavedState.c.T = 0;
|
||||
this.loadState(debugSavedState);
|
||||
}
|
||||
@ -636,7 +637,7 @@ var BaseZ80Platform = function() {
|
||||
|
||||
function cpuStateToLongString_6809(c) {
|
||||
function decodeFlags(flags) {
|
||||
var flagspec = "SZ-H-VNC";
|
||||
var flagspec = "EFHINZVC";
|
||||
var s = "";
|
||||
for (var i=0; i<8; i++)
|
||||
s += (flags & (128>>i)) ? flagspec.slice(i,i+1) : "-";
|
||||
@ -644,6 +645,11 @@ function cpuStateToLongString_6809(c) {
|
||||
}
|
||||
return "PC " + hex(c.PC,4) + " " + decodeFlags(c.CC) + "\n"
|
||||
+ "SP " + hex(c.SP,4) + "\n"
|
||||
+ " A " + hex(c.A,2) + "\n"
|
||||
+ " B " + hex(c.B,2) + "\n"
|
||||
+ " X " + hex(c.X,4) + "\n"
|
||||
+ " Y " + hex(c.Y,4) + "\n"
|
||||
+ " U " + hex(c.U,4) + "\n"
|
||||
;
|
||||
}
|
||||
|
||||
@ -658,9 +664,9 @@ var Base6809Platform = function() {
|
||||
return true;
|
||||
var op = self.readAddress(c.PC);
|
||||
// TODO: 6809 opcodes
|
||||
if (op == 0xcd) // CALL
|
||||
if (op == 0x9d || op == 0xad || op == 0xbd) // CALL
|
||||
depth++;
|
||||
else if (op == 0xc0 || op == 0xc8 || op == 0xc9 || op == 0xd0) // RET (TODO?)
|
||||
else if (op == 0x3b || op == 0x39) // RET (TODO?)
|
||||
--depth;
|
||||
return false;
|
||||
});
|
||||
|
@ -7,13 +7,20 @@ var WilliamsPlatform = function(mainElement) {
|
||||
var self = this;
|
||||
this.__proto__ = new Base6809Platform();
|
||||
|
||||
var cpu, ram, membus, iobus, rom, nvram;
|
||||
var video, timer, pixels, displayPCs;
|
||||
var SCREEN_HEIGHT = 304;
|
||||
var SCREEN_WIDTH = 256;
|
||||
|
||||
var cpu, ram, rom, nvram;
|
||||
var portsel = 0;
|
||||
var banksel = 0;
|
||||
var watchdog_counter;
|
||||
var video_counter;
|
||||
var pia6821 = [0,0,0,0,0,0,0,0];
|
||||
var pia6821 = new RAM(8).mem;
|
||||
var blitregs = new RAM(8).mem;
|
||||
|
||||
var video, timer, pixels, displayPCs;
|
||||
var membus, iobus;
|
||||
var screenNeedsRefresh = false;
|
||||
var video_counter;
|
||||
|
||||
var xtal = 12000000;
|
||||
var cpuFrequency = xtal/3/4;
|
||||
@ -22,7 +29,7 @@ var WilliamsPlatform = function(mainElement) {
|
||||
var PIXEL_ON = 0xffeeeeee;
|
||||
var PIXEL_OFF = 0xff000000;
|
||||
|
||||
var KEYCODE_MAP = makeKeycodeMap([
|
||||
var DEFENDER_KEYCODE_MAP = makeKeycodeMap([
|
||||
[Keys.VK_SPACE, 4, 0x1],
|
||||
[Keys.VK_RIGHT, 4, 0x2],
|
||||
[Keys.VK_Z, 4, 0x4],
|
||||
@ -38,6 +45,23 @@ var WilliamsPlatform = function(mainElement) {
|
||||
[Keys.VK_9, 0, 0x8],
|
||||
]);
|
||||
|
||||
var ROBOTRON_KEYCODE_MAP = makeKeycodeMap([
|
||||
[Keys.VK_W, 0, 0x1],
|
||||
[Keys.VK_S, 0, 0x2],
|
||||
[Keys.VK_A, 0, 0x4],
|
||||
[Keys.VK_D, 0, 0x8],
|
||||
[Keys.VK_1, 0, 0x10],
|
||||
[Keys.VK_2, 0, 0x20],
|
||||
[Keys.VK_UP, 0, 0x40],
|
||||
[Keys.VK_DOWN, 0, 0x80],
|
||||
[Keys.VK_LEFT, 2, 0x1],
|
||||
[Keys.VK_RIGHT, 2, 0x2],
|
||||
[Keys.VK_7, 4, 0x1],
|
||||
[Keys.VK_8, 4, 0x2],
|
||||
[Keys.VK_5, 4, 0x4],
|
||||
[Keys.VK_9, 4, 0x8],
|
||||
]);
|
||||
|
||||
var palette = [];
|
||||
for (var ii=0; ii<16; ii++)
|
||||
palette[ii] = 0xff000000;
|
||||
@ -46,74 +70,205 @@ var WilliamsPlatform = function(mainElement) {
|
||||
return WILLIAMS_PRESETS;
|
||||
}
|
||||
|
||||
var ioread = new AddressDecoder([
|
||||
// Defender
|
||||
|
||||
var ioread_defender = 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?
|
||||
var iowrite_defender = new AddressDecoder([
|
||||
[0x0, 0xf, 0xf, setPalette],
|
||||
[0x3fc, 0x3ff, 0, function(a,v) { if (v == 0x38) watchdog_counter = INITIAL_WATCHDOG; }],
|
||||
[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)); }],
|
||||
]);
|
||||
|
||||
var memread_defender = new AddressDecoder([
|
||||
[0x0000, 0xbfff, 0xffff, function(a) { return ram.mem[a]; }],
|
||||
[0xc000, 0xcfff, 0x0fff, function(a) {
|
||||
switch (banksel) {
|
||||
case 0: return ioread_defender(a);
|
||||
case 1: return rom[a+0x3000];
|
||||
case 2: return rom[a+0x4000];
|
||||
case 3: return rom[a+0x5000];
|
||||
case 7: return rom[a+0x6000];
|
||||
default: return 0; // TODO: error light
|
||||
}
|
||||
}],
|
||||
[0xd000, 0xffff, 0xffff, function(a) { return rom ? rom[a-0xd000] : 0; }],
|
||||
]);
|
||||
|
||||
var memwrite_defender = new AddressDecoder([
|
||||
[0x0000, 0x97ff, 0, write_display_byte],
|
||||
[0x9800, 0xbfff, 0, function(a,v) { ram.mem[a] = v; }],
|
||||
[0xc000, 0xcfff, 0x0fff, iowrite_defender],
|
||||
[0xd000, 0xdfff, 0, function(a,v) { banksel = v&0x7; }],
|
||||
[0, 0xffff, 0, function(a,v) { console.log(hex(a), hex(v)); }],
|
||||
]);
|
||||
|
||||
// Robotron, Joust, Bubbles, Stargate
|
||||
|
||||
var ioread_williams = new AddressDecoder([
|
||||
[0x804, 0x807, 0x3, function(a) { return pia6821[a]; }],
|
||||
[0x80c, 0x80f, 0x3, function(a) { return pia6821[a+4]; }],
|
||||
[0xb00, 0xbff, 0, function(a) { return video_counter; }],
|
||||
[0xc00, 0xfff, 0x3ff, function(a) { return nvram.mem[a]; }],
|
||||
[0x0, 0xfff, 0, function(a) { console.log('ioread',hex(a)); }],
|
||||
]);
|
||||
|
||||
var iowrite_williams = new AddressDecoder([
|
||||
[0x0, 0xf, 0xf, setPalette],
|
||||
[0x804, 0x807, 0x3, function(a,v) { console.log('iowrite',a); }], // TODO: sound
|
||||
[0x80c, 0x80f, 0x3, function(a,v) { console.log('iowrite',a+4); }], // TODO: sound
|
||||
[0x900, 0x9ff, 0, function(a,v) { banksel = v & 0x1; }],
|
||||
[0xa00, 0xa07, 0x7, setBlitter],
|
||||
[0xbff, 0xbff, 0, function(a,v) { if (v == 0x39) watchdog_counter = INITIAL_WATCHDOG; }],
|
||||
[0xc00, 0xfff, 0x3ff, function(a,v) { nvram.mem[a] = v; }],
|
||||
[0x0, 0xfff, 0, function(a,v) { console.log('iowrite',hex(a),hex(v)); }],
|
||||
]);
|
||||
|
||||
var memread_williams = new AddressDecoder([
|
||||
[0x0000, 0x8fff, 0xffff, function(a) { return banksel ? rom[a] : ram.mem[a]; }],
|
||||
[0x9000, 0xbfff, 0xffff, function(a) { return ram.mem[a]; }],
|
||||
[0xc000, 0xcfff, 0x0fff, ioread_williams],
|
||||
[0xd000, 0xffff, 0xffff, function(a) { return rom ? rom[a-0x4000] : 0; }],
|
||||
]);
|
||||
|
||||
var memwrite_williams = new AddressDecoder([
|
||||
[0x0000, 0x8fff, 0, write_display_byte],
|
||||
[0x9000, 0xbfff, 0, function(a,v) { ram.mem[a] = v; }],
|
||||
[0xc000, 0xcfff, 0x0fff, iowrite_williams],
|
||||
[0x0000, 0xffff, 0, function(a,v) { console.log(hex(a), hex(v)); }],
|
||||
]);
|
||||
|
||||
// d1d6 ldu $11 / beq $d1ed
|
||||
|
||||
function setPalette(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;
|
||||
}
|
||||
}
|
||||
|
||||
function write_display_byte(a,v) {
|
||||
ram.mem[a] = v;
|
||||
drawDisplayByte(a, v);
|
||||
displayPCs[a] = cpu.getPC(); // save program counter
|
||||
}
|
||||
|
||||
function drawDisplayByte(a,v) {
|
||||
var ofs = ((a&0xff00)<<1) | ((a&0xff)^0xff);
|
||||
pixels[ofs] = palette[v>>4];
|
||||
pixels[ofs+256] = palette[v&0xf];
|
||||
}
|
||||
|
||||
function setBlitter(a,v) {
|
||||
if (a) {
|
||||
blitregs[a] = v;
|
||||
} else {
|
||||
doBlit(v);
|
||||
}
|
||||
}
|
||||
|
||||
function doBlit(flags) {
|
||||
//console.log(hex(flags), blitregs);
|
||||
flags &= 0xff;
|
||||
var offs = SCREEN_HEIGHT - blitregs[7];
|
||||
var sstart = (blitregs[2] << 8) + blitregs[3];
|
||||
var dstart = (blitregs[4] << 8) + blitregs[5];
|
||||
var w = blitregs[6] ^ 4; // blitter bug fix
|
||||
var h = blitregs[7] ^ 4;
|
||||
if(w==0) w++;
|
||||
if(h==0) h++;
|
||||
if(h==255) h++;
|
||||
var sxinc = (flags & 0x1) ? 256 : 1;
|
||||
var syinc = (flags & 0x1) ? 1 : w;
|
||||
var dxinc = (flags & 0x2) ? 256 : 1;
|
||||
var dyinc = (flags & 0x2) ? 1 : w;
|
||||
var pixdata = 0;
|
||||
for (var y = 0; y < h; y++) {
|
||||
var source = sstart & 0xffff;
|
||||
var dest = dstart & 0xffff;
|
||||
for (var x = 0; x < w; x++) {
|
||||
var data = memread_williams(source);
|
||||
if (flags & 0x20) {
|
||||
pixdata = (pixdata << 8) | data;
|
||||
blit_pixel(dest, (pixdata >> 4) & 0xff, flags);
|
||||
} else {
|
||||
blit_pixel(dest, data, flags);
|
||||
}
|
||||
source += sxinc;
|
||||
source &= 0xffff;
|
||||
dest += dxinc;
|
||||
dest &= 0xffff;
|
||||
}
|
||||
if (flags & 0x2)
|
||||
dstart = (dstart & 0xff00) | ((dstart + dyinc) & 0xff);
|
||||
else
|
||||
dstart += dyinc;
|
||||
if (flags & 0x1)
|
||||
sstart = (sstart & 0xff00) | ((sstart + syinc) & 0xff);
|
||||
else
|
||||
sstart += syinc;
|
||||
}
|
||||
return w * h * (2 + ((flags&0x4)!=0)); // # of memory accesses
|
||||
}
|
||||
|
||||
function blit_pixel(dstaddr, srcdata, flags) {
|
||||
var curpix = dstaddr < 0xc000 ? ram.mem[dstaddr] : memread_williams(dstaddr);
|
||||
var solid = blitregs[1];
|
||||
var keepmask = 0xff; //what part of original dst byte should be kept, based on NO_EVEN and NO_ODD flags
|
||||
//even pixel (D7-D4)
|
||||
if((flags & 0x8) && !(srcdata & 0xf0)) { //FG only and src even pixel=0
|
||||
if(flags & 0x80) keepmask &= 0x0f; // no even
|
||||
} else {
|
||||
if(!(flags & 0x80)) keepmask &= 0x0f; // not no even
|
||||
}
|
||||
//odd pixel (D3-D0)
|
||||
if((flags & 0x8) && !(srcdata & 0x0f)) { //FG only and src odd pixel=0
|
||||
if(flags & 0x40) keepmask &= 0xf0; // no odd
|
||||
} else {
|
||||
if(!(flags & 0x40)) keepmask &= 0xf0; // not no odd
|
||||
}
|
||||
curpix &= keepmask;
|
||||
if(flags & 0x10) // solid bit
|
||||
curpix |= (solid & ~keepmask);
|
||||
else
|
||||
curpix |= (srcdata & ~keepmask);
|
||||
memwrite_williams(dstaddr, curpix);
|
||||
}
|
||||
|
||||
var trace = false;
|
||||
var _traceinsns = {};
|
||||
function _trace() {
|
||||
var pc = cpu.getPC();
|
||||
if (!_traceinsns[pc]) {
|
||||
_traceinsns[pc] = 1;
|
||||
console.log(hex(pc), cpu.T());
|
||||
}
|
||||
}
|
||||
|
||||
this.start = function() {
|
||||
ram = new RAM(0xc000);
|
||||
nvram = new RAM(0x200);
|
||||
nvram = new RAM(0x400);
|
||||
// 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]);
|
||||
// defender 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);
|
||||
rom = padBytes(new lzgmini().decode(ROBOTRON_ROM).slice(0), 0xc001);
|
||||
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)); }],
|
||||
]),
|
||||
read: memread_williams,
|
||||
write: memwrite_williams,
|
||||
};
|
||||
cpu = new CPU6809();
|
||||
cpu.init(membus.write, membus.read, 0);
|
||||
video = new RasterVideo(mainElement,256,304,{rotate:-90});
|
||||
video = new RasterVideo(mainElement, SCREEN_WIDTH, SCREEN_HEIGHT, {rotate:-90});
|
||||
video.create();
|
||||
$(video.canvas).click(function(e) {
|
||||
var x = Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width());
|
||||
@ -123,9 +278,9 @@ var WilliamsPlatform = function(mainElement) {
|
||||
});
|
||||
var idata = video.getFrameData();
|
||||
video.setKeyboardEvents(function(key,code,flags) {
|
||||
var o = KEYCODE_MAP[key];
|
||||
var o = ROBOTRON_KEYCODE_MAP[key];
|
||||
if (o) {
|
||||
console.log(key,code,flags,o);
|
||||
//console.log(key,code,flags,o);
|
||||
if (flags & 1) {
|
||||
pia6821[o.index] |= o.mask;
|
||||
} else {
|
||||
@ -140,14 +295,15 @@ var WilliamsPlatform = function(mainElement) {
|
||||
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?
|
||||
video_counter = [0x00, 0x3c, 0xbc, 0xfc][quarter];
|
||||
if (membus.read != memread_defender || pia6821[7] == 0x3c) { // TODO?
|
||||
cpu.interrupt();
|
||||
//console.log(cpu.getPC());
|
||||
}
|
||||
var targetTstates = cpu.T() + cpuCyclesPerFrame/4;
|
||||
if (debugCond) {
|
||||
if (debugCond || trace) {
|
||||
while (cpu.T() < targetTstates) {
|
||||
_trace();
|
||||
if (debugCond && debugCond()) {
|
||||
debugCond = null;
|
||||
break;
|
||||
@ -182,18 +338,22 @@ var WilliamsPlatform = function(mainElement) {
|
||||
cpu.loadState(state.c);
|
||||
ram.mem.set(state.b);
|
||||
nvram.mem.set(state.nvram);
|
||||
//pia6821.set(state.pia);
|
||||
blitregs.set(state.blt);
|
||||
watchdog_counter = state.wdc;
|
||||
banksel = state.bs;
|
||||
pia6821 = state.pia;
|
||||
portsel = state.ps;
|
||||
}
|
||||
this.saveState = function() {
|
||||
return {
|
||||
c:self.getCPUState(),
|
||||
b:ram.mem.slice(0),
|
||||
nvram:nvram.mem.slice(0),
|
||||
pia:pia6821.slice(0),
|
||||
blt:blitregs.slice(0),
|
||||
wdc:watchdog_counter,
|
||||
bs:banksel,
|
||||
pia:pia6821,
|
||||
ps:portsel,
|
||||
};
|
||||
}
|
||||
this.getRAMForState = function(state) {
|
||||
|
@ -766,7 +766,12 @@ function updateDisassembly() {
|
||||
s += "; " + srclinenum + ":\t" + srcline + "\n";
|
||||
}
|
||||
}
|
||||
var dline = hex(parseInt(a)) + "\t" + disasm.line + "\n";
|
||||
var bytes = "";
|
||||
for (var i=0; i<disasm.nbytes; i++)
|
||||
bytes += hex(platform.readAddress(a+i));
|
||||
while (bytes.length < 14)
|
||||
bytes += ' ';
|
||||
var dline = hex(parseInt(a)) + "\t" + bytes + "\t" + disasm.line + "\n";
|
||||
s += dline;
|
||||
if (a == pc) selline = curline;
|
||||
curline++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user