You are currently viewing Atari Assembly Color Change

Atari Assembly Color Change

This Atari Program Explained

This fun Atari assembly language program allows you to cycle through color changes using the console keys, and the space bar exits the program.

Studying this program should help you to gain a small grasp on how to write simple programs. Assembly language is all about starting small, and working your way up to the larger programs later. Think about using chunk sizes until you get to the good stuff.

Check for the Atari CONSOLE keys

First we set the program counter to memory location $8000. Next we clear the Console key buffer by placing a value of 8 there. This is because this register is updated every two stages during the Vertical Blank period.

Next we start the Console register (53279) to see if the option and start keys have been pressed and jump to those functions  if the zero page is cleared.

10 ;Atari Assembly Language Color Change

20 ;************************
30 ;* PROGRAM BEGINS
40 ;************************
50 ;
60 *= $8000
70 LDA #8
80 STA 53279
90 COLOR1
100 LDA 53279 ;Check if OPTION
110 CMP #3 ;is pressed
120 BEQ CHGCOL1 ;Yes!
130 CMP #6 ;START pressed?
140 BEQ CHGCOL2 ;Yes!
150 JMP COLOR1

Atari Space Bar Keyboard Routine

After this the Atari Assembly Language Color Change program reads an internal hardware value from 764 which is used to store values from keyboard presses. Once that space bar is pressed. A value of 255 is first issued to this memory location once information is received from the keyboard handler to clear it.

170 LDA 764 ;Check if the
180 CMP #$FF ;space bar is
190 BNE SPACEBAR ;pressed?
200 JMP COLOR1 ;Repeat loop
210 SPACEBAR
220 PLA ;use PLA & RTS when
230 RTS

Check for the Option key in the Console

A value (VALUE1) is increased in the accumulator to be later stored in the border color (712). We call a function (SLOWDOWN) to delay the cycle clock to slow everything down so we can see this in a smooth motion. The program jump returns back to the main loop otherwise.

250 ;The OPTION key was pressed
260 ;
270 INC VALUE1
280 LDA VALUE1
290 STA VALUE1
300 JSR SLOWDOWN
310 STA 712
320 JMP COLOR1

Check for the Start key in the Console

A value (VALUE2) is increased in the accumulator to be later stored in the background color (710). We call a function (SLOWDOWN) to delay the cycle clock to slow everything down so we can see this in a smooth motion. The program jump returns back to the main loop otherwise.

420 SLOWDOWN
430 LDX #$FF
440 LDY #230
450 PACE DEX
460 BNE PACE
470 INY
480 BNE PACE
490 RTS

Create a delay in a nested loop

This is the function routine that is used to slow down the program. Essentially it just accumulates clock cycles in a nested loop.

330 CHGCOL2
340 ;The START key was pressed
350 ;
360 INC VALUE2
370 LDA VALUE2
380 STA VALUE2
390 JSR SLOWDOWN
400 STA 710
410 JMP COLOR1

Setup the program's variables

Finally the last part of the program stores information for VALUE1 and VALUE2 which tracks the color changes in the border and background colors.

510 ;Lobyte directives
520 VALUE1 .BYTE 50
530 VALUE2 .BYTE 128

I hope you learned about the keyboard handler and enjoyed this session for Atari Assembly language programming.

Before sure to also check out the article on the Atari Graphics 1 to learn more about colors on the Atari.

Feel free to leave any comments or questions below as I would love to hear back from you. Finally I appreciate sharing this on social media if you liked it and it was helpful.