diff --git a/l65.lua b/l65.lua index a668ac0..2e8bbe8 100644 --- a/l65.lua +++ b/l65.lua @@ -2462,29 +2462,25 @@ local function Format65(ast) return table.concat(out.rope) end -if #arg ~= 2 then - print("Invalid arguments, usage:\nl65 source destination") - return +local l65searcher = function(name) + local dirsep = package.config:sub(1,1) + local filename,err = package.searchpath(name, string.format(".%s?;.%s?.l65", dirsep, dirsep), '.', '.') + if not filename then return end + local file = io.open(filename, 'rb') + if not file then return "failed to open " .. filename .. " for reading" end + local src = file:read('*all') + file:close() + local st, ast = ParseLua(src) + if not st then print(ast) return end + local bc = assert(load(Format65(ast), filename)) + return bc, filename end +table.insert(package.searchers, 2, l65searcher) -local inf = io.open(arg[1], 'r') -if not inf then - print("Failed to open '"..arg[1].."' for reading") +if #arg ~= 1 then + print("Invalid arguments, usage:\nl65 ") return end -local outf = io.open(arg[2], 'w') -if not outf then - print("Failed to open '"..arg[2].."' for writing") - return -end - -local sourceText = inf:read('*all') -inf:close() -local st, ast = ParseLua(sourceText) -if not st then - print(ast) - return -end - -outf:write(Format65(ast)) -outf:close() +local inf,dirsep = arg[1],package.config:sub(1,1) +local fn='' for i=#inf,1,-1 do local c=inf:sub(i,i) if c==dirsep or c=='/' then break end fn=c..fn if c=='.' then fn='' end end filename=fn +require(arg[1]) diff --git a/samples/vcs1.l65 b/samples/vcs1.l65 index 3bde92c..9e7e3b8 100644 --- a/samples/vcs1.l65 +++ b/samples/vcs1.l65 @@ -27,7 +27,6 @@ local wait = function() local l=label() lda INTIM bne l end lda#TIM_KERNEL sta T1024T kernel() wait() jmp main -local filename=string.match(arg[0], ".-([^\\/]-)%.?[^%.\\/]*$") writebin(filename..'.bin') writesym(filename..'.sym') print(stats) diff --git a/vcs.lua b/vcs.l65 similarity index 97% rename from vcs.lua rename to vcs.l65 index 218d30b..7d54074 100644 --- a/vcs.lua +++ b/vcs.l65 @@ -84,8 +84,6 @@ do for k,v in pairs(vcs) do symbols[k] = v end end ---[[ TODO enable this when lua load() is changed - mappers = {} mappers['2K'] = function() @@ -178,7 +176,7 @@ mappers.F0 = function() end end -local function bank_stubs2 = function(hotspot0, hotspot1) +local bank_stubs2 = function(hotspot0, hotspot1) function switchrom(i) if i==0 then bit hotspot0 elseif i==1 then bit hotspot1 @@ -193,11 +191,9 @@ local function bank_stubs2 = function(hotspot0, hotspot1) end end mappers.UA = function() bank_stubs2(0x220, 0x240) end -mappers.['0840'] = function() bank_stubs2(0x800, 0x840) end +mappers['0840'] = function() bank_stubs2(0x800, 0x840) end mappers['3E'] = function(rom_count, ram_count) mappers['3F'](rom_count) function switchram(i) assert(i>=0 and i