- Source code formatter for ca65-compatible 6502 assembly.
- caddy65 is currently experimental. As such, please take care to back up your source code before use.
- Clean, consistant code makes a better first impression.
- Removes clutter from source control. All modifications are meaningful.
- Removes clutter from code review. Feedback should be focused on implementation.
- Removes the mental burden of formatting while programming. Focus on the task at hand.
- Removes some sources of interpersonal awkwardness. Facilitates collaboration.
- Enables global formatting changes. Simplifies adaptation.
- Building
- POSIX Environment (Linux, MacOS, WSL)
- Cygwin, MinGW, and GnuWin32 should also work, but I have been unable to verify compatibility.
- make
- clang
- POSIX Environment (Linux, MacOS, WSL)
- Testing
- ca65
- diff
- General Use
- Source code must not exceed 4096 characters per line.
- Simply run
make
./caddy65 [-c config.cfg] <source.s>
- Simply run
make test
- If caddy65 produces unwanted results, you can disable formatting for single lines or code blocks using the following tags in comments:
#pre-formatted
#pre-formatted-start
#pre-formatted-end
adc sixteenBitVar+1 ; #pre-formatted
; #pre-formatted-start
.byte $0,$1,$2,$3
adc sixteenBitVar+1
; #pre-formatted-end
- Allows for the disabling of specific rules.
- By default, all rules are enabled.
- If the
-c
flag is not specified, caddy65 will attempt to loadcaddy65.cfg
in the current working directory. - Disabling one or more rules might have unintended consequences, so use with caution!
- For example, disabling the
indexedInstruction
rule to allowadc $42,x
will still result inadc $42, x
due to thecommaSpacing
rule enforcement. - Please see the debug flag description below should you encounter unexpected behavior.
- For example, disabling the
addressFormatting: enabled
hexLiteralFormatting: disabled
If neither of these features is used, caddy65 applies the following rules to each source line.
- If the source line is only a comment:
- If the comment starts at column 0, it will not be indented.
- Otherwise enforces indention.
; This is a comment.
; This is also a comment.
; This is also a comment.
- Trims leading whitespace from the source line.
- Indention considerations occur later.
- Trims trailing whitespace from the source line.
- Checks for blank lines.
- Enforces maximum of one blank line between source code.
- Converts all tab characters to the
indention
string (defaults to two spaces).
- Enforces lowercase hexadecimal digits.
- Enforces zero-padding to two or four digits.
- Does not attempt to detect operations that could be converted to Zero Page.
adc $0f
adc $0742
- Enforces lowercase hexadecimal digits.
- Trims zero-padding.
adc #$f
- Enforces eight digits.
and #%00001100
- Enforces no space before open parenthesis character.
- Enforces no space after open parenthesis character.
- Does not modify comments.
adc #.hibyte($42)
- Enforces no space before close parenthesis character.
- Enforces no space after close parenthesis character.
- Does not modify comments.
adc #.hibyte($42)
- Enforces lowercase operator names.
- Enforces one and only one space before operator.
- Enforces one and only one space after operator.
- Does not modify comments.
adc sixteenBitVar + 1
adc var .shr 3
- Enforces no space before comma character.
- Enforces one and only one space after comma character.
- Does not modify comments.
.byte $00, $01, $02, $03
- Enforces lowercase control command names.
- Enforces one and only one space between control commands and arguments.
- Enforces indention for the following commands:
.asciiz
.addr
.byt
.byte
.dbyt
.dword
.lobytes
.hibytes
.word
- Otherwise enforces no indention.
.proc reset
.incbin "CHR-ROM.bin"
.repeat 4, K
- Enforces one and only one space between
.macro
control command and macro name. - Enforces one and only one space between macro name and optional parameters.
.macro inc16 addr
- Enforces one and only one space between macro name and optional parameters.
- Enforces indention.
inc16 $42
- Enforces no space between label name and colon character.
- Enforces one and only one space between label and optional arguments.
- Enforces no indention.
nmi:
buttons: .res 1
- Enforces optional indention via the
labeledIndention
string.
:
: rts
- Enforces lowercase instruction names.
- Enforces indention.
clc
- Enforces lowercase instruction names.
- Enforces one and only one space between instruction and literal argument.
- Enforces indention.
adc #$42
- Enforces lowercase instruction names.
- Enforces one and only one space between instruction and address argument.
- Enforces indention.
adc $42
- Enforces lowercase instruction names.
- Enforces one and only one space between instruction and address argument.
- Enforces no space between address argument and comma character.
- Enforces one and only one space between comma character and index register name.
- Enforces lowercase index register name.
- Enforces indention.
adc $42, x
- Enforces lowercase instruction names.
- Enforces one and only one space between instruction and open parenthesis character.
- Enforces no space between open parenthesis character and address argument.
- Enforces no space between address argument and close parenthesis character.
- Enforces indention.
jmp ($42)
- Enforces lowercase instruction names.
- Enforces one and only one space between instruction and open parenthesis character.
- Enforces no space between open parenthesis character and address argument.
- Enforces no space between address argument and comma character.
- Enforces one and only one space between comma character and
x
register name. - Enforces no space between
x
register name and close parenthesis character. - Enforces lowercase
x
register name. - Enforces indention.
adc ($42, x)
- Enforces lowercase instruction names.
- Enforces one and only one space between instruction and open parenthesis character.
- Enforces no space between open parenthesis character and address argument.
- Enforces no space between address argument and close parenthesis character.
- Enforces no space between close parenthesis character and comma character.
- Enforces one and only one space between comma character and
y
register name. - Enforces lowercase
y
register name. - Enforces indention.
adc ($42), y
- Enforces lowercase instruction names.
- Enforces one and only one space between instruction and colon character.
- Enforces indention.
bcc :-
bcs :++
- Enforces lowercase instruction names.
- Enforces at least one space between source code and semicolon character.
- Enforces at least one space between semicolon character and comment.
- Does not modify additional spacing before or after the semicolon character.
clc ; Clear the carry bit,
adc #$42 ; then add 0x42 to register a.
- This tool takes your jumble of golf clubs (source code) and produces an organized (standardized) golf bag, as any good caddy should do.
- Modifying the
indention
andlabeledIndention
strings in the source code should suit your needs.
- Be sure to add the rule to the
rule_t
enum,ruleNames
array, andpatterns
array. - The rule will be applied automatically in the order specified by the
rule_t
enum. - Once you're ready, consider contributing your rule to the project!
- Please, please open an issue with as much info as possible here.
- At a minimum, please include sample input and expected output.
- I wanted to keep this project in c99 for portability, familiarity, and an excuse to learn the POSIX Regex API.
- Beyond that, I probably didn't know about the suggested solution! Feel free to let me know by opening an issue and I'll look into it.
- There are two debug flags,
verbose
andpedantic
, in the source code which can be set to 1 to increase logging levels.