Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/eventslua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@
createListener<Events::Keyboard>(L);
} else if (name == "Memory::SetLuts") {
createListener<Events::Memory::SetLuts>(L);
} else {
} else if (name == "CPU::Interrupt") {
createListener<Events::CPU::Interrupt>(L);
}
else {

Check warning on line 211 in src/core/eventslua.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Complex Method

PCSX::LuaBindings::open_events increases in cyclomatic complexity from 15 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
return L.error("createListener: unknown event name");
}
return 1;
Expand Down
8 changes: 8 additions & 0 deletions src/core/pcsxffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void luaLog(const char* msg);
void jumpToPC(uint32_t address);
void jumpToMemory(uint32_t address, unsigned width);
void invalidateCache();
void scheduleInterrupt(uint32_t eCycle);

typedef enum { BPP_16, BPP_24 } ScreenShotBPP;

Expand Down Expand Up @@ -172,6 +173,12 @@ local function jumpToMemory(address, width)
C.jumpToMemory(address, width)
end

local function scheduleInterrupt(eCycle)
if type(eCycle) ~= 'number' then error 'PCSX.scheduleInterrupt requires a numeric cycle count' end
if (eCycle < 0) or (eCycle > 0xffffffff) or (eCycle % 1 ~= 0) then error 'PCSX.scheduleInterrupt cycle count parameter should be an unsigned 32-bit integer' end
C.scheduleInterrupt(eCycle)
end
Comment on lines +176 to +180
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the exact changed block and confirm missing `end` on the second if.
sed -n '176,181p' src/core/pcsxffi.lua
python - <<'PY'
from pathlib import Path
line178 = Path("src/core/pcsxffi.lua").read_text().splitlines()[177]  # 1-based line 178
print("Line 178:", line178)
print("Ends with 'end':", line178.rstrip().endswith("end"))
PY

Repository: grumpycoders/pcsx-redux

Length of output: 560


Add missing end to close the if block on line 178.

Line 178 opens an if statement but does not close it, creating a syntax error that prevents the Lua chunk from loading.

🔧 Proposed fix
 local function scheduleInterrupt(eCycle)
     if type(eCycle) ~= 'number' then error 'PCSX.scheduleInterrupt requires a numeric cycle count' end
-    if (eCycle < 0) or (eCycle > 0xffffffff) then error 'PCSX.scheduleInterrupt cycle count parameter should be an unsigned 32-bit integer'
+    if (eCycle < 0) or (eCycle > 0xffffffff) then
+        error 'PCSX.scheduleInterrupt cycle count parameter should be an unsigned 32-bit integer'
+    end
     C.scheduleInterrupt(eCycle)
 end
🧰 Tools
🪛 Luacheck (1.2.0)

[error] 179-179: expected 'end' (to close 'if' on line 178) near 'C' (indentation-based guess)

(E011)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/pcsxffi.lua` around lines 176 - 180, The function scheduleInterrupt
contains an unclosed if: after checking (eCycle < 0) or (eCycle > 0xffffffff)
you must add a closing end before calling C.scheduleInterrupt; update the
scheduleInterrupt function so the numeric-range if block is properly terminated
(i.e., insert the missing end to close the if that validates eCycle) so the
function reads: validate type, validate range (with its own end), then call
C.scheduleInterrupt(eCycle).


PCSX = {
getCPUCycles = function() return C.getCPUCycles() end,
getMemPtr = function() return C.getMemPtr() end,
Expand All @@ -187,6 +194,7 @@ PCSX = {
softResetEmulator = function() C.softResetEmulator() end,
hardResetEmulator = function() C.hardResetEmulator() end,
invalidateCache = function() C.invalidateCache() end,
scheduleInterrupt = scheduleInterrupt,
log = function(...) printLike(function(msg) C.luaLog(msg .. '\n') end, ...) end,
GUI = { jumpToPC = jumpToPC, jumpToMemory = jumpToMemory },
nextTick = function(f)
Expand Down
2 changes: 2 additions & 0 deletions src/core/pcsxlua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void jumpToMemory(uint32_t address, unsigned width) {
PCSX::g_system->m_eventBus->signal(PCSX::Events::GUI::JumpToMemory{address, width});
}
void invalidateCache() { PCSX::g_emulator->m_cpu->invalidateCache(); }
void scheduleInterrupt(uint32_t eCycle) { PCSX::g_emulator->m_cpu->scheduleInterrupt(PCSX::PSXINT_LUA, eCycle); }

struct LuaScreenShot {
PCSX::Slice* data;
Expand Down Expand Up @@ -159,6 +160,7 @@ static void registerAllSymbols(PCSX::Lua L) {
REGISTER(L, luaLog);
REGISTER(L, jumpToPC);
REGISTER(L, jumpToMemory);
REGISTER(L, scheduleInterrupt);
REGISTER(L, invalidateCache);
REGISTER(L, takeScreenShot);
REGISTER(L, createSaveState);
Expand Down
1 change: 1 addition & 0 deletions src/core/r3000a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
checkAndUpdate(PSXINT_CDRPLAY, g_emulator->m_cdrom->playInterrupt);
checkAndUpdate(PSXINT_CDRDBUF, g_emulator->m_cdrom->decodedBufferInterrupt);
checkAndUpdate(PSXINT_CDRLID, g_emulator->m_cdrom->lidSeekInterrupt);
checkAndUpdate(PSXINT_LUA, g_emulator->m_lua->interrupt);

Check warning on line 399 in src/core/r3000a.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Complex Method

PCSX::R3000Acpu::branchTest already has high cyclomatic complexity, and now it increases in Lines of Code from 70 to 71. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
m_regs.lowestTarget = lowestTarget;
}
auto& mem = g_emulator->m_mem;
Expand Down
7 changes: 4 additions & 3 deletions src/core/r3000a.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ enum {
PSXINT_SPUASYNC,
PSXINT_CDRDBUF,
PSXINT_CDRLID,
PSXINT_CDRPLAY
PSXINT_CDRPLAY,
PSXINT_LUA,
};

struct psxRegisters {
Expand Down Expand Up @@ -316,8 +317,8 @@ class R3000Acpu {
}

psxRegisters m_regs;
float m_interruptScales[15] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
float m_interruptScales[16] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
bool m_shellStarted = false;

virtual void Reset() {
Expand Down
3 changes: 3 additions & 0 deletions src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ struct Keyboard {
namespace Memory {
struct SetLuts {};
} // namespace Memory
namespace CPU {
struct Interrupt {};
} // namespace CPU
} // namespace Events

class System {
Expand Down
4 changes: 4 additions & 0 deletions src/lua/luawrapper.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***************************************************************************

Check notice on line 1 in src/lua/luawrapper.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 4.75 to 4.65, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
* Copyright (C) 2019 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand All @@ -19,6 +19,8 @@

#include "lua/luawrapper.h"

#include "core/system.h"

#include <assert.h>

static int callwrap(lua_State* raw, lua_CFunction func) {
Expand Down Expand Up @@ -673,3 +675,5 @@
}
}
}

void PCSX::Lua::interrupt() { PCSX::g_system->m_eventBus->signal<PCSX::Events::CPU::Interrupt>({}); }
2 changes: 2 additions & 0 deletions src/lua/luawrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ class Lua {
return ar;
}

void interrupt();

private:
lua_State* L;
};
Expand Down
Loading