Skip to content

Commit

Permalink
Merge pull request #28 from Vali0004/main
Browse files Browse the repository at this point in the history
Update some ODD segments, and add some new features.
  • Loading branch information
bitsh1ft3r authored Jan 31, 2025
2 parents ea422c5 + d6fd796 commit 207de8f
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 175 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mono_crash.*
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Rr]el[Ww]ith[Dd]eb[Ii]nfo/
x64/
x86/
[Ww][Ii][Nn]32/
Expand Down Expand Up @@ -396,6 +397,7 @@ FodyWeavers.xsd
*.msix
*.msm
*.msp
*.exe

# JetBrains Rider
*.sln.iml
Expand All @@ -408,7 +410,22 @@ FodyWeavers.xsd
.idea
cmake-build-*

# Visual Studio proj files
*.vcxproj
*.vcxproj.*
*.sln

# CMake Files
third_party/CMakeFiles
third_party/cmake_install.cmake
CMakeFiles
CMakeCache.txt
cmake_install.cmake
CMakeSettings.json

# Specific to Xenon
Xenon.dir/
Xenon.dir/*
/Xenon/x64/*
/Xenon/Debug/*
/enc_temp_folder/619a1d34cec9f4ba9f9d74313f867f/PPC_MMU.cpp
Expand Down
88 changes: 0 additions & 88 deletions CMakeSettings.json

This file was deleted.

24 changes: 23 additions & 1 deletion Xenon/Base/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ static s32 screenHeight = 720;
// static s32 gpuId = -1; // Vulkan physical device index. Set to negative for
// auto select

// Filepaths
// Filepaths.
static std::string fusesTxtPath = "C:/Xbox/fuses.txt";
static std::string oneBlBinPath = "C:/Xbox/1bl.bin";
static std::string nandBinPath = "C:/Xbox/nand.bin";
static std::string oddDiscImagePath = "C:/Xbox/xenon.iso";

// Highly experimental.
static int ticksPerInstruction = 0;

std::string* COMPort() {
com = "\\\\.\\COM" + std::to_string(comPort);
Expand Down Expand Up @@ -81,10 +85,14 @@ std::string oneBlPath() { return oneBlBinPath; }

std::string nandPath() { return nandBinPath; }

std::string oddImagePath() { return oddDiscImagePath; }

// s32 getGpuId() {
// return gpuId;
// }

int tpi() { return ticksPerInstruction; }

void loadConfig(const std::filesystem::path &path) {
// If the configuration file does not exist, create it and return.
LOG_INFO(Config, "Loading configuration from: {}", path.string());
Expand Down Expand Up @@ -141,6 +149,15 @@ void loadConfig(const std::filesystem::path &path) {
toml::find_or<std::string>(paths, "OneBL", oneBlBinPath);
nandBinPath =
toml::find_or<std::string>(paths, "Nand", nandBinPath);
oddDiscImagePath =
toml::find_or<std::string>(paths, "ODDImage", oddDiscImagePath);
}

if (data.contains("HighlyExperimental")) {
const toml::value &highlyExperimental = data.at("HighlyExperimental");
toml::find_or<int>(highlyExperimental, "DoNotTouchTheseUnlessYouKnowWhatYouAreDoing", 0);
ticksPerInstruction =
toml::find_or<int>(highlyExperimental, "TPI", ticksPerInstruction);
}
}

Expand Down Expand Up @@ -186,6 +203,11 @@ void saveConfig(const std::filesystem::path &path) {
data["Paths"]["Fuses"] = fusesTxtPath;
data["Paths"]["OneBL"] = oneBlBinPath;
data["Paths"]["Nand"] = nandBinPath;
data["Paths"]["ISO"] = oddDiscImagePath;

// HighlyExperimental.
data["HighlyExperimental"]["DoNotTouchTheseUnlessYouKnowWhatYouAreDoing"] = 0;
data["HighlyExperimental"]["TPI"] = ticksPerInstruction;

std::ofstream file(path, std::ios::binary);
file << data;
Expand Down
9 changes: 8 additions & 1 deletion Xenon/Base/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ s32 windowHeight();
// s32 getGpuId();

//
// Filepaths
// Filepaths.
//

// Fuses path
Expand All @@ -62,5 +62,12 @@ std::string fusesPath();
std::string oneBlPath();
// nand.bin path
std::string nandPath();
// ODD Image path
std::string oddImagePath();

//
// Highly experimental. (things that can either break the emulator or drastically increase performance)
//
int tpi();

} // namespace Config
33 changes: 18 additions & 15 deletions Xenon/Core/RootBus/HostBridge/PCIBridge/ODD/ODD.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2025 Xenon Emulator Project

#include "Base/Config.h"
#include "Base/Logging/Log.h"

#include "ODD.h"
Expand Down Expand Up @@ -75,24 +76,24 @@
*/

/*
Bit 0 (ERR / CHK Error / Check) is defined as ERR for all commands except
Bit 0 (ERR / CHK Error / Check) is defined as ERR for all commands except
for the Packet and Service commands, for which this bit is defined as CHK.
*/
#define ATA_STATUS_ERR_CHK 0x1
/*
Bit 3 (DRQ Data Request) indicates by value 1 that the disk drive is ready
Bit 3 (DRQ Data Request) indicates by value 1 that the disk drive is ready
to transfer data between the host computer and the drive. After the computer
writes a commmand code to the Command register, the drive sets the BSY bit or
the DRQ bit to 1 until command completion.
*/
#define ATA_STATUS_DRQ 0x08
/*
Bit 5 (DF Device Fault) indicates by value 1 that a device fault has been
Bit 5 (DF Device Fault) indicates by value 1 that a device fault has been
detected.
*/
#define ATA_STATUS_DF 0x10
/*
Bit 6 (DRDY Device Ready) is set to 1 to indicate that the disk drive
Bit 6 (DRDY Device Ready) is set to 1 to indicate that the disk drive
accepts commands. If the DRDY bit is 0, the drive will accept and attempt to
execute the Device Reset and Execute Device Diagnostic commands. Other
commands will not be accepted, and the drive will set the ABRT bit in the
Expand All @@ -101,7 +102,7 @@
*/
#define ATA_STATUS_DRDY 0x40
/*
Bit 7 (BSY Busy) is set to 1 whenever the disk drive has control of the
Bit 7 (BSY Busy) is set to 1 whenever the disk drive has control of the
Command Block registers. If the BSY bit is 1, a write to any Command Block
register by the host computer will be ignored by the drive. The BSY bit is
cleared to 0 by the drive at command completion and after setting the DRQ
Expand Down Expand Up @@ -136,7 +137,7 @@
*/

/*
Bit 2 (ABRT Command Aborted) indicates by value 1 that the requested
Bit 2 (ABRT Command Aborted) indicates by value 1 that the requested
command has been aborted because the command code or a command parameter is
invalid, the command is not implemented, or some other error has occurred.
*/
Expand All @@ -158,7 +159,7 @@
*/

/*
Bit 4 (DEV Device Select) selects by value 0 the drive 0, and by value 1
Bit 4 (DEV Device Select) selects by value 0 the drive 0, and by value 1
the drive 1.
*/
#define ATA_DEV_DEV 0x8
Expand Down Expand Up @@ -206,22 +207,22 @@
*/

/*
Bit 1 (nIEN INTRQ Enable) enables by value 0 the assertion of the INTRQ
Bit 1 (nIEN INTRQ Enable) enables by value 0 the assertion of the INTRQ
interrupt request signal by the disk drive.
*/
#define ATA_DEVICE_CONTROL_NIEN 0x02
/*
Bit 2 (SRST Software Reset) is the software reset bit of the disk drives.
Bit 2 (SRST Software Reset) is the software reset bit of the disk drives.
If there are two daisy-chained drives, by setting this bit to 1 both drives
are reset.
*/
#define ATA_DEVICE_CONTROL_SRST 0x04
/*
Bit 7 (HOB High Order Byte) is defined only when the 48-bit LBA addressing
Bit 7 (HOB High Order Byte) is defined only when the 48-bit LBA addressing
is implemented. If this bit is set to 1, reading of the Features register,
the Sector Count register, and the LBA address registers is performed from
the previous content location. If the HOB bit is set to 0, reading is
performed from the most recently written location. Writing to any Command
the previous content location. If the HOB bit is set to 0, reading is
performed from the most recently written location. Writing to any Command
Block register has the effect of resetting the HOB bit to 0.
*/
#define ATA_DEVICE_CONTROL_HOB 0x80
Expand Down Expand Up @@ -401,9 +402,11 @@ void ODD::atapiReset() {
const char vendorIdentification[] = "PLDS 16D2S";
memcpy(&atapiState.atapiInquiryData.vendorIdentification,
vendorIdentification, sizeof(vendorIdentification));

wchar_t *CdImageFilename = (wchar_t *)L"C:/Xbox/xenon.iso";
atapiState.mountedCDImage = new Storage(CdImageFilename);
std::filesystem::path oddImage = Config::oddImagePath();
if (!std::filesystem::file_size(oddImage)) {
LOG_CRITICAL(ODD, "No image found!");
}
atapiState.mountedCDImage = new Storage(oddImage);
}

void ODD::atapiIdentifyCommand() {
Expand Down
52 changes: 23 additions & 29 deletions Xenon/Core/RootBus/HostBridge/PCIBridge/ODD/ODD.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2025 Xenon Emulator Project

#pragma once

#include <Windows.h>

#include <fstream>
#include <filesystem>
#include <vector>

#include "Core/RAM/RAM.h"
Expand Down Expand Up @@ -58,38 +59,31 @@ class DataBuffer {
//
class Storage {
public:
Storage(wchar_t *Filename) {
hFile = CreateFileW(Filename, GENERIC_READ, FILE_SHARE_READ, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
}
Storage(const std::filesystem::path& filepath) : path(filepath) {
file.open(path, std::ios_base::in | std::ifstream::ate | std::ifstream::binary);
}

~Storage(void) {
if (hFile != INVALID_HANDLE_VALUE)
CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
}
~Storage(void) {
if (file.is_open())
file.close();
}

u32 Size(void) {
u32 cb;
cb = GetFileSize(hFile, nullptr);
return (cb == INVALID_FILE_SIZE) ? 0 : cb;
}
u32 Size(void)
{
return std::filesystem::file_size(path);
}

bool Read(u64 Offset, u8 *Destination, u32 cu8s) {
DWORD cbRead;
OVERLAPPED Over;

#define HIDW(qw) ((u32)(((u64)(qw)) >> 32))
#define LODW(qw) ((u32)(qw))
memset(&Over, 0, sizeof Over);
Over.Offset = LODW(Offset);
Over.OffsetHigh = HIDW(Offset);
return (ReadFile(hFile, Destination, cu8s, &cbRead, &Over) &&
(cbRead == cu8s));
}
bool Read(u64 Offset, u8* Destination, u32 cu8s) {
file.seekg(static_cast<std::streamoff>(Offset), std::ios::beg);
if (!file) {
return false;
}
return file.read(reinterpret_cast<char*>(Destination), cu8s) && file.gcount() == static_cast<std::streamsize>(cu8s);
}

private:
HANDLE hFile;
std::filesystem::path path;
std::ifstream file;
};

//
Expand Down
2 changes: 1 addition & 1 deletion Xenon/Core/XCPU/Interpreter/PPCInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void PPCInterpreter::ppcExecuteSingleInstruction(PPU_STATE *hCore) {

// RGH 2 17489 in a JRunner Corona XDKBuild.
if (hCore->ppuThread[hCore->currentThread].CIA == 0x200c7f0) {
// hCore->ppuThread[hCore->currentThread].GPR[0x3] = 0;
hCore->ppuThread[hCore->currentThread].GPR[0x3] = 0;
}

// 3BL Check Bypass Devkit 2.0.1838.1
Expand Down
Loading

0 comments on commit 207de8f

Please sign in to comment.