It is currently Thu Oct 18, 2018 7:08 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: 6502 coding style.
PostPosted: Wed Jan 03, 2018 12:09 am 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 614
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 is
Code:
fCalcScreenAddrChar .function base,x,y
.endf base+(y*40)+x
Don'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.
Code:
.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
    rts
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


Top
 Profile  
 
 Post subject: Re: 6502 coding style.
PostPosted: Wed Jan 03, 2018 1:36 pm 
Offline

Joined: Sun May 03, 2015 8:19 pm
Posts: 96
I like notepad++ for its

1. Code folding
2. Special highlighting for (ZP variables, macros, fixed bank functions) . This could be achieved with naming conventions going forward but in my reverse engineering it was easier to do it this way.


I only do one level of indenting but can see where it would look nice. I have lots of comments and as above try and get rid of as many "magic numbers" as possible

One small example:

Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group