MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / DoState

Method DoState

pcsx2/USB/USB.cpp:374–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374bool USB::DoState(StateWrapper& sw)
375{
376 std::array<bool, 2> valid_devices = {};
377
378 if (sw.IsReading())
379 {
380 if (!sw.DoMarker("USB") || !USB::DoOHCIState(sw))
381 {
382 Console.Error("USB state is invalid, resetting.");
383 USBreset();
384 return true;
385 }
386
387 for (u32 port = 0; port < USB::NUM_PORTS; port++)
388 {
389 s32 state_devtype;
390 u32 state_devsubtype;
391 u32 state_size;
392 sw.Do(&state_devtype);
393 sw.Do(&state_devsubtype);
394 sw.Do(&state_size);
395
396 // this is *assuming* the config is correct... there's no reason it shouldn't be.
397 if (sw.HasError() ||
398 EmuConfig.USB.Ports[port].DeviceType != state_devtype ||
399 EmuConfig.USB.Ports[port].DeviceSubtype != state_devsubtype ||
400 (state_devtype != DEVTYPE_NONE && !s_usb_device[port]))
401 {
402 Console.Error("Save state has device type %u, but config has %u. Reattaching device.", state_devtype, EmuConfig.USB.Ports[port].DeviceType);
403 if (s_usb_device[port])
404 usb_reattach(&USB::GetOHCIPort(port).port);
405
406 sw.SkipBytes(state_size);
407 continue;
408 }
409
410 if (!s_usb_device[port])
411 {
412 // nothing in this port
413 sw.SkipBytes(state_size);
414 continue;
415 }
416
417 USB::DoDeviceState(s_usb_device[port], sw);
418
419 if (!s_usb_device_proxy[port]->Freeze(s_usb_device[port], sw) || sw.HasError())
420 {
421 Console.Error("Failed to deserialize USB port %u, removing device.", port);
422 USB::DestroyDevice(port);
423 continue;
424 }
425
426 valid_devices[port] = true;
427 }
428
429 USB::DoPacketState(&s_qemu_ohci->usb_packet, sw, valid_devices);
430 if (sw.HasError())
431 {

Callers 1

FreezeInternalsMethod · 0.45

Calls 13

USBresetFunction · 0.85
usb_reattachFunction · 0.85
IsReadingMethod · 0.80
DoMarkerMethod · 0.80
SkipBytesMethod · 0.80
GetPositionMethod · 0.80
GetStreamMethod · 0.80
SeekAbsoluteMethod · 0.80
ErrorMethod · 0.45
DoMethod · 0.45
HasErrorMethod · 0.45
FreezeMethod · 0.45

Tested by

no test coverage detected