OSDN Git Service

[VM][WIP][STATE] Updating state framework to upstream 2018-10-05.Still may cause...
[csp-qt/common_source_project-fm7.git] / source / src / vm / mc6801.h
1 /*
2         Skelton for retropc emulator
3
4         Origin : MAME 0.142
5         Author : Takeda.Toshiya
6         Date  : 2011.04.23-
7
8         [ MC6801 ]
9 */
10
11 #ifndef _MC6801_H_ 
12 #define _MC6801_H_
13
14 //#include "vm.h"
15 //#include "../emu.h"
16 #include "mc6800.h"
17 #include "device.h"
18
19 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
20 #define SIG_MC6801_PORT_1       0
21 #define SIG_MC6801_PORT_2       1
22 #define SIG_MC6801_PORT_3       2
23 #define SIG_MC6801_PORT_4       3
24 #define SIG_MC6801_PORT_3_SC1   4
25 #define SIG_MC6801_PORT_3_SC2   5
26 #define SIG_MC6801_SIO_RECV     6
27
28 class DEBUGGER;
29 class FIFO;
30 //#endif
31 class MC6801 : public MC6800
32 {
33 private:
34 protected:
35         const int RMCR_SS[4] = { 16, 128, 1024, 4096 };
36 #define XX 5 // invalid opcode unknown cc
37         const uint8_t cycles[256] = {
38 //#elif defined(HAS_MC6801)
39                 XX, 2,XX,XX, 3, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2,
40                 2, 2,XX,XX,XX,XX, 2, 2,XX, 2,XX, 2,XX,XX,XX,XX,
41                 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
42                 3, 3, 4, 4, 3, 3, 3, 3, 5, 5, 3,10, 4,10, 9,12,
43                 2,XX,XX, 2, 2,XX, 2, 2, 2, 2, 2,XX, 2, 2,XX, 2,
44                 2,XX,XX, 2, 2,XX, 2, 2, 2, 2, 2,XX, 2, 2,XX, 2,
45                 6,XX,XX, 6, 6,XX, 6, 6, 6, 6, 6,XX, 6, 6, 3, 6,
46                 6,XX,XX, 6, 6,XX, 6, 6, 6, 6, 6,XX, 6, 6, 3, 6,
47                 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 6, 3, 3,
48                 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 4, 4,
49                 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 5, 5,
50                 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 5, 5,
51                 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 3,XX, 3, 3,
52                 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
53                 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5,
54                 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5
55         };
56 #undef XX
57         //#if defined(HAS_MC6801) || defined(HAS_HD6301)
58         // data
59         struct {
60                 uint8_t wreg;
61                 uint8_t rreg;
62                 uint8_t ddr;
63                 uint8_t latched_data;
64                 bool latched;
65                 // output signals
66                 outputs_t outputs;
67                 bool first_write;
68         } port[4];
69         
70         uint8_t p3csr;
71         bool p3csr_is3_flag_read;
72         bool sc1_state;
73         bool sc2_state;
74         
75         // timer
76         pair_t counter;
77         pair_t output_compare;
78         pair_t timer_over;
79         uint8_t tcsr;
80         uint8_t pending_tcsr;
81         uint16_t input_capture;
82 //#ifdef HAS_HD6301
83 //      uint16_t latch09;
84 //#endif
85         uint32_t timer_next;
86         
87         // serial i/o
88         outputs_t outputs_sio;
89         FIFO *recv_buffer;
90         uint8_t trcsr, rdr, tdr;
91         bool trcsr_read_tdre, trcsr_read_orfe, trcsr_read_rdrf;
92         uint8_t rmcr;
93         int sio_counter;
94         
95         // memory controller
96         uint8_t ram_ctrl;
97         uint8_t ram[128];
98         
99
100         uint32_t mc6801_io_r(uint32_t offset);
101         virtual void mc6801_io_w(uint32_t offset, uint32_t data);
102         void increment_counter(int amount);
103
104         uint32_t RM(uint32_t Addr) override;
105         void WM(uint32_t Addr, uint32_t Value) override;
106
107         void run_one_opecode() override;
108
109         void insn(uint8_t code) override;
110         void abx();
111         void addd_di();
112         void addd_ex();
113         void addd_im();
114         void addd_ix();
115         void asld();
116         void ldd_di();
117         void ldd_ex();
118         void ldd_im();
119         void ldd_ix();
120         void lsrd();
121         void mul();
122         void pshx();
123         void pulx();
124         void std_di();
125         void std_ex();
126         void std_im();
127         void std_ix();
128         void subd_di();
129         void subd_ex();
130         void subd_im();
131         void subd_ix();
132         void cpx_di();
133         void cpx_ex();
134         void cpx_im();
135         void cpx_ix();
136
137 //#endif
138 public:
139         MC6801(VM_TEMPLATE* parent_vm, EMU* parent_emu) : MC6800(parent_vm, parent_emu)
140         {
141                 for(int i = 0; i < 4; i++) {
142                         initialize_output_signals(&port[i].outputs);
143                         port[i].wreg = port[i].rreg = 0;//0xff;
144                 }
145                 initialize_output_signals(&outputs_sio);
146                 set_device_name(_T("MC6801 MPU"));
147         }
148         ~MC6801() {}
149         void initialize() override;
150         void release();
151         void reset() override;
152         int run(int clock) override;
153         void write_signal(int id, uint32_t data, uint32_t mask) override;
154         bool process_state(FILEIO* state_fio, bool loading);
155
156
157         int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len) override;
158 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
159         void set_context_port1(DEVICE* device, int id, uint32_t mask, int shift)
160         {
161                 register_output_signal(&port[0].outputs, device, id, mask, shift);
162         }
163         void set_context_port2(DEVICE* device, int id, uint32_t mask, int shift)
164         {
165                 register_output_signal(&port[1].outputs, device, id, mask, shift);
166         }
167         void set_context_port3(DEVICE* device, int id, uint32_t mask, int shift)
168         {
169                 register_output_signal(&port[2].outputs, device, id, mask, shift);
170         }
171         void set_context_port4(DEVICE* device, int id, uint32_t mask, int shift)
172         {
173                 register_output_signal(&port[2].outputs, device, id, mask, shift);
174         }
175         void set_context_sio(DEVICE* device, int id)
176         {
177                 register_output_signal(&outputs_sio, device, id, 0xff);
178         }
179 //#endif
180 };
181
182 #endif