Last active
January 9, 2022 13:45
-
-
Save fujidig/4624244e0af04392ba08bebb56d33619 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
が ん ぜ ョ 空 Q | |
ぼ ダ ぞ づ 空 Q | |
ぼ ボ ク づ 空 Q | |
ぼ ノ ぞ づ 空 Q | |
が ん ぜ は 空 Q | |
ぼ ケ ぞ づ 空 Q | |
が れ ぜ 空 ョ Q | |
ヅ ー て カ 空 Q | |
へ る ん ョ カ Q | |
へ ん ん ボ ご Q | |
ざ へ る ん ご Q | |
ざ へ ん ん 空 Q | |
へ 空 空 空 う Q | |
ひ ぺ と ギ っ Q | |
ひ 空 と ゲ っ Q | |
ダ ひ ぺ ぐ ジ Q | |
ご に ヂ ざ 空 Q | |
空 て よ ん ダ Q | |
ひ ぺ と ザ っ Q | |
て ス ん ダ ダ Q | |
ダ ダ ギ ダ メ Q | |
ギ ザ く だ ザ Q | |
に ぽ に ュ ぺ Q | |
ョ ぐ ダ に ざ Q | |
に ざ ぺ 空 空 Q | |
空 空 空 空 空 Q | |
ョ ア て ゼ っ Q | |
ど の ざ の む Q | |
の ョ ア ギ て Q | |
デ ボ の | |
26 de 2e af 7f 50 3e 0f 2f 32 7f 50 3e 1c 87 32 | |
7f 50 3e 98 2f 32 7f 50 26 de 2e ca 7f 50 3e 88 | |
2f 32 7f 50 26 da 2e 7f af 50 11 e3 c3 85 7f 50 | |
cd d9 de af 85 50 cd de de 1c 2a 50 2b cd d9 de | |
2a 50 2b cd de de 7f 50 cd 7f 7f 7f b3 50 cb 47 | |
c4 06 df 50 cb 7f c4 08 df 50 0f cb 47 28 0b 50 | |
2a c6 10 2b 7f 50 7f c3 d6 de 0f 50 cb 47 c4 0a | |
df 50 c3 8c de 0f 0f 50 0f 0f 06 0f a0 50 06 0a | |
b8 30 0a 50 c6 48 c6 ae 47 50 af 28 0f c6 2b 50 | |
c6 2b 47 7f 7f 50 7f 7f 7f 7f 7f 50 af 80 c3 0d | |
df 50 34 c9 2b c9 d1 50 c9 af 80 06 c3 50 12 1c | |
c9 | |
177 bytes | |
29.5 pokes. |
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
[org(0xde64)] | |
start: | |
ld h, 0xde # call_joypad | |
ld l, 0xaf | |
ld a, 0x0f | |
cpl | |
ld [hl-], a | |
ld a, 0x1c | |
add a, a | |
ld [hl-], a | |
ld a, 0x98 | |
cpl | |
ld [hl-], a | |
ld h, 0xde # ld_hl_a | |
ld l, 0xca | |
ld a, 0x88 | |
cpl | |
ld [hl-], a | |
ld h, 0xda | |
ld l, 0x7f | |
mainloop: | |
xor a | |
ld de, 0xc3e3 | |
add a, l | |
call print_hex_with_swap | |
xor a | |
add a, l | |
call print_hex | |
inc e | |
ld a, [hl+] | |
dec hl | |
call print_hex_with_swap | |
ld a, [hl+] | |
dec hl | |
call print_hex | |
ld a, a | |
call_joypad: | |
call 0x7f7f | |
db 0x7f, 0xb3 | |
bit 0, a | |
call nz, process_a_button | |
bit 7, a | |
call nz, process_down_button | |
rrca | |
bit 0, a | |
jr z, skip_processing_b_button | |
ld a, [hl+] | |
add a, 0x10 | |
dec hl | |
ld a, a | |
ld_hl_a: | |
db 0x7f | |
jp mainloop_end | |
skip_processing_b_button: | |
rrca | |
bit 0, a | |
call nz, process_start_button | |
mainloop_end: | |
jp mainloop | |
print_hex_with_swap: | |
rrca | |
rrca | |
rrca | |
rrca | |
print_hex: | |
ld b, 0x0f | |
and b | |
ld b, 0xa | |
cp b | |
jr nc, print_hex_alphabet | |
add a, 0x48 | |
add a, 0xae | |
ld b, a | |
xor a | |
jr z, print_hex_join | |
print_hex_alphabet: | |
add a, 0x2b | |
add a, 0x2b | |
ld b, a | |
ld a, a | |
ld a, a | |
ld a, a | |
ld a, a | |
ld a, a | |
ld a, a | |
ld a, a | |
print_hex_join: | |
xor a | |
add a, b | |
jp print_hex_end | |
process_a_button: | |
inc [hl] | |
ret | |
process_down_button: | |
dec hl | |
ret | |
process_start_button: | |
pop de | |
ret | |
print_hex_end: | |
xor a | |
add a, b | |
ld b, 0xc3 | |
# ここでld d, bが挟まることが必要 | |
ld [de], a | |
inc e | |
ret |
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
require "csv" | |
Insn = Struct.new(:opcodes, :next, :jump, :index) | |
chars = CSV.read("pokemoncode.csv").map{|x| x[2] } | |
chars[0x7f] = "空" | |
chars[0x50] = "Q" | |
numbytes = { | |
0x06 => 2, | |
0x08 => 3, | |
0x0a => 2, | |
0x0e => 2, | |
0x11 => 3, | |
0x26 => 2, | |
0x28 => 2, | |
0x2e => 2, | |
0x30 => 2, | |
0x31 => 3, | |
0x3e => 2, | |
0xc2 => 3, | |
0xc3 => 3, | |
0xc4 => 3, | |
0xc6 => 2, | |
0xca => 3, | |
0xcb => 2, | |
0xcc => 3, | |
0xcd => 3, | |
0xce => 2, | |
0xd2 => 3, | |
0xd4 => 3, | |
0xd6 => 2, | |
0xda => 3, | |
0xdc => 3, | |
0xde => 2, | |
0xe0 => 2 | |
} | |
numbytes.default = 1 | |
offset = ARGV[1].to_i(16) | |
bin = File.binread(ARGV[0]).bytes.to_a[offset..-1] | |
# 連結リストを作る | |
first_insn = prev_insn = Insn.new([], nil, nil, nil) | |
insn_hash = [] | |
i = 0 | |
while i < bin.size | |
op = bin[i] | |
len = numbytes[op] | |
ops = bin[i, len] | |
insn = Insn.new(ops, nil, nil, nil) | |
insn_hash[offset + i] = insn | |
i += len | |
prev_insn.next = insn | |
prev_insn = insn | |
end | |
# ジャンプ先を設定 | |
insn = first_insn.next | |
index = 0 | |
while insn != nil | |
if [0xc4, 0xcc, 0xcd, 0xd4, 0xdc, 0xc2, 0xc3, 0xca, 0xd2, 0xda].include?(insn.opcodes[0]) | |
insn.jump = insn_hash[insn.opcodes[2] << 8 | insn.opcodes[1]] | |
end | |
if [0x28, 0x30].include?(insn.opcodes[0]) | |
off = insn.opcodes[1] | |
off -= 0x100 if off >= 0x80 | |
insn.jump = insn_hash[offset + index + 2 + off] | |
end | |
index += insn.opcodes.size | |
insn = insn.next | |
end | |
# 6バイトに1回0x50を挟む | |
prev_insn = first_insn | |
insn = first_insn.next | |
index = 0 | |
outindex = 0 | |
while insn != nil | |
len = insn.opcodes.size | |
if outindex % 6 + len >= 6 | |
(5 - outindex % 6).times { | |
new_insn = Insn.new([0x7f], insn, nil) | |
prev_insn.next = new_insn | |
prev_insn = new_insn | |
outindex += 1 | |
} | |
new_insn = Insn.new([0x50], insn, nil) | |
prev_insn.next = new_insn | |
prev_insn = new_insn | |
outindex += 1 | |
end | |
index += len | |
outindex += len | |
insn, prev_insn = insn.next, insn | |
end | |
# indexを設定 | |
insn = first_insn.next | |
index = 0 | |
while insn != nil | |
len = insn.opcodes.size | |
insn.index = index | |
index += len | |
insn = insn.next | |
end | |
# ジャンプ先の情報をopcodesに反映 | |
insn = first_insn.next | |
index = 0 | |
while insn != nil | |
len = insn.opcodes.size | |
if [0xc4, 0xcc, 0xcd, 0xd4, 0xdc, 0xc2, 0xc3, 0xca, 0xd2, 0xda].include?(insn.opcodes[0]) and insn.jump | |
insn.opcodes[1] = (offset + insn.jump.index) & 0xff | |
insn.opcodes[2] = (offset + insn.jump.index) >> 8 | |
end | |
if [0x28, 0x30].include?(insn.opcodes[0]) | |
off = insn.jump.index - index - 2 | |
off += 0x100 if off < 0 | |
if !(0 <= off && off < 0x100) | |
raise "offset error" | |
end | |
insn.opcodes[1] = off | |
end | |
index += insn.opcodes.length | |
insn = insn.next | |
end | |
# 新しいバイナリを作る | |
newbin = [] | |
insn = first_insn.next | |
while insn != nil | |
len = insn.opcodes.size | |
len.times {|i| newbin << insn.opcodes[i] } | |
insn = insn.next | |
end | |
File.binwrite(ARGV[0] + ".patched", newbin.map{|x| x.chr }.join("")) | |
newbin.each_with_index do |insn, i| | |
print chars[insn] || ("<<%02x>>" % insn) | |
print " " | |
puts if insn == 0x50 | |
end | |
puts | |
puts newbin.map{|x| "%02x" % x }.each_slice(16).map {|x| x.join(" ") }.join("\n") | |
puts "#{newbin.length} bytes" | |
puts "#{newbin.length / 6.0} pokes." |
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
0x00 | NOP | ||
---|---|---|---|
0x01 | LD BC,d16 | ||
0x02 | LD (BC),A | ||
0x03 | INC BC | ||
0x04 | INC B | ||
0x05 | DEC B | ガ | |
0x06 | LD B,d8 | ギ | |
0x07 | RLCA | グ | |
0x08 | LD (a16),SP | ゲ | |
0x09 | ADD HL,BC | ゴ | |
0x0a | LD A,(BC) | ザ | |
0x0b | DEC BC | ジ | |
0x0c | INC C | ズ | |
0x0d | DEC C | ゼ | |
0x0e | LD C,d8 | ゾ | |
0x0f | RRCA | ダ | |
0x10 | STOP 0 | ヂ | |
0x11 | LD DE,d16 | ヅ | |
0x12 | LD (DE),A | デ | |
0x13 | INC DE | ド | |
0x14 | INC D | ||
0x15 | DEC D | ||
0x16 | LD D,d8 | ||
0x17 | RLA | ||
0x18 | JR r8 | ||
0x19 | ADD HL,DE | バ | |
0x1a | LD A,(DE) | ビ | |
0x1b | DEC DE | ブ | |
0x1c | INC E | ボ | |
0x1d | DEC E | ||
0x1e | LD E,d8 | ||
0x1f | RRA | ||
0x20 | JR NZ,r8 | ||
0x21 | LD HL,d16 | ||
0x22 | LD (HL+),A | ||
0x23 | INC HL | ||
0x24 | INC H | ||
0x25 | DEC H | ||
0x26 | LD H,d8 | が | |
0x27 | DAA | ぎ | |
0x28 | JR Z,r8 | ぐ | |
0x29 | ADD HL,HL | げ | |
0x2a | LD A,(HL+) | ご | |
0x2b | DEC HL | ざ | |
0x2c | INC L | じ | |
0x2d | DEC L | ず | |
0x2e | LD L,d8 | ぜ | |
0x2f | CPL | ぞ | |
0x30 | JR NC,r8 | だ | |
0x31 | LD SP,d16 | ぢ | |
0x32 | LD (HL-),A | づ | |
0x33 | INC SP | で | |
0x34 | INC (HL) | ど | |
0x35 | DEC (HL) | ||
0x36 | LD (HL),d8 | ||
0x37 | SCF | ||
0x38 | JR C,r8 | ||
0x39 | ADD HL,SP | ||
0x3a | LD A,(HL-) | ば | |
0x3b | DEC SP | び | |
0x3c | INC A | ぶ | |
0x3d | DEC A | べ | |
0x3e | LD A,d8 | ぼ | |
0x3f | CCF | ||
0x40 | LD B,B | ||
0x41 | LD B,C | ||
0x42 | LD B,D | ||
0x43 | LD B,E | ||
0x44 | LD B,H | ぱ | |
0x45 | LD B,L | ぴ | |
0x46 | LD B,(HL) | ぷ | |
0x47 | LD B,A | ぺ | |
0x48 | LD C,B | ぽ | |
0x49 | LD C,C | ||
0x4a | LD C,D | ||
0x4b | LD C,E | ||
0x4c | LD C,H | ||
0x4d | LD C,L | ||
0x4e | LD C,(HL) | ||
0x4f | LD C,A | ||
0x50 | LD D,B | 終端文字 | |
0x51 | LD D,C | ||
0x52 | LD D,D | ||
0x53 | LD D,E | ||
0x54 | LD D,H | ||
0x55 | LD D,L | ||
0x56 | LD D,(HL) | ||
0x57 | LD D,A | ||
0x58 | LD E,B | ||
0x59 | LD E,C | ||
0x5a | LD E,D | ||
0x5b | LD E,E | ||
0x5c | LD E,H | ||
0x5d | LD E,L | ||
0x5e | LD E,(HL) | ||
0x5f | LD E,A | ||
0x60 | LD H,B | ||
0x61 | LD H,C | ||
0x62 | LD H,D | ||
0x63 | LD H,E | ||
0x64 | LD H,H | ||
0x65 | LD H,L | ||
0x66 | LD H,(HL) | ||
0x67 | LD H,A | ||
0x68 | LD L,B | ||
0x69 | LD L,C | ||
0x6a | LD L,D | ||
0x6b | LD L,E | ||
0x6c | LD L,H | ||
0x6d | LD L,L | ||
0x6e | LD L,(HL) | ||
0x6f | LD L,A | ||
0x70 | LD (HL),B | ||
0x71 | LD (HL),C | ||
0x72 | LD (HL),D | ||
0x73 | LD (HL),E | ||
0x74 | LD (HL),H | ||
0x75 | LD (HL),L | ||
0x76 | HALT | ||
0x77 | LD (HL),A | ||
0x78 | LD A,B | ||
0x79 | LD A,C | ||
0x7a | LD A,D | ||
0x7b | LD A,E | ||
0x7c | LD A,H | ||
0x7d | LD A,L | ||
0x7e | LD A,(HL) | ||
0x7f | LD A,A | (空白) | |
0x80 | ADD A,B | ア | |
0x81 | ADD A,C | イ | |
0x82 | ADD A,D | ウ | |
0x83 | ADD A,E | エ | |
0x84 | ADD A,H | オ | |
0x85 | ADD A,L | カ | |
0x86 | ADD A,(HL) | キ | |
0x87 | ADD A,A | ク | |
0x88 | ADC A,B | ケ | |
0x89 | ADC A,C | コ | |
0x8a | ADC A,D | サ | |
0x8b | ADC A,E | シ | |
0x8c | ADC A,H | ス | |
0x8d | ADC A,L | セ | |
0x8e | ADC A,(HL) | ソ | |
0x8f | ADC A,A | タ | |
0x90 | SUB B | チ | |
0x91 | SUB C | ツ | |
0x92 | SUB D | テ | |
0x93 | SUB E | ト | |
0x94 | SUB H | ナ | |
0x95 | SUB L | ニ | |
0x96 | SUB (HL) | ヌ | |
0x97 | SUB A | ネ | |
0x98 | SBC A,B | ノ | |
0x99 | SBC A,C | ハ | |
0x9a | SBC A,D | ヒ | |
0x9b | SBC A,E | フ | |
0x9c | SBC A,H | ホ | |
0x9d | SBC A,L | マ | |
0x9e | SBC A,(HL) | ミ | |
0x9f | SBC A,A | ム | |
0xa0 | AND B | メ | |
0xa1 | AND C | モ | |
0xa2 | AND D | ヤ | |
0xa3 | AND E | ユ | |
0xa4 | AND H | ヨ | |
0xa5 | AND L | ラ | |
0xa6 | AND (HL) | ル | |
0xa7 | AND A | レ | |
0xa8 | XOR B | ロ | |
0xa9 | XOR C | ワ | |
0xaa | XOR D | ||
0xab | XOR E | ン | |
0xac | XOR H | ッ | |
0xad | XOR L | ャ | |
0xae | XOR (HL) | ュ | |
0xaf | XOR A | ョ | |
0xb0 | OR B | ||
0xb1 | OR C | あ | |
0xb2 | OR D | い | |
0xb3 | OR E | う | |
0xb4 | OR H | え | |
0xb5 | OR L | お | |
0xb6 | OR (HL) | か | |
0xb7 | OR A | き | |
0xb8 | CP B | く | |
0xb9 | CP C | け | |
0xba | CP D | こ | |
0xbb | CP E | さ | |
0xbc | CP H | し | |
0xbd | CP L | す | |
0xbe | CP (HL) | せ | |
0xbf | CP A | そ | |
0xc0 | RET NZ | た | |
0xc1 | POP BC | ち | |
0xc2 | JP NZ,a16 | つ | |
0xc3 | JP a16 | て | |
0xc4 | CALL NZ,a16 | と | |
0xc5 | PUSH BC | な | |
0xc6 | ADD A,d8 | に | |
0xc7 | RST 00H | ぬ | |
0xc8 | RET Z | ね | |
0xc9 | RET | の | |
0xca | JP Z,a16 | は | |
0xcb | PREFIX CB | ひ | |
0xcc | CALL Z,a16 | ふ | |
0xcd | CALL a16 | へ | |
0xce | ADC A,d8 | ほ | |
0xcf | RST 08H | ま | |
0xd0 | RET NC | み | |
0xd1 | POP DE | む | |
0xd2 | JP NC,a16 | め | |
0xd3 | も | ||
0xd4 | CALL NC,a16 | や | |
0xd5 | PUSH DE | ゆ | |
0xd6 | SUB d8 | よ | |
0xd7 | RST 10H | ら | |
0xd8 | RET C | り | |
0xd9 | RETI | る | |
0xda | JP C,a16 | れ | |
0xdb | ろ | ||
0xdc | CALL C,a16 | わ | |
0xdd | |||
0xde | SBC A,d8 | ん | |
0xdf | RST 18H | っ | |
0xe0 | LDH (a8),A | ゃ | |
0xe1 | POP HL | ゅ | |
0xe2 | LD (C),A | ょ | |
0xe3 | ー | ||
0xe4 | |||
0xe5 | PUSH HL | ||
0xe6 | AND d8 | ||
0xe7 | RST 20H | ||
0xe8 | ADD SP,r8 | ||
0xe9 | JP (HL) | ||
0xea | LD (a16),A | ||
0xeb | |||
0xec | |||
0xed | |||
0xee | XOR d8 | ||
0xef | RST 28H | ||
0xf0 | LDH A,(a8) | ||
0xf1 | POP AF | ||
0xf2 | LD A,(C) | ||
0xf3 | DI | ||
0xf4 | |||
0xf5 | PUSH AF | ||
0xf6 | OR d8 | ||
0xf7 | RST 30H | ||
0xf8 | LD HL,SP+r8 | ||
0xf9 | LD SP,HL | ||
0xfa | LD A,(a16) | ||
0xfb | EI | ||
0xfc | |||
0xfd | |||
0xfe | CP d8 | ||
0xff | RST 38H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment