-
Notifications
You must be signed in to change notification settings - Fork 9
/
i8080_trace.js
72 lines (64 loc) · 2.15 KB
/
i8080_trace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Part of Intel 8080/KR580VM80A in JavaScript
//
// Copyright (C) 2012 Alexander Demin <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
const I8080_trace = function(i8080) {
const hex = function(n, pad) {
const pad_ = typeof (pad) === "undefined" || pad === null ? pad = 2 : pad;
let hex_ = Number(n).toString(16).toUpperCase();;
while (hex_.length < pad_) hex_ = "0" + hex_;
return hex_;
}
let r =
"PC=" + hex(i8080.pc, 4) + " " +
"[" + hex(i8080.memory_read_byte(i8080.pc)) + "] " +
"A=" + hex(i8080.a()) + " " +
"F=" + hex(i8080.store_flags()) +
" " +
(i8080.sf ? "S" : "-") +
(i8080.zf ? "Z" : "-") +
"0" +
(i8080.hf ? "H" : "-") +
"0" +
(i8080.pf ? "P" : "-") +
"1" +
(i8080.cf ? "C" : "-") +
"\n" +
"BC=" + hex(i8080.bc(), 4) + " " +
"DE=" + hex(i8080.de(), 4) + " " +
"HL=" + hex(i8080.hl(), 4) + " " +
"SP=" + hex(i8080.sp, 4) + " " +
"\n";
const code = [];
for (let i = 0; i < 3; ++i)
code[code.length] = i8080.memory.read(i8080.pc + i);
const instr = i8080_disasm(code);
r += hex(i8080.pc, 4) + " " + instr.text;
r += "\n";
const dump_mem = function(addr, title) {
let r = title + ": ";
for (let i = 0; i < 16; ++i)
r += hex(i8080.memory.read(addr + i)) + " ";
r += "\n";
return r;
}
r += dump_mem(i8080.pc, "PC");
r += dump_mem(i8080.sp, "SP");
r += dump_mem(i8080.hl(), "HL");
r += dump_mem(i8080.de(), "DE");
r += dump_mem(i8080.bc(), "BC");
return r;
}