Animated Changes

I’m still working on content changes right now… graphics, sound effects, actual FX for all the spells… a lot of work to do before I go back to coding up things.

One aside was to update my animation code. I’ve had the same block of code in place for several years, and it’s functioned adequately. But it’s hard to expand, as it’s really just a set of linear instructions for each character block. Some sample code is this:

* Tile animation
ANIME  DATA AWS,AM1
AM1    MOV  @CLOCK,R0
       ANDI R0,>0003
       JEQ  AM15
       RTWP
AM15   LI   R0,>2468
       LI   R1,HIBUFF
       LI   R2,40
       BLWP @VMBR
       LI   R1,32
       BL   @ANORTH
       C    @CHAR,@W1
       JLE  AM16
       CLR  R1
       BL   @ANORTH
       LI   R1,8
       BL   @ANORTH
       LI   R1,16
       BL   @ANORTH
       LI   R1,24
       BL   @ANORTH
AM16   LI   R0,>2468
       LI   R1,HIBUFF
       LI   R2,40
       BLWP @VMBW
       LI   R0,>0400
       LI   R1,HIBUFF
       LI   R2,104
       BLWP @VMBR
       LI   R1,64
       BL   @ASOUTH
       LI   R1,72
       BL   @AWEST
       LI   R1,80
       BL   @ANORTH
       LI   R1,88
       BL   @AEAST
       MOV  @CLOCK,R1
       CLR  R0
       DIV  @W16,R0
       MOV  R1,R1
       JEQ  AM2
AMEND  B    @AM7
AM2    MOV  R0,R7
       ANDI R7,>0003
       LI   R1,24
       BL   @AROT
       LI   R1,32
       BL   @ASOUTH
       LI   R1,40
       BL   @AWEST
       LI   R1,48
       BL   @ANORTH
       LI   R1,56
       BL   @AEAST
       CI   R7,3
       JNE  AM25
       CLR  R1
       BL   @ASOUTH
       BL   @AEAST
       LI   R1,8
       BL   @ASOUTH
       BL   @AEAST
       JMP  AM3

This kind of imperative linear approach is all right, if you don’t have a lot of things to do. Truthfully, in assembly language, you often have to balance whether or not a more generic data-driven approach wouldn’t just end up costing you more memory than its worth.

In my case, my animation requirements DID get up complicated enough I wanted to get away from this approach. I also wanted it to be easy to add new patterns or alter exiting ones (and their animation speed) with a simple change.

Here’s some of the new code, which uses a data array to store the VDP address, size, and speed and type of animation. It’s then processed in a short loop:

* Tile animation
ANIME  DATA AWS,AM1
AM1    MOV  @>8314,R10                 * Copy stack address to R10
       MOV  @CLOCK,R0
       ANDI R0,>0003                   * Check clock value for 1/15 interval
       JEQ  AM2                        * If not, skip animation
       RTWP
AM2    LI   R8,ANDAT0
       BL   @ANIMAT
       C    @GSTATE,@W2                * In combat mode?
       JNE  AM4
       LI   R8,ANDAT2
       BL   @ANIMAT
AM3    RTWP
AM4    C    @CHAR,@W2                  * Is character set 3-7?
       JLE  AM3
       LI   R8,ANDAT1
       BL   @ANIMAT
       JMP  AM3       

ANIMAT MOV  R11,*R10+                  * Animation looping for blocks
       MOV  R8,R9
       MOV  *R9+,R0                    * Load character data 
       LI   R1,HIBUFF
       MOV  *R9+,R2
       BLWP @VMBR
       CLR  R1                         * Clear pattern index
       SRL  R2,3                       * Get proper count into R2
       MOV  R2,R7
ANM1   MOV  @CLOCK,R3                  * Get clock value into R3
       CLR  R2
       DIV  *R9+,R2                    * Divide by speed factor
       MOV  *R9+,R0                    * Get animation routine into R0
       MOV  R3,R3
       JNE  ANM2                       * If not at interval, skip
       BL   *R0                        * Branch to animation routine
ANM2   AI   R1,8                       * Increment to next character
       DEC  R7
       JNE  ANM1
       MOV  *R8+,R0                    * Write character data 
       LI   R1,HIBUFF
       MOV  *R8+,R2
       BLWP @VMBW
       B    @SUBRET

* Pattern animation data for travel/combat mode 0-6 (56 bytes)
ANDAT0 DATA >0400,104
       DATA 16,ACIRC
       DATA 16,ACIRC
       DATA 16,AUPDW
       DATA 8,AROT
       DATA 8,ASOUTH
       DATA 8,AWEST
       DATA 8,ANORTH
       DATA 8,AEAST
       DATA 4,ASOUTH
       DATA 4,AWEST
       DATA 4,ANORTH
       DATA 4,AEAST
       DATA 32,ACIRC

My old approach was using around 436 bytes of code space. With the data arrays and the smaller routines, my new system uses about 100 less bytes, and is easier to use. On screen, speed seems unimpaired as well. Huzzah!

This entry was posted in Coding, CRPG, Design, TI-99/4a. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *