From 74164a2897048f0352ca7a31ba5947db55aad773 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 10 May 2015 15:01:51 -0700 Subject: [PATCH] reduce globals, more refactoring --- Lua/addrs/addrs.lua | 38 ++++++++++++++++++++++++++++++++ Lua/addrs/init.lua | 53 ++++++++------------------------------------- 2 files changed, 47 insertions(+), 44 deletions(-) create mode 100755 Lua/addrs/addrs.lua mode change 100755 => 100644 Lua/addrs/init.lua diff --git a/Lua/addrs/addrs.lua b/Lua/addrs/addrs.lua new file mode 100755 index 0000000..6e3429c --- /dev/null +++ b/Lua/addrs/addrs.lua @@ -0,0 +1,38 @@ +local basics = require "addrs.basics" +local versions = require "addrs.versions" + +local same = { + ["O JP10"] = "O US10", + ["O JP11"] = "O US11", + ["O JP12"] = "O US12", + --["O JPGC MQ"] = "O USGC", -- maybe? +} + +return function(hash) + local version = versions[hash] or VERSION_OVERRIDE + if version == nil then + print('ERROR: unknown rom') + return + end + local v = version:sub(1, 2) + local rv = same[version] or version + + local b = basics[rv] + function AL(a, s) return A(b.link + a, s) end + function AG(a, s) + if rv == 'M JP10' or rv == 'M JP11' then + if a >= 0x17000 then -- approximate + a = a - 0x20 + end + end + return A(b.global + a, s) + end + function AA(a, s) return A(b.actor + a, s) end + + local addrs = require("addrs."..rv) + addrs.version = version + addrs.oot = v == "O " + addrs.mm = v == "M " + local common = require("addrs."..v.."common") + return setmetatable(addrs, {__index=common}) +end diff --git a/Lua/addrs/init.lua b/Lua/addrs/init.lua old mode 100755 new mode 100644 index 52357ad..85a686d --- a/Lua/addrs/init.lua +++ b/Lua/addrs/init.lua @@ -1,44 +1,9 @@ -local basics = require "addrs.basics" -local versions = require "addrs.versions" - -local same = { - ["O JP10"] = "O US10", - ["O JP11"] = "O US11", - ["O JP12"] = "O US12", - --["O JPGC MQ"] = "O USGC", -- maybe? -} - -hash = gameinfo.getromhash() -- TODO: send as argument - -version = versions[hash] or _version_override - -if version == nil then - print('ERROR: unknown rom') - return -end - -local v = version:sub(1, 2) -oot = v == "O " -mm = v == "M " - -local rv = same[version] or version - -local b = basics[rv] -function AL(a, s) return A(b.link + a, s) end -function AG(a, s) - if rv == 'M JP10' or rv == 'M JP11' then - if a >= 0x17000 then -- approximate - a = a - 0x20 - end - end - return A(b.global + a, s) -end -function AA(a, s) return A(b.actor + a, s) end - -addrs = require("addrs."..rv) - -local common = require("addrs."..v.."common") - -setmetatable(addrs, {__index=common}) - -return addrs +-- deprecated +local hash = gameinfo.getromhash() +local Game = require "addrs.addrs" +local game = Game(hash) +version = game.version +oot = game.oot +mm = game.mm +addrs = game +return game