Tagalong Todd Tutorial: Part 4

From Intellivision Wiki

Jump to: navigation, search

Contents

Tagalong Todd Tutorial: Part 4

In this part of the tutorial, we'll add code that will put Todd on the screen. We'll do so in a manner that will allow moving him around later.

The complete source for this tutorial (it's a subset of the full tagalong.asm found in the SDK) is here.

How we'll draw Todd

We already have all of the pieces in place to draw Todd on the screen. He's going to use the same drawing of a man, but in a different color. He'll be drawn on the screen using MOB_UPDATE just like we do for the player character. We just need to define the right values and adjust things a little.

A couple of storage places

As you remember, we started drawing the player by having 2 variables for the X and Y positions on the screen. We'll define the same for Todd.

TODD        PROC                    ; TODD's STATS
@@XP        RMB     1               ; X position
@@YP        RMB     1               ; Y position
            ENDP

This shouldn't really require much explanation at this point. If you have a hard time remembering how we setup the player character, go back to part 2 and give it another read.

A small addition to main

Over in main, we want to provide initial values for Todd's X and Y positions.

            ;; ------------------------------------------------------------ ;;
            ;;  Put you and Todd onscreen.                                  ;;
            ;; ------------------------------------------------------------ ;;
            MVII    #$1000, R0
            MVO     R0,     PLYR.XP
            MVO     R0,     PLYR.YP

            MVII    #$4000, R0
            MVO     R0,     TODD.XP
            MVO     R0,     TODD.YP

Right along side of the initial player position we set a value for Todd.

Changes to MOB_UPDATE

Todd will need very similar code to what we've written already. Specifically, we need to put Todd's X and Y positions into our shadow buffer in the same places where we are currently doing the same for the player.

            ;; ------------------------------------------------------------ ;;
            ;;  Merge our position with our MOB registers.                  ;;
            ;; ------------------------------------------------------------ ;;
            MVII    #@@mobr,    R4      ; MOB information template
            MVII    #STICSH,    R5

            MVI     PLYR.XP,    R0      ;\
            SWAP    R0                  ; |
            ANDI    #$00FF,     R0      ; |- Player X position
            XOR@    R4,         R0      ; |
            MVO@    R0,         R5      ;/

            MVI     TODD.XP,    R0      ;\
            SWAP    R0                  ; |
            ANDI    #$00FF,     R0      ; |- Todd X position
            XOR@    R4,         R0      ; |
            MVO@    R0,         R5      ;/

So we see a very similar block here for Todd's X position.

            ADDI    #6,         R5

We need to adjust the pointer by 6 locations instead of 7, because R5 has been incremented a second time when we did the operations for Todd.

            MVI     PLYR.YP,    R0      ;\
            SWAP    R0                  ; |
            ANDI    #$007F,     R0      ; |- Player Y position
            XOR@    R4,         R0      ; |
            MVO@    R0,         R5      ;/

            MVI     TODD.YP,    R0      ;\
            SWAP    R0                  ; |
            ANDI    #$007F,     R0      ; |- Todd Y position
            XOR@    R4,         R0      ; |
            MVO@    R0,         R5      ;/

And similar updates for the Y position.

            ADDI    #6,         R5

And another adjustment of 6 locations instead of 7.

            MVI@    R4,         R0      ; \_ Player's A register
            MVO@    R0,         R5      ; /
            MVI@    R4,         R0      ; \_ Todd's A register
            MVO@    R0,         R5      ; /                     

And we need to copy the A register area for Todd as well.

            ;; ------------------------------------------------------------ ;;
            ;;  Bits to copy into MOB registers.                            ;;
            ;; ------------------------------------------------------------ ;;
@@mobr      DECLE   STIC.mobx_visb      ; make player visible
            DECLE   STIC.mobx_visb      ; make Todd visible

            DECLE   STIC.moby_yres      ; make player 8x16 MOB
            DECLE   STIC.moby_yres      ; make Todd 8x16 MOB

            DECLE   STIC.moba_fg1 + STIC.moba_gram + 0*8    ; Player is blue
            DECLE   STIC.moba_fg2 + STIC.moba_gram + 0*8    ; Todd is red

And we need to provide Todd the same kinds of bit pattern constants that we provided for the player graphic. Again, if this is unfamiliar check out part 1 of this tutorial for a bit more detail.

That's it!

Assemble and run it. We now see Todd on the screen! He doesn't move yet, but he's there. The last step of our tutorial series will be to make Todd chase us around the screen.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox