-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserial.h
More file actions
137 lines (127 loc) · 3.15 KB
/
Copy pathserial.h
File metadata and controls
137 lines (127 loc) · 3.15 KB
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
#ifndef _SERIAL_H
#define _SERIAL_H
#include <stdio.h>
#define LOG_SERIAL 0
class CSerial {
protected:
CSerial *PrevDevice;
CSerial *NextDevice;
char Name[16];
unsigned int DeviceNr;
static unsigned int NrOfDevicesAttached;
static CSerial *RootDevice;
static CSerial *LastDevice;
public:
CSerial();
virtual ~CSerial();
CSerial(unsigned int DevNr);
CSerial *getNext() { return NextDevice; };
unsigned int getDeviceNumber() { return DeviceNr; };
//
virtual void update() {};
virtual void UpdateSerialState(unsigned char ) { };
virtual unsigned char readBusWithUpdate() {
return readBus();
}
// State of IEC lines (bit 7 - DATA, bit 6 - CLK, bit 4 - ATN)
static unsigned char serialPort[16];
static void InitPorts();
static unsigned char readBus();
static class CSerial *Devices[16];
static CSerial *getRoot() { return RootDevice; };
//
friend class TED;
};
inline unsigned char CSerial::readBus()
{
// catch up with all devices to see their state
CSerial *sDevPtr = CSerial::getRoot();
while (sDevPtr) {
sDevPtr->update();
sDevPtr = sDevPtr->getNext();
}
// the bus is using open-collectors so do an AND with all devices attached
#if LOG_SERIAL
{
static unsigned char prev = 0xFF;
unsigned char retval =
serialPort[0]
&serialPort[4]&serialPort[5] // printers
&serialPort[8]&serialPort[9]&serialPort[10]&serialPort[11];
if (retval ^ prev) {
fprintf(stderr, "Serial read: %02X\n", retval);
prev = retval;
}
return retval;
}
#else
unsigned char retVal = serialPort[0]
&serialPort[4]&serialPort[5] // printers
&serialPort[8]&serialPort[9]&serialPort[10]&serialPort[11]; // drives
return retVal;
#endif
}
class CTrueSerial : public CSerial {
public:
CTrueSerial(unsigned int DevNr) : CSerial(DevNr) { };
};
class IEC;
class CIECDevice;
class IecFakeSerial : public CSerial
{
public:
IecFakeSerial(unsigned int DevNr, CIECDevice *iecDev);
virtual ~IecFakeSerial() {};
virtual void UpdateSerialState() {
update();
};
virtual void UpdateSerialState(unsigned char newAtn) {
update();
writeBus(newAtn);
};
virtual unsigned char readBusWithUpdate() {
#if 0
update();
return serialPort[dev_nr];
#else
return readBus();
#endif
}
virtual unsigned char readBusWithoutUpdate() {
return serialPort[0]
& serialPort[4]
& serialPort[8] & serialPort[9] & serialPort[10] & serialPort[11];
}
void writeBus(unsigned char newLines);
inline void updateBus() {
serialPort[dev_nr] = dataLine | clkLine;
}
virtual void update();
private:
IecFakeSerial();
protected:
void interpretIecByte();
CIECDevice *iecDevice;
unsigned int state;
unsigned int step;
unsigned int addr;
unsigned int secondaryAddress;
unsigned int secondaryAddress_prev;
unsigned char dev_nr;
size_t timeout;
size_t cycleCount;
unsigned char errorState;
unsigned int eoi;
unsigned int clkLine;
unsigned int dataLine;
unsigned char io_byte;
unsigned int bitCounter;
unsigned int dataTransfered;
unsigned char atnInLine;
unsigned char oldAtnLine;
//
char nameBuffer[16]; // Buffer for file names and command strings
char *namePtr; // Pointer for reception of file name
int nameLength; // Received length of file name
};
#endif // _SERIAL_H