User File #51619579062148959

Upload All User Files

#51619579062148959 - NES Donald Land - Terrain script

DL_Terrain_v1.lua
Game: Donald Land ( NES, see all files )
594 downloads
Uploaded 12/3/2018 4:26 PM by FatRatKnight (see all 245)
Shows terrain boxes. Has an incomplete thing I was trying, the list of special terrain IDs are at the top, but that table wasn't used. Has something else I hacked together to show special IDs I'm looking for instead, rather critical in attacking the Sky World boss where I wasn't supposed to.
Colored boxes are used to point out bits of terrain I'm not sure about. Otherwise, the white boxes are close to accurate of what I think they are. Busies up the emulator a bit.
local SpecialIDs={
  {}, -- 1, no specials
  {}, -- 2, no specials
  {0x7A}, -- 3, Touch a tile to finish
  {}, -- 4, Boss hit tiles
  {0x79}, -- 5, Touch a tile to finish
  {0x38}, -- 6, Touch a tile to finish
  {}, -- 7
  {}, -- 8
  {0x30,0x83}, -- 9
  {}, --10
  {}, --11
  {0x30,0x7A,0xBD,0xBE,0xBF,0xC0,0xC1}  --12  B7 65  A8 A9 AA
}


local r1u_ , r1s_= memory.read_u8 , memory.read_s8
local r1u= function(a) return r1u_(a,"System Bus") end
local r1s= function(a) return r1s_(a,"System Bus") end
local R1U= function(a) return r1u_(a,"PRG ROM") end
local r2u= function(a,b) return r1u(a) + r1u(b or a+1)*256 end

local Rect= gui.drawRectangle

local Tiles= {
[0]= function(x,y) end, --0:empty
function(x,y) Rect(x  ,y  ,15,15,0xFFFFFFFF,0x40FFFFFF) end, --1: :: Solid
function(x,y) Rect(x  ,y+8,15, 7,0xFFFFFFFF,0x40FFFFFF) end, --2: '' Upper
function(x,y) Rect(x  ,y  ,15, 7,0xFFFFFFFF,0x40FFFFFF) end, --3: .. Under
function(x,y) Rect(x  ,y  , 7,15,0xFFFFFFFF,0x40FFFFFF) end, --4: :  Left
function(x,y) Rect(x+8,y  , 7,15,0xFFFFFFFF,0x40FFFFFF) end, --5:  : Right
function(x,y) Rect(x  ,y  ,15,15,0xFF0000FF,0x40FF00FF) end, --6:?
function(x,y) Rect(x  ,y  ,15,15,0xFFFFFF00,0x40FF00FF) end, --7:?
function(x,y) Rect(x+4,y+8,11, 7,0xFFFFFFFF,0x40FFFFFF) end, --8:  . Down-right
function(x,y) Rect(x  ,y  ,15,15,0xFF00FFFF,0x40FF00FF) end, --9:?
function(x,y) Rect(x+8,y  , 7, 7,0xFFFFFFFF,0x40FFFFFF)
              Rect(x  ,y+8,15, 7,0xFFFFFFFF,0x40FFFFFF) end, --A: .:
function(x,y) Rect(x  ,y  , 7, 7,0xFFFFFFFF,0x40FFFFFF)
              Rect(x  ,y+8,15, 7,0xFFFFFFFF,0x40FFFFFF) end, --B: :.
function(x,y) Rect(x  ,y  , 7, 7,0xFFFFFFFF,0x40FFFFFF) end, --C: '  Up-left
function(x,y) Rect(x  ,y  ,15,15,0xFFFFFF00,0x4000FF00) end, --D:?
function(x,y) Rect(x  ,y  ,15,15,0xFFFF00FF,0x4000FF00) end, --E:?
function(x,y) Rect(x  ,y  ,15,15,0xFF00FFFF,0x4000FF00) end, --F:?
}

local Banks= { --Based on stage, it seems "arbitrary".
  0x0C000,0x00000,0x00000,0x04000,  --Got these through an advanced method.
  0x08000,0x00000,0x04000,0x0C000,  --The "guess and check" method.
  0x04000,0x08000,0x0C000,0x08000   --Fear my powers of analysis!
}
--local TgtTiles= {[0x30]=true,[0x7A]=true,
--                 [0xBD]=true,[0xBE]=true,
--                 [0xBF]=true,[0xC0]=true,[0xC1]=true}
local TgtTiles= {[0x1A]=true,[0x1B]=true,
                 [0x20]=true,[0x21]=true,[0x79]=true}

--*****************************************************************************
local function TerrainData()
--*****************************************************************************
    local CamX= r2u(0x00CC)
    local Stage=r1u(0x0051)
    if not Banks[Stage] then return end
    local Ptr=  r2u(0x0082) - 0x8000 + Banks[Stage]
    for y= -2, 12 do
        local Y= 32 + 16*y
        for x= 0, 16 do
            local X= x*16 - CamX%16
            local r= math.floor(CamX/16 + x)
            local a= 0x0240 + r%16 + (y%16)*16
            if r%32 >= 16 then a= a+0xF0 end
            local terrain_ID= r1u(a)

            local info= R1U(Ptr + terrain_ID*2 + 0)
            Tiles[bit.band(info,0x0F)](X,Y)
            if TgtTiles[terrain_ID] then
                gui.pixelText(X,Y,string.format("%02X",terrain_ID))
            end
        end
    end
end

while true do TerrainData(); emu.frameadvance() end