Mouse Basic program needs correction

7 posts / 0 new
Last post
Khaibitgfx's picture
Offline
Last seen: 15 hours 38 min ago
Joined: Jun 29 2019 - 20:02
Posts: 207
Mouse Basic program needs correction

This program needs corrections to operate properly. Your input please...

 

1 REM **********************

2 REM * MOUSE SKETCH *

3 REM **********************

 

100 REM *** VARIABLE USAGE ***

110 REM * X, Y = CURRENT MOUSE POSITION

120 REM * OX, OY = PREVIOUS POSITION

130 REM * C = COLOR AT (X,Y)

140 REM * S = MOUSE BUTTON STATUS

150 REM * N = MOUSE SLOT NUMBER

 

200 GOSUB 710: IF N = 0 THEN PRINT "NO MOUSE DETECTED!": END

 

210 GOSUB 620: REM INITIALIZE SCREEN & MOUSE

220 PRINT D$"IN#"N: REM GET INPUT FROM MOUSE

 

230 REM *** MAIN LOOP ***

240 GOSUB 390: REM READ MOUSE POSITION

250 GOSUB 300: REM UPDATE SCREEN

260 GOTO 230 : REM LOOP

 

300 REM *** SCREEN UPDATE LOGIC ***

310 IF PEEK (49249) >= 128 OR PEEK (49250) >= 128 THEN IF S < 3 THEN C = 0: COLOR=0: GOTO 330

320 IF OX <> X OR OY <> Y THEN IF S >= 2 THEN COLOR = C: PLOT OX,OY: C = SCRN(X,Y)

330 IF S < 0 THEN GOSUB 460: RETURN

340 COLOR = 15: IF S > 2 THEN COLOR = 1

350 PLOT X, Y

360 OX = X: OY = Y

370 RETURN

 

390 REM *** GET MOUSE DATA ***

400 INPUT "";X,Y,S

410 X = INT (X / 25.575)

420 Y = INT (Y / 25.575)

430 RETURN

 

460 REM *** HANDLE KEYBOARD INPUT ***

470 POKE -16368,0

480 PRINT D$"IN#0"

490 PRINT "RETURN=CONTINUE, ESC=QUIT, CTRL-C=CLEAR";: GET A$

500 IF A$ = CHR$(3) THEN HOME: GOSUB 620: RETURN

510 IF A$ = CHR$(13) THEN RETURN

520 IF A$ = CHR$(27) THEN END

530 PRINT CHR$(7): GOTO 490

 

600 REM *** INITIALIZE SCREEN & MOUSE ***

610 HOME: GR

620 D$ = CHR$(4)

630 C = 0

640 PRINT D$"PR#"N: PRINT CHR$(1)

650 PRINT D$"PR#0"

660 RETURN

 

710 REM *** FIND MOUSE SLOT ***

720 FOR I = 1 TO 7

730 IF PEEK(49420 + 256 * (I - 1)) = 32 AND PEEK(49659 + 256 * (I - 1)) = 214 THEN N = I: RETURN

740 NEXT I

750 N = 0

760 RETURN

 

 

CVT
CVT's picture
Offline
Last seen: 1 hour 49 min ago
Joined: Aug 9 2022 - 00:48
Posts: 1251
I posted the correct version

I posted the correct version here a few days ago: https://www.applefritter.com/comment/110954#comment-110954

Khaibitgfx's picture
Offline
Last seen: 15 hours 38 min ago
Joined: Jun 29 2019 - 20:02
Posts: 207
This version is meant to be

This version is meant to be more structured and efficient unfortunately there is a problem someplace.

CVT
CVT's picture
Offline
Last seen: 1 hour 49 min ago
Joined: Aug 9 2022 - 00:48
Posts: 1251
Khaibitgfx wrote:This version
Khaibitgfx wrote:

This version is meant to be more structured and efficient unfortunately there is a problem someplace.

 

Where did you get it from?

The one I posted is directly from Programming the Apple Mouse II: https://www.applefritter.com/files/2023/03/02/AppleMouseII.pdf

Khaibitgfx's picture
Offline
Last seen: 15 hours 38 min ago
Joined: Jun 29 2019 - 20:02
Posts: 207
It was posted on Twitter, or

It was posted on Twitter, or x as they are now called, I downloaded the text, tried it on apple2win, it didn't work, I tried your source, that worked, since I'm severely limited in how Apple basic works, perhaps this code is missing something, no idea really, visually it looks more streamlined to me, not that it matters if it doesn't work of course.

Offline
Last seen: 2 hours 45 min ago
Joined: Feb 27 2021 - 18:59
Posts: 695
bugged

The bug is on line 730.

Iteration (FOR... NEXT) and subroutines (GOSUB ... RETURN) both use the top of the stack. You can't mix them in that way (by using RETURN inside of FOR...NEXT), because the wrong word is taken from the top of the stack.

Khaibitgfx's picture
Offline
Last seen: 15 hours 38 min ago
Joined: Jun 29 2019 - 20:02
Posts: 207
Thanks for the correction. 

Thanks for the correction.

 

So from your point of view how does this basic program compare to the original source code mentioned above?

 

yes

Log in or register to post comments