update Gargoyles.lua:

- use M64K Bus properly
- input display
- fceux font
- map and screen borders when camhack is on
- refactor out some functions
- manual lagtount tweaks
- use r24 alias instead of rl for reading addresses from RAM
This commit is contained in:
feos 2017-01-04 15:58:34 +03:00
parent c496674301
commit 9884d47a07
1 changed files with 189 additions and 148 deletions

View File

@ -1,87 +1,72 @@
-- Gargoyles, Genesis -- Gargoyles, Genesis (BizHawk)
-- feos, 2015 -- feos, 2015-2016
--== Shortcuts ==-- --== Shortcuts ==--
local rb = memory.read_u8 rb = memory.read_u8
local rw = memory.read_u16_be rw = memory.read_u16_be
local rws = memory.read_s16_be rws = memory.read_s16_be
local rl = memory.read_u32_be r24 = memory.read_u24_be
local box = gui.drawBox rl = memory.read_u32_be
local text = gui.pixelText box = gui.drawBox
local line = gui.drawLine text = gui.pixelText
local AND = bit.band line = gui.drawLine
local SHIFT= bit.rshift AND = bit.band
SHIFT= bit.rshift
--== RAM addresses ==-- --== RAM addresses ==--
local GlobalBase = 0x1c76 GlobalBase = 0xff1c76
local GolBase = 0x2c76 GolBase = 0xff2c76
local MapA_Buff = 0x4af0 MapA_Buff = 0xff4af0
local mapline_tab = 0x0244 mapline_tab = 0xff0244
local LevelFlr = 0x00c0 LevelFlr = 0xff00c0
local LevelCon = 0x00c4 LevelCon = 0xff00c4
local levnum = 0x00ba levnum = 0xff00ba
--== Camera Hack ==-- --== Camera Hack ==--
local camhack = false camhack = true
local div = 1 -- scale div = 2 -- scale
local size = 16/div -- block size size = 16/div -- block size
--== Other stuff ==-- --== Other stuff ==--
local XposLast = 0 XposLast = 0
local YposLast = 0 YposLast = 0
room = 0
lagcount = emu.lagcount()
gui.defaultPixelFont("fceux")
function main() function main()
camx = (rws(0x010c)+16) camx = rws(0xff010c)+16
camy = (rws(0x010e)+16) camy = rws(0xff010e)+16
backx = camx backx = camx
backy = camy backy = camy
mapw = rw(0x00d4)*8 mapw = rw(0xff00d4)*8
maph = rw(0x00d6)*8 maph = rw(0xff00d6)*8
-- text(100,0,mapw.." "..maph) Xpos = rws(0xff0106)
Xpos = rws(0x0106) Ypos = rws(0xff0108)
Ypos = rws(0x0108) health = rws(0xff2cc6)
health = rws(0x2cc6) facing = AND(rb(GolBase+0x48),2) -- object flag 1
facing = AND(rb(GolBase+0x48),2) -- object flag 1 working = rb(0xff0073)
working= rb(0x0073) run = rb(0xff1699)
if camhack then inv = rw(0xff16d2)
camx = Xpos-320/2*div rnd1 = rl(0xff001c)
camy = Ypos-224/2*div rnd2 = rw(0xff0020)
end Xspd = Xpos-XposLast
run = rb(0x1699) Yspd = Ypos-YposLast
inv = rw(0x16d2)
rnd1 = rl(0x001c)
rnd2 = rw(0x0020)
Xspd = Xpos-XposLast
Yspd = Ypos-YposLast
XposLast = Xpos XposLast = Xpos
YposLast = Ypos YposLast = Ypos
rndlast = rnd1
--[ [-- CamhackHUD()
if camhack then box(0,0,320,240,0,0x66000000) end Background()
if working==0 then
box(
(backx-camx- 1)/div,
(backy-camy- 1)/div,
(backx-camx+320)/div,
(backy-camy+224)/div,
0x0000ffff)
box( 0-camx/div+size,
0-camy/div+size,
mapw/div-camx/div,
maph/div-camy/div,
0xff0000ff)
end
for i=0,20*div do
for j=0,14*div do
GetBlock(i,j)
end
end
--]]--
Objects() Objects()
PlayerBoxes() PlayerBoxes()
HUD() HUD()
RoomTime() RoomTime()
Input()
rndlast = rnd1
end end
function RoomTime() function RoomTime()
local start11 = 767 local start11 = 894--767
local start12 = 2294 local start12 = 2294
local start13 = 4101 local start13 = 4101
local startl4 = 6000 local startl4 = 6000
@ -91,20 +76,73 @@ function RoomTime()
elseif timer < start13 then room = timer - start12 elseif timer < start13 then room = timer - start12
elseif timer < startl4 then room = timer - start13 elseif timer < startl4 then room = timer - start13
end end
text(100,217,"room cnt: "..room) text(160,214,"room cnt: "..room, "white")
end
function Background()
for i=0,20*div do
for j=0,14*div do
GetBlock(i,j)
end
end
end
function CamhackHUD()
if camhack then
camx = Xpos-320/2*div
camy = Ypos-224/2*div
box(0,0,320,240,0,0x66000000)
ch = "on"
else
ch = "off"
end
text(260,206,string.format("cHack: %s\nscale: %d",ch,div))
if working==0 then
-- screen borders
box((backx-camx- 1)/div,
(backy-camy- 1)/div,
(backx-camx+320)/div,
(backy-camy+224)/div,
0xff0000ff)
-- map borders
box( 0-camx/div+size,
0-camy/div+size,
mapw/div-camx/div,
maph/div-camy/div,
0xff0000ff)
end
end
function Input()
local i,u,d,l,r,a,b,c,s
if movie.isloaded() then
i = movie.getinput(emu.framecount()-1)
else
i = joypad.getimmediate()
end
if i["P1 Up" ] then u = "U" else u = " " end
if i["P1 Down" ] then d = "D" else d = " " end
if i["P1 Left" ] then l = "L" else l = " " end
if i["P1 Right"] then r = "R" else r = " " end
if i["P1 A" ] then a = "A" else a = " " end
if i["P1 B" ] then b = "B" else b = " " end
if i["P1 C" ] then c = "C" else c = " " end
if i["P1 Start"] then s = "S" else s = " " end
text(1,10,u..d..l..r..a..b..c..s,"yellow")
end end
function GetBlock(x,y) function GetBlock(x,y)
if working>0 then return end if working>0 then return end
x = camx+x*size*div-AND(camx,0xF) x = camx+x*size*div-AND(camx,0xf)
y = camy+y*size*div-AND(camy,0xF) y = camy+y*size*div-AND(camy,0xf)
if x>0 and x<mapw and y>0 and y<maph then if x>0 and x<mapw
and y>0 and y<maph then
local x1 = x/div-camx/div local x1 = x/div-camx/div
local x2 = x1+size-1 local x2 = x1+size-1
local y1 = y/div-camy/div local y1 = y/div-camy/div
local y2 = y1+size-1 local y2 = y1+size-1
local d4 = rw(mapline_tab+SHIFT(y,4)*2) local d4 = rw(mapline_tab+SHIFT(y,4)*2)
local a1 = AND(rl(LevelFlr),0xffff) local a1 = r24(LevelFlr+1)
local d1 = SHIFT(rw(MapA_Buff+d4+SHIFT(x,4)*2),1) local d1 = SHIFT(rw(MapA_Buff+d4+SHIFT(x,4)*2),1)
local ret = rb(a1+d1+2) -- block local ret = rb(a1+d1+2) -- block
local col = 0 -- block color local col = 0 -- block color
@ -112,74 +150,73 @@ function GetBlock(x,y)
local opin = 0x66000000 -- inner opacity local opin = 0x66000000 -- inner opacity
local op = 0xff000000 local op = 0xff000000
d1 = rw(a1+d1) d1 = rw(a1+d1)
a1 = AND(rl(LevelCon),0xffffff)+d1 a1 = r24(LevelCon+1)+d1
if rb(a1,"MD CART")>0 or rb(a1+8,"MD CART")>0 then if rb(a1)>0 or rb(a1+8)>0 then
box(x1,y1,x2,y2,0x5500ff00,0x5500ff00) box(x1,y1,x2,y2,0x5500ff00,0x5500ff00)
for pixel=0,15 do for pixel=0,15 do
retc = rb(a1+pixel,"MD CART") -- contour retc = rb(a1+pixel) -- contour
if retc>0 then if retc>0 then
gui.drawPixel(x1+pixel/div,y1+retc/div-1/div,0xffffff00) gui.drawPixel(x1+pixel/div,y1+retc/div-1/div,0xffffff00)
-- text(x1,y1,string.format("%X",retc)) -- text(x1,y1,string.format("%X",retc))
end end
end end
end end
local lol = 0
--if lol==0 then return end
if ret>0 then if ret>0 then
if ret==0x80 then -- WALL if ret==0x80 then -- WALL
col = 0x00ffffff -- white col = 0x00ffffff -- white
line(x1,y1,x1,y2,col+op) -- left line(x1,y1,x1,y2,col+op) -- left
line(x2,y1,x2,y2,col+op) -- right line(x2,y1,x2,y2,col+op) -- right
elseif ret==0x81 then -- CEILING elseif ret==0x81 then -- CEILING
col = 0x00ffffff -- white col = 0x00ffffff -- white
line(x1,y2,x2,y2,col+op) -- bottom line(x1,y2,x2,y2,col+op) -- bottom
elseif ret==0x82 then -- CLIMB_U elseif ret==0x82 then -- CLIMB_U
col = 0x0000ffff -- cyan col = 0x0000ffff -- cyan
line(x1,y2,x2,y2,col+op) -- bottom line(x1,y2,x2,y2,col+op) -- bottom
elseif ret==0x83 then -- CLIMB_R elseif ret==0x83 then -- CLIMB_R
-- col = 0x00ffffff -- white -- col = 0x00ffffff -- white
-- line(x2,y1,x2,y2,col+op) -- right -- line(x2,y1,x2,y2,col+op) -- right
col = 0x0000ffff -- cyan col = 0x0000ffff -- cyan
line(x1,y1,x1,y2,col+op) -- left line(x1,y1,x1,y2,col+op) -- left
elseif ret==0x84 then -- CLIMB_L elseif ret==0x84 then -- CLIMB_L
-- col = 0x00ffffff -- white -- col = 0x00ffffff -- white
-- line(x1,y1,x1,y2,col+op) -- left -- line(x1,y1,x1,y2,col+op) -- left
col = 0x0000ffff -- cyan col = 0x0000ffff -- cyan
line(x2,y1,x2,y2,col+op) -- right line(x2,y1,x2,y2,col+op) -- right
elseif ret==0x85 then -- CLIMB_LR elseif ret==0x85 then -- CLIMB_LR
col = 0x0000ffff -- cyan col = 0x0000ffff -- cyan
line(x1,y1,x1,y2,col+op) -- left line(x1,y1,x1,y2,col+op) -- left
line(x2,y1,x2,y2,col+op) -- right line(x2,y1,x2,y2,col+op) -- right
elseif ret==0x86 then -- CLIMB_R_STAND_R elseif ret==0x86 then -- CLIMB_R_STAND_R
col = 0x00ffffff -- white col = 0x00ffffff -- white
line(x1,y1,x2,y1,col+op) -- top line(x1,y1,x2,y1,col+op) -- top
col = 0x0000ffff -- cyan col = 0x0000ffff -- cyan
line(x1,y1,x1,y2,col+op) -- left line(x1,y1,x1,y2,col+op) -- left
elseif ret==0x87 then -- CLIMB_L_STAND_L elseif ret==0x87 then -- CLIMB_L_STAND_L
col = 0x00ffffff -- white col = 0x00ffffff -- white
line(x1,y1,x2,y1,col+op) -- top line(x1,y1,x2,y1,col+op) -- top
col = 0x0000ffff -- cyan col = 0x0000ffff -- cyan
line(x2,y1,x2,y2,col+op) -- right line(x2,y1,x2,y2,col+op) -- right
elseif ret==0x87 then -- CLIMB_LR_STAND_LR elseif ret==0x87 then -- CLIMB_LR_STAND_LR
col = 0x00ffffff -- white col = 0x00ffffff -- white
line(x1,y1,x2,y1,col+op) -- top line(x1,y1,x2,y1,col+op) -- top
col = 0x00ff00ff -- cyan col = 0x00ff00ff -- cyan
line(x1,y1,x1,y2,col+op) -- left line(x1,y1,x1,y2,col+op) -- left
col = 0x0000ffff -- cyan col = 0x0000ffff -- cyan
line(x2,y1,x2,y2,col+op) -- right line(x2,y1,x2,y2,col+op) -- right
elseif ret==0x70 then -- GRAB_SWING elseif ret==0x70 then -- GRAB_SWING
col = 0x0000ff00 -- green col = 0x0000ff00 -- green
box(x1,y1,x2,y2,col,col+opout) box(x1,y1,x2,y2,col,col+opout)
-- elseif ret==0x72 then -- FORCE_TURN (for enemies) -- elseif ret==0x72 then -- FORCE_TURN (for enemies)
-- col = 0x0088ff00 -- green -- col = 0x0088ff00 -- green
-- box(x1,y1,x2,y2,col,col+opout) -- box(x1,y1,x2,y2,col,col+opout)
elseif ret==0x7f then -- EXIT elseif ret==0x7f then -- EXIT
col = 0x00ffff00 -- yellow col = 0x00ffff00 -- yellow
elseif ret==0xd0 or ret==0xd1 then -- SPIKES elseif ret==0xd0
col = 0x00ff0000 -- red or ret==0xd1 then -- SPIKES
col = 0x00ff0000 -- red
box(x1,y1,x2,y2,col,col+opout) box(x1,y1,x2,y2,col,col+opout)
else -- LEVEL_SPECIFIC else -- LEVEL_SPECIFIC
col = 0x00ff8800 -- orange col = 0x00ff8800 -- orange
box(x1,y1,x2,y2,col+opin,col+opout) box(x1,y1,x2,y2,col+opin,col+opout)
end end
box(x1,y1,x2,y2,col+opin,col+opout) box(x1,y1,x2,y2,col+opin,col+opout)
@ -189,16 +226,16 @@ function GetBlock(x,y)
end end
function HUD() function HUD()
text(1, 0,emu.framecount(), framecol)
text(1,20,emu.lagcount(), "red")
text(1,30,movie.rerecordcount(),"orange")
if working>0 then return end if working>0 then return end
if camhack then ch = "on" else ch = "off" end if rndlast ~= rnd1 then rndcol = "red" else rndcol = "white" end
if rndlast~= rnd1 then rndcol = "red" else rndcol = "white" end text( 0,214,"rnd: ","yellow")
if memory.readbyte(0xF6D4)==0 then text(170,217,"LAG","red") end text( 26,214,string.format("%08X %04X",rnd1,rnd2),rndcol)
text(280,210,string.format("cHack: %s\nscale: %d",ch,div)) text(277, 0,string.format(
text( 0,217,"rnd: ","yellow")
text( 20,217,string.format("%08X %04X",rnd1,rnd2),rndcol)
text(290, 0,string.format(
"x: %4d\ny: %4d\ndx: %3d\ndy: %3d\nhp: %3d\nrun:%3d\ninv:%3d", "x: %4d\ny: %4d\ndx: %3d\ndy: %3d\nhp: %3d\nrun:%3d\ninv:%3d",
Xpos,Ypos,Xspd,Yspd,health,run,inv),"yellow" Xpos,Ypos,Xspd,Yspd,health,run,inv)
) )
end end
@ -208,43 +245,38 @@ function Objects()
local base = GlobalBase+i*128 local base = GlobalBase+i*128
local flag2 = AND(rb(base+0x49),0x10) -- active local flag2 = AND(rb(base+0x49),0x10) -- active
if flag2==0x10 then if flag2==0x10 then
local xpos = rw(base+0x00) local xpos = rw (base+0x00)
local ypos = rw(base+0x02) local ypos = rw (base+0x02)
-- local anm = rl(base+0x20) local dmg = rb (base+0x10)
local dmg = rb(base+0x10) local type = rw (base+0x40)
local type = rw(base+0x40) local hp = rw (base+0x50)
local hp = rw(base+0x50) local cRAM = r24(base+0x75) -- pointer to 4 collision boxes per object
local cRAM = rw(base+0x76) -- pointer to 4 collision boxes per object local col = 0 -- collision color
local col = 0 -- collision color
local xscr = (xpos-camx)/div local xscr = (xpos-camx)/div
local yscr = (ypos-camy)/div local yscr = (ypos-camy)/div
if type==0 then
-- gui.text(xscr,yscr,string.format("%X",anm))
end
for boxx=0,4 do for boxx=0,4 do
local x1 = (rws(cRAM+boxx*8+0)-camx)/div local x1 = (rws(cRAM+boxx*8+0)-camx)/div
local y1 = (rws(cRAM+boxx*8+2)-camy)/div local y1 = (rws(cRAM+boxx*8+2)-camy)/div
local x2 = (rws(cRAM+boxx*8+4)-camx)/div local x2 = (rws(cRAM+boxx*8+4)-camx)/div
local y2 = (rws(cRAM+boxx*8+6)-camy)/div local y2 = (rws(cRAM+boxx*8+6)-camy)/div
if boxx==0 then if boxx==0 then
col = 0xff00ff00 -- body col = 0xff00ff00 -- body
if type==282 or type==258 then hp = 1 end -- archer hp doesn't matter if type==282 or type==258 then hp = 1 end -- archer hp doesn't matter
if hp>0 and type>0 then if hp>0 and type>0 then
text(x1+2,y1+1,string.format("%d",hp),col) text(x1+2,y1+1,string.format("%d",hp),col,0x88000000,"gens")
end end
elseif boxx==1 then elseif boxx==1 then
col = 0xffffff00 -- floor col = 0xffffff00 -- floor
elseif boxx==2 then elseif boxx==2 then
if dmg>0 then if dmg>0
col = 0xffff0000 -- projectile then col = 0xffff0000 -- projectile
else else col = 0xff8800ff -- item
col = 0xff8800ff -- item
end end
if dmg>0 then if dmg>0 then
text(x1+2,y2+1,string.format("%d",dmg),col) text(x1+2,y2+1,string.format("%d",dmg),col,0x88000000,"gens")
end end
else else
col = 0xffffffff -- other col = 0xffffffff -- other
end end
if x1~=0x8888 and x2<320 and x1>0 and y2<224 and y1>0 then if x1~=0x8888 and x2<320 and x1>0 and y2<224 and y1>0 then
box(x1,y1,x2,y2,col) box(x1,y1,x2,y2,col)
@ -259,10 +291,10 @@ function PlayerBoxes()
xx = (Xpos-camx)/div xx = (Xpos-camx)/div
yy = (Ypos-camy)/div yy = (Ypos-camy)/div
local col = 0xff00ffff local col = 0xff00ffff
local swcol = col -- usual detection local swcol = col -- usual detection
if Yspd>0 then -- gimme swings to grab!!! if Yspd>0 then -- gimme swings to grab!
swcol = 0xff00ff00 swcol = 0xff00ff00
elseif Yspd==0 then -- can tell that too elseif Yspd==0 then -- can tell that too
swcol = 0xffffffff swcol = 0xffffffff
end end
if facing==2 then if facing==2 then
@ -279,7 +311,16 @@ function PlayerBoxes()
-- box(xx -1,yy+0x10/div-1,xx +1,yy+0x10/div+1,col) -- ground -- box(xx -1,yy+0x10/div-1,xx +1,yy+0x10/div+1,col) -- ground
end end
--event.onframeend(main) event.onframeend(function()
emu.setislagged(rb(0xfff6d4)==0)
if rb(0xfff6d4)==0 then
lagcount = lagcount+1
framecol = "red"
else
framecol = "white"
end
emu.setlagcount(lagcount)
end)
while true do while true do
main() main()