70 Commits

Author SHA1 Message Date
elliotnunn 69839ea3ad Add pure-Python BinHex (.hqx) support 2025-12-01 10:37:02 +08:00
Karl Knechtel 13fc5fa05e Fix bugs and typos
The code has been informally tested using some sample data.

Trivia: as I discovered by accident, apparently LibreOffice on Linux can
open binhex-encoded PICTs, as long as the file uses a `\n` line ending
after the header (`binhex.py` uses a `\r\r` separator, but manually
editing this produces a result that LibreOffice opens).

The test data appears not to have actually taken advantage of RLE, but
it could be successfully decoded, and re-encoding and re-decoding the
result was a successful round trip.
2025-11-30 20:03:34 -05:00
Karl Knechtel d4f2f210bb Rewrite rle_encode
New approach: explicitly split the input into runs (tracking the length
and byte value for each run), and emit encoded data for each run when
the next one starts (and at the end of the data). This seems overall
easier to understand.
2025-11-30 18:15:14 -05:00
Karl Knechtel 1f165e0c5a Refactor rle_decode
The `to_repeat` value is unnecessary since we can just look at the last
byte of the output (after first checking whether there is output).
2025-11-30 17:27:31 -05:00
Karl Knechtel 2fa78735c3 Refactor rle_decode
Pulled out some logic into helper functions.
2025-11-30 17:23:42 -05:00
Karl Knechtel 873e5a657d Add rle_decode / rle_encode (first attempt)
The rle_encode implementation works somewhat differently from the
original C; rather than using numeric indices into the original data
with a nested loop to detect runs, it tries to use a single stateful
loop (remembering how many repeated characters have been seen so far).

It is an open question whether runs of the RUNCHAR byte (0x90) should be
encoded. The specification is ambiguous:
http://fileformats.archiveteam.org/wiki/RLE90
so it's unclear whether a sequence like 0x90 0x00 0x90 0x09 can be used
to encode 10 0x90 bytes, or whether this would represent 0x90 followed
by 9 0x00 bytes, or just what. It appears that the original
standard library decoder interprets this as "10 0x90 bytes", since it
gets the byte to be repeated from the output buffer. However, it also
appears that the original standard library encoder doesn't attempt this
encoding, and will turn runs of 0x90 input into runs of alternating 0x90
and 0x00 bytes.

The code here is not tested, but should preserve that behaviour.
2025-11-30 17:06:36 -05:00
Karl Knechtel ed4c97b68d Add crc implementation 2025-11-30 15:43:30 -05:00
Karl Knechtel 3267700bc9 Add a2b and b2a implementations 2025-11-30 14:02:08 -05:00
Karl Knechtel a75a901e93 Set up hook for local HQX implementation
Since the standard library `binascii` module is unavailable whenever the
vendored `binhex` would be used, the latter is modified to refer to
`hqx` in the same package instead.

For future-proofing, `hqx` delegates to a `slow_hqx` implementation,
which could be overridden by a C implementation when available.

The function names are also slightly altered to make more sense in the
context of this change. However, the original interface will be
preserved, so that no further change in `binhex.py` will be required.
2025-11-30 14:01:20 -05:00
Elliot Nunn a0aa4b500c Bump + push 2025-11-30 10:03:25 +08:00
Elliot Nunn 17e3e914db Fix failure on non-Mac systems
(thanks jduerstock)
2025-11-30 07:57:20 +08:00
Elliot Nunn a851194b98 Bump + push 2019-10-10 10:42:59 +08:00
Elliot Nunn e8580f3954 Parse version numbers more realistically 2019-10-10 10:10:50 +08:00
Elliot Nunn fc055d6aec Name lanLib parcels using that string 2019-09-29 13:50:33 +08:00
Elliot Nunn 9dd0317bdc Account for missing length bytes in NDRV sources 2019-09-29 11:50:00 +08:00
Elliot Nunn de37ceec98 Fix a/b field mixup in Parcelfile auto-comment 2019-09-28 16:52:58 +08:00
Elliot Nunn 9a320c71f7 Use the actual names of ndrv parcels, don't guess 2019-09-24 16:42:20 +08:00
Elliot Nunn 6ea035cf52 Bump + push 2019-08-11 09:39:03 +08:00
Elliot Nunn 694c2d5a27 Sharpen Parcelfile comments 2019-08-08 23:56:00 +08:00
Elliot Nunn cf388de2c7 Adopt Python's deprecated binhex module 2019-08-08 23:43:49 +08:00
Elliot Nunn 6e4da327d6 Bump + push 2019-08-04 21:08:10 +08:00
Elliot Nunn f3c3348e90 Fix typo in readme 2019-08-04 21:07:05 +08:00
Elliot Nunn 5db5af4804 Improve the comment 2019-08-04 21:06:50 +08:00
Elliot Nunn 9c2c17fed8 Add helpful comment to Parcelfile 2019-08-04 10:57:04 +08:00
Elliot Nunn 1e04aba72d Fix a very bad OldWorld ROM regression 2019-08-04 10:51:13 +08:00
Elliot Nunn e7d0480001 Bump + push 2019-08-02 14:37:54 +08:00
Elliot Nunn 188dc429de Preserve the Gibbly-bootinfo complex 2019-08-02 14:32:00 +08:00
Elliot Nunn 27d6e2d77c Patch bootscript to match Trampoline when needed
This allows any Parcels-based bootscript to work with any Parcels-based
Trampoline.
2019-08-02 11:58:57 +08:00
Elliot Nunn b03f960544 Bump + push 2019-07-28 16:37:50 +08:00
Elliot Nunn c74c9af682 Update readme with tbxi-patches 2019-07-28 16:32:19 +08:00
Elliot Nunn 0f7a98c01b Make README work on PyPI 2019-06-11 16:39:49 +08:00
Elliot Nunn 8918d7fab9 Bump + push 2019-06-11 16:15:00 +08:00
Elliot Nunn 238992d402 Add README 2019-06-11 16:14:45 +08:00
Elliot Nunn 9d93390da0 Bump + push 2019-06-11 12:30:59 +08:00
Elliot Nunn 93c5d270cd Support fixed-offset resources
Most TNT-era ROMs use this feature of RomLayout. Heuristically detect,
report and rebuild these ROMs.
2019-06-11 12:29:47 +08:00
Elliot Nunn f5f2ce1dea Fix sanity-checking of complex ROMs 2019-06-11 12:29:47 +08:00
Elliot Nunn 7a3ece33d8 Bump + push 2019-06-10 11:52:12 +08:00
Elliot Nunn 42e89b5e22 Handle incorrect zero size fields
Previously the Configfile would say something like
'HWInitCodeOffset=0x00000000=HWInit' if the size field was mistakenly
set to zero. Now we just search for whatever can be found at that
location.
2019-06-10 11:51:31 +08:00
Elliot Nunn 452519f829 Use name 'Mac OS ROM' within BinHex 2019-06-03 12:08:04 +08:00
Elliot Nunn 244c93f567 Make ConfigInfo format more consistent 2019-06-03 12:06:58 +08:00
Elliot Nunn a1b64ca588 Add .pict extension to PICT files
Nicer browsing in Mac OS X
2019-06-02 21:38:27 +08:00
Elliot Nunn e2d230f293 SuperMario: respect 68K segmented code rsrc name 2019-06-02 19:56:15 +08:00
Elliot Nunn 09c09f52bc Bump + push 2019-06-02 10:36:48 +08:00
Elliot Nunn f2353d63c7 Rip out patching mechanism
Conceived in a dream, this feature turned out to be more of a bug. The
whole idea of tbxi is to work with easily-editable text files and naked
binaries. Patching is best accomplished with a separate script.
2019-06-02 09:57:33 +08:00
Elliot Nunn b5af802944 Hacky Pippin ROM support
The Pippin ROM has lower checksums than expected, by about 4%. Without
recovering the missing data, this probably cannot be replicated, so we
just detect it and live with it.
2019-06-02 09:55:43 +08:00
Elliot Nunn 47b0cb1c38 Bump + push 2019-05-26 11:36:00 +08:00
Elliot Nunn 8bd552aa96 Output Mac metadata 2019-05-26 11:31:19 +08:00
Elliot Nunn 923f13c663 More accurate headline 2019-05-26 11:10:03 +08:00
Elliot Nunn fbb8629647 MIT license 2019-05-26 11:09:47 +08:00
Elliot Nunn f004e98c9f Improve online help 2019-05-26 11:07:44 +08:00