Commit | Line | Data |
---|---|---|
196ba1fc PH |
1 | /* altair_sio: MITS Altair serial I/O card\r |
2 | \r | |
3 | Copyright (c) 1997-2005, Charles E. Owen\r | |
4 | \r | |
5 | Permission is hereby granted, free of charge, to any person obtaining a\r | |
6 | copy of this software and associated documentation files (the "Software"),\r | |
7 | to deal in the Software without restriction, including without limitation\r | |
8 | the rights to use, copy, modify, merge, publish, distribute, sublicense,\r | |
9 | and/or sell copies of the Software, and to permit persons to whom the\r | |
10 | Software is furnished to do so, subject to the following conditions:\r | |
11 | \r | |
12 | The above copyright notice and this permission notice shall be included in\r | |
13 | all copies or substantial portions of the Software.\r | |
14 | \r | |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r | |
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r | |
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r | |
18 | ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r | |
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r | |
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r | |
21 | \r | |
22 | Except as contained in this notice, the name of Charles E. Owen shall not be\r | |
23 | used in advertising or otherwise to promote the sale, use or other dealings\r | |
24 | in this Software without prior written authorization from Charles E. Owen.\r | |
25 | \r | |
26 | These functions support a simulated MITS 2SIO interface card.\r | |
27 | The card had two physical I/O ports which could be connected\r | |
28 | to any serial I/O device that would connect to a current loop,\r | |
29 | RS232, or TTY interface. Available baud rates were jumper\r | |
30 | selectable for each port from 110 to 9600.\r | |
31 | \r | |
32 | All I/O is via programmed I/O. Each each has a status port\r | |
33 | and a data port. A write to the status port can select\r | |
34 | some options for the device (0x03 will reset the port).\r | |
35 | A read of the status port gets the port status:\r | |
36 | \r | |
37 | +---+---+---+---+---+---+---+---+\r | |
38 | | X X X X X X O I |\r | |
39 | +---+---+---+---+---+---+---+---+\r | |
40 | \r | |
41 | I - A 1 in this bit position means a character has been received\r | |
42 | on the data port and is ready to be read.\r | |
43 | O - A 1 in this bit means the port is ready to receive a character\r | |
44 | on the data port and transmit it out over the serial line.\r | |
45 | \r | |
46 | A read to the data port gets the buffered character, a write\r | |
47 | to the data port writes the character to the device.\r | |
48 | */\r | |
49 | \r | |
50 | #include <stdio.h>\r | |
51 | \r | |
52 | #include "altair_defs.h"\r | |
53 | \r | |
54 | #define UNIT_V_ANSI (UNIT_V_UF + 0) /* ANSI mode */\r | |
55 | #define UNIT_ANSI (1 << UNIT_V_ANSI)\r | |
56 | \r | |
57 | t_stat sio_svc (UNIT *uptr);\r | |
58 | t_stat sio_reset (DEVICE *dptr);\r | |
59 | t_stat ptr_svc (UNIT *uptr);\r | |
60 | t_stat ptr_reset (DEVICE *dptr);\r | |
61 | t_stat ptp_svc (UNIT *uptr);\r | |
62 | t_stat ptp_reset (DEVICE *dptr);\r | |
63 | \r | |
64 | int32 ptr_stopioe = 0, ptp_stopioe = 0; /* stop on error */\r | |
65 | \r | |
66 | /* 2SIO Standard I/O Data Structures */\r | |
67 | \r | |
68 | UNIT sio_unit = { UDATA (&sio_svc, 0, 0), KBD_POLL_WAIT };\r | |
69 | \r | |
70 | REG sio_reg[] = {\r | |
71 | { ORDATA (DATA, sio_unit.buf, 8) },\r | |
72 | { ORDATA (STAT, sio_unit.u3, 8) },\r | |
73 | { NULL }\r | |
74 | };\r | |
75 | \r | |
76 | MTAB sio_mod[] = {\r | |
77 | { UNIT_ANSI, 0, "TTY", "TTY", NULL },\r | |
78 | { UNIT_ANSI, UNIT_ANSI, "ANSI", "ANSI", NULL },\r | |
79 | { 0 }\r | |
80 | };\r | |
81 | \r | |
82 | DEVICE sio_dev = {\r | |
83 | "2SIO", &sio_unit, sio_reg, sio_mod,\r | |
84 | 1, 10, 31, 1, 8, 8,\r | |
85 | NULL, NULL, &sio_reset,\r | |
86 | NULL, NULL, NULL\r | |
87 | };\r | |
88 | \r | |
89 | UNIT ptr_unit = { UDATA (&ptr_svc, UNIT_SEQ + UNIT_ATTABLE, 0), KBD_POLL_WAIT };\r | |
90 | \r | |
91 | REG ptr_reg[] = {\r | |
92 | { ORDATA (DATA, ptr_unit.buf, 8) },\r | |
93 | { ORDATA (STAT, ptr_unit.u3, 8) },\r | |
94 | { ORDATA (POS, ptr_unit.pos, T_ADDR_W) },\r | |
95 | { NULL }\r | |
96 | };\r | |
97 | \r | |
98 | DEVICE ptr_dev = {\r | |
99 | "PTR", &ptr_unit, ptr_reg, NULL,\r | |
100 | 1, 10, 31, 1, 8, 8,\r | |
101 | NULL, NULL, &ptr_reset,\r | |
102 | NULL, NULL, NULL\r | |
103 | };\r | |
104 | \r | |
105 | UNIT ptp_unit = { UDATA (&ptp_svc, UNIT_SEQ + UNIT_ATTABLE, 0), KBD_POLL_WAIT };\r | |
106 | \r | |
107 | REG ptp_reg[] = {\r | |
108 | { ORDATA (DATA, ptp_unit.buf, 8) },\r | |
109 | { ORDATA (STAT, ptp_unit.u3, 8) },\r | |
110 | { ORDATA (POS, ptp_unit.pos, T_ADDR_W) },\r | |
111 | { NULL }\r | |
112 | };\r | |
113 | \r | |
114 | DEVICE ptp_dev = {\r | |
115 | "PTP", &ptp_unit, ptp_reg, NULL,\r | |
116 | 1, 10, 31, 1, 8, 8,\r | |
117 | NULL, NULL, &ptp_reset,\r | |
118 | NULL, NULL, NULL\r | |
119 | };\r | |
120 | \r | |
121 | /* Service routines to handle simulator functions */\r | |
122 | \r | |
123 | /* service routine - actually gets char & places in buffer */\r | |
124 | \r | |
125 | int32 sio_svc (UNIT *uptr)\r | |
126 | {\r | |
127 | int32 temp;\r | |
128 | \r | |
129 | sim_activate (&sio_unit, sio_unit.wait); /* continue poll */\r | |
130 | if ((temp = sim_poll_kbd ()) < SCPE_KFLAG)\r | |
131 | return temp; /* no char or error? */\r | |
132 | sio_unit.buf = temp & 0377; /* Save char */\r | |
133 | sio_unit.u3 |= 0x01; /* Set status */\r | |
134 | \r | |
135 | /* Do any special character handling here */\r | |
136 | \r | |
137 | sio_unit.pos++;\r | |
138 | return SCPE_OK;\r | |
139 | }\r | |
140 | \r | |
141 | \r | |
142 | int32 ptr_svc (UNIT *uptr)\r | |
143 | {\r | |
144 | return SCPE_OK;\r | |
145 | }\r | |
146 | \r | |
147 | int32 ptp_svc (UNIT *uptr)\r | |
148 | {\r | |
149 | return SCPE_OK;\r | |
150 | }\r | |
151 | \r | |
152 | \r | |
153 | /* Reset routine */\r | |
154 | \r | |
155 | int32 sio_reset (DEVICE *dptr)\r | |
156 | {\r | |
157 | sio_unit.buf = 0; /* Data */\r | |
158 | sio_unit.u3 = 0x02; /* Status */\r | |
159 | sim_activate (&sio_unit, sio_unit.wait); /* activate unit */\r | |
160 | return SCPE_OK;\r | |
161 | }\r | |
162 | \r | |
163 | \r | |
164 | int32 ptr_reset (DEVICE *dptr)\r | |
165 | {\r | |
166 | ptr_unit.buf = 0;\r | |
167 | ptr_unit.u3 = 0x02;\r | |
168 | sim_cancel (&ptr_unit); /* deactivate unit */\r | |
169 | return SCPE_OK;\r | |
170 | }\r | |
171 | \r | |
172 | int32 ptp_reset (DEVICE *dptr)\r | |
173 | {\r | |
174 | ptp_unit.buf = 0;\r | |
175 | ptp_unit.u3 = 0x02;\r | |
176 | sim_cancel (&ptp_unit); /* deactivate unit */\r | |
177 | return SCPE_OK;\r | |
178 | }\r | |
179 | \r | |
180 | \r | |
181 | /* I/O instruction handlers, called from the CPU module when an\r | |
182 | IN or OUT instruction is issued.\r | |
183 | \r | |
184 | Each function is passed an 'io' flag, where 0 means a read from\r | |
185 | the port, and 1 means a write to the port. On input, the actual\r | |
186 | input is passed as the return value, on output, 'data' is written\r | |
187 | to the device.\r | |
188 | */\r | |
189 | \r | |
190 | int32 sio0s(int32 io, int32 data)\r | |
191 | {\r | |
192 | if (io == 0) {\r | |
193 | return (sio_unit.u3);\r | |
194 | } else {\r | |
195 | if (data == 0x03) { /* reset port! */\r | |
196 | sio_unit.u3 = 0x02;\r | |
197 | sio_unit.buf = 0;\r | |
198 | sio_unit.pos = 0;\r | |
199 | }\r | |
200 | return (0);\r | |
201 | }\r | |
202 | }\r | |
203 | \r | |
204 | int32 sio0d(int32 io, int32 data)\r | |
205 | {\r | |
206 | if (io == 0) {\r | |
207 | sio_unit.u3 = sio_unit.u3 & 0xFE;\r | |
208 | return (sio_unit.buf);\r | |
209 | } else {\r | |
210 | sim_putchar(data);\r | |
211 | }\r | |
212 | return 0;\r | |
213 | }\r | |
214 | \r | |
215 | /* Port 2 controls the PTR/PTP devices */\r | |
216 | \r | |
217 | int32 sio1s(int32 io, int32 data)\r | |
218 | {\r | |
219 | if (io == 0) {\r | |
220 | if ((ptr_unit.flags & UNIT_ATT) == 0) /* attached? */\r | |
221 | return 0x02;\r | |
222 | if (ptr_unit.u3 != 0) /* No more data? */\r | |
223 | return 0x02;\r | |
224 | return (0x03); /* ready to read/write */\r | |
225 | } else {\r | |
226 | if (data == 0x03) {\r | |
227 | ptr_unit.u3 = 0;\r | |
228 | ptr_unit.buf = 0;\r | |
229 | ptr_unit.pos = 0;\r | |
230 | ptp_unit.u3 = 0;\r | |
231 | ptp_unit.buf = 0;\r | |
232 | ptp_unit.pos = 0;\r | |
233 | }\r | |
234 | return (0);\r | |
235 | }\r | |
236 | }\r | |
237 | \r | |
238 | int32 sio1d(int32 io, int32 data)\r | |
239 | {\r | |
240 | int32 temp;\r | |
241 | UNIT *uptr;\r | |
242 | \r | |
243 | if (io == 0) {\r | |
244 | if ((ptr_unit.flags & UNIT_ATT) == 0) /* attached? */\r | |
245 | return 0;\r | |
246 | if (ptr_unit.u3 != 0)\r | |
247 | return 0;\r | |
248 | uptr = ptr_dev.units;\r | |
249 | if ((temp = getc(uptr -> fileref)) == EOF) { /* end of file? */\r | |
250 | ptr_unit.u3 = 0x01;\r | |
251 | return 0;\r | |
252 | }\r | |
253 | ptr_unit.pos++;\r | |
254 | return (temp & 0xFF);\r | |
255 | } else {\r | |
256 | uptr = ptp_dev.units;\r | |
257 | putc(data, uptr -> fileref);\r | |
258 | ptp_unit.pos++;\r | |
259 | }\r | |
260 | return 0;\r | |
261 | }\r | |
262 | \r |