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.

22 APPLE II COMPUTER GRAPHICSgates memory from within a BASIC program, without having to enter theMonitor. The command PRINT PEEK (37) , for example, will print the contentsof the thirty-seventh location in memory. PEEK is a decim<strong>al</strong>-orientedcommand, so in the previous example both the address (37), and the v<strong>al</strong>ueprinted are in decim<strong>al</strong> form.Another application of the statement involves PEEKi ng to see if a key hasbeen pressed. This is usefu l when the <strong>computer</strong> is required to processcontinuously and still look for a sign<strong>al</strong> to interrupt, such as a change ofdata. Many of the <strong>computer</strong>-based arcade games provide examples of thissince they must continuously animate the figures on the screen, but stillcheck for keyboard, game paddle, and/or joystick input in order to receiv<strong>et</strong>he sign<strong>al</strong> to fi re, change the player's direction, and so on.To illustrate use of the PEEK statement, key in the program given inListing 4-1 . When you have fin ished keying in the program, run it. Whatdo you see? You should see the l<strong>et</strong>ter "L" being continuously printed onthe screen. Press another key. "*ie character which was pressed will nowbe pri nted until y<strong>et</strong> another key is pressed, and so on. Program executionmay be stopped by pressing the res<strong>et</strong> key.10 REM DEM0NSTRATE PEEK20 REM30 P$ = "L"40 REM50 REM TOP OF LOOP60 PRINT P$;70 P = PEEK ( 49152) : REM SEE IF KEY PRESSED80 IF P > 127 THEN PRINT CHR$(7);:P$ = CHR$ (P-128): POKE -16368, 090 GOTO 50Listing 4-1.The following line-by-line explanation should clarify the example and itsuse of the PEEK command.30 P$ = "L"Line 30 assigns P$ an initi<strong>al</strong> v<strong>al</strong>ue of L.60 PRINT P$;Line 60 prints the v<strong>al</strong>ue of P$. The semicolon suppresses the usu<strong>al</strong>ly automaticline feed so that the printing will continue across the screen.70 P = PEEK ( 49152) : REM SEE IF KEY PRESSEDLine 70 assigns P the v<strong>al</strong>ue in location 49152. Location 49152 has twofunctions: the first is to sign<strong>al</strong> when a key has been pressed, and thesecond is to temporari ly hold the numeric code for that key. When a key ispressed, the left-most bit in byte 49152 is turned on, so the byte has a

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

Saved successfully!

Ooh no, something went wrong!