This program will make the screen flash on the Commodore 128, and it will also run on the Commodore 64. The background color of the screen is stored at D021 (53281), so this effect is accomplished by manipulating the value at that address, multiple times. This program cannot be written in Basic, because the Basic interpreter is too slow.
Remember that the machine code monitor expects code in one format, and displays it in another, so what I show here, is what I actually type in. I will write my program at location 1000 (4096) in the memory. Type MONITOR to enter the machine code monitor, and type F 1000 1100 0 to create some free space.
To begin writing code, type . directly followed by the address you want to add an instruction to, followed by the instruction and the desired parameters. This stores what you just typed in, and expects you to type in the next command, or just hit Enter to exit the edit mode.
.1000 LDA #$01 STA $D021 NOP NOP NOP LDA #$0B STA $D021 NOP NOP NOP
(and so on…)
Let the final command in your program be JMP $1000.
Press Enter to exit edit mode, type X and Enter to exit the monitor. Start your program by typing SYS 4096. Your screen should now be flashing hysterically!
On the first row, .1000 tells the Commodore 128 machine code monitor that I want my program to start at address 1000 (4096). LDA loads a value to the accumulator, and STA stores current value in the accumulator to the given memory address, D021 (53281). The specific memory address D021 controls the background color. NOP means “no operation” and is used only to make the effect less hysterical. Finally, JMP jumps to the given address, creating an infinite loop. Who needs fireworks now?
The X position however, is a bit more tricky. The X coordinate is stored at D000 (53248). But we need more than 256 possible positions to be able to place the sprite on the right side on the screen. Commodore did not waste a whole byte on solving this problem. At D010 (53264), the first bit keeps track on if D000 holds a value that represent the left part of the screen, or the right part of the screen for the first sprite (sprite 0). We have eight sprites and eight available bits at D010, so the second bit keeps track on if D002 (53250) holds a value that represent the left part of the screen, or the right part of the screen for the second sprite (sprite 1), and so on. So this is what we must do to make the sprite we displayed in the above program run over the screen:
Följande text är hämtad från
A nice and quick way to create two filled sprites (sprite 1 and 2) is to enter the monitor and type:
On a Commodore PET, each byte that can be read using the PEEK function, and set using the POKE statement. A byte consist of 8 bits, and represent a number between 0 and 255. This code writes the value 5 to the memory address 1020, and then reads it back. The output is of course 5.
The bit pattern at 1024 is now 10000101. The value that is stored at 1024 is 133, because 1 + 4 + 128 equals 133. To turn the last bit (128) back to zero, use AND together with bit pattern that contains a one at all positions that you want the existing flag to remain, and 0 at the positions you want to turn bytes off. To turn the last bit from the right off, you would want a bit pattern that looks like this: 01111111. All bytes remains, but the last bit from the right is 0. The number 127 has this pattern.




