212. Ines file and constants
define iNES layout constants in
Lesson 212 of 356 · tests/chapter_02_rom_loading/test_212_ines_file_and_constants.py
define iNES layout constants in emulator/cartridge/ines.py.
Why this step exists
The iNES format belongs under cartridge, not generic memory, because these values describe a cartridge file container. Defining the shared sizes first gives the following parser lessons one consistent description of that layout.
Suggested implementation
INES_MAGIC = b"NES"
INES_HEADER_SIZE = 16
TRAINER_SIZE = 512
PRG_ROM_BANK_SIZE = 16 * 1024
CHR_ROM_BANK_SIZE = 8 * 1024Invariants: magic is exactly four bytes; headers and trainers are fixed-size; header bytes 4 and 5 count 16 KiB PRG and 8 KiB CHR banks, respectively. Do not mistake bank counts for byte lengths.
Out of scope for this step
1. Lesson 213 adds `INesHeader`.
2. Lesson 214 adds `parse_ines_header`.
3. Lessons 215-216 add `INesRom` and `parse_ines_rom`.Run this lesson
uv run pytest tests/chapter_02_rom_loading/test_212_ines_file_and_constants.py -v