This seemed like a sufficiently inconsequential topic I decided it didn't really belong in the technical forum. I'm trying to come up with a better way to indent my 6502 code so it helps guide the eye and communicate more meaning. I've decided in the context of ca65 to adopt the following simple rules:
-Any time a new scope is introduced, or at least the appearance of one (such as a macro), increase the tab level by 4 spaces.
-Any time a new scope is removed, decrease the tab level by 4 spaces.
-Any code between a label and a branch is also to be indented by 4 spaces.
-The root scope is to be indented by 4 spaces (everything, directives, .res, code, data, etc.)
Here's an example of a routine from my current project formatted using these rules. I think I like this, and I'm considering writing a script to just go through my whole codebase and make it all pretty like this.
Anyone else care to share thoughts on 6502 coding style?
*edit* It occurred to me the above rules might be tricky to iron out with a script, as there are cases I didn't address such as branching past a jmp instruction in order to achieve a longer branch.
Previously my rule was to only indent when new scopes are introduced. I might just have to settle for that alone, for simplicity's sake.
-Any time a new scope is introduced, or at least the appearance of one (such as a macro), increase the tab level by 4 spaces.
-Any time a new scope is removed, decrease the tab level by 4 spaces.
-Any code between a label and a branch is also to be indented by 4 spaces.
-The root scope is to be indented by 4 spaces (everything, directives, .res, code, data, etc.)
Here's an example of a routine from my current project formatted using these rules. I think I like this, and I'm considering writing a script to just go through my whole codebase and make it all pretty like this.
Code:
;****************************************************************
;This routine kills all entities that are not the player entity.
;****************************************************************
.proc entity_kill_all_but_player
lda player_entity_index
cmp #ENTITY_NULL
beq :++
ldx #(MAX_ENTITIES-1)
next_entity:
cpx player_entity_index
beq :+
entity_clear_flag #ENTITY_FLAG_ALIVE_CLEAR
:
dex
bpl next_entity
:
rts
.endproc
;This routine kills all entities that are not the player entity.
;****************************************************************
.proc entity_kill_all_but_player
lda player_entity_index
cmp #ENTITY_NULL
beq :++
ldx #(MAX_ENTITIES-1)
next_entity:
cpx player_entity_index
beq :+
entity_clear_flag #ENTITY_FLAG_ALIVE_CLEAR
:
dex
bpl next_entity
:
rts
.endproc
Anyone else care to share thoughts on 6502 coding style?
*edit* It occurred to me the above rules might be tricky to iron out with a script, as there are cases I didn't address such as branching past a jmp instruction in order to achieve a longer branch.
Previously my rule was to only indent when new scopes are introduced. I might just have to settle for that alone, for simplicity's sake.