Skip to content

Commit

Permalink
Adding Some Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Xphalnos committed Jan 29, 2025
1 parent 2d1f1df commit 121257f
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 81 deletions.
11 changes: 4 additions & 7 deletions Xenon/Base/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <toml.hpp>

#include <iostream>

#include "Config.h"
#include "Path_util.h"
#include "Logging/Log.h"
Expand Down Expand Up @@ -33,9 +31,8 @@ static bool isFullscreen = false;
Base::Log::Level currentLogLevel = Base::Log::Level::Info;

// SMC.
static int smcPowerOnReason =
0x11; // Valid values are: 0x11 (SMC_PWR_REAS_PWRBTN) and 0x12
// (SMC_PWR_REAS_EJECT).
static int smcPowerOnReason = 0x11; // Valid values are: 0x11 (SMC_PWR_REAS_PWRBTN) and 0x12
// (SMC_PWR_REAS_EJECT).
static int comPort = 2;
static std::string com = "";

Expand Down Expand Up @@ -156,9 +153,9 @@ void saveConfig(const std::filesystem::path &path) {
}
} else {
if (error) {
std::cout << "Filesystem error: " << error.message() << std::endl;
LOG_ERROR(Config, "Filesystem error: {}", error.message());
}
LOG_INFO(Config, "Config not found. Saving new configuration file: {}", path.string());
LOG_INFO(Config, "Config not found. Saving new configuration file: {}", path.string());
}

// General.
Expand Down
13 changes: 7 additions & 6 deletions Xenon/Core/NAND/NAND.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// Copyright 2025 Xenon Emulator Project

#include "Base/Logging/Log.h"

#include "NAND.h"

/********************Responsible for loading the NAND file********************/
bool NAND::Load(const std::string filePath) {
std::cout << "NAND: Loading file " << filePath.c_str() << std::endl;
LOG_INFO(System, "NAND: Loading file {}", filePath.c_str());

if (fopen_s(&inputFile, filePath.c_str(), "rb") != 0) {
std::cout << "NAND: Unable to load file!" << std::endl;
LOG_CRITICAL(System, "NAND: Unable to load file!");
return false;
}

fseek(inputFile, 0, SEEK_END);
rawFileSize = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);

std::cout << "NAND: File size = 0x" << rawFileSize << " bytes." << std::endl;
LOG_INFO(System, "NAND: File size = 0x{} bytes.", rawFileSize);

CheckMagic();

if (!CheckMagic()) {
std::cout << "NAND: wrong magic found, Xbox 360 Retail NAND magic"
<< "is 0xFF4F and Devkit NAND magic 0x0F4F." << std::endl;
LOG_ERROR(System, "NAND: wrong magic found, Xbox 360 Retail NAND magic is 0xFF4F and Devkit NAND magic 0x0F4F.");
return false;
}

Expand All @@ -37,7 +38,7 @@ bool NAND::Load(const std::string filePath) {
CheckSpare();

if (hasSpare) {
std::cout << "NAND: Image has spare." << std::endl;
LOG_INFO(System, "NAND: Image has spare.");

// Check Meta Type
imageMetaType = DetectSpareType();
Expand Down
1 change: 0 additions & 1 deletion Xenon/Core/NAND/NAND.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#pragma once

#include <fstream>
#include <iostream>

#include "Base/SystemDevice.h"

Expand Down
8 changes: 4 additions & 4 deletions Xenon/Core/RootBus/HostBridge/PCIBridge/ETHERNET/Ethernet.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2025 Xenon Emulator Project

#include "Base/Logging/Log.h"

#include "Ethernet.h"

#define XE_NET_STATUS_INT 0x0000004C
Expand Down Expand Up @@ -72,8 +74,7 @@ void Xe::PCIDev::ETHERNET::ETHERNET::Read(u64 readAddress, u64 *data,
memcpy(data, &ethPciState.address1Reg, byteCount);
break;
default:
std::cout << "[WARN] Ethernet: Unknown PCI Reg being read 0x" << (u16)offset
<< std::endl;
LOG_ERROR(ETH, "Unknown PCI Reg being read 0x{}", (u16)offset);
memset(data, 0xFF, byteCount);
break;
}
Expand Down Expand Up @@ -144,8 +145,7 @@ void Xe::PCIDev::ETHERNET::ETHERNET::Write(u64 writeAddress, u64 data,
ethPciState.address1Reg = static_cast<u32>(data);
break;
default:
std::cout << "[WARN] Ethernet: Unknown PCI Reg being written 0x"
<< (u16)offset << " data = 0x" << data << std::endl;
LOG_ERROR(ETH, "Unknown PCI Reg being written 0x{} data = 0x{}", (u16)offset, data);
break;
}
}
Expand Down
2 changes: 0 additions & 2 deletions Xenon/Core/RootBus/HostBridge/PCIBridge/ETHERNET/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#pragma once

#include <iostream>

#include "Core/RootBus/HostBridge/PCIBridge/PCIDevice.h"

namespace Xe {
Expand Down
10 changes: 5 additions & 5 deletions Xenon/Core/RootBus/HostBridge/PCIBridge/HDD/HDD.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2025 Xenon Emulator Project

#include "Base/Logging/Log.h"

#include "HDD.h"

HDD::HDD(PCIBridge *parentPCIBridge) {
Expand Down Expand Up @@ -45,8 +47,7 @@ void HDD::Read(u64 readAddress, u64 *data, u8 byteCount) {

memcpy(data, (u8 *)&ataDeviceState.ataReadState + regOffset, byteCount);
} else {
std::cout << "ATA: Unknown register being accesed: (Read)0x" << regOffset
<< std::endl;
LOG_ERROR(HDD, "ATA: Unknown register being accesed: (Read)0x{}", regOffset);
memset(data, 0, byteCount);
}
}
Expand Down Expand Up @@ -121,8 +122,7 @@ void HDD::Write(u64 writeAddress, u64 data, u8 byteCount) {

memcpy((u8 *)&ataDeviceState.ataWriteState + regOffset, &data, byteCount);
} else {
std::cout << "ATA: Unknown register being accesed: (Write)0x" << regOffset
<< std::endl;
LOG_ERROR(HDD, "ATA: Unknown register being accesed: (Write)0x{}", regOffset);
}
}

Expand All @@ -136,7 +136,7 @@ void HDD::ConfigWrite(u64 writeAddress, u64 data, u8 byteCount) {

void HDD::ataCopyIdentifyDeviceData() {
if (!ataDeviceState.readBuffer.empty())
std::cout << "HDD: Read Buffer not empty!" << std::endl;
LOG_ERROR(HDD, "Read Buffer not empty!");

ataDeviceState.readBuffer.resize(sizeof(ATA_IDENTIFY_DATA));

Expand Down
1 change: 0 additions & 1 deletion Xenon/Core/RootBus/HostBridge/PCIBridge/HDD/HDD.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#pragma once

#include <iostream>
#include <vector>

#include "Core/RootBus/HostBridge/PCIBridge/PCIBridge.h"
Expand Down
24 changes: 8 additions & 16 deletions Xenon/Core/RootBus/HostBridge/PCIBridge/ODD/ODD.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2025 Xenon Emulator Project

#include "Base/Logging/Log.h"

#include "ODD.h"

//
Expand Down Expand Up @@ -462,8 +464,7 @@ void ODD::processSCSICommand() {

break;
default:
std::cout << "ATAPI: Unknown SCSI Command requested: 0x"
<< atapiState.scsiCBD.CDB12.OperationCode << std::endl;
LOG_ERROR(ODD, "Unknown SCSI Command requested: 0x{}", atapiState.scsiCBD.CDB12.OperationCode);
}

atapiState.atapiRegs.interruptReasonReg = IDE_INTERRUPT_REASON_IO;
Expand Down Expand Up @@ -566,9 +567,7 @@ void ODD::Read(u64 readAddress, u64 *data, u8 byteCount) {
memcpy(data, &atapiState.atapiRegs.statusReg, byteCount);
return;
default:
std::cout << "ATAPI: Unknown Command Register Block register being read, "
"command"
<< "code = 0x" << atapiCommandReg << std::endl;
LOG_ERROR(ODD, "Unknown Command Register Block register being read, command code = 0x{}", atapiCommandReg);
break;
}
} else {
Expand All @@ -584,9 +583,7 @@ void ODD::Read(u64 readAddress, u64 *data, u8 byteCount) {
memcpy(data, &atapiState.atapiRegs.dmaTableOffsetReg, byteCount);
break;
default:
std::cout << "ATAPI: Unknown Control Register Block register being read, "
"command"
<< "code = 0x" << atapiControlReg << std::endl;
LOG_ERROR(ODD, "Unknown Control Register Block register being read, command code = 0x{}", atapiControlReg);
break;
}
}
Expand Down Expand Up @@ -665,15 +662,12 @@ void ODD::Write(u64 writeAddress, u64 data, u8 byteCount) {
atapiIdentifyCommand();
return;
default:
std::cout << "ATAPI: Unknown command, command code = 0x" << data
<< std::endl;
LOG_ERROR(ODD, "Unknown command, command code = 0x{}", data);
break;
}
return;
default:
std::cout << "ATAPI: Unknown Command Register Block register being "
"written, command"
<< "code = 0x" << atapiCommandReg << std::endl;
LOG_ERROR(ODD, "Unknown Command Register Block register being written, command code = 0x{}", atapiCommandReg);
break;
}
} else {
Expand All @@ -696,9 +690,7 @@ void ODD::Write(u64 writeAddress, u64 data, u8 byteCount) {
memcpy(&atapiState.atapiRegs.dmaTableOffsetReg, &data, byteCount);
break;
default:
std::cout << "ATAPI: Unknown Control Register Block register being "
"written, command"
<< "code = 0x" << atapiControlReg << std::endl;
LOG_ERROR(ODD, "Unknown Control Register Block register being written, command code = 0x{}", atapiControlReg);
break;
}
}
Expand Down
1 change: 0 additions & 1 deletion Xenon/Core/RootBus/HostBridge/PCIBridge/ODD/ODD.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#pragma once

#include <Windows.h>
#include <iostream>
#include <vector>

#include "Core/RAM/RAM.h"
Expand Down
26 changes: 11 additions & 15 deletions Xenon/Core/RootBus/HostBridge/PCIBridge/SFCX/SFCX.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2025 Xenon Emulator Project

#include <fstream>
#include <iostream>
#include "Base/Logging/Log.h"

#include "SFCX.h"

Expand All @@ -13,7 +12,7 @@ SFCX::SFCX(const std::string nandLoadPath, PCIBridge *parentPCIBridge) {
pciConfigSpace.configSpaceHeader.reg0.vendorID = 0x1414;
pciConfigSpace.configSpaceHeader.reg0.deviceID = 0x580B;

std::cout << "Xenon Secure Flash Controller for Xbox" << std::endl;
LOG_INFO(SFCX, "Xenon Secure Flash Controller for Xbox.");

// Set the registers as a dump from my Corona 16MB. These were dumped at POR
// via Xell before SFCX Init. These are also readable via JRunner and
Expand All @@ -35,20 +34,18 @@ SFCX::SFCX(const std::string nandLoadPath, PCIBridge *parentPCIBridge) {
sfcxState.commandReg = NO_CMD;

// Load the NAND dump.
std::cout << "SFCX: Loading NAND from path: " << nandLoadPath << std::endl;
LOG_INFO(SFCX, "Loading NAND from path: {}", nandLoadPath);

fopen_s(&nandFile, nandLoadPath.c_str(), "rb");

if (!nandFile) {
std::cout << "SFCX: Fatal error, check your nand dump path." << std::endl;
LOG_CRITICAL(SFCX, "Fatal error, check your nand dump path.");
system("PAUSE");
}

// Check file magic.
if (!checkMagic()) {
std::cout << "SFCX: Fatal error, loaded faile magic does'nt correspond to "
"Xbox 360 NAND."
<< std::endl;
LOG_CRITICAL(SFCX, "Fatal error, loaded faile magic does'nt correspond to Xbox 360 NAND.");
system("PAUSE");
}

Expand Down Expand Up @@ -166,7 +163,7 @@ void SFCX::Read(u64 readAddress, u64 *data, u8 byteCount) {
*data = sfcxState.mmcIDReg;
break;
default:
std::cout << "SFCX: Read from unknown register 0x" << reg << std::endl;
LOG_ERROR(SFCX, "Read from unknown register 0x{}", reg);
break;
}
}
Expand Down Expand Up @@ -212,7 +209,7 @@ void SFCX::Write(u64 writeAddress, u64 data, u8 byteCount) {
sfcxState.mmcIDReg = (u32)data;
break;
default:
std::cout << "SFCX: Write to unknown register 0x" << reg << std::endl;
LOG_ERROR(SFCX, "Write from unknown register 0x{}", reg);
break;
}
}
Expand Down Expand Up @@ -272,8 +269,7 @@ void SFCX::sfcxMainLoop() {
// case UNLOCK_CMD_1:
// break;
default:
std::cout << "SFCX: Unrecognized command was issued. 0x"
<< sfcxState.commandReg << std::endl;
LOG_ERROR(SFCX, "Unrecognized command was issued. 0x{}", sfcxState.commandReg);
break;
}

Expand All @@ -298,15 +294,15 @@ bool SFCX::checkMagic() {
// Older Devkit Nand's magic is 0x0F3F.

if (magic[0] == (char)0xff && magic[1] == (char)0x4f) {
std::cout << "SFCX: Retail NAND Magic found." << std::endl;
LOG_INFO(SFCX, "Retail NAND Magic found.");
return true;
}
if (magic[0] == (char)0x0f && magic[1] == (char)0x4f) {
std::cout << "SFCX: Devkit NAND Magic found." << std::endl;
LOG_INFO(SFCX, "Devkit NAND Magic found.");
return true;
}
if (magic[0] == (char)0x0f && magic[1] == (char)0x3f) {
std::cout << "SFCX: Old Devkit NAND Magic found." << std::endl;
LOG_INFO(SFCX, "Old Devkit NAND Magic found.");
return true;
}
return false;
Expand Down
1 change: 0 additions & 1 deletion Xenon/Core/RootBus/HostBridge/PCIBridge/SFCX/SFCX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#pragma once

#include <iostream>
#include <thread>

#include "Core/RootBus/HostBridge/PCIBridge/PCIBridge.h"
Expand Down
10 changes: 4 additions & 6 deletions Xenon/Core/XCPU/IIC/IIC.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2025 Xenon Emulator Project

#include <iostream>
#include <thread>

#include "Base/Logging/Log.h"

#include "IIC.h"

Xe::XCPU::IIC::XenonIIC::XenonIIC() {
Expand Down Expand Up @@ -64,9 +65,7 @@ void Xe::XCPU::IIC::XenonIIC::writeInterrupt(u64 intAddress, u64 intData) {
static_cast<u32>(_byteswap_uint64(intData));
break;
default:
std::cout
<< "Xenon IIC: Unknown CPU Interrupt Ctrl Blck Reg being written: "
<< ppeIntCtrlBlckReg << std::endl;
LOG_ERROR(Xenon_PostBus, "IIC: Unknown CPU Interrupt Ctrl Blck Reg being written: {}", ppeIntCtrlBlckReg);
break;
}
}
Expand Down Expand Up @@ -98,8 +97,7 @@ void Xe::XCPU::IIC::XenonIIC::readInterrupt(u64 intAddress, u64 *intData) {
*intData = _byteswap_uint64(PRIO_NONE);
break;
default:
std::cout << "XenonIIC: Unknown interupt being read 0x" << ppeIntCtrlBlckReg
<< std::endl;
LOG_ERROR(Xenon_PostBus, "IIC: Unknown interupt being read 0x{}", ppeIntCtrlBlckReg);
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions Xenon/Core/XCPU/Interpreter/Interpreter_Helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2025 Xenon Emulator Project

#include "Base/Logging/Log.h"

#include "PPCInterpreter.h"

void PPCInterpreter::ppcUpdateCR(PPU_STATE *hCore, s8 crNum, u32 crValue) {
Expand Down Expand Up @@ -102,10 +104,8 @@ void PPCInterpreter::ppcDebugLoadImageSymbols(PPU_STATE *hCore,
Kdinfo.CheckSum = MMURead32(hCore, moduleInfoAddress + 8);
Kdinfo.SizeOfImage = MMURead32(hCore, moduleInfoAddress + 12);

std::cout << "XCPU[" << hCore->ppuName
<< "]: *** DebugLoadImageSymbols ***\n\t > Loaded: " << moduleName
<< " at address 0x" << Kdinfo.BaseOfDll << " - 0x"
<< Kdinfo.BaseOfDll + Kdinfo.SizeOfImage << std::endl;
LOG_INFO(Xenon_PostBus, "XCPU[{}]: *** DebugLoadImageSymbols ***", hCore->ppuName);
LOG_INFO(Xenon_PostBus, "Loaded: {} at address 0x{} - 0x{}", moduleName, Kdinfo.BaseOfDll, (Kdinfo.BaseOfDll + Kdinfo.SizeOfImage));
}

void PPCInterpreter::ppcDebugUnloadImageSymbols(PPU_STATE *hCore,
Expand Down
Loading

0 comments on commit 121257f

Please sign in to comment.