OSDN Git Service

[VM] MEMORY:: class within some VM will change Foo_MEMORY:: to reduce misundestanding...
[csp-qt/common_source_project-fm7.git] / source / src / vm / msx / memory.h
1 /*
2         ASCII MSX1 Emulator 'yaMSX1'
3         ASCII MSX2 Emulator 'yaMSX2'
4         Pioneer PX-7 Emulator 'ePX-7'
5
6         Author : Takeda.Toshiya
7         Date   : 2014.01.09-
8
9         modified by tanam
10         modified by umaiboux
11
12         [ memory ]
13 */
14
15 #ifndef _MSX_MEMORY_H_
16 #define _MSX_MEMORY_H_
17
18 #include "../vm.h"
19 #include "../../emu.h"
20 #include "../device.h"
21
22 #define SIG_SLOT2_EXV   0
23 #define SIG_SLOT2_ACK   1
24 #define SIG_SLOT2_MUTE  2
25
26 #define SIG_MEMORY_SEL  0
27
28 #if !defined(_PX7)
29 class DISK;
30 #endif
31
32 // slot #0
33
34 class SLOT0 : public DEVICE
35 {
36 private:
37         uint8_t wdmy[0x2000];
38         uint8_t rdmy[0x2000];
39         uint8_t* wbank[8];
40         uint8_t* rbank[8];
41         uint8_t rom[0x8000];
42 #if defined(_PX7)
43         uint8_t ram[0x8000];
44 #endif  
45 public:
46         SLOT0(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
47         {
48                 set_device_name(_T("Slot #0"));
49         }
50         ~SLOT0() {}
51         
52         // common functions
53         void initialize();
54         void write_data8(uint32_t addr, uint32_t data);
55         uint32_t read_data8(uint32_t addr);
56         bool process_state(FILEIO* state_fio, bool loading);
57 };
58
59 // slot #1
60
61 class SLOT1 : public DEVICE
62 {
63 private:
64         uint8_t wdmy[0x2000];
65         uint8_t rdmy[0x2000];
66         uint8_t* wbank[8];
67         uint8_t* rbank[8];
68         uint8_t rom[0x10000];
69         bool inserted;
70 #if defined(_MSX2)
71         uint8_t mapper[2];
72 #endif
73         
74 public:
75         SLOT1(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
76         {
77                 set_device_name(_T("Slot #1"));
78         }
79         ~SLOT1() {}
80         
81         // common functions
82         void initialize();
83         void write_data8(uint32_t addr, uint32_t data);
84         uint32_t read_data8(uint32_t addr);
85         bool process_state(FILEIO* state_fio, bool loading);
86         
87         // unique functions
88         void open_cart(const _TCHAR *file_path);
89         void close_cart();
90         bool is_cart_inserted()
91         {
92                 return inserted;
93         }
94 };
95
96 // slot #2
97
98 #if defined(_PX7)
99 class SLOT2 : public DEVICE
100 {
101 private:
102         DEVICE *d_cpu, *d_ldp, *d_vdp;
103         
104         uint8_t wdmy[0x2000];
105         uint8_t rdmy[0x2000];
106         uint8_t* wbank[8];
107         uint8_t* rbank[8];
108         uint8_t rom[0x2000];
109         
110         bool clock;
111         bool exv, ack;
112         bool super_impose;
113         bool req_intr;
114         bool pc4, mute_l, mute_r;
115         
116 public:
117         SLOT2(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
118         {
119                 set_device_name(_T("Slot #2"));
120         }
121         ~SLOT2() {}
122         
123         // common functions
124         void initialize();
125         void reset();
126         void write_data8(uint32_t addr, uint32_t data);
127         uint32_t read_data8(uint32_t addr);
128         void write_signal(int id, uint32_t data, uint32_t mask);
129         void event_callback(int event_id, int err);
130         bool process_state(FILEIO* state_fio, bool loading);
131         
132         // unique functions
133         void set_context_cpu(DEVICE* device)
134         {
135                 d_cpu = device;
136         }
137         void set_context_ldp(DEVICE* device)
138         {
139                 d_ldp = device;
140         }
141         void set_context_vdp(DEVICE* device)
142         {
143                 d_vdp = device;
144         }
145 };
146 #else
147 class SLOT2 : public DEVICE
148 {
149 private:
150         uint8_t wdmy[0x2000];
151         uint8_t rdmy[0x2000];
152         uint8_t* wbank[8];
153         uint8_t* rbank[8];
154         uint8_t rom[0x8000];
155         
156 public:
157         SLOT2(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
158         {
159                 set_device_name(_T("Slot #2"));
160         }
161         ~SLOT2() {}
162         
163         // common functions
164         void initialize();
165         void write_data8(uint32_t addr, uint32_t data);
166         uint32_t read_data8(uint32_t addr);
167 };
168 #endif
169
170 // slot #3
171
172 class SLOT3 : public DEVICE
173 {
174 private:
175         uint8_t wdmy[0x2000];
176         uint8_t rdmy[0x2000];
177         uint8_t* wbank[8];
178         uint8_t* rbank[8];
179         uint8_t rom[0x10000];
180         uint8_t ram[0x20000];
181         bool inserted;
182         uint8_t mapper[4];
183         
184 public:
185         SLOT3(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
186         {
187                 set_device_name(_T("Slot #3"));
188         }
189         ~SLOT3() {}
190         
191         // common functions
192         void initialize();
193         void write_data8(uint32_t addr, uint32_t data);
194         uint32_t read_data8(uint32_t addr);
195         void write_io8(uint32_t addr, uint32_t data);
196         bool process_state(FILEIO* state_fio, bool loading);
197         
198         // unique functions
199         void open_cart(const _TCHAR *file_path);
200         void close_cart();
201         bool is_cart_inserted()
202         {
203                 return inserted;
204         }
205 };
206
207 // memory bus
208
209 class MSX_MEMORY : public DEVICE
210 {
211 private:
212         DEVICE *d_slot[4];
213         DEVICE *d_map[4];
214 #if !defined(_PX7)
215         DISK* disk[MAX_DRIVE];
216         bool access[MAX_DRIVE]
217 #endif
218         uint32_t slot_select;
219         void update_map(uint32_t val);
220         
221 public:
222         MSX_MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
223         {
224                 set_device_name(_T("Memory Bus"));
225         }
226         ~MSX_MEMORY() {}
227         
228         // common functions
229 #if !defined(_PX7)
230         void initialize();
231         void release();
232 #endif
233         void reset();
234         void write_data8(uint32_t addr, uint32_t data);
235         uint32_t read_data8(uint32_t addr);
236         uint32_t fetch_op(uint32_t addr, int* wait);
237         void write_io8(uint32_t addr, uint32_t data);
238         void write_signal(int id, uint32_t data, uint32_t mask);
239 #if !defined(_PX7)
240         uint32_t read_signal(int id);
241         bool bios_ret_z80(uint16_t PC, pair_t* af, pair_t* bc, pair_t* de, pair_t* hl, pair_t* ix, pair_t* iy, uint8_t* iff1);
242 #endif
243         bool process_state(FILEIO* state_fio, bool loading);
244         
245         // unique functions
246         void set_context_slot(int drv, DEVICE *device)
247         {
248                 d_slot[drv] = device;
249         }
250 #if !defined(_PX7)
251         void open_disk(int drv, const _TCHAR* file_path, int bank);
252         void close_disk(int drv);
253         bool is_disk_inserted(int drv);
254         void is_disk_protected(int drv, bool value);
255         bool is_disk_protected(int drv);
256 #endif
257 };
258
259 #endif
260