My second Atari Program - Gradient
In this new exercise, I challenged myself to create a gradient on the screen using Assembly language for the Atari 2600.
This time, I decided to play a bit with what I've already learned about Assembly language for the 6507 microprocessor of the Atari 2600 and challenged myself to create a red gradient to fill the screen. Since I already knew there are 192 scanlines used to "draw" in the visible area of the screen and that the red colors have 16 values between numbers 40 and 4F in hexadecimal, I divided 192 by 16 to discover that each strip of my gradient would consist of 12 scanlines. From there, I modified my Assembly code from the previous article so that it would draw 12 lines for each shade of red.
I admit it wasn't simple, mainly because I'm still getting used to Assembly language. During development, I discovered that I could use the bytes between addresses 80 and FF (in hexadecimal) to store variable values. This helped me a lot when creating the loop responsible for controlling when each stripe's color in the gradient should be changed.
Among the most important lessons learned from this challenge, in addition to the variable storage aspect described above, is that whenever I use the BNE conditional jump instruction, which jumps whenever the “zero bit” of the status register is set, I must be careful to check if there's any instruction before the BNE that might have altered the “zero bit” of the status register, changing the expected behavior. Another lesson I learned is the critical importance of controlling the number of CPU cycles each instruction demands, as this directly impacts the time we have to implement the program logic before each scanline. In the code I created, my synchronization is not perfect because I noticed some “noise” on the last scanline, which probably happened due to some issue with my CPU cycle management after the WSYNC. Since the objective of this exercise wasn't focused on that control, I didn't worry too much about it.
Gradient generated as a result of the code written in Assembly language for the Atari 2600.
If you enjoyed this article, be sure to check out part three.