comparison gst.c @ 1752:d6d4c006a7b3

Initial attempt at interrupts in new Z80 core and integrating it into main executable
author Michael Pavone <pavone@retrodev.com>
date Sun, 10 Feb 2019 11:58:23 -0800
parents 7e67f8a37051
children 2d462aa78349
comparison
equal deleted inserted replaced
1751:c5d4e1d14dac 1752:d6d4c006a7b3
142 fputs("Failed to read Z80 registers from savestate\n", stderr); 142 fputs("Failed to read Z80 registers from savestate\n", stderr);
143 return 0; 143 return 0;
144 } 144 }
145 uint8_t * curpos = regdata; 145 uint8_t * curpos = regdata;
146 uint8_t f = *(curpos++); 146 uint8_t f = *(curpos++);
147 #ifndef NEW_CORE
147 context->flags[ZF_C] = f & 1; 148 context->flags[ZF_C] = f & 1;
148 f >>= 1; 149 f >>= 1;
149 context->flags[ZF_N] = f & 1; 150 context->flags[ZF_N] = f & 1;
150 f >>= 1; 151 f >>= 1;
151 context->flags[ZF_PV] = f & 1; 152 context->flags[ZF_PV] = f & 1;
198 context->mem_pointers[1] = context->mem_pointers[2] + bank; 199 context->mem_pointers[1] = context->mem_pointers[2] + bank;
199 } else { 200 } else {
200 context->mem_pointers[1] = NULL; 201 context->mem_pointers[1] = NULL;
201 } 202 }
202 context->bank_reg = bank >> 15; 203 context->bank_reg = bank >> 15;
204 #endif
203 uint8_t buffer[Z80_RAM_BYTES]; 205 uint8_t buffer[Z80_RAM_BYTES];
204 fseek(gstfile, GST_Z80_RAM, SEEK_SET); 206 fseek(gstfile, GST_Z80_RAM, SEEK_SET);
205 if(fread(buffer, 1, sizeof(buffer), gstfile) != (8*1024)) { 207 if(fread(buffer, 1, sizeof(buffer), gstfile) != (8*1024)) {
206 fputs("Failed to read Z80 RAM from savestate\n", stderr); 208 fputs("Failed to read Z80 RAM from savestate\n", stderr);
207 return 0; 209 return 0;
208 } 210 }
209 for (int i = 0; i < Z80_RAM_BYTES; i++) 211 for (int i = 0; i < Z80_RAM_BYTES; i++)
210 { 212 {
211 if (context->mem_pointers[0][i] != buffer[i]) { 213 if (context->mem_pointers[0][i] != buffer[i]) {
212 context->mem_pointers[0][i] = buffer[i]; 214 context->mem_pointers[0][i] = buffer[i];
215 #ifndef NEW_CORE
213 z80_handle_code_write(i, context); 216 z80_handle_code_write(i, context);
214 } 217 #endif
215 } 218 }
219 }
220 #ifndef NEW_CORE
216 context->native_pc = NULL; 221 context->native_pc = NULL;
217 context->extra_pc = NULL; 222 context->extra_pc = NULL;
223 #endif
218 return 1; 224 return 1;
219 } 225 }
220 226
221 uint8_t vdp_load_gst(vdp_context * context, FILE * state_file) 227 uint8_t vdp_load_gst(vdp_context * context, FILE * state_file)
222 { 228 {
294 uint8_t z80_save_gst(z80_context * context, FILE * gstfile) 300 uint8_t z80_save_gst(z80_context * context, FILE * gstfile)
295 { 301 {
296 uint8_t regdata[GST_Z80_REG_SIZE]; 302 uint8_t regdata[GST_Z80_REG_SIZE];
297 uint8_t * curpos = regdata; 303 uint8_t * curpos = regdata;
298 memset(regdata, 0, sizeof(regdata)); 304 memset(regdata, 0, sizeof(regdata));
305 #ifndef NEW_CORE
299 uint8_t f = context->flags[ZF_S]; 306 uint8_t f = context->flags[ZF_S];
300 f <<= 1; 307 f <<= 1;
301 f |= context->flags[ZF_Z] ; 308 f |= context->flags[ZF_Z] ;
302 f <<= 2; 309 f <<= 2;
303 f |= context->flags[ZF_H]; 310 f |= context->flags[ZF_H];
346 *(curpos++) = !context->reset; 353 *(curpos++) = !context->reset;
347 *curpos = context->busreq; 354 *curpos = context->busreq;
348 curpos += 3; 355 curpos += 3;
349 uint32_t bank = context->bank_reg << 15; 356 uint32_t bank = context->bank_reg << 15;
350 write_le_32(curpos, bank); 357 write_le_32(curpos, bank);
358 #endif
351 fseek(gstfile, GST_Z80_REGS, SEEK_SET); 359 fseek(gstfile, GST_Z80_REGS, SEEK_SET);
352 if (fwrite(regdata, 1, sizeof(regdata), gstfile) != sizeof(regdata)) { 360 if (fwrite(regdata, 1, sizeof(regdata), gstfile) != sizeof(regdata)) {
353 return 0; 361 return 0;
354 } 362 }
355 fseek(gstfile, GST_Z80_RAM, SEEK_SET); 363 fseek(gstfile, GST_Z80_RAM, SEEK_SET);