Commit Graph

446 Commits

Author SHA1 Message Date
Kevin Bortis
120174e4cd Add multi-threaded zstd compression support
Switch zstd encoder from simple API (ZSTD_compress) to advanced API
(ZSTD_CCtx + ZSTD_compress2) with configurable worker threads via
ZSTD_c_nbWorkers. Consumer controls threading through threads=N
option string parameter. Default is 1 (single-threaded, bit-identical
output to previous behavior).

- Enable ZSTD_MULTITHREAD compile definition and link pthreads
- Add num_threads field to options struct and context
- Parse threads=N in option string (clamped >= 1)
- Rewrite aaruf_zstd_encode_buffer() with num_threads parameter
- Update all call sites (write.c, close.c)
2026-03-29 12:56:19 +02:00
0b6f10e526 Merge pull request #14 from FakeShemp/fakeshemp/wii-long
Add long sector for Wii/GC
2026-03-19 20:07:18 +00:00
Kevin Bortis
8a8a89450d lru: use native uint64 keys instead of string conversion
Replace string-keyed uthash lookups with HASH_FIND/HASH_ADD on native
uint64_t keys. This eliminates per-lookup malloc/snprintf/strlen/free
overhead from the block cache hot path (2 lookups per sector read).

Before: malloc(17) + snprintf hex + HASH_FIND_STR + free per lookup
After:  HASH_FIND with 8-byte integer key, zero allocations

Also removes the unused string-key API (find_in_cache/add_to_cache)
and the uint64_to_string helper — all callers use uint64 keys.

Fix off-by-one in eviction: >= caused cache to hold max_items-1
entries instead of max_items. Changed to > so the configured
capacity is honored exactly.
2026-03-19 20:35:42 +01:00
6dbd5f1bb2 Merge pull request #12 from RomTholos/fix/cross-compilation-arm-riscv
Fix cross-compilation for ARM FPU variants and add RISC-V support
2026-03-19 11:58:49 +00:00
c9cf1a42c0 Merge pull request #11 from RomTholos/fix/mode2-errored-suffix-read
Fix Mode 2 errored sector suffix not restored on read
2026-03-19 11:57:44 +00:00
Kevin Bortis
bd01e7d8a5 Fix cross-compilation for ARM FPU variants and add RISC-V support 2026-03-19 12:34:00 +01:00
65b00baf1a Merge pull request #10 from RomTholos/fix/calling-convention-pointer-order
Fix calling convention placement for pointer-returning functions
2026-03-19 09:50:02 +00:00
Kevin Bortis
48093ba779 Fix Mode 2 errored sector suffix not restored on read
When reading back Mode 2 sectors with errored ECC/EDC (SectorStatusErrored),
the else branch copied 2328 bytes from bare_data. However, bare_data only
contains the user data portion (2048 bytes for Form 1, 2324 for Form 2).
The EDC/ECC suffix was stored separately in sector_suffix during write but
never read back, causing the suffix area to contain stale data from adjacent
sectors in the decompressed block.

Fix both DDT v2 and v1 code paths to check the subheader form bit and copy
user data + suffix from their respective storage locations.

Affects any Mode 2 disc image (Dreamcast, PS1, PS2 CD, Saturn, Mega CD,
PC Engine CD, Neo Geo CD) where sectors have incorrect or zeroed ECC/EDC.
2026-03-19 10:11:06 +01:00
Kevin Bortis
981b54562e Fix calling convention placement for pointer-returning functions 2026-03-19 08:53:35 +01:00
Kevin Bortis
6be36b6bda Add Zstandard compression support
Implements zstd as an alternative to LZMA for data block and
subchannel compression using the allocated compression IDs 4
(kCompressionZstd) and 5 (kCompressionZstdCst).

Adds zstd v1.5.7 as a bundled submodule with a static library
build including x86_64 assembly fast path for decompression.

Write path selects zstd or LZMA based on the zstd option.
Subchannel blocks use zstd+CST instead of LZMA+CST when enabled.
LZMA properties header is only written for LZMA-based compression
types, preventing format corruption in zstd-compressed images.

Activated via options string: "zstd=true;zstd_level=19".
Default remains LZMA for backwards compatibility.

Tested: SHA-256 verified lossless roundtrips across 9 disc systems
(Dreamcast, Saturn, Mega CD, PC Engine CD, Neo Geo CD, PS1, PS2 CD,
PS2 DVD) and PS1 SBI subchannel preservation with zstd+CST.
2026-03-19 08:45:07 +01:00
Rebecca Wallander
91f24ae789 Add long sector for Wii/GC 2026-03-18 21:39:55 +01:00
Kevin Bortis
cf4b09b8b0 Fix uninitialized EDC bytes for Mode 2 Form 2 NoCrc sectors
When reading back Mode 2 Form 2 sectors with SectorStatusMode2Form2NoCrc,
the 4-byte EDC field at bytes 2348-2351 was left untouched. Since the
caller's buffer may contain arbitrary data, this results in non-deterministic
output for those bytes.

The NoCrc status indicates the original disc had no CRC (zeroed EDC).
The fix adds the missing else branch to zero the EDC field, matching
the behavior that Mode2Form2Ok already has via aaruf_ecc_cd_reconstruct.

Both DDT v1 and v2 code paths are fixed.
2026-03-18 21:36:44 +01:00
a9be6b51bc Return correct error status and expected buffer length when buffer is null in generated sectors. 2026-03-18 09:13:01 +00:00
c989ba6131 Reorder includes in helpers.c: move wincrypt.h after windows.h for better organization 2026-03-17 01:26:13 +00:00
694601cc63 Enhance Wii junk data handling: reconstruct junk in user data area during read and write operations 2026-03-16 22:54:53 +00:00
a15cc47b84 Fix stream position calculation for junk region: adjust to use block start for seed alignment 2026-03-16 19:30:07 +00:00
bd10c2ea29 Free resources for Nintendo GameCube/Wii junk map and Wii encryption contexts: implement cleanup in close function 2026-03-16 18:49:33 +00:00
96cace1860 Add support for regenerating junk sectors and Wii re-encryption: implement lazy initialization and encryption handling 2026-03-16 18:47:18 +00:00
05e451d68e Add support for generable sectors in write process: implement DDT entry handling without data storage 2026-03-16 18:42:25 +00:00
dd23682c16 Disable checksums for unencrypted and generable sectors in write process 2026-03-16 18:41:54 +00:00
a128473f41 Add Wii disc encryption support: implement partition key map and group encrypt/decrypt functions 2026-03-16 18:39:18 +00:00
d5d6e036e4 Add junk map serialization and deserialization for Nintendo GameCube/Wii: implement functions for entry management and lazy initialization 2026-03-16 18:39:08 +00:00
b50f2e56b6 Add new media tag mappings for Wii and GameCube: include WiiPartitionKeyMap and NgcwJunkMap for improved data handling 2026-03-16 18:32:45 +00:00
2ebe8127bd Add Lagged Fibonacci Generator for Nintendo GameCube/Wii: implement LFG context and functions for junk data generation 2026-03-16 18:28:22 +00:00
913d0508a2 Add recursion guard for Wii U re-encryption: implement flag to prevent recursive calls during sector processing 2026-03-16 13:28:16 +00:00
1c577808d1 Add Wii U re-encryption support: implement sector key retrieval and encryption logic 2026-03-16 11:20:46 +00:00
a6226e0c2e Add Wii U disc encryption support: implement key mapping, encrypt/decrypt functions, and serialization 2026-03-16 11:16:27 +00:00
b6fddcced6 Add Wii U partition key mapping to data type and media tag handling 2026-03-16 11:13:10 +00:00
93357cbf1f Add Wii U encryption support to context structure and cleanup logic 2026-03-16 11:11:40 +00:00
a8f500fd5f Refactor AES-128 implementation: move source files to lib directory and update includes 2026-03-16 10:48:54 +00:00
73dac131b8 Implement PS3 encryption support with lazy initialization and error handling 2026-03-15 19:12:59 +00:00
85dc9ea1b8 Added PS3 encryption. 2026-03-15 18:32:08 +00:00
608b391c96 Added AES128. 2026-03-15 18:31:19 +00:00
d53faf7a38 Rename track type enums for consistency 2026-03-15 18:18:15 +00:00
32b41b165f Fix sector tag assignment for decrypted DVD title key 2026-03-14 21:45:51 +00:00
3d81f50afe Rename data type enum. 2026-03-14 21:45:02 +00:00
a5b8054a14 Rename compression enum. 2026-03-14 20:39:56 +00:00
ce9f6ba610 Rename media tags. 2026-03-14 20:18:35 +00:00
43b226bbfa Rename sector tags. 2026-03-14 19:54:52 +00:00
6fa82b4dfe Add feature compatibility checks for V2+ images and define new error codes 2026-03-14 18:52:51 +00:00
1516e9ff24 Add PS3 related media tags. 2026-03-09 20:11:07 +00:00
30965a0c94 Add Nintendo Wii U disc key to enums and update related functions 2026-03-08 19:59:28 +00:00
1a16c7b6e2 Add blockAlignmentShift to header in create.c 2026-01-10 14:40:27 +00:00
e598dd97c7 Fix order of includes. 2026-01-06 14:27:50 +00:00
4df22c47ef Add Floppy Write-Protect status to media tag and data type enums 2026-01-06 14:00:55 +00:00
ba6e122c7c Fix bug that reported incorrect list of readable sector tags for CD images that had no unconforming prefix or suffix. 2026-01-06 10:54:32 +00:00
Rebecca Wallander
869376604c Use lazy loading of flux captures 2026-01-01 13:37:21 +01:00
Rebecca Wallander
c412030a8b Use block alignment offset instead of absolute offset 2026-01-01 13:37:21 +01:00
Rebecca Wallander
86b6680e3e Add data type to datastream block 2026-01-01 13:37:20 +01:00
Rebecca Wallander
d644f81fe3 Address some Sonar issues 2026-01-01 13:35:45 +01:00