Skip to content

Instantly share code, notes, and snippets.

@taotao54321
Created December 31, 2016 06:11
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/187d2dca9a3a33494e678e15646e26ef to your computer and use it in GitHub Desktop.
Save taotao54321/187d2dca9a3a33494e678e15646e26ef to your computer and use it in GitHub Desktop.
NES Star Soldier (J) tile display for FCEUX
----------------------------------------------------------------------
-- NES Star Soldier (J) tile display for FCEUX
----------------------------------------------------------------------
----------------------------------------------------------------------
-- util
----------------------------------------------------------------------
local function mem_read_u8(addr)
return memory.readbyte(addr)
end
local function mem_read_bytes(addr, len)
local buf = {}
for i = 1, len do
buf[i] = mem_read_u8(addr + i-1)
end
return buf
end
----------------------------------------------------------------------
-- main
----------------------------------------------------------------------
local COLS = 20
local ROWS = 15
local COLOR_GRID = "#00FFFF"
local fmt = string.format
local function get_info()
local info = {}
info.scroll_x = mem_read_u8(0x13)
info.scroll_y = mem_read_u8(0x14)
info.tiles = mem_read_bytes(0x06CA, COLS * ROWS)
return info
end
local function line(src_x, src_y, dst_x, dst_y, color)
gui.line(src_x, src_y, dst_x, dst_y, color)
end
local function text(x, y, str)
gui.text(x, y, str)
end
local function draw_grid(scroll_x, scroll_y)
local off_x = -scroll_x
local off_y = -(scroll_y % 16) - 1
for row = 0, ROWS-1 do
line( off_x, 16*row + off_y,
16*COLS + off_x, 16*row + off_y,
COLOR_GRID)
end
for col = 0, COLS-1 do
line(16*col + off_x, off_y,
16*col + off_x, 16*ROWS + off_y,
COLOR_GRID)
end
end
local function draw_tile(tiles, scroll_x, scroll_y)
local off_x = -scroll_x
local off_y = -(scroll_y % 16) - 1
for row = 0, ROWS-1 do
for col = 0, COLS-1 do
local tile = tiles[COLS*row + col + 1]
text(16*col + off_x + 2, 16*row + off_y + 2,
fmt("%02X", tile))
end
end
end
local function draw()
local info = get_info()
draw_grid(info.scroll_x, info.scroll_y)
draw_tile(info.tiles, info.scroll_x, info.scroll_y)
end
local function main()
gui.opacity(0.7)
emu.registerafter(draw)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment