source: buchla-68k/orig/IOLIB/RAWIO.C@ de91266

Last change on this file since de91266 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 5.5 KB
Line 
1/*
2 ============================================================================
3 rawio.c -- Some raw serial I/O routines for ROMP, et al
4 Version 5 -- 1987-06-11 -- D.N. Lynx Crowe
5
6 Defines: getln(), getrln(), readln(), writeln()
7
8 All of the following use raw BIOS calls to do their I/O.
9
10 int
11 getln(unit,nb,buf)
12 int unit; logical unit number 1..4
13 int nb; buffer limit
14 char *buf; buffer pointer
15
16 Reads a line from unit into buf, with a limit of nb
17 bytes. Does standard input editing (BS. DEL, ^X). Returns
18 on CR, LF, ^X, or buffer full. Returns the byte that stopped
19 the input, or ERR01 for buffer full. Echoes the characters as
20 it reads them, such that "What you see is what you get" on a crt.
21
22 int
23 getrln(unit, nb, buf)
24 int unit; logical unit number 1..4
25 int nb; buffer limit
26 char *buf; buffer pointer
27
28 Reads a line from unit into buf, with a limit of nb bytes.
29 Allows input to be cancelled by ^X. Returns on CR, LF, ^X,
30 ^Z, or buffer full. Returns the byte that stopped the input,
31 or ERR01 for buffer full.
32
33
34
35 int
36 readln(unit,nc,ctl,nb,buf)
37 int unit; logical unit number 1..4
38 int nc; length of control string ctl
39 char *ctl; control string pointer
40 int nb; buffer limit
41 char *buf; buffer pointer (at least nb+1 bytes)
42
43 Reads characters from unit into buf until: 1) nb bytes
44 have been transferred, or, 2) one of the characters in the string
45 at ctl has been read. The terminating character will be in the
46 buffer, followed by a null byte (even if the character from ctl
47 was a null byte). Returns: 1) the terminating character as its value,
48 or 2) ERR01 if stopped by the count in nb, or 3) ERR15 for an
49 invalid unit. Echoes characters as it reads them, unless the
50 character is one of those in ctl.
51
52 void
53 writeln(unit,buf)
54 int unit; logical unit number 0..4
55 char *buf; buffer pointer
56
57 Writes the zero terminated string from buf onto unit.
58
59 ============================================================================
60*/
61
62/*
63 */
64
65#include "stddefs.h"
66#include "errdefs.h"
67#include "ascii.h"
68#include "biosdefs.h"
69
70
71int
72readln(unit,nc,ctl,nb,buf)
73int unit; /* logical unit number 1..4 */
74int nc; /* length of control string ctl */
75char *ctl; /* control string pointer */
76int nb; /* buffer limit */
77char *buf; /* buffer pointer (at least nb+1 bytes) */
78{
79 register char *cp;
80 register int i, j;
81 register char *bp;
82 register char c;
83
84
85 if (unit LT 1 OR unit GT 4) /* verify unit number is in range */
86 return(ERR15); /* return ERR15 if not */
87
88 bp = buf; /* setup buffer pointer */
89
90 for (i = 0; i < nb; i++) { /* main read loop */
91
92 c = BIOS(B_GETC, unit) & 0xFF; /* get a byte from the unit */
93
94 *bp++ = c; /* add it to the buffer */
95 *bp = '\0'; /* ... followed by a zero byte */
96
97 cp = ctl; /* setup to scan ctl for the character */
98
99 for (j = 0; j < nc; j++) /* scan each byte of ctl */
100 if (*ctl++ EQ c ) /* done if we find it */
101 return((int)c);
102
103 BIOS(B_PUTC, unit, c); /* echo the character */
104 }
105
106 return(ERR01); /* buffer full */
107}
108
109/*
110 */
111
112int
113getln(unit,nb,buf)
114int unit; /* logical unit number 1..4 */
115int nb; /* buffer limit */
116char *buf; /* buffer pointer */
117{
118 register char *bp;
119 register char c;
120 register int bc;
121
122 bc = 0; /* number of characters currently in buffer */
123 bp = buf; /* current buffer pointer */
124 *bp = '\0'; /* initial null into buffer */
125
126 while (bc LT nb) {
127
128 c = BIOS(B_GETC, unit) & 0xFF;
129
130 switch (c) {
131
132 case A_BS:
133 case A_DEL:
134
135 if (bc EQ 0) {
136
137 BIOS(B_PUTC, unit, A_BEL);
138 break;
139
140 } else {
141
142 bc--;
143 bp--;
144 *bp = '\0';
145 BIOS(B_PUTC, unit, A_BS);
146 BIOS(B_PUTC, unit, ' ');
147 BIOS(B_PUTC, unit, A_BS);
148 break;
149 }
150
151 case A_CR:
152 case A_LF:
153
154 *bp++ = c; /* put character in buffer */
155 *bp = '\0'; /* terminate line with null */
156 return((int)c); /* return -- CR or LF hit */
157
158/*
159 */
160
161 case CTL('X'):
162
163 *buf = '\0'; /* clear the buffer */
164 return((int)c); /* return -- line cancelled */
165
166 default:
167
168 *bp++ = c; /* put character in buffer */
169 *bp = '\0'; /* terminate line with null */
170 BIOS(B_PUTC, unit, c); /* echo the character */
171 bc++; /* update character count */
172 }
173 }
174
175 return(ERR01); /* buffer full error */
176}
177
178/*
179 */
180
181int
182getrln(unit,nb,buf)
183int unit; /* logical unit number 1..4 */
184int nb; /* buffer limit */
185char *buf; /* buffer pointer */
186{
187 register char *bp;
188 register char c;
189 register int bc;
190
191 bc = 0; /* number of characters currently in buffer */
192 bp = buf; /* current buffer pointer */
193 *bp = '\0'; /* initial null into buffer */
194
195 while (bc LT nb) {
196
197 c = BIOS(B_GETC, unit) & 0xFF;
198
199 switch (c) {
200
201 case A_CR:
202 case A_LF:
203 case CTL('Z'):
204
205 *bp++ = c; /* put character in buffer */
206 *bp = '\0'; /* terminate line with null */
207 return((int)c); /* return -- CR, LF, or ^Z hit */
208
209 case CTL('X'):
210
211 *buf = '\0'; /* clear the buffer */
212 return((int)c); /* return -- line cancelled */
213
214 default:
215
216 *bp++ = c; /* put character in buffer */
217 *bp = '\0'; /* terminate line with null */
218 bc++; /* update character count */
219 }
220 }
221
222 return(ERR01); /* buffer full error */
223}
224
225/*
226 */
227
228writeln(unit,buf)
229int unit; /* logical unit number 0..4 */
230char *buf; /* buffer pointer */
231{
232 register char *bp;
233 register char c;
234
235 bp = buf; /* setup buffer pointer */
236
237 while (c = *bp++) /* send the string, a byte at a time */
238 BIOS(B_PUTC, unit, c);
239}
Note: See TracBrowser for help on using the repository browser.