Skip to content

Commit

Permalink
sum frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Dec 19, 2023
1 parent 874e219 commit 49fd86c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for the IPL3 5101 variant (Used by Aleck 64 games).
- New frontends:
- `detect_cic`: Allows to detect the cic type used by a rom.
- `sum`: Calculates the ipl3 checksum of a rom.

### Changed

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ Those examples are distributed with the Python library as cli tools. Each one
of them can be executed with either `ipl3checksum utilityname` or
`python3 -m ipl3checksum utilityname`, for example `ipl3checksum detect_cic`.

The list can be checked in runtime with `ipl3checksum --help`.
The list can be checked in runtime with `ipl3checksum --help`. Suboptions for
each tool can be checked with `ipl3checksum utilityname --help`.

- `detect_cic`: Tries to detect the cic used from the given big endian rom.
- `sum`: Calculates the ipl3 checksum o a given big endian rom.

## Versioning and changelog

Expand Down
1 change: 1 addition & 0 deletions src/ipl3checksum/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def ipl3checksumMain():
subparsers = parser.add_subparsers(description="action", help="The CLI utility to run", required=True)

ipl3checksum.frontends.detect_cic.addSubparser(subparsers)
ipl3checksum.frontends.sum.addSubparser(subparsers)

args = parser.parse_args()
args.func(args)
Expand Down
1 change: 1 addition & 0 deletions src/ipl3checksum/frontends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@


from . import detect_cic as detect_cic
from . import sum as sum
10 changes: 5 additions & 5 deletions src/ipl3checksum/frontends/detect_cic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

import ipl3checksum

def doDetectCic(romPath: Path) -> int:
romBytes = romPath.read_bytes()

def doDetectCic(romBytes: bytes) -> int:
kind = ipl3checksum.detectCIC(romBytes)

if kind is None:
Expand All @@ -27,10 +25,12 @@ def doDetectCic(romPath: Path) -> int:
def processArguments(args: argparse.Namespace):
romPath: Path = args.rom_path

exit(doDetectCic(romPath))
romBytes = romPath.read_bytes()

exit(doDetectCic(romBytes))

def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]):
parser = subparser.add_parser("detect_cic", help="Display various information about a symbol or address.")
parser = subparser.add_parser("detect_cic", help="Detects the CIC variant of a given rom")

parser.add_argument("rom_path", help="Path to a big endian ROM file", type=Path)

Expand Down
45 changes: 45 additions & 0 deletions src/ipl3checksum/frontends/sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations

import argparse
from pathlib import Path

import ipl3checksum

def doChecksumize(romBytes: bytes) -> int:
kind = ipl3checksum.detectCIC(romBytes)

if kind is None:
print(f"Unable to detect CIC kind")
return 1

print(f"Detected kind is '{kind.name}'")

checksum = ipl3checksum.calculateChecksum(romBytes, kind)
if checksum is None:
print(f"Unable to calculate checksum")
return 1

chk0, chk1 = checksum
print(f"Calculated checksum: {chk0:08X} {chk1:08X}")

return 0


def processArguments(args: argparse.Namespace):
romPath: Path = args.rom_path

romBytes = romPath.read_bytes()

exit(doChecksumize(romBytes))

def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]):
parser = subparser.add_parser("sum", help="Calculates the ipl3 checksum of a big endian ROM.")

parser.add_argument("rom_path", help="Path to a big endian ROM file", type=Path)

parser.set_defaults(func=processArguments)

0 comments on commit 49fd86c

Please sign in to comment.