12.07.2015 Views

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

162 APPLE II COMPUTER GRAPHICSs<strong>et</strong> up a table which assigns to each line on the screen ((/J- 191) its startingaddress.Line 515 divides the X-coordinate by 7 to d<strong>et</strong>ermine which of the 4(/Jbytes across the screen the missile is in (Q%), and which dot in that bytewill be the point of the missile (R%). L<strong>et</strong>'s suppose that the missile is fi redat X-coordinate 45, so the tip is in byte number 6 and dot number 3(counting the fi rst dot in each byte as number (/)). As we move the missileup, we need to check the third dot in the byte above the missile before wemove. As long as that dot is off, then there is nothing to hit. If that dot ison, then we are about to run into ' the targ<strong>et</strong>, and need to s<strong>et</strong> the collisionflag.Isolating a particular dot is clumsy, but lines 338-546 do the job. Line336 s<strong>et</strong>s V% to the v<strong>al</strong>ue of the byte you need to check. To understandhow these lines operate, it is instructive (though tedious) to s<strong>et</strong> V% to, say!(/J(/)1 1 11(/J(/J (6(/J), and step through those lines by hand. Here we go.If the X-coordinate is 45, then line 515 c<strong>al</strong>culates R% to be three (we arechecking fo r dot number 3 in the byte), and then adds 1 to it so R% entersthe loop at 538 with a v<strong>al</strong>ue of four. Dot number 3 corresponds to thefou rth bit from the right, yes the FOU RTH bit, for they are numbered (/), 1,2, and 3.P% is the v<strong>al</strong>ue d<strong>et</strong>ermi ned by two to the "I" power, and that justhappens to correspond to each digit in a binary byte. Two to the eighth isthe left-most bit (128), two to the seventh is the next bit over, and so on.Each time the loop is executed, it effectively checks one of the bits in thebyte and turns it off if it happens to be on. This continues until the bitind icated by R% is reached. L<strong>et</strong>'s run through the example using Figure14-1 .IP%V%765412864321660602812! 0011 1100! 0011 1100i0001 ·· 1100! 0000 1100312 =Figure 14-1.The first time through the loop, I = 7, so P% = 128. Line 542 fi nds thecomparison (IF V% > = P%) f<strong>al</strong>se, so it does not subtract anything fromV%. The second time through, P% = 64, still greater than V%, so againnothing happens. But on the third iteration, I = 5, P% = 32, so P% issubtracted from V% to res<strong>et</strong> V% at !(/J(/J(/)1 11 (/)(/). As promised, the bit was

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!