From f0f152ace5bb9ccfcef340b7fde64b57078dacaa Mon Sep 17 00:00:00 2001 From: ergo720 Date: Mon, 22 Jan 2018 19:08:08 +0100 Subject: [PATCH] Simplified HalIsResetOrShutdownPending implementation --- src/CxbxKrnl/EmuKrnlHal.cpp | 17 +++++++++-------- src/devices/SMCDevice.cpp | 13 ------------- src/devices/SMCDevice.h | 7 +------ 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/CxbxKrnl/EmuKrnlHal.cpp b/src/CxbxKrnl/EmuKrnlHal.cpp index 216fd8ec2..dc82052a0 100644 --- a/src/CxbxKrnl/EmuKrnlHal.cpp +++ b/src/CxbxKrnl/EmuKrnlHal.cpp @@ -70,6 +70,11 @@ namespace NtDll static DWORD EmuSoftwareInterrupRequestRegister = 0; HalSystemInterrupt HalSystemInterrupts[MAX_BUS_INTERRUPT_LEVEL + 1]; +// variables used by the SMC to know a reset / shutdown is pending +uint8_t ResetOrShutdownCommandCode = 0; +uint32_t ResetOrShutdownDataValue = 0; + + // ****************************************************************** // * 0x0009 - HalReadSMCTrayState() // ****************************************************************** @@ -685,11 +690,8 @@ XBSYSAPI EXPORTNUM(358) xboxkrnl::BOOLEAN NTAPI xboxkrnl::HalIsResetOrShutdownPe LOG_FUNC(); BOOLEAN ret = FALSE; - uint8_t CommandCode; - uint32_t DataValue; - g_SMC->GetResetOrShutdownCode(&CommandCode, &DataValue); - if (CommandCode != 0) { ret = TRUE; } + if (ResetOrShutdownCommandCode != 0) { ret = TRUE; } RETURN(ret); } @@ -704,10 +706,9 @@ XBSYSAPI EXPORTNUM(360) xboxkrnl::NTSTATUS NTAPI xboxkrnl::HalInitiateShutdown { LOG_FUNC(); - uint8_t CommandCode = SMC_COMMAND_RESET; - uint32_t DataValue = SMC_RESET_ASSERT_SHUTDOWN; - g_SMC->SetResetOrShutdownCode(&CommandCode, &DataValue); - xboxkrnl::HalWriteSMBusValue(SMBUS_SMC_SLAVE_ADDRESS, CommandCode, 0, DataValue); + ResetOrShutdownCommandCode = SMC_COMMAND_RESET; + ResetOrShutdownDataValue = SMC_RESET_ASSERT_SHUTDOWN; + xboxkrnl::HalWriteSMBusValue(SMBUS_SMC_SLAVE_ADDRESS, ResetOrShutdownCommandCode, 0, ResetOrShutdownDataValue); RETURN(S_OK); } diff --git a/src/devices/SMCDevice.cpp b/src/devices/SMCDevice.cpp index 3b83ba6d1..d496ea7e3 100644 --- a/src/devices/SMCDevice.cpp +++ b/src/devices/SMCDevice.cpp @@ -75,8 +75,6 @@ void SMCDevice::Init() buffer[SMC_COMMAND_AV_PACK] = AV_PACK_HDTV; // see http://xboxdevwiki.net/PIC#The_AV_Pack buffer[SMC_COMMAND_LED_SEQUENCE] = LED::GREEN; buffer[SMC_COMMAND_SCRATCH] = 0; // http://xboxdevwiki.net/PIC#Scratch_register_values - ResetOrShutdownCommandCode.store(0); - ResetOrShutdownDataValue.store(0); } void SMCDevice::Reset() @@ -212,14 +210,3 @@ void SMCDevice::WriteBlock(uint8_t command, uint8_t* data, int length) // TODO } -void SMCDevice::GetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue) -{ - *CommandCode = ResetOrShutdownCommandCode.load(); - *DataValue = ResetOrShutdownDataValue.load(); -} - -void SMCDevice::SetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue) -{ - ResetOrShutdownCommandCode.store(*CommandCode); - ResetOrShutdownDataValue.store(*DataValue); -} diff --git a/src/devices/SMCDevice.h b/src/devices/SMCDevice.h index a43cc0d40..306b04ca7 100644 --- a/src/devices/SMCDevice.h +++ b/src/devices/SMCDevice.h @@ -36,7 +36,6 @@ #pragma once #include "SMDevice.h" -#include // This https://upload.wikimedia.org/wikipedia/commons/9/94/Xbox-Motherboard-FR.jpg shows : // PIC16LC63A-04/SO @@ -120,15 +119,11 @@ public: void WriteByte(uint8_t command, uint8_t value); void WriteWord(uint8_t command, uint16_t value); void WriteBlock(uint8_t command, uint8_t* data, int length); - void GetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue); - void SetResetOrShutdownCode(uint8_t* CommandCode, uint32_t* DataValue); + private: HardwareModel m_HardwareModel; int m_PICVersionStringIndex = 0; uint8_t buffer[256] = {}; - // variables used by the SMC to know a reset / shutdown is pending - std::atomic ResetOrShutdownCommandCode; - std::atomic ResetOrShutdownDataValue; }; extern SMCDevice* g_SMC;