forked from mirror/Archipelago
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
import json
|
|
from typing import Optional, Callable, Any, TypeVar
|
|
import pkgutil
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
def fetch_json(
|
|
path: str, object_hook: Optional[Callable[[dict[str, Any]], T]] = None
|
|
) -> Any:
|
|
data = pkgutil.get_data(__name__, path)
|
|
if data is None:
|
|
raise FileNotFoundError
|
|
return json.loads(data.decode("utf-8"), object_hook=object_hook)
|
|
|
|
|
|
def write_bytes_le(data: bytearray, addr: int, val: int, size: int):
|
|
for offset in range(size):
|
|
data[addr + offset] = val & 0xFF
|
|
val >>= 8
|
|
|
|
|
|
def write_short_le(data: bytearray, addr: int, val: int):
|
|
write_bytes_le(data, addr, val, 2)
|
|
|
|
|
|
def write_word_le(data: bytearray, addr: int, val: int):
|
|
write_bytes_le(data, addr, val, 4)
|
|
|
|
|
|
def read_bytes_le(data: bytearray, offs: int, size: int) -> int:
|
|
result = 0
|
|
for i in range(size):
|
|
result += data[offs + i] << 8*i
|
|
return result
|
|
|
|
|
|
def read_short_le(data: bytearray, offs: int) -> int:
|
|
return read_bytes_le(data, offs, 2)
|
|
|
|
|
|
def read_word_le(data: bytearray, offs: int) -> int:
|
|
return read_bytes_le(data, offs, 4)
|