Page 2 of 2

Posted: Thu Jul 21, 2011 9:52 pm
by tomaitheous
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.

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
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.

Posted: Mon Jul 25, 2011 7:09 pm
by psycopathicteen
Something that I hate using is complicated tables. It gets frustrating and confusing trying to remember what your currently using X and Y for and where did you store X or Y when you had to use X or Y for something else.

Posted: Thu Jul 28, 2011 5:52 am
by tomaitheous
I was looking at this on the 6280, but should be the same on the 65x and related processors; BIT instruction. You should be able to use it as a quick 2bit flag test without using any regs. Irregardless of what's in Acc and the logic operation of BIT, the byte loaded from BIT should set N and V flags corresponding from bits 7 and 6 of that byte. Makes for a quick flag check.

Posted: Thu Jul 28, 2011 8:43 am
by tokumaru
BIT is great, it's just the lack of addressing modes that reduce its usefulness on the 6502.

Posted: Tue Oct 11, 2011 8:52 am
by psycopathicteen
Something I figured out by myself is, that it is good to have some engine code, but not to make your engine too out of specs with the way the system works.

A year ago my so-called "dynamic animation engine" sounded good in theory, but it was a b**** to actually implement, especially when you wanted other people to use it.

The engine I use nowadays simply divides the 64kB of V-RAM into 1kB slots with an "update_vram_slot" macro, and a little routine during v-blank. I use it for sprites, tiles and maps.