Mercurial > repos > blastem
comparison io.c @ 1427:4e5797b3935a
WIP - New savestate format
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 06 Aug 2017 00:06:36 -0700 |
parents | 6a0e3bb6981f |
children | 178de1432291 |
comparison
equal
deleted
inserted
replaced
1426:957325c990d5 | 1427:4e5797b3935a |
---|---|
13 #include <errno.h> | 13 #include <errno.h> |
14 #endif | 14 #endif |
15 #include <string.h> | 15 #include <string.h> |
16 #include <stdlib.h> | 16 #include <stdlib.h> |
17 | 17 |
18 #include "serialize.h" | |
18 #include "io.h" | 19 #include "io.h" |
19 #include "blastem.h" | 20 #include "blastem.h" |
20 #include "genesis.h" | 21 #include "genesis.h" |
21 #include "sms.h" | 22 #include "sms.h" |
22 #include "render.h" | 23 #include "render.h" |
2128 printf ("value: %X\n", value); | 2129 printf ("value: %X\n", value); |
2129 }*/ | 2130 }*/ |
2130 return value; | 2131 return value; |
2131 } | 2132 } |
2132 | 2133 |
2133 | 2134 void io_serialize(io_port *port, serialize_buffer *buf) |
2135 { | |
2136 save_int8(buf, port->output); | |
2137 save_int8(buf, port->control); | |
2138 save_int8(buf, port->serial_out); | |
2139 save_int8(buf, port->serial_in); | |
2140 save_int8(buf, port->serial_ctrl); | |
2141 save_int8(buf, port->device_type); | |
2142 save_buffer32(buf, port->slow_rise_start, 8); | |
2143 switch (port->device_type) | |
2144 { | |
2145 case IO_GAMEPAD6: | |
2146 save_int32(buf, port->device.pad.timeout_cycle); | |
2147 save_int16(buf, port->device.pad.th_counter); | |
2148 break; | |
2149 case IO_MOUSE: | |
2150 save_int32(buf, port->device.mouse.ready_cycle); | |
2151 save_int16(buf, port->device.mouse.last_read_x); | |
2152 save_int16(buf, port->device.mouse.last_read_y); | |
2153 save_int16(buf, port->device.mouse.latched_x); | |
2154 save_int16(buf, port->device.mouse.latched_y); | |
2155 save_int8(buf, port->device.mouse.tr_counter); | |
2156 break; | |
2157 case IO_SATURN_KEYBOARD: | |
2158 case IO_XBAND_KEYBOARD: | |
2159 save_int8(buf, port->device.keyboard.tr_counter); | |
2160 if (port->device_type == IO_XBAND_KEYBOARD) { | |
2161 save_int8(buf, port->device.keyboard.mode); | |
2162 save_int8(buf, port->device.keyboard.cmd); | |
2163 } | |
2164 break; | |
2165 } | |
2166 } | |
2167 | |
2168 void io_deserialize(deserialize_buffer *buf, void *vport) | |
2169 { | |
2170 io_port *port = vport; | |
2171 port->output = load_int8(buf); | |
2172 port->control = load_int8(buf); | |
2173 port->serial_out = load_int8(buf); | |
2174 port->serial_in = load_int8(buf); | |
2175 port->serial_ctrl = load_int8(buf); | |
2176 uint8_t device_type = load_int8(buf); | |
2177 if (device_type != port->device_type) { | |
2178 warning("Loaded save state has a different device type from the current configuration"); | |
2179 return; | |
2180 } | |
2181 switch (port->device_type) | |
2182 { | |
2183 case IO_GAMEPAD6: | |
2184 port->device.pad.timeout_cycle = load_int32(buf); | |
2185 port->device.pad.th_counter = load_int16(buf); | |
2186 break; | |
2187 case IO_MOUSE: | |
2188 port->device.mouse.ready_cycle = load_int32(buf); | |
2189 port->device.mouse.last_read_x = load_int16(buf); | |
2190 port->device.mouse.last_read_y = load_int16(buf); | |
2191 port->device.mouse.latched_x = load_int16(buf); | |
2192 port->device.mouse.latched_y = load_int16(buf); | |
2193 port->device.mouse.tr_counter = load_int8(buf); | |
2194 break; | |
2195 case IO_SATURN_KEYBOARD: | |
2196 case IO_XBAND_KEYBOARD: | |
2197 port->device.keyboard.tr_counter = load_int8(buf); | |
2198 if (port->device_type == IO_XBAND_KEYBOARD) { | |
2199 port->device.keyboard.mode = load_int8(buf); | |
2200 port->device.keyboard.cmd = load_int8(buf); | |
2201 } | |
2202 break; | |
2203 } | |
2204 } |