Mercurial > repos > blastem
comparison gst.c @ 2053:3414a4423de1 segacd
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Jan 2022 13:15:21 -0800 |
parents | 2d462aa78349 |
children | f699f9d500b4 |
comparison
equal
deleted
inserted
replaced
1692:5dacaef602a7 | 2053:3414a4423de1 |
---|---|
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 { |
236 } | 242 } |
237 for (int i = 0; i < CRAM_SIZE; i++) { | 243 for (int i = 0; i < CRAM_SIZE; i++) { |
238 uint16_t value; | 244 uint16_t value; |
239 write_cram_internal(context, i, (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]); | 245 write_cram_internal(context, i, (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]); |
240 } | 246 } |
241 if (fread(tmp_buf, 2, VSRAM_SIZE, state_file) != VSRAM_SIZE) { | 247 if (fread(tmp_buf, 2, MIN_VSRAM_SIZE, state_file) != MIN_VSRAM_SIZE) { |
242 fputs("Failed to read VSRAM from savestate\n", stderr); | 248 fputs("Failed to read VSRAM from savestate\n", stderr); |
243 return 0; | 249 return 0; |
244 } | 250 } |
245 for (int i = 0; i < VSRAM_SIZE; i++) { | 251 for (int i = 0; i < MIN_VSRAM_SIZE; i++) { |
246 context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; | 252 context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; |
247 } | 253 } |
248 fseek(state_file, GST_VDP_MEM, SEEK_SET); | 254 fseek(state_file, GST_VDP_MEM, SEEK_SET); |
249 if (fread(tmp_buf, 1, VRAM_SIZE, state_file) != VRAM_SIZE) { | 255 if (fread(tmp_buf, 1, VRAM_SIZE, state_file) != VRAM_SIZE) { |
250 fputs("Failed to read VRAM from savestate\n", stderr); | 256 fputs("Failed to read VRAM from savestate\n", stderr); |
272 } | 278 } |
273 if (fwrite(tmp_buf, 1, sizeof(tmp_buf), outfile) != sizeof(tmp_buf)) { | 279 if (fwrite(tmp_buf, 1, sizeof(tmp_buf), outfile) != sizeof(tmp_buf)) { |
274 fputs("Error writing CRAM to savestate\n", stderr); | 280 fputs("Error writing CRAM to savestate\n", stderr); |
275 return 0; | 281 return 0; |
276 } | 282 } |
277 for (int i = 0; i < VSRAM_SIZE; i++) | 283 for (int i = 0; i < MIN_VSRAM_SIZE; i++) |
278 { | 284 { |
279 tmp_buf[i*2] = context->vsram[i]; | 285 tmp_buf[i*2] = context->vsram[i]; |
280 tmp_buf[i*2+1] = context->vsram[i] >> 8; | 286 tmp_buf[i*2+1] = context->vsram[i] >> 8; |
281 } | 287 } |
282 if (fwrite(tmp_buf, 2, VSRAM_SIZE, outfile) != VSRAM_SIZE) { | 288 if (fwrite(tmp_buf, 2, MIN_VSRAM_SIZE, outfile) != MIN_VSRAM_SIZE) { |
283 fputs("Error writing VSRAM to savestate\n", stderr); | 289 fputs("Error writing VSRAM to savestate\n", stderr); |
284 return 0; | 290 return 0; |
285 } | 291 } |
286 fseek(outfile, GST_VDP_MEM, SEEK_SET); | 292 fseek(outfile, GST_VDP_MEM, SEEK_SET); |
287 if (fwrite(context->vdpmem, 1, VRAM_SIZE, outfile) != VRAM_SIZE) { | 293 if (fwrite(context->vdpmem, 1, VRAM_SIZE, outfile) != VRAM_SIZE) { |
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); |