Created
August 2, 2016 22:21
-
-
Save spiiin/3635525e6846d4eaf33d7eafb5a6673f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from find_blocks import * | |
start2x2hMacro = (0,1,16,17) | |
MACROBLOCKS_SIZE = NAME_TABLE_SIZE / 4 | |
#считывание данных о блоках 1-го уровня, расположенных в SoA-формате | |
def grouper(n, iterable, padvalue=None): | |
"grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')" | |
return list(izip_longest(*[iter(iterable)]*n, fillvalue=padvalue)) | |
def readFromAlignedArrays(romdata, addrs, blocksCount): | |
return grouper(4, [romdata[addr+x] for x in xrange(blocksCount) for addr in addrs]) | |
def readBlocksDwd(d): | |
return readFromAlignedArrays(d, [0x3AF0,0x3BF0,0x3CF0,0x3DF0] , 256) | |
#считывание экранных блоков из дампа PPU | |
def readScreenBlocksDwd(l): | |
tiles = l[NAME_TABLE_ADDR_1 : NAME_TABLE_ADDR_1+NAME_TABLE_SIZE] | |
return getAllScreenBlocks(start2x2h, tiles, BLOCK_SIZE_ENUM_2x2) | |
#ремаппинг индексов | |
def remap(screenBlocks, blocks): | |
ans = [] | |
for sb in screenBlocks: | |
try: | |
ans.append(chr(blocks.index(sb))) | |
except: | |
ans.append(chr(255)) | |
return ans | |
def macroBlocksDarkwingDuck(): | |
romName = "Darkwing Duck (U) [!].nes") | |
dataName = romName.replace(".nes", "_ppu1.bin") | |
with open(romName, "rb") as f: | |
d = f.read() | |
with open(dataName, "rb") as f: | |
l = f.read() | |
blocks = readBlocksDwd(d) | |
screenBlocks = readScreenBlocksDwd(l) | |
#делаем ремап индексов тайлов на индексы блоков | |
macroTiles = remap(screenBlocks, blocks) | |
#главная фишка - ищем макроблоки тем же способом, что и обычные блоки (отличается только размеры) | |
macroBlocks = getBlocks(start2x2hMacro, macroTiles, 0, rowLenInBytes = 32, nameTableSize = MACROBLOCKS_SIZE) | |
found = findBlocksInRom(macroBlocks, d, escapeRe, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment