2 EPSON QC-10 Emulator 'eQC-10'
4 Author : Takeda.Toshiya
12 #include "../pcm1bit.h"
13 #include "../upd765a.h"
14 #include "../../fileio.h"
16 #define SET_BANK(s, e, w, r) { \
17 int sb = (s) >> 11, eb = (e) >> 11; \
18 for(int i = sb; i <= eb; i++) { \
19 wbank[i] = (w) + 0x800 * (i - sb); \
20 rbank[i] = (r) + 0x800 * (i - sb); \
24 void MEMORY::initialize()
27 memset(ram, 0, sizeof(ram));
28 memset(cmos, 0, sizeof(cmos));
29 memset(ipl, 0xff, sizeof(ipl));
30 memset(rdmy, 0xff, sizeof(rdmy));
33 FILEIO* fio = new FILEIO();
34 if(fio->Fopen(emu->bios_path(_T("IPL.ROM")), FILEIO_READ_BINARY)) {
35 fio->Fread(ipl, sizeof(ipl), 1);
38 if(fio->Fopen(emu->bios_path(_T("CMOS.BIN")), FILEIO_READ_BINARY)) {
39 fio->Fread(cmos, sizeof(cmos), 1);
44 cmos_crc32 = getcrc32(cmos, sizeof(cmos));
47 void MEMORY::release()
49 if(cmos_crc32 != getcrc32(cmos, sizeof(cmos))) {
50 FILEIO* fio = new FILEIO();
51 if(fio->Fopen(emu->bios_path(_T("CMOS.BIN")), FILEIO_WRITE_BINARY)) {
52 fio->Fwrite(cmos, sizeof(cmos), 1);
67 pcm_on = pcm_cont = pcm_pit = false;
69 // init fdc/fdd status
70 fdc_irq = motor = false;
73 void MEMORY::write_data8(uint32 addr, uint32 data)
76 wbank[addr >> 11][addr & 0x7ff] = data;
79 uint32 MEMORY::read_data8(uint32 addr)
82 return rbank[addr >> 11][addr & 0x7ff];
85 void MEMORY::write_io8(uint32 addr, uint32 data)
88 case 0x18: case 0x19: case 0x1a: case 0x1b:
91 d_pit->write_signal(SIG_I8253_GATE_0, data, 1);
92 d_pit->write_signal(SIG_I8253_GATE_2, data, 2);
94 pcm_cont = ((data & 4) != 0);
97 case 0x1c: case 0x1d: case 0x1e: case 0x1f:
100 case 0x20: case 0x21: case 0x22: case 0x23:
107 uint32 MEMORY::read_io8(uint32 addr)
109 switch(addr & 0xff) {
110 case 0x18: case 0x19: case 0x1a: case 0x1b:
111 return ~config.dipswitch & 0xff;
112 case 0x30: case 0x31: case 0x32: case 0x33:
113 return (bank & 0xf0) | (d_fdc->disk_inserted() ? 8 : 0) | (motor ? 0 : 2) | (fdc_irq ? 1 : 0);
119 0000-DFFF : RAM * 4banks
126 void MEMORY::write_signal(int id, uint32 data, uint32 mask)
128 if(id == SIG_MEMORY_PCM) {
130 pcm_pit = ((data & mask) != 0);
132 } else if(id == SIG_MEMORY_FDC_IRQ) {
133 fdc_irq = ((data & mask) != 0);
134 } else if(id == SIG_MEMORY_MOTOR) {
135 motor = ((data & mask) != 0);
139 void MEMORY::update_map()
142 SET_BANK(0x0000, 0x1fff, wdmy, ipl);
143 SET_BANK(0x2000, 0xdfff, wdmy, rdmy);
144 } else if(csel & 1) {
146 SET_BANK(0x0000, 0x7fff, ram + 0x00000, ram + 0x00000);
147 } else if(bank & 0x20) {
148 SET_BANK(0x0000, 0x7fff, ram + 0x10000, ram + 0x10000);
149 } else if(bank & 0x40) {
150 SET_BANK(0x0000, 0x7fff, ram + 0x20000, ram + 0x20000);
151 } else if(bank & 0x80) {
152 SET_BANK(0x0000, 0x7fff, ram + 0x30000, ram + 0x30000);
154 SET_BANK(0x0000, 0x7fff, wdmy, rdmy);
156 SET_BANK(0x8000, 0x87ff, cmos, cmos);
159 SET_BANK(0x0000, 0xdfff, ram + 0x00000, ram + 0x00000);
160 } else if(bank & 0x20) {
161 SET_BANK(0x0000, 0xdfff, ram + 0x10000, ram + 0x10000);
162 } else if(bank & 0x40) {
163 SET_BANK(0x0000, 0xdfff, ram + 0x20000, ram + 0x20000);
164 } else if(bank & 0x80) {
165 SET_BANK(0x0000, 0xdfff, ram + 0x30000, ram + 0x30000);
167 SET_BANK(0x0000, 0xdfff, wdmy, rdmy);
170 SET_BANK(0xe000, 0xffff, ram + 0xe000, ram + 0xe000);
173 void MEMORY::update_pcm()
175 if(!pcm_on && (pcm_cont || pcm_pit)) {
176 d_pcm->write_signal(SIG_PCM1BIT_ON, 1, 1);
178 } else if(pcm_on && !(pcm_cont || pcm_pit)) {
179 d_pcm->write_signal(SIG_PCM1BIT_ON, 0, 1);
184 #define STATE_VERSION 1
186 void MEMORY::save_state(FILEIO* state_fio)
188 state_fio->FputUint32(STATE_VERSION);
189 state_fio->FputInt32(this_device_id);
191 state_fio->Fwrite(ram, sizeof(ram), 1);
192 state_fio->Fwrite(cmos, sizeof(cmos), 1);
193 state_fio->FputUint32(cmos_crc32);
194 state_fio->FputUint8(bank);
195 state_fio->FputUint8(psel);
196 state_fio->FputUint8(csel);
197 state_fio->FputBool(pcm_on);
198 state_fio->FputBool(pcm_cont);
199 state_fio->FputBool(pcm_pit);
200 state_fio->FputBool(fdc_irq);
201 state_fio->FputBool(motor);
204 bool MEMORY::load_state(FILEIO* state_fio)
206 if(state_fio->FgetUint32() != STATE_VERSION) {
209 if(state_fio->FgetInt32() != this_device_id) {
212 state_fio->Fread(ram, sizeof(ram), 1);
213 state_fio->Fread(cmos, sizeof(cmos), 1);
214 cmos_crc32 = state_fio->FgetUint32();
215 bank = state_fio->FgetUint8();
216 psel = state_fio->FgetUint8();
217 csel = state_fio->FgetUint8();
218 pcm_on = state_fio->FgetBool();
219 pcm_cont = state_fio->FgetBool();
220 pcm_pit = state_fio->FgetBool();
221 fdc_irq = state_fio->FgetBool();
222 motor = state_fio->FgetBool();