-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIoCardPrinter.cpp
157 lines (119 loc) · 2.73 KB
/
IoCardPrinter.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
147
148
149
150
151
152
153
154
155
156
157
// Emulate a printer device. Most of the work is done in the GUI side.
#include "Cpu2200.h"
#include "IoCardPrinter.h"
#include "Ui.h"
#include "system2200.h"
#define NOISY 0 // turn on some debugging messages
#ifdef _MSC_VER
#pragma warning( disable: 4127 ) // conditional expression is constant
#endif
IoCardPrinter::IoCardPrinter(std::shared_ptr<Cpu2200> cpu,
int base_addr, int card_slot) :
m_cpu(cpu),
m_base_addr(base_addr),
m_slot(card_slot)
{
if (m_slot >= 0) {
int io_addr;
const bool ok = system2200::getSlotInfo(card_slot, nullptr, &io_addr);
assert(ok);
m_wndhnd = UI_printerInit(io_addr);
reset(true);
}
}
// instance destructor
IoCardPrinter::~IoCardPrinter()
{
if (m_slot >= 0) {
reset(true); // turns off handshakes in progress
UI_printerDestroy(getGuiPtr());
}
}
std::string
IoCardPrinter::getDescription() const
{
return "Printer Controller";
}
std::string
IoCardPrinter::getName() const
{
return "7079";
}
// return a list of the various base addresses a card can map to
// the default comes first.
std::vector<int>
IoCardPrinter::getBaseAddresses() const
{
std::vector<int> v { 0x215, 0x216 };
return v;
}
// return the list of addresses that this specific card responds to
std::vector<int>
IoCardPrinter::getAddresses() const
{
std::vector<int> v;
v.push_back(m_base_addr);
return v;
}
void
IoCardPrinter::reset(bool /*hard_reset*/) noexcept
{
// reset card state
m_selected = false;
m_cpb = true; // CPU busy
}
void
IoCardPrinter::select()
{
if (NOISY) {
UI_info("printer ABS");
}
m_selected = true;
m_cpu->setDevRdy(true);
}
void
IoCardPrinter::deselect()
{
if (NOISY) {
UI_info("printer -ABS");
}
m_cpu->setDevRdy(false);
// ...
m_selected = false;
m_cpb = true;
}
void
IoCardPrinter::strobeOBS(int val)
{
const uint8 val8 = val & 0xFF;
if (NOISY) {
UI_info("printer OBS: Output of byte 0x%02x", val8);
}
UI_printerChar(getGuiPtr(), val8);
m_cpu->setDevRdy(true);
}
void
IoCardPrinter::strobeCBS(int val)
{
strobeOBS(val);
}
// change of CPU Busy state
void
IoCardPrinter::setCpuBusy(bool busy)
{
// it appears that except for reset, ucode only ever clears it,
// and of course the IBS sets it back.
if (NOISY) {
UI_info("printer CPB%c", busy ? '+' : '-');
}
m_cpb = busy;
// FIXME: return printer status (requires handshaking logic, though)
m_cpu->setDevRdy(true);
}
// ---- accessor of opaque gui pointer ----
PrinterFrame *
IoCardPrinter::getGuiPtr() const noexcept
{
return m_wndhnd.get();
}
// vim: ts=8:et:sw=4:smarttab