Skip to content

Commit fed205b

Browse files
authored
Merge pull request #1 from Decompollaborate/develop
1.0.1
2 parents 58bf93f + a11ab68 commit fed205b

18 files changed

+251
-52
lines changed

.github/workflows/md_lint.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Lint markdown files
2+
3+
# Build on every branch push, tag push, and pull request change:
4+
on: [push, pull_request]
5+
6+
jobs:
7+
checks:
8+
runs-on: ubuntu-latest
9+
name: Lint md files
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Lint markdown files
15+
uses: articulate/[email protected]
16+
with:
17+
config: .markdownlint.jsonc

.github/workflows/mypy.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ jobs:
88
runs-on: ubuntu-latest
99
name: mypy
1010
steps:
11-
- uses: actions/checkout@v4
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
1213

1314
- name: Set up Python 3.7
1415
uses: actions/setup-python@v4

.github/workflows/tests.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v4
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
1314

1415
- name: Install local ipl3checksum
1516
run: pip install .

.github/workflows/tests_other_repo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push, pull_request_target]
55

66
jobs:
77
build_repo:
8-
name: Build repo
8+
name: Test other repo
99
runs-on: ubuntu-latest
1010

1111
strategy:

.github/workflows/upload_pypi.yml

+18-17
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,30 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v4
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
1314

14-
- name: Install build module
15-
run: pip install build
15+
- name: Install build module
16+
run: pip install build
1617

17-
- name: Build wheel and source
18-
run: python -m build --sdist --wheel --outdir dist/ .
18+
- name: Build wheel and source
19+
run: python -m build --sdist --wheel --outdir dist/ .
1920

20-
- uses: actions/upload-artifact@v3
21-
with:
22-
path: dist/*
21+
- uses: actions/upload-artifact@v3
22+
with:
23+
path: dist/*
2324

2425
upload_pypi:
2526
needs: [build_wheel]
2627
runs-on: ubuntu-latest
2728
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
2829
steps:
29-
- uses: actions/download-artifact@v3
30-
with:
31-
name: artifact
32-
path: dist
33-
34-
- uses: pypa/[email protected]
35-
with:
36-
user: __token__
37-
password: ${{ secrets.pypi_password }}
30+
- uses: actions/download-artifact@v3
31+
with:
32+
name: artifact
33+
path: dist
34+
35+
- uses: pypa/[email protected]
36+
with:
37+
user: __token__
38+
password: ${{ secrets.pypi_password }}

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ cython_debug/
162162
#.idea/
163163

164164

165-
#
166-
.vscode/
167165

168166
asm/
169167
*.z64

.markdownlint.jsonc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
3+
// MD024 - Multiple headings with the same content
4+
"MD024": {
5+
"siblings_only": true
6+
},
7+
8+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md
9+
// MD013 - Line length
10+
"MD013": {
11+
"code_block_line_length": 120,
12+
"headings": false
13+
}
14+
}

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"davidanson.vscode-markdownlint"
6+
]
7+
}

CHANGELOG.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [1.0.1] - 2023-09-21
11+
12+
### Added
13+
14+
- Allow invoking `ipl3checksum` as a CLI program.
15+
- Currently it only allows the `-V`/`--version` argument, which prints the
16+
version of the library.
17+
- A `CHANGELOG.md`
18+
- Cleanup the `README.md`
19+
- Reorder sections.
20+
- Add more notes about installing and the develop version.
21+
- Reference the changelog.
22+
- List features.
23+
- Add a `py.typed` file.
24+
25+
## [1.0.0] - 2023-09-20
26+
27+
### Added
28+
29+
- Initial relase
30+
31+
[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/1.1.0...HEAD
32+
[1.0.1]: https://github.com/olivierlacan/keep-a-changelog/compare/1.0.0...1.1.1
33+
[1.0.0]: https://github.com/Decompollaborate/ipl3checksum/releases/tag/1.0.0

README.md

+89-23
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ A Python library to calculate the IPL3 checksum for N64 ROMs.
1010

1111
## How to use it?
1212

13-
First you need to install the library, one way of doing it is via `pip`.
14-
15-
```bash
16-
python3 -m pip install -U ipl3checksum
17-
```
18-
19-
Now you can invoke the library from your script.
13+
To calculate the checksum of a ROM:
2014

2115
```py
2216
romBytes = # A big endian bytes-like object
@@ -36,32 +30,104 @@ cickind = ipl3checksum.detectCIC(romBytes)
3630
print(cickind) # Either a `ipl3checksum.CICKind` or None if was not able to detect the CIC
3731
```
3832

33+
## Features
34+
35+
- Supports all 6 retail CIC variants.
36+
- Can calculate the checksum of a ROM using the algorithm of any of the
37+
supported CIC variants.
38+
- Can detect any of the supported CIC variants.
39+
40+
### Restrictions/requirements
41+
42+
- The library assumes the passed ROM contains a ROM header at offset range
43+
`[0x0, 0x40]` and a correct IPL3 is at `[0x40, 0x1000]`
44+
- Since the checksum algorithm is calculated on the first MiB after IPL3 (from
45+
`0x1000` to `0x101000`), then the library expects the passed ROM to be at least
46+
`0x101000` bytes long, otherwise the library will reject the ROM.
47+
- If it is not the case, then pad your ROM with zeroes to that size.
48+
49+
## Installing
50+
51+
First you need to install the library, one way of doing it is via `pip`.
52+
53+
```bash
54+
python3 -m pip install -U ipl3checksum
55+
```
56+
57+
If you use a `requirements.txt` file in your repository, then you can add
58+
this library with the following line:
59+
60+
```txt
61+
ipl3checksum>=1.0.0,<2.0.0
62+
``````
63+
64+
Now you can invoke the library from your script.
65+
66+
### Development version
67+
68+
The unstable development version is located at the [develop](https://github.com/Decompollaborate/ipl3checksum/tree/develop)
69+
branch. PRs should be made into that branch instead of the main one.
70+
71+
The recommended way to install a locally cloned repo is by passing the `-e`
72+
(editable) flag to `pip`.
73+
74+
```bash
75+
python3 -m pip install -e .
76+
```
77+
78+
In case you want to mess with the latest development version without wanting to
79+
clone the repository, then you could use the following commands:
80+
81+
```bash
82+
python3 -m pip uninstall ipl3checksum
83+
python3 -m pip install git+https://github.com/Decompollaborate/ipl3checksum.git@develop
84+
```
85+
86+
NOTE: Installing the development version is not recommended unless you know what
87+
you are doing. Proceed at your own risk.
88+
89+
## Versioning and changelog
90+
91+
This library follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
92+
We try to always keep backwards compatibility, so no breaking changes should
93+
happen until a major release (i.e. jumping from 1.X.X to 2.0.0).
94+
95+
To see what changed on each release check either the [CHANGELOG.md](CHANGELOG.md)
96+
file or check the [releases page on Github](https://github.com/Decompollaborate/ipl3checksum/releases).
97+
You can also use [this link](https://github.com/Decompollaborate/ipl3checksum/releases/latest)
98+
to check the latest release.
99+
39100
## Where does this come from?
40101

41-
This algorithm comes directly from the IPL3, which each variant is part of the first 0x1000 bytes of the rom of every retail N64 ROM.
102+
This algorithm comes directly from the IPL3, which each variant is part of the
103+
first 0x1000 bytes of the rom of every retail N64 ROM.
42104

43-
There are various implementations floating around on the internet, but for this specific one was reverse-engineered by myself.
44-
I made this because I couldn't find a library to calculate this checksum, so I decided to reverse-engineer it myself instead of
45-
taking somebody else's work. It also was an interesting learning experience.
105+
There are various implementations floating around on the internet, but for this
106+
specific one was reverse-engineered by myself. I made this because I couldn't
107+
find a library to calculate this checksum, so I decided to reverse-engineer it
108+
myself instead of taking somebody else's work. It also was an interesting
109+
learning experience.
46110

47111
## Note about licensing
48112

49-
Most of the repository is licensed under the [MIT license](LICENSE), but I also made a
50-
[reference implementation](docs/reference_implementation.md) that is part of the public domain (licensed under CC0-1.0), feel free to
51-
use it however you prefer (acknowledgment is always appreciated, but not required).
113+
Most of the repository is licensed under the [MIT license](LICENSE), but I also
114+
made a [reference implementation](docs/reference_implementation.md) that is part
115+
of the public domain (licensed under CC0-1.0), feel free to use it however you
116+
prefer (acknowledgment is always appreciated, but not required).
52117

53118
## I want to learn more! What is an IPL3? What is CIC?
54119

55-
I'm not really the guy that can answer all your hunger for knowledge, but here are a few links that may be helpful:
120+
I'm not really the guy that can answer all your hunger for knowledge, but here
121+
are a few links that may be helpful:
56122

57-
* CIC-NUS: <https://n64brew.dev/wiki/CIC-NUS>
58-
* Initial Program Load 3 (IPL3) <https://n64brew.dev/wiki/Initial_Program_Load#IPL3>
59-
* List of retail games, containing which CIC they use: <https://docs.google.com/spreadsheets/d/1WgZ7DZSzWwYIxwg03yoN9NK_0okuSx9dVL2u5MWPQ60/edit#gid=1247952340>
60-
* Research about the CIC 6105: <https://github.com/Dragorn421/n64checksum>
61-
* Disassembly of all the retail IPL3 binaries: <https://github.com/decompals/N64-IPL/blob/main/src/ipl3.s>
123+
- CIC-NUS: <https://n64brew.dev/wiki/CIC-NUS>
124+
- Initial Program Load 3 (IPL3) <https://n64brew.dev/wiki/Initial_Program_Load#IPL3>
125+
- List of retail games, containing which CIC they use: <https://docs.google.com/spreadsheets/d/1WgZ7DZSzWwYIxwg03yoN9NK_0okuSx9dVL2u5MWPQ60/edit#gid=1247952340>
126+
- Research about the CIC 6105: <https://github.com/Dragorn421/n64checksum>
127+
- Disassembly of all the retail IPL3 binaries: <https://github.com/decompals/N64-IPL/blob/main/src/ipl3.s>
62128

63129
## References
64130

65-
* "IPL3 checksum algorithm" section of the "PIF-NUS" article on n64brew.dev: <https://n64brew.dev/wiki/PIF-NUS#IPL3_checksum_algorithm>
66-
* Used for getting the "8-bit IPL3" seed value.
67-
* List of retail games, containing which CIC they use: <https://docs.google.com/spreadsheets/d/1WgZ7DZSzWwYIxwg03yoN9NK_0okuSx9dVL2u5MWPQ60/edit#gid=1247952340>
131+
- "IPL3 checksum algorithm" section of the "PIF-NUS" article on n64brew.dev: <https://n64brew.dev/wiki/PIF-NUS#IPL3_checksum_algorithm>
132+
- Used for getting the "8-bit IPL3" seed value.
133+
- List of retail games, containing which CIC they use: <https://docs.google.com/spreadsheets/d/1WgZ7DZSzWwYIxwg03yoN9NK_0okuSx9dVL2u5MWPQ60/edit#gid=1247952340>

docs/reference_implementation.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
This whole file is licensed under CC0-1.0. See [docs/LICENSE](./LICENSE).
66

7-
This file contains a reference implementation of the IPL3 checksum algorithm, adapted to work with every known retail CIC/IPL3 variant.
7+
This file contains a reference implementation of the IPL3 checksum algorithm,
8+
adapted to work with every known retail CIC/IPL3 variant.
89

9-
This implementation is a very crude direct translation from the original assembly and it could be greatly simplified in a reimplementation.
10+
This implementation is a very crude direct translation from the original
11+
assembly and it could be greatly simplified in a reimplementation.
1012

1113
```c
1214
/* SPDX-License-Identifier: CC0-1.0 */
@@ -158,7 +160,8 @@ void calculateChecksum(const uint8_t *rom, uint32_t cic, uint32_t *dst1, uint32_
158160
switch (cic) {
159161
case 6105:
160162
case 7105:
161-
/* ipl3 6105 copies 0x330 bytes from the ROM's offset 0x000554 (or offset 0x000514 into IPL3) to vram 0xA0000004 */
163+
/* ipl3 6105 copies 0x330 bytes from the ROM's offset 0x000554 (or offset 0x000514 into IPL3) */
164+
/* to vram 0xA0000004 */
162165
/* lw $t7, 0x0($s6) */
163166
t7 = readWord(rom, s6 - 0xA0000004 + 0x000554);
164167

notes/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Notes
22

3-
This folder contains the scripts I made while I was trying to understand the checksum algorithm of every IPL3 variant.
3+
This folder contains the scripts I made while I was trying to understand the
4+
checksum algorithm of every IPL3 variant.
45

5-
All of the implementations here are direct and crude translations from the original asm.
6+
All of the implementations here are direct and crude translations from the
7+
original asm.

pyproject.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[project]
55
name = "ipl3checksum"
6-
version = "1.0.0"
6+
version = "1.0.1"
77
description = "Library to calculate the IPL3 checksum for N64 ROMs"
88
readme = "README.md"
99
requires-python = ">=3.7"
@@ -17,5 +17,11 @@ dynamic = ["dependencies"]
1717
requires = ["hatchling", "hatch-requirements-txt"]
1818
build-backend = "hatchling.build"
1919

20+
[project.scripts]
21+
ipl3checksum = "ipl3checksum.frontends.climain:ipl3checksumMain"
22+
2023
[tool.cibuildwheel]
2124
skip = ["cp36-*"]
25+
26+
[tool.setuptools.package-data]
27+
ipl3checksum = ["py.typed"]

src/ipl3checksum/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
__version_info__: tuple[int, int, int] = (1, 0, 0)
8+
__version_info__: tuple[int, int, int] = (1, 0, 1)
99
__version__ = ".".join(map(str, __version_info__))
1010
__author__ = "Decompollaborate"
1111

src/ipl3checksum/__main__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: © 2023 Decompollaborate
4+
# SPDX-License-Identifier: MIT
5+
6+
from __future__ import annotations
7+
8+
import argparse
9+
10+
from .frontends import climain
11+
12+
13+
if __name__ == "__main__":
14+
climain.ipl3checksumMain()
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: © 2023 Decompollaborate
4+
# SPDX-License-Identifier: MIT
5+
6+
from __future__ import annotations
7+
8+
9+
from . import climain as climain

0 commit comments

Comments
 (0)