source: buchla-68k/iolib/rawio.c@ 7bb1284

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

Unused variables and parameters.

  • Property mode set to 100644
File size: 4.8 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 int
34 readln(unit,nc,ctl,nb,buf)
35 int unit; logical unit number 1..4
36 int nc; length of control string ctl
37 char *ctl; control string pointer
38 int nb; buffer limit
39 char *buf; buffer pointer (at least nb+1 bytes)
40
41 Reads characters from unit into buf until: 1) nb bytes
42 have been transferred, or, 2) one of the characters in the string
43 at ctl has been read. The terminating character will be in the
44 buffer, followed by a null byte (even if the character from ctl
45 was a null byte). Returns: 1) the terminating character as its value,
46 or 2) ERR01 if stopped by the count in nb, or 3) ERR15 for an
47 invalid unit. Echoes characters as it reads them, unless the
48 character is one of those in ctl.
49
50 void
51 writeln(unit,buf)
52 int unit; logical unit number 0..4
53 char *buf; buffer pointer
54
55 Writes the zero terminated string from buf onto unit.
56
57 ============================================================================
58*/
59
60#include "ram.h"
61
62int16_t readln(int16_t unit, int16_t nc, int8_t *ctl, int16_t nb, int8_t *buf)
63{
64 register int8_t *cp;
65 register int16_t i, j;
66 register int8_t *bp;
67 register int8_t c;
68
69
70 if (unit LT 1 OR unit GT 4) /* verify unit number is in range */
71 return(ERR15); /* return ERR15 if not */
72
73 bp = buf; /* setup buffer pointer */
74
75 for (i = 0; i < nb; i++) { /* main read loop */
76
77 c = BIOS(B_GETC, unit) & 0xFF; /* get a byte from the unit */
78
79 *bp++ = c; /* add it to the buffer */
80 *bp = '\0'; /* ... followed by a zero byte */
81
82 cp = ctl; /* setup to scan ctl for the character */
83
84 for (j = 0; j < nc; j++) /* scan each byte of ctl */
85 if (*cp++ EQ c ) /* done if we find it */
86 return((int16_t)c);
87
88 BIOS(B_PUTC, unit, c); /* echo the character */
89 }
90
91 return(ERR01); /* buffer full */
92}
93
94int16_t getln(int16_t unit, int16_t nb, int8_t *buf)
95{
96 register int8_t *bp;
97 register int8_t c;
98 register int16_t bc;
99
100 bc = 0; /* number of characters currently in buffer */
101 bp = buf; /* current buffer pointer */
102 *bp = '\0'; /* initial null into buffer */
103
104 while (bc LT nb) {
105
106 c = BIOS(B_GETC, unit) & 0xFF;
107
108 switch (c) {
109
110 case A_BS:
111 case A_DEL:
112
113 if (bc EQ 0) {
114
115 BIOS(B_PUTC, unit, A_BEL);
116 break;
117
118 } else {
119
120 bc--;
121 bp--;
122 *bp = '\0';
123 BIOS(B_PUTC, unit, A_BS);
124 BIOS(B_PUTC, unit, ' ');
125 BIOS(B_PUTC, unit, A_BS);
126 break;
127 }
128
129 case A_CR:
130 case A_LF:
131
132 *bp++ = c; /* put character in buffer */
133 *bp = '\0'; /* terminate line with null */
134 return((int16_t)c); /* return -- CR or LF hit */
135
136 case CTL('X'):
137
138 *buf = '\0'; /* clear the buffer */
139 return((int16_t)c); /* return -- line cancelled */
140
141 default:
142
143 *bp++ = c; /* put character in buffer */
144 *bp = '\0'; /* terminate line with null */
145 BIOS(B_PUTC, unit, c); /* echo the character */
146 bc++; /* update character count */
147 }
148 }
149
150 return(ERR01); /* buffer full error */
151}
152
153int16_t getrln(int16_t unit, int16_t nb, int8_t *buf)
154{
155 register int8_t *bp;
156 register int8_t c;
157 register int16_t bc;
158
159 bc = 0; /* number of characters currently in buffer */
160 bp = buf; /* current buffer pointer */
161 *bp = '\0'; /* initial null into buffer */
162
163 while (bc LT nb) {
164
165 c = BIOS(B_GETC, unit) & 0xFF;
166
167 switch (c) {
168
169 case A_CR:
170 case A_LF:
171 case CTL('Z'):
172
173 *bp++ = c; /* put character in buffer */
174 *bp = '\0'; /* terminate line with null */
175 return((int16_t)c); /* return -- CR, LF, or ^Z hit */
176
177 case CTL('X'):
178
179 *buf = '\0'; /* clear the buffer */
180 return((int16_t)c); /* return -- line cancelled */
181
182 default:
183
184 *bp++ = c; /* put character in buffer */
185 *bp = '\0'; /* terminate line with null */
186 bc++; /* update character count */
187 }
188 }
189
190 return(ERR01); /* buffer full error */
191}
192
193void writeln(int16_t unit, int8_t *buf)
194{
195 register int8_t *bp;
196 register int8_t c;
197
198 bp = buf; /* setup buffer pointer */
199
200 while (c = *bp++) /* send the string, a byte at a time */
201 BIOS(B_PUTC, unit, c);
202}
203
Note: See TracBrowser for help on using the repository browser.