1 /*
2  * Copyright 2001 by Arto Salmi and Joze Fabcic
3  * Copyright 2006 by Brian Dominy <brian@oddchange.com>
4  *
5  * This file is part of GCC6809.
6  *
7  * GCC6809 is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * GCC6809 is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GCC6809; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 
23 #ifndef M6809_H
24 #define M6809_H
25 
26 #include "vice.h"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 
32 #ifdef HAVE_STDINT_H
33 #include <stdint.h>
34 #endif
35 
36 #include "alarm.h"
37 #include "interrupt.h"
38 
39 /* Uncomment the following if you want emulation of the
40    6809 illegal/undocumented opcodes/behaviour. */
41 #define FULL6809
42 
43 /* Uncomment the following if you want emulation of the
44    6309 CPU. */
45 /* #define H6309 */
46 
47 /* Sanity check */
48 #if defined(FULL6809) && defined(H6309)
49 #error cannot use FULL6809 and H6309 at the same time.
50 #endif
51 
52 typedef uint8_t UINT8;
53 typedef int8_t INT8;
54 
55 typedef uint16_t UINT16;
56 typedef int16_t INT16;
57 
58 typedef uint16_t target_addr_t;
59 
60 typedef unsigned int absolute_address_t;
61 
62 #define MAX_CPU_ADDR 65536
63 
64 /* end of #include "machine.h" */
65 
66 #define E_FLAG 0x80
67 #define F_FLAG 0x40
68 #define H_FLAG 0x20
69 #define I_FLAG 0x10
70 #define N_FLAG 0x08
71 #define Z_FLAG 0x04
72 #define V_FLAG 0x02
73 #define C_FLAG 0x01
74 
75 /* Primitive read/write macros */
76 #define read8(addr)      mem6809_read((addr))
77 #define write8(addr, val) mem6809_store((addr), (val))
78 
79 
80 /* 16-bit versions */
81 #define read16(addr)       mem6809_read16((addr))
82 #define write16(addr, val)                   \
83     do {                                     \
84         write8((addr) + 1, (val) & 0xFF);    \
85         write8((addr), ((val) >> 8) & 0xFF); \
86     } while (0)
87 
88 
89 /* 32-bit versions */
90 #ifdef H6309
91 #define read32(addr)       mem6809_read32((addr))
92 #define write32(addr, val)                       \
93     do {                                         \
94         write16((addr) + 2, (val) & 0xFFFF);     \
95         write16((addr), ((val) >> 16) & 0xFFFF); \
96     } while (0)
97 #endif
98 
99 /* Fetch macros */
100 
101 #define abs_read8(addr)    read8(addr)
102 #define abs_read16(addr)   ((abs_read8(addr) << 8) | abs_read8(addr + 1))
103 
104 #define fetch8()           abs_read8 (pc++)
105 #define fetch16()          (pc += 2, abs_read16(pc - 2))
106 
107 /* 6809.c */
108 extern void h6809_mainloop (struct interrupt_cpu_status_s *, struct alarm_context_s *);
109 extern void cpu6809_reset (void);
110 struct snapshot_s;
111 extern int cpu6809_snapshot_write_module(struct snapshot_s *s);
112 extern int cpu6809_snapshot_read_module(struct snapshot_s *s);
113 
114 #endif /* M6809_H */
115