Useful
Inventions
Favorite
Quotes
Game
Design
Atari
Memories
Personal
Pages

Let’s Make a Game!

Step 12: Add the Missile Objects

By Darrell Spice, Jr. (adapted by Duane Alan Hahn)

Original Blog Entry

The 2LK has been revised to display both missile objects. Missile objects do not support Vertical Delay, so there's no need to prime ENAM0 or ENAM1.

ArenaLoop:                  ;   17 - (currently 17 from bpl ArenaLoop)
    ; continuation of line 2 of the 2LK
    ; this precalculates data that's used on line 1 of the 2LK
        tya                 ; 2 19 - 2LK loop counter in A for testing
        and #%11            ; 2 21 - test for every 4th time through the loop,
        bne SkipX           ; 2 23 - (3 24) branch if not 4th time
        inc ArenaIndex      ; 5 28 - if 4th time, increase index so new playfield data is used
SkipX:                      ;   28 - use 28 as it's the longest path to here        

        ldx #1              ; 2 30 - D1=0, so missile1 will be off 
        lda #BOX_HEIGHT-1   ; 2 32 - height of box graphic
        dcp Missile1Draw    ; 5 37 - Decrement Missile1Draw and compare with height
        bcs DoEnam1         ; 2 39 - (3 40) if Carry is Set, then missile1 is on current scanline
        .byte $24           ; 3 42 - $24 = BIT with zero page addressing, trick that
                            ;        causes the inx to be skipped
DoEnam1:                    ;   40 - from bcs DoEnam1
        inx                 ; 2 42 - D1=1, so ball will be ON
    
        lda #HUMAN_HEIGHT-1 ; 2 44 - height of the humanoid graphics, subtract 1 due to starting with 0
        dcp Player1Draw     ; 5 49 - Decrement Player1Draw and compare with height
        bcs DoDrawGrp1      ; 2 51 - (3 52) if Carry is Set, then player1 is on current scanline
        lda #0              ; 2 53 - otherwise use 0 to turn off player1
        .byte $2C           ; 4 57 - $2C = BIT with absolute addressing, trick that
                            ;        causes the lda (Player1Ptr),y to be skipped
DoDrawGrp1:                 ;   52 - from bcs DoDrawGrp1
        lda (Player1Ptr),y  ; 5 57 - load the shape for player1
        sta WSYNC           ; 3 60
;---------------------------------------
    ; start of line 1 of the 2LK
        sta GRP1            ; 3  3 - @0-22, update player1 graphics
        stx ENAM1           ; 3  6 - @0-22, update missile1 graphics
        ldx ArenaIndex      ; 3  9
        lda ArenaPF0,x      ; 4 13 - get current scanline's playfield pattern
        sta PF0             ; 3 16 - @0-22 and update it
        lda ArenaPF1,x      ; 4 20 - get current scanline's playfield pattern
        sta PF1             ; 3 23 - @71-28 and update it
        lda ArenaPF2,x      ; 4 27 - get current scanline's playfield pattern
        sta PF2             ; 3 30 - @60-39
        
    ; precalculate data that's needed for line 2 of the 2LK    
        ldx #1              ; 2 32 - D1=0, so missile0 will be off 
        lda #BOX_HEIGHT-1   ; 2 34 - height of box graphic
        dcp Missile0Draw    ; 5 39 - Decrement Missile0Draw and compare with height
        bcs DoEnam0         ; 2 41 - (3 42) if Carry is Set, then missile0 is on current scanline
        .byte $24           ; 3 44 - $24 = BIT with zero page addressing, trick that
                            ;        causes the inx to be skipped
DoEnam0:                    ;   42 - from bcs DoEnam0
        inx                 ; 2 44 - D1=1, so ball will be ON
        stx Temp            ; 3 47 - save for line 2
        
        ldx #1              ; 2 49 - D1=0, so ball will be off 
        lda #BOX_HEIGHT-1   ; 2 51 - height of box graphic
        dcp BallDraw        ; 5 56 - Decrement BallDraw and compare with height
        bcs DoEnabl         ; 2 58 - (3 59) if Carry is Set, then ball is on current scanline
        .byte $24           ; 3 61 - $24 = BIT with zero page addressing, trick that
                            ;        causes the inx to be skipped
DoEnabl:                    ;   59 - from bcs DoEnablPre
        inx                 ; 2 61 - D1=1, so ball will be ON
    
        lda #HUMAN_HEIGHT-1 ; 2 63 - height of the box graphics, 
        dcp Player0Draw     ; 5 68 - Decrement Player0Draw and compare with height
        bcs DoDrawGrp0      ; 2 70 - (3 71) if Carry is Set then player0 is on current scanline
        lda #0              ; 2 72 - otherwise use 0 to turn off player0
        .byte $2C           ; 4 76 - $2C = BIT with absolute addressing, trick that
                            ;        causes the lda (Player0Ptr),y to be skipped
    ; start of line 2 of the 2LK
DoDrawGrp0:                 ;   71 - from bcs DoDrawGRP0
        lda (Player0Ptr),y  ; 5 76 - load the shape for player0
;---------------------------------------
    ; start of line 2 of the 2LK
        sta GRP0            ; 3  3 - @0-22, update player0 graphics
        stx ENABL           ; 3  6 - @0-22, update ball graphics
        lda Temp            ; 3  9 - get the precalced data for missile0
        sta ENAM0           ; 3 12 - @0-22, update missile0 graphics
        dey                 ; 2 14 - decrease the 2LK loop counter
        bne ArenaLoop       ; 2 16 - (3 17) branch if there's more Arena to draw
        sty PF0             ; 3 19 - @0-22, Y is 0, blank out playfield
        sty PF1             ; 3 22 - @71-28, Y is 0, blank out playfield
        sty PF2             ; 3 25 - @60-39, Y is 0, blank out playfield
        rts                 ; 6 31 - ReTurn from Subroutine

The 2 lines of the 2LK now work like this:

  1. updates player1, missile1, playfield, precalcs player0, missile0, ball for line 2
  2. updates player0, missile0, ball, precalcs player1, missile1 and playfield index for line 1

 

We didn't have enough time to update missile0 and missile1 on both lines of the 2LK. Since the TIA doesn't offer a vertical delay feature for the missiles, they can never line up. This is just like how the players didn't line up when VDELP0 and VDELP1 were not used. For our game, this isn't a problem.

 

One thing to notice about the revised 2LK is the 1st line uses exactly 76 cycles, so it no longer ends with a sta WSYNC.

 

PositionObjects has been modified to initialize 2 new variables, Missile0Draw and Missile1Draw, that are used by the 2LK to control when the missiles are drawn.

PositionObjects:
...
    ; prep missile0's Y position for 2LK
        lda ObjectY+2       ; get the missile's Y position
        lsr                 ; divide by 2 for 2LK
        sta Temp            ; save for position calculation
    ; Missile0Draw = ARENA_HEIGHT + BOX_HEIGHT - Y position
        lda #(ARENA_HEIGHT + BOX_HEIGHT)
        sec
        sbc Temp
        sta Missile0Draw        
        
    ; prep missile1's Y position for 2LK
        lda ObjectY+3       ; get the missile's Y position
        lsr                 ; divide by 2 for 2LK
        sta Temp            ; save for position calculation
    ; Missile0Draw = ARENA_HEIGHT + BOX_HEIGHT - Y position
        lda #(ARENA_HEIGHT + BOX_HEIGHT)
        sec
        sbc Temp
        sta Missile1Draw

The routines are a little simpler than the others (for player0, player1 and ball) as the missiles don't have a Vertical Delay to set up. This is how the Arena looks with all the boxes drawn:

Arena

Not exactly right, is it? One thing we forgot to do was set the width of the missiles! We'd done that for the ball back in step 9 when we set the upper nybble of CTRLPF to 3:

TimerBar:
...
        lda Variation       ; 3 20
        lsr                 ; 2 22 - which Arena to show
        tay                 ; 2 24 - set for index
        ldx ArenaOffset,y   ; 4 28 - set X for which arena to draw
        lda ArenaPF0,x      ; 4 32 - reflect and priority for playfield
        and #%00000111      ; 2 34 - get the lower 3 bits for CTRLPF
        ora #%00110000      ; 2 36 - set ball to display as 8x pixel 
        sta CTRLPF          ; 3 39

Which is why the ball was the right width when we added it in step 11. The same setting is needed for the missiles, but it goes into NUSIZ0 and NUSIZ1 instead:

VerticalSync:
...
        lda #$30    ; 
        sta NUSIZ0  ; set missile0 to be 8x
        sta NUSIZ1  ; set missile1 to be 8x
...

And now it looks correct:

Arena

OverScan was updated to detect collisions with the boxes drawn by the missiles:

OverScan:
...
notP0BL:        
        bit CXM0P       ; V=player0/missile0
        bvc notP0M0     ; if V is off then player0 did not collide with missile0
        ldx #2          ; which box was collected
        jsr CollectBox  ; update score and reposition box
        
notP0M0:
        bit CXM1P       ; N=player0/missile1
        bpl notP0M1     ; if N is off then player0 did not collide with missile1
        ldx #3          ; which box was collected
        jsr CollectBox  ; update score and reposition box
        
notP0M1:
...
notP1BL:        
        bit CXM0P       ; N=player1/missile0
        bpl notP1M0     ; if N is off then player1 did not collide with missile0
        ldx #2          ; which box was collected
        jsr CollectBox  ; update score and reposition box
        
notP1M0:
        bit CXM1P       ; V=player1/missile1
        bvc notP1M1     ; if V is off then player1 did not collide with missile1
        ldx #3          ; which box was collected
        jsr CollectBox  ; update score and reposition box
        
notP1M1:

A test run of the players collecting the boxes:

Arena

Lastly, on the off chance that somebody might roll the score, a new Digit graphic has been added:

Digit Graphic

And a minor change was made to CollectBox to display it and end the game if a player collected 100 boxes.

CollectBox:
        sed                 ; SEt Decimal flag
        clc                 ; CLear Carry bit
        lda #1              ; 1 point per box
        adc Score,y         ; add to player's current score
        bcc Not100          ; if the Carry is clear, score did not roll
        sta GameState       ; stop the game (A holds 0)
        lda #$BB            ; B image is !! to show that score rolled
Not100:        
        sta Score,y         ; and save it
        cld                 ; CLear Decimal flag
        jsr RandomLocation  ; move box to new location
        rts

To test it, I started up a game and used Stella's debugger to change the score to 99:

Arena

Then collected another box:

Arena

 

The ROM and the source are at the bottom of my blog entry.

 

 

 

 

 

< Previous Step

 

 

Next Step >

 

 

 

 

 

Table of Contents for Let’s Make a Game!

Introduction

Goals for this tutorial.

Step 1: Generate a Stable Display

On other systems, the video chip generates the display; on the 2600, your program generates the display.

Step 2: Timers

Improve the display generation by using the built-in timer.

Step 3: Score and Timer Display

Using the playfield to display information.

Step 4: 2 Line Kernel

Draw the player objects (sprites) on screen (X & Y location).

Step 5: Automate Vertical Delay

Finish the Y positioning of the player objects (sprites).

Step 6: Spec Change

Revise our goals.

Step 7: Draw the Playfield

Display an arena (like the mazes in Combat).

Step 8: Select and Reset Support

Using the Game Select and Game Reset console switches.

Step 9: Game Variations

How to implement game variations (number of players, different mazes).

Step 10: “Random Numbers”

How to randomize your game.

Step 11: Add the Ball Object

Draw the ball on screen (X & Y location).

Step 12: Add the Missile Objects

Draw the missiles on screen (X & Y location)

Step 13: Add Sound Effects

Let’s make some noise!

Step 14: Add Animation

Make the humans run instead of glide.

 

 

 

 

Useful Links

Easy 6502 by Nick Morgan

How to get started writing 6502 assembly language. Includes a JavaScript 6502 assembler and simulator.

 

 

Atari Roots by Mark Andrews (Online Book)

This book was written in English, not computerese. It's written for Atari users, not for professional programmers (though they might find it useful).

 

 

Machine Language For Beginners by Richard Mansfield (Online Book)

This book only assumes a working knowledge of BASIC. It was designed to speak directly to the amateur programmer, the part-time computerist. It should help you make the transition from BASIC to machine language with relative ease.

 

 

The Second Book Of Machine Language by Richard Mansfield (Online Book)

This book shows how to put together a large machine language program. All of the fundamentals were covered in Machine Language for Beginners. What remains is to put the rules to use by constructing a working program, to take the theory into the field and show how machine language is done.

 

 

6502 Instruction Set with Examples

A useful page from Assembly Language Programming for the Atari Computers.

 

 

6502.org

Continually strives to remain the largest and most complete source for 6502-related information in the world.

 

 

Guide to 6502 Assembly Language Programming by Andrew Jacobs

Below are direct links to the most important pages.

 

 

Stella Programmer's Guide

HTMLified version.

 

 

Nick Bensema's Guide to Cycle Counting on the Atari 2600

Cycle counting is an important aspect of Atari 2600 programming. It makes possible the positioning of sprites, the drawing of six-digit scores, non-mirrored playfield graphics and many other cool TIA tricks that keep every game from looking like Combat.

 

 

How to Draw A Playfield by Nick Bensema

Atari 2600 programming is different from any other kind of programming in many ways. Just one of these ways is the flow of the program.

 

 

Cart Sizes and Bankswitching Methods by Kevin Horton

The "bankswitching bible." Also check out the Atari 2600 Fun Facts and Information Guide and this post about bankswitching by SeaGtGruff at AtariAge.

 

 

Atari 2600 Specifications

Atari 2600 programming specs (HTML version).

 

 

Atari 2600 Programming Page (AtariAge)

Links to useful information, tools, source code, and documentation.

 

 

MiniDig

Atari 2600 programming site based on Garon's "The Dig," which is now dead.

 

 

TIA Color Charts and Tools

Includes interactive color charts, an NTSC/PAL color conversion tool, and Atari 2600 color compatibility tools that can help you quickly find colors that go great together.

 

 

The Atari 2600 Music and Sound Page

Adapted information and charts related to Atari 2600 music and sound.

 

 

Game Standards and Procedures

A guide and a check list for finished carts.

 

 

Stella

A multi-platform Atari 2600 VCS emulator. It has a built-in debugger to help you with your works in progress or you can use it to study classic games.

 

 

JAVATARI

A very good emulator that can also be embedded on your own web site so people can play the games you make online. It's much better than JStella.

 

 

batari Basic Commands

If assembly language seems a little too hard, don't worry. You can always try to make Atari 2600 games the faster, easier way with batari Basic.

 

 

Back to Top

 

Disclaimer

View this page and any external web sites at your own risk. I am not responsible for any possible spiritual, emotional, physical, financial or any other damage to you, your friends, family, ancestors, or descendants in the past, present, or future, living or dead, in this dimension or any other.

 

Home Inventions Quotations Game Design Atari Memories Personal Pages About Site Map Contact Privacy Policy Tip Jar