1 /*  mp-a2.c: SWTP MP-A2 M6800 CPU simulator
2 
3     Copyright (c) 2011, William Beech
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     WILLIAM A. BEECH 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 William A. Beech shall not
23     be used in advertising or otherwise to promote the sale, use or other dealings
24     in this Software without prior written authorization from William A. Beech.
25 
26     The MP-A2 CPU Board contains the following devices [mp-a2.c]:
27         M6800 processor [m6800.c].
28         M6810 128 byte RAM at 0xA000 [m6810.c].
29         M6830, SWTBUG, or custom boot ROM at 0xE000 [bootrom.c].
30         4 ea 2716 EPROMs at either 0xC000, 0xC800, 0xD000 and 0xD800 (LO_PROM)or
31             0xE000, 0xE800, 0xF000 and 0xF800 (HI_PROM) [eprom.c].
32         Interface to the SS-50 bus and the MP-B2 Mother Board for I/O
33             and memory boards [mp-b2.c].
34         Note: The file names of the emulator source programs for each device are
35         contained in "[]".
36 */
37 
38 #include <stdio.h>
39 #include "swtp_defs.h"
40 
41 #define UNIT_V_USER_D   (UNIT_V_UF)     /* user defined switch */
42 #define UNIT_USER_D     (1 << UNIT_V_USER_D)
43 #define UNIT_V_4K_8K    (UNIT_V_UF+1)   /* off if HI_PROM and only 2K EPROM */
44 #define UNIT_4K_8K      (1 << UNIT_V_4K_8K)
45 #define UNIT_V_SWT      (UNIT_V_UF+2)   /* on SWTBUG, off MIKBUG */
46 #define UNIT_SWT        (1 << UNIT_V_SWT)
47 #define UNIT_V_8K       (UNIT_V_UF+3)   /* off if HI_PROM and only 2K or 4k EPROM */
48 #define UNIT_8K         (1 << UNIT_V_8K)
49 #define UNIT_V_RAM      (UNIT_V_UF+4)   /* off disables 6810 RAM */
50 #define UNIT_RAM        (1 << UNIT_V_RAM)
51 #define UNIT_V_LO_PROM  (UNIT_V_UF+5)   /* on EPROMS @ C000-CFFFH, off no EPROMS */
52 #define UNIT_LO_PROM    (1 << UNIT_V_LO_PROM)
53 #define UNIT_V_HI_PROM  (UNIT_V_UF+6)   /* on EPROMS @ F000-FFFFH, off fo LO_PROM, MON, or no EPROMS */
54 #define UNIT_HI_PROM    (1 << UNIT_V_HI_PROM)
55 #define UNIT_V_MON      (UNIT_V_UF+7)   /* on for monitor vectors in high memory */
56 #define UNIT_MON        (1 << UNIT_V_MON)
57 
58 /* local global variables */
59 
60 /* function prototypes */
61 
62 int32 get_base(void);
63 int32 CPU_BD_get_mbyte(int32 addr);
64 int32 CPU_BD_get_mword(int32 addr);
65 void CPU_BD_put_mbyte(int32 addr, int32 val);
66 void CPU_BD_put_mword(int32 addr, int32 val);
67 
68 /* external routines */
69 
70 /* MP-B2 bus routines */
71 extern int32 MB_get_mbyte(int32 addr);
72 extern int32 MB_get_mword(int32 addr);
73 extern void MB_put_mbyte(int32 addr, int32 val);
74 extern void MB_put_mword(int32 addr, int32 val);
75 
76 /* M6810 bus routines */
77 extern int32 m6810_get_mbyte(int32 addr);
78 extern void m6810_put_mbyte(int32 addr, int32 val);
79 
80 /* BOOTROM bus routines */
81 extern UNIT BOOTROM_unit;
82 extern int32 BOOTROM_get_mbyte(int32 offset);
83 
84 /* I2716 bus routines */
85 extern int32 i2716_get_mbyte(int32 offset);
86 
87 /* MP-A2 data structures
88 
89    CPU_BD_dev        MP-A2 device descriptor
90    CPU_BD_unit       MP-A2 unit descriptor
91    CPU_BD_reg        MP-A2 register list
92    CPU_BD_mod        MP-A2 modifiers list */
93 
94 UNIT CPU_BD_unit = { UDATA (NULL, 0, 0) };
95 
96 REG CPU_BD_reg[] = {
97     { NULL }
98 };
99 
100 MTAB CPU_BD_mod[] = {
101     { UNIT_USER_D, UNIT_USER_D, "USER_D", "USER_D", NULL },
102     { UNIT_USER_D, 0, "NOUSER_D", "NOUSER_D", NULL },
103     { UNIT_4K_8K, UNIT_4K_8K, "4K_8K", "4K_8K", NULL },
104     { UNIT_4K_8K, 0, "NO4K_8K", "NO4K_8K", NULL },
105     { UNIT_SWT, UNIT_SWT, "SWT", "SWT", NULL },
106     { UNIT_SWT, 0, "NOSWT", "NOSWT", NULL },
107     { UNIT_8K, UNIT_8K, "8K", "8K", NULL },
108     { UNIT_8K, 0, "NO8K", "NO8K", NULL },
109     { UNIT_RAM, UNIT_RAM, "RAM", "RAM", NULL },
110     { UNIT_RAM, 0, "NORAM", "NORAM", NULL },
111     { UNIT_LO_PROM, UNIT_LO_PROM, "LO_PROM", "LO_PROM", NULL },
112     { UNIT_LO_PROM, 0, "NOLO_PROM", "NOLO_PROM", NULL },
113     { UNIT_HI_PROM, UNIT_HI_PROM, "HI_PROM", "HI_PROM", NULL },
114     { UNIT_HI_PROM, 0, "NOHI_PROM", "NOHI_PROM", NULL },
115     { UNIT_MON, UNIT_MON, "MON", "MON", NULL },
116     { UNIT_MON, 0, "NOMON", "NOMON", NULL },
117     { 0 }
118 };
119 
120 DEBTAB CPU_BD_debug[] = {
121     { "ALL", DEBUG_all },
122     { "FLOW", DEBUG_flow },
123     { "READ", DEBUG_read },
124     { "WRITE", DEBUG_write },
125     { "LEV1", DEBUG_level1 },
126     { "LEV2", DEBUG_level2 },
127     { NULL }
128 };
129 
130 DEVICE CPU_BD_dev = {
131     "MP-A2",                            //name
132     &CPU_BD_unit,                        //units
133     CPU_BD_reg,                          //registers
134     CPU_BD_mod,                          //modifiers
135     1,                                  //numunits
136     16,                                 //aradix
137     16,                                 //awidth
138     1,                                  //aincr
139     16,                                 //dradix
140     8,                                  //dwidth
141     NULL,                               //examine
142     NULL,                               //deposit
143     NULL,                               //reset
144     NULL,                               //boot
145     NULL,                               //attach
146     NULL,                               //detach
147     NULL,                               //ctxt
148     DEV_DEBUG,                          //flags
149     0,                                  //dctrl
150     CPU_BD_debug,                       /* debflags */
151     NULL,                               //msize
152     NULL                                //lname
153 };
154 
155 /*  get base address of 2716's */
156 
get_base(void)157 int32 get_base(void)
158 {
159     if (CPU_BD_unit.flags & UNIT_LO_PROM)
160         return 0xC000;
161     else if (CPU_BD_unit.flags & UNIT_HI_PROM)
162         return 0xF000;
163     return 0;
164 }
165 
166 /*  get a byte from memory */
167 
CPU_BD_get_mbyte(int32 addr)168 int32 CPU_BD_get_mbyte(int32 addr)
169 {
170     int32 val;
171 
172     if (CPU_BD_dev.dctrl & DEBUG_read)
173         printf("CPU_BD_get_mbyte: addr=%04X\n", addr);
174     switch(addr & 0xF000) {
175         case 0xA000:
176             if (CPU_BD_unit.flags & UNIT_RAM) {
177                 val = m6810_get_mbyte(addr - 0xA000) & 0xFF;
178                 if (CPU_BD_dev.dctrl & DEBUG_read)
179                     printf("CPU_BD_get_mbyte: m6810 val=%02X\n", val);
180                 return val;
181             } else {
182                 val = MB_get_mbyte(addr) & 0xFF;
183                 if (CPU_BD_dev.dctrl & DEBUG_read)
184                     printf("CPU_BD_get_mbyte: m6810 val=%02X\n", val);
185                 return val;
186             }
187         case 0xC000:
188             if (CPU_BD_unit.flags & UNIT_LO_PROM) {
189                 val = i2716_get_mbyte(addr - 0xC000) & 0xFF;
190                 if (CPU_BD_dev.dctrl & DEBUG_read)
191                     printf("CPU_BD_get_mbyte: 2716=%02X\n", val);
192                 return val;
193             } else
194                 return 0xFF;
195             break;
196         case 0xE000:
197             val = BOOTROM_get_mbyte(addr - 0xE000) & 0xFF;
198             if (CPU_BD_dev.dctrl & DEBUG_read)
199                 printf("CPU_BD_get_mbyte: EPROM=%02X\n", val);
200             return val;
201         case 0xF000:
202             if (CPU_BD_unit.flags & UNIT_MON) {
203                 val = BOOTROM_get_mbyte(addr - (0x10000 - BOOTROM_unit.capac)) & 0xFF;
204                 if (CPU_BD_dev.dctrl & DEBUG_read)
205                     printf("CPU_BD_get_mbyte: EPROM=%02X\n", val);
206                 return val;
207             }
208         default:
209             val = MB_get_mbyte(addr) & 0xFF;
210             if (CPU_BD_dev.dctrl & DEBUG_read)
211                 printf("CPU_BD_get_mbyte: mp_b2 val=%02X\n", val);
212             return val;
213     }
214 }
215 
216 /*  get a word from memory */
217 
CPU_BD_get_mword(int32 addr)218 int32 CPU_BD_get_mword(int32 addr)
219 {
220     int32 val;
221 
222     if (CPU_BD_dev.dctrl & DEBUG_read)
223         printf("CPU_BD_get_mword: addr=%04X\n", addr);
224     val = (CPU_BD_get_mbyte(addr) << 8);
225     val |= CPU_BD_get_mbyte(addr+1);
226     val &= 0xFFFF;
227     if (CPU_BD_dev.dctrl & DEBUG_read)
228         printf("CPU_BD_get_mword: val=%04X\n", val);
229     return val;
230 }
231 
232 /*  put a byte to memory */
233 
CPU_BD_put_mbyte(int32 addr,int32 val)234 void CPU_BD_put_mbyte(int32 addr, int32 val)
235 {
236     if (CPU_BD_dev.dctrl & DEBUG_write)
237         printf("CPU_BD_put_mbyte: addr=%04X, val=%02X\n", addr, val);
238     switch(addr & 0xF000) {
239         case 0xA000:
240             if (CPU_BD_unit.flags & UNIT_RAM) {
241                 m6810_put_mbyte(addr - 0xA000, val);
242                 return;
243             } else {
244                 MB_put_mbyte(addr, val);
245                 return;
246             }
247         default:
248             MB_put_mbyte(addr, val);
249             return;
250     }
251 }
252 
253 /*  put a word to memory */
254 
CPU_BD_put_mword(int32 addr,int32 val)255 void CPU_BD_put_mword(int32 addr, int32 val)
256 {
257     if (CPU_BD_dev.dctrl & DEBUG_write)
258         printf("CPU_BD_put_mword: addr=%04X, val=%04X\n", addr, val);
259     CPU_BD_put_mbyte(addr, val >> 8);
260     CPU_BD_put_mbyte(addr+1, val);
261 }
262 
263 /* end of mp-a2.c */
264