-
Notifications
You must be signed in to change notification settings - Fork 0
/
asmlog.cpp
103 lines (83 loc) · 2.87 KB
/
asmlog.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
/*
* This file is part of the 8080 distribution (https://github.com/temaweb/8080).
* Copyright (c) 2020 Artem Okonechnikov.
*
* 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, version 3.
*
* 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, see <https://www.gnu.org/licenses/>.
*/
#include <cstdint>
#include <iomanip>
#include <iostream>
#include "cpu.hpp"
#include "asmlog.hpp"
template<class T>
void Asmlog::print(int width, std::string prefix, T value)
{
std::cout << std::setfill(delimiter) << prefix
<< std::setfill(filler) << std::setw(width) << std::right << std::hex << unsigned(value);
}
void Asmlog::printDivider(int width)
{
std::cout << std::setfill(delimiter) << std::setw(width);
}
void Asmlog::log(uint16_t counter, const Cpu * cpu)
{
auto opcode = cpu -> opcode;
auto command = cpu -> commands[opcode];
std::cout << std::uppercase;
print(4, "0x", counter);
print(2, " ", opcode);
if (command.addrmod == &Cpu::DIR)
{
auto lo = cpu -> read(counter + 1);
auto hi = cpu -> read(counter + 2);
auto value = cpu -> read((hi << 8) | lo);
print(2, " ", lo);
print(2, " ", hi);
print(2, " $", value);
printDivider(6);
}
else if (command.addrmod == &Cpu::IMM)
{
auto value = cpu -> read(counter + 1);
print(2, " ", value);
printDivider(13);
}
else
{
printDivider(16);
}
std::cout << std::right << command.name;
print(2, " A:", cpu -> registers[cpu -> A]);
print(2, " B:", cpu -> registers[cpu -> B]);
print(2, " C:", cpu -> registers[cpu -> C]);
print(2, " D:", cpu -> registers[cpu -> D]);
print(2, " E:", cpu -> registers[cpu -> E]);
print(2, " H:", cpu -> registers[cpu -> H]);
print(2, " L:", cpu -> registers[cpu -> L]);
auto printReg = [&](uint8_t index)
{
auto address = cpu -> readpair(index);
auto value = cpu -> read(address);
print(2, " $", value);
};
printReg(cpu -> BC);
printReg(cpu -> DE);
printReg(cpu -> HL);
std::cout << " S=" << unsigned(cpu ->status.GetSign());
std::cout << " Z=" << unsigned(cpu ->status.GetZero());
std::cout << " AC=" << unsigned(cpu ->status.GetAux());
std::cout << " P=" << unsigned(cpu ->status.GetParity());
std::cout << " C=" << unsigned(cpu ->status.GetCarry());
print(4, " 0x", cpu -> stack);
std::cout << std::endl;
}