-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinilin.c
205 lines (197 loc) · 6.24 KB
/
inilin.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
void inilin()
{
/*
this subroutine initializes the com port defined by
global cmport (0=com1, 1=com2, ... etc).
the initialization parameters are set using param
if BIOS is not defined, do not use bios calls but access the
hardware directly. this is done by determining the hardware
address of the comport by looking in low core locations.
*/
#include <stdio.h>
#include "nistime.h"
#ifdef IBMPC
#include <dos.h>
char param;
#endif
extern int cmport; /* which comport to use ? */
extern int hs; /* which speed to use ? */
extern int debug; /* debug is on if = 1 */
#ifdef IBMPC
void wait(); /*wait for DSR to come true */
extern int lpadr; /* address of line printer -- determined here */
#ifndef BIOS
extern int cmadr; /* hardware address of comport -- determined here*/
#endif
extern int lpt; /* pulse line printer? 1=yes, 0= no */
#endif
extern char number[]; /* which number to dial, first char = mode*/
int j;
#ifdef SUN
#include <sgtty.h>
struct sgttyb blah,*arg; /* parameters used for ioctl calls */
arg= &blah; /* blah is structure */
if(hs == 1)
{
arg->sg_ispeed=B1200;
arg->sg_ospeed=B1200;
}
else
{
arg->sg_ispeed=B300;
arg->sg_ospeed=B300;
}
arg->sg_erase='\177';
arg->sg_kill='\025';
arg->sg_flags=RAW;
j=ioctl(cmport,TIOCSETP,arg);
if(j != 0) printf("\n Watch out! ioctl status=%d",j);
#endif
#ifdef IBMPC
unsigned char stat;
#endif
/*
operation of the IBMPC version:
if this is the direct access version of the program, then the
hardware address of the comport must be either specified in the
configuration file or determined by looking in low memory. if
it was specified in the configuration file, then cmport was set
to -1 there and cmadr was read from line 6. in that case we
don't have to do anything here. if cmadr is positive, then
the value must be determined here by looking at the table starting
at address 400 (hex).
following variables and code are used to look in low memory
to get the address of the comport requested in the config. file
if the address in low memory is zero, then exit with an error.
since the line printer addresses are stored just after the tty
port addresses, these variables are also used for getting the
hardware address of lpt1 (see below)
operation of the SUN version:
the port was opened in setcfg and this subroutine sets the
speed and other parameters based on values in the config.
file.
*/
#ifdef IBMPC
unsigned int ttyseg = 0x40;
unsigned int ttyoff = 0;
int far *cmptr;
#ifndef BIOS
/*
first get hardware address of requested comport if necessary
these address are stored starting at 400. if cmport is -1,
then the address was already gotten by setcfg from the configuration
file and we don't have to do that here.
*/
if(cmport >= 0)
{
ttyoff=2*cmport;
cmptr=MK_FP(ttyseg,ttyoff);
cmadr=*cmptr;
if(cmadr == 0)
{
printf("\n Port COM%d not present in configuration.",cmport+1
);
exit();
}
}
/*
disable interrupts, turn on DTR and RTS, then
set 8 bits, no parity, 1 stop bit, Div. Latch Acc Bits on
*/
param=0;
outportb(cmadr+intena,param);
param=3;
outportb(cmadr+modreg,param);
param='\x83';
outportb(cmadr+lcreg,param);
/*
now set requested speed using two halves of divisor
from tables in interface manual
*/
if(hs == 1)
{
param=96;
outportb(cmadr+divlsb,param);
param=0;
outportb(cmadr+divmsb,param);
}
else
{
param='\x80';
outportb(cmadr+divlsb,param);
param=1;
outportb(cmadr+divmsb,param);
}
/*
now turn off divisor latch access bits
*/
param=3;
outportb(cmadr+lcreg,param);
wait();
wait();
wait(); /*wait for ROLM system to wake up*/
/*
get modem status
*/
stat=inportb(cmadr+msreg);
#endif
#ifdef BIOS
/*
if we get here then we are going to do the same stuff using
BIOS calls. the parameters are:
300 baud no parity 1 stop bit 8 bits
0 1 0 0 0 0 1 1
1200 baud no parity 1 stop bit 8 bits
1 0 0 0 0 0 1 1
9600 baud no parity 1 stop bit 8 bits
1 1 1 0 0 0 1 1
*/
if(hs == 1)param='\x83';
else param='\x43';
_AL=param;
_AH=0;
_DX=cmport;
geninterrupt(0x14);
stat=_AL; /* return with modem status */
#endif
/*
if this is automatic dialing using either manual or pulse mode
then be sure that the modem is ready to go. check DSR
*/
if( (number[3] == 't') || (number[3] == 'T') ||
(number[3] == 'p') || (number[3] == 'P') )
{
if( (stat & 0x20) == 0)
{
printf("\nWarning! modem does not ");
printf("show data set ready (DSR).");
}
}
/*
now set line printer address if lpt is set to pulse it. if
lpt is zero so that pulsing is disabled, then return now.
get lpt1 address by looking in low core at address 408
*/
if(lpt == 0) return;
ttyoff=8;
cmptr=MK_FP(ttyseg,ttyoff);
lpadr=*cmptr;
if(lpadr == 0)
{
printf("\n printer-port not installed in system.");
printf("\n pulsing selection disabled.");
lpt=0;
return;
}
outportb(lpadr,1);
for(j=0; j<200; j++); /*wait a bit*/
if( (inportb(lpadr) & 0x1f) == 1)
{
outportb(lpadr,0);
return;
}
printf("\n printer-port does not respond to pulse.");
printf("\n pulsing selection will be disabled.");
lpt=0;
#endif
}