How to use the Mouse Wheel on X16 (BASIC and ASM)

Post Reply
voidstar
Posts: 359
Joined: Thu Apr 15, 2021 8:05 am

How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by voidstar »

Mouse Wheel support is confirmed working (thanks to Stefan Jakobsson!).

An SMC ROM update is needed. I had trouble doing this on my H/W #108, but MooingLemur helped me out!! If you have a DevBoard, some feedback on if others are also having trouble would be good too (something about the bootloader might be there, but some fuse values may be incorrect on ATtiny? should try to confirm before Kevin prints the next batch!)

Some System ROM updates are also needed for the BASIC command support, and KERNAL support. This will probably become standard in the next "R45" System ROM update. For now, it is this update to R44:
https://github.com/X16Community/x16-rom ... 6079048038

Here is some BASIC code on using it (which also includes an example of how to do some "inline machine code" in BASIC-- it's an optional/alternative way to access the mouse wheel; a more typical way is to just use the MB and MWHEEL BASIC keywords that are added).

HOWEVER... The "scale" or range of mouse wheel values differs between the asm and BASIC. See below for example.

NOTE: I only tried using the Perixx mouse that came with the X16 DevBoards (same brand as the keyboards)

Code: Select all

10 W=$2000:WT=W
20 READ A:REM READ THE NEXT DATA VALUE (AT END OF LISTING)
30 IF A=-1 THEN GOTO 70
40 POKE WT,A
50 WT=WT+1
55 GOTO 20
60 ZZ=0:REM 0 FOR ASM SYS, 1 FOR BASIC MWHEEL
70 MOUSE 1
80 CLS:MWACC=0:A=49:REM SET TO DEFAULT TO ASM MODE
90 GOTO 237
130 IF ZZ=0 GOTO 160:REM GOTO ASM MODE
140 GOTO 190:REM GOTO BASIC MODE
160 SYS W:REM INVOKE MACHINE CODE. RTS TO GET BACK
170 A=PEEK($0780)
180 GOTO 200
190 A=MWHEEL
200 MWACC=MWACC+A:REM JUST MW ACCUMULATOR (NOT REALLY USEFUL)
210 IF A=0 AND MB=0 GOTO 230:REM ONLY PRINT WHEN NEW STATE
220 PRINT MWACC;:PRINT MB;:PRINT A
230 GET A$:A=ASC(A$)
235 IF A = 0 GOTO 260
236 IF A=27 THEN END:REM ESCAPE TO EXIT
237 PRINT "SWITCH MODE [";
240 IF A=49 THEN ZZ=0:PRINT"ASM]":GOTO 260:REM PRESS 1 FOR ASM
250 IF A=50 THEN ZZ=1:PRINT"BASIC]":REM PRESS 2 FOR BASIC MWHEEL
260 GOTO 130
1000 DATA $A2,$22    :REM LDX #$22
1010 DATA $20,$6B,$FF:REM JSR $FF6B
1020 DATA $8E,$80,$07:REM STX $0780
1030 DATA $60        :REM RTS
1040 DATA -1        :REM END OF LINE

Here is an example of the output. When running the BASIC sample, press #1 for the "assembler" version, press #2 for the BASIC version.
mousewheelx16.jpg
mousewheelx16.jpg (397.09 KiB) Viewed 3003 times
In the ASM call, SLOW MOUSE WHEEL UP will be value 255. The faster you scroll, the lower from 255 it will go (lowest I got was a value of about 251). SLOW MOUSE WHEEL DOWN will be value 1, and the faster you scroll (down) the higher from 1 it will go (highest value I got was about 7).

In the BASIC call, using MWHEEL: negative values are SCROLL UP. So -1 is a slow UP scroll, then faster scrolling "decreases" from there (I only got up to about -3 or -4). Positive values are SCROLL DOWN, starting at 1. Faster scrolling down increases that value (I only got up to value 4 or 6).

BASIC variable MB is updated to also recognize the mouse wheel itself as a button click.
Last edited by voidstar on Wed Oct 18, 2023 4:44 am, edited 1 time in total.
voidstar
Posts: 359
Joined: Thu Apr 15, 2021 8:05 am

Re: How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by voidstar »

And... Here is a dumb Fishing Game that I put together, it might be the first BASIC program in the world that makes use of a mouse wheel!!? :P

Code: Select all

10 SCREEN 3:COLOR 15,6:CLS:MOUSE 1
15 YP=10:XP=30
20 XV=0:GOTO 300
30 XV=XV+0.5
40 Y=2*SIN(XV)+10
50 YD=INT(Y)+1
58 IF (XD=XP) AND (YD=YP-1) GOTO 2000
60 XD=INT(XV)+1
65 IF XD>(XP+1) GOTO 1000
66 IF (XD=XP) AND (YD=YP) GOTO 2000
67 IF (XD=XP) AND (YD=YP+1) GOTO 2000
70 LOCATE YD,XD
75 COLOR 14,6
80 PRINT CHR$(119)
90 SLEEP RND(1)*20+1
100 LOCATE YD,XD
110 PRINT" "
220 A=MWHEEL
230 IF A=0 GOTO 310
235 LOCATE YP,XP:PRINT "\XA0"
240 IF A>0 GOTO 280
250 REM MOVE UP
260 YP=YP+A
265 IF YP<3 THEN YP=3:GOTO 300
270 GOTO 300
280 REM MOVE DOWN
290 YP=YP+A
295 IF YP>15 THEN YP=15:GOTO 300
300 COLOR 15,6:FOR I = 1 TO 30
301 LOCATE I,XP
302 IF I<YP THEN PRINT CHR$(125)
303 IF I=YP THEN PRINT "J"
304 IF I>YP THEN PRINT"\XA0"
305 NEXT I
310 GOTO 30
1000 PRINT "YOU LOST!"
1010 END
2000 PRINT "YOU GOT A FISH!":END
https://www.youtube.com/watch?v=wqYOSKbUIJU
Stefan
Posts: 434
Joined: Thu Aug 20, 2020 8:59 am

Re: How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by Stefan »

The mouse wheel return value in assembly is an 8 bit signed value (2’s complement). So 255=-1
voidstar
Posts: 359
Joined: Thu Apr 15, 2021 8:05 am

Re: How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by voidstar »

Make sense! So, in line 170 of the original BASIC example, when doing A=PEEK(address storing copy of X register), I'm not sure how to get BASIC to treat that as signed.

Hopefully there is some simple way, otherwise, add a line 175 to do line:
175 IF (A>127) THEN A=(A-256)
Which would be slow, so the "built in" MWHEEL is probably the way to go.

In general, the negative values for "up" is a good convention (if majority of screen coordinate conventions is 0 or 1 at the top).


BTW does "MWHEEL" actually associate with a variable "MW" (two letters)? Or does it not stomp on a variable that might be called "MW"? Seems like it does not.
Stefan
Posts: 434
Joined: Thu Aug 20, 2020 8:59 am

Re: How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by Stefan »

It doesn’t stomp MW, which still can be used in BASIC programs.

This is thanks to MooingLemur, as I first called it MW.
mortarm
Posts: 232
Joined: Tue May 16, 2023 6:21 pm

Re: How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by mortarm »

I just tried it with the online emulator and the wheel did nothing.
Stefan
Posts: 434
Joined: Thu Aug 20, 2020 8:59 am

Re: How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by Stefan »

Mouse wheel support is not yet in any official release. Hopefully it will make the cut for R45.

In the emulator, mouse wheel is still just a pull request. It should work if you clone that code and build it from source.
voidstar
Posts: 359
Joined: Thu Apr 15, 2021 8:05 am

Re: How to use the Mouse Wheel on X16 (BASIC and ASM)

Post by voidstar »

mortarm wrote: Thu Sep 21, 2023 3:35 pm I just tried it with the online emulator and the wheel did nothing.
It needs a SMC and System ROM update. SMC is the core parts to talk to the hardware, and the SystemROM update is the BASIC keyword (and kernel) updates to talk to the SMC.

This was a demonstration that the capability seems stable and no apparent negative impacts. So hopefully these become standard in the next build of the emulator and the next batch of the DevBoards (and the 100 existing boards, the SYSTEM PRG software updates are also confirmed to work to update these ROMs). The SystemROM is prebuilt (nightly builds).

Stay tuned!
Post Reply