From ce7aaf5c8c964e323743192922f9ca937873085a Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 1 Dec 2020 21:57:18 +0100 Subject: [PATCH 1/3] warn when data could not be sent to snes --- MultiClient.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MultiClient.py b/MultiClient.py index 3c98708c..b0d7f84c 100644 --- a/MultiClient.py +++ b/MultiClient.py @@ -638,13 +638,13 @@ async def snes_write(ctx : Context, write_list): PutAddress_Request = {"Opcode": "PutAddress", "Operands": [], 'Space': 'SNES'} try: - #will pack those requests as soon as qusb2snes actually supports that for real for address, data in write_list: PutAddress_Request['Operands'] = [hex(address)[2:], hex(len(data))[2:]] if ctx.snes_socket is not None: await ctx.snes_socket.send(json.dumps(PutAddress_Request)) - if ctx.snes_socket is not None: await ctx.snes_socket.send(data) + else: + logging.warning(f"Could not send data to SNES: {data}") except websockets.ConnectionClosed: logging.warning("Could not write data to SNES") return False @@ -655,7 +655,8 @@ async def snes_write(ctx : Context, write_list): def snes_buffered_write(ctx : Context, address, data): - if len(ctx.snes_write_buffer) > 0 and (ctx.snes_write_buffer[-1][0] + len(ctx.snes_write_buffer[-1][1])) == address: + if ctx.snes_write_buffer and (ctx.snes_write_buffer[-1][0] + len(ctx.snes_write_buffer[-1][1])) == address: + # append to existing write command, bundling them ctx.snes_write_buffer[-1] = (ctx.snes_write_buffer[-1][0], ctx.snes_write_buffer[-1][1] + data) else: ctx.snes_write_buffer.append((address, data)) @@ -665,8 +666,9 @@ async def snes_flush_writes(ctx : Context): if not ctx.snes_write_buffer: return - await snes_write(ctx, ctx.snes_write_buffer) - ctx.snes_write_buffer = [] + # swap buffers + ctx.snes_write_buffer, writes = [], ctx.snes_write_buffer + await snes_write(ctx, writes) async def send_msgs(websocket, msgs): From c31e38debed2a1a5b43d5cc01ab12437181fb90b Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 1 Dec 2020 22:23:37 +0100 Subject: [PATCH 2/3] restore fxpak special handling, as it is apparently still needed. Also slightly improve it. This reverts commit ee933698 --- MultiClient.py | 51 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/MultiClient.py b/MultiClient.py index b0d7f84c..cc1603d3 100644 --- a/MultiClient.py +++ b/MultiClient.py @@ -73,6 +73,7 @@ class Context(): self.snes_reconnect_address = None self.snes_recv_queue = asyncio.Queue() self.snes_request_lock = asyncio.Lock() + self.is_sd2snes = False self.snes_write_buffer = [] self.server_task = None @@ -521,6 +522,15 @@ async def snes_connect(ctx: Context, address): ctx.snes_attached_device = (devices.index(device), device) ctx.ui_node.send_connection_status(ctx) + if 'sd2snes' in device.lower() or 'COM' in device: + ctx.ui_node.log_info("SD2SNES/FXPAK Detected") + ctx.is_sd2snes = True + await ctx.snes_socket.send(json.dumps({"Opcode" : "Info", "Space" : "SNES"})) + reply = json.loads(await ctx.snes_socket.recv()) + if reply and 'Results' in reply: + ctx.ui_node.log_info(reply['Results']) + else: + ctx.is_sd2snes = False ctx.snes_reconnect_address = address recv_task = asyncio.create_task(snes_recv_loop(ctx)) @@ -637,17 +647,44 @@ async def snes_write(ctx : Context, write_list): PutAddress_Request = {"Opcode": "PutAddress", "Operands": [], 'Space': 'SNES'} - try: + if ctx.is_sd2snes: + cmd = b'\x00\xE2\x20\x48\xEB\x48' + for address, data in write_list: - PutAddress_Request['Operands'] = [hex(address)[2:], hex(len(data))[2:]] + if (address < WRAM_START) or ((address + len(data)) > (WRAM_START + WRAM_SIZE)): + ctx.ui_node.log_error("SD2SNES: Write out of range %s (%d)" % (hex(address), len(data))) + return False + for ptr, byte in enumerate(data, address + 0x7E0000 - WRAM_START): + cmd += b'\xA9' # LDA + cmd += bytes([byte]) + cmd += b'\x8F' # STA.l + cmd += bytes([ptr & 0xFF, (ptr >> 8) & 0xFF, (ptr >> 16) & 0xFF]) + + cmd += b'\xA9\x00\x8F\x00\x2C\x00\x68\xEB\x68\x28\x6C\xEA\xFF\x08' + + PutAddress_Request['Space'] = 'CMD' + PutAddress_Request['Operands'] = ["2C00", hex(len(cmd)-1)[2:], "2C00", "1"] + try: if ctx.snes_socket is not None: await ctx.snes_socket.send(json.dumps(PutAddress_Request)) - await ctx.snes_socket.send(data) + await ctx.snes_socket.send(cmd) else: - logging.warning(f"Could not send data to SNES: {data}") - except websockets.ConnectionClosed: - logging.warning("Could not write data to SNES") - return False + logging.warning(f"Could not send data to SNES: {cmd}") + except websockets.ConnectionClosed: + return False + else: + PutAddress_Request['Space'] = 'SNES' + try: + #will pack those requests as soon as qusb2snes actually supports that for real + for address, data in write_list: + PutAddress_Request['Operands'] = [hex(address)[2:], hex(len(data))[2:]] + if ctx.snes_socket is not None: + await ctx.snes_socket.send(json.dumps(PutAddress_Request)) + await ctx.snes_socket.send(data) + else: + logging.warning(f"Could not send data to SNES: {data}") + except websockets.ConnectionClosed: + return False return True finally: From cd081b7e0699b3013ef6520b8feced47ed42e6e7 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Wed, 2 Dec 2020 20:00:32 +0100 Subject: [PATCH 3/3] Update VC++ --- inno_setup.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inno_setup.iss b/inno_setup.iss index 675fddb7..7f8d6b7d 100644 --- a/inno_setup.iss +++ b/inno_setup.iss @@ -82,7 +82,7 @@ begin begin // Is the installed version at least the packaged one ? Log('VC Redist x64 Version : found ' + strVersion); - Result := (CompareStr(strVersion, 'v14.26.28720') < 0); + Result := (CompareStr(strVersion, 'v14.28.29325') < 0); end else begin