Optiroc / SuperFamiconv

Flexible and composable tile graphics converter supporting Super Nintendo, Game Boy, Game Boy Color, Game Boy Advance, Mega Drive, PC Engine and WonderSwan formats.
MIT License
155 stars 22 forks source link

SNES 16x16 Tile Map is incorrect #17

Closed oziphantom closed 4 years ago

oziphantom commented 4 years ago

So the SNES still does 8x8 maths on tile locations when in 16x16 mode. so if you have 16x16 tiles mapped like so in VRAM

001122334455667788
001122334455667788
99AABBCCDDEEFFGGHH
99AABBCCDDEEFFGGHH

then in the map you need to do

00020406080A0C0E
20222426282A2C2E

as a tile of 1 will get you a tile that looks like

12
12

a tile of $10 will get you

12
AB
oziphantom commented 4 years ago

For reference here a python script I wrote to "patch it"

with open(r"fileFromYourTool.map", "rb") as inputMap:
    bytes = list(inputMap.read())
    words = [bytes[i] + (bytes[i + 1]*256) for i in range(0, len(bytes), 2)] #convert hilo bytes to words
    scalledbytes = []
    for char in words:
        tile = char & 0x3FFF  # get tile number
        flags = char & 0xFC00 # preserve flags
        column = tile % 8 #get the X
        row = int(tile / 8) # get the Y, this needs to be an int other wise you get 0.5 which gets you odd numbers
        newValue = int((column*2)+(row*32)) | flags # scale x by 2 and Y by $20 and or in flags
        scalledbytes.append(newValue & 255) # convert word back to lo hi format
        scalledbytes.append(int(newValue / 256))

    with open(r"FileToUse.map", "wb") as outputMap:
        arr = bytearray(scalledbytes)
        outputMap.write(arr)
Optiroc commented 4 years ago

Oh, I was sure I had some old test case for this (before I threw them out to do automated testing, which never got done 😄). Apparently not correctly, or a regression, I suppose.

I’ll fix ASAP.

Optiroc commented 4 years ago

@oziphantom ASAP is relative, but issue should be fixed now.