mouse control in asm

By ARTRAG

Enlighted (6538)

ARTRAG's picture

22-10-2009, 22:33

does anyone have a small snippet to read and control a mouse cursor in assembler?
thanks in advance

Login or register to post comments

By SaebaMSX

Hero (533)

SaebaMSX's picture

23-10-2009, 01:50

MSX1 or MSX2?

By Edwin

Paragon (1182)

Edwin's picture

23-10-2009, 02:14

Check here. Comments are in Dutch, but I think it'll be clear enough.

By ro

Scribe (4473)

ro's picture

23-10-2009, 16:14

Yes, I have stuff for controlling the mouse. I'll look into it hopefully this evening/weekend and get back on it. if ye still need it, that is.

By ARTRAG

Enlighted (6538)

ARTRAG's picture

23-10-2009, 18:04

Do msx1 and msx2 differ in mouse control?
I'd like to find a general method that uses direct i/o.
No bios please, subrom calls are terrible Tongue

Edwin I'll study your code, in case i'll ask some Dutch friends to translate.
Thanks

By Edwin

Paragon (1182)

Edwin's picture

24-10-2009, 01:16

Here is the code with translated comments:

A routine  to read the mouse:


        LD    D,&B10010011     ; Use these values for a mouse in port 1
        LD    E,&B00010000 
 

        LD    D,&B11101100     ; Use these values for a mouse in port 2
        LD    E,&B00100000

; Read the mouse.   Input: D/E=.... Output: H=X-offset, L=Y-offset
; Note that the routine will output H=L=255 if no mouse is present!
GTMOUS: 

        LD    B,WAIT2          ; Long delay for first read
        CALL  GTOFS2          ; Read bit 7-4 of the x-offset
        AND   0FH
        RLCA
        RLCA
        RLCA
        RLCA
        LD    C,A
        CALL  GTOFST          ; Read bit 3-0 of the x-offset
        AND   0FH
        OR    C
        LD    H,A             ; Store combined x-offset
        CALL  GTOFST          ; Read bit 7-4 of the y-offset
        AND   0FH
        RLCA
        RLCA
        RLCA
        RLCA
        LD    C,A
        CALL  GTOFST          ; Read bit 3-0 of the y-offset
        AND   0FH
        OR    C
        LD    L,A             ; Store combined y-offset
        RET

WAIT1: EQU   10              ; Short delay value
WAIT2: EQU   30              ; Long delay value

GTOFST: LD    B,WACHT1
GTOFS2: LD    A,15            ; Read psg register 15 voor mouse
        OUT   (0A0H),A
        LD    A,D
        OUT   (0A1H),A
        XOR   E
        LD    D,A

WAIT:  DJNZ  WAIT           ; Extra delay because the mouse is slow.

        LD    A,14
        OUT   (0A0H),A
        IN    A,(0A2H)
        RET

This code is valid for all MSX types. As long as you use an MSX mouse of course. Wink

By Sander

Founder (1865)

Sander's picture

24-10-2009, 02:39

GTOFST: LD B,WACHT1 ; should be
GTOFST: LD B,WAIT1 ; I think

By ARTRAG

Enlighted (6538)

ARTRAG's picture

24-10-2009, 06:28

yes! thanks! it worked also with labels and comments in Duck Wink

By Manuel

Ascended (18133)

Manuel's picture

24-10-2009, 11:03

quack quack!

By ARTRAG

Enlighted (6538)

ARTRAG's picture

24-10-2009, 11:16

hoops, unwanted typo

By Manuel

Ascended (18133)

Manuel's picture

24-10-2009, 13:47

funny one though! Smile