Skip to content

Commit 88e9fa3

Browse files
CaitSith2Jouramie
authored andcommitted
Fix root cause of ALttP hardware crashes on collect. (ArchipelagoMW#2132)
As it turns out, SD2SNES / FXPAK Pro has a limit as to how many bytes can be written in a single command packet. Exceed this limit, and the hardware will crash. That limit is 512 bytes. Even then, I have scaled back to 256 bytes at a time for a margin of safety.
1 parent 590fdf7 commit 88e9fa3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

SNIClient.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,16 @@ async def snes_write(ctx: SNIContext, write_list: typing.List[typing.Tuple[int,
565565
PutAddress_Request: SNESRequest = {"Opcode": "PutAddress", "Operands": [], 'Space': 'SNES'}
566566
try:
567567
for address, data in write_list:
568-
PutAddress_Request['Operands'] = [hex(address)[2:], hex(len(data))[2:]]
569-
# REVIEW: above: `if snes_socket is None: return False`
570-
# Does it need to be checked again?
571-
if ctx.snes_socket is not None:
572-
await ctx.snes_socket.send(dumps(PutAddress_Request))
573-
await ctx.snes_socket.send(data)
574-
else:
575-
snes_logger.warning(f"Could not send data to SNES: {data}")
568+
while data:
569+
# Divide the write into packets of 256 bytes.
570+
PutAddress_Request['Operands'] = [hex(address)[2:], hex(min(len(data), 256))[2:]]
571+
if ctx.snes_socket is not None:
572+
await ctx.snes_socket.send(dumps(PutAddress_Request))
573+
await ctx.snes_socket.send(data[:256])
574+
address += 256
575+
data = data[256:]
576+
else:
577+
snes_logger.warning(f"Could not send data to SNES: {data}")
576578
except ConnectionClosed:
577579
return False
578580

0 commit comments

Comments
 (0)