Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oupo
Last active November 15, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oupo/58b2a858360b574661a3 to your computer and use it in GitHub Desktop.
Save oupo/58b2a858360b574661a3 to your computer and use it in GitHub Desktop.
-- vba-rerecording, ポケモン赤用
function printf(...) print(string.format(...)) end
reg = memory.getregister
regw = memory.setregister
read8 = memory.readbyte
read16 = memory.readword
write8 = memory.writebyte
-- トレーナーID書き込みのトレース
memory.registerwrite(0xd2d8, 2, function (addr)
printf("トレーナーID pc = %x, addr=%x %.2x", reg("pc"), addr, read8(addr))
end)
-- 乱数ルーチンの最後の命令
memory.registerexec(0x3E9C, function ()
local lr = read16(reg("sp")) -- 呼び出し元
-- 戻り値を0に固定する
-- 0ae9からは毎フレーム呼ばれる模様
-- 0に固定していると戦闘で6981から呼ばれ続け無限ループしてしまうため6981のときは0に固定しないことにする
if lr ~= 0x0ae9 and lr ~= 0x6981 then
printf("%d %d %d %x", reg("a"), read8(0xffd3), read8(0xffd4), lr)
regw("a", 0)
write8(0xffd3, 0)
write8(0xffd4, 0)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment