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 (
:,:+++) - Preserves indentation level of comments
- Supports basic macros
- Skips files with
; nice65: ignorecomment - Tested with C64 Kernal/Basic and my 6502-based SBC ROM code
Improvements to do:
- Complex macros
- Proper formatting of arithmetic expressions
Notes:
- Colon-less label mode (
-l) breaks macros due to ambiguity of the syntax. Use this option only with legacy code that contains no macros (such as C64 source code).
Installation
pip install nice65
Example usage
# Reformat and print to STDOUT
nice65 samples/example.s
# Modify file in-place
nice65 samples/example.s -m
# Write result to another file
nice65 samples/example.s -o samples/clean.s
# or
nice65 samples/example.s > samples/clean.s
# Recursively reformat all files in directory with extension ".s"
nice65 ./samples/ -r
# Recursively reformat all files in directory with extension ".asm"
nice65 ./samples/ -r -p '*.asm'
Before:
.macro ldax aa, bb ; do stuff
lda aa
ldx bb ; load bb
.endmacro
four .set 9
var = 1337 + four
four .set 4
.macro push_all
phA
phX
PHy
.endmacro
.data
foo:.byte 1
.code
; Fill zeropage with zeroes
fill:
; save registers
push_all
@start: ldax #0, #0
@again: sta $00 ,x ;Yeah, we can use stz, but I just need some code to test nice65!
inx
bne @again ; Repeat
; Do unnecessary throwaway stuff to test expressions
;
lda #<($42 + %10101010- (foo*2))
cmp foo+2
jmp :+
: lda $1234
@ridiculously_long_label_just_for_the_sake_of_it:PLX
pla
end:rts
After:
.macro ldax aa, bb ; do stuff
LDA aa
LDX bb ; load bb
.endmacro
four .set 9
var = 1337 + four
four .set 4
.macro push_all
PHA
PHX
PHY
.endmacro
.data
foo: .byte 1
.code
; Fill zeropage with zeroes
fill:
; save registers
push_all
@start:
ldax #0, #0
@again:
STA $00, X ; Yeah, we can use stz, but I just need some code to test nice65!
INX
BNE @again ; Repeat
; Do unnecessary throwaway stuff to test expressions
;
LDA #<($42 + %10101010 - (foo * 2))
CMP foo + 2
JMP :+
: LDA $1234
@ridiculously_long_label_just_for_the_sake_of_it:
PLX
PLA
end: RTS
Using with Vim
:nnoremap <M-r> :%! nice65 -<CR>
Using with NeoVim
If you want to be fancy, 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 = 'nice65', args = {'-'}, to_stdin = true, from_stdout = true, }), })
-
Trigger the formatting:
:lua vim.lsp.buf.format()
Metadata
Release files for nice65 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nice65-0.1.8.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nice65-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.7 kB
Release files / nice65-0.1.8.tar.gz
| Download URL | nice65-0.1.8.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb4fd8605b815affb5c8de24572aecd50bfe154bec60382c2f907cbbca04b99c
|
|
BLAKE2b-256 checksum How to use checksums |
341ddb362934316102f736aac32b3faf4b63dcae96850d599688a04d7fae4f4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / nice65-0.1.8-py3-none-any.whl
| Download URL | nice65-0.1.8-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a834348bce3f18bc36f9c6446e47967d6f1b2c9a5066179d88fdcd211576534
|
|
BLAKE2b-256 checksum How to use checksums |
f16a9c85e2b40d6cb83b5c556b3a078ab956a273cd228e8ec32aa8d9c120a7e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|