comparison m68k_core.c @ 1427:4e5797b3935a

WIP - New savestate format
author Michael Pavone <pavone@retrodev.com>
date Sun, 06 Aug 2017 00:06:36 -0700
parents df6af7187b36
children aa945f1bdd71
comparison
equal deleted inserted replaced
1426:957325c990d5 1427:4e5797b3935a
7 #include "m68k_internal.h" 7 #include "m68k_internal.h"
8 #include "68kinst.h" 8 #include "68kinst.h"
9 #include "backend.h" 9 #include "backend.h"
10 #include "gen.h" 10 #include "gen.h"
11 #include "util.h" 11 #include "util.h"
12 #include "serialize.h"
12 #include <stdio.h> 13 #include <stdio.h>
13 #include <stddef.h> 14 #include <stddef.h>
14 #include <stdlib.h> 15 #include <stdlib.h>
15 #include <string.h> 16 #include <string.h>
16 17
1200 context->int_cycle = CYCLE_NEVER; 1201 context->int_cycle = CYCLE_NEVER;
1201 context->status = 0x27; 1202 context->status = 0x27;
1202 context->reset_handler = (code_ptr)reset_handler; 1203 context->reset_handler = (code_ptr)reset_handler;
1203 return context; 1204 return context;
1204 } 1205 }
1206
1207 void m68k_serialize(m68k_context *context, uint32_t pc, serialize_buffer *buf)
1208 {
1209 for (int i = 0; i < 8; i++)
1210 {
1211 save_int32(buf, context->dregs[i]);
1212 }
1213 for (int i = 0; i < 9; i++)
1214 {
1215 save_int32(buf, context->aregs[i]);
1216 }
1217 save_int32(buf, pc);
1218 uint16_t sr = context->status << 3;
1219 for (int flag = 4; flag >= 0; flag--) {
1220 sr <<= 1;
1221 sr |= context->flags[flag] != 0;
1222 }
1223 save_int16(buf, sr);
1224 save_int32(buf, context->current_cycle);
1225 save_int32(buf, context->int_cycle);
1226 save_int8(buf, context->int_num);
1227 save_int8(buf, context->int_pending);
1228 save_int8(buf, context->trace_pending);
1229 }
1230
1231 void m68k_deserialize(deserialize_buffer *buf, void *vcontext)
1232 {
1233 m68k_context *context = vcontext;
1234 for (int i = 0; i < 8; i++)
1235 {
1236 context->dregs[i] = load_int32(buf);
1237 }
1238 for (int i = 0; i < 9; i++)
1239 {
1240 context->aregs[i] = load_int32(buf);
1241 }
1242 //hack until both PC and IR registers are represented properly
1243 context->last_prefetch_address = load_int32(buf);
1244 uint16_t sr = load_int16(buf);
1245 context->status = sr >> 8;
1246 for (int flag = 0; flag < 5; flag++)
1247 {
1248 context->flags[flag] = sr & 1;
1249 sr >>= 1;
1250 }
1251 context->current_cycle = load_int32(buf);
1252 context->int_cycle = load_int32(buf);
1253 context->int_num = load_int8(buf);
1254 context->int_pending = load_int8(buf);
1255 context->trace_pending = load_int8(buf);
1256 }