Home > Atari Memories > #Assembly > Let’s Make a Game!
By Darrell Spice, Jr. (adapted by Duane Alan Hahn, a.k.a. Random Terrain)
As an Amazon Associate I earn from qualifying purchases. (I get commissions for purchases made through certain links on this page.)
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:
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:
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:
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:
Lastly, on the off chance that somebody might roll the score, a new Digit graphic has been added:
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:
Then collected another box:
The ROM and the source are at the bottom of my blog entry.
Other Assembly Language Tutorials
Be sure to check out the other assembly language tutorials and the general programming pages on this web site.
#ad Amazon: Atari 2600 Programming
#ad Amazon: 6502 Assembly Language Programming
#ad Atari 2600 Programming for Newbies
#ad Making Games for the Atari 2600
|
|
Table of Contents for Let’s Make a Game!
Step 1: Generate a Stable Display
Step 3: Score and Timer Display
Step 5: Automate Vertical Delay
Step 8: Select and Reset Support
Step 12: Add the Missile Objects
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 6502 Instruction Set broken down into 6 groups.
Nice, simple instruction set in little boxes (not made out of ticky-tacky).
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.
An easy-to-read page from The Second Book Of Machine Language.
6502 Instruction Set with Examples
A useful page from Assembly Language Programming for the Atari Computers.
Continually strives to remain the largest and most complete source for 6502-related information in the world.
By John Pickens. Updated by Bruce Clark.
Guide to 6502 Assembly Language Programming by Andrew Jacobs
Below are direct links to the most important pages.
Goes over each of the internal registers and their use.
Gives a summary of whole instruction set.
Describes each of the 6502 memory addressing modes.
Describes the complete instruction set in detail.
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 programming specs (HTML version).
Atari 2600 Programming Page (AtariAge)
Links to useful information, tools, source code, and documentation.
Atari 2600 programming site based on Garon's "The Dig," which is now dead.
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.
A guide and a check list for finished carts.
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.
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.
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.
Some people appear to have a mental illness because they have a vitamin B deficiency. For example, the wife of a guy I used to chat with online had severe mood swings which seemed to be caused by food allergies or intolerances. She would became irrational, obnoxious, throw tantrums, and generally act like she had a mental illness. The horrid behavior stopped after she started taking a vitamin B complex. I've been taking #ad Jarrow B-Right for many years. It makes me much easier to live with.
Unfermented soy is bad! “When she stopped eating soy, the mental problems went away.” Fermented soy doesn't bother me, but the various versions of unfermented soy (soy flour, soybean oil, and so on) that are used in all kinds of products these days causes a negative mental health reaction in me that a vitamin B complex can't tame. The sinister encroachment of soy has made the careful reading of ingredients a necessity.
If you are overweight, have type II diabetes, or are worried about the condition of your heart, check out the videos by William Davis and Ivor Cummins. It seems that most people should avoid wheat, not just those who have a wheat allergy or celiac disease. Check out these books: #ad Undoctored, #ad Wheat Belly, and #ad Eat Rich, Live Long.
Negative ions are good for us. You might want to avoid positive ion generators and ozone generators. Whenever I need a new air cleaner (with negative ion generator), I buy it from surroundair.com. A plain old air cleaner is better than nothing, but one that produces negative ions makes the air in a room fresher and easier for me to breathe. It also helps to brighten my mood.
Never litter. Toss it in the trash or take it home. Do not throw it on the ground. Also remember that good people clean up after themselves at home, out in public, at a campsite and so on. Leave it better than you found it.
Climate Change Cash Grab = Bad
Seems like more people than ever finally care about water, land, and air pollution, but the climate change cash grab scam is designed to put more of your money into the bank accounts of greedy politicians. Those power-hungry schemers try to trick us with bad data and lies about overpopulation while pretending to be caring do-gooders. Trying to eliminate pollution is a good thing, but the carbon footprint of the average law-abiding human right now is actually making the planet greener instead of killing it.
Watch these two YouTube videos for more information:
Take a look at my page called The H Word and Beyond. You might also want to look at my page called Zinc and Quercetin. My sister and I started taking those two supplements near the end of 2020 in the hopes that they would scare away the flu and other viruses.
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.
Use any example programs at your own risk. I am not responsible if they blow up your computer or melt your Atari 2600. Use assembly language at your own risk. I am not responsible if assembly language makes you cry or gives you brain damage.