SF2:scan mouse

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search

This code is part of FutureOS. Please give credit if you use it for your own applications. Questions can be posed to TFM who wrote this code.


06920                     ;PS/2-Mausabfrage(+) This is part of the FutureOS ROM D
06921                     
06922                     ;Subroutine
06923                     
06924  FB5C  22 00 60      MRNM    LD    (KS0XL),HL
06925                     
06926                     ;Call OS function here! by TFM of FutureSoft, please credit.
06927                     
06928  FB5F  01 10 FD      R_PS2   LD    BC,&FD10
06928  FB62  ED 78                 IN    A,(C)
06928  FB64  3C                    INC   A
06928  FB65  C8                    RET   Z
06928  FB66  3D                    DEC   A
06929                     
06930  FB67  57                    LD    D,A
06930  FB68  07                    RLCA  
06930  FB69  38 29                 JR    C,MVMB       ;Vertikal/Button
06931                     
06932  FB6B  07                    RLCA  
06932  FB6C  D0                    RET   NC           ;Mouse not moved
06933                     
06934  FB6D  07                    RLCA  
06934  FB6E  7A                    LD    A,D
06934  FB6F  38 13                 JR    C,MLMM       ;left
06935                     
06936  FB71  E6 1F                 AND   A,&1F        ;Mouse right, A = %000 00001 to %000 11111
06937                     
06938  FB73  16 00                 LD    D,&00
06938  FB75  5F                    LD    E,A
06939  FB76  2A 00 60              LD    HL,(KS0XL)
06939  FB79  19                    ADD   HL,DE
06940  FB7A  7C                    LD    A,H
06940  FB7B  FE 02                 CP    A,&02
06940  FB7D  20 DD                 JR    NZ,MRNM
06941  FB7F  21 FF 01              LD    HL,&01FF
06941  FB82  20 D8                 JR    NZ,MRNM
06942                     
06943                     ;Mouse left
06944                     
06945  FB84  F6 E0         MLMM    OR    A,&E0        ;A = %111 11111 (-1) to %111 00000
06946                     
06947  FB86  16 FF                 LD    D,&FF
06947  FB88  5F                    LD    E,A
06948  FB89  2A 00 60              LD    HL,(KS0XL)
06948  FB8C  19                    ADD   HL,DE
06948  FB8D  38 CD                 JR    C,MRNM
06949  FB8F  21 00 00              LD    HL,&0000
06949  FB92  38 C8                 JR    C,MRNM
06950                     
06951                     ;auf/ab od. Ohr
06952                     
06953  FB94  07            MVMB    RLCA  
06953  FB95  38 21                 JR    C,MBMW       ;Button/Wheel
06954                     
06955  FB97  07                    RLCA  
06955  FB98  7A                    LD    A,D
06955  FB99  30 0F                 JR    NC,MAMM
06956                     
06957  FB9B  F6 E0                 OR    A,&E0        ;Maus runter, A=11111111(-1) - 11100000
06958  FB9D  ED 44                 NEG   
06959  FB9F  21 02 60              LD    HL,KS0YL
06960  FBA2  86                    ADD   A,(HL)
06960  FBA3  30 02                 JR    NC,MUMO
06961  FBA5  3E FF                 LD    A,&FF
06962                     
06963  FBA7  77            MUMO    LD    (HL),A
06963  FBA8  18 B5                 JR    R_PS2
06964                     
06965                     ;Maus rauf
06966                     
06967  FBAA  E6 1F         MAMM    AND   A,&1F        ;A = 00000001 - 00011111
06968                     
06969  FBAC  ED 44                 NEG   
06970  FBAE  21 02 60              LD    HL,KS0YL
06971  FBB1  86                    ADD   A,(HL)
06971  FBB2  38 01                 JR    C,MAMO
06972  FBB4  AF                    XOR   A,A
06973                     
06974  FBB5  77            MAMO    LD    (HL),A
06974  FBB6  18 A7                 JR    R_PS2
06975                     
06976                     ;Maus-Ohren, -Rad
06977                     
06978  FBB8  07            MBMW    RLCA  
06978  FBB9  38 0B                 JR    C,MWSO
06979                     
06980  FBBB  07                    RLCA               ; CALL C,backward
06981  FBBC  07                    RLCA               ; CALL C,forward
06982  FBBD  07                    RLCA               ; CALL C,MIDDLE_Fire2
06983  FBBE  07                    RLCA  
06983  FBBF  38 11                 JR    C,F1_TUR_E   ;Fire 1 (right button)
06984  FBC1  07                    RLCA  
06984  FBC2  38 12                 JR    C,F0_KCF0    ;Fire 0 (left button)
06985  FBC4  18 99                 JR    R_PS2
06986                     
06987                     ;Mouse wheel was turned
06988                     
06989  FBC6  07            MWSO    RLCA  
06989  FBC7  7A                    LD    A,D
06989  FBC8  38 04                 JR    C,MWMM       ;Wheel turned in negative direction (back)
06990                     
06991  FBCA  E6 1F                 AND   A,&1F        ;A[Bits 3-0] = scroll wheel offset positive!
06992                     
06993                     ;0000 0001 = 1
06994                     ;0000 0010 = 2
06995                     ;0000 0011 = 3
06996                     ;0000 0100 = 4
06997                     
06998  FBCC  18 91                 JR    R_PS2
06999                     
07000                     ;Mouse turned wheel backward
07001                     
07002  FBCE  F6 F0         MWMM    OR    A,&F0        ;A[Bits 3-0] = scroll wheel offset (negative signed, 2s Complement)
07003                     
07004                     ;1111 1111 = -1
07005                     ;1111 1110 = -2
07006                     ;1111 1101 = -3
07007                     ;1111 1100 = -4
07008                     
07009  FBD0  18 8D                 JR    R_PS2
07010                     
07011                     ;Adjust Stack!
07012                     
07013  FBD2  E1            F1_TUR_E
                                   POP   HL
07013  FBD3  C3 6B F7              JP    TUR_E ;or where ever you want to go!

07014  FBD6  E1            F0_KCF0 POP   HL
07014  FBD7  C3 75 FA              JP    KCF0 ;or where ever you want to go!
07015                     

See also