-
Notifications
You must be signed in to change notification settings - Fork 3
/
trace.cpp
146 lines (123 loc) · 3.84 KB
/
trace.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//==============================================================================
// _____ __ __ __ ____ ____ ___ _ __
// | ____| \/ | / /_| ___| / ___( _ )/ |/ /_
// | _| | |\/| |_____| '_ \___ \| | / _ \| | '_ \
// | |___| | | |_____| (_) |__) | |__| (_) | | (_) |
// |_____|_|__|_|___ __\___/____/ \____\___/|_|\___/
// | ____/ ___|| _ \___ /___ \
// | _| \___ \| |_) ||_ \ __) |
// | |___ ___) | __/___) / __/
// |_____|____/|_| |____/_____|
//
//------------------------------------------------------------------------------
// Copyright (C),2019 Andrew John Jacobs
// All rights reserved.
//
// This work is made available under the terms of the Creative Commons
// Attribution-NonCommercial-ShareAlike 4.0 International license. Open the
// following URL to see the details.
//
// http://creativecommons.org/licenses/by-nc-sa/4.0/
//------------------------------------------------------------------------------
// Notes:
//
//==============================================================================
#include <Arduino.h>
#pragma GCC optimize ("-O3")
#include "Emulator.h"
//==============================================================================
bool Trace::enabled = false;
const char *Trace::toHex(uint32_t value, uint16_t digits)
{
static char buffer[32];
char *pBuffer = &(buffer[32]);
*--pBuffer = '\0';
while (digits--) {
*--pBuffer = "0123456789abcdef"[value & 0x0f];
value >>= 4;
}
return (pBuffer);
}
void Trace::start(void)
{
if (enabled) {
cout << toHex(pbr.b, 2) << ':';
cout << toHex(pc.w, 4) << ' ';
cout << toHex(Memory::getByte(pbr.a | pc.w), 2) << ' ';
}
}
void Trace::bytes(uint16_t count)
{
if (enabled) {
cout << ((count >= 1) ? toHex(Memory::getByte(pbr.a | (pc.w + 0)), 2) : " ") << ' ';
cout << ((count >= 2) ? toHex(Memory::getByte(pbr.a | (pc.w + 1)), 2) : " ") << ' ';
cout << ((count >= 3) ? toHex(Memory::getByte(pbr.a | (pc.w + 2)), 2) : " ") << ' ';
}
}
void Trace::trace(const char *pOpcode, uint32_t eal, uint32_t eah)
{
if (enabled) {
cout << pOpcode << " {";
cout << toHex(eal >> 16, 2) << ':';
cout << toHex(eal, 4) << ',';
cout << toHex(eah >> 16, 2) << ':';
cout << toHex(eah, 4) << "} ";
cout << "E=" << (e ? '1' : '0') << ' ';
cout << "P="
<< (p.n ? 'N' : '.')
<< (p.v ? 'V' : '.')
<< (p.m ? 'M' : '.')
<< (p.x ? 'X' : '.')
<< (p.d ? 'D' : '.')
<< (p.i ? 'I' : '.')
<< (p.z ? 'Z' : '.')
<< (p.c ? 'C' : '.') << ' ';
cout << "C=";
if (e || p.m) {
cout << toHex(c.h, 2) << '[';
cout << toHex(c.l, 2) << "] ";
}
else
cout << '[' << toHex(c.w, 4) << "] ";
cout << "X=";
if (e || p.x) {
cout << toHex(x.h, 2) << '[';
cout << toHex(x.l, 2) << "] ";
}
else
cout << '[' << toHex(x.w, 4) << "] ";
cout << "Y=";
if (e || p.x) {
cout << toHex(y.h, 2) << '[';
cout << toHex(y.l, 2) << "] ";
}
else
cout << '[' << toHex(y.w, 4) << "] ";
cout << "DP=" << toHex(dp.w, 4) << ' ';
cout << "SP=";
if (e) {
cout << toHex(sp.h, 2) << '[';
cout << toHex(sp.l, 2) << "] {";
Word xp;
xp.w = sp.w;
++xp.l; cout << toHex(Memory::getByte(xp.w), 2) << ' ';
++xp.l; cout << toHex(Memory::getByte(xp.w), 2) << ' ';
++xp.l; cout << toHex(Memory::getByte(xp.w), 2) << ' ';
++xp.l; cout << toHex(Memory::getByte(xp.w), 2) << "} ";
}
else {
cout << '[' << toHex(sp.w, 4) << "] {";
cout << toHex(Memory::getByte(sp.w + 1), 2) << ' ';
cout << toHex(Memory::getByte(sp.w + 2), 2) << ' ';
cout << toHex(Memory::getByte(sp.w + 3), 2) << ' ';
cout << toHex(Memory::getByte(sp.w + 4), 2) << "} ";
}
cout << "DBR=" << toHex(dbr.b, 2) << ' ';
}
}
void Trace::cycles(uint16_t cycles)
{
if (enabled) {
cout << "CY=" << cycles << endl;
}
}