Skip to content

Commit

Permalink
Adding nopad option to ps1-packer.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasnoble committed Nov 14, 2023
1 parent a64ba39 commit 0e6f33d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/supportpsx/binffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct BinaryLoaderInfo {
struct PS1PackerOptions {
uint32_t tload;
bool shell;
bool nopad;
bool booty;
bool raw;
bool rom;
Expand Down Expand Up @@ -99,6 +100,7 @@ PCSX.Binary.pack = function(src, dest, addr, pc, gp, sp, options)
opts.tload = options.tload and options.tload or 0
opts.booty = options.booty and true or false
opts.shell = options.shell and true or false
opts.nopad = options.nopad and true or false
opts.raw = options.raw and true or false
opts.rom = options.rom and true or false
opts.cpe = options.cpe and true or false
Expand Down
3 changes: 2 additions & 1 deletion src/supportpsx/ps1-packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ void PCSX::PS1Packer::pack(IO<File> src, IO<File> dest, uint32_t addr, uint32_t
pushBytes(dataOut, jr(Reg::T0));
pushBytes(dataOut, addiu(Reg::RA, Reg::T8, 0));
}
while (!options.cpe && !options.booty && !options.rom && !options.raw && ((dataOut.size() & 0x7ff) != 0)) {
while (!options.cpe && !options.booty && !options.rom && !options.raw && !options.nopad &&
((dataOut.size() & 0x7ff) != 0)) {

Check warning on line 175 in src/supportpsx/ps1-packer.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

PCSX::PS1Packer::pack increases in cyclomatic complexity from 35 to 36, 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.

Check warning on line 175 in src/supportpsx/ps1-packer.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Conditional

PCSX::PS1Packer::pack increases from 1 complex conditionals with 4 branches to 1 complex conditionals with 5 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.

Check warning on line 175 in src/supportpsx/ps1-packer.cc

View check run for this annotation

Codecov / codecov/patch

src/supportpsx/ps1-packer.cc#L174-L175

Added lines #L174 - L175 were not covered by tests
dataOut.push_back(0);
}

Expand Down
1 change: 1 addition & 0 deletions src/supportpsx/ps1-packer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace PS1Packer {
struct Options {
uint32_t tload = 0;
bool shell = false;
bool nopad = false;
bool booty = false;
bool raw = false;
bool rom = false;
Expand Down
3 changes: 3 additions & 0 deletions tools/ps1-packer/ps1-packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ps1-packer by Nicolas "Pixel" Noble
const bool booty = args.get<bool>("booty").value_or(false);
const bool rom = args.get<bool>("rom").value_or(false);
const bool cpe = args.get<bool>("cpe").value_or(false);
const bool nopad = args.get<bool>("nopad").value_or(false);
unsigned outputTypeCount = (raw ? 1 : 0) + (booty ? 1 : 0) + (rom ? 1 : 0) + (cpe ? 1 : 0);
if (asksForHelp || !oneInput || !hasOutput || (outputTypeCount > 1)) {
fmt::print(R"(
Expand All @@ -53,6 +54,7 @@ Usage: {} input.ps-exe [-h] [-tload addr] [-shell] [-raw | -booty | -rom | -cpe]
-h displays this help information and exit.
-tload force loading at this address instead of doing in-place.
-shell adds a kernel reset stub.
-nopad disables padding of the output file to 2048 bytes. Only for PS-EXE output.
These options control the output format, and are mutually exclusive:
-raw outputs a raw file.
Expand Down Expand Up @@ -99,6 +101,7 @@ Valid input binary files can be in the following formats:
options.cpe = cpe;
options.shell = shell;
options.tload = tload;
options.nopad = nopad;

Check warning on line 104 in tools/ps1-packer/ps1-packer.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

main already has high cyclomatic complexity, and now it increases in Lines of Code from 81 to 84. 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.
PCSX::IO<PCSX::File> out(new PCSX::PosixFile(output.value().c_str(), PCSX::FileOps::TRUNCATE));
PCSX::PS1Packer::pack(new PCSX::SubFile(memory, memory->lowestAddress(), memory->actualSize()), out,
memory->lowestAddress(), info.pc.value_or(0), info.gp.value_or(0), info.sp.value_or(0),
Expand Down

0 comments on commit 0e6f33d

Please sign in to comment.