mirror of
https://github.com/g012/l65.git
synced 2024-06-02 12:41:28 +00:00
Added local label references resolver.
This commit is contained in:
parent
3e5d4ee9ff
commit
86d46f101e
9
6502.lua
9
6502.lua
|
@ -131,6 +131,13 @@ M.resolve = function()
|
||||||
elseif t == 'string' then symbols[k]=symbols[v] count=count+1 end
|
elseif t == 'string' then symbols[k]=symbols[v] count=count+1 end
|
||||||
end end
|
end end
|
||||||
stats.resolved_count = count
|
stats.resolved_count = count
|
||||||
|
|
||||||
|
-- set local label references resolver
|
||||||
|
local llresolver = { __index = function(tab,key)
|
||||||
|
if type(key) ~= 'string' or key:sub(1,1) ~= '_' then return nil end
|
||||||
|
return symbols[M.label_current .. key]
|
||||||
|
end }
|
||||||
|
setmetatable(symbols, llresolver)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.genbin = function(filler)
|
M.genbin = function(filler)
|
||||||
|
@ -152,6 +159,7 @@ M.genbin = function(filler)
|
||||||
for _,section in ipairs(sections) do
|
for _,section in ipairs(sections) do
|
||||||
assert(section.org >= #bin+of0)
|
assert(section.org >= #bin+of0)
|
||||||
for i=#bin+of0,section.org-1 do ins(bin, filler) end
|
for i=#bin+of0,section.org-1 do ins(bin, filler) end
|
||||||
|
M.label_current = section.label
|
||||||
for _,instruction in ipairs(section.instructions) do
|
for _,instruction in ipairs(section.instructions) do
|
||||||
local b,f = instruction.bin,instruction.asbin
|
local b,f = instruction.bin,instruction.asbin
|
||||||
if b then mov(b,1,#b,#bin+1,bin)
|
if b then mov(b,1,#b,#bin+1,bin)
|
||||||
|
@ -253,6 +261,7 @@ M.label = function(name)
|
||||||
name = M.label_current .. name
|
name = M.label_current .. name
|
||||||
else
|
else
|
||||||
M.label_current = name
|
M.label_current = name
|
||||||
|
label.asbin = function() M.label_current = name end
|
||||||
end
|
end
|
||||||
if symbols[name] then error("duplicate symbol: " .. name) end
|
if symbols[name] then error("duplicate symbol: " .. name) end
|
||||||
symbols[name] = label
|
symbols[name] = label
|
||||||
|
|
13
asm.l65
13
asm.l65
|
@ -88,11 +88,12 @@ ptr_table("ptrs", message, data, 0)
|
||||||
|
|
||||||
-- cycles are counted without taking any branch
|
-- cycles are counted without taking any branch
|
||||||
table.insert(section_current.instructions, { asbin=function() print('kernel cycles: ', cycles-kernel_cycles, 'kernel size: ', size-kernel_size) end })
|
table.insert(section_current.instructions, { asbin=function() print('kernel cycles: ', cycles-kernel_cycles, 'kernel size: ', size-kernel_size) end })
|
||||||
--[[
|
|
||||||
lda function(c) return data * c end, v
|
v=7
|
||||||
lda \c(data*c), v
|
lda function(c) return 0xffff&(data * c) end, v
|
||||||
local f = \c(data*c) v=5 lda !f,v v=12 lda !f,v
|
lda \c((data*c)&0xffff), v
|
||||||
local g = function() return function(c) return data * c end end
|
local f = \c((data*c)&0xffff) v=5 lda !f,v v=3 lda !f,v
|
||||||
|
local g = function() return function(c) return (data * c)&0xffff end end
|
||||||
|
|
||||||
lda !g(),v
|
lda !g(),v
|
||||||
#pragma encapsulate off
|
#pragma encapsulate off
|
||||||
|
@ -100,7 +101,6 @@ ptr_table("ptrs", message, data, 0)
|
||||||
lda !_toto+15,16,x
|
lda !_toto+15,16,x
|
||||||
lda #15
|
lda #15
|
||||||
#pragma encapsulate on
|
#pragma encapsulate on
|
||||||
]]
|
|
||||||
|
|
||||||
samepage
|
samepage
|
||||||
lda #0xac
|
lda #0xac
|
||||||
|
@ -114,6 +114,7 @@ ptr_table("ptrs", message, data, 0)
|
||||||
lda (VBLANK),y
|
lda (VBLANK),y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
beq _toto
|
||||||
asl
|
asl
|
||||||
asl VBLANK
|
asl VBLANK
|
||||||
asl
|
asl
|
||||||
|
|
23
asm.lua
23
asm.lua
|
@ -88,19 +88,17 @@ section("waitForIntim") --alt short syntax when no other option
|
||||||
|
|
||||||
-- cycles are counted without taking any branch
|
-- cycles are counted without taking any branch
|
||||||
table.insert(section_current.instructions, { asbin=function() print('kernel cycles: ', cycles-kernel_cycles, 'kernel size: ', size-kernel_size) end })
|
table.insert(section_current.instructions, { asbin=function() print('kernel cycles: ', cycles-kernel_cycles, 'kernel size: ', size-kernel_size) end })
|
||||||
--[[
|
|
||||||
lda function(c) return data * c end, v
|
|
||||||
lda \c(data*c), v
|
|
||||||
local f = \c(data*c) v=5 lda !f,v v=12 lda !f,v
|
|
||||||
local g = function() return function(c) return data * c end end
|
|
||||||
|
|
||||||
lda !g(),v
|
v=7
|
||||||
#pragma encapsulate off
|
ldazab( function(c) return 0xffff&(data * c) end, v)
|
||||||
lda f,v
|
ldazab( function(c) return (data*c)&0xffff end, v)
|
||||||
lda !_toto+15,16,x
|
local f = function(c) return (data*c)&0xffff end v=5 ldazab(f,v) v=3 ldazab(f,v)
|
||||||
lda #15
|
local g = function() return function(c) return (data * c)&0xffff end end
|
||||||
#pragma encapsulate on
|
|
||||||
]]
|
ldazab(g(),v)
|
||||||
|
ldazab( f,v)
|
||||||
|
ldazax (function(_o) return _o+(_toto+15) end,16)
|
||||||
|
ldaimm (15)
|
||||||
|
|
||||||
do samepage()
|
do samepage()
|
||||||
ldaimm (function(_o) return _o+(0xac) end)
|
ldaimm (function(_o) return _o+(0xac) end)
|
||||||
|
@ -114,6 +112,7 @@ section("waitForIntim") --alt short syntax when no other option
|
||||||
ldainy (function(_o) return _o+(VBLANK) end) endpage()
|
ldainy (function(_o) return _o+(VBLANK) end) endpage()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
beqrel( "_toto")
|
||||||
aslimp()
|
aslimp()
|
||||||
aslzab(function(_o) return _o+( VBLANK) end)
|
aslzab(function(_o) return _o+( VBLANK) end)
|
||||||
aslimp()
|
aslimp()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user