Code formatter for CC65 assembly
Project description
nice65
Code formatter for CC65 assembly (WIP).
Requirements:
- Python 3.x
- Lark
Features:
- Makes ugly code less ugly
- Fixes indentation and letter cases (mnemonics, registers)
- Understands weird labels, such as colon-less (C64 style) and unnamed (
:
,:+++
) - Skip files with
; nice65: ignore
comment - Tested with C64 Kernal/Basic and my 6502-based SBC ROM code
Not implemented yet:
- Macros (basic ones might work though).
- Proper formatting of arithmetic expressions
- Better indentation of comments based on deduced context
Example usage
# Reformat and print to STDOUT
./nice65.py samples/example.s
# Modify file in-place
./nice65.py samples/example.s -m
# Write result to another file
./nice65.py samples/example.s -o samples/clean.s
# or
./nice65.py samples/example.s > samples/clean.s
# Recursively reformat all files in directory with extension ".s"
./nice65.py ./samples/ -r
# Recursively reformat all files in directory with extension ".asm"
./nice65.py ./samples/ -r -p '*.asm'
Before:
.data
foo:.byte 1
.code
; Fill zeropage with zeroes
fill:
PHa
Phx
lDa #0
LdX #0
@again: sta $00 ,x ;Yeah, we can use stz, but I just need some code to test nice65!
inx
bne fill ; Repeat
; Do unnecessary throwaway stuff to test expressions
lda #<($42 + %10101010- (foo*2))
cmp A
lda ($1234), X
@ridiculously_long_label_just_for_the_sake_of_it:PLX
pla
rts
After:
.data
foo: .byte 1
.code
; Fill zeropage with zeroes
fill:
PHA
PHX
LDA #0
LDX #0
@again:
STA $00, X ; Yeah, we can use stz, but I just need some code to test nice65!
INX
BNE fill ; Repeat
; Do unnecessary throwaway stuff to test expressions
LDA #<($42+%10101010-(foo*2))
CMP A
LDA ($1234), X
@ridiculously_long_label_just_for_the_sake_of_it:
PLX
PLA
RTS
Using with NeoVim
Here's an example on how to have nice65 configured as code formatter for NeoVim with null-ls
-
Make sure you have the following neovim plugins installed:
maxbane/vim-asm_ca65
- sets filetype for CA65 buffersjose-elias-alvarez/null-ls.nvim
- allows to run custom scripts as language servers
-
Add configuration:
local null_ls = require("null-ls") null_ls.setup({ on_attach = on_attach, -- Remove this line if you don't use on_attach }) null_ls.register({ method = null_ls.methods.FORMATTING, filetypes = { 'asm_ca65' }, generator = null_ls.formatter({ command = '/path/to/nice65.py', -- point at nice65.py in your filesystem args = {'-'}, to_stdin = true, from_stdout = true, }), })
-
Trigger the formatting:
:lua vim.lsp.buf.format()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nice65-0.0.1.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file nice65-0.0.1.tar.gz
.
File metadata
- Download URL: nice65-0.0.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce970f6e12cacd79c36095f7b6382ca680b7e8d6837e905d57bc61c863b5c7e4 |
|
MD5 | 98bc70943f5e60c7255108d84927ed0f |
|
BLAKE2b-256 | 496534f298d9c9cc9aa219890083a31c2db14d60ee7916a697beb91decaa4a0e |
File details
Details for the file nice65-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: nice65-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b4690c3dd57bff000453754e2c68a60c98e706d441211e66af0fb1112c83d56 |
|
MD5 | 06ddfc8899ba0857b3668f852c234872 |
|
BLAKE2b-256 | 82215bd14f1a12577202d07bcb358367ded70ee59c070decda56b33c2946b9be |