Posted: Thu Jul 21, 2011 9:52 pm
I'm much more organized in my code nowadays, because it often gets too large and complex to maintain.
Macros - use them a ton. Not only for higher level functionality but code compacting as well. There are plenty of times where a few extra cycles means nothing, and readability means everything.
Equates - I use the hell out of them for arguments in macros. Though I specifically make up pseudo registers of ZP addresses with them too. An, Dn, Rn, etc.
Labels - extremely important. And for local labels, I completely avoid using "-" and "+", even though I added support them to PCEAS. I rather know what the local label via even the most generic choice of description.
Indenting and code layout - I use a lot of header markers. I.e. long lines of characters to separate subs. Asterisks for important breaks, periods and other chars for less important breaks. Makes skimming through the source code much-much easier. I also indent a lot more than I used to. Though I never used no indentation.
Most of my coding is 6280 based rather than 6502 based, so I tend to optimize for speed over size more often. I've used every single opcode in the ISA more than once. Though one of my favorite instruction is the TST #nn, <address>. ANDs an immediate value with the value of the address (zp, zp+x, abs, abs+x). Nothing gets stored and Acc isn't effected. But N, V, and Z flags are effected. Perfect for bit testing VARs without wasting a reg.
Macros - use them a ton. Not only for higher level functionality but code compacting as well. There are plenty of times where a few extra cycles means nothing, and readability means everything.
Code: Select all
main:
jsr init_vdc
jsr init_wsg
jsr init_dma
VCE_REG MID_RES|H_FILTER
VDC_REG DCR , AUTO_SATB_ON
VDC_REG CR , $0000
IRQ_CNTR IRQ2_ON|VIRQ_ON|TIRQ_ON
VDC_REG SATB , $7F00
VDC_REG MWR , SCR64_32
TIMER_REG TMR_CMD, #$00
TIMER_REG TMR_PORT, #$01
VDC_REG CR , BG_ON|SPR_OFF|VINT_ON|HINT_OFF
;load font
MAP_BANK_WIDE Font , MPR3
VDC_REG MAWR, $1000
VDC_REG VRWR
DMA Font, $6000, vdata_port, (FontEnd-Font)
;load palette
BG_COLOR #$0
DMA_local FontPal,vce_data, #$10
jsr ClearScreen
PRINT_STR_i "Custom XM player ver: 1.0.11 alpha",3,1
PRINT_STR_i "----------------------------------",3,2
PRINT_STR_i "Song info: BPM=144 SPEED=4 ",3,11
PRINT_STR_i "List: Pattern: Line: ",3,3
Labels - extremely important. And for local labels, I completely avoid using "-" and "+", even though I added support them to PCEAS. I rather know what the local label via even the most generic choice of description.
Indenting and code layout - I use a lot of header markers. I.e. long lines of characters to separate subs. Asterisks for important breaks, periods and other chars for less important breaks. Makes skimming through the source code much-much easier. I also indent a lot more than I used to. Though I never used no indentation.
Most of my coding is 6280 based rather than 6502 based, so I tend to optimize for speed over size more often. I've used every single opcode in the ISA more than once. Though one of my favorite instruction is the TST #nn, <address>. ANDs an immediate value with the value of the address (zp, zp+x, abs, abs+x). Nothing gets stored and Acc isn't effected. But N, V, and Z flags are effected. Perfect for bit testing VARs without wasting a reg.