Skip to content

Instantly share code, notes, and snippets.

@tjanas
Created May 25, 2021 15:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjanas/8495647a0c80f34ec131fdb438e296cb to your computer and use it in GitHub Desktop.
Save tjanas/8495647a0c80f34ec131fdb438e296cb to your computer and use it in GitHub Desktop.
Super Nt JB / SD2SNES: convert no-intro SNES Enhancement Chips
#!/usr/bin/env python3
import os, sys
import hashlib
# DSP1/2/3/4 file: 8192 bytes
# Program (6144 bytes, 24-bit words) + Data (2048 bytes, 16-bit words)
# Reverses word byte ordering
def create_dsp(source_filename, dest_filename, source_checksum):
source_file = None
try:
source_file = open(source_filename, "rb")
except:
pass
if source_file:
readBytes = source_file.read(8192)
source_file.close()
if readBytes:
hasher = hashlib.sha1()
hasher.update(readBytes)
if hasher.hexdigest() == source_checksum:
dest_buf = bytearray(8192)
for x in range(2048): # 2048 words of 24-bits = 6144 bytes
dest_buf[x*3 + 0] = readBytes[x*3 + 2]
dest_buf[x*3 + 1] = readBytes[x*3 + 1]
dest_buf[x*3 + 2] = readBytes[x*3 + 0]
for x in range(1024): # 1024 words of 16-bits = 2048 bytes
dest_buf[6144 + x*2 + 0] = readBytes[6144 + x*2 + 1]
dest_buf[6144 + x*2 + 1] = readBytes[6144 + x*2 + 0]
with open(dest_filename, "wb") as dest_file:
dest_file.write(dest_buf)
print('Wrote ' + dest_filename)
dest_file.close()
else:
print(source_filename + ": unexpected checksum")
# ST010/ST011 file: 53248 bytes
# Program (49152 bytes, 24-bit words) + Data (4096 bytes, 16-bit words)
# Reverses word byte ordering
def create_st(source_filename, dest_filename, source_checksum):
source_file = None
try:
source_file = open(source_filename, "rb")
except:
pass
if source_file:
readBytes = source_file.read(53248)
source_file.close()
if readBytes:
hasher = hashlib.sha1()
hasher.update(readBytes)
if hasher.hexdigest() == source_checksum:
dest_buf = bytearray(53248)
for x in range(16384): # 16384 words of 24-bits = 49152 bytes
dest_buf[x*3 + 0] = readBytes[x*3 + 2]
dest_buf[x*3 + 1] = readBytes[x*3 + 1]
dest_buf[x*3 + 2] = readBytes[x*3 + 0]
for x in range(2048): # 2048 words of 16-bits = 4096 bytes
dest_buf[49152 + x*2 + 0] = readBytes[49152 + x*2 + 1]
dest_buf[49152 + x*2 + 1] = readBytes[49152 + x*2 + 0]
with open(dest_filename, "wb") as dest_file:
dest_file.write(dest_buf)
print('Wrote ' + dest_filename)
dest_file.close()
else:
print(source_filename + ": unexpected checksum")
create_dsp('DSP1 (World) (Enhancement Chip).bin', 'dsp1.bin', '188d471fefea71eb53f0ee7064697ff0971b1014') # -> CRC32: 27124599
create_dsp('DSP1 B (World) (Enhancement Chip).bin', 'dsp1b.bin', '78b724811f5f18d8c67669d9390397eb1a47a5e2') # -> CRC32: 588279B4
create_dsp('DSP2 (World) (Enhancement Chip).bin', 'dsp2.bin', '198c4b1c3bfc6d69e734c5957af3dbfa26238dfb') # -> CRC32: F0221C90
create_dsp('DSP3 (Japan) (Enhancement Chip).bin', 'dsp3.bin', '558da7cb3bd3876a6ca693661ffc6c110e948cf9') # -> CRC32: E3B54E6A
create_dsp('DSP4 (World) (Enhancement Chip).bin', 'dsp4.bin', 'af6478aecb6f1b67177e79c82ca04c56250a8c72') # -> CRC32: CA09E176
create_st('ST010 (Japan, USA) (Enhancement Chip).bin', 'st0010.bin', '6472828403de3589433a906e2c3f3d274c0ff008') # -> CRC32: 8D136190
create_st('ST011 (Japan) (Enhancement Chip).bin', 'st0011.bin', 'fecbae2cec76c710422486baa186ffa7ca1cf925') # -> CRC32: 750C6012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment