inexorabletash / jsbasic

Applesoft BASIC in JavaScript

Home Page:https://calormen.com/jsbasic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add mouse support

inexorabletash opened this issue · comments

ftp://ftp.apple.asimov.net/pub/apple_II/documentation/hardware/io/AppleMouse%20II%20User's%20Manual.pdf

tl;dr:

5 S = 4 : REM Slot - should scan for it 
10 PRINT CHR$(4)"PR#"S :  PRINT CHR$(1) : PRINT CHR$(4)"PR#0" : REM Initialize mouse 
20 PRINT CHR$(4)"IN#"S : INPUT "";X,Y,B : PRINT CHR$(4)"IN#0" : REM Read mouse 
30 PRINT X,Y,B : REM x,y coords, button state (4=up, 2=pressed, 1=down, 3=released) 
40 GOTO 20 

... where B will be negative if a key is pressed, until strobe is cleared (POKE 49168,0)

And to scan for the mouse - using Pascal 1.1 protocol:

10 FOR S = 1 TO 7 : SO = S * 256 
20 IF PEEK(49157 + SO) = 56 AND PEEK(49159 + SO) = 24 AND PEEK(49163 + SO) = 1 AND PEEK(49164 + SO) = 32 THEN PRINT "Mouse is in slot ";S : END 
30 NEXT 

Or alternately just $Cn0C == $20 && $CnFB == $D6:

10 FOR S = 1 TO 7 : SO = S * 256 
20 IF PEEK(49164+ SO) = 32 AND PEEK(49403 + SO) = 214 THEN PRINT "Mouse is in slot ";S : END 
30 NEXT : PRINT "No mouse :("