First Commit of my working state
[simh.git] / AltairZ80 / altairz80_defs.h
1 /* altairz80_defs.h: MITS Altair simulator definitions
2
3 Copyright (c) 2002-2008, 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 8 /* 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
55 /* simulator stop codes */
56 #define STOP_HALT 0 /* HALT */
57 #define STOP_IBKPT 1 /* breakpoint (program counter) */
58 #define STOP_MEM 2 /* breakpoint (memory access) */
59 #define STOP_OPCODE 3 /* invalid operation encountered (8080, Z80, 8086) */
60
61 #define UNIT_CPU_V_OPSTOP (UNIT_V_UF+0) /* stop on invalid operation */
62 #define UNIT_CPU_OPSTOP (1 << UNIT_CPU_V_OPSTOP)
63 #define UNIT_CPU_V_BANKED (UNIT_V_UF+1) /* banked memory is used */
64 #define UNIT_CPU_BANKED (1 << UNIT_CPU_V_BANKED)
65 #define UNIT_CPU_V_ALTAIRROM (UNIT_V_UF+2) /* ALTAIR ROM exists */
66 #define UNIT_CPU_ALTAIRROM (1 << UNIT_CPU_V_ALTAIRROM)
67 #define UNIT_CPU_V_VERBOSE (UNIT_V_UF+3) /* warn if ROM is written to */
68 #define UNIT_CPU_VERBOSE (1 << UNIT_CPU_V_VERBOSE)
69 #define UNIT_CPU_V_MMU (UNIT_V_UF+4) /* use MMU and slower CPU */
70 #define UNIT_CPU_MMU (1 << UNIT_CPU_V_MMU)
71 #define UNIT_CPU_V_STOPONHALT (UNIT_V_UF+5) /* stop simulation on HALT */
72 #define UNIT_CPU_STOPONHALT (1 << UNIT_CPU_V_STOPONHALT)
73
74 #ifdef CPUSWITCHER
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 #endif
78
79 #define UNIX_PLATFORM (defined (__linux) || defined(__NetBSD__) \
80 || defined (__OpenBSD__) || defined (__FreeBSD__) || defined (__APPLE__))
81
82 #define ADDRESS_FORMAT "[0x%05x]"
83 #define PC_FORMAT "\n" ADDRESS_FORMAT " "
84 #define MESSAGE_1(p1) \
85 sprintf(messageBuffer,PC_FORMAT p1,PCX); printMessage()
86 #define MESSAGE_2(p1,p2) \
87 sprintf(messageBuffer,PC_FORMAT p1,PCX,p2); printMessage()
88 #define MESSAGE_3(p1,p2,p3) \
89 sprintf(messageBuffer,PC_FORMAT p1,PCX,p2,p3); printMessage()
90 #define MESSAGE_4(p1,p2,p3,p4) \
91 sprintf(messageBuffer,PC_FORMAT p1,PCX,p2,p3,p4); printMessage()
92 #define MESSAGE_5(p1,p2,p3,p4,p5) \
93 sprintf(messageBuffer,PC_FORMAT p1,PCX,p2,p3,p4,p5); printMessage()
94 #define MESSAGE_6(p1,p2,p3,p4,p5,p6) \
95 sprintf(messageBuffer,PC_FORMAT p1,PCX,p2,p3,p4,p5,p6); printMessage()
96 #define MESSAGE_7(p1,p2,p3,p4,p5,p6,p7) \
97 sprintf(messageBuffer,PC_FORMAT p1,PCX,p2,p3,p4,p5,p6,p7); printMessage()
98
99 /* use NLP for new line printing while the simulation is running */
100 #if UNIX_PLATFORM
101 #define NLP "\r\n"
102 #else
103 #define NLP "\n"
104 #endif
105
106 #define TRACE_PRINT(level, args) if(trace_level & level) { \
107 printf args; \
108 }
109
110 #if defined (__MWERKS__) && defined (macintosh)
111 #define __FUNCTION__ __FILE__
112 #endif
113
114 typedef struct {
115 uint32 mem_base; /* Memory Base Address */
116 uint32 mem_size; /* Memory Address space requirement */
117 uint32 io_base; /* I/O Base Address */
118 uint32 io_size; /* I/O Address Space requirement */
119 } PNP_INFO;