OSDN Git Service

[VM][COMMON_VM] Include IO:: class to common_vm.
[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 __FASTCALL run_one_opecode();
46         virtual void __FASTCALL OP(uint8_t code);
47         void __FASTCALL 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                 d_debugger = NULL;
55                 d_mem = NULL;
56                 d_mem_stored = NULL;
57                 d_pic = NULL;
58                 set_device_name(_T("M6502 CPU"));
59         }
60         ~M6502_BASE() {}
61         
62         // common functions
63         virtual void initialize();
64         virtual void reset();
65         virtual int __FASTCALL run(int clock);
66         
67         void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask);
68         void set_intr_line(bool line, bool pending, uint32_t bit)
69         {
70                 write_signal(SIG_CPU_IRQ, line ? 1 : 0, 1);
71         }
72         uint32_t get_pc()
73         {
74                 return prev_pc;
75         }
76         uint32_t get_next_pc()
77         {
78                 return pc.w.l;
79         }
80 //#ifdef USE_DEBUGGER
81         void *get_debugger()
82         {
83                 return d_debugger;
84         }
85         uint32_t get_debug_prog_addr_mask()
86         {
87                 return 0xffff;
88         }
89         uint32_t get_debug_data_addr_mask()
90         {
91                 return 0xffff;
92         }
93         void __FASTCALL write_debug_data8(uint32_t addr, uint32_t data);
94         uint32_t __FASTCALL read_debug_data8(uint32_t addr);
95         bool write_debug_reg(const _TCHAR *reg, uint32_t data);
96         bool get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
97         virtual int debug_dasm_with_userdata(uint32_t pc, _TCHAR *buffer, size_t buffer_len, uint32_t userdata = 0);
98 //#endif
99         
100         // unique functions
101         void set_context_mem(DEVICE* device)
102         {
103                 d_mem = device;
104         }
105         void set_context_intr(DEVICE* device)
106         {
107                 d_pic = device;
108         }
109 //#ifdef USE_DEBUGGER
110         void set_context_debugger(DEBUGGER* device)
111         {
112                 d_debugger = device;
113         }
114 //#endif
115 };
116
117 class M6502 : public M6502_BASE
118 {
119 protected:
120         void __FASTCALL OP(uint8_t code);
121 public:
122         M6502(VM_TEMPLATE* parent_vm, EMU* parent_emu) : M6502_BASE(parent_vm, parent_emu)
123         {
124         }
125         ~M6502() {}
126         void initialize();
127         void reset();
128         int __FASTCALL run(int clock);
129         int debug_dasm_with_userdata(uint32_t pc, _TCHAR *buffer, size_t buffer_len, uint32_t userdata = 0);
130         bool process_state(FILEIO* state_fio, bool loading);
131 };      
132
133 class N2A03 : public M6502_BASE
134 {
135 protected:
136         void __FASTCALL OP(uint8_t code);
137 public:
138         N2A03(VM_TEMPLATE* parent_vm, EMU* parent_emu) : M6502_BASE(parent_vm, parent_emu)
139         {
140         }
141         ~N2A03() {}
142         void initialize();
143         void reset();
144         int __FASTCALL run(int clock);
145         int debug_dasm_with_userdata(uint32_t pc, _TCHAR *buffer, size_t buffer_len, uint32_t userdata = 0);
146         bool process_state(FILEIO* state_fio, bool loading);
147 };      
148
149 #endif
150