1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-04 15:04:31 +00:00

Match compression for gc-eu-mq (#1704)

* Improve compression

* Format

* Typo

* Use Python assignment expression in tools/dmadata.py

Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>

* Review decompress_baserom.py

* Replace DEFINE_DEBUG_SCENE with CPP defines

* Pass is_zlib_compressed instead of version

* Reword NOLOAD comment in write_compress_ranges

* Remove redundant comment

---------

Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
This commit is contained in:
cadmic 2024-02-03 14:59:19 -08:00 committed by GitHub
parent 0cbcebfded
commit d674dad3da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 220 additions and 177 deletions

75
tools/dmadata.py Normal file
View file

@ -0,0 +1,75 @@
# SPDX-FileCopyrightText: © 2024 ZeldaRET
# SPDX-License-Identifier: CC0-1.0
from __future__ import annotations
import dataclasses
import struct
STRUCT_IIII = struct.Struct(">IIII")
@dataclasses.dataclass
class DmaEntry:
"""
A Python counterpart to the dmadata entry struct:
```c
typedef struct {
/* 0x00 */ uintptr_t vromStart;
/* 0x04 */ uintptr_t vromEnd;
/* 0x08 */ uintptr_t romStart;
/* 0x0C */ uintptr_t romEnd;
} DmaEntry;
```
"""
vrom_start: int
vrom_end: int
rom_start: int
rom_end: int
def __repr__(self):
return (
"DmaEntry("
f"vrom_start=0x{self.vrom_start:08X}, "
f"vrom_end=0x{self.vrom_end:08X}, "
f"rom_start=0x{self.rom_start:08X}, "
f"rom_end=0x{self.rom_end:08X}"
")"
)
SIZE_BYTES = STRUCT_IIII.size
def to_bin(self, data: memoryview):
STRUCT_IIII.pack_into(
data,
0,
self.vrom_start,
self.vrom_end,
self.rom_start,
self.rom_end,
)
@staticmethod
def from_bin(data: memoryview):
return DmaEntry(*STRUCT_IIII.unpack_from(data))
def is_compressed(self) -> bool:
return self.rom_end != 0
DMA_ENTRY_END = DmaEntry(0, 0, 0, 0)
def read_dmadata(rom_data: memoryview, start_offset: int) -> list[DmaEntry]:
result = []
offset = start_offset
while (
entry := DmaEntry.from_bin(rom_data[offset : offset + DmaEntry.SIZE_BYTES])
) != DMA_ENTRY_END:
result.append(entry)
offset += DmaEntry.SIZE_BYTES
return result