1 /* h316_defs.h: Honeywell 316/516 simulator definitions
2 
3    Copyright (c) 1999-2011, 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    19-Nov-11    RMS     Removed XR macro, added XR_LOC macro (from Adrian Wise)
27    22-May-10    RMS     Added check for 64b definitions
28    15-Feb-05    RMS     Added start button interrupt
29    01-Dec-04    RMS     Added double precision constants
30    24-Oct-03    RMS     Added DMA/DMC support
31    25-Apr-03    RMS     Revised for extended file support
32 */
33 
34 #ifndef _H316_DEFS_H_
35 #define _H316_DEFS_H_   0
36 
37 #include "sim_defs.h"                                   /* simulator defns */
38 
39 #if defined(USE_INT64) || defined(USE_ADDR64)
40 #error "H316 does not support 64b values!"
41 #endif
42 
43 /* Simulator stop codes */
44 
45 #define STOP_RSRV       1                               /* must be 1 */
46 #define STOP_IODV       2                               /* must be 2 */
47 #define STOP_HALT       3                               /* HALT */
48 #define STOP_IBKPT      4                               /* breakpoint */
49 #define STOP_IND        5                               /* indirect loop */
50 #define STOP_DMAER      6                               /* DMA error */
51 #define STOP_MTWRP      7                               /* MT write protected */
52 #define STOP_DPOVR      8                               /* DP write overrun */
53 #define STOP_DPFMT      9                               /* DP invalid format */
54 
55 /* Memory */
56 
57 #define MAXMEMSIZE      32768                           /* max memory size */
58 #define MEMSIZE         (cpu_unit.capac)                /* actual memory size */
59 #define X_AMASK         (MAXMEMSIZE - 1)                /* ext address mask */
60 #define NX_AMASK        ((MAXMEMSIZE / 2) - 1)          /* nx address mask */
61 #define MEM_ADDR_OK(x)  (((uint32) (x)) < MEMSIZE)
62 
63 /* Architectural constants */
64 
65 #define SIGN            0100000                         /* sign */
66 #define DP_SIGN         010000000000
67 #define DMASK           0177777                         /* data mask */
68 #define MMASK           (DMASK & ~SIGN)                 /* magnitude mask */
69 #define M_CLK           061                             /* clock location */
70 #define M_RSTINT        062                             /* restrict int */
71 #define M_INT           063                             /* int location */
72 #define M_XR            (ext? 0: (PC & 040000))         /* XR location */
73 
74 /* CPU options */
75 
76 #define UNIT_V_MSIZE    (UNIT_V_UF + 0)                 /* dummy mask */
77 #define UNIT_V_EXT      (UNIT_V_UF + 1)                 /* extended mem */
78 #define UNIT_V_HSA      (UNIT_V_UF + 2)                 /* high speed arith */
79 #define UNIT_V_DMC      (UNIT_V_UF + 3)                 /* DMC */
80 #define UNIT_MSIZE      (1u << UNIT_V_MSIZE)
81 #define UNIT_EXT        (1u << UNIT_V_EXT)
82 #define UNIT_HSA        (1u << UNIT_V_HSA)
83 #define UNIT_DMC        (1u << UNIT_V_DMC)
84 
85 /* Instruction format */
86 
87 #define I_M_OP          077                             /* opcode */
88 #define I_V_OP          10
89 #define I_GETOP(x)      (((x) >> I_V_OP) & I_M_OP)
90 #define I_M_FNC         017                             /* function */
91 #define I_V_FNC         6
92 #define I_GETFNC(x)     (((x) >> I_V_FNC) & I_M_FNC)
93 #define IA              0100000                         /* indirect address */
94 #define IDX             0040000                         /* indexed */
95 #define SC              0001000                         /* sector */
96 #define DISP            0000777                         /* page displacement */
97 #define PAGENO          0077000                         /* page number */
98 #define INCLRA          (010 << I_V_FNC)                /* INA clear A */
99 #define DEVMASK         0000077                         /* device mask */
100 #define SHFMASK         0000077                         /* shift mask */
101 
102 /* I/O opcodes */
103 
104 #define ioOCP           0                               /* output control */
105 #define ioSKS           1                               /* skip if set */
106 #define ioINA           2                               /* input to A */
107 #define ioOTA           3                               /* output from A */
108 #define ioEND           4                               /* channel end */
109 
110 /* Device information block */
111 
112 struct h316_dib {
113     uint32              dev;                            /* device number */
114     uint32              chan;                           /* dma/dmc channel */
115     uint32              num;                            /* number of slots */
116     int32               (*io) (int32 inst, int32 fnc, int32 dat, int32 dev);  };
117 
118 typedef struct h316_dib DIB;
119 
120 /* DMA/DMC channel numbers */
121 
122 #define IOBUS           0                               /* IO bus */
123 #define DMA_MIN         1                               /* 4 DMA channels */
124 #define DMA_MAX         4
125 #define DMC_MIN         1                               /* 16 DMC channels */
126 #define DMC_MAX         16
127 
128 #define DMA1            (DMA_MIN)
129 #define DMC1            (DMA_MAX+DMC_MIN)
130 
131 /* DMA/DMC bit assignments in channel request word */
132 
133 #define DMA_V_DMA1      0                               /* DMA channels */
134 #define DMC_V_DMC1      4                               /* DMC channels */
135 #define SET_CH_REQ(x)   chan_req = chan_req | (1 << (x))
136 #define Q_DMA(x)        (((x) >= 0) && ((x) < DMC_V_DMC1))
137 
138 /* DMA/DMC definitions */
139 
140 #define DMA_IN          0100000                         /* input flag */
141 #define DMC_BASE        020                             /* DMC memory base */
142 
143 /* I/O device codes */
144 
145 #define PTR             001                             /* paper tape reader */
146 #define PTP             002                             /* paper tape punch */
147 #define LPT             003                             /* line printer */
148 #define TTY             004                             /* console */
149 #define CDR             005                             /* card reader */
150 #define MT              010                             /* mag tape data */
151 #define CLK_KEYS        020                             /* clock/keys (CPU) */
152 #define FHD             022                             /* fixed head disk */
153 #define DMA             024                             /* DMA control */
154 #define DP              025                             /* moving head disk */
155 #define DEV_MAX         64
156 
157 /* Interrupt flags, definitions correspond to SMK bits */
158 
159 #define INT_V_CLK       0                               /* clock */
160 #define INT_V_MPE       1                               /* parity error */
161 #define INT_V_LPT       2                               /* line printer */
162 #define INT_V_CDR       4                               /* card reader */
163 #define INT_V_TTY       5                               /* teletype */
164 #define INT_V_PTP       6                               /* paper tape punch */
165 #define INT_V_PTR       7                               /* paper tape reader */
166 #define INT_V_FHD       8                               /* fixed head disk */
167 #define INT_V_DP        12                              /* moving head disk */
168 #define INT_V_MT        15                              /* mag tape */
169 #define INT_V_START     16                              /* start button */
170 #define INT_V_NODEF     17                              /* int not deferred */
171 #define INT_V_ON        18                              /* int on */
172 
173 /* I/O macros */
174 
175 #define IOT_V_REASON    17
176 #define IOT_V_SKIP      16
177 #define IOT_SKIP        (1u << IOT_V_SKIP)
178 #define IORETURN(f,v)   (((f)? (v): SCPE_OK) << IOT_V_REASON)
179 #define IOBADFNC(x)     (((stop_inst) << IOT_V_REASON) | (x))
180 #define IOSKIP(x)       (IOT_SKIP | (x))
181 
182 #define INT_CLK         (1u << INT_V_CLK)
183 #define INT_MPE         (1u << INT_V_MPE)
184 #define INT_LPT         (1u << INT_V_LPT)
185 #define INT_CDR         (1u << INT_V_CDR)
186 #define INT_TTY         (1u << INT_V_TTY)
187 #define INT_PTP         (1u << INT_V_PTP)
188 #define INT_PTR         (1u << INT_V_PTR)
189 #define INT_FHD         (1u << INT_V_FHD)
190 #define INT_DP          (1u << INT_V_DP)
191 #define INT_MT          (1u << INT_V_MT)
192 #define INT_START       (1u << INT_V_START)
193 #define INT_NODEF       (1u << INT_V_NODEF)
194 #define INT_ON          (1u << INT_V_ON)
195 #define INT_NMI         (INT_START)
196 #define INT_PEND        (INT_ON | INT_NODEF)
197 
198 #define SET_INT(x)      dev_int = dev_int | (x)
199 #define CLR_INT(x)      dev_int = dev_int & ~(x)
200 #define TST_INT(x)      ((dev_int & (x)) != 0)
201 #define CLR_ENB(x)      dev_enb = dev_enb & ~(x)
202 #define TST_INTREQ(x)   ((dev_int & dev_enb & (x)) != 0)
203 
204 /* Prototypes */
205 
206 t_stat io_set_iobus (UNIT *uptr, int32 val, char *cptr, void *desc);
207 t_stat io_set_dma (UNIT *uptr, int32 val, char *cptr, void *desc);
208 t_stat io_set_dmc (UNIT *uptr, int32 val, char *cptr, void *desc);
209 t_stat io_show_chan (FILE *st, UNIT *uptr, int32 val, void *desc);
210 
211 #endif
212