OSDN Git Service

[VM][FM7] keyboard.cpp : Add implementation ofd RTC, includes within keyboard.
[csp-qt/common_source_project-fm7.git] / source / src / vm / i8080.h
1 /*
2         Skelton for retropc emulator
3
4         Origin : MAME
5         Author : Takeda.Toshiya
6         Date   : 2008.11.04 -
7
8         [ i8080 / i8085 ]
9 */
10
11 #ifndef _I8080_H_ 
12 #define _I8080_H_
13
14 #include "vm.h"
15 #include "../emu.h"
16 #include "device.h"
17
18 #define SIG_I8080_INTR  0
19 #ifdef HAS_I8085
20 #define SIG_I8085_RST5  1
21 #define SIG_I8085_RST6  2
22 #define SIG_I8085_RST7  3
23 #define SIG_I8085_SID   4
24 #endif
25
26 #ifdef USE_DEBUGGER
27 class DEBUGGER;
28 #endif
29
30 class I8080 : public DEVICE
31 {
32 private:
33         /* ---------------------------------------------------------------------------
34         contexts
35         --------------------------------------------------------------------------- */
36         
37         DEVICE *d_mem, *d_io, *d_pic;
38 #ifdef USE_DEBUGGER
39         DEBUGGER *d_debugger;
40         DEVICE *d_mem_stored, *d_io_stored;
41 #endif
42         
43         // output signals
44         outputs_t outputs_busack;
45         outputs_t outputs_sod;
46         
47         /* ---------------------------------------------------------------------------
48         registers
49         --------------------------------------------------------------------------- */
50         
51         int count;
52         pair regs[4];
53         uint16 SP, PC, prevPC;
54         uint16 IM, RIM_IEN;
55         bool HALT, BUSREQ, SID, afterEI;
56         
57         /* ---------------------------------------------------------------------------
58         virtual machine interfaces
59         --------------------------------------------------------------------------- */
60         
61         // memory
62         inline uint8 RM8(uint16 addr)
63         {
64 #ifdef I8080_MEMORY_WAIT
65                 int wait;
66                 uint8 val = d_mem->read_data8w(addr, &wait);
67                 count -= wait;
68                 return val;
69 #else
70                 return d_mem->read_data8(addr);
71 #endif
72         }
73         inline void WM8(uint16 addr, uint8 val)
74         {
75 #ifdef I8080_MEMORY_WAIT
76                 int wait;
77                 d_mem->write_data8w(addr, val, &wait);
78                 count -= wait;
79 #else
80                 d_mem->write_data8(addr, val);
81 #endif
82         }
83         
84         inline uint16 RM16(uint16 addr)
85         {
86 #ifdef I8080_MEMORY_WAIT
87                 int wait;
88                 uint16 val = d_mem->read_data16w(addr, &wait);
89                 count -= wait;
90                 return val;
91 #else
92                 return d_mem->read_data16(addr);
93 #endif
94         }
95         inline void WM16(uint16 addr, uint16 val)
96         {
97 #ifdef I8080_MEMORY_WAIT
98                 int wait;
99                 d_mem->write_data16w(addr, val, &wait);
100                 count -= wait;
101 #else
102                 d_mem->write_data16(addr, val);
103 #endif
104         }
105         inline uint8 FETCHOP()
106         {
107 #ifdef I8080_MEMORY_WAIT
108                 int wait;
109                 uint8 val = d_mem->read_data8w(PC++, &wait);
110                 count -= wait;
111                 return val;
112 #else
113                 return d_mem->read_data8(PC++);
114 #endif
115         }
116         inline uint8 FETCH8()
117         {
118 #ifdef I8080_MEMORY_WAIT
119                 int wait;
120                 uint8 val = d_mem->read_data8w(PC++, &wait);
121                 count -= wait;
122                 return val;
123 #else
124                 return d_mem->read_data8(PC++);
125 #endif
126         }
127         inline uint16 FETCH16()
128         {
129 #ifdef I8080_MEMORY_WAIT
130                 int wait;
131                 uint16 val = d_mem->read_data16w(PC, &wait);
132                 count -= wait;
133 #else
134                 uint16 val = d_mem->read_data16(PC);
135 #endif
136                 PC += 2;
137                 return val;
138         }
139         inline uint16 POP16()
140         {
141 #ifdef I8080_MEMORY_WAIT
142                 int wait;
143                 uint16 val = d_mem->read_data16w(SP, &wait);
144                 count -= wait;
145 #else
146                 uint16 val = d_mem->read_data16(SP);
147 #endif
148                 SP += 2;
149                 return val;
150         }
151         inline void PUSH16(uint16 val)
152         {
153                 SP -= 2;
154 #ifdef I8080_MEMORY_WAIT
155                 int wait;
156                 d_mem->write_data16w(SP, val, &wait);
157                 count -= wait;
158 #else
159                 d_mem->write_data16(SP, val);
160 #endif
161         }
162         
163         // i/o
164         inline uint8 IN8(uint8 addr)
165         {
166 #ifdef I8080_IO_WAIT
167                 int wait;
168                 uint8 val = d_io->read_io8w(addr, &wait);
169                 count -= wait;
170                 return val;
171 #else
172                 return d_io->read_io8(addr);
173 #endif
174         }
175         inline void OUT8(uint8 addr, uint8 val)
176         {
177 #ifdef I8080_IO_WAIT
178                 int wait;
179                 d_io->write_io8w(addr, val, &wait);
180                 count -= wait;
181 #else
182                 d_io->write_io8(addr, val);
183 #endif
184         }
185         
186         // interrupt
187         inline uint32 ACK_INTR()
188         {
189                 return d_pic->intr_ack();
190         }
191         
192         /* ---------------------------------------------------------------------------
193         opecodes
194         --------------------------------------------------------------------------- */
195         
196         void run_one_opecode();
197         void OP(uint8 code);
198         
199 public:
200         I8080(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
201         {
202                 BUSREQ = false;
203                 SID = true;
204                 init_output_signals(&outputs_busack);
205                 init_output_signals(&outputs_sod);
206         }
207         ~I8080() {}
208         
209         // common functions
210         void initialize();
211         void reset();
212         int run(int clock);
213         void write_signal(int id, uint32 data, uint32 mask);
214         void set_intr_line(bool line, bool pending, uint32 bit);
215         uint32 get_pc()
216         {
217                 return prevPC;
218         }
219         uint32 get_next_pc()
220         {
221                 return PC;
222         }
223 #ifdef USE_DEBUGGER
224         void *get_debugger()
225         {
226                 return d_debugger;
227         }
228         uint32 debug_prog_addr_mask()
229         {
230                 return 0xffff;
231         }
232         uint32 debug_data_addr_mask()
233         {
234                 return 0xffff;
235         }
236         void debug_write_data8(uint32 addr, uint32 data);
237         uint32 debug_read_data8(uint32 addr);
238         void debug_write_io8(uint32 addr, uint32 data);
239         uint32 debug_read_io8(uint32 addr);
240         bool debug_write_reg(_TCHAR *reg, uint32 data);
241         void debug_regs_info(_TCHAR *buffer, size_t buffer_len);
242         int debug_dasm(uint32 pc, _TCHAR *buffer, size_t buffer_len);
243 #endif
244         
245         void save_state(FILEIO* state_fio);
246         bool load_state(FILEIO* state_fio);
247         // unique function
248         void set_context_mem(DEVICE* device)
249         {
250                 d_mem = device;
251         }
252         void set_context_io(DEVICE* device)
253         {
254                 d_io = device;
255         }
256         void set_context_intr(DEVICE* device)
257         {
258                 d_pic = device;
259         }
260 #ifdef USE_DEBUGGER
261         void set_context_debugger(DEBUGGER* device)
262         {
263                 d_debugger = device;
264         }
265 #endif
266         void set_context_busack(DEVICE* device, int id, uint32 mask)
267         {
268                 register_output_signal(&outputs_busack, device, id, mask);
269         }
270         void set_context_sod(DEVICE* device, int id, uint32 mask)
271         {
272                 register_output_signal(&outputs_sod, device, id, mask);
273         }
274 };
275
276 #endif
277
278