From 844b06f5f055d4fea8773b418c13c8ea1f61907a Mon Sep 17 00:00:00 2001 From: g012 Date: Fri, 6 Oct 2017 15:49:12 +0200 Subject: [PATCH] Added pragma to create opcode aliases. --- .travis.yml | 1 + l65.lua | 8 ++++++++ samples/vcs_spr48.l65 | 7 ++++--- vim/syntax/l65.vim | 12 ++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 99efc26..230b031 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ script: - ../l65 vcs_flush.l65 - ../l65 vcs_hello.l65 - ../l65 vcs_hooks.l65 + - ../l65 vcs_spr48.l65 - cd .. deploy: provider: releases diff --git a/l65.lua b/l65.lua index 7b98024..841c268 100644 --- a/l65.lua +++ b/l65.lua @@ -77,6 +77,7 @@ end opcode_arg_encapsulate(true) local opcode_encapsulate = {} -- additionnal opcode, to have basic encapsulation (function(a) return a end) +local opcode_alias = {} -- alternate user names for opcodes local opcode_implied = lookupify{ 'asl', 'brk', 'clc', 'cld', 'cli', 'clv', 'dex', 'dey', 'inx', 'iny', 'lsr', 'nop', 'pha', 'php', 'pla', 'plp', @@ -507,6 +508,12 @@ local function LexLua(src) table.insert(Keywords_6502, opcode) Keywords[opcode] = syntax6502_on toEmit = {Type = 'Symbol', Data = ';'} + elseif dat == 'alias' then + local org,new = get_word(),get_word() + opcode_alias[new] = org + table.insert(Keywords_6502, new) + Keywords[new] = syntax6502_on + toEmit = {Type = 'Symbol', Data = ';'} else generateError("unknown pragma: " .. dat) end @@ -1528,6 +1535,7 @@ local function ParseLua(src, src_name) local mod_st, mod_expr, inverse_encapsulate for _,op in pairs(Keywords_6502) do if tok:ConsumeKeyword(op, tokenList) then + if opcode_alias[op] then op = opcode_alias[op] end if opcode_encapsulate[op] then inverse_encapsulate = tok:ConsumeSymbol('!', tokenList) local st, expr = ParseExpr(scope) if not st then return false, expr end diff --git a/samples/vcs_spr48.l65 b/samples/vcs_spr48.l65 index 081e900..712737b 100644 --- a/samples/vcs_spr48.l65 +++ b/samples/vcs_spr48.l65 @@ -1,6 +1,8 @@ require'vcs' mappers['2K']() +#pragma alias and dna + local i = 0x80 local ramk=i i=i+51 local spritestack=i i=i+31 @@ -16,7 +18,6 @@ local img = assert(l65.image("dotbin.png")) local sp = sprite{image=img, y0=185, y1=0, yinc=-1} for i=1,6 do section{"spr"..i, align=256} byte(sp[i]) - local c = #sp[i] end -- sprite anim frames offset in spr* @@ -103,7 +104,7 @@ local on_vblank = function() inc time bne _noover inc time+1 @_noover -- frame change - lda time; and#3 bne _keep lda seed jsr rand sta seed @_keep + lda time dna#3 bne _keep lda seed jsr rand sta seed @_keep ldy#8 @_glitch lda time+1 cmp glitch_cmphi,y bcc _glitchdone bne _glitchnext lda time cmp glitch_cmplo,y bcc _glitchdone @@ -113,7 +114,7 @@ local on_vblank = function() tay jsr setframe -- position change - lda time; and#7 bne _skipmove + lda time; and#7 bne _skipmove -- alias opcode 'and' to 'dna' to avoid use of ';', as on line 107 ldy#6 @_move lda time+1 cmp sproff_cmphi,y bcc _stay bne _movenext lda time cmp sproff_cmplo,y bcc _stay diff --git a/vim/syntax/l65.vim b/vim/syntax/l65.vim index 4e246e6..6852454 100644 --- a/vim/syntax/l65.vim +++ b/vim/syntax/l65.vim @@ -577,6 +577,18 @@ syn match l65Opcode /\/ syn match l65Opcode /\/ syn match l65Opcode /\/ syn match l65Opcode /\/ +" Common alias, reomve if desired. +syn match l65Opcode /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ +syn match l65Keyword /\/ " Define the default highlighting. " For version 5.7 and earlier: only when not done already