Difference between revisions of "Module:Address"
From ALttP Speedrunning Wiki
Line 9: | Line 9: | ||
local addr10 = tonumber(HEX._convert(addr, 10, 16)) | local addr10 = tonumber(HEX._convert(addr, 10, 16)) | ||
local addr10short = addr10 % 0x10000 | local addr10short = addr10 % 0x10000 | ||
− | local bank = (addr10 - | + | local bank = (addr10 - addr10short) / 0x10000 |
local size = args[2] or 1 | local size = args[2] or 1 | ||
local size10 = tonumber(HEX._convert(size, 10, 16)) | local size10 = tonumber(HEX._convert(size, 10, 16)) |
Revision as of 14:34, 7 April 2019
Documentation for this module may be created at Module:Address/doc
local p = {} local HEX = require('Module:Base convert') function p.main(frame) local args = frame:getParent().args local addr = args[1] or 'FF' local addr10 = tonumber(HEX._convert(addr, 10, 16)) local addr10short = addr10 % 0x10000 local bank = (addr10 - addr10short) / 0x10000 local size = args[2] or 1 local size10 = tonumber(HEX._convert(size, 10, 16)) local ret = mw.html.create('code') local title = '' local length = 0 if addr10short <= 0xFF then title = 'Direct Page address' length = 2 elseif addr10short <= 0x1FFF then title = 'Short address' length = 4 elseif addr10short <= 0x7FFF then title = 'Hardware register' length = 4 else title = string.format('Long address $%06X; Bank %02X') length = 6 end ret:title(title) ret:wikitext(string.format('$%0'..length..'X', addr10)) return ret end return p