mzm/tools/oam.py

109 lines
2.5 KiB
Python

def ParsePart0(value):
result = ""
if value & 0x100:
result = "OBJ_ROTATION_SCALING"
if value & 0x200:
if result != "":
result += " | OBJ_DOUBLE_SIZE"
else:
result = "OBJ_DISABLE"
if value & 0x400:
if result != "":
result += " | "
result += "OBJ_MODE_SEMI_TRANSPARENT"
if value & 0x1000:
if result != "":
result += " | "
result += "OBJ_MOSAIC"
if value & 0x2000:
if result != "":
result += " | "
result += "OBJ_COLOR_256_1"
if value & 0x4000:
if result != "":
result += " | "
result += "OBJ_SHAPE_HORIZONTAL"
if value & 0x8000:
if result != "":
result += " | "
result += "OBJ_SHAPE_VERTICAL"
if result != "":
result += " | "
result += hex(value & 0xFF)
return result
def ParsePart1(part0, value):
result = ""
sizes = ["OBJ_SIZE_16x16", "OBJ_SIZE_32x32", "OBJ_SIZE_64x64"]
if part0.__contains__("OBJ_ROTATION_SCALING"):
result = hex(value & 0x3E00)
else:
if value & 0x1000:
result = "OBJ_X_FLIP"
if value & 0x2000:
if result != "":
result += " | "
result += "OBJ_Y_FLIP"
if part0.__contains__("OBJ_SHAPE_HORIZONTAL"):
sizes = ["OBJ_SIZE_32x8", "OBJ_SIZE_32x16", "OBJ_SIZE_64x32"]
elif part0.__contains__("OBJ_SHAPE_VERTICAL"):
sizes = ["OBJ_SIZE_8x32", "OBJ_SIZE_16x32", "OBJ_SIZE_32x64"]
if value >> 14 & 3 != 0:
if result != "":
result += " | "
result += sizes[(value >> 14 & 3) - 1]
if result != "":
result += " | "
result += hex(value & 0x1FF)
return result
def ParsePart2(value):
result = ""
if value & 0x8000:
result = "OBJ_SPRITE_OAM | "
result += hex(value & ~0x8000)
return result
file = open("../mzm_us_baserom.gba", "rb")
def Func():
inputValue = input("Address : ")
addr = int(inputValue, 16)
file.seek(addr)
part_count = int.from_bytes(file.read(2), "little")
result = hex(part_count) + ",\n"
for x in range(0, part_count):
part0 = ParsePart0(int.from_bytes(file.read(2), "little"))
result += part0 + ", "
result += ParsePart1(part0, int.from_bytes(file.read(2), "little")) + ", "
result += ParsePart2(int.from_bytes(file.read(2), "little")) + ",\n"
print(result)
Func()
Func()