Mercurial > repos > blastem
comparison z80_util.c @ 1784:72540af9c90a
Implement serialization/deserialization in new Z80 core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 12 Mar 2019 23:06:04 -0700 |
parents | 6e4faa10f9ee |
children | dbff641a33df |
comparison
equal
deleted
inserted
replaced
1783:eda8df5bc74c | 1784:72540af9c90a |
---|---|
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 void z80_serialize(z80_context *context, serialize_buffer *buf) | 229 void z80_serialize(z80_context *context, serialize_buffer *buf) |
230 { | 230 { |
231 //TODO: Implement me | 231 save_int8(buf, context->main[1]);//C |
232 save_int8(buf, context->main[0]);//B | |
233 save_int8(buf, context->main[3]);//E | |
234 save_int8(buf, context->main[2]);//D | |
235 save_int8(buf, context->main[5]);//L | |
236 save_int8(buf, context->main[4]);//H | |
237 save_int8(buf, context->ix);//IXL | |
238 save_int8(buf, context->ix >> 8);//IXH | |
239 save_int8(buf, context->iy);//IYL | |
240 save_int8(buf, context->iy >> 8);//IYH | |
241 save_int8(buf, context->i); | |
242 save_int8(buf, (context->rhigh & 0x80) | (context->r & 0x7F)); | |
243 save_int8(buf, context->main[7]);//A | |
244 uint8_t f = context->last_flag_result & 0xA8 | |
245 | (context->zflag ? 0x40 : 0) | |
246 | (context->chflags & 8 ? 0x10 : 0) | |
247 | (context->pvflag ? 4 : 0) | |
248 | (context->nflag ? 2 : 0) | |
249 | (context->chflags & 0x80 ? 1 : 0); | |
250 save_int8(buf, f); | |
251 save_int8(buf, context->alt[1]);//C | |
252 save_int8(buf, context->alt[0]);//B | |
253 save_int8(buf, context->alt[3]);//E | |
254 save_int8(buf, context->alt[2]);//D | |
255 save_int8(buf, context->alt[5]);//L | |
256 save_int8(buf, context->alt[4]);//H | |
257 save_int8(buf, 0);//non-existant alt ixl | |
258 save_int8(buf, 0);//non-existant alt ixh | |
259 save_int8(buf, 0);//non-existant alt iyl | |
260 save_int8(buf, 0);//non-existant alt iyh | |
261 save_int8(buf, 0);//non-existant alt i | |
262 save_int8(buf, 0);//non-existant alt r | |
263 save_int8(buf, context->alt[7]);//A | |
264 save_int8(buf, context->alt[6]);//F | |
265 | |
266 save_int16(buf, context->pc); | |
267 save_int16(buf, context->sp); | |
268 save_int8(buf, context->imode); | |
269 save_int8(buf, context->iff1); | |
270 save_int8(buf, context->iff2); | |
271 uint8_t is_nmi = context->nmi_cycle != 0xFFFFFFFF && (context->nmi_cycle < context->int_cycle || !context->iff1); | |
272 save_int8(buf, is_nmi);//int_is_nmi | |
273 save_int8(buf, context->busack); | |
274 save_int32(buf, context->cycles); | |
275 save_int32(buf, is_nmi ? context->nmi_cycle : context->int_cycle);//int_cycle | |
276 save_int32(buf, 0);//int_enable_cycle | |
277 save_int32(buf, context->int_cycle); | |
278 save_int32(buf, context->int_end_cycle); | |
279 save_int32(buf, context->nmi_cycle); | |
232 } | 280 } |
233 | 281 |
234 void z80_deserialize(deserialize_buffer *buf, void *vcontext) | 282 void z80_deserialize(deserialize_buffer *buf, void *vcontext) |
235 { | 283 { |
236 //TODO: Implement me | 284 z80_context *context = vcontext; |
285 context->main[1] = load_int8(buf);//C | |
286 context->main[0] = load_int8(buf);//B | |
287 context->main[3] = load_int8(buf);//E | |
288 context->main[2] = load_int8(buf);//D | |
289 context->main[5] = load_int8(buf);//L | |
290 context->main[4] = load_int8(buf);//H | |
291 context->ix = load_int8(buf);//IXL | |
292 context->ix |= load_int8(buf) << 8;//IXH | |
293 context->iy = load_int8(buf);//IYL | |
294 context->iy |= load_int8(buf) << 8;//IYH | |
295 context->i = load_int8(buf); | |
296 context->r = load_int8(buf); | |
297 context->rhigh = context->r & 0x80; | |
298 context->main[7] = load_int8(buf);//A | |
299 context->last_flag_result = load_int8(buf); | |
300 context->zflag = context->last_flag_result & 0x40; | |
301 context->chflags = context->last_flag_result & 0x10 ? 8 : 0; | |
302 context->pvflag = context->last_flag_result & 4; | |
303 context->nflag = context->last_flag_result & 2; | |
304 context->chflags |= context->last_flag_result & 1 ? 0x80 : 0; | |
305 context->alt[1] = load_int8(buf);//C | |
306 context->alt[0] = load_int8(buf);//B | |
307 context->alt[3] = load_int8(buf);//E | |
308 context->alt[2] = load_int8(buf);//D | |
309 context->alt[5] = load_int8(buf);//L | |
310 context->alt[4] = load_int8(buf);//H | |
311 load_int8(buf);//non-existant alt ixl | |
312 load_int8(buf);//non-existant alt ixh | |
313 load_int8(buf);//non-existant alt iyl | |
314 load_int8(buf);//non-existant alt iyh | |
315 load_int8(buf);//non-existant alt i | |
316 load_int8(buf);//non-existant alt r | |
317 context->alt[7] = load_int8(buf);//A | |
318 context->alt[6] = load_int8(buf);//F | |
319 | |
320 context->pc = load_int16(buf); | |
321 context->sp = load_int16(buf); | |
322 context->imode = load_int8(buf); | |
323 context->iff1 = load_int8(buf); | |
324 context->iff2 = load_int8(buf); | |
325 load_int8(buf);//int_is_nmi | |
326 context->busack = load_int8(buf); | |
327 context->cycles = load_int32(buf); | |
328 load_int32(buf);//int_cycle | |
329 load_int32(buf);//int_enable_cycle | |
330 context->int_cycle = load_int32(buf); | |
331 context->int_end_cycle = load_int32(buf); | |
332 context->nmi_cycle = load_int32(buf); | |
237 } | 333 } |
238 | 334 |
239 void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler) | 335 void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler) |
240 { | 336 { |
241 } | 337 } |