| 378 | } |
| 379 | |
| 380 | void Sio2::Write(u8 data) |
| 381 | { |
| 382 | Sio2Log.WriteLn("%s(%02X) SIO2 DATA Write", __FUNCTION__, data); |
| 383 | |
| 384 | if (!queueRead) |
| 385 | { |
| 386 | // No more queue positions to access, but the game is still sending us SIO2 writes. Lets ignore them. |
| 387 | if (queuePosition > CmdQueue.size()) |
| 388 | { |
| 389 | Console.Warning("%s(%02X) Received data after exhausting all queue entries!", __FUNCTION__, data); |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | const u32 currentCmd = CmdQueue[queuePosition]; |
| 394 | port = currentCmd & Sio2Cmd::PORT; |
| 395 | commandLength = (currentCmd >> 8) & Sio2Cmd::COMMAND_LENGTH_MASK; |
| 396 | queueRead = true; |
| 397 | |
| 398 | // The freshly read cmd position had a length of 0, so we are done handling SIO2 commands until |
| 399 | // the next cmd writes. |
| 400 | if (commandLength == 0) |
| 401 | { |
| 402 | queueComplete = true; |
| 403 | } |
| 404 | |
| 405 | // If the prior command did not need to fully pop g_Sio2FifoIn, do so now, |
| 406 | // so that the next command isn't trying to read the last command's leftovers. |
| 407 | while (!g_Sio2FifoIn.empty()) |
| 408 | { |
| 409 | g_Sio2FifoIn.pop_front(); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | if (queueComplete) |
| 414 | { |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | g_Sio2FifoIn.push_back(data); |
| 419 | |
| 420 | // We have received as many command bytes as we expect, and... |
| 421 | // |
| 422 | // ... These were from direct writes into IOP memory (DMA block size is zero when direct writes occur) |
| 423 | // ... These were from SIO2 DMA (DMA block size is non-zero when SIO2 DMA occurs) |
| 424 | if ((g_Sio2FifoIn.size() == g_Sio2.commandLength && g_Sio2.dmaBlockSize == 0) || g_Sio2FifoIn.size() == g_Sio2.dmaBlockSize) |
| 425 | { |
| 426 | // Go ahead and prep so the next write triggers a load of the new cmd value. |
| 427 | g_Sio2.queueRead = false; |
| 428 | g_Sio2.queuePosition++; |
| 429 | |
| 430 | // Check the SIO mode |
| 431 | const u8 sioMode = g_Sio2FifoIn.front(); |
| 432 | g_Sio2FifoIn.pop_front(); |
| 433 | |
| 434 | switch (sioMode) |
| 435 | { |
| 436 | case SioMode::PAD: |
| 437 | this->Pad(); |
no test coverage detected