Created
June 10, 2019 03:57
-
-
Save taotao54321/a1d8cc1472ddb3e3604e180f60808f8b to your computer and use it in GitHub Desktop.
紫禁城 (FC) HUDスクリプト for FCEUX
This file contains hidden or 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
local function mem_read_u8(addr) | |
return memory.readbyte(addr) | |
end | |
local fmt = string.format | |
local function text(x, y, str, color) | |
gui.text(x, y, str, color) | |
end | |
local function idx2yx(idx) | |
return math.floor(idx/14), idx%14 | |
end | |
local function yx2screen(y, x) | |
local sx = 16 + 16*x | |
local sy = 16 + 24*y | |
return sx, sy | |
end | |
local function idx2screen(idx) | |
local y,x = idx2yx(idx) | |
return yx2screen(y, x) | |
end | |
local function get_pieces() | |
local pieces = {} | |
for i = 0, 84 do | |
local piece = {} | |
local addr = 0x0620 + 3*i | |
local byte0 = mem_read_u8(addr) | |
local byte1 = mem_read_u8(addr+1) | |
local byte2 = mem_read_u8(addr+2) | |
local y,x = idx2yx(byte1-1) -- 0-based | |
piece.exists = byte0 ~= 0 | |
piece.y = y | |
piece.x = x | |
piece.movable = bit.band(byte2,0x80) == 0 | |
piece.kind = bit.band(byte2,0x1F) | |
piece.under = byte0 >= 2 and byte0-2 or -1 | |
pieces[i+1] = piece | |
end | |
return pieces | |
end | |
local function get_pits() | |
local pits = {} | |
for i = 0, 59 do | |
local addr = 0x079F + i | |
pits[i+1] = mem_read_u8(addr)-1 -- 0-based | |
end | |
return pits | |
end | |
local function get_info() | |
local info = {} | |
info.pieces = get_pieces() | |
info.pits = get_pits() | |
return info | |
end | |
local function draw() | |
local info = get_info() | |
for i = 1, #info.pieces do | |
local piece = info.pieces[i] | |
if piece.exists then | |
local color = piece.movable and "white" or "red" | |
local x,y = yx2screen(piece.y, piece.x) | |
text(x, y, fmt("%d",piece.kind), color) | |
if piece.under >= 0 then | |
text(x, y+8, fmt("%d",piece.under), "magenta") | |
end | |
end | |
end | |
for i = 1, #info.pits do | |
local pit = info.pits[i] | |
if pit >= 0 then | |
local x,y = idx2screen(pit) | |
text(x, y, "##", "red") | |
text(x, y+8, "##", "red") | |
text(x, y+16, "##", "red") | |
end | |
end | |
end | |
local function main() | |
gui.opacity(0.8) | |
emu.registerafter(draw) | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment