mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-06-02 12:41:30 +00:00
converted everything to new Z80, debugging broken
This commit is contained in:
parent
3b4d2b5f82
commit
d8421fee7f
|
@ -33,17 +33,14 @@ function require(modname) {
|
|||
}
|
||||
|
||||
importScripts("../../gen/emu.js");
|
||||
importScripts("../cpu/z80.js");
|
||||
|
||||
window.buildZ80({
|
||||
applyContention: false
|
||||
});
|
||||
importScripts("../../gen/cpu/ZilogZ80.js");
|
||||
|
||||
var cpu, ram, rom, membus, iobus;
|
||||
var audio;
|
||||
var command = 0;
|
||||
var dac = 0;
|
||||
var current_buffer;
|
||||
var tstates;
|
||||
var last_tstate;
|
||||
|
||||
var timer;
|
||||
|
@ -62,7 +59,7 @@ rom = new RAM(0x4000).mem;
|
|||
rom.fill(0x76); // HALT opcodes
|
||||
|
||||
function fillBuffer() {
|
||||
var t = cpu.getTstates() / cpuAudioFactor;
|
||||
var t = tstates / cpuAudioFactor;
|
||||
while (last_tstate < t) {
|
||||
current_buffer[last_tstate*2] = dac;
|
||||
current_buffer[last_tstate*2+1] = dac;
|
||||
|
@ -91,25 +88,24 @@ function start() {
|
|||
fillBuffer();
|
||||
}
|
||||
};
|
||||
cpu = window.Z80({
|
||||
display: {},
|
||||
memory: membus,
|
||||
ioBus: iobus
|
||||
});
|
||||
cpu = new exports.Z80();
|
||||
cpu.connectMemoryBus(membus);
|
||||
cpu.connectIOBus(iobus);
|
||||
current_buffer = new Int16Array(bufferLength);
|
||||
console.log('started audio');
|
||||
}
|
||||
|
||||
function timerCallback() {
|
||||
cpu.setTstates(0);
|
||||
tstates = 0;
|
||||
last_tstate = 0;
|
||||
var numStates = Math.floor(bufferLength * cpuAudioFactor / numChannels);
|
||||
cpu.runFrame(numStates);
|
||||
//console.log(numStates, cpu.getTstates());
|
||||
cpu.setTstates(numStates); // TODO?
|
||||
while (tstates < numStates) {
|
||||
tstates += cpu.advanceInsn();
|
||||
}
|
||||
tstates = 0;
|
||||
fillBuffer();
|
||||
postMessage({samples:current_buffer});
|
||||
if (!cpu.getHalted()) {
|
||||
if (!cpu.saveState().halted) {
|
||||
curTime += timerPeriod;
|
||||
var dt = curTime - new Date().getTime();
|
||||
if (dt < 0) dt = 0;
|
||||
|
|
|
@ -4,8 +4,9 @@ import { hex, printFlags, invertMap } from "./util";
|
|||
import { CodeAnalyzer } from "./analysis";
|
||||
import { disassemble6502 } from "./cpu/disasm6502";
|
||||
import { disassembleZ80 } from "./cpu/disasmz80";
|
||||
import { Z80 } from "./cpu/ZilogZ80";
|
||||
|
||||
declare var buildZ80, jt, CPU6809;
|
||||
declare var jt, CPU6809;
|
||||
|
||||
export interface OpcodeMetadata {
|
||||
minCycles: number;
|
||||
|
@ -488,85 +489,40 @@ export function cpuStateToLongString_Z80(c) {
|
|||
;
|
||||
}
|
||||
|
||||
export function BusProbe(bus : MemoryBus) {
|
||||
var active = false;
|
||||
var callback;
|
||||
this.activate = function(_callback) {
|
||||
active = true;
|
||||
callback = _callback;
|
||||
}
|
||||
this.deactivate = function() {
|
||||
active = false;
|
||||
callback = null;
|
||||
}
|
||||
this.read = function(a) {
|
||||
if (active) {
|
||||
callback(a);
|
||||
}
|
||||
return bus.read(a);
|
||||
}
|
||||
this.write = function(a,v) {
|
||||
if (active) {
|
||||
callback(a,v);
|
||||
}
|
||||
bus.write(a,v);
|
||||
}
|
||||
this.contend = function(addr,cyc) {
|
||||
return bus.contend(addr,cyc);
|
||||
}
|
||||
this.isContended = function(addr) {
|
||||
return bus.isContended(addr);
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class BaseZ80Platform extends BaseDebugPlatform {
|
||||
|
||||
_cpu;
|
||||
probe;
|
||||
waitCycles : number = 0;
|
||||
|
||||
newCPU(membus : MemoryBus, iobus : MemoryBus, z80opts? : {}) {
|
||||
this.probe = new BusProbe(membus);
|
||||
this._cpu = buildZ80(z80opts || {})({
|
||||
display: {},
|
||||
memory: this.probe,
|
||||
ioBus: iobus
|
||||
});
|
||||
newCPU(membus : MemoryBus, iobus : MemoryBus) {
|
||||
this._cpu = new Z80();
|
||||
this._cpu.connectMemoryBus(membus);
|
||||
this._cpu.connectIOBus(iobus);
|
||||
return this._cpu;
|
||||
}
|
||||
|
||||
getProbe() { return this.probe; } // TODO?
|
||||
getPC() { return this._cpu.getPC(); }
|
||||
getSP() { return this._cpu.getSP(); }
|
||||
|
||||
// TODO: refactor other parts into here
|
||||
runCPU(cpu, cycles:number) {
|
||||
this._cpu = cpu; // TODO?
|
||||
this.waitCycles = 0; // TODO: needs to spill over betwenn calls
|
||||
if (this.wasBreakpointHit())
|
||||
return 0;
|
||||
var debugCond = this.getDebugCallback();
|
||||
var targetTstates = cpu.getTstates() + cycles;
|
||||
try {
|
||||
if (debugCond) { // || trace) {
|
||||
while (cpu.getTstates() < targetTstates) {
|
||||
var n = 0;
|
||||
this.waitCycles += cycles;
|
||||
while (this.waitCycles > 0) {
|
||||
if (debugCond && debugCond()) {
|
||||
debugCond = null;
|
||||
break;
|
||||
}
|
||||
cpu.runFrame(cpu.getTstates() + 1);
|
||||
var cyc = cpu.advanceInsn();
|
||||
n += cyc;
|
||||
this.waitCycles -= cyc;
|
||||
}
|
||||
} else {
|
||||
cpu.runFrame(targetTstates);
|
||||
}
|
||||
} catch (e) {
|
||||
// TODO: show alert w/ error msg
|
||||
console.log(e);
|
||||
this.breakpointHit(cpu.getTstates());
|
||||
}
|
||||
return cpu.getTstates() - targetTstates;
|
||||
}
|
||||
requestInterrupt(cpu, data) {
|
||||
if (!this.wasBreakpointHit())
|
||||
cpu.requestInterrupt(data);
|
||||
return n;
|
||||
}
|
||||
postFrame() {
|
||||
if (this.debugCallback) {
|
||||
|
|
|
@ -27,8 +27,6 @@ import { CPU, Bus, InstructionBased, IOBusConnected, SavesState, Interruptable }
|
|||
/// or at http://opensource.org/licenses/MIT
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
"use strict";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// We'll begin with the object constructor and the public API functions.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -306,7 +306,9 @@ const _BallyAstrocadePlatform = function(mainElement, arcade) {
|
|||
refreshall();
|
||||
break;
|
||||
case 0xb: // OTIR (set palette)
|
||||
setpalette(cpu.getBC()>>8, membus.read(cpu.getHL()));
|
||||
var c = cpu.saveState();
|
||||
//console.log(c.BC>>8, c.HL);
|
||||
setpalette((c.BC>>8)-1, membus.read(c.HL));
|
||||
break;
|
||||
case 0xc: // magic register
|
||||
magicop = val;
|
||||
|
@ -334,7 +336,8 @@ const _BallyAstrocadePlatform = function(mainElement, arcade) {
|
|||
psg.setACRegister(addr, val);
|
||||
break;
|
||||
case 0x18:
|
||||
psg.setACRegister(cpu.getBC()>>8, membus.read(cpu.getHL()));
|
||||
var c = cpu.saveState();
|
||||
psg.setACRegister((c.BC>>8)-1, membus.read(c.HL));
|
||||
break;
|
||||
case 0x19: // XPAND
|
||||
xpand = val;
|
||||
|
@ -389,7 +392,7 @@ const _BallyAstrocadePlatform = function(mainElement, arcade) {
|
|||
// interrupt
|
||||
if (sl == inlin && (inmod & 0x8)) {
|
||||
cpu.retryInterrupts = !(inmod & 0x4);
|
||||
cpu.requestInterrupt(infbk);
|
||||
cpu.interrupt(infbk);
|
||||
}
|
||||
// refresh this line in frame buffer?
|
||||
if (sl < sheight && refreshlines>0) {
|
||||
|
@ -495,7 +498,6 @@ const _BallyAstrocadePlatform = function(mainElement, arcade) {
|
|||
}
|
||||
reset() {
|
||||
cpu.reset();
|
||||
cpu.setTstates(0);
|
||||
psg.reset();
|
||||
// TODO?
|
||||
magicop = xpand = inmod = inlin = infbk = shift2 = horcb = 0;
|
||||
|
|
|
@ -336,7 +336,7 @@ const _GalaxianPlatform = function(mainElement, options) {
|
|||
this.reset();
|
||||
}
|
||||
// NMI interrupt @ 0x66
|
||||
if (interruptEnabled) { cpu.nonMaskableInterrupt(); }
|
||||
if (interruptEnabled) { cpu.NMI(); }
|
||||
}
|
||||
|
||||
getRasterScanline() { return this.scanline; }
|
||||
|
@ -412,8 +412,6 @@ const _GalaxianPlatform = function(mainElement, options) {
|
|||
}
|
||||
reset() {
|
||||
cpu.reset();
|
||||
//audio.reset();
|
||||
if (!this.getDebugCallback()) cpu.setTstates(0); // TODO?
|
||||
watchdog_counter = INITIAL_WATCHDOG;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ var WilliamsSoundPlatform = function(mainElement) {
|
|||
var dac = 0;
|
||||
var dac_float = 0.0
|
||||
var current_buffer;
|
||||
var last_tstate;
|
||||
var last_tstate = 0;
|
||||
var tstates = 0;
|
||||
var pixels;
|
||||
|
||||
var cpuFrequency = 18432000 / 6; // 3.072 MHz
|
||||
|
@ -52,7 +53,7 @@ var WilliamsSoundPlatform = function(mainElement) {
|
|||
var cpuAudioFactor = 32;
|
||||
|
||||
function fillBuffer() {
|
||||
var t = cpu.getTstates() / cpuAudioFactor;
|
||||
var t = tstates / cpuAudioFactor;
|
||||
while (last_tstate < t) {
|
||||
current_buffer[last_tstate++] = dac_float;
|
||||
}
|
||||
|
@ -88,11 +89,12 @@ var WilliamsSoundPlatform = function(mainElement) {
|
|||
audio = new SampleAudio(cpuFrequency / cpuAudioFactor);
|
||||
audio.callback = function(lbuf) {
|
||||
if (self.isRunning()) {
|
||||
cpu.setTstates(0);
|
||||
current_buffer = lbuf;
|
||||
last_tstate = 0;
|
||||
self.runCPU(cpu, lbuf.length * cpuAudioFactor);
|
||||
cpu.setTstates(lbuf.length * cpuAudioFactor); // TODO?
|
||||
tstates = 0;
|
||||
while (tstates < lbuf.length * cpuAudioFactor) {
|
||||
tstates += self.runCPU(cpu, 1);
|
||||
}
|
||||
fillBuffer();
|
||||
for (var i = 0; i < 256; i++) {
|
||||
var y = Math.round((current_buffer[i] * 127) + 128);
|
||||
|
@ -150,7 +152,6 @@ var WilliamsSoundPlatform = function(mainElement) {
|
|||
}
|
||||
this.reset = function() {
|
||||
cpu.reset();
|
||||
if (!this.getDebugCallback()) cpu.setTstates(0); // TODO?
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -389,7 +389,7 @@ var Z80ColorVectorPlatform = function(mainElement, proto) {
|
|||
|
||||
};
|
||||
this.readAddress = bus.read;
|
||||
cpu = this.newCPU(bus);
|
||||
cpu = this.newCPU(bus, bus);
|
||||
// create video/audio
|
||||
video = new VectorVideo(mainElement,1024,1024);
|
||||
dvg = new DVGColorStateMachine(bus, video, 0xa000);
|
||||
|
@ -402,7 +402,7 @@ var Z80ColorVectorPlatform = function(mainElement, proto) {
|
|||
this.advance = (novideo) => {
|
||||
if (!novideo) video.clear();
|
||||
this.runCPU(cpu, cpuCyclesPerFrame);
|
||||
cpu.requestInterrupt();
|
||||
cpu.interrupt(0xff); // RST 0x38
|
||||
switches[0xf] = (switches[0xf] + 1) & 0x3;
|
||||
if (--switches[0xe] <= 0) {
|
||||
console.log("WATCHDOG FIRED"); // TODO: alert on video
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
import { Platform, BaseZ80Platform, Base6809Platform } from "../baseplatform";
|
||||
import { PLATFORMS, RAM, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap } from "../emu";
|
||||
|
@ -189,7 +188,7 @@ var WilliamsPlatform = function(mainElement, proto) {
|
|||
blitregs[a] = v;
|
||||
} else {
|
||||
var cycles = doBlit(v);
|
||||
cpu.setTstates(cpu.getTstates() + cycles * cpuScale);
|
||||
this.waitCycles -= cycles * cpuScale; // wait CPU cycles
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ describe('Platform Replay', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
it('Should run williams 6809', () => {
|
||||
var platform = testPlatform('williams', 'vidfill.asm.rom', 72, (platform, frameno) => {
|
||||
if (frameno == 62) {
|
||||
|
@ -249,6 +249,7 @@ describe('Platform Replay', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
*/
|
||||
it('Should run williams-z80', () => {
|
||||
var platform = testPlatform('williams-z80', 'game1.c.rom', 72, (platform, frameno) => {
|
||||
if (frameno == 62) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user