Subject: [stella] Neat assembler auto-table/label generation... From: "Andrew Davie" <atari2600@xxxxxxxxxxxxx> Date: Sat, 8 Feb 2003 01:28:43 +1100 |
Here's a neat usage of macros for table/label generation. Sometimes I need to have a table of vectors to code, so I can load a code address via an entry number/index and then branch to the code. I usually have a table of hand-maintained equates giving the 'NAME' of an entry and its ordinal number, and I use that name (*2) to access the table entry. And the table entries have to be in the same order as the numeric order of the tokens. TOKEN_JUMP equ 0 TOKEN_LOCK equ 1 TOKEN_MOVE equ 2 TOKEN_UNLOCK equ 3 TOKEN_DONE equ 4 TOKEN_FLIP equ 5 AnimVec .word AnimateJUMP .word AnimateLOCK .word AnimateMOVE .word AnimateUNLOCK .word AnimateDONE .word AnimateFLIP AnimateJUMP ; code here rts AnimateLOCK ; code here rts ;etc... Here's a much better way... ;--------------------------------------------------------------------------- --- ; Automatically define tokens and a vector table to token-processing code ; This is fairly neat, as the ordering of the entries in the table auto-generates ; the appropriate equates to access the table correctly! TOK SET 0 MAC TOKEN TOKEN_{1} equ TOK TOK SET TOK + 1 .word Animate{1} ENDM AnimVec TOKEN JUMP TOKEN LOCK TOKEN MOVE TOKEN UNLOCK TOKEN DONE TOKEN FLIP The big *advantage* of doing it with the macro like this is that you never need worry about the values of tokens, or adding/removing or reordering entries in the vector table. If you add a new entry to the AnimVec, a new token is generated, with a new value, and all will continue working properly. There are a couple of gotchas - the entries in the table must be unique. The labels of the code vectored TO should be of consistent format. That is easy to get around, if you want to have two parameters for the macro - one the label, one the token name. Anyway, thought I'd pass this on. I find it quite elegant. Cheers A ---------------------------------------------------------------------------------------------- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [stella] Combat AI - Omega, KirkIsrael | Thread | [stella] Samantha Fox, Andrew Davie |
Re: [stella] Combat AI - Omega, Thomas Jentzsch | Date | Re: [stella] Combat AI - Omega, KirkIsrael |
Month |