SM: smoother co-op, basepatch internal improvements (#793)

* SM: remote touch instantly, pull ips refactor and symbols

* SM: remove hard-coded ROM address writes

* SM: Full length player table, incl. receive-only player ids

+ apply PR feedback (correct graphic offset, readable data file paths)
This commit is contained in:
strotlog
2022-07-26 00:43:39 -07:00
committed by GitHub
parent a0482cf27e
commit 1e366ff66f
9 changed files with 1027 additions and 81 deletions

View File

@@ -1,11 +1,12 @@
import hashlib
import os
import json
import Utils
from Patch import read_rom, APDeltaPatch
SMJUHASH = '21f3e98df4780ee1c667b84e57d88675'
ROM_PLAYER_LIMIT = 65535
ROM_PLAYER_LIMIT = 65535 # max archipelago player ID. note, SM ROM itself will only store 201 names+ids max
class SMDeltaPatch(APDeltaPatch):
@@ -17,7 +18,6 @@ class SMDeltaPatch(APDeltaPatch):
def get_source_data(cls) -> bytes:
return get_base_rom_bytes()
def get_base_rom_bytes(file_name: str = "") -> bytes:
base_rom_bytes = getattr(get_base_rom_bytes, "base_rom_bytes", None)
if not base_rom_bytes:
@@ -40,3 +40,48 @@ def get_base_rom_path(file_name: str = "") -> str:
if not os.path.exists(file_name):
file_name = Utils.user_path(file_name)
return file_name
def get_sm_symbols(sym_json_path) -> dict:
with open(sym_json_path, "r") as stream:
symbols = json.load(stream)
symboltable = {}
for name, sixdigitaddr in symbols.items():
(bank, addr_within_bank) = sixdigitaddr.split(":")
bank = int(bank, 16)
addr_within_bank = int(addr_within_bank, 16)
# categorize addresses using snes lorom mapping:
# (reference: https://en.wikibooks.org/wiki/Super_NES_Programming/SNES_memory_map)
if (bank >= 0x70 and bank <= 0x7d):
offset_within_rom_file = None
# SRAM is not continuous, but callers may want it in continuous terms
# SRAM @ data bank $70-$7D, addr_within_bank $0000-$7FFF
#
# symbol aka snes offestwithincontinuousSRAM
# --------------- --------------------------
# $70:0000-7FFF -> 0x0000- 7FFF
# $71:0000-7FFF -> 0x8000- FFFF
# $72:0000-7FFF -> 0x10000-17FFF
# etc...
offset_within_continuous_sram = (bank - 0x70) * 0x8000 + addr_within_bank
offset_within_wram = None
elif bank == 0x7e or bank == 0x7f or (bank == 0x00 and addr_within_bank <= 0x1fff):
offset_within_rom_file = None
offset_within_continuous_sram = None
offset_within_wram = addr_within_bank
if bank == 0x7f:
offset_within_wram += 0x10000
elif bank >= 0x80:
offset_within_rom_file = ((bank - 0x80) * 0x8000) + (addr_within_bank % 0x8000)
offset_within_continuous_sram = None
offset_within_wram = None
else:
offset_within_rom_file = None
offset_within_continuous_sram = None
offset_within_wram = None
symboltable[name] = {"bank": bank,
"addr_within_bank": addr_within_bank,
"offset_within_rom_file": offset_within_rom_file,
"offset_within_continuous_sram": offset_within_continuous_sram,
"offset_within_wram": offset_within_wram
}
return symboltable