fixed williams z80 cpu

This commit is contained in:
Steven Hugg 2017-01-29 16:06:05 -05:00
parent 5851394f40
commit e579663a8d
9 changed files with 74 additions and 44 deletions

View File

@ -2352,7 +2352,14 @@ return {
Ts-=step();
}
},
runFrame: function(Tt){
while (T<Tt){
step();
}
},
T:function(){return T;},
getTstates:function(){return T;},
setTstates:function(t){T=t;},
reset: reset,
init: function(bt,ba,tck){
byteTo=bt;

View File

@ -544,8 +544,21 @@ function cpuStateToLongString_Z80(c) {
;
}
window.buildZ80({
applyContention: false // TODO???
});
var BaseZ80Platform = function() {
// TODO: refactor w/ platforms
this.newCPU = function(membus, iobus) {
return window.Z80({
display: {},
memory: membus,
ioBus: iobus
});
}
var onBreakpointHit;
var debugCondition;
var debugSavedState = null;
@ -686,6 +699,12 @@ function cpuStateToLongString_6809(c) {
var Base6809Platform = function() {
this.__proto__ = new BaseZ80Platform();
this.newCPU = function(membus) {
var cpu = new CPU6809();
cpu.init(membus.write, membus.read, 0);
return cpu;
}
this.runUntilReturn = function() {
var self = this;
var depth = 1;

View File

@ -2,11 +2,6 @@
var GALAXIAN_PRESETS = [
];
// TODO: global???
window.buildZ80({
applyContention: false
});
var GalaxianPlatform = function(mainElement) {
var self = this;
this.__proto__ = new BaseZ80Platform();
@ -181,11 +176,7 @@ var GalaxianPlatform = function(mainElement) {
console.log('IO write', hex(addr,4), hex(val,2));
}
};
cpu = window.Z80({
display: {},
memory: membus,
ioBus: iobus
});
cpu = self.newCPU(membus, iobus);
video = new RasterVideo(mainElement,264,264,{rotate:90});
audio = new MasterAudio();
video.create();

View File

@ -2,11 +2,6 @@
var KONAMISOUND_PRESETS = [
];
// TODO: global???
window.buildZ80({
applyContention: false
});
var KonamiSoundPlatform = function(mainElement) {
var self = this;
this.__proto__ = new BaseZ80Platform();

View File

@ -5,11 +5,6 @@
var MW8080BW_PRESETS = [
];
// TODO: global???
window.buildZ80({
applyContention: false
});
var Midway8080BWPlatform = function(mainElement) {
var self = this;
this.__proto__ = new BaseZ80Platform();

View File

@ -2,11 +2,6 @@
var VICDUAL_PRESETS = [
];
// TODO: global???
window.buildZ80({
applyContention: false
});
var VicDualPlatform = function(mainElement) {
var self = this;
this.__proto__ = new BaseZ80Platform();

View File

@ -3,9 +3,9 @@
var WILLIAMS_PRESETS = [
];
var WilliamsPlatform = function(mainElement) {
var WilliamsPlatform = function(mainElement, proto) {
var self = this;
this.__proto__ = new Base6809Platform();
this.__proto__ = new (proto?proto:Base6809Platform)();
var SCREEN_HEIGHT = 304;
var SCREEN_WIDTH = 256;
@ -76,7 +76,7 @@ var WilliamsPlatform = function(mainElement) {
[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)); }],
[0x0, 0xfff, 0, function(a) { /*console.log('ioread',hex(a));*/ }],
]);
var iowrite_defender = new AddressDecoder([
@ -117,7 +117,7 @@ var WilliamsPlatform = function(mainElement) {
[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)); }],
[0x0, 0xfff, 0, function(a) { /* console.log('ioread',hex(a)); */ }],
]);
var iowrite_williams = new AddressDecoder([
@ -172,7 +172,8 @@ var WilliamsPlatform = function(mainElement) {
if (a) {
blitregs[a] = v;
} else {
doBlit(v);
var cycles = doBlit(v);
cpu.setTstates(cpu.getTstates() + cycles);
}
}
@ -241,7 +242,8 @@ var WilliamsPlatform = function(mainElement) {
curpix |= (solid & ~keepmask);
else
curpix |= (srcdata & ~keepmask);
memwrite_williams(dstaddr, curpix);
if (dstaddr < 0x9000) // can cause recursion otherwise
memwrite_williams(dstaddr, curpix);
}
var trace = false;
@ -250,7 +252,7 @@ var WilliamsPlatform = function(mainElement) {
var pc = cpu.getPC();
if (!_traceinsns[pc]) {
_traceinsns[pc] = 1;
console.log(hex(pc), cpu.T());
console.log(hex(pc), cpu.getTstates());
}
}
@ -266,8 +268,7 @@ var WilliamsPlatform = function(mainElement) {
read: memread_williams,
write: memwrite_williams,
};
cpu = new CPU6809();
cpu.init(membus.write, membus.read, 0);
cpu = self.newCPU(membus);
video = new RasterVideo(mainElement, SCREEN_WIDTH, SCREEN_HEIGHT, {rotate:-90});
video.create();
$(video.canvas).click(function(e) {
@ -287,21 +288,23 @@ var WilliamsPlatform = function(mainElement) {
for (var quarter=0; quarter<4; quarter++) {
video_counter = [0x00, 0x3c, 0xbc, 0xfc][quarter];
if (membus.read != memread_defender || pia6821[7] == 0x3c) { // TODO?
cpu.interrupt();
//console.log(cpu.getPC());
if (cpu.interrupt)
cpu.interrupt();
if (cpu.requestInterrupt)
cpu.requestInterrupt();
}
var targetTstates = cpu.T() + cpuCyclesPerFrame/4;
var targetTstates = cpu.getTstates() + cpuCyclesPerFrame/4;
if (debugCond || trace) {
while (cpu.T() < targetTstates) {
while (cpu.getTstates() < targetTstates) {
_trace();
if (debugCond && debugCond()) {
debugCond = null;
break;
}
cpu.steps(1);
cpu.runFrame(cpu.getTstates() + 1);
}
} else {
cpu.steps(cpuCyclesPerFrame);
cpu.runFrame(targetTstates);
}
}
if (screenNeedsRefresh) {
@ -320,6 +323,9 @@ var WilliamsPlatform = function(mainElement) {
}
this.loadROM = function(title, data) {
if (data.length > 2) {
rom = padBytes(data, 0xc000);
}
// TODO
self.reset();
}
@ -362,10 +368,16 @@ var WilliamsPlatform = function(mainElement) {
this.reset = function() {
cpu.reset();
watchdog_counter = INITIAL_WATCHDOG;
banksel = 1;
}
this.readAddress = function(addr) {
return membus.read(addr);
}
}
var WilliamsZ80Platform = function(mainElement) {
this.__proto__ = new WilliamsPlatform(mainElement, BaseZ80Platform);
}
PLATFORMS['williams'] = WilliamsPlatform;
PLATFORMS['williams-z80'] = WilliamsZ80Platform;

View File

@ -907,6 +907,7 @@ function initPlatform() {
function startPlatform() {
initPlatform();
if (!PLATFORMS[platform_id]) throw Error("Invalid platform '" + platform_id + "'.");
platform = new PLATFORMS[platform_id]($("#emulator")[0]);
PRESETS = platform.getPresets();
if (qs['file']) {
@ -970,7 +971,8 @@ function startUI(loadplatform) {
} else {
// load and start platform object
if (loadplatform) {
$.getScript('src/platform/' + platform_id + '.js', function() {
var scriptfn = 'src/platform/' + platform_id.split('-')[0] + '.js';
$.getScript(scriptfn, function() {
console.log("loaded platform", platform_id);
startPlatform();
});

View File

@ -19,6 +19,12 @@ var PLATFORM_PARAMS = {
data_start: 0x4000,
data_size: 0x400,
},
'williams-z80': {
code_start: 0x0,
code_size: 0x9000,
data_start: 0x9000,
data_size: 0x3000,
},
};
var loaded = {}
@ -639,7 +645,11 @@ function compileSDCC(code, platform) {
if (msvc_errors.length) {
return {errors:msvc_errors};
}
var asmout = FS.readFile("main.asm", {encoding:'utf8'});
try {
var asmout = FS.readFile("main.asm", {encoding:'utf8'});
} catch (e) {
return {errors:[{line:1, msg:e+""}]};
}
var warnings = msvc_errors;
var result = assemblelinkSDASZ80(asmout, platform, true);
result.asmlines = result.lines;
@ -711,7 +721,7 @@ function preprocessMCPP(code, platform) {
FS.writeFile("main.c", code, {encoding:'utf8'});
MCPP.callMain([
"-D", "__8BITWORKSHOP__",
"-D", platform.toUpperCase(),
"-D", platform.toUpperCase().replace('-','_'),
"-I", "/share/include",
"-Q",
"main.c", "main.i"]);
@ -725,7 +735,11 @@ function preprocessMCPP(code, platform) {
var errout = FS.readFile("mcpp.err", {encoding:'utf8'});
if (errout.length) {
// //main.c:2: error: Can't open include file "stdiosd.h"
return {errors: extractErrors(/[^:]+:(\d+): (.+)/, errout.split("\n"))};
var errors = extractErrors(/[^:]+:(\d+): (.+)/, errout.split("\n"));
if (errors.length == 0) {
errors = [{line:1, msg:errout}];
}
return {errors: errors};
}
} catch (e) {
//