OSDN Git Service

[VM][FMTOWNS][MEMORY] Fix setup around memory banks by I/O 0404h and 0480h.
[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 namespace MSX {
35
36 class SLOT0 : public DEVICE
37 {
38 private:
39         uint8_t wdmy[0x2000];
40         uint8_t rdmy[0x2000];
41         uint8_t* wbank[8];
42         uint8_t* rbank[8];
43         uint8_t rom[0x8000];
44 #if defined(_PX7)
45         uint8_t ram[0x8000];
46 #endif  
47 public:
48         SLOT0(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
49         {
50                 set_device_name(_T("Slot #0"));
51         }
52         ~SLOT0() {}
53         
54         // common functions
55         void initialize();
56         void __FASTCALL write_data8(uint32_t addr, uint32_t data);
57         uint32_t __FASTCALL read_data8(uint32_t addr);
58         bool process_state(FILEIO* state_fio, bool loading);
59 };
60
61 // slot #1
62
63 class SLOT1 : public DEVICE
64 {
65 private:
66         uint8_t wdmy[0x2000];
67         uint8_t rdmy[0x2000];
68         uint8_t* wbank[8];
69         uint8_t* rbank[8];
70         uint8_t rom[0x10000];
71         bool inserted;
72 #if defined(_MSX2)
73         uint8_t mapper[2];
74 #endif
75         
76 public:
77         SLOT1(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
78         {
79                 set_device_name(_T("Slot #1"));
80         }
81         ~SLOT1() {}
82         
83         // common functions
84         void initialize();
85         void __FASTCALL write_data8(uint32_t addr, uint32_t data);
86         uint32_t __FASTCALL read_data8(uint32_t addr);
87         bool process_state(FILEIO* state_fio, bool loading);
88         
89         // unique functions
90         void open_cart(const _TCHAR *file_path);
91         void close_cart();
92         bool is_cart_inserted()
93         {
94                 return inserted;
95         }
96 };
97
98 // slot #2
99
100 #if defined(_PX7)
101 class SLOT2 : public DEVICE
102 {
103 private:
104         DEVICE *d_cpu, *d_ldp, *d_vdp;
105         
106         uint8_t wdmy[0x2000];
107         uint8_t rdmy[0x2000];
108         uint8_t* wbank[8];
109         uint8_t* rbank[8];
110         uint8_t rom[0x2000];
111         
112         bool clock;
113         bool exv, ack;
114         bool super_impose;
115         bool req_intr;
116         bool pc4, mute_l, mute_r;
117         
118 public:
119         SLOT2(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
120         {
121                 set_device_name(_T("Slot #2"));
122         }
123         ~SLOT2() {}
124         
125         // common functions
126         void initialize();
127         void reset();
128         void __FASTCALL write_data8(uint32_t addr, uint32_t data);
129         uint32_t __FASTCALL read_data8(uint32_t addr);
130         void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask);
131         void __FASTCALL event_callback(int event_id, int err);
132         bool process_state(FILEIO* state_fio, bool loading);
133         
134         // unique functions
135         void set_context_cpu(DEVICE* device)
136         {
137                 d_cpu = device;
138         }
139         void set_context_ldp(DEVICE* device)
140         {
141                 d_ldp = device;
142         }
143         void set_context_vdp(DEVICE* device)
144         {
145                 d_vdp = device;
146         }
147 };
148 #else
149 class SLOT2 : public DEVICE
150 {
151 private:
152         uint8_t wdmy[0x2000];
153         uint8_t rdmy[0x2000];
154         uint8_t* wbank[8];
155         uint8_t* rbank[8];
156         uint8_t rom[0x8000];
157         
158 public:
159         SLOT2(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
160         {
161                 set_device_name(_T("Slot #2"));
162         }
163         ~SLOT2() {}
164         
165         // common functions
166         void initialize();
167         void __FASTCALL write_data8(uint32_t addr, uint32_t data);
168         uint32_t __FASTCALL read_data8(uint32_t addr);
169 };
170 #endif
171
172 // slot #3
173
174 class SLOT3 : public DEVICE
175 {
176 private:
177         uint8_t wdmy[0x2000];
178         uint8_t rdmy[0x2000];
179         uint8_t* wbank[8];
180         uint8_t* rbank[8];
181         uint8_t rom[0x10000];
182         uint8_t ram[0x20000];
183         bool inserted;
184         uint8_t mapper[4];
185         
186 public:
187         SLOT3(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
188         {
189                 set_device_name(_T("Slot #3"));
190         }
191         ~SLOT3() {}
192         
193         // common functions
194         void initialize();
195         void __FASTCALL write_data8(uint32_t addr, uint32_t data);
196         uint32_t __FASTCALL read_data8(uint32_t addr);
197         void __FASTCALL write_io8(uint32_t addr, uint32_t data);
198         bool process_state(FILEIO* state_fio, bool loading);
199         
200         // unique functions
201         void open_cart(const _TCHAR *file_path);
202         void close_cart();
203         bool is_cart_inserted()
204         {
205                 return inserted;
206         }
207 };
208
209 // memory bus
210
211 class MSX_MEMORY : public DEVICE
212 {
213 private:
214         DEVICE *d_slot[4];
215         DEVICE *d_map[4];
216 #if !defined(_PX7)
217         DISK* disk[MAX_DRIVE];
218         bool access[MAX_DRIVE]
219 #endif
220         uint32_t slot_select;
221         void update_map(uint32_t val);
222         
223 public:
224         MSX_MEMORY(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
225         {
226                 set_device_name(_T("Memory Bus"));
227         }
228         ~MSX_MEMORY() {}
229         
230         // common functions
231 #if !defined(_PX7)
232         void initialize();
233         void release();
234 #endif
235         void reset();
236         void __FASTCALL write_data8(uint32_t addr, uint32_t data);
237         uint32_t __FASTCALL read_data8(uint32_t addr);
238         uint32_t __FASTCALL fetch_op(uint32_t addr, int* wait);
239         void __FASTCALL write_io8(uint32_t addr, uint32_t data);
240         void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask);
241 #if !defined(_PX7)
242         uint32_t __FASTCALL read_signal(int id);
243         bool bios_ret_z80(uint16_t PC, pair32_t* af, pair32_t* bc, pair32_t* de, pair32_t* hl, pair32_t* ix, pair32_t* iy, uint8_t* iff1);
244 #endif
245         bool process_state(FILEIO* state_fio, bool loading);
246         
247         // unique functions
248         void set_context_slot(int drv, DEVICE *device)
249         {
250                 d_slot[drv] = device;
251         }
252 #if !defined(_PX7)
253         void open_disk(int drv, const _TCHAR* file_path, int bank);
254         void close_disk(int drv);
255         bool is_disk_inserted(int drv);
256         void is_disk_protected(int drv, bool value);
257         bool is_disk_protected(int drv);
258 #endif
259 };
260
261 }
262 #endif
263