-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathepspdumper.c
187 lines (163 loc) · 4.55 KB
/
epspdumper.c
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
/*
* epspdumper.c version 1.3 part of the vfloppy 1.4 package
*
* Copyright 1996 Justin Mitchell (madmitch@discordia.org.uk) and friends.
*
* This version delivered in 2002 by Fred Jan Kraan (fjkraan@xs4all.nl)
*
* epspdumper is placed under the GNU General Public License in July 2002.
*
* This file is part of Vfloppy 1.5.
*
* Vfloppy 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; either version 2 of the License, or
* (at your option) any later version.
*
* Vfloppy 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 Vfloppy; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*
* epspdumper - passive epsp data viewer. To be used as monitor on the serial
* line between the PX-4 or PX-8 and the Terminal Disk Drive (TF-20, PF-10,
* epspdv3, ...) Currently no attempt is made to structure the data into
*
* meaningful information.
* epspd -s <port>
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include "epspv2.h"
#include "fdc.h"
int epsp_port;
int drive_fd[4];
int debug = 3;
int unit0 = 0;
int unit1 = 0;
int dataSize = 0;
char dataMsg[256];
char fntMode = 0; /* 0 = comp sending, 1 = vFloppy sending */
char myID, otherID; /* DID, SID data */
char fdcCmd;
char selectedUnit = 0x00;
/* Actually serial port read */
int blk_read(int fd, char *blk, int len)
{
int sofar = 0;
int syncup = 1;
while(sofar < len)
{
int got = read(fd, blk, 1);
if(got <= 0)
{
if(got < 0)
{
perror("epspd: read");
exit(1);
}
if(len == 0)
{
fprintf(stderr, "epspd: Lost connection.\n");
exit(1);
}
}
if (debug > 2) {
int i;
for (i = 0; i < got; i++)
printf("%02X ", (int)blk[i] & 0xFF);
}
fflush(stdout);
sofar += got;
blk += got;
syncup = 0;
}
if (debug > 2)
printf("\n");
return sofar;
}
void setSerial(char *s_device) {
struct termios t;
if ( s_device[0] != '\0' ) {
printf("\nSerial port %s specified", s_device);
epsp_port=open(s_device, O_RDWR);
if(epsp_port==-1)
{
printf("\n setSerial; Error opening serial port %s. Exiting...\n", s_device);
perror(s_device);
exit(2);
} else {
printf("\n setSerial; Serial port \'%s\' (fd: %d) opened succesfully.", s_device, epsp_port);
label[epsp_port] = s_device;
}
} else {
printf("\nNo serial port specified. Exiting...\n");
exit(1);
}
if(tcgetattr(epsp_port, &t)==-1) {
perror("tcgetattr");
printf("\n setSerial; Some error with the serial port\n");
exit(2);
}
cfsetispeed(&t, B38400);
cfsetospeed(&t, B38400);
t.c_iflag=t.c_iflag&~(ISTRIP|INLCR|ICRNL|IGNCR|IUCLC|IXON|IXANY|IXOFF);
t.c_oflag=t.c_oflag&~(OPOST);
t.c_cflag=t.c_cflag&~(CSIZE|PARENB);
t.c_cflag|=CS8;
t.c_lflag=t.c_lflag&~(ISIG|ICANON|ECHO);
t.c_cc[VTIME]=0;
t.c_cc[VMIN]=1;
if(tcsetattr(epsp_port, TCSANOW, &t)==-1) {
perror("tcsetattr");
exit(2);
}
}
int main(int argc, char *argv[]) {
char *s_device = "\0";
char ch;
char *optstr = "d:0:1:2:3:s:";
while( -1 != (ch=getopt(argc,argv,optstr))) {
switch(ch) {
case 's':
s_device = optarg;
printf("option: -s : %s\n", s_device);
break;
case 'd':
debug = atoi(optarg);
printf("option: -d : %d\n", debug);
break;
case '?':
printf("unrecognized option: %c\n",optopt);
break;
default:
printf("error? condition unaccounted for?\n");
break;
}
}
if (debug > 1) {
printf("\nEPSPD version 1.5 (2009-0m-dd)");
printf("\nDebug level: %d", debug);
}
setSerial(s_device);
/*
* Up.. time to go (Clunk, ..(wait), Clunk, Clunk)
*/
printf("\nEPSPD: Starting EPSP disk services on %s", s_device);
printf("\n");
while(1) {
blk_read(epsp_port, dataMsg, 256);
}
return(1);
}