Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding nopad option to ps1-packer. #1463

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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
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 @@
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,61 +44,64 @@
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"(
Usage: {} input.ps-exe [-h] [-tload addr] [-shell] [-raw | -booty | -rom | -cpe] -o output.ps-exe
input.ps-exe mandatory: specify the input binary file.
-o output.ps-exe mandatory: name of the output file.
-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.
-booty outputs a counter-booty payload.
-rom outputs a bootable rom, which can be used in a cheat cart.
-cpe outputs a CPE file instead of a ps-exe one.
If none of these options is provided, a ps-exe file will be emitted by default.

Valid input binary files can be in the following formats:
- PS-EXE (needs the "PS-X EXE" signature)
- ELF
- CPE
- PSF
- MiniPSF
)",
argv[0]);
return -1;
}

auto& input = inputs[0];
PCSX::IO<PCSX::File> file(new PCSX::PosixFile(input));
if (file->failed()) {
fmt::print("Unable to open file: {}\n", input);
return -1;
}

PCSX::BinaryLoader::Info info;
PCSX::IO<PCSX::Mem4G> memory(new PCSX::Mem4G());
std::map<uint32_t, std::string> symbols;
bool success = PCSX::BinaryLoader::load(file, memory, info, symbols);
if (!success) {
fmt::print("Unable to load file: {}\n", input);
return -1;
}
if (!info.pc.has_value()) {
fmt::print("File {} is invalid.\n", input);
return -1;
}

PCSX::PS1Packer::Options options;
options.booty = booty;
options.raw = raw;
options.rom = rom;
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
Loading