OSDN Git Service

[VM] Really update to upstream 2018-10-07.
[csp-qt/common_source_project-fm7.git] / source / src / vm / msx / memory_ex.h
1 /*
2         Common Source Code Project
3         MSX Series (experimental)
4
5         Origin : src/vm/msx/memory.h
6
7         modified by umaiboux
8         Date   : 2016.03.xx-
9
10         [ memory ]
11 */
12
13 #ifndef _MEMORY_EX_H_
14 #define _MEMORY_EX_H_
15
16 #define USE_MEGAROM
17
18 #include "../vm.h"
19 #include "../../emu.h"
20 #include "../device.h"
21
22 #ifdef USE_MEGAROM
23 #include "sound_cart.h"
24 #endif
25
26 #define SIG_LDC_EXV     0
27 #define SIG_LDC_ACK     1
28 #define SIG_LDC_MUTE    2
29
30 #define SIG_MEMORY_SEL  0
31
32 #if defined(FDD_PATCH_SLOT)
33 class DISK;
34 #endif
35
36 // MAIN ROM 32K
37 // or MAIN ROM 32K + MAIN RAM 32K
38
39 namespace MSX {
40         
41 class SLOT_MAINROM : public DEVICE
42 {
43 private:
44         uint8_t wdmy[0x2000];
45         uint8_t rdmy[0x2000];
46         uint8_t* wbank[8];
47         uint8_t* rbank[8];
48         uint8_t rom[0x8000];
49 #ifdef MAINROM_PLUS_RAM_32K
50         uint8_t ram[0x8000];
51 #endif
52 public:
53         SLOT_MAINROM(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
54         {
55                 set_device_name(_T("Main ROM"));
56         }
57         ~SLOT_MAINROM() {}
58         
59         // common functions
60         void initialize();
61         void write_data8(uint32_t addr, uint32_t data);
62         uint32_t read_data8(uint32_t addr);
63         bool process_state(FILEIO* state_fio, bool loading);
64 };
65
66 // Cart
67
68 class SLOT_CART : public DEVICE
69 {
70 private:
71         uint8_t wdmy[0x2000];
72         uint8_t rdmy[0x2000];
73         uint8_t* wbank[8];
74         uint8_t* rbank[8];
75 #ifdef USE_MEGAROM
76         uint8_t rom[1024*1024*4];
77         int32_t type;
78         SOUND_CART *d_sound;
79         bool bank_scc;
80
81         int tmp_rbank_ptr[8];
82 #else
83         uint8_t rom[0x10000];
84 #endif
85         bool inserted;
86         
87 public:
88         SLOT_CART(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
89         {
90 #ifdef USE_MEGAROM
91         event_register_id = -1;
92 #endif
93                 set_device_name(_T("ROM Cartridge"));
94         }
95         ~SLOT_CART() {}
96         
97         // common functions
98         void initialize();
99         void write_data8(uint32_t addr, uint32_t data);
100         uint32_t read_data8(uint32_t addr);
101         bool process_state(FILEIO* state_fio, bool loading);
102 #ifdef USE_MEGAROM
103         void event_callback(int event_id, int err);
104         int event_register_id;
105 #endif
106         
107         // unique functions
108         void open_cart(const _TCHAR *file_path);
109         void close_cart();
110         bool is_cart_inserted()
111         {
112                 return inserted;
113         }
114 #ifdef USE_MEGAROM
115         void set_context_sound(SOUND_CART *device)
116         {
117                 d_sound = device;
118         }
119 #endif
120         bool load_cart(const _TCHAR *file_path/*, uint8_t *rom*/);
121 };
122
123 // MSXDOS2
124
125 #if defined(MSXDOS2_SLOT)
126 class SLOT_MSXDOS2 : public DEVICE
127 {
128 private:
129         uint8_t wdmy[0x2000];
130         uint8_t rdmy[0x2000];
131         uint8_t* wbank[8];
132         uint8_t* rbank[8];
133         uint8_t rom[0x10000];
134         uint8_t mapper[2];
135         
136 public:
137         SLOT_MSXDOS2(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
138         {
139                 set_device_name(_T("MSX-DOS2"));
140         }
141         ~SLOT_MSXDOS2() {}
142         
143         // common functions
144         void initialize();
145         void write_data8(uint32_t addr, uint32_t data);
146         uint32_t read_data8(uint32_t addr);
147         bool process_state(FILEIO* state_fio, bool loading);
148 };
149 #endif
150
151 // LD Control
152
153 #if defined(LDC_SLOT)
154 class SLOT_LDC : public DEVICE
155 {
156 private:
157         DEVICE *d_cpu, *d_ldp, *d_vdp;
158         
159         uint8_t wdmy[0x2000];
160         uint8_t rdmy[0x2000];
161         uint8_t* wbank[8];
162         uint8_t* rbank[8];
163         uint8_t rom[0x2000];
164         
165         bool clock;
166         bool exv, ack;
167         bool super_impose;
168         bool req_intr;
169         bool pc4, mute_l, mute_r;
170         
171 public:
172         SLOT_LDC(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
173         {
174                 set_device_name(_T("LDC Control"));
175         }
176         ~SLOT_LDC() {}
177         
178         // common functions
179         void initialize();
180         void reset();
181         void write_data8(uint32_t addr, uint32_t data);
182         uint32_t read_data8(uint32_t addr);
183         void write_signal(int id, uint32_t data, uint32_t mask);
184         void event_callback(int event_id, int err);
185         bool process_state(FILEIO* state_fio, bool loading);
186         
187         // unique functions
188         void set_context_cpu(DEVICE* device)
189         {
190                 d_cpu = device;
191         }
192         void set_context_ldp(DEVICE* device)
193         {
194                 d_ldp = device;
195         }
196         void set_context_vdp(DEVICE* device)
197         {
198                 d_vdp = device;
199         }
200 };
201 #endif
202
203 // SUBROM
204
205 #if defined(SUBROM_SLOT)
206 class SLOT_SUBROM : public DEVICE
207 {
208 private:
209         uint8_t wdmy[0x2000];
210         uint8_t rdmy[0x2000];
211         uint8_t* wbank[8];
212         uint8_t* rbank[8];
213 #if defined(_MSX2_VARIANTS)
214         uint8_t rom[0x4000];
215 #else
216         uint8_t rom[0xc000];
217 #endif
218         
219 public:
220         SLOT_SUBROM(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
221         {
222                 set_device_name(_T("Sub ROM"));
223         }
224         ~SLOT_SUBROM() {}
225         
226         // common functions
227         void initialize();
228         void write_data8(uint32_t addr, uint32_t data);
229         uint32_t read_data8(uint32_t addr);
230 };
231 #endif
232
233 // FDD with ROM-PATCH
234
235 #if defined(FDD_PATCH_SLOT)
236 class SLOT_FDD_PATCH : public DEVICE
237 {
238 private:
239         uint8_t wdmy[0x2000];
240         uint8_t rdmy[0x2000];
241         uint8_t* wbank[8];
242         uint8_t* rbank[8];
243         uint8_t rom[0x4000];
244         
245 public:
246         SLOT_FDD_PATCH(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
247         {
248                 set_device_name(_T("FDD I/F"));
249         }
250         ~SLOT_FDD_PATCH() {}
251         
252         // common functions
253         void initialize();
254         void write_data8(uint32_t addr, uint32_t data);
255         uint32_t read_data8(uint32_t addr);
256 };
257 #endif
258
259 // MAPPER RAM
260
261 #if defined(MAPPERRAM_SLOT)
262 class SLOT_MAPPERRAM : public DEVICE
263 {
264 private:
265         uint8_t wdmy[0x2000];
266         uint8_t rdmy[0x2000];
267         uint8_t* wbank[8];
268         uint8_t* rbank[8];
269         uint8_t ram[MAPPERRAM_SIZE];
270         uint8_t mapper[4];
271         
272 public:
273         SLOT_MAPPERRAM(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
274         {
275                 set_device_name(_T("Mapper RAM"));
276         }
277         ~SLOT_MAPPERRAM() {}
278         
279         // common functions
280         void initialize();
281         void write_data8(uint32_t addr, uint32_t data);
282         uint32_t read_data8(uint32_t addr);
283         void write_io8(uint32_t addr, uint32_t data);
284         bool process_state(FILEIO* state_fio, bool loading);
285 };
286 #endif
287
288 // NORMAL RAM 64K
289
290 #if defined(RAM64K_SLOT)
291 class SLOT_RAM64K : public DEVICE
292 {
293 private:
294         uint8_t ram[0x10000];
295         
296 public:
297         SLOT_RAM64K(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
298         {
299                 set_device_name(_T("RAM 64KB"));
300         }
301         ~SLOT_RAM64K() {}
302         
303         // common functions
304         void initialize();
305         void write_data8(uint32_t addr, uint32_t data);
306         uint32_t read_data8(uint32_t addr);
307         bool process_state(FILEIO* state_fio, bool loading);
308 };
309 #endif
310
311 // FIRMWARE 32K
312
313 #if defined(FIRMWARE32K1_SLOT)
314 class SLOT_FIRMWARE32K : public DEVICE
315 {
316 private:
317         uint8_t wdmy[0x2000];
318         uint8_t rdmy[0x2000];
319         uint8_t* wbank[8];
320         uint8_t* rbank[8];
321         uint8_t rom[0x8000];
322         const _TCHAR* m_filename;
323         
324 public:
325         SLOT_FIRMWARE32K(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
326         {
327                 set_device_name(_T("Firmware 32KB"));
328         }
329         ~SLOT_FIRMWARE32K() {}
330         
331         // common functions
332         void initialize();
333         void write_data8(uint32_t addr, uint32_t data);
334         uint32_t read_data8(uint32_t addr);
335
336         // unique function
337         void set_context_filename(const _TCHAR* filename)
338         {
339                 m_filename = filename;
340         }
341 };
342 #endif
343
344 // MSX-MUSIC
345
346 #if defined(MSXMUSIC_SLOT)
347 class SLOT_MSXMUSIC : public DEVICE
348 {
349 private:
350         uint8_t wdmy[0x2000];
351         uint8_t rdmy[0x2000];
352         uint8_t* wbank[8];
353         uint8_t* rbank[8];
354         uint8_t rom[0x4000];
355         
356 public:
357         SLOT_MSXMUSIC(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
358         {
359                 set_device_name(_T("MSX-MUSIC"));
360         }
361         ~SLOT_MSXMUSIC() {}
362         
363         // common functions
364         void initialize();
365         void write_data8(uint32_t addr, uint32_t data);
366         uint32_t read_data8(uint32_t addr);
367 };
368 #endif
369
370 // memory bus
371
372 class MEMORY_EX : public DEVICE
373 {
374 private:
375         DEVICE *d_slot[4*4];
376         DEVICE *d_map[4];
377 #if defined(FDD_PATCH_SLOT)
378         DISK* disk[MAX_DRIVE];
379         DEVICE *d_fdpat;
380         bool access[MAX_DRIVE];
381 #endif
382 #if defined(FDD_PATCH_SLOT) && defined(_MSX_VDP_MESS)
383         DEVICE *d_vdp;
384 #endif
385 #if defined(MAPPERRAM_SLOT)
386         DEVICE *d_mapper;
387 #endif
388         bool expanded[4];
389         uint8_t psl;
390         uint8_t ssl[4];
391         //uint32_t slot_select;
392         void update_map(uint32_t val);
393         
394 public:
395         MEMORY_EX(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
396         {
397                 ssl[0] = ssl[1] = ssl[2] = ssl[3] = 0;
398                 expanded[0] = expanded[1] = expanded[2] = expanded[3] = false;
399                 set_device_name(_T("Memory Bus (ex)"));
400         }
401         ~MEMORY_EX() {}
402         
403         // common functions
404 #if defined(FDD_PATCH_SLOT)
405         void initialize();
406         void release();
407 #endif
408         void reset();
409         void write_data8(uint32_t addr, uint32_t data);
410         uint32_t read_data8(uint32_t addr);
411         uint32_t fetch_op(uint32_t addr, int* wait);
412         void write_io8(uint32_t addr, uint32_t data);
413         void write_signal(int id, uint32_t data, uint32_t mask);
414 #if defined(FDD_PATCH_SLOT)
415         uint32_t read_signal(int id);
416         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);
417 #endif
418         bool process_state(FILEIO* state_fio, bool loading);
419         
420         // unique functions
421         void set_context_slot_dummy(DEVICE *device)
422         {
423                 int i;
424                 for(i=0; i<16; i++) d_slot[i] = device;
425         }
426         void set_context_slot(int drv, DEVICE *device)
427         {
428                 d_slot[drv & 0x0f] = device;
429                 if (drv & 0x80) expanded[drv & 0x03] = true;
430         }
431 #if defined(FDD_PATCH_SLOT)
432         void set_context_fdd_patch(DEVICE *device)
433         {
434                 d_fdpat = device;
435         }
436         void open_disk(int drv, const _TCHAR* file_path, int bank);
437         void close_disk(int drv);
438         bool is_disk_inserted(int drv);
439         void is_disk_protected(int drv, bool value);
440         bool is_disk_protected(int drv);
441 #endif
442 #if defined(MAPPERRAM_SLOT)
443         void set_context_mapper(DEVICE *device)
444         {
445                 d_mapper = device;
446         }
447 #endif
448 #if defined(FDD_PATCH_SLOT) && defined(_MSX_VDP_MESS)
449         void set_context_vdp(DEVICE *device)
450         {
451                 d_vdp = device;
452         }
453 #endif
454 };
455
456 }
457 #endif
458