REM HOW TO CALCULATE THE HIRES ADDRESS
REM GIVEN THE COORDINATE OF A PIXEL
REM THE APPLE II HI-RESOLUTION SCREEN
REM HAS SOME IDIOSYNCRASIES IN THE WAY
REM IT IS MAPPED IN MEMORY
NEW
REM PLOT A PIXEL SOMEWHERE ON THE SCREEN
REM THE X AND Y VALUES ARE CHOSEN RANDOMLY
REM HI-RES PAGE 2 IS DISPLAYED FULLSCREEN
REM THE SCREEN IS CLEARED TO BLACK
REM THE COLOR IS SET TO WHITE BEFORE
REM A SINGLE PIXEL IS PLOTTED
1 X = INT ( RND (1) * 280)
2 Y = INT ( RND (1) * 192)
3 HGR2
4 HCOLOR= 3
5 HPLOT X,Y
REM DETERMINE THE HI-RES PAGE:
REM PG
REM IS IT HGR (HI-RES PAGE 1), OR
REM IS IT HGR2 (HI-RES PAGE 2) ?
10 PG = PEEK (230)
REM IF PG = 32 THEN IT'S HGR
REM IF PG = 64 THEN IT'S HGR2
REM GIVEN A Y VALUE FROM 0 TO 191:
REM Y
REM *** EVERY 8 PIXELS GOING DOWN THE SCREEN
REM DETERMINE THE VERTICAL POSITION: DIVIDE BY 8
20 VT = INT (Y / 8)
REM VT WILL HAVE A VALUE FROM 0 TO 23
REM WHICH IS, BY THE WAY, THE SAME AS THE
REM VERTICAL POSITION (VTAB - 1) ON THE TEXT SCREEN
REM DETERMINE THE REMAINDER: MODULA 8
30 Y8 = Y - VT * 8
REM Y8 WILL HAVE A VALUE FROM 0 TO 7
REM *** EVERY 2 ROWS GOING DOWN THE SCREEN
REM GIVEN THE VERTICAL POSITION: DIVIDE BY 2
40 YH = INT (VT / 2)
REM YH WILL HAVE A VALUE FROM 0 TO 11
REM WHICH IS HALF THE VERTICAL POSITION
REM DETERMINE THE REMAINDER: MODULA 2
50 Y2 = VT - YH * 2
REM Y2 WILL HAVE A VALUE OF EITHER 0 OR 1
REM *** EVERY THIRD OF THE SCREEN GOING DOWN THE SCREEN
REM GIVEN THE HALVED VERTICAL POSITION: DIVIDE BY 4
60 Y3 = INT (YH / 4)
REM Y3 WILL HAVE A VALUE FROM 0 TO 2
REM DETERMINE THE REMAINDER: MODULA 4
70 Y4 = YH - Y3 * 4
REM Y4 WILL HAVE A VALUE FROM 0 TO 3
REM GIVEN AN X VALUE FROM 0 TO 279:
REM X
REM DETERMINE THE HORIZONTAL OFFSET IN BYTES: DIVIDE BY 7
80 HT = INT (X / 7)
REM HT WILL HAVE A VALUE FROM 0 TO 39
REM WHICH IS, BY THE WAY, THE SAME AS THE
REM HORIZONTAL POSITION (HTAB - 1) ON THE TEXT SCREEN
REM DETERMINE THE REMAINDER: MODULA 7
90 X7 = X - HT * 7
REM X7 WILL HAVE A VALUE FROM 0 TO 6
REM CALCULATE THE ADDRESS ON THE SCREEN:
REM A
100 A = Y3 * 0040 + HT
110 A = Y2 * 0128 + A
120 A = Y4 * 0256 + A
130 A = PG * 0256 + A
140 A = Y8 * 1024 + A
REM PRINT THE PIXEL COORDINATE BESIDE THE BYTE VALUE
REM OF THE ADDRESS THAT WAS CALCULATED
150 PRINT X;",";Y, PEEK (A)
REM PRINT THE STATEMENT THAT WOULD POKE THE ADDRESS
REM WITH THE CALCULATED BYTE VALUE
160 PRINT "POKE ";A;",",2 ^ X7
REM THE BYTE VALUES SHOULD BE EQUAL
170 TEXT
RUN
LIST