Use class fields instead of binding (#40)

* Use class fields instead of binding
* classy tests
* Fix typing
This commit is contained in:
Will Scullin 2020-11-07 08:54:49 -08:00 committed by GitHub
parent c4df78cf06
commit b3cb64357f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 588 additions and 618 deletions

View File

@ -56,7 +56,7 @@
} }
}, { }, {
"files": [ "js/entry2.js", "js/entry2e.js"], "files": [ "js/entry2.js", "js/entry2e.js", "jest.config.js"],
"env": { "env": {
"commonjs": true "commonjs": true
} }

View File

@ -1,13 +1,13 @@
module.exports = { module.exports = {
"roots": [ 'roots': [
"js/", 'js/',
"test/", 'test/',
], ],
"testMatch": [ 'testMatch': [
"**/?(*.)+(spec|test).+(ts|js)" '**/?(*.)+(spec|test).+(ts|js)'
], ],
"transform": { 'transform': {
"^.+\\.js$": "babel-jest", '^.+\\.js$': 'babel-jest',
"^.+\\.ts$": "ts-jest" '^.+\\.ts$': 'ts-jest'
}, },
} };

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
SYMBOLS = { const SYMBOLS = {
/* /*
0x00: 'GOWARM', 0x00: 'GOWARM',
0x03: 'GOSTROUT', 0x03: 'GOSTROUT',

View File

@ -9,7 +9,7 @@
* implied warranty. * implied warranty.
*/ */
/** /**
* Printer UI. The "paper" is bound to the element selected by the input. * Printer UI. The "paper" is bound to the element selected by the input.
* *
* Every line that is output to the printer is added as a <div> to the paper. * Every line that is output to the printer is added as a <div> to the paper.
@ -69,7 +69,7 @@ export default function Printer(el) {
clear: function() { clear: function() {
_lineBuffer = ''; _lineBuffer = '';
paper.innerHTML = ""; paper.innerHTML = '';
newLine(); newLine();
_raw = new Uint8Array(1024); _raw = new Uint8Array(1024);
_rawLen = 0; _rawLen = 0;

View File

@ -6,9 +6,9 @@ import Test65C02 from './roms/65C02test';
import { toHex } from '../js/util'; import { toHex } from '../js/util';
describe('CPU', function () { describe('CPU', function () {
var cpu; let cpu: CPU6502;
var lastPC = 0; let lastPC = 0;
var done = false; let done = false;
function traceCB() { function traceCB() {
var pc = cpu.getPC(); var pc = cpu.getPC();

View File

@ -1,23 +0,0 @@
// From https://github.com/Klaus2m5/6502_65C02_functional_tests
import fs from 'fs';
import path from 'path';
export default function Test6502() {
var data = fs.readFileSync(path.join(__dirname, '6502_functional_test.bin'));
return {
start: function() {
return 0x00;
},
end: function() {
return 0xff;
},
read: function(page, off) {
return data[page << 8 | off];
},
write: function(page, off, val) {
data[page << 8 | off] = val;
}
};
}

27
test/roms/6502test.ts Normal file
View File

@ -0,0 +1,27 @@
// From https://github.com/Klaus2m5/6502_65C02_functional_tests
import fs from 'fs';
import path from 'path';
import { PageHandler } from '../../js/cpu6502'
import { byte } from '../../js/types'
const data = fs.readFileSync(path.join(__dirname, '6502_functional_test.bin'));
export default class Test6502 implements PageHandler {
private data: Buffer
start = () => {
return 0x00;
}
end = () => {
return 0xff;
}
read = (page: byte, off: byte) => {
return data[page << 8 | off];
}
write = (page: byte, off: byte, val: byte) => {
data[page << 8 | off] = val;
}
}

View File

@ -1,23 +0,0 @@
// From https://github.com/Klaus2m5/6502_65C02_functional_tests
import fs from 'fs';
import path from 'path';
export default function Test65C02() {
var data = fs.readFileSync(path.join(__dirname, '65C02_extended_opcodes_test.bin'));
return {
start: function() {
return 0x00;
},
end: function() {
return 0xff;
},
read: function(page, off) {
return data[page << 8 | off];
},
write: function(page, off, val) {
data[page << 8 | off] = val;
}
};
}

31
test/roms/65C02test.ts Normal file
View File

@ -0,0 +1,31 @@
// From https://github.com/Klaus2m5/6502_65C02_functional_tests
import fs from 'fs';
import path from 'path';
import { PageHandler } from '../../js/cpu6502'
import { byte } from '../../js/types'
const data = fs.readFileSync(path.join(__dirname, '65C02_extended_opcodes_test.bin'));
export default class Test65C02 implements PageHandler {
private data: Buffer
constructor() {
}
start = function() {
return 0x00;
}
end = function() {
return 0xff;
}
read = function(page: byte, off: byte) {
return data[page << 8 | off];
}
write = function(page: byte, off: byte, val: byte) {
data[page << 8 | off] = val;
}
}