First Commit of my working state
[simh.git] / GRI / gri_defs.h
1 /* gri_defs.h: GRI-909 simulator definitions
2
3 Copyright (c) 2001-2008, Robert M. Supnik
4
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:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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.
21
22 Except as contained in this notice, the name of Robert M Supnik 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 Robert M Supnik.
25
26 12-Jan-08 RMS Added GRI-99 support
27 25-Apr-03 RMS Revised for extended file support
28 19-Sep-02 RMS Fixed declarations in gdev structure
29
30 There are several discrepancies between the original GRI-909 Reference
31 Manual of 1969 and the only surviving code sample, the MIT Crystal Growing
32 System of 1972. These discrepancies were clarified by later documentation:
33
34 1. Ref Manual documents two GR's at codes 26-27; MITCS documents six GR's
35 at 30-35. Answer: 6 GR's, 26-27 were used for character compares.
36 2. Ref Manual documents only unsigned overflow (carry) for arithmetic
37 operator; MITCS uses both unsigned overflow (AOV) and signed overflow
38 (SOV). Answer: signed and unsigned.
39 3. Ref Manual documents a ROM-subroutine multiply operator and mentions
40 but does not document a "fast multiply"; MITCS uses an extended
41 arithmetic operator with multiply, divide, and shift. Answer: EAO
42 is a package of ROM subroutines with just four functions: multiply,
43 divide, arithmetic right shift, and normalize.
44 4. Is SOV testable even if the FOA is not ADD? Answer: AOV and SOV are
45 calculated regardless of the function.
46 5. How does the EAO handle divide overflow? Answer: set link.
47 */
48
49 #include "sim_defs.h" /* simulator defns */
50
51 /* Simulator stop codes */
52
53 #define STOP_DEV 1 /* must be 1 */
54 #define STOP_HALT 2 /* HALT */
55 #define STOP_IBKPT 3 /* breakpoint */
56 #define STOP_ILLINT 4 /* illegal intr */
57
58 /* Memory */
59
60 #define MAXMEMSIZE 32768 /* max memory size */
61 #define AMASK 077777 /* logical addr mask */
62 #define MEMSIZE (cpu_unit.capac) /* actual memory size */
63 #define MEM_ADDR_OK(x) (((uint32) (x)) < MEMSIZE)
64
65 /* Architectural constants */
66
67 #define SIGN 0100000 /* sign */
68 #define INDEX 0100000 /* indexed (GRI-99) */
69 #define DMASK 0177777 /* data mask */
70 #define CBIT (DMASK + 1) /* carry bit */
71
72 /* Instruction format */
73
74 #define I_M_SRC 077 /* source */
75 #define I_V_SRC 10
76 #define I_GETSRC(x) (((x) >> I_V_SRC) & I_M_SRC)
77 #define I_M_OP 017 /* operator */
78 #define I_V_OP 6
79 #define I_GETOP(x) (((x) >> I_V_OP) & I_M_OP)
80 #define I_M_DST 077 /* destination */
81 #define I_V_DST 0
82 #define I_GETDST(x) (((x) >> I_V_DST) & I_M_DST)
83 #define SF_V_REASON 1 /* SF reason */
84
85 /* IO return */
86
87 #define IORETURN(f,v) ((f)? (v): SCPE_OK) /* stop on error */
88
89 /* Operators */
90
91 #define U_ZERO 000 /* zero */
92 #define U_IR 001 /* instruction reg */
93 #define U_FSK 002 /* func out/skip */
94 #define U_TRP 003 /* trap */
95 #define U_ISR 004 /* intr status */
96 #define U_MA 005 /* mem addr */
97 #define U_MEM 006 /* mem data */
98 #define U_SC 007 /* seq counter */
99 #define U_SWR 010 /* switch register */
100 #define U_AX 011 /* arith in 1 */
101 #define U_AY 012 /* arith in 2 */
102 #define U_AO 013 /* arith out */
103 #define U_EAO 014 /* ext arith */
104 #define U_MSR 017 /* machine status */
105 #define U_XR 022 /* GRI-99: idx reg */
106 #define U_GTRP 023 /* GRI-99: alt trap */
107 #define U_BSW 024 /* byte swap */
108 #define U_BPK 025 /* byte pack */
109 #define U_BCP1 026 /* byte compare 1 */
110 #define U_BCP2 027 /* byte compare 2 */
111 #define U_GR 030 /* hex general regs */
112 #define U_CDR 055 /* card reader */
113 #define U_CADR 057
114 #define U_DWC 066 /* disk */
115 #define U_DCA 067
116 #define U_DISK 070
117 #define U_LPR 071 /* line printer */
118 #define U_CAS 074 /* casette */
119 #define U_RTC 075 /* clock */
120 #define U_HS 076 /* paper tape */
121 #define U_TTY 077 /* console */
122
123 struct gdev {
124 uint32 (*Src)(uint32); /* source */
125 t_stat (*Dst)(uint32, uint32); /* dest */
126 t_stat (*FO)(uint32); /* func out */
127 uint32 (*SF)(uint32); /* skip func */
128 };
129
130 /* Trap (jump) */
131
132 #define TRP_DIR 00 /* direct */
133 #define TRP_DEF 01 /* defer */
134
135 /* Interrupt status */
136
137 #define ISR_OFF 01 /* int off */
138 #define ISR_ON 02 /* int on */
139
140 /* Bus modifiers */
141
142 #define BUS_COM 002 /* complement */
143 #define BUS_FNC 014 /* function mask */
144 #define BUS_P1 004 /* + 1 */
145 #define BUS_L1 010 /* rotate left */
146 #define BUS_R1 014 /* rotate right */
147
148 /* Memory address modes */
149
150 #define MEM_MOD 03
151 #define MEM_DIR 00 /* direct */
152 #define MEM_DEF 01 /* defer */
153 #define MEM_IMM 02 /* immediate */
154 #define MEM_IDF 03 /* immediate defer */
155
156 /* Arithmetic unit */
157
158 #define FO_V_FOA 8 /* arith func */
159 #define FO_M_FOA 03
160 #define OP_GET_FOA(x) (((x) >> (FO_V_FOA - I_V_OP)) & FO_M_FOA)
161 #define AO_ADD 00 /* add */
162 #define AO_AND 01 /* and */
163 #define AO_XOR 02 /* xor */
164 #define AO_IOR 03 /* or */
165 #define EAO_MUL 01 /* multiply */
166 #define EAO_DIV 02 /* divide */
167 #define EAO_ARS 03 /* arith rshft */
168 #define EAO_NORM 04 /* normalize */
169
170 /* Machine status */
171
172 #define MSR_V_BOV 15 /* bus carry */
173 #define MSR_V_L 14 /* bus link */
174 #define MSR_V_FOA 8 /* arith func */
175 #define MSR_M_FOA 03
176 #define MSR_V_SOV 1 /* arith ovflo */
177 #define MSR_V_AOV 0 /* arith carry */
178 #define MSR_BOV (1u << MSR_V_BOV)
179 #define MSR_L (1u << MSR_V_L)
180 #define MSR_FOA (MSR_M_FOA << MSR_V_FOA)
181 #define MSR_SOV (1u << MSR_V_SOV)
182 #define MSR_AOV (1u << MSR_V_AOV)
183 #define MSR_GET_FOA(x) (((x) >> MSR_V_FOA) & MSR_M_FOA)
184 #define MSR_PUT_FOA(x,n) (((x) & ~(MSR_M_FOA << MSR_V_FOA)) | \
185 (((n) & MSR_M_FOA) << MSR_V_FOA))
186 #define MSR_RW (MSR_BOV|MSR_L|MSR_FOA|MSR_SOV|MSR_AOV)
187
188 /* Real time clock */
189
190 #define RTC_OFF 001 /* off */
191 #define RTC_ON 002 /* clock on */
192 #define RTC_OV 010 /* clock flag */
193 #define RTC_CTR 0103 /* counter */
194
195 /* Terminal */
196
197 #define TTY_ORDY 002 /* output flag */
198 #define TTY_IRDY 010 /* input flag */
199
200 /* Paper tape */
201
202 #define PT_STRT 001 /* start reader */
203 #define PT_ORDY 002 /* output flag */
204 #define PT_IRDY 010 /* input flag */
205
206 /* Interrupt masks (ISR) */
207
208 #define INT_V_TTO 0 /* console out */
209 #define INT_V_TTI 1 /* console in */
210 #define INT_V_HSP 2 /* paper tape punch */
211 #define INT_V_HSR 3 /* paper tape reader */
212 #define INT_V_LPR 5 /* line printer */
213 #define INT_V_CDR 7 /* card reader */
214 #define INT_V_CASW 9 /* casette */
215 #define INT_V_CASR 10
216 #define INT_V_RTC 11 /* clock */
217 #define INT_V_DISK 14 /* disk */
218 #define INT_V_NODEF 16 /* nodefer */
219 #define INT_V_ON 17 /* enable */
220 #define INT_TTO (1u << INT_V_TTO)
221 #define INT_TTI (1u << INT_V_TTI)
222 #define INT_HSP (1u << INT_V_HSP)
223 #define INT_HSR (1u << INT_V_HSR)
224 #define INT_LPR (1u << INT_V_LPR)
225 #define INT_CDR (1u << INT_V_CDR)
226 #define INT_CASW (1u << INT_V_CAS1)
227 #define INT_CASR (1u << INT_V_CAS2)
228 #define INT_RTC (1u << INT_V_RTC)
229 #define INT_DISK (1u << INT_V_DISK)
230 #define INT_NODEF (1u << INT_V_NODEF)
231 #define INT_ON (1u << INT_V_ON)
232 #define INT_PENDING (INT_ON | INT_NODEF)
233
234 /* Vectors */
235
236 #define VEC_BKP 0000 /* breakpoint */
237 #define VEC_TTO 0011 /* console out */
238 #define VEC_TTI 0014 /* console in */
239 #define VEC_HSP 0017 /* paper tape punch */
240 #define VEC_HSR 0022 /* paper tape reader */
241 #define VEC_LPR 0033 /* line printer */
242 #define VEC_CDR 0033 /* card reader */
243 #define VEC_CASW 0044 /* casette */
244 #define VEC_CASR 0047
245 #define VEC_DISK 0055 /* disk */
246 #define VEC_RTC 0100 /* clock */