1 /* altair_sio: MITS Altair serial I/O card
3 Copyright (c) 1997-2005, Charles E. Owen
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of Charles E. Owen shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from Charles E. Owen.
26 These functions support a simulated MITS 2SIO interface card.
27 The card had two physical I/O ports which could be connected
28 to any serial I/O device that would connect to a current loop,
29 RS232, or TTY interface. Available baud rates were jumper
30 selectable for each port from 110 to 9600.
32 All I/O is via programmed I/O. Each each has a status port
33 and a data port. A write to the status port can select
34 some options for the device (0x03 will reset the port).
35 A read of the status port gets the port status:
37 +---+---+---+---+---+---+---+---+
39 +---+---+---+---+---+---+---+---+
41 I - A 1 in this bit position means a character has been received
42 on the data port and is ready to be read.
43 O - A 1 in this bit means the port is ready to receive a character
44 on the data port and transmit it out over the serial line.
46 A read to the data port gets the buffered character, a write
47 to the data port writes the character to the device.
52 #include "altair_defs.h"
54 #define UNIT_V_ANSI (UNIT_V_UF + 0) /* ANSI mode */
55 #define UNIT_ANSI (1 << UNIT_V_ANSI)
57 t_stat
sio_svc (UNIT
*uptr
);
58 t_stat
sio_reset (DEVICE
*dptr
);
59 t_stat
ptr_svc (UNIT
*uptr
);
60 t_stat
ptr_reset (DEVICE
*dptr
);
61 t_stat
ptp_svc (UNIT
*uptr
);
62 t_stat
ptp_reset (DEVICE
*dptr
);
64 int32 ptr_stopioe
= 0, ptp_stopioe
= 0; /* stop on error */
66 /* 2SIO Standard I/O Data Structures */
68 UNIT sio_unit
= { UDATA (&sio_svc
, 0, 0), KBD_POLL_WAIT
};
71 { ORDATA (DATA
, sio_unit
.buf
, 8) },
72 { ORDATA (STAT
, sio_unit
.u3
, 8) },
77 { UNIT_ANSI
, 0, "TTY", "TTY", NULL
},
78 { UNIT_ANSI
, UNIT_ANSI
, "ANSI", "ANSI", NULL
},
83 "2SIO", &sio_unit
, sio_reg
, sio_mod
,
85 NULL
, NULL
, &sio_reset
,
89 UNIT ptr_unit
= { UDATA (&ptr_svc
, UNIT_SEQ
+ UNIT_ATTABLE
, 0), KBD_POLL_WAIT
};
92 { ORDATA (DATA
, ptr_unit
.buf
, 8) },
93 { ORDATA (STAT
, ptr_unit
.u3
, 8) },
94 { ORDATA (POS
, ptr_unit
.pos
, T_ADDR_W
) },
99 "PTR", &ptr_unit
, ptr_reg
, NULL
,
101 NULL
, NULL
, &ptr_reset
,
105 UNIT ptp_unit
= { UDATA (&ptp_svc
, UNIT_SEQ
+ UNIT_ATTABLE
, 0), KBD_POLL_WAIT
};
108 { ORDATA (DATA
, ptp_unit
.buf
, 8) },
109 { ORDATA (STAT
, ptp_unit
.u3
, 8) },
110 { ORDATA (POS
, ptp_unit
.pos
, T_ADDR_W
) },
115 "PTP", &ptp_unit
, ptp_reg
, NULL
,
117 NULL
, NULL
, &ptp_reset
,
121 /* Service routines to handle simulator functions */
123 /* service routine - actually gets char & places in buffer */
125 int32
sio_svc (UNIT
*uptr
)
129 sim_activate (&sio_unit
, sio_unit
.wait
); /* continue poll */
130 if ((temp
= sim_poll_kbd ()) < SCPE_KFLAG
)
131 return temp
; /* no char or error? */
132 sio_unit
.buf
= temp
& 0377; /* Save char */
133 sio_unit
.u3
|= 0x01; /* Set status */
135 /* Do any special character handling here */
142 int32
ptr_svc (UNIT
*uptr
)
147 int32
ptp_svc (UNIT
*uptr
)
155 int32
sio_reset (DEVICE
*dptr
)
157 sio_unit
.buf
= 0; /* Data */
158 sio_unit
.u3
= 0x02; /* Status */
159 sim_activate (&sio_unit
, sio_unit
.wait
); /* activate unit */
164 int32
ptr_reset (DEVICE
*dptr
)
168 sim_cancel (&ptr_unit
); /* deactivate unit */
172 int32
ptp_reset (DEVICE
*dptr
)
176 sim_cancel (&ptp_unit
); /* deactivate unit */
181 /* I/O instruction handlers, called from the CPU module when an
182 IN or OUT instruction is issued.
184 Each function is passed an 'io' flag, where 0 means a read from
185 the port, and 1 means a write to the port. On input, the actual
186 input is passed as the return value, on output, 'data' is written
190 int32
sio0s(int32 io
, int32 data
)
193 return (sio_unit
.u3
);
195 if (data
== 0x03) { /* reset port! */
204 int32
sio0d(int32 io
, int32 data
)
207 sio_unit
.u3
= sio_unit
.u3
& 0xFE;
208 return (sio_unit
.buf
);
215 /* Port 2 controls the PTR/PTP devices */
217 int32
sio1s(int32 io
, int32 data
)
220 if ((ptr_unit
.flags
& UNIT_ATT
) == 0) /* attached? */
222 if (ptr_unit
.u3
!= 0) /* No more data? */
224 return (0x03); /* ready to read/write */
238 int32
sio1d(int32 io
, int32 data
)
244 if ((ptr_unit
.flags
& UNIT_ATT
) == 0) /* attached? */
246 if (ptr_unit
.u3
!= 0)
248 uptr
= ptr_dev
.units
;
249 if ((temp
= getc(uptr
-> fileref
)) == EOF
) { /* end of file? */
254 return (temp
& 0xFF);
256 uptr
= ptp_dev
.units
;
257 putc(data
, uptr
-> fileref
);