Path: news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!vixen.cso.uiuc.edu!newsfeed.internetmci.com!news.dacom.co.kr!news.uoregon.edu!cie-2.uoregon.edu!nparker From: nparker@cie-2.uoregon.edu (Neil Parker) Newsgroups: comp.sys.apple2.programmer Subject: Re: PEEKs and POKES Date: 19 Apr 1996 21:12:14 GMT Organization: University of Oregon Campus Information Exchange Lines: 64 Message-ID: <4l8vje$bj@pith.uoregon.edu> References: <4l47v1$lun@newsbf02.news.aol.com> NNTP-Posting-Host: cie-2.uoregon.edu In article <4l47v1$lun@newsbf02.news.aol.com> cbrmaster@aol.com (CbrMaster) writes: >I need to write a program that will allow me to control a cursor on the >Apple IIe/gs. Using the PEEK(49168) to get data from the keyboard. Also >I need to get the cursors location so it acts like a arrow controlled >mouse. The Peek values for the up, down, left, and right are 139, 138, >136, 149 (I think). First, it's preferable to use PEEK(49152) to read the keyboard. The value will be greater than 127 if a key was pressed since the last time you checked. When you have the keypress, POKE 49168,0 to reset the keyboard for the next keypress. let K = PEEK(49152)-128 if K<0 then no key was pressed else POKE 49168,0 if K = 8 then left arrow was pressed if K = 21 then right arrow was pressed if K = 10 then down arrow was pressed if K = 11 then up arrow was pressed endif If the 80-column display is inactive, then the current cursor position can be found in PEEK(36) (horizontal position, 0-39) and PEEK(37) (vertical position, 0-23). If the 80-column display is active, substitute PEEK(1403) for PEEK(36). But if I understand your intent correctly, you probably don't need to keep track of the system's cursor position at all--you can probably get along just fine using your own "private" cursor. For example, 10 PRINT CHR$ (21): TEXT : HOME 20 X = 1:Y = 1:XP = 1:YP = 1: PRINT "*"; 30 IF X = XP AND Y = YP THEN 70 40 HTAB X: VTAB Y: PRINT "*"; 50 HTAB XP: VTAB YP: PRINT " "; 60 XP = X:YP = Y 70 WAIT 49152,128: K = PEEK (49152) - 128: POKE 49168,0 80 IF K = 8 THEN X = X - 1: IF X < 1 THEN X = 1 90 IF K = 21 THEN X = X + 1: IF X > 40 THEN X = 40 100 IF K = 10 THEN Y = Y + 1: IF Y > 24 THEN Y = 24 110 IF K = 11 THEN Y = Y - 1: IF Y < 1 THEN Y = 1 120 IF K = 27 THEN VTAB 22: END 130 GOTO 30 This lets you move a "*" around the screen using the arrow keys. Note that the new cursor isn't PRINTed unless a movement occurred--this helps to reduce flickering. Beware of the lower right corner of the screen--when you try to PRINT anything in that position, the screen scrolls, even if the PRINT statement ends with a semicolon. The above program makes no attempt to compensate for this problem, so moving the "*" into the lower right corner will cause "glitches" on the display. The problem could have been avoided by POKEing the cursor character into the screen memory instead of PRINTing it. - Neil Parker -- Neil Parker | No cute quote, no cute ASCII art, no cute nparker@cie-2.uoregon.edu | disclaimer, no deposit, no return.... nparker@cie.uoregon.edu | (This space intentionally left blank: http://cie-2.uoregon.edu/~nparker | )