Atari 2600 Programming for Newbies

Session 15: Playfield Continued

By Andrew Davie (adapted by Duane Alan Hahn, a.k.a. Random Terrain)

As an Amazon Associate I earn from qualifying purchases.

Page Table of Contents

Original Session

We've had a bit of time to think about the playfield, and hopefully have a go at some of the exercises. Admittedly I threw you in the deep end with the last sessionso we'll go back a step and walk through exactly what all this playfield oddity is about. We'll also tackle some of the exercises to show that there's more than one way to skin a fish.


Last session we learned that the playfield registers PF0 and PF2 are reversed. Specifically, the order of pixels in the playfield registers (one bit per pixel, remember!) is backward, compared to the order for the first playfield register we encounteredPF1. This backward ordering is rather confusing, but that's just the way it is. Have a close look at the diagram presented in the last session and try and understand exactly the "playfield register/bit" to "pixel position on the scanline" correspondence.

Playfield Wierdness






Playfield Mirroring

There's one new playfield-related capability of the '2600 which I'd like to introduce nowplayfield mirroring. I've already introduced this to you when I stated that the right hand side of the playfield was a copy of the left hand side (that is, the left 20 pixels come from the 20 playfield bits held in the TIA registers PF0, PF1 and PF2and the right 20 bits are a copy of the same bits). That copy can be displayed 'normally'or 'mirrored'. When mirrored, the bits are literally a mirrored copy of the left side of the playfield.


We're already familiar with two 'types' of TIA register. There's the strobe-type, where a write of any value to the register causes something to happen, independent of the value written (an example is WSYNC, which halts the 6502 until the TIA starts the next scanline). A second type is the normal register to which we write a byte, and the TIA uses that byte for some internal purpose (examples of these are the playfield registers PF0, PF1 and PF2). PF0 was a special-case of this type, wherethough we wrote a byteonly four of the bits were actually used by the TIA. The remaining bits were discarded/ignored (have a look at the PF0 register in the diagram in the last sessionthe X for each bit position in bits D0-D3 indicates those bits are not used).






The third type of register (they're not really 'types'but I want you to understand the difference between the way we're writing data to the TIA) is where we are interested in just the state of a single BIT in a register. Time to introduce a new TIA register, called CTRLPF. It's located at address 10 ($A)


     This address is used to write into the playfield control

     register (a logic 1 causes action as described below)

     D0 = REF (reflect playfield)

     D1 = SCORE (left half of playfield gets color of

     player 0, right half gets color of player 1)

     D2 = PFP (playfield gets priority over players so they

     can move behind the playfield)

     D4 & D5 = BALL SIZE

               D5   D4   Width

               0    0    1 clock

               0    1    2 clocks

               1    0    4 clocks

               1    1    8 clocks

Wow! This register has a lot of different stuff associated with it! Most of it is related to playfield display (bits D0, D1, D2) but bits D4 and D5 control the 'BALL SIZE'we'll worry about those bits later :)





D0 (Reflection)

Bit D0 controls the reflection (mirroring) of our playfield. If this bit is 0, then we have a 'normal' non-mirrored playfield, and that's what we've been seeing so far in our demos. If we set this bit to 1, then the '2600 will display a reflected playfield (that is, the right-side of the playfield is a mirror-image of the left-side, instead of a copy). Note that only a single bit is used to control this featureif we wrote a byte with this bit set (ie: %00000001) to CTRLPF we would also be setting those other bits to 0and we should be very sure this is what we want. In fact, it's often NOT what we want, so when we are writing to registers such as this (which contain many bits controlling different parts of the TIA hardware/display), we should be very careful to keep all the bits exactly as we need them. Sometimes this is done with a 'shadow' registera RAM copy of our current register state, and by first setting or clearing the appropriate bit in the shadow register, and THEN writing the shadow register to the TIA register. This is necessary because many/most of the TIA registers are only writablethat is, you cannot successfully read their contents and expect to get the value last written.


Let's have a quick look at those other bits in this register, related to playfield…





D1 (Two Colors)

D1 = SCORE. This is interesting. Setting this bit causes the playfield to have two colors instead of one. The left side of the playfield will be displayed using the color of sprite 0 (register COLUP0), and the right side of the playfield will be displayed using the color of sprite 1 (register COLUP1). We won't play with this for nowbut keep in mind that it is possible. Remember, this machine was designed for PONG-style games, so this sort of effect makes sense in that context.





D2 (Playfield Priority)

D2 = PFP. Playfield priority. You may have the playfield appear in front of, or behind, sprites. If you set this bit, then the playfield will be displayed in front, and all sprites will appear to go behind the playfield pixels. If this bit is not set, then all sprites appear to go in front of the playfield pixels.


That's a very quick rundown of this register. We know now that it controls the playfield mirroring (=reflection), the playfield color control for left/right halves, the playfield priority (if sprites go in front of or behind the playfield), and finally it does something with the 'BALL SIZE' which we're not worrying about yet.





Shadow Register

I've indicated that it's useful to have a 'shadow' copy of the register in RAM, so that we can easily keep track of the state of this sort of register. In practice, this is rarely doneas we generally just set the reflection on or off, the score coloring on or off, the priority on or off, and the ball size as appropriate… and then forget it. But if, for example, you were doing a game where you were changing the priority on the fly (so your sprites went behind SOME bits background, but not other bits) then you'd need to know what those other values should be.


In any case, the point of this is to introduce you slowly to more TIA capabilities, and at the same time build your proficiency with 6502 programming. Here's how we set and clear bits with 6502.


  CTRLPF_shadow = $82 ; a RAM location for our shadow register

  lda #%00000000

  sta CTRLPF_shadow   ; init our shadow register as required

   ; lots of code here

  lda CTRLPF_shadow

  sta CTRLPF          ; copy shadow register to TIA register

The above code snippet shows the general form of shadow register usage. The shadow register is initialisedand at some point later in the code, we copy it to the TIA register. Now for the fun bitsetting and clearing individual bits in the shadow register…


   ; how to set a single bit in a byte

   lda CTRLPF_shadow  ; load the shadow register from RAM

   ora #%00000001     ; SET bit 0 (D0 = 1)

   sta CTRLPF_shadow  ; save new register value back to RAM

   ; how to clear a single bit in a byte

   lda CTRLPF_shadow

   and #%11111110  ; keep all bits BUT the one we want to clear

   sta CTRLPF_shadow





AND and OR

OK, that's not too difficult to understand. The two new 6502 instructions we have just used are 'ORA', which does a logical-OR (that is, combines the accumulator with the immediate value bit-by-bit using a OR operation)and the 'AND', which does a logical-AND (again, combines the accumulator with the immediate value bit-by-bit using an AND operation). Now this is getting into pretty basic binary mathand you should read up on this stuff if you don't already know.

A bit is like a simple light switch. It can be on or off.



AND = OFF      (0 = OFF    1 = UNTOUCHED)

Use 0 to make sure the light switch is off.

Use 1 to leave it as it is.



OR = ON      (1 = ON    0 = UNTOUCHED)

Use 1 to make sure the light switch is on.

Use 0 to leave it as it is.



XOR = FLIP      (1 = FLIP    0 = UNTOUCHED)

Use 1 to reverse the position of the light switch.

Use 0 to leave it as it is.


Here are some truth tables for you…

OR operation

 BIT |   0     1


  0  |   0     1


  1  |   1     1

AND operation

 BIT |   0     1


  0  |   0     0


  1  |   0     1

Basically the above two tables give you the result FOR A SINGLE BIT POSITION, where you either OR or AND together two bits. For example, if I 'OR' together 1 and 0, the resultant value (bit) is 1. Likewise, if I 'AND' together a 1 and 0, I get a 0. This logical operation is performed on each bit of the accumulator, with the corresponding bit of the immediate value as part of the instruction. So 'ora #%00000001' will actually leave the accumulator with the lowest bit SET. No matter what. Likewise, 'and #%11111110' will leave the accumulator with the lowest bit CLEAR. No matter what. And in the other bits, their value will remain unchanged. You should try some values and check this out, because understanding this binary logical operation on bits is pretty fundamental to '2600 programming.





Playfield Reflection

In the initialization section of your current kernel, add the following lines…

    lda #%00000001

    sta CTRLPF

That's our playfield reflection in operationif you're running any sort of playfield code, you will see that the right-side is now a mirror-image of the left-side. Now have a think about the exercise I offered in session 14…

  1. How would you make a 'wall' which was 8 scanlines high, full screen width, followed by left and right walls just 1 pixel wide each, at extreme left/right edges of the screen, 176 scanlines high, followed by another horizontal 'wall', full screen width and 8 scanlines high? Note: this would form a 'box' border around the entire playfield.

It should be apparent, now, that in this sort of situation we really only need to worry about the left side of the playfield! If we let the '2600 reflect the right side, we will get a symmetrical copy of the left, and we'll have our box if only we do the left-side borders. This is a huge advantage to the programmer, because we suddenly don't have to write new PF0, PF1, PF2 values each scanline. Remember (and I'll drum this into you until the very last session!) we only have 76 cycles per scanlinethe less we have to do on any line, the better. At the very least, rewriting PF0, PF1 and PF2 twice per scanline would cost 30 cycles IF you were being clever. That's almost half the available time JUST to draw backgroundand there's still colors, sprites, balls and missiles to worry about! However, if you just use a reflected playfield, then we are only looking at single writes to PF0, PF1, PF2, cutting our playfield update to only 15 cycles per line (eg: lda #value / sta PF0 / lda #value2 / sta PF1 / lda #value3 / sta PF2).


Just an aside, heresome people have been posting code IN UPPERCASE. It is quite acceptable to use upper or lowercase for the mnemonics of your 6502 code. I prefer lowercase, as I find it easier to read and LESS LIKE SHOUTING! But its totally up to youyou will typically (but not always) find my code is lowercase, and you may feel free to adopt a style that suits you. I make my constants UPPERCASE, my variables typically a mixture, and my mnemonics lower-case. Your mileage may vary.


So, let's get down to ithere's a solution for exercise 5, of session 14…


; '2600 for Newbies
; Session 15 - Playfield Continued
; This kernel draws a simple box around the screen border
; Introduces playfield reflection 

                processor 6502

                include "vcs.h"

                include "macro.h"



                ORG $F000


   ; Clear RAM and all TIA registers

                ldx #0 

                lda #0 

Clear           sta 0,x 


                bne Clear


       ; Once-only initialization. . .

                lda #$45

                sta COLUPF             ; set the playfield color

                lda #%00000001

                sta CTRLPF             ; reflect playfield



   ; Start of new frame

   ; Start of vertical blank processing

                lda #0

                sta VBLANK

                lda #2

                sta VSYNC

                sta WSYNC

                sta WSYNC

                sta WSYNC               ; 3 scanlines of VSYNC signal

                lda #0

                sta VSYNC



       ; 37 scanlines of vertical blank. . .


                ldx #0

VerticalBlank   sta WSYNC


                cpx #37

                bne VerticalBlank


       ; Do 192 scanlines of color-changing (our picture)

                ldx #0                 ; this counts our scanline number

                lda #%11111111

                sta PF0

                sta PF1

                sta PF2

   ; We won't bother rewriting PF0-PF2 every scanline of the
   ; top 8 lines - they never change!

Top8Lines     sta WSYNC


              cpx #8                 ; Are we at line 8?

              bne Top8Lines          ; No, so do another

                   ; Now we want 176 lines of "wall"

                   ; Note: 176 (middle) + 8 (top) + 8 (bottom) = 192 lines

              lda #%00010000  ; PF0 is mirrored <-- direction,
                              ; low 4 bits ignored
              sta PF0

              lda #0

              sta PF1

              sta PF2

                ; Again, we don't bother writing PF0-PF2 every
                ; scanline - they never change!

MiddleLines   sta WSYNC


              cpx #184

              bne MiddleLines

             ; Finally, our bottom 8 scanlines - the same as the top 8

             ; AGAIN, we aren't going to bother writing PF0-PF2 mid scanline!

              lda #%11111111

              sta PF0

              sta PF1

              sta PF2

Bottom8Lines  sta WSYNC


              cpx #192

              bne Bottom8Lines



              lda #%01000010

              sta VBLANK          ; end of screen - enter blanking

   ; 30 scanlines of overscan. . .

              ldx #0

Overscan      sta WSYNC


              cpx #30

              bne Overscan

              jmp StartOfFrame


            ORG $FFFA


            .word Reset          ; NMI

            .word Reset          ; RESET

            .word Reset          ; IRQ


This kernel is interesting in that it achieves the box effect by writing the playfield registers BEFORE the scanline loops to do the appropriate section. It uses the knowledge that the TIA has an internal state and will keep displaying whatever it already has in the playfield registers. So, in fact, the actual cost (in cycles) of drawing the 'box' playfield on each scanline is 0 cyclesie; it's free. We just had that short initial load before each section (taking a few cycles out of the very first scanline of each section). This is how you need to think about '2600 programminghow to remove cycles from your scanlinesand do the absolute minimal necessary.


Here's a screenshot:

Kernel 15

Here's the .bin file to use with an emulator:








That will do for today's session. We've had an introduction to controlling individual TIA register bits, and seen how to achieve a reflected playfield at next to no cost. We've had a brief introduction to the CTRLPF register, and seen how it has a myriad (well, more than 3) uses. Although some of the previous sessions have asked you to think about tricky subjects like horizontal scrolling, and asymmetrical playfieldsnow is not the time to actually discuss these tricky areas. So until next time (when we'll develop our playfield skills a bit more)… ciao!







  1. Introduce a RAM shadow of the CTRLPF register, and modify it differently in each section of the kernel. For example turn reflection on and off partway through the midsection of the box, and see what happens.
  2. Have a play with the SCORE bit in the CTRLPF register, and in conjunction with that the COLUP0 and COLUP1 color registers. Note how this SCORE bit changes where the color for the playfield comes from.




Other Assembly Language Tutorials

Be sure to check out the other assembly language tutorials and the general programming pages on this web site.


Amazon Stuff


< Previous Session



Next Session >





Session Links

Session 1: Start Here

Session 2: Television Display Basics

Sessions 3 & 6: The TIA and the 6502

Session 4: The TIA

Session 5: Memory Architecture

Session 7: The TV and our Kernel

Session 8: Our First Kernel

Session 9: 6502 and DASM - Assembling the Basics

Session 10: Orgasm

Session 11: Colorful Colors

Session 12: Initialization

Session 13: Playfield Basics

Session 14: Playfield Weirdness

Session 15: Playfield Continued

Session 16: Letting the Assembler do the Work

Sessions 17 & 18: Asymmetrical Playfields (Parts 1 & 2)

Session 19: Addressing Modes

Session 20: Asymmetrical Playfields (Part 3)

Session 21: Sprites

Session 22: Sprites, Horizontal Positioning (Part 1)

Session 22: Sprites, Horizontal Positioning (Part 2)

Session 23: Moving Sprites Vertically

Session 24: Some Nice Code

Session 25: Advanced Timeslicing





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 Six Instruction Groups

The 6502 Instruction Set broken down into 6 groups.

6502 Instruction Set

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.

6502 Instruction Set

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.

NMOS 6502 Opcodes

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.

Instruction Set

Gives a summary of whole instruction set.

Addressing Modes

Describes each of the 6502 memory addressing modes.

Instruction Reference

Describes the complete instruction set in detail.



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.




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.




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. Stella finally got Atari 2600 quality sound in December of 2018. Until version 6.0, the game sounds in Stella were mostly OK, but not great. Now it's almost impossible to tell the difference between the sound effects in Stella and a real Atari 2600.




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



In Case You Didn't Know


Trump's Jab = Bad

Did you know that Trump's rushed experimental rona jab has less than one percent overall benefit? It also has many possible horrible side effects. Some brainwashed rona jab cultists claim that there are no victims of the jab, but person after person will post what the jab did to them, a friend, or a family member on web sites such as Facebook and Twitter and they'll be lucky if they don't get banned soon after. Posting the truth is “misinformation” don't you know. Awakened sheep might turn into lions, so powerful people will do just about anything to keep the sheep from waking up.


Check out these videos:

What is causing the mysterious self-assembling non-organic clots?

If You Got the COVID Shot and Aren't Injured, This May Be Why

Full Video of Tennessee House of Representatives Health Subcommittee Hearing Room 2 (The Doctors Start Talking at 33:28)



H Word and I Word = Good

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 have been taking those two supplements since summer of 2020 in the hopes that they would scare away the flu and other viruses (or at least make them less severe).



B Vitamins = Good

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 Jarrow B-Right (#ad) for many years. It makes me much easier to live with.



Soy = Bad

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.



Wheat = Bad

If you are overweight, have type II diabetes, or are worried about the condition of your heart, check out the videos by Ken D Berry, 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: Undoctored (#ad), Wheat Belly (#ad), and Eat Rich, Live Long (#ad).



Negative Ions = Good

Negative ions are good for us. You might want to avoid positive ion generators and ozone generators. 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.



Litterbugs = Bad

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.


Eliminating farms and ranches, eating bugs, getting locked down in 15-minute cities, owning nothing, using digital currency (with expiration dates) that is tied to your social credit score, and paying higher taxes will not make things better and “save the Earth.” All that stuff is part of an agenda that has nothing to do with making the world a better place for the average person. It's all about control, depopulation, and making things better for the ultra-rich. They just want enough peasants left alive to keep things running smoothly.


Watch these two YouTube videos for more information:

CO2 is Greening The Earth

The Climate Agenda



How to Wake Up Normies

Charlie Robinson had some good advice about waking up normies (see the link to the video below). He said instead of verbally unloading or being nasty or acting like a bully, ask the person a question. Being nice and asking a question will help the person actually think about the subject.


Interesting videos:

Charlie Robinson Talks About the Best Way to Wake Up Normies

Georgia Guidestones Explained

The Men Who Own Everything


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.


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