Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
shicks committed Jan 10, 2016
1 parent d92f6cb commit a9a489b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
20 changes: 14 additions & 6 deletions cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default class Cpu {

this.opcodes_ = instructionTable();
this.message = '';


var logdiv = document.getElementById('log');
this.log = logdiv ? msg => logdiv.textContent += msg + '\n' : msg => console.log(msg);
this.log = () => {};
}

init() {
Expand All @@ -61,9 +66,9 @@ export default class Cpu {
try {
this.opcode.op.call(this);
} finally {
if (window.msg) {
console.log(this.message);
window.msg = false; }
//if (window.msg) {
this.log(this.message);
//window.msg = false; }
}

if (!this.opcode.extraCycles) this.wait = 0;
Expand All @@ -79,6 +84,9 @@ export default class Cpu {
for (let i = this.opcode.mode.bytes; i > 0; i--) {
this.operand |= this.mem_.get(++this.PC) << ((shift += 8) - 8);
}
if (this.opcode.mode.signed && this.operand > 0x7F) {
this.operand -= 0x100;
}
this.wait += this.opcode.cycles;
const lastPc = hex(this.PC - this.opcode.mode.bytes, 2);
this.message = `${lastPc}: ${this.opcode.format(this.operand)}`;
Expand Down Expand Up @@ -451,15 +459,15 @@ class AddressingMode {
this.bytes = /\$\$/.test(fmt) ? 2 : /\$/.test(fmt) ? 1 : 0;
/** @const {function(!Cpu): ?number} */
this.func = func;

const signed = /\+\$/.test(fmt);
/** @const {boolean} */
this.signed = /\+\$/.test(fmt);
const before = fmt.replace(/\+?\$\$?.*/, '');
const after = fmt.replace(/.*\+?\$\$?/, '');
this.format =
!this.bytes ?
arg => fmt :
arg => {
return `${before}${hex(arg, this.bytes, signed)}${after}`
return `${before}${hex(arg, this.bytes, this.signed)}${after}`
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

<input type="submit" id="stop" value="stop" style="display:none;">
<input type="submit" id="next" value="next" style="display:none;">

<div id="log" style="white-space: pre; font-family: monospace;"></div>
2 changes: 2 additions & 0 deletions nsf.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export default class Nsf {
cpu.pushWord(0xffff); // special signal that we're done...
cpu.pushWord(this.playAddress_ - 1);
cpu.PC = this.initAddress_ - 1;
mem.set(0x4015, 0xf);
mem.set(0x4017, 0x40);
cpu.A = song != null ? song : this.startSong_;
// really, we need the clock... this is getting horribly tangled!
cpu.X = this.palNtsc_ != 'pal' ? 0 : 1; // default to NTSC
Expand Down
9 changes: 7 additions & 2 deletions nsfplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export default class NsfPlayer {
}

play(promise) {

// TODO - add a check - store assembler logs for first ten (60?)
// frames - if volume is never non-zero after these frames,
// dump the whole log...?

if (this.promise != promise) return;
for (let frameCycle = this.cyclesPerFrame; frameCycle >= 0; frameCycle--) {
if (frameCycle != frameCycle) throw new Error('NaN');
Expand Down Expand Up @@ -65,12 +70,12 @@ function readLocalFiles() {

function startEmu(buf) {
const nsf = new Nsf(buf);
console.log(nsf + '');
new Cpu(new Memory()).log(nsf + '');
const ac = new AudioContext();
const player = new NsfPlayer(ac, nsf);
window.PLAYER = player;

let track = 1;
let track = 2;

player.start(track);

Expand Down

0 comments on commit a9a489b

Please sign in to comment.