rename to ca65

This commit is contained in:
matthias@arch 2023-12-14 01:41:14 +01:00
parent fc9dad4a60
commit 6d14e796ef
9 changed files with 2225 additions and 168 deletions

View File

@ -1,37 +1,66 @@
# vim-ca6502 Support for the ca65 assembler
This plugin provides syntax highlighting, convenience functions and help pages for the ca65 assembler.
It is focused on the 65C02 processor, please open an issue/a pull request if you find anything that is missing.
# vim-ca65: Vim support for the ca65 assembler
This plugin provides **syntax** highlighting, **convenience** functions and **help** pages for the ca65 assembler.
By default, the plugin loads for files having a `.s65` or `.h65` extension.
To load it for your preferred extension, write this into `~/.vim/ftdetect/ca6502.vim`:
```vim
" in ~/.vim/ftdetect/ca6502.vim
au BufRead,BufNewFile *.myExtension setfiletype ca6502
```
*I currently only work with the 65C02 processor. However, I tried to include everything for the 65816 as well.
If you find anything that is missing or mistakes, please open an issue or a pull request.*
## Syntax
The syntax highlighting currently supports the 65C02 opcodes, the ca65 assembler functions
## Features
### Syntax Highlighting
The syntax highlighting currently supports the (undocumented) 6502, 65C02 and 65816 opcodes, the ca65 assembler functions
and the macro packs `generic` and `longbranch`.
If the labels and instructions have the same color in your colorscheme,
link `ca65Opcode` or `ca65Label` to another class, eg: `hi link ca65Label Typedef`.
## Convenience
This plugin provides the `b:match_words` variable for jumping between words.
### Convenience
This plugin provides the `b:match_words` variable for jumping between words (requires `matchit.vim`)
Supported are the assembler commands like `.if` `.endif`, `.macro` `.endmacro` as well as stack instructions.
This allows for easier checking of stack push/pull order.
There is also a function that opens a header/source file with the same name in a vsplit.
For example if `~/project/main.s65` is opened, `~/project/main.h65` would be opened.
To use it, map it and set your preferred assembly filetypes.
For example if `~/project/main.s65` is opened, the function would open `~/project/main.h65` to the right of it.
### Help
I compiled parts of the W65C02 datasheet and parts of the "Programming the 658126" book into a vim help page.
Type `:help <opcode>` (or `help ca65-<opcode>` if the first one gives the wrong page) to see information about a opcode (how it works, updated flags...).
## Installation
Install using your favorite plugin manager, for example with vim-plug:
```vim
" in ~/.vim/ftplugin/ca6502.vim (or vimrc)
nnoremap <buffer> <leader>h :call SplitHeader("h65", "s65")<Cr>
" in vimrc
call plug#begin()
Plug 'MatthiasQuintern/vim-ca65'
call plug#end()
```
## Help
I compiled the datasheet of the WDC 65C02 into a vim help page.
Type `:help <opcode>` to see info about the opcode (addressing modes, updated flags...).
## Configuration
### Select processor
By default, the syntax highlighting only highlights the original 6502 instructions.
To enable the undocumented instructions, the 65C02 instructions or the 65816 instructions, write this into `~/.vim/ftplugin/ca65.vim`:
```vim
" in ~/.vim/ftplugin/ca65.vim (or vimrc)
let g:ca65_undoc = 1 " enable the undocumented opcodes
let g:ca65_65C02 = 1 " enable 65C02 instructions
let g:ca65_65816 = 1 " enable 65816 instructions
```
### Select filetype
By default, the plugin loads for files having a `.s65` or `.h65` extension.
To load it for your preferred extension, write this into `~/.vim/ftdetect/ca65.vim`:
```vim
" in ~/.vim/ftdetect/ca65.vim
au BufRead,BufNewFile *.myExtension setfiletype ca65
```
### Customize syntax highlighting
If the labels and instructions have the same color in your colorscheme,
link `ca65Label` (or `ca65Opcode`) to another class, eg:
```vim
" in ~/.vim/ftplugin/ca65.vim
hi link ca65Label Typedef
```
### Header/Source split function
To use the source-header split function, map it and set your preferred assembly filetypes:
```vim
" in ~/.vim/ftplugin/ca65.vim
nnoremap <buffer> <leader>h :call SplitHeader("h65", "s65")<Cr>
```

2039
doc/ca65.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
*ca6502.txt* ca65 + 65C02
CONTENTS
Instruction list |ca6502-instructions|
ADC |ca6502-adc|
Addressing modes |ca6502-addressing-modes|
Status flags |ca6502-status-flags|
==============================================================================
This help file provides information on the ca6502 processor instructions.
You can jump to each instruction by using the corresponding keyword.
==============================================================================
INSTRUCTIONS *ca6502-instructions*
------------------------------------------------------------------------------
ADC *ca6502-adc*
Add with Carry~
A + M + C -> A `N V - - - - Z C` |ca6502-status-flags|
Addressing Modes~
a a,x a,y # zp (zp,x) zp,x (zp) (zp),y |ca6502-addresing-modes|
------------------------------------------------------------------------------
AND *ca6502-and*
Add with Carry~
A ^ M -> A ` N - - - - - Z -` |ca6502-status-flags|
Addressing Modes~
a a,x a,y # zp (zp,x) zp,x (zp) (zp),y |ca6502-addresing-modes|
==============================================================================
ADDRESSING MODES *ca6502-addressing-modes*
==============================================================================
Status flags *ca6502-status-flags*
Use the following commands to navigate this help file:
:help ADC Jump to the Add with Carry instruction
==============================================================================
vim:tw=78:sta:noet:ts=8:sts=0:ft=help:fen:

View File

@ -1,81 +0,0 @@
load and store
LDA load accumulator with memory NZ
LDX load X register with memory NZ
LDY load Y register with memory NZ
STA STore Accumulator in memory -
STX STore X register in memory -
STY STore Y register in memory -
STZ store zero in memory -
Stack Operations
PHA push accumulator on stack -
PHX push X register on stack -
PHY push Y register on stack -
PHP push processor status on stack -
PLA pull accumulator from stack NZ
PLX pull X register from stack NZ
PLY pull Y register from stack NZ
PLP pull processor status from stack All
TSX transfer the stack pointer to the X register NZ
TXS transfer the X register to the stack pointer register -
Increment & Decrement Operations
INX increment X register by one NZ
INY increment Y register by one NZ
DEX decrement X register by one NZ
DEY decrement Y register by one NZ
INC increment memory or accumulator by one NZ
DEC decrement memory or accumulator by one NZ
Shift Operations
ASL arithmetic shift one bit left, memory or accumulator NZC
LSR logical shift one bit right, memory or accumulator N=0 ZC
ROL rotate one bit left memory or accumulator NZC
ROR rotate one bit right memory or accumulator NZC
Logical Operations
AND and accumulator with memory NZ
ORA or accumulator with memory NZ
EOR exclusive-or accumulator with memory NZ
BIT BIt Test N=M7 V=M6 Z
CMP compare accumulator with memory NZC
CPX compare X register with memory NZC
CPY compare Y register with memory NZC
TRB Test and Reset memory Bit x
TSB Test and Set memory Bit x
RMB reset memory bit x
SMB set memory bit x
Math Operations
ADC add memory to accumulator with carry NZCV
SBC subtract memory accumulator, with borrow (carry bit) NZCV
Flow Control Instructions
JMP jump to new location -
JSR jump to Subroutine -
RTS return from Subroutine -
RTI return from Interrupt
BRA branch Always -
BEQ branch if equal (Z == 0) -
BNE branch if not equal (Z == 1) -
BCC branch if carry clear (C == 0) -
BCS branch if carry set (C == 1) -
BVC branch if overflow clear (V == 0) -
BVS branch if overflow set (V == 1) -
BMI branch if minus (N == 1) -
BPL branch if plus (N == 0) -
BBR branch if bit reset -
BBS branch if bit set -
Processor Status Instructions
CLC clear carry flag C=0
CLD clear decimal mode D=0
CLI clear interrupt disable bit I=0
CLV clear overflow flag V=0
SEC set carry flag C=1
SED set decimal mode D=1
SEI set interrupt disable bit I=1
Transfer Instructions
TAX transfer accumulator to X register NZ
TAY transfer accumulator to Y register NZ
TXA transfer X register to accumulator NZ
TYA transfer Y register to accumulator NZ
Misc Instructions
NOP no operation -
BRK break instruction B=1
Interrupt
wai wait for interrupt
stp stop mode

View File

@ -1,6 +1,93 @@
ca6502-adc ca6502.txt /*ca6502-adc*
ca6502-addressing-modes ca6502.txt /*ca6502-addressing-modes*
ca6502-and ca6502.txt /*ca6502-and*
ca6502-instructions ca6502.txt /*ca6502-instructions*
ca6502-status-flags ca6502.txt /*ca6502-status-flags*
ca6502.txt ca6502.txt /*ca6502.txt*
ca65-adc ca65.txt /*ca65-adc*
ca65-and ca65.txt /*ca65-and*
ca65-asl ca65.txt /*ca65-asl*
ca65-bcc ca65.txt /*ca65-bcc*
ca65-bcs ca65.txt /*ca65-bcs*
ca65-beq ca65.txt /*ca65-beq*
ca65-bit ca65.txt /*ca65-bit*
ca65-bmi ca65.txt /*ca65-bmi*
ca65-bne ca65.txt /*ca65-bne*
ca65-bpl ca65.txt /*ca65-bpl*
ca65-bra ca65.txt /*ca65-bra*
ca65-brk ca65.txt /*ca65-brk*
ca65-brl ca65.txt /*ca65-brl*
ca65-bvc ca65.txt /*ca65-bvc*
ca65-bvs ca65.txt /*ca65-bvs*
ca65-clc ca65.txt /*ca65-clc*
ca65-cld ca65.txt /*ca65-cld*
ca65-cli ca65.txt /*ca65-cli*
ca65-clv ca65.txt /*ca65-clv*
ca65-cmp ca65.txt /*ca65-cmp*
ca65-contents ca65.txt /*ca65-contents*
ca65-cop ca65.txt /*ca65-cop*
ca65-cpx ca65.txt /*ca65-cpx*
ca65-cpy ca65.txt /*ca65-cpy*
ca65-dec ca65.txt /*ca65-dec*
ca65-dex ca65.txt /*ca65-dex*
ca65-dey ca65.txt /*ca65-dey*
ca65-eor ca65.txt /*ca65-eor*
ca65-inc ca65.txt /*ca65-inc*
ca65-instructions ca65.txt /*ca65-instructions*
ca65-inx ca65.txt /*ca65-inx*
ca65-iny ca65.txt /*ca65-iny*
ca65-jmp ca65.txt /*ca65-jmp*
ca65-jsl ca65.txt /*ca65-jsl*
ca65-jsr ca65.txt /*ca65-jsr*
ca65-lda ca65.txt /*ca65-lda*
ca65-ldx ca65.txt /*ca65-ldx*
ca65-ldy ca65.txt /*ca65-ldy*
ca65-lsr ca65.txt /*ca65-lsr*
ca65-mvn ca65.txt /*ca65-mvn*
ca65-mvp ca65.txt /*ca65-mvp*
ca65-nop ca65.txt /*ca65-nop*
ca65-ora ca65.txt /*ca65-ora*
ca65-pea ca65.txt /*ca65-pea*
ca65-pei ca65.txt /*ca65-pei*
ca65-per ca65.txt /*ca65-per*
ca65-pha ca65.txt /*ca65-pha*
ca65-phb ca65.txt /*ca65-phb*
ca65-phd ca65.txt /*ca65-phd*
ca65-phk ca65.txt /*ca65-phk*
ca65-php ca65.txt /*ca65-php*
ca65-phx ca65.txt /*ca65-phx*
ca65-phy ca65.txt /*ca65-phy*
ca65-pla ca65.txt /*ca65-pla*
ca65-plb ca65.txt /*ca65-plb*
ca65-pld ca65.txt /*ca65-pld*
ca65-plp ca65.txt /*ca65-plp*
ca65-plx ca65.txt /*ca65-plx*
ca65-ply ca65.txt /*ca65-ply*
ca65-rep ca65.txt /*ca65-rep*
ca65-rol ca65.txt /*ca65-rol*
ca65-ror ca65.txt /*ca65-ror*
ca65-rti ca65.txt /*ca65-rti*
ca65-rtl ca65.txt /*ca65-rtl*
ca65-rts ca65.txt /*ca65-rts*
ca65-sbc ca65.txt /*ca65-sbc*
ca65-sec ca65.txt /*ca65-sec*
ca65-sed ca65.txt /*ca65-sed*
ca65-sei ca65.txt /*ca65-sei*
ca65-sep ca65.txt /*ca65-sep*
ca65-sta ca65.txt /*ca65-sta*
ca65-stp ca65.txt /*ca65-stp*
ca65-stx ca65.txt /*ca65-stx*
ca65-sty ca65.txt /*ca65-sty*
ca65-stz ca65.txt /*ca65-stz*
ca65-tax ca65.txt /*ca65-tax*
ca65-tay ca65.txt /*ca65-tay*
ca65-tcd ca65.txt /*ca65-tcd*
ca65-tcs ca65.txt /*ca65-tcs*
ca65-tdc ca65.txt /*ca65-tdc*
ca65-trb ca65.txt /*ca65-trb*
ca65-tsb ca65.txt /*ca65-tsb*
ca65-tsc ca65.txt /*ca65-tsc*
ca65-tsx ca65.txt /*ca65-tsx*
ca65-txa ca65.txt /*ca65-txa*
ca65-txs ca65.txt /*ca65-txs*
ca65-txy ca65.txt /*ca65-txy*
ca65-tya ca65.txt /*ca65-tya*
ca65-tyx ca65.txt /*ca65-tyx*
ca65-wai ca65.txt /*ca65-wai*
ca65-wdm ca65.txt /*ca65-wdm*
ca65-xba ca65.txt /*ca65-xba*
ca65-xce ca65.txt /*ca65-xce*

2
ftdetect/ca65.vim Normal file
View File

@ -0,0 +1,2 @@
au BufRead,BufNewFile *.h65 setfiletype ca65
au BufRead,BufNewFile *.s65 setfiletype ca65

View File

@ -1,2 +0,0 @@
au BufRead,BufNewFile *.h65 setfiletype ca6502
au BufRead,BufNewFile *.s65 setfiletype ca6502

View File

@ -11,7 +11,8 @@ if !exists("*SplitHeader")
endif
" navigation with % using matchit plugin
let b:match_words = '\<ph[axy]\>:\<pl[axy]\>,'
" pea pei per missing because they push two bytes
let b:match_words = '\<ph[abdpkxy]\>:\<pl[abdpxy]\>,'
\ . '\.\<if\>:\.\<elseif\>:\.\<else\>:\.\<endif\>,'
\ . '\.\<proc\>:\.\<endproc\>,'
\ . '\.\<mac(ro)?\>:\.\<endmac(ro)?\>,'

View File

@ -8,6 +8,16 @@ if exists("b:current_syntax")
finish
endif
if exists("g:ca65_65C02")
let b:ca65_65C02 = 1
endif
if exists("g:ca65_65816")
let b:ca65_65816 = 1
endif
if exists("g:ca65_illegal")
let b:ca65_illegal = 1
endif
" Remove any old syntax stuff hanging about
syn clear
syn case ignore
@ -23,25 +33,36 @@ syn keyword ca65Reg x y a
" OPCODES
" keywords that are used in regions will not be defined here
" ********************************************************************************
" 650x
" 65xxx
" ********************************************************************************
syn keyword ca6502Opcode adc and asl bit brk clc cld cli clv cmp cpx cpy dec dex dey eor inc inx iny lda ldx ldy lsr nop ora pha php pla plp rol ror rti rts sbc sec sed sei sta stx sty tax tay tsx txa txs tya
syn region ca65BranchTarget matchgroup=ca6502Opcode start="\v(bcc|bcs|beq|bmi|bne|bpl|bvc|bvs|jmp|jsr)[ \t]+" end="$" contains=ca65Comment keepend
syn region ca6502BranchTarget matchgroup=ca6502Opcode start="\v(bcc|bcs|beq|bmi|bne|bpl|bvc|bvs|jmp|jsr)[ \t]+" end="$" contains=ca65Comment keepend
" ********************************************************************************
" Atari 800XL 'Sally' undocumented opcodes
" mnemonics taken from Trevin Beattie's 'Atari Technical Information' page
" at "http://www.xmission.com/~trevin/atari/atari.shtml"
" 6502 - Illegal/undocumented opcodes
" ********************************************************************************
" syn keyword ca65SallyUndoc anc arr asr asx ax7 axe brk dcp jam las lax php rla rra sax slo sre sx7 sy7 xea xs7
if exists("b:ca65_illegal")
syn keyword ca65Illegal alr anc arr axs dcp isc las lax rla rra sax slo sre
endif
" ********************************************************************************
" 65C02
" ********************************************************************************
if exists("b:ca65_65C02") || exists("b:ca65_65816")
syn keyword ca65C02Opcode phx phy plx ply stz trb tsb stp wai
syn match ca65C02Opcode "bb[rs][0-7]"
syn region ca65i65C02BranchTarget matchgroup=ca65C02Opcode start="\(bra \)" end="$" contains=ca65Comment keepend
syn region ca65C02BranchTarget matchgroup=ca65C02Opcode start="\(bra \)" end="$" contains=ca65Comment keepend
syn match ca65BitSetBranchTarget "\v(bb[rs][0-7][ \t]+[^,]+,[ \t]*)@<=[^;]+"
endif
" ********************************************************************************
" 65816
" ********************************************************************************
if exists("b:ca65_65816")
syn keyword ca65816Opcode cop mvn mvp pea pei per phb phd phk plb pld rep rtl sep stp tcd tcs tdc tsc txy tyx wai xba xce
syn keyword ca65816OpcodeAlt cpa dea ina swa tad tas tda tsa
syn region ca65816BranchTarget matchgroup=ca65816Opcode start="\v(brl|jml|jsl)[ \t]+" end="$" contains=ca65Comment keepend
endif
" ********************************************************************************
" ASSEMBLER
@ -58,7 +79,7 @@ syn match decNumber "\<\d\+\>"
syn match hexNumber "\$\x\+\>" " 'bug', but adding \< doesn't behave!
syn match binNumber "%[01]\+\>"
" syn region ca65Immediate start="\v((adc|and|bit|cmp|cpx|cpy|eor|lda|ldx|ldy|ora|sbc) +)@<=#" end="$" contains=ca65Comment,hexNumber,decNumber,binNumber,ca65Char,ca65Expression
syn match ca65Immediate "\v((adc|and|bit|cmp|cpx|cpy|eor|lda|ldx|ldy|ora|sbc)[ \t]+)@<=#"
syn match ca65Immediate "\v((adc|and|bit|cmp|cpx|cpy|eor|lda|ldx|ldy|ora|sbc|sep|rep)[ \t]+)@<=#"
" ********************************************************************************
" ca65
" ********************************************************************************
@ -74,8 +95,9 @@ syn region ca65MacGenericBranchTarget matchgroup=ca65MacGeneric start="\v(bg
" LABELS:
hi link ca65CheapLabel ca65Label
hi link ca65UnnamedLabel ca65Label
hi link ca65BranchTarget ca65Label
hi link ca65i65C02BranchTarget ca65Label
hi link ca6502BranchTarget ca65Label
hi link ca65C02BranchTarget ca65Label
hi link ca65816BranchTarget ca65Label
hi link ca65BitSetBranchTarget ca65Label
hi link ca65ProcLabel ca65Label
hi link ca65MacLongbranchTarget ca65Label
@ -98,8 +120,10 @@ hi link customMacros PreProc
" INSTRUCTIONS
hi link ca6502Opcode ca65Opcode
hi link ca65C02Opcode ca65Opcode
hi link ca65816Opcode ca65Opcode
hi link ca65816OpcodeAlt ca65Opcode
hi link ca65Opcode Statement
hi link ca65SallyUndoc Special
hi link ca65Illegal Special
hi link ca65Reg Identifier
hi link ca65Todo Todo