跳转到主要内容

CC65汇编代码格式化工具

项目描述

nice65

CC65汇编代码格式化工具(WIP)。

需求

特性

  • 使丑陋的代码变得不那么丑陋
  • 修复缩进和字母大小写(助记符、寄存器)
  • 理解奇怪的标签,例如无冒号的(C64风格)和无名的(::+++
  • 保留注释的缩进级别
  • 支持基本宏
  • 跳过包含; nice65: ignore注释的文件
  • C64 Kernal/Basic我的基于6502的SBC ROM代码进行了测试

待改进事项

  • 复杂宏
  • 正确格式化算术表达式

注意

  • 无冒号标签模式(-l)由于语法歧义而破坏宏。仅在使用不包含宏的旧代码(例如C64源代码)时使用此选项。

安装

pip install nice65

示例用法

# 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'

之前

.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

之后

.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

与Vim一起使用

:nnoremap <M-r> :%! nice65 -<CR>

与NeoVim一起使用

如果您想更高级,以下是如何将nice65配置为NeoVim的代码格式化工具的示例,使用null-ls

  1. 请确保您已安装以下neovim插件

    • maxbane/vim-asm_ca65 - 为CA65缓冲区设置文件类型
    • jose-elias-alvarez/null-ls.nvim - 允许运行自定义脚本作为语言服务器
  2. 添加配置

    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,
        }),
    })
    
  3. 触发格式化

    :lua vim.lsp.buf.format()
    

项目详情


下载文件

下载您平台对应的文件。如果您不确定该选择哪一个,请了解更多关于 安装包 的信息。

源代码发行版

nice65-0.1.8.tar.gz (7.1 kB 查看哈希值)

上传时间 源代码

构建发行版

nice65-0.1.8-py3-none-any.whl (7.6 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面