roland p, on Sat May 23, 2009 8:52 PM, said:
How about using a macro?
MAC SHIP; 1st parameter the var name prefix
{1}_PositionX .word
{1}_PositionZ .word
{1}_VelocityX .word
{1}_VelocityZ .word
{1}_Direction .byte
ENDM
; declare the ships...
SHIP Ship1
SHIP Ship2
Then you'd access the vars as "Ship1_PositionX", etc. The above will work, barring any minor typos.
Having said that, I don't think this is a great way to define variables. I'd have each variable indexed by ship number. Where you have word variables, split into two with a low/high, or double the index before lookup.
Just for reference, macros can do interesting stuff... here's a few to browse through...
ROM_BANK_SIZE = $800
MAC NEWBANK; bank name
SEG {1}
ORG ORIGIN
RORG $F000
BANK_START SET *
{1} SET ORIGIN / 2048
ORIGIN SET ORIGIN + 2048
_CURRENT_BANK SET {1}
ENDM
MAC DEFINE_1K_SEGMENT; {seg name}
ALIGN $400
SEGMENT_{1} SET *
BANK_{1} SET _CURRENT_BANK
ENDM
MAC CHECK_BANK_SIZE; name
.TEMP = * - BANK_START
ECHO {1}, "(2K) SIZE = ", .TEMP, ", FREE=", ROM_BANK_SIZE - .TEMP
#if ( .TEMP ) > ROM_BANK_SIZE
ECHO "BANK OVERFLOW @ ", * - ORIGIN
ERR
#endif
ENDM
MAC CHECK_HALF_BANK_SIZE; name
; This macro is for checking the first 1K of ROM bank data that is to be copied to RAM.
; Note that these ROM banks can contain 2K, so this macro will generally go 'halfway'
.TEMP = * - BANK_START
ECHO {1}, "(1K) SIZE = ", .TEMP, ", FREE=", ROM_BANK_SIZE/2 - .TEMP
#if ( .TEMP ) > ROM_BANK_SIZE/2
ECHO "BANK OVERFLOW @ ", * - ORIGIN
ERR
#endif
ENDM
MAC OVERLAY; {name}
SEG.U OVERLAY_{1}
org Overlay
ENDM
;--------------------------------------------------------------------------
MAC VALIDATE_OVERLAY
LIST OFF
#if * - Overlay > OVERLAY_SIZE
ERR
#endif
LIST ON
ENDM
;--------------------------------------------------------------------------
; Macro inserts a page break if the object would overlap a page
MAC OPTIONAL_PAGEBREAK; { string, size }
LIST OFF
IF (>( * + {2} -1 )) > ( >* )
EARLY_LOCATION SET *
ALIGN 256
ECHO "PAGE BREAK INSERTED FOR ", {1}
ECHO "REQUESTED SIZE = ", {2}
ECHO "WASTED SPACE = ", *-EARLY_LOCATION
ECHO "PAGEBREAK LOCATION = ", *
ENDIF
LIST ON
ENDM
MAC CHECK_PAGE_CROSSING
LIST OFF
#if ( >BLOCK_END != >BLOCK_START )
ECHO "PAGE CROSSING @ ", BLOCK_START
#endif
LIST ON
ENDM
MAC CHECKPAGE
LIST OFF
IF >. != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ")"
ECHO ""
ERR
ENDIF
LIST ON
ENDM
MAC CHECKPAGE_BNE
LIST OFF
IF 0;>(. + 2) != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ")"
ECHO ""
ERR
ENDIF
LIST ON
bne {1}
ENDM
MAC CHECKPAGE_BPL
LIST OFF
IF (>(.+2 )) != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ")"
ECHO ""
ERR
ENDIF
LIST ON
bpl {1}
ENDM
IDENTITY SET 0
MAC IDENT; {object}
#if DEBUG=YES
lda #IDENTITY
sta debug_ident
lda {1}
sta debug_object
#endif
IDENTITY SET IDENTITY + 1
ENDM
Cheers
A