Continuing with my simple PREFS program, I made a simple modification to learn about the JMP (JuMP) instruction. This also gave me the opportunity to learn about labels, not that there is much to learn, and how defines work in Mac/65. These are not permanent, just experimental.
Now the program jumps around doing different steps in a non-linear order. It also utilizes the random number memory location and sets the background color to whatever value it contains at runtime. The Atari 8 bit computer random number location is 53770 ($D20A). It will always have a number between 0 ($00) and 255 ($FF) in it.
The definition of the JMP instruction is:
- JMP (JuMP): Alters program execution to the jump address specified.
Adding It In
Rather than drive straight through, I’ve added labels and a series of JuMPs to alter the order in which the settings are made. I also renumbered the first couple of line to make room for modifications.
10 *= $3800 20 .OPT OBJ 50 ; Define memory location 53770 as RAND 51 RAND = $D20A 105 ; 106 ; Set left margin to 0 110 LDA #0 120 STA 82 121 JMP COLOR 125 ; 126 ; Set key repeat rate 130 KEYS LDA #2 140 STA 730 145 ; Set key delay 150 LDA #14 160 STA 729 161 JMP CLICK 165 ; 166 ; Set random background color 170 COLOR LDA RAND 180 STA 710 185 ; Set text color 190 LDA #$0C 200 STA 709 201 JMP KEYS 205 ; 206 ; No key click 210 CLICK LDA #1 220 STA 731 225 ; 230 RTS 240 .END
Breaking It Down
Changes in source from last time are bold.
- 10: Specify the load address of $3800
- 20: Tell Mac/65 to product object code
- 51: Tell Mac/65 to replace occurrences of RAND with $D20A
- 110: Load the accumulator with decimal value 0
- 120: Store the accumulators contents (0) into memory location 82 (the right margin)
- 121: Jump to the address referenced by the label COLOR
- 130: Assign location to label KEYS. Load the accumulator with decimal value 2
- 140: Store the accumulators contents (2) into memory location 730 (the key repeat rate)
- 150: Load the accumulator with decimal value 14
- 160: Store the accumulators contents (14) into memory location 729 (the key repeat delay)
- 161: Jump to the address referenced by the label CLICK
- 170: Assign location to label COLOR. Load the accumulator with the value from the memory location identified by RAND.
- 180: Store the accumulators contents (random #) into memory location 710 (the background color for graphics 0 display mode)
- 190: Load the accumulator with hex value 0C
- 200: Store the accumulators contents (decimal 12) into memory location 709 (the text color for graphics 0 display mode)
- 201: Jump to the address referenced by the label KEYS
- 210: Assign location to label CLICK. Load the accumulator with decimal value 1
- 220: Store the accumulators contents (1) into memory location 731 (the key click; > 0 is off)
- 230: Return
- 240: Tell the assembler we’re done.
Trying It Out
After compiling with “ASM ,,#D:PREFS.COM”, drop back to DOS and run it with “D:PREFS.COM”. My data drive is D2 so you’ll see D2 instead of D in the screen shots. At DOS, about to press [RETURN] for the first run:
After the first run:
I ran it again to validate I got a different random color:
Success! Now I want it to print something on the screen. Hopefully that isn’t too complex.
Thanks to Bill L for pointing out a listing mistake. It is now corrected in the post above. Line 170 did not reference RAND, but instead a set hex value. I inadvertently copied and pasted from a different version of the source code. Sorry about that.