import numpy as np import PIL.Image import sys X_FLIP = 0x4000 Y_FLIP = 0x8000 PAL = 0x1000 im = PIL.Image.open(sys.argv[1]) tiles = np.array(np.split(np.array(np.split(np.array(im), 28, 0)), 32, 2)) tilemapRaw = bytearray(32 * 28 * 2) tilemap = np.ndarray(shape=(28, 32), dtype='> 0) << (7 - x) tileData[1] |= ((t & 2) >> 1) << (7 - x) tileData[2] |= ((t & 4) >> 2) << (7 - x) tileData[3] |= ((t & 8) >> 3) << (7 - x) tileBase = i * 32 + y * 2 print(tileBase) chardataRaw[tileBase + 0x00] = tileData[0] chardataRaw[tileBase + 0x01] = tileData[1] chardataRaw[tileBase + 0x10] = tileData[2] chardataRaw[tileBase + 0x11] = tileData[3] def printMem(mem): for i in range(len(mem) // 16): line = mem[i * 16:(i + 1) * 16] print(', '.join([f'0x{b:02X}' for b in line]) + ',')