OSDN Git Service

[VM][General] Apply Upstream 2018-10-07.Still WIP.
[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
53         uint64_t total_count;
54         uint64_t prev_total_count;
55
56         int count, period, scount, tcount;
57         bool wait;
58         
59         pair32_t regs[8];
60         uint16_t SP, PC, prevPC;
61         uint8_t PSW, IRR, IFF, SIRQ, HALT, MK, MB, MC, TM0, TM1, SR;
62         // for port c
63         uint8_t SAK, TO, HLDA, PORTC;
64         // for serial i/o
65         bool SI, SCK;
66         int sio_count;
67         
68         /* ---------------------------------------------------------------------------
69         virtual machine interface
70         --------------------------------------------------------------------------- */
71         
72         // memory
73         inline uint8_t RM8(uint16_t addr);
74         inline void WM8(uint16_t addr, uint8_t val);
75         inline uint16_t RM16(uint16_t addr);
76         inline void WM16(uint16_t addr, uint16_t val);
77         inline uint8_t FETCH8();
78         inline uint16_t FETCH16();
79         inline uint16_t FETCHWA();
80         inline uint8_t POP8();
81         inline void PUSH8(uint8_t val);
82         inline uint16_t POP16();
83         inline void PUSH16(uint16_t val);
84         
85         // i/o
86         inline uint8_t IN8(int port);
87         inline void OUT8(int port, uint8_t val);
88         inline void UPDATE_PORTC(uint8_t IOM);
89
90         bool __USE_DEBUGGER;
91         bool __UPD7801_MEMORY_WAIT;
92         
93         /* ---------------------------------------------------------------------------
94         opecode
95         --------------------------------------------------------------------------- */
96         
97         void run_one_opecode();
98 //#ifdef USE_DEBUGGER
99         void run_one_opecode_debugger();
100 //#endif
101         void OP();
102         void OP48();
103         void OP4C();
104         void OP4D();
105         void OP60();
106         void OP64();
107         void OP70();
108         void OP74();
109         
110 public:
111         UPD7801(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
112         {
113
114                 total_count = prev_total_count = 0;
115
116                 initialize_output_signals(&outputs_so);
117                 SI = SCK = false;
118                 d_debugger = NULL;
119                 d_mem_stored = d_io_stored = NULL;
120                 __USE_DEBUGGER = __UPD7801_MEMORY_WAIT = false;
121                 set_device_name(_T("uPD7801 CPU"));
122         }
123         ~UPD7801() {}
124         
125         // common functions
126         void initialize();
127         void reset();
128         int run(int clock);
129         void write_signal(int id, uint32_t data, uint32_t mask);
130         uint32_t get_pc()
131         {
132                 return prevPC;
133         }
134         uint32_t get_next_pc()
135         {
136                 return PC;
137         }
138 //#ifdef USE_DEBUGGER
139         void *get_debugger()
140         {
141                 return d_debugger;
142         }
143         uint32_t get_debug_prog_addr_mask()
144         {
145                 return 0xffff;
146         }
147         uint32_t get_debug_data_addr_mask()
148         {
149                 return 0xffff;
150         }
151         void write_debug_data8(uint32_t addr, uint32_t data);
152         uint32_t read_debug_data8(uint32_t addr);
153         void write_debug_io8(uint32_t addr, uint32_t data);
154         uint32_t read_debug_io8(uint32_t addr);
155         bool write_debug_reg(const _TCHAR *reg, uint32_t data);
156         void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
157         int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
158 //#endif
159         bool process_state(FILEIO* state_fio, bool loading);
160         
161         // unique functions
162         void set_context_mem(DEVICE* device)
163         {
164                 d_mem = device;
165         }
166         void set_context_io(DEVICE* device)
167         {
168                 d_io = device;
169         }
170 //#ifdef USE_DEBUGGER
171         void set_context_debugger(DEBUGGER* device)
172         {
173                 d_debugger = device;
174         }
175 //#endif
176         void set_context_so(DEVICE* device, int id, uint32_t mask)
177         {
178                 register_output_signal(&outputs_so, device, id, mask);
179         }
180 };
181
182 #endif