insertion code for $08 text script asm

hg-commit-id: 5668ca41238c
This commit is contained in:
Bryan Bishop 2012-01-09 22:24:04 -06:00
parent 6ee0c38b35
commit 52e723ae65
4 changed files with 620 additions and 529 deletions

View file

@ -203,6 +203,11 @@ def parse_text_script(text_pointer, text_id, map_id, txfar=False):
#07 = shift texts 1 row above (2nd line becomes 1st line); address for next text = 2nd line. [07] #07 = shift texts 1 row above (2nd line becomes 1st line); address for next text = 2nd line. [07]
command = {"type": command_byte, "start_address": offset, "end_address": offset} command = {"type": command_byte, "start_address": offset, "end_address": offset}
offset += 1 offset += 1
elif command_byte == 0x8:
#08 = asm until whenever
command = {"type": command_byte, "start_address": offset, "end_address": offset}
offset += 1
end = True
elif command_byte == 0x9: elif command_byte == 0x9:
#09 = write hex-to-dec number from RAM to textbox [09][2-byte RAM address][byte bbbbcccc] #09 = write hex-to-dec number from RAM to textbox [09][2-byte RAM address][byte bbbbcccc]
# bbbb = how many bytes to read (read number is big-endian) # bbbb = how many bytes to read (read number is big-endian)
@ -303,8 +308,6 @@ def parse_text_script(text_pointer, text_id, map_id, txfar=False):
#FF = change music to a specific song that i don't know the name of #FF = change music to a specific song that i don't know the name of
command = {"type": command_byte, "start_address": offset, "end_address": offset} command = {"type": command_byte, "start_address": offset, "end_address": offset}
offset += 1 offset += 1
elif command_byte == 0x8: #not ready to process asm
end = True
else: else:
#if len(commands) > 0: #if len(commands) > 0:
# print "Unknown text command " + hex(command_byte) + " at " + hex(offset) + ", script began with " + hex(commands[0]["type"]) # print "Unknown text command " + hex(command_byte) + " at " + hex(offset) + ", script began with " + hex(commands[0]["type"])

View file

@ -23,12 +23,12 @@ temp_opt_table = [
[ "ADD E", 0x83, 0 ], [ "ADD E", 0x83, 0 ],
[ "ADD H", 0x84, 0 ], [ "ADD H", 0x84, 0 ],
[ "ADD [HL]", 0x86, 0 ], [ "ADD [HL]", 0x86, 0 ],
[ "ADD HL,BC", 0x9, 0 ], [ "ADD HL, BC", 0x9, 0 ],
[ "ADD HL,DE", 0x19, 0 ], [ "ADD HL, DE", 0x19, 0 ],
[ "ADD HL,HL", 0x29, 0 ], [ "ADD HL, HL", 0x29, 0 ],
[ "ADD HL,SP", 0x39, 0 ], [ "ADD HL, SP", 0x39, 0 ],
[ "ADD L", 0x85, 0 ], [ "ADD L", 0x85, 0 ],
[ "ADD SP,x", 0xe8, 1 ], [ "ADD SP, x", 0xe8, 1 ],
[ "ADD x", 0xc6, 1 ], [ "ADD x", 0xc6, 1 ],
[ "AND A", 0xa7, 0 ], [ "AND A", 0xa7, 0 ],
[ "AND B", 0xa0, 0 ], [ "AND B", 0xa0, 0 ],
@ -39,74 +39,74 @@ temp_opt_table = [
[ "AND [HL]", 0xa6, 0 ], [ "AND [HL]", 0xa6, 0 ],
[ "AND L", 0xa5, 0 ], [ "AND L", 0xa5, 0 ],
[ "AND x", 0xe6, 1 ], [ "AND x", 0xe6, 1 ],
[ "BIT 0,A", 0x47cb, 3 ], [ "BIT 0, A", 0x47cb, 3 ],
[ "BIT 0,B", 0x40cb, 3 ], [ "BIT 0, B", 0x40cb, 3 ],
[ "BIT 0,C", 0x41cb, 3 ], [ "BIT 0, C", 0x41cb, 3 ],
[ "BIT 0,D", 0x42cb, 3 ], [ "BIT 0, D", 0x42cb, 3 ],
[ "BIT 0,E", 0x43cb, 3 ], [ "BIT 0, E", 0x43cb, 3 ],
[ "BIT 0,H", 0x44cb, 3 ], [ "BIT 0, H", 0x44cb, 3 ],
[ "BIT 0, [HL]", 0x46cb, 3 ], [ "BIT 0, [HL]", 0x46cb, 3 ],
[ "BIT 0,L", 0x45cb, 3 ], [ "BIT 0, L", 0x45cb, 3 ],
[ "BIT 1,A", 0x4fcb, 3 ], [ "BIT 1, A", 0x4fcb, 3 ],
[ "BIT 1,B", 0x48cb, 3 ], [ "BIT 1, B", 0x48cb, 3 ],
[ "BIT 1,C", 0x49cb, 3 ], [ "BIT 1, C", 0x49cb, 3 ],
[ "BIT 1,D", 0x4acb, 3 ], [ "BIT 1, D", 0x4acb, 3 ],
[ "BIT 1,E", 0x4bcb, 3 ], [ "BIT 1, E", 0x4bcb, 3 ],
[ "BIT 1,H", 0x4ccb, 3 ], [ "BIT 1, H", 0x4ccb, 3 ],
[ "BIT 1, [HL]", 0x4ecb, 3 ], [ "BIT 1, [HL]", 0x4ecb, 3 ],
[ "BIT 1,L", 0x4dcb, 3 ], [ "BIT 1, L", 0x4dcb, 3 ],
[ "BIT 2,A", 0x57cb, 3 ], [ "BIT 2, A", 0x57cb, 3 ],
[ "BIT 2,B", 0x50cb, 3 ], [ "BIT 2, B", 0x50cb, 3 ],
[ "BIT 2,C", 0x51cb, 3 ], [ "BIT 2, C", 0x51cb, 3 ],
[ "BIT 2,D", 0x52cb, 3 ], [ "BIT 2, D", 0x52cb, 3 ],
[ "BIT 2,E", 0x53cb, 3 ], [ "BIT 2, E", 0x53cb, 3 ],
[ "BIT 2,H", 0x54cb, 3 ], [ "BIT 2, H", 0x54cb, 3 ],
[ "BIT 2, [HL]", 0x56cb, 3 ], [ "BIT 2, [HL]", 0x56cb, 3 ],
[ "BIT 2,L", 0x55cb, 3 ], [ "BIT 2, L", 0x55cb, 3 ],
[ "BIT 3,A", 0x5fcb, 3 ], [ "BIT 3, A", 0x5fcb, 3 ],
[ "BIT 3,B", 0x58cb, 3 ], [ "BIT 3, B", 0x58cb, 3 ],
[ "BIT 3,C", 0x59cb, 3 ], [ "BIT 3, C", 0x59cb, 3 ],
[ "BIT 3,D", 0x5acb, 3 ], [ "BIT 3, D", 0x5acb, 3 ],
[ "BIT 3,E", 0x5bcb, 3 ], [ "BIT 3, E", 0x5bcb, 3 ],
[ "BIT 3,H", 0x5ccb, 3 ], [ "BIT 3, H", 0x5ccb, 3 ],
[ "BIT 3, [HL]", 0x5ecb, 3 ], [ "BIT 3, [HL]", 0x5ecb, 3 ],
[ "BIT 3,L", 0x5dcb, 3 ], [ "BIT 3, L", 0x5dcb, 3 ],
[ "BIT 4,A", 0x67cb, 3 ], [ "BIT 4, A", 0x67cb, 3 ],
[ "BIT 4,B", 0x60cb, 3 ], [ "BIT 4, B", 0x60cb, 3 ],
[ "BIT 4,C", 0x61cb, 3 ], [ "BIT 4, C", 0x61cb, 3 ],
[ "BIT 4,D", 0x62cb, 3 ], [ "BIT 4, D", 0x62cb, 3 ],
[ "BIT 4,E", 0x63cb, 3 ], [ "BIT 4, E", 0x63cb, 3 ],
[ "BIT 4,H", 0x64cb, 3 ], [ "BIT 4, H", 0x64cb, 3 ],
[ "BIT 4, [HL]", 0x66cb, 3 ], [ "BIT 4, [HL]", 0x66cb, 3 ],
[ "BIT 4,L", 0x65cb, 3 ], [ "BIT 4, L", 0x65cb, 3 ],
[ "BIT 5,A", 0x6fcb, 3 ], [ "BIT 5, A", 0x6fcb, 3 ],
[ "BIT 5,B", 0x68cb, 3 ], [ "BIT 5, B", 0x68cb, 3 ],
[ "BIT 5,C", 0x69cb, 3 ], [ "BIT 5, C", 0x69cb, 3 ],
[ "BIT 5,D", 0x6acb, 3 ], [ "BIT 5, D", 0x6acb, 3 ],
[ "BIT 5,E", 0x6bcb, 3 ], [ "BIT 5, E", 0x6bcb, 3 ],
[ "BIT 5,H", 0x6ccb, 3 ], [ "BIT 5, H", 0x6ccb, 3 ],
[ "BIT 5, [HL]", 0x6ecb, 3 ], [ "BIT 5, [HL]", 0x6ecb, 3 ],
[ "BIT 5,L", 0x6dcb, 3 ], [ "BIT 5, L", 0x6dcb, 3 ],
[ "BIT 6,A", 0x77cb, 3 ], [ "BIT 6, A", 0x77cb, 3 ],
[ "BIT 6,B", 0x70cb, 3 ], [ "BIT 6, B", 0x70cb, 3 ],
[ "BIT 6,C", 0x71cb, 3 ], [ "BIT 6, C", 0x71cb, 3 ],
[ "BIT 6,D", 0x72cb, 3 ], [ "BIT 6, D", 0x72cb, 3 ],
[ "BIT 6,E", 0x73cb, 3 ], [ "BIT 6, E", 0x73cb, 3 ],
[ "BIT 6,H", 0x74cb, 3 ], [ "BIT 6, H", 0x74cb, 3 ],
[ "BIT 6, [HL]", 0x76cb, 3 ], [ "BIT 6, [HL]", 0x76cb, 3 ],
[ "BIT 6,L", 0x75cb, 3 ], [ "BIT 6, L", 0x75cb, 3 ],
[ "BIT 7,A", 0x7fcb, 3 ], [ "BIT 7, A", 0x7fcb, 3 ],
[ "BIT 7,B", 0x78cb, 3 ], [ "BIT 7, B", 0x78cb, 3 ],
[ "BIT 7,C", 0x79cb, 3 ], [ "BIT 7, C", 0x79cb, 3 ],
[ "BIT 7,D", 0x7acb, 3 ], [ "BIT 7, D", 0x7acb, 3 ],
[ "BIT 7,E", 0x7bcb, 3 ], [ "BIT 7, E", 0x7bcb, 3 ],
[ "BIT 7,H", 0x7ccb, 3 ], [ "BIT 7, H", 0x7ccb, 3 ],
[ "BIT 7, [HL]", 0x7ecb, 3 ], [ "BIT 7, [HL]", 0x7ecb, 3 ],
[ "BIT 7,L", 0x7dcb, 3 ], [ "BIT 7, L", 0x7dcb, 3 ],
[ "CALL C,?", 0xdc, 2 ], [ "CALL C, ?", 0xdc, 2 ],
[ "CALL NC,?", 0xd4, 2 ], [ "CALL NC, ?", 0xd4, 2 ],
[ "CALL NZ,?", 0xc4, 2 ], [ "CALL NZ, ?", 0xc4, 2 ],
[ "CALL Z,?", 0xcc, 2 ], [ "CALL Z, ?", 0xcc, 2 ],
[ "CALL ?", 0xcd, 2 ], [ "CALL ?", 0xcd, 2 ],
[ "CCF", 0x3f, 0 ], [ "CCF", 0x3f, 0 ],
[ "CP A", 0xbf, 0 ], [ "CP A", 0xbf, 0 ],
@ -148,24 +148,24 @@ temp_opt_table = [
[ "INC [HL]", 0x34, 0 ], [ "INC [HL]", 0x34, 0 ],
[ "INC L", 0x2c, 0 ], [ "INC L", 0x2c, 0 ],
[ "INC SP", 0x33, 0 ], [ "INC SP", 0x33, 0 ],
[ "JP C,?", 0xda, 2 ], [ "JP C, ?", 0xda, 2 ],
[ "JP HL", 0xe9, 0 ], [ "JP HL", 0xe9, 0 ],
[ "JP NC,?", 0xd2, 2 ], [ "JP NC, ?", 0xd2, 2 ],
[ "JP NZ,?", 0xc2, 2 ], [ "JP NZ, ?", 0xc2, 2 ],
[ "JP Z,?", 0xca, 2 ], [ "JP Z, ?", 0xca, 2 ],
[ "JP ?", 0xc3, 2 ], [ "JP ?", 0xc3, 2 ],
[ "JR C,x", 0x38, 1 ], [ "JR C, x", 0x38, 1 ],
[ "JR NC,x", 0x30, 1 ], [ "JR NC, x", 0x30, 1 ],
[ "JR NZ,x", 0x20, 1 ], [ "JR NZ, x", 0x20, 1 ],
[ "JR Z,x", 0x28, 1 ], [ "JR Z, x", 0x28, 1 ],
[ "JR x", 0x18, 1 ], [ "JR x", 0x18, 1 ],
[ "LD A,A", 0x7f, 0 ], [ "LD A, A", 0x7f, 0 ],
[ "LD A,B", 0x78, 0 ], [ "LD A, B", 0x78, 0 ],
[ "LD A,C", 0x79, 0 ], [ "LD A, C", 0x79, 0 ],
[ "LD A,D", 0x7a, 0 ], [ "LD A, D", 0x7a, 0 ],
[ "LD A,E", 0x7b, 0 ], [ "LD A, E", 0x7b, 0 ],
[ "LD A,H", 0x7c, 0 ], [ "LD A, H", 0x7c, 0 ],
[ "LD A,L", 0x7d, 0 ], [ "LD A, L", 0x7d, 0 ],
[ "LD A, [$FF00+C]", 0xf2, 0 ], [ "LD A, [$FF00+C]", 0xf2, 0 ],
[ "LD A, [$FF00+x]", 0xf0, 1 ], [ "LD A, [$FF00+x]", 0xf0, 1 ],
[ "LD A, [BC]", 0xa, 0 ], [ "LD A, [BC]", 0xa, 0 ],
@ -176,92 +176,92 @@ temp_opt_table = [
[ "LD A, [HLD]", 0x3a, 0 ], [ "LD A, [HLD]", 0x3a, 0 ],
[ "LD A, [HLI]", 0x2a, 0 ], [ "LD A, [HLI]", 0x2a, 0 ],
[ "LD A, [?]", 0xfa, 2 ], [ "LD A, [?]", 0xfa, 2 ],
[ "LD A,x", 0x3e, 1 ], [ "LD A, x", 0x3e, 1 ],
[ "LD B,A", 0x47, 0 ], [ "LD B, A", 0x47, 0 ],
[ "LD B,B", 0x40, 0 ], [ "LD B, B", 0x40, 0 ],
[ "LD B,C", 0x41, 0 ], [ "LD B, C", 0x41, 0 ],
[ "LD [BC],A", 0x2, 0 ], [ "LD [BC], A", 0x2, 0 ],
[ "LD B,D", 0x42, 0 ], [ "LD B, D", 0x42, 0 ],
[ "LD B,E", 0x43, 0 ], [ "LD B, E", 0x43, 0 ],
[ "LD B,H", 0x44, 0 ], [ "LD B, H", 0x44, 0 ],
[ "LD B, [HL]", 0x46, 0 ], [ "LD B, [HL]", 0x46, 0 ],
[ "LD B,L", 0x45, 0 ], [ "LD B, L", 0x45, 0 ],
[ "LD B,x", 0x6, 1 ], [ "LD B, x", 0x6, 1 ],
[ "LD C,A", 0x4f, 0 ], [ "LD C, A", 0x4f, 0 ],
[ "LD C,B", 0x48, 0 ], [ "LD C, B", 0x48, 0 ],
[ "LD C,C", 0x49, 0 ], [ "LD C, C", 0x49, 0 ],
[ "LD C,D", 0x4a, 0 ], [ "LD C, D", 0x4a, 0 ],
[ "LD C,E", 0x4b, 0 ], [ "LD C, E", 0x4b, 0 ],
[ "LD C,H", 0x4c, 0 ], [ "LD C, H", 0x4c, 0 ],
[ "LD C, [HL]", 0x4e, 0 ], [ "LD C, [HL]", 0x4e, 0 ],
[ "LD C,L", 0x4d, 0 ], [ "LD C, L", 0x4d, 0 ],
[ "LD C,x", 0xe, 1 ], [ "LD C, x", 0xe, 1 ],
[ "LD D,A", 0x57, 0 ], [ "LD D, A", 0x57, 0 ],
[ "LDD A, [HL]", 0x3a, 0 ], [ "LDD A, [HL]", 0x3a, 0 ],
[ "LD D,B", 0x50, 0 ], [ "LD D, B", 0x50, 0 ],
[ "LD D,C", 0x51, 0 ], [ "LD D, C", 0x51, 0 ],
[ "LD D,D", 0x52, 0 ], [ "LD D, D", 0x52, 0 ],
[ "LD D,E", 0x53, 0 ], [ "LD D, E", 0x53, 0 ],
[ "LD [DE],A", 0x12, 0 ], [ "LD [DE], A", 0x12, 0 ],
[ "LD D,H", 0x54, 0 ], [ "LD D, H", 0x54, 0 ],
[ "LD D, [HL]", 0x56, 0 ], [ "LD D, [HL]", 0x56, 0 ],
[ "LDD [HL],A", 0x32, 0 ], [ "LDD [HL], A", 0x32, 0 ],
[ "LD D,L", 0x55, 0 ], [ "LD D, L", 0x55, 0 ],
[ "LD D,x", 0x16, 1 ], [ "LD D, x", 0x16, 1 ],
[ "LD E,A", 0x5f, 0 ], [ "LD E, A", 0x5f, 0 ],
[ "LD E,B", 0x58, 0 ], [ "LD E, B", 0x58, 0 ],
[ "LD E,C", 0x59, 0 ], [ "LD E, C", 0x59, 0 ],
[ "LD E,D", 0x5a, 0 ], [ "LD E, D", 0x5a, 0 ],
[ "LD E,E", 0x5b, 0 ], [ "LD E, E", 0x5b, 0 ],
[ "LD E,H", 0x5c, 0 ], [ "LD E, H", 0x5c, 0 ],
[ "LD E, [HL]", 0x5e, 0 ], [ "LD E, [HL]", 0x5e, 0 ],
[ "LD E,L", 0x5d, 0 ], [ "LD E, L", 0x5d, 0 ],
[ "LD E,x", 0x1e, 1 ], [ "LD E, x", 0x1e, 1 ],
[ "LD [$FF00+C],A", 0xe2, 0 ], [ "LD [$FF00+C], A", 0xe2, 0 ],
[ "LD [$FF00+x],A", 0xe0, 1 ], [ "LD [$FF00+x], A", 0xe0, 1 ],
[ "LD H,A", 0x67, 0 ], [ "LD H, A", 0x67, 0 ],
[ "LDH A, [x]", 0xf0, 1 ], [ "LDH A, [x]", 0xf0, 1 ],
[ "LD H,B", 0x60, 0 ], [ "LD H, B", 0x60, 0 ],
[ "LD H,C", 0x61, 0 ], [ "LD H, C", 0x61, 0 ],
[ "LD H,D", 0x62, 0 ], [ "LD H, D", 0x62, 0 ],
[ "LD H,E", 0x63, 0 ], [ "LD H, E", 0x63, 0 ],
[ "LD H,H", 0x64, 0 ], [ "LD H, H", 0x64, 0 ],
[ "LD H, [HL]", 0x66, 0 ], [ "LD H, [HL]", 0x66, 0 ],
[ "LD H,L", 0x65, 0 ], [ "LD H, L", 0x65, 0 ],
[ "LD [HL+],A", 0x22, 0 ], [ "LD [HL+], A", 0x22, 0 ],
[ "LD [HL-],A", 0x32, 0 ], [ "LD [HL-], A", 0x32, 0 ],
[ "LD [HL],A", 0x77, 0 ], [ "LD [HL], A", 0x77, 0 ],
[ "LD [HL],B", 0x70, 0 ], [ "LD [HL], B", 0x70, 0 ],
[ "LD [HL],C", 0x71, 0 ], [ "LD [HL], C", 0x71, 0 ],
[ "LD [HL],D", 0x72, 0 ], [ "LD [HL], D", 0x72, 0 ],
[ "LD [HLD],A", 0x32, 0 ], [ "LD [HLD], A", 0x32, 0 ],
[ "LD [HL],E", 0x73, 0 ], [ "LD [HL], E", 0x73, 0 ],
[ "LD [HL],H", 0x74, 0 ], [ "LD [HL], H", 0x74, 0 ],
[ "LD [HLI],A", 0x22, 0 ], [ "LD [HLI], A", 0x22, 0 ],
[ "LD [HL],L", 0x75, 0 ], [ "LD [HL], L", 0x75, 0 ],
[ "LD HL,SP+x", 0xf8, 1 ], [ "LD HL, SP+x", 0xf8, 1 ],
[ "LD [HL],x", 0x36, 1 ], [ "LD [HL], x", 0x36, 1 ],
[ "LD H,x", 0x26, 1 ], [ "LD H, x", 0x26, 1 ],
[ "LDH [x],A", 0xe0, 1 ], [ "LDH [x], A", 0xe0, 1 ],
[ "LDI A, [HL]", 0x2a, 0 ], [ "LDI A, [HL]", 0x2a, 0 ],
[ "LDI [HL],A", 0x22, 0 ], [ "LDI [HL], A", 0x22, 0 ],
[ "LD L,A", 0x6f, 0 ], [ "LD L, A", 0x6f, 0 ],
[ "LD L,B", 0x68, 0 ], [ "LD L, B", 0x68, 0 ],
[ "LD L,C", 0x69, 0 ], [ "LD L, C", 0x69, 0 ],
[ "LD L,D", 0x6a, 0 ], [ "LD L, D", 0x6a, 0 ],
[ "LD L,E", 0x6b, 0 ], [ "LD L, E", 0x6b, 0 ],
[ "LD L,H", 0x6c, 0 ], [ "LD L, H", 0x6c, 0 ],
[ "LD L, [HL]", 0x6e, 0 ], [ "LD L, [HL]", 0x6e, 0 ],
[ "LD L,L", 0x6d, 0 ], [ "LD L, L", 0x6d, 0 ],
[ "LD L,x", 0x2e, 1 ], [ "LD L, x", 0x2e, 1 ],
[ "LD PC,HL", 0xe9, 0 ], [ "LD PC, HL", 0xe9, 0 ],
[ "LD SP,HL", 0xf9, 0 ], [ "LD SP, HL", 0xf9, 0 ],
[ "LD BC,?", 0x1, 2 ], [ "LD BC, ?", 0x1, 2 ],
[ "LD DE,?", 0x11, 2 ], [ "LD DE, ?", 0x11, 2 ],
[ "LD HL,?", 0x21, 2 ], [ "LD HL, ?", 0x21, 2 ],
[ "LD SP,?", 0x31, 2 ], [ "LD SP, ?", 0x31, 2 ],
[ "LD [?],SP", 0x8, 2 ], [ "LD [?], SP", 0x8, 2 ],
[ "LD [?],A", 0xea, 2 ], [ "LD [?], A", 0xea, 2 ],
[ "NOP", 0x0, 0 ], [ "NOP", 0x0, 0 ],
[ "OR A", 0xb7, 0 ], [ "OR A", 0xb7, 0 ],
[ "OR B", 0xb0, 0 ], [ "OR B", 0xb0, 0 ],
@ -280,70 +280,70 @@ temp_opt_table = [
[ "PUSH BC", 0xc5, 0 ], [ "PUSH BC", 0xc5, 0 ],
[ "PUSH DE", 0xd5, 0 ], [ "PUSH DE", 0xd5, 0 ],
[ "PUSH HL", 0xe5, 0 ], [ "PUSH HL", 0xe5, 0 ],
[ "RES 0,A", 0x87cb, 3 ], [ "RES 0, A", 0x87cb, 3 ],
[ "RES 0,B", 0x80cb, 3 ], [ "RES 0, B", 0x80cb, 3 ],
[ "RES 0,C", 0x81cb, 3 ], [ "RES 0, C", 0x81cb, 3 ],
[ "RES 0,D", 0x82cb, 3 ], [ "RES 0, D", 0x82cb, 3 ],
[ "RES 0,E", 0x83cb, 3 ], [ "RES 0, E", 0x83cb, 3 ],
[ "RES 0,H", 0x84cb, 3 ], [ "RES 0, H", 0x84cb, 3 ],
[ "RES 0, [HL]", 0x86cb, 3 ], [ "RES 0, [HL]", 0x86cb, 3 ],
[ "RES 0,L", 0x85cb, 3 ], [ "RES 0, L", 0x85cb, 3 ],
[ "RES 1,A", 0x8fcb, 3 ], [ "RES 1, A", 0x8fcb, 3 ],
[ "RES 1,B", 0x88cb, 3 ], [ "RES 1, B", 0x88cb, 3 ],
[ "RES 1,C", 0x89cb, 3 ], [ "RES 1, C", 0x89cb, 3 ],
[ "RES 1,D", 0x8acb, 3 ], [ "RES 1, D", 0x8acb, 3 ],
[ "RES 1,E", 0x8bcb, 3 ], [ "RES 1, E", 0x8bcb, 3 ],
[ "RES 1,H", 0x8ccb, 3 ], [ "RES 1, H", 0x8ccb, 3 ],
[ "RES 1, [HL]", 0x8ecb, 3 ], [ "RES 1, [HL]", 0x8ecb, 3 ],
[ "RES 1,L", 0x8dcb, 3 ], [ "RES 1, L", 0x8dcb, 3 ],
[ "RES 2,A", 0x97cb, 3 ], [ "RES 2, A", 0x97cb, 3 ],
[ "RES 2,B", 0x90cb, 3 ], [ "RES 2, B", 0x90cb, 3 ],
[ "RES 2,C", 0x91cb, 3 ], [ "RES 2, C", 0x91cb, 3 ],
[ "RES 2,D", 0x92cb, 3 ], [ "RES 2, D", 0x92cb, 3 ],
[ "RES 2,E", 0x93cb, 3 ], [ "RES 2, E", 0x93cb, 3 ],
[ "RES 2,H", 0x94cb, 3 ], [ "RES 2, H", 0x94cb, 3 ],
[ "RES 2, [HL]", 0x96cb, 3 ], [ "RES 2, [HL]", 0x96cb, 3 ],
[ "RES 2,L", 0x95cb, 3 ], [ "RES 2, L", 0x95cb, 3 ],
[ "RES 3,A", 0x9fcb, 3 ], [ "RES 3, A", 0x9fcb, 3 ],
[ "RES 3,B", 0x98cb, 3 ], [ "RES 3, B", 0x98cb, 3 ],
[ "RES 3,C", 0x99cb, 3 ], [ "RES 3, C", 0x99cb, 3 ],
[ "RES 3,D", 0x9acb, 3 ], [ "RES 3, D", 0x9acb, 3 ],
[ "RES 3,E", 0x9bcb, 3 ], [ "RES 3, E", 0x9bcb, 3 ],
[ "RES 3,H", 0x9ccb, 3 ], [ "RES 3, H", 0x9ccb, 3 ],
[ "RES 3, [HL]", 0x9ecb, 3 ], [ "RES 3, [HL]", 0x9ecb, 3 ],
[ "RES 3,L", 0x9dcb, 3 ], [ "RES 3, L", 0x9dcb, 3 ],
[ "RES 4,A", 0xa7cb, 3 ], [ "RES 4, A", 0xa7cb, 3 ],
[ "RES 4,B", 0xa0cb, 3 ], [ "RES 4, B", 0xa0cb, 3 ],
[ "RES 4,C", 0xa1cb, 3 ], [ "RES 4, C", 0xa1cb, 3 ],
[ "RES 4,D", 0xa2cb, 3 ], [ "RES 4, D", 0xa2cb, 3 ],
[ "RES 4,E", 0xa3cb, 3 ], [ "RES 4, E", 0xa3cb, 3 ],
[ "RES 4,H", 0xa4cb, 3 ], [ "RES 4, H", 0xa4cb, 3 ],
[ "RES 4, [HL]", 0xa6cb, 3 ], [ "RES 4, [HL]", 0xa6cb, 3 ],
[ "RES 4,L", 0xa5cb, 3 ], [ "RES 4, L", 0xa5cb, 3 ],
[ "RES 5,A", 0xafcb, 3 ], [ "RES 5, A", 0xafcb, 3 ],
[ "RES 5,B", 0xa8cb, 3 ], [ "RES 5, B", 0xa8cb, 3 ],
[ "RES 5,C", 0xa9cb, 3 ], [ "RES 5, C", 0xa9cb, 3 ],
[ "RES 5,D", 0xaacb, 3 ], [ "RES 5, D", 0xaacb, 3 ],
[ "RES 5,E", 0xabcb, 3 ], [ "RES 5, E", 0xabcb, 3 ],
[ "RES 5,H", 0xaccb, 3 ], [ "RES 5, H", 0xaccb, 3 ],
[ "RES 5, [HL]", 0xaecb, 3 ], [ "RES 5, [HL]", 0xaecb, 3 ],
[ "RES 5,L", 0xadcb, 3 ], [ "RES 5, L", 0xadcb, 3 ],
[ "RES 6,A", 0xb7cb, 3 ], [ "RES 6, A", 0xb7cb, 3 ],
[ "RES 6,B", 0xb0cb, 3 ], [ "RES 6, B", 0xb0cb, 3 ],
[ "RES 6,C", 0xb1cb, 3 ], [ "RES 6, C", 0xb1cb, 3 ],
[ "RES 6,D", 0xb2cb, 3 ], [ "RES 6, D", 0xb2cb, 3 ],
[ "RES 6,E", 0xb3cb, 3 ], [ "RES 6, E", 0xb3cb, 3 ],
[ "RES 6,H", 0xb4cb, 3 ], [ "RES 6, H", 0xb4cb, 3 ],
[ "RES 6, [HL]", 0xb6cb, 3 ], [ "RES 6, [HL]", 0xb6cb, 3 ],
[ "RES 6,L", 0xb5cb, 3 ], [ "RES 6, L", 0xb5cb, 3 ],
[ "RES 7,A", 0xbfcb, 3 ], [ "RES 7, A", 0xbfcb, 3 ],
[ "RES 7,B", 0xb8cb, 3 ], [ "RES 7, B", 0xb8cb, 3 ],
[ "RES 7,C", 0xb9cb, 3 ], [ "RES 7, C", 0xb9cb, 3 ],
[ "RES 7,D", 0xbacb, 3 ], [ "RES 7, D", 0xbacb, 3 ],
[ "RES 7,E", 0xbbcb, 3 ], [ "RES 7, E", 0xbbcb, 3 ],
[ "RES 7,H", 0xbccb, 3 ], [ "RES 7, H", 0xbccb, 3 ],
[ "RES 7, [HL]", 0xbecb, 3 ], [ "RES 7, [HL]", 0xbecb, 3 ],
[ "RES 7,L", 0xbdcb, 3 ], [ "RES 7, L", 0xbdcb, 3 ],
[ "RETI", 0xd9, 0 ], [ "RETI", 0xd9, 0 ],
[ "RET C", 0xd8, 0 ], [ "RET C", 0xd8, 0 ],
[ "RET NC", 0xd0, 0 ], [ "RET NC", 0xd0, 0 ],
@ -404,70 +404,70 @@ temp_opt_table = [
[ "SBC L", 0x9d, 0 ], [ "SBC L", 0x9d, 0 ],
[ "SBC x", 0xde, 1 ], [ "SBC x", 0xde, 1 ],
[ "SCF", 0x37, 0 ], [ "SCF", 0x37, 0 ],
[ "SET 0,A", 0xc7cb, 3 ], [ "SET 0, A", 0xc7cb, 3 ],
[ "SET 0,B", 0xc0cb, 3 ], [ "SET 0, B", 0xc0cb, 3 ],
[ "SET 0,C", 0xc1cb, 3 ], [ "SET 0, C", 0xc1cb, 3 ],
[ "SET 0,D", 0xc2cb, 3 ], [ "SET 0, D", 0xc2cb, 3 ],
[ "SET 0,E", 0xc3cb, 3 ], [ "SET 0, E", 0xc3cb, 3 ],
[ "SET 0,H", 0xc4cb, 3 ], [ "SET 0, H", 0xc4cb, 3 ],
[ "SET 0, [HL]", 0xc6cb, 3 ], [ "SET 0, [HL]", 0xc6cb, 3 ],
[ "SET 0,L", 0xc5cb, 3 ], [ "SET 0, L", 0xc5cb, 3 ],
[ "SET 1,A", 0xcfcb, 3 ], [ "SET 1, A", 0xcfcb, 3 ],
[ "SET 1,B", 0xc8cb, 3 ], [ "SET 1, B", 0xc8cb, 3 ],
[ "SET 1,C", 0xc9cb, 3 ], [ "SET 1, C", 0xc9cb, 3 ],
[ "SET 1,D", 0xcacb, 3 ], [ "SET 1, D", 0xcacb, 3 ],
[ "SET 1,E", 0xcbcb, 3 ], [ "SET 1, E", 0xcbcb, 3 ],
[ "SET 1,H", 0xcccb, 3 ], [ "SET 1, H", 0xcccb, 3 ],
[ "SET 1, [HL]", 0xcecb, 3 ], [ "SET 1, [HL]", 0xcecb, 3 ],
[ "SET 1,L", 0xcdcb, 3 ], [ "SET 1, L", 0xcdcb, 3 ],
[ "SET 2,A", 0xd7cb, 3 ], [ "SET 2, A", 0xd7cb, 3 ],
[ "SET 2,B", 0xd0cb, 3 ], [ "SET 2, B", 0xd0cb, 3 ],
[ "SET 2,C", 0xd1cb, 3 ], [ "SET 2, C", 0xd1cb, 3 ],
[ "SET 2,D", 0xd2cb, 3 ], [ "SET 2, D", 0xd2cb, 3 ],
[ "SET 2,E", 0xd3cb, 3 ], [ "SET 2, E", 0xd3cb, 3 ],
[ "SET 2,H", 0xd4cb, 3 ], [ "SET 2, H", 0xd4cb, 3 ],
[ "SET 2, [HL]", 0xd6cb, 3 ], [ "SET 2, [HL]", 0xd6cb, 3 ],
[ "SET 2,L", 0xd5cb, 3 ], [ "SET 2, L", 0xd5cb, 3 ],
[ "SET 3,A", 0xdfcb, 3 ], [ "SET 3, A", 0xdfcb, 3 ],
[ "SET 3,B", 0xd8cb, 3 ], [ "SET 3, B", 0xd8cb, 3 ],
[ "SET 3,C", 0xd9cb, 3 ], [ "SET 3, C", 0xd9cb, 3 ],
[ "SET 3,D", 0xdacb, 3 ], [ "SET 3, D", 0xdacb, 3 ],
[ "SET 3,E", 0xdbcb, 3 ], [ "SET 3, E", 0xdbcb, 3 ],
[ "SET 3,H", 0xdccb, 3 ], [ "SET 3, H", 0xdccb, 3 ],
[ "SET 3, [HL]", 0xdecb, 3 ], [ "SET 3, [HL]", 0xdecb, 3 ],
[ "SET 3,L", 0xddcb, 3 ], [ "SET 3, L", 0xddcb, 3 ],
[ "SET 4,A", 0xe7cb, 3 ], [ "SET 4, A", 0xe7cb, 3 ],
[ "SET 4,B", 0xe0cb, 3 ], [ "SET 4, B", 0xe0cb, 3 ],
[ "SET 4,C", 0xe1cb, 3 ], [ "SET 4, C", 0xe1cb, 3 ],
[ "SET 4,D", 0xe2cb, 3 ], [ "SET 4, D", 0xe2cb, 3 ],
[ "SET 4,E", 0xe3cb, 3 ], [ "SET 4, E", 0xe3cb, 3 ],
[ "SET 4,H", 0xe4cb, 3 ], [ "SET 4, H", 0xe4cb, 3 ],
[ "SET 4, [HL]", 0xe6cb, 3 ], [ "SET 4, [HL]", 0xe6cb, 3 ],
[ "SET 4,L", 0xe5cb, 3 ], [ "SET 4, L", 0xe5cb, 3 ],
[ "SET 5,A", 0xefcb, 3 ], [ "SET 5, A", 0xefcb, 3 ],
[ "SET 5,B", 0xe8cb, 3 ], [ "SET 5, B", 0xe8cb, 3 ],
[ "SET 5,C", 0xe9cb, 3 ], [ "SET 5, C", 0xe9cb, 3 ],
[ "SET 5,D", 0xeacb, 3 ], [ "SET 5, D", 0xeacb, 3 ],
[ "SET 5,E", 0xebcb, 3 ], [ "SET 5, E", 0xebcb, 3 ],
[ "SET 5,H", 0xeccb, 3 ], [ "SET 5, H", 0xeccb, 3 ],
[ "SET 5, [HL]", 0xeecb, 3 ], [ "SET 5, [HL]", 0xeecb, 3 ],
[ "SET 5,L", 0xedcb, 3 ], [ "SET 5, L", 0xedcb, 3 ],
[ "SET 6,A", 0xf7cb, 3 ], [ "SET 6, A", 0xf7cb, 3 ],
[ "SET 6,B", 0xf0cb, 3 ], [ "SET 6, B", 0xf0cb, 3 ],
[ "SET 6,C", 0xf1cb, 3 ], [ "SET 6, C", 0xf1cb, 3 ],
[ "SET 6,D", 0xf2cb, 3 ], [ "SET 6, D", 0xf2cb, 3 ],
[ "SET 6,E", 0xf3cb, 3 ], [ "SET 6, E", 0xf3cb, 3 ],
[ "SET 6,H", 0xf4cb, 3 ], [ "SET 6, H", 0xf4cb, 3 ],
[ "SET 6, [HL]", 0xf6cb, 3 ], [ "SET 6, [HL]", 0xf6cb, 3 ],
[ "SET 6,L", 0xf5cb, 3 ], [ "SET 6, L", 0xf5cb, 3 ],
[ "SET 7,A", 0xffcb, 3 ], [ "SET 7, A", 0xffcb, 3 ],
[ "SET 7,B", 0xf8cb, 3 ], [ "SET 7, B", 0xf8cb, 3 ],
[ "SET 7,C", 0xf9cb, 3 ], [ "SET 7, C", 0xf9cb, 3 ],
[ "SET 7,D", 0xfacb, 3 ], [ "SET 7, D", 0xfacb, 3 ],
[ "SET 7,E", 0xfbcb, 3 ], [ "SET 7, E", 0xfbcb, 3 ],
[ "SET 7,H", 0xfccb, 3 ], [ "SET 7, H", 0xfccb, 3 ],
[ "SET 7, [HL]", 0xfecb, 3 ], [ "SET 7, [HL]", 0xfecb, 3 ],
[ "SET 7,L", 0xfdcb, 3 ], [ "SET 7, L", 0xfdcb, 3 ],
[ "SLA A", 0x27cb, 3 ], [ "SLA A", 0x27cb, 3 ],
[ "SLA B", 0x20cb, 3 ], [ "SLA B", 0x20cb, 3 ],
[ "SLA C", 0x21cb, 3 ], [ "SLA C", 0x21cb, 3 ],
@ -577,7 +577,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
byte_labels[offset] = {} byte_labels[offset] = {}
byte_labels[offset]["name"] = line_label byte_labels[offset]["name"] = line_label
byte_labels[offset]["usage"] = 1 byte_labels[offset]["usage"] = 1
output += line_label + "\n" output += line_label + " ; " + hex(offset) + "\n"
#find out if there's a two byte key like this #find out if there's a two byte key like this
temp_maybe = maybe_byte temp_maybe = maybe_byte
@ -585,7 +585,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
if temp_maybe in opt_table.keys(): if temp_maybe in opt_table.keys():
opstr = copy(opt_table[temp_maybe][0]) opstr = copy(opt_table[temp_maybe][0])
output += spacing + opstr + " ; " + hex(offset) output += spacing + opstr #+ " ; " + hex(offset)
output += spacing + "\n" output += spacing + "\n"
current_byte_number += 2 current_byte_number += 2
@ -598,8 +598,8 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
#type = -1 when it's the E op #type = -1 when it's the E op
#if op_code_type != -1: #if op_code_type != -1:
if op_code_type == 0 and ord(rom[offset]) == op_code_byte: if op_code_type == 0 and ord(rom[offset]) == op_code_byte:
output += spacing + op_code[0] + " ; " + hex(offset) output += spacing + op_code[0] #+ " ; " + hex(offset)
output += spacing + "\n" output += "\n"
offset += 1 offset += 1
current_byte_number += 1 current_byte_number += 1
@ -607,6 +607,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
oplen = len(op_code[0]) oplen = len(op_code[0])
opstr = copy(op_code[0]) opstr = copy(op_code[0])
xes = op_code[0].count("x") xes = op_code[0].count("x")
include_comment = False
for x in range(0, xes): for x in range(0, xes):
insertion = ord(rom[offset + 1]) insertion = ord(rom[offset + 1])
insertion = "$" + hex(insertion)[2:] insertion = "$" + hex(insertion)[2:]
@ -624,16 +625,19 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
byte_labels[target_address]["usage"] = 1 byte_labels[target_address]["usage"] = 1
insertion = line_label2 insertion = line_label2
include_comment = True
opstr = opstr[:opstr.find("x")] + insertion + opstr[opstr.find("x")+1:] opstr = opstr[:opstr.find("x")] + insertion + opstr[opstr.find("x")+1:]
output += spacing + opstr + " ; " + hex(offset) + "\n" output += spacing + opstr
if include_comment: output += " ; " + hex(offset)
output += "\n"
current_byte_number += 1 current_byte_number += 1
offset += 1 offset += 1
current_byte_number += 1 current_byte_number += 1
offset += 1 offset += 1
include_comment = False
elif op_code_type == 2 and ord(rom[offset]) == op_code_byte: elif op_code_type == 2 and ord(rom[offset]) == op_code_byte:
oplen = len(op_code[0]) oplen = len(op_code[0])
opstr = copy(op_code[0]) opstr = copy(op_code[0])
@ -647,7 +651,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
insertion = "$%.4x" % (number) insertion = "$%.4x" % (number)
opstr = opstr[:opstr.find("?")] + insertion + opstr[opstr.find("?")+1:] opstr = opstr[:opstr.find("?")] + insertion + opstr[opstr.find("?")+1:]
output += spacing + opstr + " ; " + hex(offset) output += spacing + opstr #+ " ; " + hex(offset)
output += spacing + "\n" output += spacing + "\n"
current_byte_number += 2 current_byte_number += 2
@ -672,7 +676,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
break break
if is_data and keep_reading: if is_data and keep_reading:
output += spacing + "db $" + hex(ord(rom[offset+1]))[2:] + " ; " + hex(offset) output += spacing + "db $" + hex(ord(rom[offset+1]))[2:] #+ " ; " + hex(offset)
output += spacing + "\n" output += spacing + "\n"
#else the while loop would have spit out the opcode #else the while loop would have spit out the opcode
@ -682,17 +686,22 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
#clean up unused labels #clean up unused labels
for label_line in byte_labels.keys(): for label_line in byte_labels.keys():
address = label_line
label_line = byte_labels[label_line] label_line = byte_labels[label_line]
if label_line["usage"] == 1: if label_line["usage"] == 1:
output = output.replace(label_line["name"] + "\n", "") output = output.replace(label_line["name"] + " ; " + hex(address) + "\n", "")
return output.lower() return (output.lower(), offset)
def text_asm_pretty_printer(label, address_of_08): def text_asm_pretty_printer(label, address_of_08):
"""returns (output, end_address)"""
output = label + ": ; " + hex(address_of_08) + "\n" output = label + ": ; " + hex(address_of_08) + "\n"
output += output_bank_opcodes(address_of_08 + 1) output += spacing + "db $08 ; asm\n"
results = output_bank_opcodes(address_of_08 + 1)
output += results[0]
end_address = results[1]
return output return (output, end_address)
if __name__ == "__main__": if __name__ == "__main__":
extract_maps.load_rom() extract_maps.load_rom()

View file

@ -8,6 +8,7 @@ from pretty_map_headers import map_name_cleaner, make_text_label, map_constants,
import pretty_map_headers import pretty_map_headers
from analyze_incbins import asm, offset_to_pointer, find_incbin_to_replace_for, split_incbin_line_into_three, generate_diff_insert, load_asm, isolate_incbins, process_incbins, reset_incbins, apply_diff from analyze_incbins import asm, offset_to_pointer, find_incbin_to_replace_for, split_incbin_line_into_three, generate_diff_insert, load_asm, isolate_incbins, process_incbins, reset_incbins, apply_diff
import analyze_incbins import analyze_incbins
from gbz80disasm import text_asm_pretty_printer
import os, sys import os, sys
import subprocess import subprocess
spacing = " " spacing = " "
@ -276,6 +277,81 @@ def insert_all_text_labels():
isolate_incbins() isolate_incbins()
process_incbins() process_incbins()
def insert_08_asm(map_id, text_id):
map2 = extract_maps.map_headers[map_id]
base_label = map_name_cleaner(map2["name"], None)[:-2]
label = base_label + "Text" + str(text_id)
start_address = all_texts[map_id][text_id][0]["start_address"]
(text_asm, end_address) = text_asm_pretty_printer(label, start_address)
print "end address is: " + hex(end_address)
#find where to insert the assembly
line_number = find_incbin_to_replace_for(start_address)
if line_number == None:
print "skipping text label for a $08 on map_id=" + str(map_id) + " text_id=" + str(text_id) + " because the address is taken"
return
#also do a name check
if 1 < ("\n".join(analyze_incbins.asm)).count(label + ":"):
print "skipping text label for a $08 on map_id=" + str(map_id) + " text_id=" + str(text_id) + " because the label is already taken (" + label + ":)"
return
newlines = split_incbin_line_into_three(line_number, start_address, end_address - start_address )
newlines = newlines.split("\n")
if len(newlines) == 2: index = 0 #replace the 1st line with new content
elif len(newlines) == 3: index = 1 #replace the 2nd line with new content
newlines[index] = text_asm
if len(newlines) == 3 and newlines[2][-2:] == "$0":
#get rid of the last incbin line if it is only including 0 bytes
del newlines[2]
#note that this has to be done after adding in the new asm
newlines = "\n".join(line for line in newlines)
newlines = newlines.replace("$x", "$")
diff = generate_diff_insert(line_number, newlines)
print "working on map_id=" + str(map_id) + " text_id=" + str(text_id)
print diff
apply_diff(diff)
def find_all_08s():
all_08s = []
for map_id in all_texts:
for text_id in all_texts[map_id].keys():
if 0 in all_texts[map_id][text_id].keys():
if "type" in all_texts[map_id][text_id][0].keys():
if all_texts[map_id][text_id][0]["type"] == 0x8:
all_08s.append([map_id, text_id])
return all_08s
def insert_all_08s():
all_08s = find_all_08s()
for the_08_line in all_08s:
map_id = the_08_line[0]
text_id = the_08_line[1]
print "processing map_id=" + str(map_id) + " text_id=" + str(text_id)
insert_08_asm(map_id, text_id)
#reset everything
analyze_incbins.reset_incbins()
asm = None
incbin_lines = []
processed_incbins = {}
analyze_incbins.asm = None
analyze_incbins.incbin_lines = []
analyze_incbins.processed_incbins = {}
#reload
load_asm()
isolate_incbins()
process_incbins()
if __name__ == "__main__": if __name__ == "__main__":
#load map headers and object data #load map headers and object data
extract_maps.load_rom() extract_maps.load_rom()
@ -305,7 +381,10 @@ if __name__ == "__main__":
# texts_label_pretty_printer(map_id) # texts_label_pretty_printer(map_id)
#insert_texts_label(240) #insert_texts_label(240)
insert_all_texts_labels() #insert_all_texts_labels()
#insert_text_label_tx_far(240, 1) #insert_text_label_tx_far(240, 1)
#insert_all_text_labels() #insert_all_text_labels()
#insert_08_asm(1, 2)
insert_all_08s()

View file

@ -8,7 +8,7 @@ import extract_maps
import sprite_helper import sprite_helper
import random import random
import string import string
#import analyze_texts #hopefully not a dependency loop import analyze_texts #hopefully not a dependency loop
base = 16 base = 16
spacing = " " spacing = " "