Skip to content

Instantly share code, notes, and snippets.

@taotao54321
Created September 30, 2018 14:21
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 taotao54321/981994da0e92f345ab7f1f5e3ceee8c1 to your computer and use it in GitHub Desktop.
Save taotao54321/981994da0e92f345ab7f1f5e3ceee8c1 to your computer and use it in GitHub Desktop.
エジプト (FC) 問題データ抽出スクリプト for FCEUX
--[[
エジプト (FC) 問題データ抽出スクリプト for FCEUX
面セレの裏技(https://gamefaqs.gamespot.com/nes/570566-egypt/cheats)を
実行後、FREE PLAYのROOM選択画面から実行する。
--]]
local function play(inp, n)
n = n or 1
for i = 1, n do
joypad.set(1, inp)
emu.frameadvance()
end
end
local function idx2xy(i)
return i%8, i/8
end
local function xy2idx(x, y)
return 8*y + x
end
local function load_problem(level, room)
memory.writebyte(0x8A, level)
memory.writebyte(0x8B, room)
play({ A = 1 });
play({}, 16);
play({ A = 1 });
play({}, 120);
local pos_x = memory.readbyte(0xDE) - 1
local pos_y = memory.readbyte(0xDD) - 2
local vec = {}
for y = 0, 7 do
for x = 0, 7 do
vec[xy2idx(x,y)] = memory.readbyte(0x0721 + 16*y + x)
end
end
return pos_x, pos_y, vec
end
local CELL_CHR = {
[0x00] = ".",
[0x04] = "0",
[0x08] = "1",
[0x0C] = "2",
[0x10] = "3",
[0x14] = "4",
[0x18] = "5",
[0x1C] = "6",
[0x20] = "7",
[0x24] = "8",
[0x28] = "^",
[0x2C] = "v",
[0x30] = ">",
[0x34] = "<",
[0x38] = "#",
}
local function save_problem(level, room, pos_x, pos_y, vec)
local path = string.format("%02d-%d.txt", level, room)
local out = io.open(path, "w")
out:write(string.format("%d %d\n", pos_x, pos_y))
for y = 0, 7 do
for x = 0, 7 do
local b = bit.band(0x3F, vec[xy2idx(x,y)])
local c = CELL_CHR[b]
if c == nil then error(string.format("unknown byte: 0x%02X", b)) end
out:write(c)
end
out:write("\n")
end
out:close()
end
local function main()
emu.speedmode("maximum")
local state = savestate.object()
savestate.save(state)
for level = 0, 18 do
for room = 0, 5 do
savestate.load(state)
pos_x, pos_y, vec = load_problem(level, room)
save_problem(level, room, pos_x, pos_y, vec)
end
end
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment