Fixed bug when za* addressing is not evaluated for size.

This commit is contained in:
g012 2017-09-20 00:35:46 +02:00
parent cc1c6f74ec
commit 3e5d4ee9ff
4 changed files with 86 additions and 56 deletions

View File

@ -53,6 +53,7 @@ M.link = function()
for chunk_ix,chunk in ipairs(location.chunks) do
if chunk.start <= section.org and chunk.size - (section.org - chunk.start) >= section.size then
chunk_reserve(chunk_ix, chunk, section.org, section.size)
symbols[section.label] = section.org
goto chunk_located
end
end
@ -476,11 +477,10 @@ for k,_ in pairs(opzab) do
if x >= -32768 and x <= 0xffff then return M[k .. 'abs'](late, early) end
error("value out of word range: " .. x)
end
local eval, asbin
local abs = opabs[k]
local ins = { size=eval, cycles=abs.cycles, asbin=asbin }
eval = function()
local r,x = pcall(late(early or 0))
local ins = { cycles=abs.cycles }
ins.size = function()
local r,x = pcall(late, early or 0)
if not r then return 3 end
x = word_normalize(x)
local zpg = opzpg[k]
@ -494,7 +494,7 @@ for k,_ in pairs(opzab) do
ins.asbin = function(b) b[#b+1]=abs.opc b[#b+1]=x&0xff b[#b+1]=x>>8 end
return 3
end
asbin = function(b)
ins.asbin = function(b)
local x = word_normalize(late(early or 0))
-- since we assumed absolute on link phase, we must generate absolute in binary
if x <= 0xff and opzpg[k] then print("warning: forcing abs on zpg operand for opcode " .. k) end
@ -539,11 +539,10 @@ for k,_ in pairs(opzax) do
if x >= -32768 and x <= 0xffff then return M[k .. 'abx'](late, early) end
error("value out of word range: " .. x)
end
local eval, asbin
local abx = opabx[k]
local ins = { size=eval, cycles=abx.cycles, asbin=asbin }
eval = function()
local r,x = pcall(late(early or 0))
local ins = { cycles=abx.cycles }
ins.size = function()
local r,x = pcall(late, early or 0)
if not r then return 3 end
x = word_normalize(x)
local zpx = opzpx[k]
@ -557,7 +556,7 @@ for k,_ in pairs(opzax) do
ins.asbin = function(b) b[#b+1]=abx.opc b[#b+1]=x&0xff b[#b+1]=x>>8 end
return 3
end
asbin = function(b)
ins.asbin = function(b)
local x = word_normalize(late(early or 0))
-- since we assumed absolute on link phase, we must generate absolute in binary
if x <= 0xff and opzpx[k] then print("warning: forcing abx on zpx operand for opcode " .. k) end
@ -601,11 +600,10 @@ for k,_ in pairs(opzay) do
if x >= -32768 and x <= 0xffff then return M[k .. 'aby'](late, early) end
error("value out of word range: " .. x)
end
local eval, asbin
local aby = opaby[k]
local ins = { size=eval, cycles=aby.cycles, asbin=asbin }
eval = function()
local r,x = pcall(late(early or 0))
local ins = { cycles=aby.cycles }
ins.size = function()
local r,x = pcall(late, early or 0)
if not r then return 3 end
x = word_normalize(x)
local zpy = opzpy[k]
@ -619,7 +617,7 @@ for k,_ in pairs(opzay) do
ins.asbin = function(b) b[#b+1]=aby.opc b[#b+1]=x&0xff b[#b+1]=x>>8 end
return 3
end
asbin = function(b)
ins.asbin = function(b)
local x = word_normalize(late(early or 0))
-- since we assumed absolute on link phase, we must generate absolute in binary
if x <= 0xff and opzpy[k] then print("warning: forcing aby on zpy operand for opcode " .. k) end

19
asm.l65
View File

@ -4,7 +4,18 @@ TIM_OVERSCAN = 50 -- TIM64T, 3200 cycles = ~ 42 scanlines
TIM_VBLANK = 61 -- TIM64T, 3904 cycles = ~ 51 scanlines
TIM_KERNEL = 17 -- T1024T, 17408 cycles = ~229 scanlines
location(0xf000, 0xffff)
function switchbank(i) bit 0x1ff4+i end
-- create bank stubs
for bi=0,7,1 do
local o=(bi<<12)
_ENV['bank' .. bi] = location(0x8000+o, 0x8fff+o)
section{"entry"..bi, org=0x8fee+o} switchbank(0) jmp main
section{"switchtab"..bi, org=0x8ff4+o} byte(0,0,0,0,0,0,0,0)
section{"vectors"..bi, org=0x8ffc+o} word(0xffee,0xffee)
end
location(bank0)
--location(0xf000, 0xffff)
if toto ~= 15 then end
@ -42,6 +53,9 @@ charset()
ptr_table("ptrs", message, data, 0)
@@main
lda #0
--section{ "toto", align = 256, offset = 16 }
--section{ "toto", org = 0xf100 }
--section "waitForIntim"
@ -74,7 +88,7 @@ ptr_table("ptrs", message, data, 0)
-- 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 })
--[[
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
@ -86,6 +100,7 @@ ptr_table("ptrs", message, data, 0)
lda !_toto+15,16,x
lda #15
#pragma encapsulate on
]]
samepage
lda #0xac

89
asm.lua
View File

@ -4,7 +4,18 @@ TIM_OVERSCAN = 50 -- TIM64T, 3200 cycles = ~ 42 scanlines
TIM_VBLANK = 61 -- TIM64T, 3904 cycles = ~ 51 scanlines
TIM_KERNEL = 17 -- T1024T, 17408 cycles = ~229 scanlines
location(0xf000, 0xffff)
function switchbank(i) bitzab(function(_o) return _o+( 0x1ff4+i) end) end
-- create bank stubs
for bi=0,7,1 do
local o=(bi<<12)
_ENV['bank' .. bi] = location(0x8000+o, 0x8fff+o)
section{"entry"..bi, org=0x8fee+o} switchbank(0) jmpabs(function(_o) return _o+( main) end)
section{"switchtab"..bi, org=0x8ff4+o} byte(0,0,0,0,0,0,0,0)
section{"vectors"..bi, org=0x8ffc+o} word(0xffee,0xffee)
end
location(bank0)
--location(0xf000, 0xffff)
if toto ~= 15 then end
@ -42,6 +53,9 @@ section("data")
ptr_table("ptrs", message, data, 0)
section("main")
ldaimm (function(_o) return _o+(0) end)
--section{ "toto", align = 256, offset = 16 }
--section{ "toto", org = 0xf100 }
--section "waitForIntim"
@ -49,56 +63,59 @@ section("waitForIntim") --alt short syntax when no other option
-- n_{ a=INTIM } ?
--lda(INTIM) -- or a=INTIM
--bne "waitForIntim"
ldximm (function(o) return o+(0xf0) end)
ldximm (function(o) return o+(13) end)
ldyimm (function(o) return o+(0xAB - 16 + 27 & 3 | 6 ~ 0xf >> ~3 << 1 // 5) end)
ldximm (function(o) return o+(15) end,3)
ldximm (function(_o) return _o+(0xf0) end)
ldximm (function(_o) return _o+(13) end)
ldyimm (function(_o) return _o+(0xAB - 16 + 27 & 3 | 6 ~ 0xf >> ~3 << 1 // 5) end)
ldximm (function(_o) return _o+(15) end,3)
local kernel_cycles,kernel_size
table.insert(section_current.instructions, { asbin=function() kernel_cycles=cycles kernel_size=size end })
ldazab(function(o) return o+( data) end)
ldazab(function(o) return o+( data) end,5)
ldazax(function(o) return o+( data) end,5)
ldaaby(function(o) return o+( data) end,5)
ldazab(function(o) return o+( data+3) end,12)
ldazax(function(o) return o+( data+3) end,12)
ldaaby(function(o) return o+( data+3) end,12)
ldainx (function(o) return o+(VBLANK) end,5)
ldazab(function(_o) return _o+( data) end)
ldazab(function(_o) return _o+( data) end,5)
ldazax(function(_o) return _o+( data) end,5)
ldaaby(function(_o) return _o+( data) end,5)
ldazab(function(_o) return _o+( data+3) end,12)
ldazax(function(_o) return _o+( data+3) end,12)
ldaaby(function(_o) return _o+( data+3) end,12)
ldainx (function(_o) return _o+(VBLANK) end,5)
ldainx (function(a) return a+2 end,VBLANK)
ldainy (function(o) return o+(VBLANK) end,5)
ldainy (function(_o) return _o+(VBLANK) end,5)
ldainy (function(a) return a&3 end,VBLANK)
jmpind (function(o) return o+(VBLANK) end)
jmpind (function(o) return o+(VBLANK) end,12)
jmpind (function(o) return o+(VBLANK-4) end)
jmpind (function(_o) return _o+(VBLANK) end)
jmpind (function(_o) return _o+(VBLANK) end,12)
jmpind (function(_o) return _o+(VBLANK-4) end)
-- 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 })
ldazab( function(c) return data * c end, v)
ldazab( function(c) return data*c end, v)
local f = function(c) return data*c end v=5 ldazab(f,v) v=12 ldazab(f,v)
--[[
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
ldazab(g(),v)
ldazab( f,v)
ldazax (function(o) return o+(_toto+15) end,16)
ldaimm (15)
lda !g(),v
#pragma encapsulate off
lda f,v
lda !_toto+15,16,x
lda #15
#pragma encapsulate on
]]
do samepage()
ldaimm (function(o) return o+(0xac) end)
ldaimm (function(o) return o+(VBLANK) end)
ldazab(function(o) return o+( 0xbeef) end)
ldazab(function(o) return o+( VBLANK) end)
ldaabs(function(o) return o+( VBLANK) end)
ldazax(function(o) return o+( VBLANK) end)
ldaaby(function(o) return o+( VBLANK) end)
ldainx (function(o) return o+(VBLANK) end)
ldainy (function(o) return o+(VBLANK) end) endpage()
ldaimm (function(_o) return _o+(0xac) end)
ldaimm (function(_o) return _o+(VBLANK) end)
ldazab(function(_o) return _o+( 0xbeef) end)
ldazab(function(_o) return _o+( VBLANK) end)
ldaabs(function(_o) return _o+( VBLANK) end)
ldazax(function(_o) return _o+( VBLANK) end)
ldaaby(function(_o) return _o+( VBLANK) end)
ldainx (function(_o) return _o+(VBLANK) end)
ldainy (function(_o) return _o+(VBLANK) end) endpage()
end
aslimp()
aslzab(function(o) return o+( VBLANK) end)
aslzab(function(_o) return _o+( VBLANK) end)
aslimp()
label("_toto")
bnerel( "_toto")
@ -106,7 +123,7 @@ label("_toto")
f=function() return "_toto" end bnerel( f())
bnerel( "_toto")
jamimp() aslimp() lsrimp() ldximm (function(o) return o+(16) end) ldyzab(function(o) return o+( 0xf0f0) end)
jamimp() aslimp() lsrimp() ldximm (function(_o) return _o+(16) end) ldyzab(function(_o) return _o+( 0xf0f0) end)
rtsimp()
writebin()

View File

@ -1217,7 +1217,7 @@ local function ParseLua(src)
local inner_add = {
AstType='BinopExpr', Op='+', OperatorPrecedence=10, Tokens={ t('Symbol', '+') },
Lhs = {
AstType='VarExpr', Name='o', Variable={ IsGlobal=false, Name='o', Scope=inner_call_scope }, Tokens={ t('Ident', 'o', {space}) }
AstType='VarExpr', Name='_o', Variable={ IsGlobal=false, Name='_o', Scope=inner_call_scope }, Tokens={ t('Ident', '_o', {space}) }
},
Rhs = {
AstType='Parentheses', Inner=args[1], Tokens={ t('Symbol', '('), t('Symbol', ')') }
@ -1230,8 +1230,8 @@ local function ParseLua(src)
}
local inner_call = {
AstType='Function', VarArg=false, IsLocal=true, Scope=inner_call_scope, Body=inner_call_body,
Arguments={ { IsGlobal=false, Name='o', Scope=inner_call_scope } },
Tokens={ t('Keyword', 'function'), t('Symbol', '('), t('Ident', 'o'), t('Symbol', ')'), t('Keyword', 'end', {space}) }
Arguments={ { IsGlobal=false, Name='_o', Scope=inner_call_scope } },
Tokens={ t('Keyword', 'function'), t('Symbol', '('), t('Ident', '_o'), t('Symbol', ')'), t('Keyword', 'end', {space}) }
}
args[1] = inner_call
end