Skip to content

Commit

Permalink
Criado ferramenta para reinserir os gráficos da tela de gameover na r…
Browse files Browse the repository at this point in the history
…om. #14
  • Loading branch information
hansenhahn committed Sep 2, 2018
1 parent fd2070b commit b288d53
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 89 deletions.
7 changes: 6 additions & 1 deletion asm/create_rom.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ call pack_sub.bat
cd..
copy "tool_sub\new\sub.bin" "ROM Modificada\ROCK\data\sub.bin" /B/Y

cd tool_g_over
call pack_g_over.bat
cd..
copy "tool_g_over\new\g_over.bin" "ROM Modificada\ROCK\data\g_over.bin" /B/Y

copy "tool_game_parm\new\game_parm.bin" "ROM Modificada\ROCK\data\game_parm.bin" /B/Y

rem Copia os binários commitados pelo Solid One
copy "..\graficos\face.bin" "ROM Modificada\ROCK\data\face.bin" /B/Y
copy "..\graficos\font_pal.bin" "ROM Modificada\ROCK\data\font_pal.bin" /B/Y
copy "..\graficos\g_back.bin" "ROM Modificada\ROCK\data\g_back.bin" /B/Y
copy "..\graficos\g_over.bin" "ROM Modificada\ROCK\data\g_over.bin" /B/Y
REM copy "..\graficos\g_over.bin" "ROM Modificada\ROCK\data\g_over.bin" /B/Y
copy "..\graficos\miss.bin" "ROM Modificada\ROCK\data\miss.bin" /B/Y
copy "..\graficos\repair.bin" "ROM Modificada\ROCK\data\repair.bin" /B/Y
copy "..\graficos\sec_disk.bin" "ROM Modificada\ROCK\data\sec_disk.bin" /B/Y
Expand Down
Binary file modified asm/tool_g_over/asm_g_over_000/000.bin
Binary file not shown.
Binary file added asm/tool_g_over/asm_g_over_000/000_old.bin
Binary file not shown.
Binary file not shown.
Binary file modified asm/tool_g_over/asm_g_over_001/001_000.bin
Binary file not shown.
Binary file not shown.
Binary file modified asm/tool_g_over/asm_g_over_001/001_001.bin
Binary file not shown.
Binary file not shown.
Binary file modified asm/tool_g_over/lzss.pyc
Binary file not shown.
Binary file added asm/tool_g_over/new/g_over.bin
Binary file not shown.
Binary file added asm/tool_g_over/new_g_over/000.bin
Binary file not shown.
Binary file added asm/tool_g_over/new_g_over/001.bin
Binary file not shown.
Binary file added asm/tool_g_over/new_g_over/001_descomprimido.bin
Binary file not shown.
Binary file added asm/tool_g_over/new_g_over/002.bin
Binary file not shown.
Binary file added asm/tool_g_over/new_g_over/003.bin
Binary file not shown.
Binary file added asm/tool_g_over/new_g_over/003_descomprimido.bin
Binary file not shown.
Binary file added asm/tool_g_over/new_g_over/004.bin
Binary file not shown.
4 changes: 0 additions & 4 deletions asm/tool_g_over/pack_elf.bat

This file was deleted.

4 changes: 4 additions & 0 deletions asm/tool_g_over/pack_g_over.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off

call pack_tiles.bat
python tool_g_over.py -m p -s "new_g_over" -d "new\g_over.bin"
13 changes: 7 additions & 6 deletions asm/tool_g_over/pack_tiles.bat
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@echo off

copy /B/Y "tilemap_general.bin" "tilemap_general_novo.bin"
xcopy /S/Y "old_elf" "new_elf\"
xcopy /S/Y "old_g_over" "new_g_over\"

echo "Packing 004_tileset"
echo "Packing 000_tileset"

copy /B/Y "asm_g_over_000\000_000_image.bin"+"asm_g_over_000\000_001_image.bin" "asm_g_over_000\000_tileset_full.bin"
rem concatena as imagens para criar um tileset full
pypy tool_tilemap.py -m p -s "asm_elf_004_002/002_image.bin" -d "new_elf/ptr_table_1/004/002.bin" -f "asm_elf_004_002/002_image.bin" -e 7 -c 4
pypy tool_tilemap.py -m p -s "asm_elf_004_001/001_image.bin" -d "new_elf/ptr_table_1/004/001.bin" -f "asm_elf_004_001/001_image.bin" -e 6 -c 4
pypy tool_tilemap.py -m p -s "asm_g_over_000/000_000_image.bin" -d "asm_g_over_000/000.bin" -t "asm_g_over_001\001_000.bin" -f "asm_g_over_000/000_tileset_full.bin" -e 0 -c 8
pypy tool_tilemap.py -m p -s "asm_g_over_000/000_001_image.bin" -d "asm_g_over_000/000.bin" -t "asm_g_over_001\001_001.bin" -f "asm_g_over_000/000_tileset_full.bin" -e 0 -c 8

pypy cl-comp.py -i "tilemap_general_novo.bin" -o "new_elf/ptr_table_1/005.bin" -m c -t lz10
REM pypy cl-comp.py -i "tilemap_general_novo.bin" -o "new_elf/ptr_table_1/005.bin" -m c -t lz10
180 changes: 124 additions & 56 deletions asm/tool_g_over/tool_g_over.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ def Unpack(src, dst):
fd.seek( addr_2 + 4 )
w, h = struct.unpack("<2H", fd.read(4))
size = w*h*2
od.write( fd.read( size ) )



od.write( fd.read( size ) )

# 0x00000078 -> Ponteiro pro arquivo + f.tell()
# 0x00007320 -> Tamanho do arquivo
Expand All @@ -104,68 +101,64 @@ def Unpack(src, dst):
# 0x00080000 -> ??

def Pack(src, dst):
print ">> Packing elf.bin"
print ">> Packing g_over.bin"

ptr_table_1_path = os.path.join( src, "ptr_table_1" )
if not os.path.isdir(ptr_table_1_path):
os.makedirs(ptr_table_1_path)

ptr_table_2_path = os.path.join( ptr_table_1_path, "004" )
if not os.path.isdir(ptr_table_2_path):
os.makedirs(ptr_table_2_path)

files = os.listdir(ptr_table_2_path)
splitted_files = [ f for f in files if "palette" not in f ]
splitted_pallete = [ f for f in files if "palette" in f ]

# Este arquivo importa
with open( os.path.join( ptr_table_1_path , "004.bin" ), "wb" ) as fd:

fd.seek(0x3c)
# pack 000.bin
with open( os.path.join( src , "000.bin" ), "r+b" ) as fd:
path = "asm_g_over_000"

ptr_table_2_table = []
fd.seek( 40 )

for i in range( 2 ):
with open( os.path.join( path , "%03d.bin" % i ) , "rb" ) as od:
data = od.read()

for i, f in enumerate(splitted_files):
addr = fd.tell()
fd.write( data )
link = fd.tell()

fd.seek( 20 * i )
fd.write( struct.pack("<L", (addr - fd.tell()) ) )
fd.write( struct.pack("<L", len(data)) )

fd.seek( link )

# pack 001.bin
with open( os.path.join( src , "001_descomprimido.bin" ), "r+b" ) as fd:
print os.path.join( src , "001_descomprimido.bin" )
addr_0 = struct.unpack("<L" , fd.read(4))[0]
addr_1 = struct.unpack("<L" , fd.read(4))[0]
addr_2 = struct.unpack("<L" , fd.read(4))[0]

path = "asm_g_over_001"

with open( os.path.join( path , "001_000.bin" ) , "rb" ) as od:
fd.seek( addr_0 + 8)
#w, h = struct.unpack("<2H", fd.read(4))
#size = w*h*2
fd.write( od.read() )

input = open( os.path.join(ptr_table_2_path, f), "rb" )
buff = input.read()
fd.write( buff )
input.close()
if ( fd.tell() % 4 != 0 ):
fd.write( "\x00" * (4 - (fd.tell() % 4)) )

size = len(buff)
paddr = fd.tell()
if ("%03d_palette.bin" % i) in splitted_pallete:
input = open( os.path.join(ptr_table_2_path, ("%03d_palette.bin" % i)), "rb" )
buff = input.read()
fd.write( buff )
input.close()

psize = len(buff)
else:
psize = 0

ptr_table_2_table.append( (addr, size, PTR2_MARK[i], paddr, psize) )

fd.seek(0x0)
for i, p in enumerate(ptr_table_2_table):
fd.write( struct.pack( "<L", p[0] - fd.tell() ))
fd.write( struct.pack( "<L", p[1] ))
fd.write( struct.pack( "<L", p[2] ))
fd.write( struct.pack( "<L", p[3] - fd.tell() ))
fd.write( struct.pack( "<L", p[4] | 0x00080000 | ( P[i] << 24 ) ))
with open( os.path.join( path , "001_001.bin" ) , "rb" ) as od:
fd.seek( addr_1 + 8 )
#w, h = struct.unpack("<2H", fd.read(4))
#size = w*h*2
fd.write( od.read() )

with open( os.path.join( src , "001_descomprimido.bin" ), "rb" ) as fd:
ret = lzss.compress( fd )
with open( os.path.join( src , "001.bin" ), "wb" ) as gd:
ret.tofile( gd )


with open( dst, "wb" ) as fd:
fd.write( struct.pack("<L", 0x000006) )
fd.seek( 0x20 )
fd.write( struct.pack("<L", 0x000005) )
fd.seek( 0x1c )

ptr_table_1_table = []
for i, f in enumerate(range(6)):
for i, f in enumerate(range(5)):
addr = fd.tell()

input = open( os.path.join(ptr_table_1_path, "%03d.bin" % f), "rb" )
input = open( os.path.join(src, "%03d.bin" % f), "rb" )
fd.write( input.read() )
input.close()

Expand All @@ -177,7 +170,82 @@ def Pack(src, dst):

fd.seek( 0x04 )
for i, p in enumerate(ptr_table_1_table):
fd.write( struct.pack( "<L", p | COMPRESSION_FLAG[i] ))
fd.write( struct.pack( "<L", p | COMPRESSION_FLAG[i] ))



# ptr_table_1_path = os.path.join( src, "ptr_table_1" )
# if not os.path.isdir(ptr_table_1_path):
# os.makedirs(ptr_table_1_path)

# ptr_table_2_path = os.path.join( ptr_table_1_path, "004" )
# if not os.path.isdir(ptr_table_2_path):
# os.makedirs(ptr_table_2_path)

# files = os.listdir(ptr_table_2_path)
# splitted_files = [ f for f in files if "palette" not in f ]
# splitted_pallete = [ f for f in files if "palette" in f ]

# # Este arquivo importa
# with open( os.path.join( ptr_table_1_path , "004.bin" ), "wb" ) as fd:

# fd.seek(0x3c)

# ptr_table_2_table = []

# for i, f in enumerate(splitted_files):
# addr = fd.tell()

# input = open( os.path.join(ptr_table_2_path, f), "rb" )
# buff = input.read()
# fd.write( buff )
# input.close()
# if ( fd.tell() % 4 != 0 ):
# fd.write( "\x00" * (4 - (fd.tell() % 4)) )

# size = len(buff)
# paddr = fd.tell()
# if ("%03d_palette.bin" % i) in splitted_pallete:
# input = open( os.path.join(ptr_table_2_path, ("%03d_palette.bin" % i)), "rb" )
# buff = input.read()
# fd.write( buff )
# input.close()

# psize = len(buff)
# else:
# psize = 0

# ptr_table_2_table.append( (addr, size, PTR2_MARK[i], paddr, psize) )

# fd.seek(0x0)
# for i, p in enumerate(ptr_table_2_table):
# fd.write( struct.pack( "<L", p[0] - fd.tell() ))
# fd.write( struct.pack( "<L", p[1] ))
# fd.write( struct.pack( "<L", p[2] ))
# fd.write( struct.pack( "<L", p[3] - fd.tell() ))
# fd.write( struct.pack( "<L", p[4] | 0x00080000 | ( P[i] << 24 ) ))

# with open( dst, "wb" ) as fd:
# fd.write( struct.pack("<L", 0x000006) )
# fd.seek( 0x20 )

# ptr_table_1_table = []
# for i, f in enumerate(range(6)):
# addr = fd.tell()

# input = open( os.path.join(ptr_table_1_path, "%03d.bin" % f), "rb" )
# fd.write( input.read() )
# input.close()

# if ( fd.tell() % 4 != 0 ):
# fd.write( "\x00" * (4 - (fd.tell() % 4)) )

# ptr_table_1_table.append(addr)
# ptr_table_1_table.append(fd.tell())

# fd.seek( 0x04 )
# for i, p in enumerate(ptr_table_1_table):
# fd.write( struct.pack( "<L", p | COMPRESSION_FLAG[i] ))

if __name__ == "__main__":

Expand Down
47 changes: 25 additions & 22 deletions asm/tool_g_over/tool_tilemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ def create_tilesdict( buff , codec ):
tilesdict.update({x:buff[64*x:64*(x+1)]})
return tilesdict

def reduce_tilesdict( tilesdict ):
def reduce_tilesdict( tilesdict, codec ):
offset = 0
reduced_tilesdict = dict()
for x in tilesdict:
if reduced_tilesdict.has_key(tilesdict[x]):
continue
elif reduced_tilesdict.has_key(horizontal(tilesdict[x])):
elif reduced_tilesdict.has_key(horizontal(tilesdict[x],codec)):
continue
elif reduced_tilesdict.has_key(vertical(tilesdict[x])):
elif reduced_tilesdict.has_key(vertical(tilesdict[x],codec)):
continue
elif reduced_tilesdict.has_key(diagonal(tilesdict[x])):
elif reduced_tilesdict.has_key(diagonal(tilesdict[x],codec)):
continue
else:
reduced_tilesdict.update({tilesdict[x]:offset})
Expand All @@ -72,12 +72,12 @@ def reduce_tilesdict( tilesdict ):

return ret

def EncodeImage( src, dst, full, entry, codec ):
def EncodeImage( src, dst, maps, full, entry, codec ):
# Monta o tileset a partir da imagem full (concatenação de todas as imagens)
with open( full, "rb" ) as fd :
tilesdict = create_tilesdict( fd.read() , codec )
# Simplifica o dicionário de tiles para apenas tiles únicos
reduced_td = reduce_tilesdict(tilesdict)
reduced_td = reduce_tilesdict(tilesdict, codec)

# Monta o tileset
tileset = array.array("c")
Expand All @@ -96,30 +96,33 @@ def EncodeImage( src, dst, full, entry, codec ):
for i in range(len(tilesdict)):
if tilesdict[i] in val:
tilemap.append( 0x0000 | val.index(tilesdict[i]))
elif horizontal(tilesdict[i]) in val:
tilemap.append( 0x0400 | val.index(horizontal(tilesdict[i])))
elif vertical(tilesdict[i]) in val:
tilemap.append( 0x0800 | val.index(vertical(tilesdict[i])))
elif diagonal(tilesdict[i]) in val:
tilemap.append( 0x0C00 | val.index(diagonal(tilesdict[i])))
elif horizontal(tilesdict[i], codec) in val:
tilemap.append( 0x0400 | val.index(horizontal(tilesdict[i], codec)))
elif vertical(tilesdict[i], codec) in val:
tilemap.append( 0x0800 | val.index(vertical(tilesdict[i], codec)))
elif diagonal(tilesdict[i], codec) in val:
tilemap.append( 0x0C00 | val.index(diagonal(tilesdict[i], codec)))
else:
raise Exception
sys.exit(1)

# Atualiza o tilemap
with open("tilemap_general_novo.bin", "r+b") as fd:
fd.seek( 4 * entry )
addr, next = struct.unpack( "<LL", fd.read(8) )
size = (next - addr)/2 -4
fd.seek( addr + 8 )
with open(maps, "wb") as fd:
# fd.seek( 4 * entry )
# addr, next = struct.unpack( "<LL", fd.read(8) )
# size = (next - addr)/2 -4
# fd.seek( addr + 8 )

size = 0x20*0x20

palette = []
for i in range(size):
palette.append(struct.unpack("<H", fd.read(2))[0] & 0xF000)
# palette = []
# for i in range(size):
# palette.append(struct.unpack("<H", fd.read(2))[0] & 0xF000)

fd.seek( addr+8)
# fd.seek( addr+8)
for i in range(size):
fd.write(struct.pack("<H", palette[i] | tilemap[i]))
#fd.write(struct.pack("<H", palette[i] | tilemap[i]))
fd.write(struct.pack("<H", tilemap[i]))

def DecodeImage( src, dst, map, entry, codec ):

Expand Down

0 comments on commit b288d53

Please sign in to comment.