Added pragma to create opcode aliases.

This commit is contained in:
g012 2017-10-06 15:49:12 +02:00
parent f84ea4e357
commit 844b06f5f0
4 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -577,6 +577,18 @@ syn match l65Opcode /\<sre\%(.[bw]\)\=\>/
syn match l65Opcode /\<far\>/
syn match l65Opcode /\<rtx\>/
syn match l65Opcode /\<xsr\>/
" Common alias, reomve if desired.
syn match l65Opcode /\<dna\%(.[bw]\)\=\>/
syn match l65Keyword /\<dnaimm\>/
syn match l65Keyword /\<dnazpg\>/
syn match l65Keyword /\<dnazpx\>/
syn match l65Keyword /\<dnaabs\>/
syn match l65Keyword /\<dnaabx\>/
syn match l65Keyword /\<dnaaby\>/
syn match l65Keyword /\<dnazab\>/
syn match l65Keyword /\<dnazax\>/
syn match l65Keyword /\<dnainx\>/
syn match l65Keyword /\<dnainy\>/
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already