-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagnostics.cpp
More file actions
328 lines (276 loc) · 7.51 KB
/
Copy pathDiagnostics.cpp
File metadata and controls
328 lines (276 loc) · 7.51 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
// Diagnostics.cpp : implementation file
//
#include "stdafx.h"
#include "derby1.h"
#include "Diagnostics.h"
#include <conio.h>
#define HIGH_BASE_ADDRESS 0x03BC // printer port base address
#define HIGH_DATA_REGISTER (HIGH_BASE_ADDRESS+0) // address of data register
#define HIGH_STATUS_REGISTER (HIGH_BASE_ADDRESS+1) // address of status register
#define HIGH_CONTROL_REGISTER (HIGH_BASE_ADDRESS+2) // address of control register
#define MID_BASE_ADDRESS 0x0378 // printer port base address
#define MID_DATA_REGISTER (MID_BASE_ADDRESS+0) // address of data register
#define MID_STATUS_REGISTER (MID_BASE_ADDRESS+1) // address of status register
#define MID_CONTROL_REGISTER (MID_BASE_ADDRESS+2) // address of control register
#define LOW_BASE_ADDRESS 0x0278 // printer port base address
#define LOW_DATA_REGISTER (LOW_BASE_ADDRESS+0) // address of data register
#define LOW_STATUS_REGISTER (LOW_BASE_ADDRESS+1) // address of status register
#define LOW_CONTROL_REGISTER (LOW_BASE_ADDRESS+2) // address of control register
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
static unsigned char stat_reg;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDiagnostics dialog
CDiagnostics::CDiagnostics(CWnd* pParent /*=NULL*/)
: CDialog(CDiagnostics::IDD, pParent)
{
//{{AFX_DATA_INIT(CDiagnostics)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDiagnostics::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDiagnostics)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDiagnostics, CDialog)
//{{AFX_MSG_MAP(CDiagnostics)
ON_BN_CLICKED(IDC_DIAG_START, OnDiagStart)
ON_BN_CLICKED(IDC_DIAG_STOP, OnDiagStop)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#if 0
int CDiagnostics::OnInitialUpdate()
{
return (0);
}
#endif
/////////////////////////////////////////////////////////////////////////////
// CDiagnostics message handlers
void CDiagnostics::OnDiagStart()
{
// UINT id = this->SetTimer(DIAG_UPDATE_TIMER_ID, 5, (TIMERPROC)DiagTimerProc);
// UINT id = this->SetTimer(DIAG_UPDATE_TIMER_ID, 5, NULL);
char result = (char) 0xff;
char buff[10];
MSG msg;
bool bypass = false;
CString sPortName;
CDerby1App* theApp = (CDerby1App*)AfxGetApp ();
// set status register
sPortName = theApp->GetPort ();
if (sPortName == "LPT1")
stat_reg = (unsigned char)HIGH_STATUS_REGISTER;
if (sPortName == "LPT2")
stat_reg = (unsigned char)MID_STATUS_REGISTER;
if (sPortName == "LPT3")
stat_reg = (unsigned char)LOW_STATUS_REGISTER;
if (theApp != NULL)
{
pulsecount1 = 0;
pulsecount2 = 0;
pulsecount3 = 0;
pulsecount4 = 0;
pulsecount5 = 0;
m_DiagOn = true;
bypass = theApp->m_BypassSwitch;
result = 0;
do
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if ((msg.message == WM_QUIT) || (msg.message == WM_KEYDOWN) || (!m_DiagOn))
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
if (!bypass)
// result = (_inp (STATUS_REGISTER) & 0xf8);
result = (Inp32 (stat_reg) & 0xf8); //NT, XP, Win2K compatibility
if (!(result & 0x08)) // pin 15 (Error)
{
pulsecount1++;
sprintf (buff, "%d", pulsecount1);
SetDlgItemText (IDC_GATE_STAT, "1");
SetDlgItemText (IDC_GATE_PC, buff);
}
else
{
SetDlgItemText (IDC_GATE_STAT, "0");
pulsecount1 = 0;
}
if (!(result & 0x10)) // pin 13 (Selected)
{
pulsecount2++;
sprintf (buff, "%d", pulsecount2);
SetDlgItemText (IDC_1_STAT, "1");
SetDlgItemText (IDC_1_PC, buff);
}
else
{
SetDlgItemText (IDC_1_STAT, "0");
pulsecount2 = 0;
}
if (!(result & 0x20)) // pin 12 (No Paper)
{
pulsecount3++;
sprintf (buff, "%d", pulsecount3);
SetDlgItemText (IDC_2_STAT, "1");
SetDlgItemText (IDC_2_PC, buff);
}
else
{
SetDlgItemText (IDC_2_STAT, "0");
pulsecount3 = 0;
}
if ((result & 0x80)) // pin 11 (Busy) <--- this pin inverted
{
pulsecount4++;
sprintf (buff, "%d", pulsecount4);
SetDlgItemText (IDC_3_STAT, "1");
SetDlgItemText (IDC_3_PC, buff);
}
else
{
SetDlgItemText (IDC_3_STAT, "0");
pulsecount4 = 0;
}
if (!(result & 0x40)) // pin 10 (Ack)
{
pulsecount5++;
sprintf (buff, "%d", pulsecount5);
SetDlgItemText (IDC_4_STAT, "1");
SetDlgItemText (IDC_4_PC, buff);
}
else
{
SetDlgItemText (IDC_4_STAT, "0");
pulsecount5 = 0;
}
}
}
while (true);
}
}
void CDiagnostics::OnDiagStop()
{
// char buff[10];
// this->KillTimer (DIAG_UPDATE_TIMER_ID);
// sprintf (buff, " - ");
// SetDlgItemText (IDC_GATE_STAT, buff);
m_DiagOn = false;
}
void CDiagnostics::DiagTimerProc (HWND hwnd, UINT msg, UINT id, DWORD curtime)
{
}
void CDiagnostics::OnTimer(UINT nIDEvent)
{
char result = (char) 0xff;
char buff[10];
// result = (_inp (STATUS_REGISTER) & 0xf8);
result = (Inp32 (stat_reg) & 0xf8); //NT, XP, Win2K compatibility
sprintf (buff, "%d", result);
SetDlgItemText (IDC_GATE_STAT, buff);
if (!(result & 0x08)) // Lane 1 - pin 15 (Error)
{
pulsecount1++;
sprintf (buff, "%d", pulsecount1);
SetDlgItemText (IDC_1_STAT, "1");
SetDlgItemText (IDC_1_PC, buff);
}
else
{
SetDlgItemText (IDC_1_STAT, "0");
pulsecount1 = 0;
}
if (!(result & 0x10)) // Lane 2 - pin 13 (Selected)
{
pulsecount2++;
sprintf (buff, "%d", pulsecount2);
SetDlgItemText (IDC_2_STAT, "1");
SetDlgItemText (IDC_2_PC, buff);
}
else
{
SetDlgItemText (IDC_2_STAT, "0");
pulsecount2 = 0;
}
if (!(result & 0x20)) // Lane 3 - pin 12 (No Paper)
{
pulsecount3++;
sprintf (buff, "%d", pulsecount3);
SetDlgItemText (IDC_3_STAT, "1");
SetDlgItemText (IDC_3_PC, buff);
}
else
{
SetDlgItemText (IDC_3_STAT, "0");
pulsecount3 = 0;
}
if (!(result & 0x40)) // Lane 4 - pin 10 (Ack)
{
pulsecount4++;
sprintf (buff, "%d", pulsecount4);
SetDlgItemText (IDC_4_STAT, "1");
SetDlgItemText (IDC_4_PC, buff);
}
else
{
SetDlgItemText (IDC_4_STAT, "0");
pulsecount4 = 0;
}
}
BOOL CDiagnostics::OnInitDialog()
{
CDialog::OnInitDialog();
CDerby1App* theApp = (CDerby1App*)AfxGetApp ();
if (theApp != NULL)
{
CWnd* pWin = NULL;
pWin = GetDlgItem (IDC_P10_LABEL);
if (pWin)
pWin->SetWindowText (theApp->GetPin10());
pWin = GetDlgItem (IDC_P11_LABEL);
if (pWin)
pWin->SetWindowText (theApp->GetPin11());
pWin = GetDlgItem (IDC_P12_LABEL);
if (pWin)
pWin->SetWindowText (theApp->GetPin12());
pWin = GetDlgItem (IDC_P13_LABEL);
if (pWin)
pWin->SetWindowText (theApp->GetPin13());
pWin = GetDlgItem (IDC_P15_LABEL);
if (pWin)
pWin->SetWindowText (theApp->GetPin15());
pWin = GetDlgItem (IDC_PORT_STRING);
if (pWin)
pWin->SetWindowText (theApp->GetPort());
pWin = GetDlgItem (IDC_PORT_ADDRESS);
if (pWin)
{
/*
* LPT1 = 0x0378 or 0x03BC
* LPT2 = 0x0278 or 0x0378
* LPT3 = 0x0278
*/
if (theApp->GetPort () == "LPT1")
pWin->SetWindowText ("0x03BC");
if (theApp->GetPort () == "LPT2")
pWin->SetWindowText ("0x0378");
if (theApp->GetPort () == "LPT3")
pWin->SetWindowText ("0x0278");
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}