1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-29 14:51:17 +00:00

ZilogZ80 class; fixed test

This commit is contained in:
Steven Hugg 2019-08-22 22:01:05 -04:00
parent 52783cffe7
commit 30db326f57
6 changed files with 1812 additions and 2 deletions

1747
src/cpu/ZilogZ80.ts Normal file

File diff suppressed because one or more lines are too long

View File

@ -68,6 +68,10 @@ export interface MemoryBusConnected {
connectMemoryBus(bus:Bus) : void; connectMemoryBus(bus:Bus) : void;
} }
export interface IOBusConnected {
connectIOBus(bus:Bus) : void;
}
export interface CPU extends MemoryBusConnected, Resettable { export interface CPU extends MemoryBusConnected, Resettable {
getPC() : number; getPC() : number;
getSP() : number; getSP() : number;

View File

@ -2,8 +2,8 @@
var assert = require('assert'); var assert = require('assert');
var fs = require('fs'); var fs = require('fs');
var emu = require("gen/nemu/nemu.js"); var emu = require("gen/devices.js");
var MOS6502 = require("gen/nemu/cpu/MOS6502.js"); var MOS6502 = require("gen/cpu/MOS6502.js");
var testbin = fs.readFileSync('test/cli/6502/6502_functional_test.bin', null); var testbin = fs.readFileSync('test/cli/6502/6502_functional_test.bin', null);
describe('MOS6502', function() { describe('MOS6502', function() {

View File

@ -0,0 +1,59 @@
var assert = require('assert');
var fs = require('fs');
var emu = require("gen/devices.js");
var ZilogZ80 = require("gen/cpu/ZilogZ80.js");
var testbin = fs.readFileSync('test/cli/z80/zexall.bin', null);
var runall = false;
describe('ZilogZ80', function() {
it('Should pass functional tests', function() {
assert.equal(8590, testbin.length);
var mem = new Uint8Array(65536);
mem.set(testbin, 0x100);
var bus = {
read: (a) => { return mem[a]; },
write: (a,v) => { mem[a] = v; }
};
var iobus = {
read: (a) => { return 0; },
write: (a,v) => { }
};
mem[0] = 0xC3;
mem[1] = 0x00;
mem[2] = 0x01; // JP 0x100 CP/M TPA
mem[5] = 0xC9; // Return from BDOS call
var cpu = new ZilogZ80.Z80();
cpu.connectMemoryBus(bus);
cpu.connectIOBus(bus);
cpu.reset();
let cycles = 0;
let finish = false;
var maxcyc = runall ? 10000000000 : 1000000;
for (var i=0; i<maxcyc; i++) {
cycles += cpu.advanceInsn(1);
var pc = cpu.getPC();
if (pc == 0x5) { // BDOS call
var regC = cpu.saveState().BC & 0xff;
console.log(cycles, pc, regC);
switch (regC) {
case 0: // reset
finish = true;
break;
case 9: // print
var regDE = cpu.saveState().DE;
var s = "";
while (mem[regDE] != 0x24/*'$'*/) {
s += String.fromCharCode(mem[regDE++] & 0x7f);
}
console.log(s);
break;
}
}
}
console.log("runall", runall);
assert.equal(finish, runall);
});
});

BIN
test/cli/z80/zexall.bin Normal file

Binary file not shown.

BIN
test/cli/z80/zexdoc.bin Normal file

Binary file not shown.