Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fuckit
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/gui/gui.cc
#	src/main/main.cc
  • Loading branch information
nicolasnoble committed Jul 26, 2023
2 parents 5a4c1e3 + e3dd299 commit 2d3b863
Show file tree
Hide file tree
Showing 46 changed files with 870 additions and 273 deletions.
1 change: 1 addition & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: nicolasnoble
23 changes: 23 additions & 0 deletions .github/workflows/codesee-arch-diagram.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow was added by CodeSee. Learn more at https://codesee.io/
# This is v2.0 of this workflow file
on:
push:
branches:
- main
pull_request_target:
types: [opened, synchronize, reopened]

name: CodeSee

permissions: read-all

jobs:
codesee:
runs-on: ubuntu-latest
continue-on-error: true
name: Analyze the repo with CodeSee
steps:
- uses: Codesee-io/codesee-action@v2
with:
codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
codesee-url: https://app.codesee.io
2 changes: 1 addition & 1 deletion .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
path: '**/*.ps-exe'

macos-build-and-test:
runs-on: macOS-latest
runs-on: macos-11
needs: build-openbios
steps:
- uses: actions/checkout@v1
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
![Debugger screenshot](https://pcsx-redux.consoledev.net/images/debugger1.png)

<a href='https://ko-fi.com/nicolasnoble' target='_blank'><img height='35' style='border:0px;height:46px;' src='https://az743702.vo.msecnd.net/cdn/kofi3.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' />

|Platform|Build status|Download|
|--------|------------|--------|
Expand Down Expand Up @@ -137,7 +138,7 @@ Since the inception of this codebase, several people have contributed to it. Ple
When Sony released the Playstation Classic recently, I came to realize two things: first, the state of the Playstation emulation isn't that great, and second, the only half-decent debugging tool still available for this console is that old telnet debugger I wrote eons ago, while other emulators out there for other consoles gained a lot of debugging superpowers. I think it was time for the Playstation emulation to get to better standards with regards to debuggability. I also felt I had a responsability to cleaning up some of the horrors I've introduced myself in the codebase long ago, and that made me cry a little looking at them. Hopefully, I got better at programming. Hopefully.

## Status?
The codebase still requires a lot of cleanup, and the current product isn't properly usable yet. Despite that, a lot can already be achieved using the product in its current state. If you want to help with localization, you can find the translation project [on transifex](https://www.transifex.com/grumpycoders/pcsx-redux/languages/).
The codebase still requires a lot of cleanup, and while the product is usable in its current state and lots can be achieved with it, there is still ways to go for reaching the first stable release. If you want to help with localization, you can find the translation project [on transifex](https://www.transifex.com/grumpycoders/pcsx-redux/languages/).

### What works?
- Dynamic Recompiler (x86-64, experimental arm64 support)
Expand Down
42 changes: 42 additions & 0 deletions src/core/arguments.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/***************************************************************************
* Copyright (C) 2023 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/

#include "core/arguments.h"

#include <filesystem>

PCSX::Arguments::Arguments(const CommandLine::args& args) {
if (args.get<bool>("lua_stdout") || args.get<bool>("no-ui") || args.get<bool>("cli")) {
m_luaStdoutEnabled = true;
}
if (args.get<bool>("stdout") && !args.get<bool>("tui")) m_stdoutEnabled = true;
if (args.get<bool>("no-ui") || args.get<bool>("cli")) m_stdoutEnabled = true;
if (args.get<bool>("testmode") || args.get<bool>("no-gui-log")) m_guiLogsEnabled = false;
if (args.get<bool>("testmode")) m_testModeEnabled = true;
if (args.get<bool>("portable")) m_portable = true;
if (std::filesystem::exists("pcsx.json")) m_portable = true;
if (std::filesystem::exists("Makefile")) m_portable = true;
if (std::filesystem::exists(std::filesystem::path("..") / "pcsx-redux.sln")) m_portable = true;
if (args.get<bool>("safe") || args.get<bool>("testmode") || args.get<bool>("cli")) m_safeModeEnabled = true;
if (args.get<bool>("resetui")) m_uiResetRequested = true;
if (args.get<bool>("noshaders")) m_shadersDisabled = true;
if (args.get<bool>("noupdate")) m_updateDisabled = true;
if (args.get<bool>("viewports")) m_viewportsEnabled = true;
if (args.get<bool>("no-viewports")) m_viewportsEnabled = false;
}
94 changes: 94 additions & 0 deletions src/core/arguments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/***************************************************************************
* Copyright (C) 2023 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/

#pragma once

#include <stdint.h>

#include "flags.h"

namespace PCSX {

class Arguments {
public:
Arguments(const CommandLine::args& args);
Arguments(const Arguments&) = delete;
Arguments(Arguments&&) = delete;
Arguments& operator=(const Arguments&) = delete;
Arguments& operator=(Arguments&&) = delete;

// Returns true if stdout should be enabled.
// Enabled with the flags -stdout (but not when -tui is used), -no-ui, or -cli.
bool isStdoutEnabled() const { return m_stdoutEnabled; }

// Returns true if Lua should be displaying its console output to stdout.
// Enabled with the flags -lua_stdout, -no-ui, or -cli.
bool isLuaStdoutEnabled() const { return m_luaStdoutEnabled; }

// Returns true if the GUI logs window should be enabled.
// Disabled with -testmode or -no-gui-log.
bool isGUILogsEnabled() const { return m_guiLogsEnabled; }

// Returns true if the the flag -testmode was used.
bool isTestModeEnabled() const { return m_testModeEnabled; }

// Returns true if the the flag -portable was used, if the executable is
// located in the same directory as the pcsx.json file, or if the
// executable is being run from its source tree.
bool isPortable() const { return m_portable; }

// Returns true if the safe mode was enabled. This implies
// that the pcsx.json file won't be loaded.
// Enabled with the flags -safe, -testmode, or -cli.
bool isSafeModeEnabled() const { return m_safeModeEnabled; }

// Returns true if the user requested to reset the UI.
// Enabled with the flag -resetui.
bool isUIResetRequested() const { return m_uiResetRequested; }

// Returns true if the user requested that no shaders be used.
// Enabled with the flag -noshaders.
bool isShadersDisabled() const { return m_shadersDisabled; }

// Returns true if the user requested that no update be performed.
// Enabled with the flag -noupdate.
bool isUpdateDisabled() const { return m_updateDisabled; }

// Returns true if the user requested that viewports be enabled.
// Toggled with the flags -viewports / -no-viewports.
bool isViewportsEnabled() const { return m_viewportsEnabled; }

private:
bool m_luaStdoutEnabled = false;
bool m_stdoutEnabled = false;
bool m_guiLogsEnabled = true;
bool m_testModeEnabled = false;
bool m_portable = false;
bool m_safeModeEnabled = false;
bool m_uiResetRequested = false;
bool m_shadersDisabled = false;
bool m_updateDisabled = false;
#ifdef __linux__
bool m_viewportsEnabled = false;
#else
bool m_viewportsEnabled = true;
#endif
};

} // namespace PCSX
5 changes: 4 additions & 1 deletion src/core/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ void PCSX::Debug::process(uint32_t oldPC, uint32_t newPC, uint32_t oldCode, uint
}

if (m_step == STEP_NONE) return;
if (!m_wasInISR && g_emulator->m_cpu->m_inISR) return;
if (!m_wasInISR && g_emulator->m_cpu->m_inISR) {
uint32_t cause = (regs.CP0.n.Cause >> 2) & 0x1f;
if (cause == 0) return;
}

switch (m_step) {
case STEP_IN: {
Expand Down
9 changes: 0 additions & 9 deletions src/core/gdb-server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ PCSX::GdbServer::GdbServer() : m_listener(g_system->m_eventBus) {
m_listener.listen<Events::SettingsLoaded>([this](const auto& event) {
auto& args = g_system->getArgs();
auto& settings = g_emulator->settings.get<Emulator::SettingDebugSettings>();
if (args.get<bool>("gdb", false)) {
settings.get<Emulator::DebugSettings::GdbServer>() = true;
}
if (args.get<bool>("no-gdb", false)) {
settings.get<Emulator::DebugSettings::GdbServer>() = false;
}
if (args.get<int>("gdb-port").has_value()) {
settings.get<Emulator::DebugSettings::GdbServerPort>() = args.get<int>("gdb-port").value();
}
if (settings.get<Emulator::DebugSettings::GdbServer>() && (m_serverStatus != SERVER_STARTED)) {
startServer(g_system->getLoop(), settings.get<Emulator::DebugSettings::GdbServerPort>());
}
Expand Down
19 changes: 14 additions & 5 deletions src/core/memorycard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,20 @@ uint8_t PCSX::MemoryCard::tickPS_GetVersion(uint8_t value) {
}

// To-do: "All the code starting here is terrible and needs to be rewritten"
void PCSX::MemoryCard::loadMcd(const PCSX::u8string str) {
void PCSX::MemoryCard::loadMcd(PCSX::u8string mcd) {
char *data = m_mcdData;
const char *fname = reinterpret_cast<const char *>(str.c_str());
if (std::filesystem::path(mcd).is_relative()) {
mcd = (g_system->getPersistentDir() / mcd).u8string();
}
const char *fname = reinterpret_cast<const char *>(mcd.c_str());
size_t bytesRead;

m_directoryFlag = Flags::DirectoryUnread;

FILE *f = fopen(fname, "rb");
if (f == nullptr) {
PCSX::g_system->printf(_("The memory card %s doesn't exist - creating it\n"), fname);
createMcd(str);
createMcd(mcd);
f = fopen(fname, "rb");
if (f != nullptr) {
struct stat buf;
Expand Down Expand Up @@ -386,7 +389,10 @@ void PCSX::MemoryCard::loadMcd(const PCSX::u8string str) {
}
}

void PCSX::MemoryCard::saveMcd(const PCSX::u8string mcd, const char *data, uint32_t adr, size_t size) {
void PCSX::MemoryCard::saveMcd(PCSX::u8string mcd, const char *data, uint32_t adr, size_t size) {
if (std::filesystem::path(mcd).is_relative()) {
mcd = (g_system->getPersistentDir() / mcd).u8string();
}
const char *fname = reinterpret_cast<const char *>(mcd.c_str());
FILE *f = fopen(fname, "r+b");

Expand Down Expand Up @@ -419,7 +425,10 @@ void PCSX::MemoryCard::saveMcd(const PCSX::u8string mcd, const char *data, uint3
}
}

void PCSX::MemoryCard::createMcd(const PCSX::u8string mcd) {
void PCSX::MemoryCard::createMcd(PCSX::u8string mcd) {
if (std::filesystem::path(mcd).is_relative()) {
mcd = (g_system->getPersistentDir() / mcd).u8string();
}
const char *fname = reinterpret_cast<const char *>(mcd.c_str());
int s = c_cardSize;

Expand Down
8 changes: 4 additions & 4 deletions src/core/memorycard.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class MemoryCard {
saveMcd(path);
}
}
void createMcd(const PCSX::u8string mcd);
void createMcd(PCSX::u8string mcd);
bool dataChanged() { return !m_savedToDisk; }
void disablePocketstation() { m_pocketstationEnabled = false; };
void enablePocketstation() { m_pocketstationEnabled = true; };
char *getMcdData() { return m_mcdData; }
void loadMcd(const PCSX::u8string str);
void saveMcd(const PCSX::u8string mcd, const char *data, uint32_t adr, size_t size);
void saveMcd(const PCSX::u8string path) { saveMcd(path, m_mcdData, 0, c_cardSize); }
void loadMcd(PCSX::u8string mcd);
void saveMcd(PCSX::u8string mcd, const char *data, uint32_t adr, size_t size);
void saveMcd(PCSX::u8string mcd) { saveMcd(mcd, m_mcdData, 0, c_cardSize); }

private:
enum Commands : uint8_t {
Expand Down
15 changes: 0 additions & 15 deletions src/core/psxemulator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,8 @@ int PCSX::Emulator::init() {

const auto& args = g_system->getArgs();

if (args.get<bool>("openglgpu")) {
settings.get<SettingHardwareRenderer>() = true;
}
if (args.get<bool>("softgpu")) {
settings.get<SettingHardwareRenderer>() = false;
}

m_gpu = settings.get<SettingHardwareRenderer>() ? GPU::getOpenGL() : GPU::getSoft();

// Enable or disable Kiosk Mode if command line flags are set
if (args.get<bool>("kiosk")) {
settings.get<SettingKioskMode>() = true;
}
if (args.get<bool>("no-kiosk")) {
settings.get<SettingKioskMode>() = false;
}

setPGXPMode(m_config.PGXP_Mode);
m_sio->init();
return ret;
Expand Down
11 changes: 5 additions & 6 deletions src/core/r3000a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ int PCSX::R3000Acpu::psxInit() {
g_system->printf(_("Copyright (C) 2019-2023 PCSX-Redux authors\n"));
const auto& args = g_system->getArgs();

if (args.get<bool>("interpreter"))
g_emulator->m_cpu = Cpus::Interpreted();
else if (args.get<bool>("dynarec"))
g_emulator->m_cpu = Cpus::DynaRec();
else if (g_emulator->settings.get<Emulator::SettingDynarec>())
if (g_emulator->settings.get<Emulator::SettingDynarec>()) {
g_emulator->m_cpu = Cpus::DynaRec();
}

if (!g_emulator->m_cpu) g_emulator->m_cpu = Cpus::Interpreted();

PGXP_Init();
g_system->printf(_("CPU type: %s\n"), g_emulator->m_cpu->getName().c_str());

return g_emulator->m_cpu->Init();
}
Expand Down Expand Up @@ -244,7 +242,8 @@ void PCSX::R3000Acpu::exception(uint32_t code, bool bd, bool cop0) {
}
}
ec = 1 << ec;
if (!g_system->testmode() && ((debugSettings.get<Emulator::DebugSettings::FirstChanceException>() & ec) != 0)) {
if (!g_system->getArgs().isTestModeEnabled() &&
((debugSettings.get<Emulator::DebugSettings::FirstChanceException>() & ec) != 0)) {
auto name = magic_enum::enum_name(e.value());
g_system->printf(fmt::format("First chance exception: {} from 0x{:08x}\n", name, m_regs.pc).c_str());
g_system->pause(true);
Expand Down
5 changes: 0 additions & 5 deletions src/core/sio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,6 @@ void PCSX::SIO::scheduledCallback() {
#endif
}

void PCSX::SIO::loadMcds(const PCSX::u8string mcd1, const PCSX::u8string mcd2) {
m_memoryCard[0].loadMcd(mcd1);
m_memoryCard[1].loadMcd(mcd2);
}

void PCSX::SIO::getMcdBlockInfo(int mcd, int block, McdBlock &info) {
if (block < 1 || block > 15) {
throw std::runtime_error(_("Wrong block number"));
Expand Down
8 changes: 7 additions & 1 deletion src/core/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ class SIO {
void getMcdBlockInfo(int mcd, int block, McdBlock &info);
char *getMcdData(int mcd);
char *getMcdData(const McdBlock &block) { return getMcdData(block.mcd); }
void loadMcds(const PCSX::u8string mcd1, const PCSX::u8string mcd2);
void loadMcd(const PCSX::u8string &path, int mcd) {
if (mcd > 0 && mcd <= c_cardCount) m_memoryCard[mcd - 1].loadMcd(path);
}
void loadMcds(const PCSX::u8string &mcd1, const PCSX::u8string &mcd2) {
m_memoryCard[0].loadMcd(mcd1);
m_memoryCard[1].loadMcd(mcd2);
}
void saveMcd(int mcd);
static constexpr int otherMcd(int mcd) {
if ((mcd != 1) && (mcd != 2)) throw std::runtime_error("Bad memory card number");
Expand Down
25 changes: 25 additions & 0 deletions src/core/system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,28 @@ bool PCSX::System::findResource(std::function<bool(const std::filesystem::path&
// No luck here...
return false;
}

std::filesystem::path PCSX::System::getPersistentDir() const {
if (getArgs().isPortable()) return "";
#ifdef _WIN32
char* homeDir;
auto ret = _dupenv_s(&homeDir, nullptr, "APPDATA");
if ((ret != 0) || (!homeDir)) {
return "";
}
std::filesystem::path persistentDir = std::filesystem::path(homeDir) / "pcsx-redux";
free(homeDir);
#else
char* homeDir = getenv("HOME");
if (!homeDir) {
return "";
}
std::filesystem::path persistentDir = std::filesystem::path(homeDir) / ".config" / "pcsx-redux";
#endif
if (!std::filesystem::exists(persistentDir)) {
if (!std::filesystem::create_directories(persistentDir)) {
return "";
}
}
return persistentDir;
}
Loading

0 comments on commit 2d3b863

Please sign in to comment.