mirror of https://github.com/mgba-emu/mgba.git
Tools: Spit out dotcodes that mGBA can read
This commit is contained in:
parent
4bb8744cd5
commit
2e0c245e2d
|
@ -34,8 +34,6 @@ for i in range(16):
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
gg[i] = rev[gg[i]]
|
gg[i] = rev[gg[i]]
|
||||||
|
|
||||||
print(*[hex(x) for x in gg])
|
|
||||||
|
|
||||||
def interleave(data, header):
|
def interleave(data, header):
|
||||||
data = data.reshape([-1, 48]).T
|
data = data.reshape([-1, 48]).T
|
||||||
new_data = np.zeros((64, data.shape[1]), dtype=data.dtype)
|
new_data = np.zeros((64, data.shape[1]), dtype=data.dtype)
|
||||||
|
@ -88,67 +86,69 @@ def bin2raw(data):
|
||||||
new_data = interleave(np.frombuffer(data, np.uint8), header)
|
new_data = interleave(np.frombuffer(data, np.uint8), header)
|
||||||
return new_data.tobytes()
|
return new_data.tobytes()
|
||||||
|
|
||||||
with open(sys.argv[1], 'rb') as f:
|
def make_dotcode(data):
|
||||||
data = f.read()
|
|
||||||
size = len(data)
|
|
||||||
|
|
||||||
if size in (1344, 2112):
|
|
||||||
data = bin2raw(data)
|
|
||||||
size = len(data)
|
size = len(data)
|
||||||
with open('dotcode.raw', 'wb') as f:
|
|
||||||
f.write(data)
|
|
||||||
|
|
||||||
blocks = size // blocksize
|
if size in (1344, 2112):
|
||||||
height = 36
|
data = bin2raw(data)
|
||||||
width = 35
|
size = len(data)
|
||||||
margin = 2
|
|
||||||
|
|
||||||
dots = np.zeros((width * blocks + margin * 2 + 1, height + margin * 2), dtype=np.bool)
|
blocks = size // blocksize
|
||||||
anchor = np.array([[0, 1, 1, 1, 0],
|
height = 36
|
||||||
[1, 1, 1, 1, 1],
|
width = 35
|
||||||
[1, 1, 1, 1, 1],
|
margin = 2
|
||||||
[1, 1, 1, 1, 1],
|
|
||||||
[0, 1, 1, 1, 0]], dtype=np.bool)
|
|
||||||
alignment = np.array([1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0], dtype=np.bool)
|
|
||||||
nybbles = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [1, 0, 0, 1, 0],
|
|
||||||
[0, 0, 1, 0, 0], [0, 0, 1, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 1, 0],
|
|
||||||
[0, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 0],
|
|
||||||
[0, 1, 1, 0, 0], [0, 1, 1, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 0]]
|
|
||||||
addr = [0x03FF]
|
|
||||||
for i in range(1, 54):
|
|
||||||
addr.append(addr[i - 1] ^ ((i & -i) * 0x769))
|
|
||||||
if (i & 0x07) == 0:
|
|
||||||
addr[i] ^= 0x769
|
|
||||||
if (i & 0x0F) == 0:
|
|
||||||
addr[i] ^= 0x769 << 1
|
|
||||||
if (i & 0x1F) == 0:
|
|
||||||
addr[i] ^= (0x769 << 2) ^ 0x769
|
|
||||||
|
|
||||||
base = 1 if blocks == 18 else 25
|
dots = np.zeros((width * blocks + margin * 2 + 1, height + margin * 2), dtype=bool)
|
||||||
for i in range(blocks + 1):
|
anchor = np.array([[0, 1, 1, 1, 0],
|
||||||
dots[i * width:i * width + 5, 0:5] = anchor
|
[1, 1, 1, 1, 1],
|
||||||
dots[i * width:i * width + 5, height + margin * 2 - 5:height + margin * 2] = anchor
|
[1, 1, 1, 1, 1],
|
||||||
dots[i * width + margin, margin + 5] = 1
|
[1, 1, 1, 1, 1],
|
||||||
a = addr[base + i]
|
[0, 1, 1, 1, 0]], dtype=bool)
|
||||||
for j in range(16):
|
alignment = np.array([1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0], dtype=bool)
|
||||||
dots[i * width + margin, margin + 14 + j] = a & (1 << (15 - j))
|
nybbles = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [1, 0, 0, 1, 0],
|
||||||
for i in range(blocks):
|
[0, 0, 1, 0, 0], [0, 0, 1, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 1, 0],
|
||||||
dots[i * width:(i + 1) * width, margin] = alignment
|
[0, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 0],
|
||||||
dots[i * width:(i + 1) * width, height + margin - 1] = alignment
|
[0, 1, 1, 0, 0], [0, 1, 1, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 0]]
|
||||||
block = []
|
addr = [0x03FF]
|
||||||
for byte in data[i * blocksize:(i + 1) * blocksize]:
|
for i in range(1, 54):
|
||||||
block.extend(nybbles[byte >> 4])
|
addr.append(addr[i - 1] ^ ((i & -i) * 0x769))
|
||||||
block.extend(nybbles[byte & 0xF])
|
if (i & 0x07) == 0:
|
||||||
j = 0
|
addr[i] ^= 0x769
|
||||||
for y in range(3):
|
if (i & 0x0F) == 0:
|
||||||
dots[i * width + margin + 5:i * width + margin + 31, margin + 2 + y] = block[j:j + 26]
|
addr[i] ^= 0x769 << 1
|
||||||
j += 26
|
if (i & 0x1F) == 0:
|
||||||
for y in range(26):
|
addr[i] ^= (0x769 << 2) ^ 0x769
|
||||||
dots[i * width + margin + 1:i * width + margin + 35, margin + 5 + y] = block[j:j + 34]
|
|
||||||
j += 34
|
base = 1 if blocks == 18 else 25
|
||||||
for y in range(3):
|
for i in range(blocks + 1):
|
||||||
dots[i * width + margin + 5:i * width + margin + 31, margin + 31 + y] = block[j:j + 26]
|
dots[i * width:i * width + 5, 0:5] = anchor
|
||||||
j += 26
|
dots[i * width:i * width + 5, height + margin * 2 - 5:height + margin * 2] = anchor
|
||||||
im = PIL.Image.fromarray(dots.T)
|
dots[i * width + margin, margin + 5] = 1
|
||||||
|
a = addr[base + i]
|
||||||
|
for j in range(16):
|
||||||
|
dots[i * width + margin, margin + 14 + j] = a & (1 << (15 - j))
|
||||||
|
for i in range(blocks):
|
||||||
|
dots[i * width:(i + 1) * width, margin] = alignment
|
||||||
|
dots[i * width:(i + 1) * width, height + margin - 1] = alignment
|
||||||
|
block = []
|
||||||
|
for byte in data[i * blocksize:(i + 1) * blocksize]:
|
||||||
|
block.extend(nybbles[byte >> 4])
|
||||||
|
block.extend(nybbles[byte & 0xF])
|
||||||
|
j = 0
|
||||||
|
for y in range(3):
|
||||||
|
dots[i * width + margin + 5:i * width + margin + 31, margin + 2 + y] = block[j:j + 26]
|
||||||
|
j += 26
|
||||||
|
for y in range(26):
|
||||||
|
dots[i * width + margin + 1:i * width + margin + 35, margin + 5 + y] = block[j:j + 34]
|
||||||
|
j += 34
|
||||||
|
for y in range(3):
|
||||||
|
dots[i * width + margin + 5:i * width + margin + 31, margin + 31 + y] = block[j:j + 26]
|
||||||
|
j += 26
|
||||||
|
return np.pad(dots.T, 2)
|
||||||
|
|
||||||
|
with open(sys.argv[1], 'rb') as f:
|
||||||
|
dots = make_dotcode(f.read())
|
||||||
|
|
||||||
|
im = PIL.Image.fromarray(dots)
|
||||||
im = PIL.ImageChops.invert(im)
|
im = PIL.ImageChops.invert(im)
|
||||||
im.save('dotcode.png')
|
im.save('dotcode.bmp')
|
||||||
|
|
Loading…
Reference in New Issue