A Mouse In Applesoft
I recently purchased an Apple IIGS system. I am happy with it, but I cannot find out how to use the mouse in my own programs. I would appreciate any information you could give me.
The Apple IIGS and Apple IIc both have a built-in mouse port. (A mouse is also available for the Apple IIe.) The mouse is accessed through slot 4. At the beginning of your program, you should initialize the mouse with the following code:
PRINT CHR$(4) "PR#4" PRINT CHR$(1) PRINT CHR$(4) "PR#0"
This turns on the mouse and enables transparent mode, which sets up an interrupt routine to update the mouse position counters each time the mouse is moved. This is the only mouse mode that works with Applesoft BASIC.
After initializing the mouse, you must set up the mouse for input with the command IN#4. Now, the mouse can be read using a statement of the form
INPUT X, Y, ST
where the X variable returns a value in the range 0–1023, representing the horizontal coordinate of the mouse; the Y variable returns a value in the range 0–1023, representing the vertical coordinate of the mouse; and the ST variable returns a value representing the status of the mouse button. The button status value will be 1 if the mouse button is currently being pressed, 2 if it was just pressed, 3 if it was just released, and 4 if the button is currently released.
After you are through reading the mouse, your program must execute an IN#0 statement so that the computer again looks to the keyboard for input.
The following BASIC program lets you draw on the high-resolution screen with a mouse. To exit the program, press the mouse button.
10 PRINT CHR$(4) "PR#4" 20 PRINT CHR$(1) 30 PRINT CHR$(4) "PR#0" 40 PRINT CHR$(4) "IN#4" 50 HGR : POKE -16302,0 60 INPUT X, Y, ST 70 X1 = INT(X / 3.65357143):Y1 = INT(Y / 5.35602094) 80 HPLOT X1,Y1 90 IF ST = 4 THEN GOTO 60 100 PRINT CHR$(4) "IN#0" 110 HOME : TEXT