EUG PD


Scrolling Stars

 
Published in EUG #55

This file explains the code to the short assembly language utility "U.STARS" present on this disk, which creates a backdrop of scrolling stars. The 'stars' are really moving white dots, but the effect is impressive, and it's easier to achieve than you might think.

We first of all set up a table of 30 addresses in the range &3000-&7FFF. That is to say, choose some random two-byte pointers into the Mode 2 screen. This is done in lines 570-610; the addresses are held at TABLE.

The machine code routine BACKDROP EORs 21 (the pixel code for black-white in Mode 2) into each of the addresses. The routine SCROLL then moves each address down the screen by one pixel before redrawing the screen. But there are two things to watch out for:

  1. If the star's address is the bottom row of a character row, then it needs to be changed to the top row of the next character row. We detect this by ANDing the low byte of the address with 7 and then CoMParing it with 7. If the result is 7, then &278 must be added to the address. For example, the low byte of &3007 is &07, &07 AND 7=7, so &3007 + &278=&327F, and because all addresses are INCremented by one, &327F + 1=&3280, the address of the second character row in Mode 2.
  2. The star's address may have gone off the bottom of the screen, i.e. it's bigger than &7FFF. The way to check this is to examine the state of the Negative flag after the addition of &278. It will set if the high byte if &80 or more - i.e. the address is &8000 or greater - because in "two's complement" arithmetic a number above &7F is a negative number. We then 'wrap around' the address to the top of the screen by subtracting &50 (the Mode 2 screen is &5000 bytes big). If the result wasn't bigger than &80, the BPL CONT2 skips this substraction. So why is the instruction SBC #&4F and not SBC #&50? Well, subtracting one less than is necessary saves an SEC instruction.
This all adds up to a short and efficient routine, only 135 bytes long including the table of addresses, that you could include in your games programs. One alteration you could make is to have coloured stars by using the X register to derive the colour.

Chris Dewhurst, EUG #55

Chris Dewhurst