From 0e9d298606e88f53850ebb47bd41aec65d1e7e83 Mon Sep 17 00:00:00 2001 From: g012 Date: Sun, 10 Sep 2017 00:11:21 +0200 Subject: [PATCH] Added vim syntax file for l65. --- 6502.lua | 9 ++ asm.l65 | 102 ++++++++++++++ asm.lua | 50 +++---- asm.min.lua | 24 ---- l65.vim | 375 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 511 insertions(+), 49 deletions(-) create mode 100644 asm.l65 delete mode 100644 asm.min.lua create mode 100644 l65.vim diff --git a/6502.lua b/6502.lua index 0776e6d..d3dc6c1 100644 --- a/6502.lua +++ b/6502.lua @@ -206,14 +206,23 @@ M.section = function(t) for _,instruction in ipairs(self.instructions) do -- TODO end + -- TODO update start and finish fields of constraints to actual addresses end end M.samepage = function() + local section = sections[#sections] + table.insert(section.constraints, { type='samepage', start=#section.instructions }) end M.crosspage = function() + local section = sections[#sections] + table.insert(section.constraints, { type='crosspage', start=#section.instructions }) end M.endpage = function() + local section = sections[#sections] + local constraint = section.constraints[#section.constraints] + assert(constraint and not constraint.finish, "closing constraint, but no constraint is open") + constraint.finish = #section.instructions end M.byte = function(...) diff --git a/asm.l65 b/asm.l65 new file mode 100644 index 0000000..0c28329 --- /dev/null +++ b/asm.l65 @@ -0,0 +1,102 @@ +dofile "vcs.lua" + +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) + +if toto ~= 15 then end + +abc = 13 ~ 0x7 +xyz = 1 << 2 + +x:f() +::lualabel:: + +#pragma syntax6502 off +lda = 5 if lda < 6 then print('yep') end +#pragma syntax6502 on + +--@@data samepage byte(1, 2) crosspage byte(3, 4) + +--section{ "toto", align = 256, offset = 16 } +--section{ "toto", org = 0xf100 } +section "waitForIntim" --alt short syntax when no other option: @@waitForIntim ? + -- n_{ a=INTIM } ? + --lda(INTIM) -- or a=INTIM + --bne "waitForIntim" + ldx #0xf0 + ldx #0b1101 + ldy #0xAB - 16 + 0b11011 & 3 | 6 ~ 0xf >> ~3 << 1 // 5 + + samepage + lda #0xac + lda #INTIM + lda 0xbeef + lda INTIM + lda.w INTIM + lda INTIM,x + lda INTIM,y + lda (INTIM,x) + lda (INTIM),y + end + + asl + asl INTIM + asl +@.toto + bne "test" + bne waitForIntim + bne f() + bne .toto + + jam asl lsr ldx #16 ldy 0xf0f0 + + rts + +--[[ +section "doOverscan" + sta{WSYNC} -- WSYNC=a + lda(2) sta{VBLANK} -- a=2 VBLANK=a + lda(TIM_OVERSCAN) sta{TIM64T} -- a=TIM_OVERSCAN TIM64T=a + jsr "waitForIntim" + +section "doVBlank" + lda(0x0e) + label ".vsyncLoop" + sta{WSYNC} + sta{VSYNC} + lsr() + bne ".vsyncLoop" + lda(2) + sta{VBLANK} + lda(TIM_VBLANK) + sta{TIM64T} + jsr "waitForIntim" + +section "doKernel" + lda(TIM_KERNEL) + sta{T1024T} + jsr "waitForIntim" + +section "start" + -- clear zeropage + cld() + ldx(0) + txa() + label ".clearLoop" + dex() + tsx() + pha() + bne ".clearLoop" + -- main + label "mainLoop" + jsr "doOverscan" + jsr "doVBlank" + jsr "doKernel" + jmp "mainLoop" + +section{ name="vectors", org=0xfffc } + word{ "start", "start" } + +]] diff --git a/asm.lua b/asm.lua index 0c28329..ae46831 100644 --- a/asm.lua +++ b/asm.lua @@ -13,9 +13,9 @@ xyz = 1 << 2 x:f() ::lualabel:: -#pragma syntax6502 off +; lda = 5 if lda < 6 then print('yep') end -#pragma syntax6502 on +; --@@data samepage byte(1, 2) crosspage byte(3, 4) @@ -25,34 +25,34 @@ section "waitForIntim" --alt short syntax when no other option: @@waitForIntim ? -- n_{ a=INTIM } ? --lda(INTIM) -- or a=INTIM --bne "waitForIntim" - ldx #0xf0 - ldx #0b1101 - ldy #0xAB - 16 + 0b11011 & 3 | 6 ~ 0xf >> ~3 << 1 // 5 + ldx_immediate(0xf0) + ldx_immediate(13) + ldy_immediate(0xAB - 16 + 27 & 3 | 6 ~ 0xf >> ~3 << 1 // 5) - samepage - lda #0xac - lda #INTIM - lda 0xbeef - lda INTIM - lda.w INTIM - lda INTIM,x - lda INTIM,y - lda (INTIM,x) - lda (INTIM),y + do samepage() + lda_immediate(0xac) + lda_immediate(INTIM) + lda_absolute( 0xbeef) + lda_absolute( INTIM) + lda_absolute_nozp( INTIM) + lda_absolute_x( INTIM) + lda_absolute_x( INTIM) + lda_indirect_x(INTIM) + lda_indirect_y(INTIM) endpage() end - asl - asl INTIM - asl -@.toto - bne "test" - bne waitForIntim - bne f() - bne .toto + asl_implied() + asl_absolute( INTIM) + asl_implied() +label_local("toto") + bne_relative( "test") + bne_relative( "waitForIntim") + bne_relative( f()) + bne_relative_local("toto") - jam asl lsr ldx #16 ldy 0xf0f0 + jam_implied() asl_implied() lsr_implied() ldx_immediate(16) ldy_absolute( 0xf0f0) - rts + rts_implied() --[[ section "doOverscan" diff --git a/asm.min.lua b/asm.min.lua deleted file mode 100644 index fc01c7b..0000000 --- a/asm.min.lua +++ /dev/null @@ -1,24 +0,0 @@ -dofile "vcs.lua" -TIM_OVERSCAN = 50 -TIM_VBLANK = 61 -TIM_KERNEL = 17 -location(0xf000, 0xffff) -section "waitForIntim" -ldx_immediate(0xf0) -lda_immediate(0xac) -lda_immediate(INTIM) -lda_absolute(0xbeef) -lda_absolute(INTIM) -lda_absolute_x(INTIM) -lda_absolute_x(INTIM) -lda_indirect_x(INTIM) -lda_indirect_y(INTIM) -asl_implied() -asl_absolute(INTIM) -asl_implied() -bne_relative("test") -bne_relative("waitForIntim") -bne_relative(f()) -bne_relative("_toto") -rts_implied() - diff --git a/l65.vim b/l65.vim new file mode 100644 index 0000000..3095c6b --- /dev/null +++ b/l65.vim @@ -0,0 +1,375 @@ +" Vim syntax file +" Language: Lua 4.0, Lua 5.0, Lua 5.1 and Lua 5.2 +" Maintainer: Marcus Aurelius Farias +" First Author: Carlos Augusto Teixeira Mendes +" Last Change: 2012 Aug 12 +" Options: lua_version = 4 or 5 +" lua_subversion = 0 (4.0, 5.0) or 1 (5.1) or 2 (5.2) +" default 5.2 + +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +if !exists("lua_version") + " Default is lua 5.2 + let lua_version = 5 + let lua_subversion = 2 +elseif !exists("lua_subversion") + " lua_version exists, but lua_subversion doesn't. So, set it to 0 + let lua_subversion = 0 +endif + +syn case match + +" syncing method +syn sync minlines=100 + +" Comments +syn keyword luaTodo contained TODO FIXME XXX +syn match luaComment "--.*$" contains=luaTodo,@Spell +if lua_version == 5 && lua_subversion == 0 + syn region luaComment matchgroup=luaComment start="--\[\[" end="\]\]" contains=luaTodo,luaInnerComment,@Spell + syn region luaInnerComment contained transparent start="\[\[" end="\]\]" +elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) + " Comments in Lua 5.1: --[[ ... ]], [=[ ... ]=], [===[ ... ]===], etc. + syn region luaComment matchgroup=luaComment start="--\[\z(=*\)\[" end="\]\z1\]" contains=luaTodo,@Spell +endif + +" First line may start with #! +syn match luaComment "\%^#!.*" + +syn region l65PreProc start="^#\s*\(pragma\>\)" skip="\\$" end="$" keepend + +" catch errors caused by wrong parenthesis and wrong curly brackets or +" keywords placed outside their respective blocks +syn region luaParen transparent start='(' end=')' contains=ALLBUT,luaParenError,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaBlock,luaLoopBlock,luaIn,luaStatement +syn region luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaBraceError,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaBlock,luaLoopBlock,luaIn,luaStatement + +syn match luaParenError ")" +syn match luaBraceError "}" +syn match luaError "\<\%(end\|else\|elseif\|then\|until\|in\)\>" + +" function ... end +syn region luaFunctionBlock transparent matchgroup=luaFunction start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn + +" if ... then +syn region luaIfThen transparent matchgroup=luaCond start="\" end="\"me=e-4 contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaIn nextgroup=luaThenEnd skipwhite skipempty + +" then ... end +syn region luaThenEnd contained transparent matchgroup=luaCond start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaThenEnd,luaIn + +" elseif ... then +syn region luaElseifThen contained transparent matchgroup=luaCond start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn + +" else +syn keyword luaElse contained else + +" do ... end +syn region luaBlock transparent matchgroup=luaStatement start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn + +" samepage ... end +syn region luaBlock transparent matchgroup=luaStatement start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn +" crosspage ... end +syn region luaBlock transparent matchgroup=luaStatement start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn + +" repeat ... until +syn region luaLoopBlock transparent matchgroup=luaRepeat start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn + +" while ... do +syn region luaLoopBlock transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaIn nextgroup=luaBlock skipwhite skipempty + +" for ... do and for ... in ... do +syn region luaLoopBlock transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd nextgroup=luaBlock skipwhite skipempty + +syn keyword luaIn contained in + +" other keywords +syn keyword luaStatement return local break +if lua_version > 5 || (lua_version == 5 && lua_subversion >= 2) + syn keyword luaStatement goto + syn match luaLabel "::\I\i*::" +endif +syn keyword luaOperator and or not +syn keyword luaConstant nil +if lua_version > 4 + syn keyword luaConstant true false +endif + +" Strings +if lua_version < 5 + syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\[[:digit:]]\{,3}" +elseif lua_version == 5 + if lua_subversion == 0 + syn match luaSpecial contained #\\[\\abfnrtv'"[\]]\|\\[[:digit:]]\{,3}# + syn region luaString2 matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2,@Spell + else + if lua_subversion == 1 + syn match luaSpecial contained #\\[\\abfnrtv'"]\|\\[[:digit:]]\{,3}# + else " Lua 5.2 + syn match luaSpecial contained #\\[\\abfnrtvz'"]\|\\x[[:xdigit:]]\{2}\|\\[[:digit:]]\{,3}# + endif + syn region luaString2 matchgroup=luaString start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell + endif +endif +syn region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial,@Spell +syn region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial,@Spell + +" integer number +syn match luaNumber "\<\d\+\>" +" floating point number, with dot, optional exponent +syn match luaNumber "\<\d\+\.\d*\%([eE][-+]\=\d\+\)\=\>" +" floating point number, starting with a dot, optional exponent +syn match luaNumber "\.\d\+\%([eE][-+]\=\d\+\)\=\>" +" floating point number, without dot, with exponent +syn match luaNumber "\<\d\+[eE][-+]\=\d\+\>" + +" hex numbers +if lua_version >= 5 + if lua_subversion == 1 + syn match luaNumber "\<0[xX]\x\+\>" + elseif lua_subversion >= 2 + syn match luaNumber "\<0[xX][[:xdigit:].]\+\%([pP][-+]\=\d\+\)\=\>" + endif +endif + +syn keyword luaFunc assert collectgarbage dofile error next +syn keyword luaFunc print rawget rawset tonumber tostring type _VERSION + +if lua_version == 4 + syn keyword luaFunc _ALERT _ERRORMESSAGE gcinfo + syn keyword luaFunc call copytagmethods dostring + syn keyword luaFunc foreach foreachi getglobal getn + syn keyword luaFunc gettagmethod globals newtag + syn keyword luaFunc setglobal settag settagmethod sort + syn keyword luaFunc tag tinsert tremove + syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR + syn keyword luaFunc openfile closefile flush seek + syn keyword luaFunc setlocale execute remove rename tmpname + syn keyword luaFunc getenv date clock exit + syn keyword luaFunc readfrom writeto appendto read write + syn keyword luaFunc PI abs sin cos tan asin + syn keyword luaFunc acos atan atan2 ceil floor + syn keyword luaFunc mod frexp ldexp sqrt min max log + syn keyword luaFunc log10 exp deg rad random + syn keyword luaFunc randomseed strlen strsub strlower strupper + syn keyword luaFunc strchar strrep ascii strbyte + syn keyword luaFunc format strfind gsub + syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook +elseif lua_version == 5 + syn keyword luaFunc getmetatable setmetatable + syn keyword luaFunc ipairs pairs + syn keyword luaFunc pcall xpcall + syn keyword luaFunc _G loadfile rawequal require + if lua_subversion == 0 + syn keyword luaFunc getfenv setfenv + syn keyword luaFunc loadstring unpack + syn keyword luaFunc gcinfo loadlib LUA_PATH _LOADED _REQUIREDNAME + else + syn keyword luaFunc load select + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + if lua_subversion == 1 + syn keyword luaFunc getfenv setfenv + syn keyword luaFunc loadstring module unpack + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + elseif lua_subversion == 2 + syn keyword luaFunc _ENV rawlen + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + endif + syn match luaFunc /\/ + endif + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + if lua_subversion == 0 + syn match luaFunc /\/ + else + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + endif + if lua_subversion == 0 + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + elseif lua_subversion == 1 + syn match luaFunc /\/ + elseif lua_subversion == 2 + syn match luaFunc /\/ + syn match luaFunc /\/ + endif + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + if lua_subversion == 0 + syn match luaFunc /\/ + syn match luaFunc /\/ + else + if lua_subversion == 1 + syn match luaFunc /\/ + endif + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + endif + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + if lua_subversion == 1 + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + elseif lua_subversion == 2 + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + syn match luaFunc /\/ + endif +endif + +" Define the default highlighting. +" For version 5.7 and earlier: only when not done already +" For version 5.8 and later: only when an item doesn't have highlighting yet +if version >= 508 || !exists("did_lua_syntax_inits") + if version < 508 + let did_lua_syntax_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink l65PreProc PreProc + HiLink luaStatement Statement + HiLink luaRepeat Repeat + HiLink luaFor Repeat + HiLink luaString String + HiLink luaString2 String + HiLink luaNumber Number + HiLink luaOperator Operator + HiLink luaIn Operator + HiLink luaConstant Constant + HiLink luaCond Conditional + HiLink luaElse Conditional + HiLink luaFunction Function + HiLink luaComment Comment + HiLink luaTodo Todo + HiLink luaTable Structure + HiLink luaError Error + HiLink luaParenError Error + HiLink luaBraceError Error + HiLink luaSpecial SpecialChar + HiLink luaFunc Identifier + HiLink luaLabel Label + + delcommand HiLink +endif + +let b:current_syntax = "lua" + +let &cpo = s:cpo_save +unlet s:cpo_save +" vim: et ts=8 sw=2