Re: 6502 coding style.
Posted: Wed Jan 03, 2018 12:09 am
Interesting to see how it rolls on the "other side" I talked about indenting on the C64 and got told "THERE IS NO TAB KEY ON 64 FOR A REASON"... however I replied with "THERE IS ON 128 - EVOLVE!"
I think a few more broad-line rules should be discussed
My "ruless... well guidelines" are
Don't use magic numbers, make constants.
Make sure all constants start k(uppercase letter) this way my tools can catch when I forget to do a #
Make blocks for groupings, and put "classes" i.e code that is grouped together in its own block and section
If maths is repeated make a function that does it, i.e convert X,Y to a screen locations isDon't make magic bytes in order. Either make a structure and declare it as a struct instance or if small enough ( 1~2 simple params ) use build in functions to convert an AOS to SOA.
variables and data should be inlined wherever possible, or near by as much as possible.Flags variables should be marked as such, if they are do thing if negative thingNF is positive thingPF. If zero thingZF, Not Zero thingNEF
If a branch targets an rts name it EXIT
If a branch targets a jmp name it bJ<place it jumps to>
After each code stop there is a blank line. So rts, rti, an always taken branch, or opposing branch pair
functions lowerCaseStart
Data UpperCaseStart
IF_DEFS all caps
Each bank should be in its own block so you have to enter BANK_XX.func if you call it from outside of the bank
I think a few more broad-line rules should be discussed
My "ruless... well guidelines" are
Don't use magic numbers, make constants.
Make sure all constants start k(uppercase letter) this way my tools can catch when I forget to do a #
Make blocks for groupings, and put "classes" i.e code that is grouped together in its own block and section
If maths is repeated make a function that does it, i.e convert X,Y to a screen locations is
Code: Select all
fCalcScreenAddrChar .function base,x,y
.endf base+(y*40)+xvariables and data should be inlined wherever possible, or near by as much as possible.
Code: Select all
.section ZP
myVar .byte ?
.send ZP
myFunc
lda myVar
bpl _skip
ldx #size(myData)-1
- lda myData,x
.section Bank0Data
myData .byte VIC.Colours.(black,red,green,yellow)
.send Bank0Data
sta VIC.Sprite.Colour0
dex
bpl -
_skip
rtsIf a branch targets an rts name it EXIT
If a branch targets a jmp name it bJ<place it jumps to>
After each code stop there is a blank line. So rts, rti, an always taken branch, or opposing branch pair
functions lowerCaseStart
Data UpperCaseStart
IF_DEFS all caps
Each bank should be in its own block so you have to enter BANK_XX.func if you call it from outside of the bank
