1 /* i1620_defs.h: IBM 1620 simulator definitions
2 
3    Copyright (c) 2002-2010, 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    This simulator is based on the 1620 simulator written by Geoff Kuenning.
27    I am grateful to Al Kossow, the Computer History Museum, and the IBM Corporate
28    Archives for their help in gathering documentation about the IBM 1620.
29 
30    22-May-10    RMS     Added check for 64b definitions
31    18-Oct-02    RMS     Fixed bug in ADDR_S macro (found by Hans Pufal)
32 */
33 
34 #ifndef _I1620_DEFS_H_
35 #define _I1620_DEFS_H_  0
36 
37 #include "sim_defs.h"                                   /* simulator defns */
38 
39 #if defined(USE_INT64) || defined(USE_ADDR64)
40 #error "1620 does not support 64b values!"
41 #endif
42 
43 /* Simulator stop codes */
44 
45 #define STOP_HALT       1                               /* HALT */
46 #define STOP_IBKPT      2                               /* breakpoint */
47 #define STOP_INVINS     3                               /* invalid instruction */
48 #define STOP_INVDIG     4                               /* invalid digit */
49 #define STOP_INVCHR     5                               /* invalid char */
50 #define STOP_INVIND     6                               /* invalid indicator */
51 #define STOP_INVPDG     7                               /* invalid P addr digit */
52 #define STOP_INVPAD     8                               /* invalid P addr */
53 #define STOP_INVPIA     9                               /* invalid P indir addr */
54 #define STOP_INVQDG     10                              /* invalid Q addr digits */
55 #define STOP_INVQAD     11                              /* invalid Q addr */
56 #define STOP_INVQIA     12                              /* invalid Q indir addr */
57 #define STOP_INVIO      13                              /* invalid IO address */
58 #define STOP_INVRTN     14                              /* invalid return */
59 #define STOP_INVFNC     15                              /* invalid function */
60 #define STOP_INVIAD     16                              /* invalid instr addr */
61 #define STOP_INVSEL     17                              /* invalid select */
62 #define STOP_INVIDX     18                              /* invalid index instr */
63 #define STOP_INVEAD     19                              /* invalid even addr */
64 #define STOP_INVDCF     20                              /* invalid DCF addr */
65 #define STOP_INVDRV     21                              /* invalid disk drive */
66 #define STOP_INVDSC     22                              /* invalid disk sector */
67 #define STOP_INVDCN     23                              /* invalid disk count */
68 #define STOP_INVDBA     24                              /* invalid disk buf addr */
69 #define STOP_DACERR     25                              /* disk addr comp err */
70 #define STOP_DWCERR     26                              /* disk wr check err */
71 #define STOP_CYOERR     27                              /* cylinder ovflo err */
72 #define STOP_WRLERR     28                              /* wrong rec lnt err */
73 #define STOP_CCT        29                              /* runaway CCT */
74 #define STOP_FWRAP      30                              /* field wrap */
75 #define STOP_RWRAP      31                              /* record wrap */
76 #define STOP_NOCD       32                              /* no card in reader */
77 #define STOP_OVERFL     33                              /* overflow */
78 #define STOP_EXPCHK     34                              /* exponent error */
79 #define STOP_WRADIS     35                              /* write addr disabled */
80 #define STOP_FPLNT      36                              /* invalid fp length */
81 #define STOP_FPUNL      37                              /* fp lengths unequal */
82 #define STOP_FPMF       38                              /* no flag on exp */
83 #define STOP_FPDVZ      39                              /* divide by zero */
84 
85 /* Memory */
86 
87 #define MAXMEMSIZE      60000                           /* max mem size */
88 #define MEMSIZE         (cpu_unit.capac)                /* act memory size */
89 
90 /* Processor parameters */
91 
92 #define INST_LEN        12                              /* inst length */
93 #define ADDR_LEN        5                               /* addr length */
94 #define MUL_TABLE       100                             /* multiply table */
95 #define MUL_TABLE_LEN   200
96 #define ADD_TABLE       300                             /* add table */
97 #define ADD_TABLE_LEN   100
98 #define IDX_A           300                             /* index A base */
99 #define IDX_B           340                             /* index B base */
100 #define PROD_AREA       80                              /* product area */
101 #define PROD_AREA_LEN   20                              /* product area */
102 #define PROD_AREA_END   (PROD_AREA + PROD_AREA_LEN)
103 
104 /* Branch indicator codes */
105 
106 #define NUM_IND         100                             /* number of indicators */
107 
108 #define IN_SW1          1                               /* sense switch 1 */
109 #define IN_SW2          2                               /* sense switch 2 */
110 #define IN_SW3          3                               /* sense switch 3 */
111 #define IN_SW4          4                               /* sense switch 4 */
112 #define IN_RDCHK        6                               /* read check (I/O error) */
113 #define IN_WRCHK        7                               /* write check (I/O error) */
114 #define IN_LAST         9                               /* last card was just read */
115 #define IN_HP           11                              /* high or positive result */
116 #define IN_EZ           12                              /* equal or zero result */
117 #define IN_HPEZ         13                              /* high/positive or equal/zero */
118 #define IN_OVF          14                              /* overflow */
119 #define IN_EXPCHK       15                              /* floating exponent check */
120 #define IN_MBREVEN      16                              /* even parity check */
121 #define IN_MBRODD       17                              /* odd parity check */
122 #define IN_ANYCHK       19                              /* any of read, write, even/odd */
123 #define IN_PRCHK        25                              /* printer check */
124 #define IN_IXN          30                              /* IX neither */
125 #define IN_IXA          31                              /* IX A band */
126 #define IN_IXB          32                              /* IX B band */
127 #define IN_PRCH9        33                              /* printer chan 9 */
128 #define IN_PRCH12       34                              /* printer chan 12 */
129 #define IN_PRBSY        35                              /* printer busy */
130 #define IN_DACH         36                              /* disk addr/data check */
131 #define IN_DWLR         37                              /* disk rec length */
132 #define IN_DCYO         38                              /* disk cyl overflow */
133 #define IN_DERR         39                              /* disk any error */
134 
135 /* I/O channel codes */
136 
137 #define NUM_IO          100                             /* number of IO chan */
138 
139 #define IO_TTY          1                               /* console typewriter */
140 #define IO_PTP          2                               /* paper-tape punch */
141 #define IO_PTR          3                               /* paper-tape reader */
142 #define IO_CDP          4                               /* card punch */
143 #define IO_CDR          5                               /* card reader */
144 #define IO_DSK          7                               /* disk */
145 #define IO_LPT          9                               /* line printer */
146 #define IO_BTP          32                              /* binary ptp */
147 #define IO_BTR          33                              /* binary ptr */
148 
149 #define LPT_WIDTH       120                             /* line print width */
150 #define CCT_LNT         132                             /* car ctrl length */
151 
152 #define CRETIOE(f,c)    return ((f)? (c): SCPE_OK)
153 
154 /* Memory representation: flag + BCD digit per byte */
155 
156 #define FLAG            0x10
157 #define DIGIT           0x0F
158 #define REC_MARK        0xA
159 #define NUM_BLANK       0xC
160 #define GRP_MARK        0xF
161 #define BAD_DIGIT(x)    ((x) > 9)
162 
163 /* Instruction format */
164 
165 #define I_OP            0                               /* opcode */
166 #define I_P             2                               /* P start */
167 #define I_PL            6                               /* P end */
168 #define I_Q             7                               /* Q start */
169 #define I_QL            11                              /* Q end */
170 #define I_IO            8                               /* IO select */
171 #define I_BR            8                               /* indicator select */
172 #define I_CTL           10                              /* control select */
173 #define I_SEL           11                              /* BS select */
174 
175 #define ADDR_A(x,a)     ((((x) + (a)) >= MEMSIZE)? ((x) + (a) - MEMSIZE): ((x) + (a)))
176 #define ADDR_S(x,a)     (((x) < (a))? ((x) - (a) + MEMSIZE): ((x) - (a)))
177 #define PP(x)           x = ADDR_A(x,1)
178 #define MM(x)           x = ADDR_S(x,1)
179 
180 /* CPU options, stored in cpu_unit.flags */
181 /* Decoding flags must be part of the same definition set */
182 
183 #define UNIT_SCP        ((1 << UNIT_V_UF) - 1)          /* mask of SCP flags */
184 #define IF_MII          (1 << (UNIT_V_UF + 0))          /* model 2 */
185 #define IF_DIV          (1 << (UNIT_V_UF + 1))          /* automatic divide */
186 #define IF_IA           (1 << (UNIT_V_UF + 2))          /* indirect addressing */
187 #define IF_EDT          (1 << (UNIT_V_UF + 3))          /* edit */
188 #define IF_FP           (1 << (UNIT_V_UF + 4))          /* floating point */
189 #define IF_BIN          (1 << (UNIT_V_UF + 5))          /* binary */
190 #define IF_IDX          (1 << (UNIT_V_UF + 6))          /* indexing */
191 #define IF_VPA          (1 << (UNIT_V_UF + 7))          /* valid P addr */
192 #define IF_VQA          (1 << (UNIT_V_UF + 8))          /* valid Q addr */
193 #define IF_4QA          (1 << (UNIT_V_UF + 9))          /* 4 char Q addr */
194 #define IF_NQX          (1 << (UNIT_V_UF + 10))         /* no Q indexing */
195 #define IF_IMM          (1 << (UNIT_V_UF + 11))         /* immediate */
196 #define UNIT_BCD        (1 << (UNIT_V_UF + 12))         /* BCD coded */
197 #define UNIT_MSIZE      (1 << (UNIT_V_UF + 13))         /* fake flag */
198 #define ALLOPT          (IF_DIV + IF_IA + IF_EDT + IF_FP + IF_BIN + IF_IDX)
199 #define MI_OPT          (IF_DIV + IF_IA + IF_EDT + IF_FP)
200 #define MI_STD          (IF_DIV + IF_IA + IF_EDT)
201 #define MII_OPT         (ALLOPT)
202 #define MII_STD         (IF_DIV + IF_IA + IF_EDT + IF_BIN + IF_IDX)
203 
204 /* Add status codes */
205 
206 #define ADD_NOCRY       0                               /* no carry out */
207 #define ADD_CARRY       1                               /* carry out */
208 #define ADD_SIGNC       2                               /* sign change */
209 
210 /* Opcodes */
211 
212 enum opcodes {
213     OP_FADD = 1, OP_FSUB, OP_FMUL,                      /* 00 - 09 */
214     OP_FSL = 5, OP_TFL, OP_BTFL, OP_FSR, OP_FDIV,
215     OP_BTAM = 10, OP_AM, OP_SM, OP_MM, OP_CM,           /* 10 - 19 */
216     OP_TDM, OP_TFM, OP_BTM, OP_LDM, OP_DM,
217     OP_BTA = 20, OP_A, OP_S, OP_M, OP_C,                /* 20 - 29 */
218     OP_TD, OP_TF, OP_BT, OP_LD, OP_D,
219     OP_TRNM = 30, OP_TR, OP_SF, OP_CF, OP_K,            /* 30 - 39 */
220     OP_DN, OP_RN, OP_RA, OP_WN, OP_WA,
221     OP_NOP = 41, OP_BB, OP_BD, OP_BNF,                  /* 40 - 49 */
222     OP_BNR, OP_BI, OP_BNI, OP_H, OP_B,
223     OP_BNG = 55,
224     OP_BS = 60, OP_BX, OP_BXM, OP_BCX, OP_BCXM,         /* 60 - 69 */
225     OP_BLX, OP_BLXM, OP_BSX,
226     OP_MA = 70, OP_MF, OP_TNS, OP_TNF,                  /* 70 - 79 */
227                                                         /* 80 - 89 */
228     OP_BBT = 90, OP_BMK, OP_ORF, OP_ANDF, OP_CPLF,      /* 90 - 99 */
229     OP_EORF, OP_OTD, OP_DTO };
230 
231 #endif
232