OSDN Git Service

4e99bf282ee905f82bad692863e0a991c37a6516
[csp-qt/common_source_project-fm7.git] / source / src / vm / upd7801.h
1 /*
2         Skelton for retropc emulator
3
4         Origin : MESS UPD7810 Core
5         Author : Takeda.Toshiya
6         Date   : 2006.08.21 -
7
8         [ uPD7801 ]
9 */
10
11 #ifndef _UPD7801_H_
12 #define _UPD7801_H_
13
14 #include "vm.h"
15 #include "../emu.h"
16 #include "device.h"
17
18 #define SIG_UPD7801_INTF0       0
19 #define SIG_UPD7801_INTF1       1
20 #define SIG_UPD7801_INTF2       2
21 #define SIG_UPD7801_WAIT        3
22 #define SIG_UPD7801_SI          4
23 #define SIG_UPD7801_SCK         5
24
25 // virtual i/o port address
26 #define P_A     0
27 #define P_B     1
28 #define P_C     2
29
30 #ifdef USE_DEBUGGER
31 class DEBUGGER;
32 #endif
33
34 class UPD7801 : public DEVICE
35 {
36 private:
37         /* ---------------------------------------------------------------------------
38         contexts
39         --------------------------------------------------------------------------- */
40         
41         outputs_t outputs_so;
42         DEVICE *d_mem, *d_io;
43 #ifdef USE_DEBUGGER
44         DEBUGGER *d_debugger;
45         DEVICE *d_mem_stored, *d_io_stored;
46 #endif
47         
48         /* ---------------------------------------------------------------------------
49         registers
50         --------------------------------------------------------------------------- */
51         
52         int count, period, scount, tcount;
53         bool wait;
54         
55         pair regs[8];
56         uint16 SP, PC, prevPC;
57         uint8 PSW, IRR, IFF, SIRQ, HALT, MK, MB, MC, TM0, TM1, SR;
58         // for port c
59         uint8 SAK, TO, PORTC;
60         // for serial i/o
61         bool SI, SCK;
62         int sio_count;
63         
64         /* ---------------------------------------------------------------------------
65         virtual machine interface
66         --------------------------------------------------------------------------- */
67         
68         // memory
69         inline uint8 RM8(uint16 addr);
70         inline void WM8(uint16 addr, uint8 val);
71         inline uint16 RM16(uint16 addr);
72         inline void WM16(uint16 addr, uint16 val);
73         inline uint8 FETCH8();
74         inline uint16 FETCH16();
75         inline uint16 FETCHWA();
76         inline uint8 POP8();
77         inline void PUSH8(uint8 val);
78         inline uint16 POP16();
79         inline void PUSH16(uint16 val);
80         
81         // i/o
82         inline uint8 IN8(int port);
83         inline void OUT8(int port, uint8 val);
84         inline void UPDATE_PORTC(uint8 IOM);
85         
86         /* ---------------------------------------------------------------------------
87         opecode
88         --------------------------------------------------------------------------- */
89         
90         void run_one_opecode();
91 #ifdef USE_DEBUGGER
92         void run_one_opecode_debugger();
93 #endif
94         void OP();
95         void OP48();
96         void OP4C();
97         void OP4D();
98         void OP60();
99         void OP64();
100         void OP70();
101         void OP74();
102         
103 public:
104         UPD7801(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
105         {
106                 init_output_signals(&outputs_so);
107                 SI = SCK = false;
108         }
109         ~UPD7801() {}
110         
111         // common functions
112         void initialize();
113         void reset();
114         int run(int clock);
115         void write_signal(int id, uint32 data, uint32 mask);
116         uint32 get_pc()
117         {
118                 return prevPC;
119         }
120         uint32 get_next_pc()
121         {
122                 return PC;
123         }
124 #ifdef USE_DEBUGGER
125         void *get_debugger()
126         {
127                 return d_debugger;
128         }
129         uint32 debug_prog_addr_mask()
130         {
131                 return 0xffff;
132         }
133         uint32 debug_data_addr_mask()
134         {
135                 return 0xffff;
136         }
137         void debug_write_data8(uint32 addr, uint32 data);
138         uint32 debug_read_data8(uint32 addr);
139         void debug_write_io8(uint32 addr, uint32 data);
140         uint32 debug_read_io8(uint32 addr);
141         bool debug_write_reg(const _TCHAR *reg, uint32 data);
142         void debug_regs_info(_TCHAR *buffer, size_t buffer_len);
143         int debug_dasm(uint32 pc, _TCHAR *buffer, size_t buffer_len);
144 #endif
145         void save_state(FILEIO* state_fio);
146         bool load_state(FILEIO* state_fio);
147         
148         // unique functions
149         void set_context_mem(DEVICE* device)
150         {
151                 d_mem = device;
152         }
153         void set_context_io(DEVICE* device)
154         {
155                 d_io = device;
156         }
157 #ifdef USE_DEBUGGER
158         void set_context_debugger(DEBUGGER* device)
159         {
160                 d_debugger = device;
161         }
162 #endif
163         void set_context_so(DEVICE* device, int id, uint32 mask)
164         {
165                 register_output_signal(&outputs_so, device, id, mask);
166         }
167 };
168
169 #endif