OSDN Git Service

[VM][General] Merge upstream 2016-03-01. (Pahse 1).
[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 _MEMORY_H_
16 #define _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* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
47         ~SLOT0() {}
48         
49         // common functions
50         void initialize();
51         void write_data8(uint32_t addr, uint32_t data);
52         uint32_t read_data8(uint32_t addr);
53         void save_state(FILEIO* state_fio);
54         bool load_state(FILEIO* state_fio);
55 };
56
57 // slot #1
58
59 class SLOT1 : public DEVICE
60 {
61 private:
62         uint8_t wdmy[0x2000];
63         uint8_t rdmy[0x2000];
64         uint8_t* wbank[8];
65         uint8_t* rbank[8];
66         uint8_t rom[0x10000];
67         bool inserted;
68 #if defined(_MSX2)
69         uint8_t mapper[2];
70 #endif
71         
72 public:
73         SLOT1(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
74         ~SLOT1() {}
75         
76         // common functions
77         void initialize();
78         void write_data8(uint32_t addr, uint32_t data);
79         uint32_t read_data8(uint32_t addr);
80         void save_state(FILEIO* state_fio);
81         bool load_state(FILEIO* state_fio);
82         
83         // unique functions
84         void open_cart(const _TCHAR *file_path);
85         void close_cart();
86         bool is_cart_inserted()
87         {
88                 return inserted;
89         }
90 };
91
92 // slot #2
93
94 #if defined(_PX7)
95 class SLOT2 : public DEVICE
96 {
97 private:
98         DEVICE *d_cpu, *d_ldp, *d_vdp;
99         
100         uint8_t wdmy[0x2000];
101         uint8_t rdmy[0x2000];
102         uint8_t* wbank[8];
103         uint8_t* rbank[8];
104         uint8_t rom[0x2000];
105         
106         bool clock;
107         bool exv, ack;
108         bool super_impose;
109         bool req_intr;
110         bool pc4, mute_l, mute_r;
111         
112 public:
113         SLOT2(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
114         ~SLOT2() {}
115         
116         // common functions
117         void initialize();
118         void reset();
119         void write_data8(uint32_t addr, uint32_t data);
120         uint32_t read_data8(uint32_t addr);
121         void write_signal(int id, uint32_t data, uint32_t mask);
122         void event_callback(int event_id, int err);
123         void save_state(FILEIO* state_fio);
124         bool load_state(FILEIO* state_fio);
125         
126         // unique functions
127         void set_context_cpu(DEVICE* device)
128         {
129                 d_cpu = device;
130         }
131         void set_context_ldp(DEVICE* device)
132         {
133                 d_ldp = device;
134         }
135         void set_context_vdp(DEVICE* device)
136         {
137                 d_vdp = device;
138         }
139 };
140 #else
141 class SLOT2 : public DEVICE
142 {
143 private:
144         uint8_t wdmy[0x2000];
145         uint8_t rdmy[0x2000];
146         uint8_t* wbank[8];
147         uint8_t* rbank[8];
148         uint8_t rom[0x8000];
149         
150 public:
151         SLOT2(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
152         ~SLOT2() {}
153         
154         // common functions
155         void initialize();
156         void write_data8(uint32_t addr, uint32_t data);
157         uint32_t read_data8(uint32_t addr);
158 };
159 #endif
160
161 // slot #3
162
163 class SLOT3 : public DEVICE
164 {
165 private:
166         uint8_t wdmy[0x2000];
167         uint8_t rdmy[0x2000];
168         uint8_t* wbank[8];
169         uint8_t* rbank[8];
170         uint8_t rom[0x10000];
171         uint8_t ram[0x20000];
172         bool inserted;
173         uint8_t mapper[4];
174         
175 public:
176         SLOT3(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
177         ~SLOT3() {}
178         
179         // common functions
180         void initialize();
181         void write_data8(uint32_t addr, uint32_t data);
182         uint32_t read_data8(uint32_t addr);
183         void write_io8(uint32_t addr, uint32_t data);
184         void save_state(FILEIO* state_fio);
185         bool load_state(FILEIO* state_fio);
186         
187         // unique functions
188         void open_cart(const _TCHAR *file_path);
189         void close_cart();
190         bool is_cart_inserted()
191         {
192                 return inserted;
193         }
194 };
195
196 // memory bus
197
198 class MEMORY : public DEVICE
199 {
200 private:
201         DEVICE *d_slot[4];
202         DEVICE *d_map[4];
203 #if !defined(_PX7)
204         DISK* disk[MAX_DRIVE];
205 #endif
206         uint32_t slot_select;
207         void update_map(uint32_t val);
208         
209 public:
210         MEMORY(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
211         ~MEMORY() {}
212         
213         // common functions
214 #if !defined(_PX7)
215         void initialize();
216         void release();
217 #endif
218         void reset();
219         void write_data8(uint32_t addr, uint32_t data);
220         uint32_t read_data8(uint32_t addr);
221         uint32_t fetch_op(uint32_t addr, int* wait);
222         void write_io8(uint32_t addr, uint32_t data);
223         void write_signal(int id, uint32_t data, uint32_t mask);
224 #if !defined(_PX7)
225         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);
226 #endif
227         void save_state(FILEIO* state_fio);
228         bool load_state(FILEIO* state_fio);
229         
230         // unique functions
231         void set_context_slot(int drv, DEVICE *device)
232         {
233                 d_slot[drv] = device;
234         }
235 #if !defined(_PX7)
236         void open_disk(int drv, const _TCHAR* file_path, int bank);
237         void close_disk(int drv);
238         bool is_disk_inserted(int drv);
239         void is_disk_protected(int drv, bool value);
240         bool is_disk_protected(int drv);
241 #endif
242 };
243
244 #endif
245