Mercurial > repos > blastem
comparison m68k_util.c @ 2654:6068d32b756c
Implement serialization for new 68K core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 02 Mar 2025 17:34:02 -0800 |
parents | 1072cc337822 |
children | ec02a08196d5 |
comparison
equal
deleted
inserted
replaced
2653:f85208405ae8 | 2654:6068d32b756c |
---|---|
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 void m68k_serialize(m68k_context *context, uint32_t pc, serialize_buffer *buf) | 288 void m68k_serialize(m68k_context *context, uint32_t pc, serialize_buffer *buf) |
289 { | 289 { |
290 //TODO: implement me | 290 for (int i = 0; i < 8; i++) |
291 { | |
292 save_int32(buf, context->dregs[i]); | |
293 } | |
294 for (int i = 0; i < 8; i++) | |
295 { | |
296 save_int32(buf, context->aregs[i]); | |
297 } | |
298 save_int32(buf, context->other_sp); | |
299 //old core saves the address of hte instruction that will execute upon resume | |
300 //in this field so we need to adjust PC here for compatibility | |
301 save_int32(buf, context->pc - 2); | |
302 uint16_t sr = context->status << 8; | |
303 if (context->xflag) { sr |= 0x10; } | |
304 if (context->nflag) { sr |= 0x08; } | |
305 if (context->zflag) { sr |= 0x04; } | |
306 if (context->vflag) { sr |= 0x02; } | |
307 if (context->cflag) { sr |= 0x1; } | |
308 save_int16(buf, sr); | |
309 save_int32(buf, context->cycles); | |
310 save_int32(buf, context->int_cycle); | |
311 save_int8(buf, context->int_priority); //int_num on old core, but it's the priority level | |
312 save_int8(buf, context->int_pending); | |
313 save_int8(buf, context->trace_pending); | |
314 //remaining fields have no equivalent in old core | |
315 save_int16(buf, context->prefetch); | |
316 save_int8(buf, context->stopped); | |
317 save_int8(buf, context->int_num); | |
318 save_int8(buf, context->int_pending_num); | |
291 } | 319 } |
292 | 320 |
293 void m68k_deserialize(deserialize_buffer *buf, void *vcontext) | 321 void m68k_deserialize(deserialize_buffer *buf, void *vcontext) |
294 { | 322 { |
295 //TODO: implement me | 323 m68k_context *context = vcontext; |
324 for (int i = 0; i < 8; i++) | |
325 { | |
326 context->dregs[i] = load_int32(buf); | |
327 } | |
328 for (int i = 0; i < 8; i++) | |
329 { | |
330 context->aregs[i] = load_int32(buf); | |
331 } | |
332 context->other_sp = load_int32(buf); | |
333 context->pc = load_int32(buf); | |
334 uint16_t sr = load_int16(buf); | |
335 context->status = sr >> 8; | |
336 context->xflag = sr & 0x10; | |
337 context->nflag = sr & 0x08; | |
338 context->zflag = sr & 0x04; | |
339 context->vflag = sr & 0x02; | |
340 context->cflag = sr & 0x01; | |
341 context->cycles = load_int32(buf); | |
342 context->int_cycle = load_int32(buf); | |
343 context->int_priority = load_int8(buf); //int_num on old core, but it's the priority level | |
344 context->int_pending = load_int8(buf); | |
345 context->trace_pending = load_int8(buf); | |
346 if (buf->cur_pos < buf->size) { | |
347 context->prefetch = load_int16(buf); | |
348 context->stopped = load_int8(buf); | |
349 context->int_num = load_int8(buf); | |
350 context->int_pending_num = load_int8(buf); | |
351 } else { | |
352 context->prefetch = read_word(context->pc, (void**)context->mem_pointers, &context->opts->gen, context); | |
353 context->stopped = 0; | |
354 context->int_num = context->int_pending_num = 0; | |
355 } | |
356 //adjust for compatibility with old core | |
357 context->pc += 2; | |
296 } | 358 } |
297 | 359 |
298 void start_68k_context(m68k_context *context, uint32_t pc) | 360 void start_68k_context(m68k_context *context, uint32_t pc) |
299 { | 361 { |
300 context->scratch1 = context->pc = pc; | 362 context->scratch1 = context->pc = pc; |