OSDN Git Service

[General] Completely merge upstream 2019-01-11.
[csp-qt/common_source_project-fm7.git] / source / src / vm / m6502.h
1 /*
2         Skelton for retropc emulator
3
4         Origin : MAME
5         Author : Takeda.Toshiya
6         Date   : 2010.08.10-
7
8         [ M6502 ]
9 */
10
11 #ifndef _M6502_H_ 
12 #define _M6502_H_
13
14 //#include "vm.h"
15 //#include "../emu.h"
16 #include "device.h"
17
18 #define SIG_M6502_OVERFLOW      0
19
20 //#ifdef USE_DEBUGGER
21 class DEBUGGER;
22 //#endif
23
24 class M6502_BASE : public DEVICE
25 {
26 protected:
27         DEVICE *d_mem, *d_pic;
28 //#ifdef USE_DEBUGGER
29         DEBUGGER *d_debugger;
30         DEVICE *d_mem_stored;
31 //#endif
32         
33         pair32_t pc, sp, zp, ea;
34         uint16_t prev_pc;
35         uint8_t a, x, y, p;
36         bool pending_irq, after_cli;
37         bool nmi_state, irq_state, so_state;
38
39         uint64_t total_icount;
40         uint64_t prev_total_icount;
41
42         int icount;
43         bool busreq;
44         
45         void run_one_opecode();
46         virtual void OP(uint8_t code);
47         void update_irq();
48
49 public:
50         M6502_BASE(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
51         {
52                 total_icount = prev_total_icount = 0;
53                 busreq = false;
54                 set_device_name(_T("M6502 CPU"));
55         }
56         ~M6502_BASE() {}
57         
58         // common functions
59         virtual void initialize();
60         virtual void reset();
61         virtual int run(int clock);
62         
63         void write_signal(int id, uint32_t data, uint32_t mask);
64         void set_intr_line(bool line, bool pending, uint32_t bit)
65         {
66                 write_signal(SIG_CPU_IRQ, line ? 1 : 0, 1);
67         }
68         uint32_t get_pc()
69         {
70                 return prev_pc;
71         }
72         uint32_t get_next_pc()
73         {
74                 return pc.w.l;
75         }
76 //#ifdef USE_DEBUGGER
77         void *get_debugger()
78         {
79                 return d_debugger;
80         }
81         uint32_t get_debug_prog_addr_mask()
82         {
83                 return 0xffff;
84         }
85         uint32_t get_debug_data_addr_mask()
86         {
87                 return 0xffff;
88         }
89         void write_debug_data8(uint32_t addr, uint32_t data);
90         uint32_t read_debug_data8(uint32_t addr);
91         bool write_debug_reg(const _TCHAR *reg, uint32_t data);
92         void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
93         virtual int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
94 //#endif
95         
96         // unique functions
97         void set_context_mem(DEVICE* device)
98         {
99                 d_mem = device;
100         }
101         void set_context_intr(DEVICE* device)
102         {
103                 d_pic = device;
104         }
105 //#ifdef USE_DEBUGGER
106         void set_context_debugger(DEBUGGER* device)
107         {
108                 d_debugger = device;
109         }
110 //#endif
111 };
112
113 class M6502 : public M6502_BASE
114 {
115 protected:
116         void OP(uint8_t code);
117 public:
118         M6502(VM_TEMPLATE* parent_vm, EMU* parent_emu) : M6502_BASE(parent_vm, parent_emu)
119         {
120         }
121         ~M6502() {}
122         void initialize();
123         void reset();
124         int run(int clock);
125         int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
126         bool process_state(FILEIO* state_fio, bool loading);
127 };      
128
129 class N2A03 : public M6502_BASE
130 {
131 protected:
132         void OP(uint8_t code);
133 public:
134         N2A03(VM_TEMPLATE* parent_vm, EMU* parent_emu) : M6502_BASE(parent_vm, parent_emu)
135         {
136         }
137         ~N2A03() {}
138         void initialize();
139         void reset();
140         int run(int clock);
141         int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
142         bool process_state(FILEIO* state_fio, bool loading);
143 };      
144
145 #endif
146