1 /*  altairz80_defs.h: MITS Altair simulator definitions
2 
3     Copyright (c) 2002-2011, Peter Schorn
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     PETER SCHORN 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 Peter Schorn 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 Peter Schorn.
25 
26     Based on work by Charles E Owen (c) 1997
27 */
28 
29 #include "sim_defs.h"                                       /* simulator definitions                        */
30 
31 #define MAXBANKSIZE             65536                       /* maximum memory size, a power of 2            */
32 #define MAXBANKSIZELOG2         16                          /* log2 of MAXBANKSIZE                          */
33 #define MAXBANKS                16                          /* max number of memory banks, a power of 2     */
34 #define MAXBANKSLOG2            4                           /* log2 of MAXBANKS                             */
35 #define MAXMEMORY               (MAXBANKS * MAXBANKSIZE)    /* maximum, total memory size                   */
36 #define ADDRMASK                (MAXBANKSIZE - 1)           /* address mask                                 */
37 #define ADDRMASKEXTENDED        (MAXMEMORY - 1)             /* extended address mask                        */
38 #define BANKMASK                (MAXBANKS - 1)              /* bank mask                                    */
39 #define MEMORYSIZE              (cpu_unit.capac)            /* actual memory size                           */
40 #define KB                      1024                        /* kilo byte                                    */
41 #define KBLOG2                  10                          /* log2 of KB                                   */
42 #define ALTAIR_ROM_LOW          0xff00                      /* start address of regular Altair ROM          */
43 #define RESOURCE_TYPE_MEMORY    1
44 #define RESOURCE_TYPE_IO        2
45 
46 #define NUM_OF_DSK              16                          /* NUM_OF_DSK must be power of two              */
47 #define LDA_INSTRUCTION         0x3e                        /* op-code for LD A,<8-bit value> instruction   */
48 #define UNIT_NO_OFFSET_1        0x37                        /* LD A,<unitno>                                */
49 #define UNIT_NO_OFFSET_2        0xb4                        /* LD a,80h | <unitno>                          */
50 
51 #define CHIP_TYPE_8080          0
52 #define CHIP_TYPE_Z80           1
53 #define CHIP_TYPE_8086          2
54 #define MAX_CHIP_TYPE           CHIP_TYPE_8086
55 
56 /* simulator stop codes */
57 #define STOP_HALT       0   /* HALT                                             */
58 #define STOP_IBKPT      1   /* breakpoint   (program counter)                   */
59 #define STOP_MEM        2   /* breakpoint   (memory access)                     */
60 #define STOP_INSTR      3   /* breakpoint   (instruction access)                */
61 #define STOP_OPCODE     4   /* invalid operation encountered (8080, Z80, 8086)  */
62 
63 #define UNIT_CPU_V_OPSTOP       (UNIT_V_UF+0)               /* stop on invalid operation                    */
64 #define UNIT_CPU_OPSTOP         (1 << UNIT_CPU_V_OPSTOP)
65 #define UNIT_CPU_V_BANKED       (UNIT_V_UF+1)               /* banked memory is used                        */
66 #define UNIT_CPU_BANKED         (1 << UNIT_CPU_V_BANKED)
67 #define UNIT_CPU_V_ALTAIRROM    (UNIT_V_UF+2)               /* ALTAIR ROM exists                            */
68 #define UNIT_CPU_ALTAIRROM      (1 << UNIT_CPU_V_ALTAIRROM)
69 #define UNIT_CPU_V_VERBOSE      (UNIT_V_UF+3)               /* warn if ROM is written to                    */
70 #define UNIT_CPU_VERBOSE        (1 << UNIT_CPU_V_VERBOSE)
71 #define UNIT_CPU_V_MMU          (UNIT_V_UF+4)               /* use MMU and slower CPU                       */
72 #define UNIT_CPU_MMU            (1 << UNIT_CPU_V_MMU)
73 #define UNIT_CPU_V_STOPONHALT   (UNIT_V_UF+5)               /* stop simulation on HALT                      */
74 #define UNIT_CPU_STOPONHALT     (1 << UNIT_CPU_V_STOPONHALT)
75 #define UNIT_CPU_V_SWITCHER     (UNIT_V_UF+6)               /* switcher 8086 <--> 8080/Z80 enabled          */
76 #define UNIT_CPU_SWITCHER       (1 << UNIT_CPU_V_SWITCHER)
77 
78 #if defined (__linux) || defined(__NetBSD__) || defined (__OpenBSD__) || defined (__FreeBSD__) || defined (__APPLE__)
79 #define UNIX_PLATFORM 1
80 #else
81 #define UNIX_PLATFORM 0
82 #endif
83 
84 #define ADDRESS_FORMAT          "[0x%05x]"
85 
86 /* use NLP for new line printing while the simulation is running */
87 #if UNIX_PLATFORM
88 #define NLP "\r\n"
89 #else
90 #define NLP "\n"
91 #endif
92 
93 #if (defined (__MWERKS__) && defined (macintosh)) || defined(__DECC)
94 #define __FUNCTION__ __FILE__
95 #endif
96 
97 typedef struct {
98     uint32 mem_base;    /* Memory Base Address */
99     uint32 mem_size;    /* Memory Address space requirement */
100     uint32 io_base;     /* I/O Base Address */
101     uint32 io_size;     /* I/O Address Space requirement */
102 } PNP_INFO;
103