Skip to content

Commit

Permalink
linter: various (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
showa-yojyo committed Nov 3, 2024
1 parent 088a9ae commit 770faf7
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 147 deletions.
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,14 @@ build-backend = "hatchling.build"

[tool.hatch.version]
path = "src/dqutils/release.py"

[tool.ruff.lint]
ignore = [
"ARG004",
"RUF001",
"RUF003",
"PLR2004",
"PT009",
"S101",
"T201",
]
3 changes: 0 additions & 3 deletions src/dqutils/dq3/disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,10 @@
0xC2C573: (1,),
0xC2C739: (1,),
0xC2C766: (1,),
0xC2C766: (1,),
0xC2C791: (1,),
0xC2C7C6: (1,),
0xC32251: (1,),
0xC322C6: (1,),
0xC322C6: (1,),
0xC3233B: (1,),
0xC323B0: (1,),
0xC32436: (1,),
Expand Down Expand Up @@ -232,7 +230,6 @@
0xC45ADC: (1,),
0xC45B1A: (1,),
0xC45B66: (1,),
0xC45B66: (1,),
0xC45BEB: (1,),
0xC45C5A: (1,),
0xC4624E: (1,),
Expand Down
48 changes: 24 additions & 24 deletions src/dqutils/dq3/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@
from dqutils.message_generator import IteratorT
from dqutils.string_generator import StringInfo

CONTEXT_MESSAGE_BATTLE: Final[dict] = dict(
title="DRAGONQUEST3",
delimiters=b"\xac\xae",
charmap=CHARMAP_SMALL,
message_id_first=0x0000,
message_id_last=0x0177,
addr_message=0xFC9F22,
decoding_read_size=2,
)

CONTEXT_MESSAGE_SCENARIO: Final[dict] = dict(
title="DRAGONQUEST3",
delimiters=array(
CONTEXT_MESSAGE_BATTLE: Final[dict] = {
"title": "DRAGONQUEST3",
"delimiters": b"\xac\xae",
"charmap": CHARMAP_SMALL,
"message_id_first": 0x0000,
"message_id_last": 0x0177,
"addr_message": 0xFC9F22,
"decoding_read_size": 2,
}

CONTEXT_MESSAGE_SCENARIO: Final[dict] = {
"title": "DRAGONQUEST3",
"delimiters": array(
"H",
(
0x00AC,
0x00AE,
),
),
charmap=CHARMAP_LARGE,
message_id_first=0x0000,
message_id_last=0x0FCF,
addr_group=0xC15331,
addr_shiftbit_array=0xC1B01C,
addr_message=0xFCC258,
addr_huffman_off=0xC159D3,
addr_huffman_on=0xC161A7,
huffman_root=0x07D2,
decoding_read_size=2,
)
"charmap": CHARMAP_LARGE,
"message_id_first": 0x0000,
"message_id_last": 0x0FCF,
"addr_group": 0xC15331,
"addr_shiftbit_array": 0xC1B01C,
"addr_message": 0xFCC258,
"addr_huffman_off": 0xC159D3,
"addr_huffman_on": 0xC161A7,
"huffman_root": 0x07D2,
"decoding_read_size": 2,
}


def enum_battle(first: int | None = None, last: int | None = None) -> Iterator[StringInfo]:
Expand Down
16 changes: 8 additions & 8 deletions src/dqutils/dq3/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
if TYPE_CHECKING:
from dqutils.string_generator import StringInfo

CONTEXT: Final[dict] = dict(
title="DRAGONQUEST3",
delimiters=b"\xac",
charmap=CHARMAP,
addr_string=0xFECFB7,
string_id_first=0x0000,
string_id_last=0x03BE,
)
CONTEXT: Final[dict] = {
"title": "DRAGONQUEST3",
"delimiters": b"\xac",
"charmap": CHARMAP,
"addr_string": 0xFECFB7,
"string_id_first": 0x0000,
"string_id_last": 0x03BE,
}


def enum_string(first: int | None = None, last: int | None = None) -> Iterator[StringInfo]:
Expand Down
14 changes: 10 additions & 4 deletions src/dqutils/dq5/disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
) # BRK #$AC


BRK_BPL_RANGE_FIRST = 0x01
BRK_BPL_RANGE_LAST = 0x1B
BRK_BMI_RANGE_FIRST = 0x80
BRK_BMI_RANGE_LAST = 0xAD

class DisassembleStateDQ5(DisassembleState):
"""A specialized state class for disassembling DQ5."""

Expand All @@ -103,15 +108,16 @@ class BRK(get_instruction(0x00)): # type: ignore[misc]
def execute(state: DisassembleState, context: ContextT) -> tuple[ContextT, str | None]:
sigbyte = cast(int, self.current_operand)

if sigbyte == 0x00 or sigbyte >= 0xAD:
if sigbyte == 0x00 or sigbyte >= BRK_BMI_RANGE_LAST:
return context, None
elif sigbyte < 0x1B:

if sigbyte < BRK_BPL_RANGE_LAST:
byte_count = BRK_BPL[sigbyte]
elif 0x1B <= sigbyte < 0x80:
elif BRK_BPL_RANGE_LAST <= sigbyte < BRK_BMI_RANGE_FIRST:
# This case is illegal.
return context, None
else:
byte_count = BRK_BMI[sigbyte - 0x80]
byte_count = BRK_BMI[sigbyte - BRK_BMI_RANGE_FIRST]

if byte_count == (0,):
return context, None
Expand Down
62 changes: 31 additions & 31 deletions src/dqutils/dq5/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@
from dqutils.dq5.charsmall import CHARMAP as CHARMAP_SMALL
from dqutils.dq5.charsmall import process_dakuten

CONTEXT_MESSAGE_BATTLE: Final[dict] = dict(
title="DRAGONQUEST5",
delimiters=array("H", (0x00E7, 0x00EF, 0x00FE)),
charmap=CHARMAP_SMALL,
message_id_first=0x0000,
message_id_last=0x01A3,
addr_group=0x24AECD,
addr_shiftbit_array=0x249E8C,
addr_message=0x000000,
addr_huffman_off=0x249D18,
addr_huffman_on=0x249C2E,
huffman_root=0x00E8,
decoding_mask=0x00FF,
decoding_read_size=1,
)

CONTEXT_MESSAGE_SCENARIO: Final[dict] = dict(
title="DRAGONQUEST5",
delimiters=array("H", (0x1001, 0x1010, 0x1018)),
charmap=CHARMAP_LARGE,
message_id_first=0x0000,
message_id_last=0x0C7E,
addr_group=0x24AF1E,
addr_shiftbit_array=0x249E8C,
addr_message=0x000000,
addr_huffman_off=0x249472,
addr_huffman_on=0x248CB6,
huffman_root=0x07BA,
decoding_mask=0x1FFF,
decoding_read_size=2,
)
CONTEXT_MESSAGE_BATTLE: Final[dict] = {
"title": "DRAGONQUEST5",
"delimiters": array("H", (0x00E7, 0x00EF, 0x00FE)),
"charmap": CHARMAP_SMALL,
"message_id_first": 0x0000,
"message_id_last": 0x01A3,
"addr_group": 0x24AECD,
"addr_shiftbit_array": 0x249E8C,
"addr_message": 0x000000,
"addr_huffman_off": 0x249D18,
"addr_huffman_on": 0x249C2E,
"huffman_root": 0x00E8,
"decoding_mask": 0x00FF,
"decoding_read_size": 1,
}

CONTEXT_MESSAGE_SCENARIO: Final[dict] = {
"title": "DRAGONQUEST5",
"delimiters": array("H", (0x1001, 0x1010, 0x1018)),
"charmap": CHARMAP_LARGE,
"message_id_first": 0x0000,
"message_id_last": 0x0C7E,
"addr_group": 0x24AF1E,
"addr_shiftbit_array": 0x249E8C,
"addr_message": 0x000000,
"addr_huffman_off": 0x249472,
"addr_huffman_on": 0x248CB6,
"huffman_root": 0x07BA,
"decoding_mask": 0x1FFF,
"decoding_read_size": 2,
}


def enum_battle(first: int | None = None, last: int | None = None) -> IteratorT:
Expand Down
36 changes: 18 additions & 18 deletions src/dqutils/dq5/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@

CONTEXT_GROUP: Final[tuple[dict[str, int], ...]] = (
# Partners (human beings).
dict(addr_string=0x23C5CE, string_id_first=0, string_id_last=8),
{"addr_string": 0x23C5CE, "string_id_first": 0, "string_id_last": 8},
# Classes.
dict(addr_string=0x23C5F9, string_id_first=0, string_id_last=17),
{"addr_string": 0x23C5F9, "string_id_first": 0, "string_id_last": 17},
# Distinction (male/female/others!).
dict(addr_string=0x23C690, string_id_first=0, string_id_last=3),
{"addr_string": 0x23C690, "string_id_first": 0, "string_id_last": 3},
# Spells and skills.
dict(addr_string=0x228000, string_id_first=0, string_id_last=171),
{"addr_string": 0x228000, "string_id_first": 0, "string_id_last": 171},
# Monsters.
dict(addr_string=0x23C69C, string_id_first=0, string_id_last=236),
{"addr_string": 0x23C69C, "string_id_first": 0, "string_id_last": 236},
# Items.
dict(addr_string=0x23CE0E, string_id_first=0, string_id_last=216),
{"addr_string": 0x23CE0E, "string_id_first": 0, "string_id_last": 216},
# Strategies.
dict(addr_string=0x23D5B5, string_id_first=0, string_id_last=6),
{"addr_string": 0x23D5B5, "string_id_first": 0, "string_id_last": 6},
# Unknown 1.
dict(addr_string=0x308000, string_id_first=0, string_id_last=0),
{"addr_string": 0x308000, "string_id_first": 0, "string_id_last": 0},
# Unknown 2.
dict(addr_string=0x23D6A1, string_id_first=0, string_id_last=0),
{"addr_string": 0x23D6A1, "string_id_first": 0, "string_id_last": 0},
# Ditto.
dict(addr_string=0x23D6A1, string_id_first=0, string_id_last=0),
{"addr_string": 0x23D6A1, "string_id_first": 0, "string_id_last": 0},
# Partners (monsters).
dict(addr_string=0x23C242, string_id_first=0, string_id_last=168),
{"addr_string": 0x23C242, "string_id_first": 0, "string_id_last": 168},
# Destination list.
dict(addr_string=0x23D5F3, string_id_first=0, string_id_last=23),
{"addr_string": 0x23D5F3, "string_id_first": 0, "string_id_last": 23},
)
"""the string table located at $21955B."""

CONTEXT_PROTOTYPE: Final[dict] = dict(
title="DRAGONQUEST5",
charmap=CHARMAP,
)
CONTEXT_PROTOTYPE: Final[dict] = {
"title": "DRAGONQUEST5",
"charmap": CHARMAP,
}

for group in CONTEXT_GROUP:
group.update(CONTEXT_PROTOTYPE) # type: ignore[arg-type]
Expand Down Expand Up @@ -89,7 +89,7 @@ def print_all() -> None:
for groupid, context in enumerate(CONTEXT_GROUP):
print(f"Group #{groupid:d}")
charmap = cast(dict[int, str], context["charmap"])
for id, entry in enumerate(StringGeneratorPascalStyle(context)):
for i, entry in enumerate(StringGeneratorPascalStyle(context)):
address, code_seq = entry
text = process_dakuten(get_text(code_seq, charmap, None))
print(f"{id:04X}:{address:06X}:{text}")
print(f"{i:04X}:{address:06X}:{text}")
48 changes: 24 additions & 24 deletions src/dqutils/dq6/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@
from dqutils.message_generator import IteratorT
from dqutils.string_generator import StringInfo

CONTEXT_MESSAGE_BATTLE: Final[dict] = dict(
title="DRAGONQUEST6",
delimiters=b"\xac\xae",
charmap=CHARMAP_SMALL,
message_id_first=0x0000,
message_id_last=0x025B,
addr_message=0xF6DEBD,
decoding_read_size=2,
)

CONTEXT_MESSAGE_SCENARIO: Final[dict] = dict(
title="DRAGONQUEST6",
delimiters=array(
CONTEXT_MESSAGE_BATTLE: Final[dict] = {
"title": "DRAGONQUEST6",
"delimiters": b"\xac\xae",
"charmap": CHARMAP_SMALL,
"message_id_first": 0x0000,
"message_id_last": 0x025B,
"addr_message": 0xF6DEBD,
"decoding_read_size": 2,
}

CONTEXT_MESSAGE_SCENARIO: Final[dict] = {
"title": "DRAGONQUEST6",
"delimiters": array(
"H",
(
0x00AC,
0x00AE,
),
),
charmap=CHARMAP_LARGE,
message_id_first=0x0000,
message_id_last=0x1B2D,
addr_group=0xC15BB5,
addr_shiftbit_array=0xC02BCC,
addr_message=0xF7175B,
addr_huffman_off=0xC167BE,
addr_huffman_on=0xC1700E,
huffman_root=0x084E,
decoding_read_size=2,
)
"charmap": CHARMAP_LARGE,
"message_id_first": 0x0000,
"message_id_last": 0x1B2D,
"addr_group": 0xC15BB5,
"addr_shiftbit_array": 0xC02BCC,
"addr_message": 0xF7175B,
"addr_huffman_off": 0xC167BE,
"addr_huffman_on": 0xC1700E,
"huffman_root": 0x084E,
"decoding_read_size": 2,
}


def enum_battle(first: int | None = None, last: int | None = None) -> Iterator[StringInfo]:
Expand Down
16 changes: 8 additions & 8 deletions src/dqutils/dq6/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
if TYPE_CHECKING:
from dqutils.string_generator import StringInfo

CONTEXT: Final[dict] = dict(
title="DRAGONQUEST6",
delimiters=b"\xac",
charmap=CHARMAP,
addr_string=0xFB8703,
string_id_first=0x0000,
string_id_last=0x09CA,
)
CONTEXT: Final[dict] = {
"title": "DRAGONQUEST6",
"delimiters": b"\xac",
"charmap": CHARMAP,
"addr_string": 0xFB8703,
"string_id_first": 0x0000,
"string_id_last": 0x09CA,
}


def enum_string(first: int | None = None, last: int | None = None) -> Iterator[StringInfo]:
Expand Down
8 changes: 4 additions & 4 deletions src/dqutils/message_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from dqutils.snescpu.mapper import AbstractMapper

_DUMMY_CODE: Final[int] = 0xFFFFFFFF

_SHIFTBIT_ARRAY_SIZE: Final[int] = 8

class AbstractMessageGenerator(metaclass=ABCMeta):
"""The base class of MessageGenerator subclasses."""
Expand Down Expand Up @@ -103,7 +103,7 @@ def assert_valid(self: Self) -> None:
assert self.delimiters.typecode == "H"
assert self.addr_group >= 0
assert self.addr_shiftbit_array >= 0
assert len(self.shiftbit_array) == 8
assert len(self.shiftbit_array) == _SHIFTBIT_ARRAY_SIZE
assert self.addr_message >= 0
self._assert_range()
assert self.addr_huffman_off >= 0
Expand Down Expand Up @@ -174,9 +174,9 @@ def _setup_shiftbit_array(self: Self, mem: mmap.mmap) -> None:
assert self.addr_shiftbit_array

mem.seek(self.mapper.from_cpu(self.addr_shiftbit_array))
self.shiftbit_array = mem.read(8)
self.shiftbit_array = mem.read(_SHIFTBIT_ARRAY_SIZE)

assert len(self.shiftbit_array) == 8
assert len(self.shiftbit_array) == _SHIFTBIT_ARRAY_SIZE

def locate_message(self: Self, mem: mmap.mmap, message_id: int) -> tuple[int, int]:
"""Return the location where the messege data is stored.
Expand Down
Loading

0 comments on commit 770faf7

Please sign in to comment.