OSDN Git Service

[VM][General] Merge Upstream 2017-12-15.
[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 "i8080_base.h"
15
16 class I8080 : public I8080_BASE
17 {
18 protected:
19         /* ---------------------------------------------------------------------------
20         virtual machine interfaces
21         --------------------------------------------------------------------------- */
22         
23         // memory
24         uint8_t RM8(uint16_t addr)  override
25         {
26 #ifdef I8080_MEMORY_WAIT
27                 int wait;
28                 uint8_t val = d_mem->read_data8w(addr, &wait);
29                 count -= wait;
30                 return val;
31 #else
32                 return d_mem->read_data8(addr);
33 #endif
34         }
35         void WM8(uint16_t addr, uint8_t val)  override
36         {
37 #ifdef I8080_MEMORY_WAIT
38                 int wait;
39                 d_mem->write_data8w(addr, val, &wait);
40                 count -= wait;
41 #else
42                 d_mem->write_data8(addr, val);
43 #endif
44         }
45         
46         uint16_t RM16(uint16_t addr) override
47         {
48 #ifdef I8080_MEMORY_WAIT
49                 int wait;
50                 uint16_t val = d_mem->read_data16w(addr, &wait);
51                 count -= wait;
52                 return val;
53 #else
54                 return d_mem->read_data16(addr);
55 #endif
56         }
57         void WM16(uint16_t addr, uint16_t val)  override
58         {
59 #ifdef I8080_MEMORY_WAIT
60                 int wait;
61                 d_mem->write_data16w(addr, val, &wait);
62                 count -= wait;
63 #else
64                 d_mem->write_data16(addr, val);
65 #endif
66         }
67         uint8_t FETCHOP()  override
68         {
69                 int wait;
70                 uint8_t val = d_mem->fetch_op(PC++, &wait);
71 #ifdef I8080_MEMORY_WAIT
72                 count -= wait;
73 #endif
74                 return val;
75         }
76         uint8_t FETCH8()  override
77         {
78 #ifdef I8080_MEMORY_WAIT
79                 int wait;
80                 uint8_t val = d_mem->read_data8w(PC++, &wait);
81                 count -= wait;
82                 return val;
83 #else
84                 return d_mem->read_data8(PC++);
85 #endif
86         }
87         
88         uint16_t FETCH16()  override
89         {
90 #ifdef I8080_MEMORY_WAIT
91                 int wait;
92                 uint16_t val = d_mem->read_data16w(PC, &wait);
93                 count -= wait;
94 #else
95                 uint16_t val = d_mem->read_data16(PC);
96 #endif
97                 PC += 2;
98                 return val;
99         }
100         uint16_t POP16()  override
101         {
102 #ifdef I8080_MEMORY_WAIT
103                 int wait;
104                 uint16_t val = d_mem->read_data16w(SP, &wait);
105                 count -= wait;
106 #else
107                 uint16_t val = d_mem->read_data16(SP);
108 #endif
109                 SP += 2;
110                 return val;
111         }
112         void PUSH16(uint16_t val)  override
113         {
114                 SP -= 2;
115 #ifdef I8080_MEMORY_WAIT
116                 int wait;
117                 d_mem->write_data16w(SP, val, &wait);
118                 count -= wait;
119 #else
120                 d_mem->write_data16(SP, val);
121 #endif
122         }
123         
124         // i/o
125         uint8_t IN8(uint8_t addr)  override
126         {
127 #ifdef I8080_IO_WAIT
128                 int wait;
129                 uint8_t val = d_io->read_io8w(addr, &wait);
130                 count -= wait;
131                 return val;
132 #else
133                 return d_io->read_io8(addr);
134 #endif
135         }
136         void OUT8(uint8_t addr, uint8_t val)  override
137         {
138 #ifdef I8080_IO_WAIT
139                 int wait;
140                 d_io->write_io8w(addr, val, &wait);
141                 count -= wait;
142 #else
143                 d_io->write_io8(addr, val);
144 #endif
145         }
146         
147         // interrupt
148         uint32_t ACK_INTR()  override
149         {
150                 return d_pic->get_intr_ack();
151         }
152
153         
154         void dec_count(uint8_t code) override;
155         void check_reg_c(uint8_t val) override;
156         void check_reg_e(uint8_t val) override;
157         void check_reg_l(uint8_t val) override;
158         void check_reg_sp(uint8_t val) override;
159         void INSN_0x08(void) override;
160         void INSN_0x10(void) override;
161         void RLDE(void) override;
162         void RIM(void) override;
163         void _DAA(void) override;
164         void LDEH(void) override;
165         void CMA(void) override;
166         void SIM(void) override;
167         void LDES(void) override;
168         void INSN_0xcb(void) override;
169         void INSN_0xd9(void) override;
170         void INSN_0xdd(void) override;
171         void INSN_0xed(void) override;
172         void INSN_0xfd(void) override;
173
174
175         void JMP(uint8_t c) override;
176         void CALL(uint8_t c) override;
177         void ANA(uint8_t n) override;
178         /* ---------------------------------------------------------------------------
179         opecodes
180         --------------------------------------------------------------------------- */
181         void run_one_opecode();
182         void check_interrupt();
183         //void OP(uint8_t code);
184 public:
185         I8080(VM* parent_vm, EMU* parent_emu) : I8080_BASE(parent_vm, parent_emu)
186         {
187 #ifdef HAS_I8085
188                 set_device_name(_T("i8085 CPU"));
189 #endif
190         }
191         ~I8080() {}
192         
193         // common functions
194         void initialize();
195         void reset();
196         int run(int clock);
197         void write_signal(int id, uint32_t data, uint32_t mask);
198         void save_state(FILEIO* state_fio);
199         bool load_state(FILEIO* state_fio);
200         
201 #ifdef USE_DEBUGGER
202         void set_context_debugger(DEBUGGER* device)
203         {
204                 d_debugger = device;
205         }
206 #endif
207 };
208
209 #endif
210
211