-
Notifications
You must be signed in to change notification settings - Fork 4
/
ctmouse.asm
5066 lines (4555 loc) · 117 KB
/
ctmouse.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Cute Mouse Driver - a tiny mouse driver
;
; Copyright (c) 1997-2002 Nagy Daniel <nagyd@users.sourceforge.net>
;
; BIOS wheel mouse support: Ported from Konstantin Koll's public
; domain code into Cute Mouse by Eric Auer 2007 (places marked -X-)
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA
; -X- no longer: 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;
; NOTE: memcopy and MOVSEG_ have "assume..." as side effects!
; %pagesize 255
; %noincl
;%macs
; %nosyms
;%depth 0
; %linum 0
;%pcnt 0
;%bin 0
; warn
; locals
CTMVER equ <"2.1"> ; major driver version
CTMRELEASE equ <"2.1 beta4"> ; full driver version with suffixes
driverversion equ 705h ; imitated Microsoft driver version
; at least 705h because our int 33 function _26 operates in 7.05+ style
FASTER_CODE = 0 ; optimize by speed instead size
OVERFLOW_PROTECT = 0 ; prevent variables overflow
FOOLPROOF = 1 ; check driver arguments validness
USE28 = 0 ; include code for INT 33/0028 function
USERIL = 0 ; include code for INT 10/Fn EGA functions
; %define PS2DEBUG 1 ; print debug messages for PS2serv calls
.286
;.386
;------------------------------------------------------------------------
include asmlib/asm.mac
; *** include asmlib/hll.mac ; if_ loop_ countloop_ etc - TASM specific
include asmlib/code.def
include asmlib/code.mac
include asmlib/macro.mac
include asmlib/BIOS/area0.def ; ** int11 flags and various 40:xx gfx info
; HW_PS2 equ 4 ; bit set in int 11h returned AX if PS/2 mouse present
; VIDEO_control VIDEO_switches VIDEO_width VIDEO_pageoff VIDEO_mode
; VIDEO_switches VIDSW_feature0 VIDSW_display VIDEO_ptrtable@
; VPARAM_SEQC VIDEO_paramtbl@ VIDEO_lastrow VIDEO_pageno
include asmlib/convert/digit.mac ; ** only count2x uses digits in ASCII
include asmlib/convert/count2x.mac ; ** only used as _word_hex for I/O port
include asmlib/DOS/MCB.def ; ** small, used to set ownerid and name
include asmlib/DOS/PSP.def ; ** only DOS_exit env_seg cmdline_len PSP_TSR used
; include asmlib/DOS/file.mac ; was only used once - DOSCloseFile
include asmlib/DOS/mem.mac
; include asmlib/hard/PIC8259A.def ; only PIC1_OCW2, PIC1_IMR const used:
PIC1_OCW2 equ 20h
PIC1_IMR equ 21h
include asmlib/hard/UART.def
USE_286 equ <(@CPU and 4)>
USE_386 equ <(@CPU and 8)>
_ARG_DI_ equ <word ptr [bp]>
_ARG_SI_ equ <word ptr [bp+2]>
_ARG_BP_ equ <word ptr [bp+4]>
if USE_286
_ARG_BX_ equ <word ptr [bp+8]>
_ARG_DX_ equ <word ptr [bp+10]>
_ARG_CX_ equ <word ptr [bp+12]>
_ARG_AX_ equ <word ptr [bp+14]>
_ARG_ES_ equ <word ptr [bp+16]>
_ARG_DS_ equ <word ptr [bp+18]>
; arg offset: far pointer plus 8+2 words (push 2 segs, pusha)
_ARG_OFFS_ = 24
PUSHALL equ <pusha>
POPALL equ <popa>
else ; USE_286
_ARG_BX_ equ <word ptr [bp+6]>
_ARG_DX_ equ <word ptr [bp+8]>
_ARG_CX_ equ <word ptr [bp+10]>
_ARG_AX_ equ <word ptr [bp+12]>
_ARG_ES_ equ <word ptr [bp+14]>
_ARG_DS_ equ <word ptr [bp+16]>
_ARG_OFFS_ = 22
PUSHALL macro
push ax
push cx
push dx
push bx
push bp
push si
push di
endm
POPALL macro
pop di
pop si
pop bp
pop bx
pop dx
pop cx
pop ax
endm
endif ; USE_286
nl equ <13,10>
eos equ <0>
POINT struc
X dw 0
Y dw 0
POINT ends
PS2serv macro serv:req,errlabel ; :vararg
mov ax,serv
%ifdef PS2DEBUG
push ax
mov al,'<'
int 29h
pop ax
push ax
and al,15 ; assume ax is c20n, only show low nibble
add al,30h ; convert to digit
int 29h
mov al,'/'
int 29h
mov al,bh ; low nibble of bh is interesting, too
add al,30h ; (func 7: es bx is pointer)
int 29h
pop ax
%endif ; ifdef PS2DEBUG
int 15h
%ifdef PS2DEBUG
pushf
push ax
mov al,20h ; space
adc al,0 ; if carry, exclamation mark
int 29h
pop ax
push ax
mov al,ah
add al,30h ; usually ah is only 0..9 status
int 29h
mov al,'/'
int 29h
mov al,bh ; func 1, 4: device id (1: bl is aa if okay)
add al,30h ; can be ff+30 or aa+30 now :-p
int 29h
mov al,'>'
int 29h
pop ax
popf
%endif ; ifdef PS2DEBUG
ifnb <errlabel>
jc errlabel
test ah,ah
jnz errlabel
endif
endm
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ SEGMENTS DEFINITION ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
; .model use16 tiny
assume ss:nothing
@TSRcode equ <DGROUP>
@TSRdata equ <DGROUP>
; TSR ends at TSRend, roughly line 3000 of the 4000 lines of ctmouse
TSRcref equ <offset @TSRcode> ; offset relative TSR code group
TSRdref equ <offset @TSRdata> ; - " - data
coderef equ <offset @code> ; offset relative main code group
dataref equ <offset @data> ; - " - data
.code
org 0
TSRstart label byte
org 100h ; .COM style program
start: jmp real_start
TSRavail label byte ; initialized data may come from here
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ UNINITIALIZED DATA ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
;!!! WARNING: don't init variables in uninitialized section because
; they will not be present in the executable image
org PSP_TSR-3*16 ; reuse part of PSP
spritebuf db 3*16 dup (?) ; copy of screen sprite in modes 4-6
;----- application state -----
;!!! WARNING: variables order between RedefArea and szDefArea must be
; syncronized with variables order after DefArea
even
SaveArea = $
RedefArea = $
mickey8 POINT ? ; mickeys per 8 pixel ratios
;;*doublespeed dw ? ; double-speed threshold (mickeys/sec)
senscoeff POINT ? ; mickeys sensitivity, ~[1/3..3.0]*256
sensval POINT ? ; original 001A sensitivity values-1
startscan dw ? ; screen mask/cursor start scanline
endscan dw ? ; cursor mask/cursor end scanline
;----- hotspot, screenmask and cursormask must follow as is -----
hotspot POINT ? ; cursor bitmap hot spot
screenmask db 2*16 dup (?) ; user defined screen mask
cursormask db 2*16 dup (?) ; user defined cursor mask
nocursorcnt db ? ; 0=cursor enabled, else hide counter
;;*nolightpen? db ? ; 0=emulate light pen
even
szDefArea = $ - RedefArea ; initialized by softreset_21
rangemax POINT ? ; horizontal/vertical range max
upleft POINT ? ; upper left of update region
lowright POINT ? ; lower right of update region
pos POINT ? ; virtual cursor position
granpos POINT ? ; granulated virtual cursor position
UIR@ dd ? ; user interrupt routine address
even
ClearArea = $
sensround POINT ? ; rounding error in applying
; sensitivity for mickeys
rounderr POINT ? ; same in conversion mickeys to pixels
even
szClearArea1 = $ - ClearArea ; cleared by setpos_04
rangemin POINT ? ; horizontal/vertical range min
even
szClearArea2 = $ - ClearArea ; cleared by setupvideo
cursortype db ? ; 0 - software, else hardware
callmask db ? ; user interrupt routine call mask
mickeys POINT ? ; mouse move since last access
BUTTLASTSTATE struc
counter dw ?
lastrow dw ?
lastcol dw ?
BUTTLASTSTATE ends
buttpress BUTTLASTSTATE ?,?,?
buttrelease BUTTLASTSTATE ?,?,?
wheel BUTTLASTSTATE ? ; wheel counter since last access
wheelUIR db ? ; wheel counter for UIR
even
szClearArea3 = $ - ClearArea ; cleared by softreset_21
szSaveArea = $ - SaveArea
if USERIL ; -X-
;----- registers values for RIL -----
;!!! WARNING: registers order and RGROUPDEF contents must be fixed
even
VRegsArea = $
regs_SEQC db 5 dup (?)
reg_MISC db ?
regs_CRTC db 25 dup (?)
regs_ATC db 21 dup (?)
regs_GRC db 9 dup (?)
reg_FC db ?
reg_GPOS1 db ?
reg_GPOS2 db ?
DefVRegsArea = $
def_SEQC db 5 dup (?)
def_MISC db ?
def_CRTC db 25 dup (?)
def_ATC db 21 dup (?)
def_GRC db 9 dup (?)
def_FC db ?
def_GPOS1 db ?
def_GPOS2 db ?
szVRegsArea = $ - DefVRegsArea
; ERRIF (szVRegsArea ne 64 or $-VRegsArea ne 2*64) "VRegs area contents corrupted!"
else
crtc dw ? ; 3d4 or 3b4
endif ; -X- USERIL
;----- old interrupt vectors -----
oldint33 dd ? ; old INT 33 handler address
oldIRQaddr dd ? ; old IRQ handler address
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ INITIALIZED DATA ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
even
TSRdata label byte
; ERRIF (TSRdata lt TSRavail) "TSR uninitialized data area too small!"
DefArea = $
POINT <8,16> ; mickey8
POINT <1*256,1*256> ; senscoeff
POINT <49,49> ; sensval
;;* dw 64 ; doublespeed
dw 77FFh,7700h ; startscan, endscan
POINT <0,0> ; hotspot
dw 0011111111111111b ; screenmask
dw 0001111111111111b
dw 0000111111111111b
dw 0000011111111111b
dw 0000001111111111b
dw 0000000111111111b
dw 0000000011111111b
dw 0000000001111111b
dw 0000000000111111b
dw 0000000000011111b
dw 0000000111111111b
dw 0000000011111111b
dw 0011000011111111b
dw 1111100001111111b
dw 1111100001111111b
dw 1111110011111111b
dw 0000000000000000b ; cursormask
dw 0100000000000000b
dw 0110000000000000b
dw 0111000000000000b
dw 0111100000000000b
dw 0111110000000000b
dw 0111111000000000b
dw 0111111100000000b
dw 0111111110000000b
dw 0111110000000000b
dw 0110110000000000b
dw 0100011000000000b
dw 0000011000000000b
dw 0000001100000000b
dw 0000001100000000b
dw 0000000000000000b
db 1 ; nocursorcnt
;;* db 0 ; nolightpen?
db 0 ; JWASM would use 0fch, "CLD" as pad byte??
even
; ERRIF ($-DefArea ne szDefArea) "Defaults area contents corrupted!"
;----- driver and video state begins here -----
even
granumask POINT <-1,-1>
textbuf label word
buffer@ dd ? ; pointer to screen sprite copy
cursor@ dw -1,0 ; cursor sprite offset in videoseg;
; -1=cursor not drawn
videoseg equ <cursor@[2]> ; 0=not supported video mode
UIRunlock db 1 ; 0=user intr routine is in progress
videolock db 1 ; drawing: 1=ready,0=busy,-1=busy+queue
newcursor db 0 ; 1=force cursor redraw
;----- table of pointers to registers values for RIL -----
REGSET struc
rgroup dw ?
regnum db ?
regval db ?
REGSET ends
db 0 ; JWASM would use 0fch, "CLD" as pad byte??
even
dw (vdata1end-vdata1)/(size REGSET)
vdata1 REGSET <10h,1>,<10h,3>,<10h,4>,<10h,5>,<10h,8>,<08h,2>
vdata1end label word
dw (vdata2end-vdata2)/(size REGSET)
vdata2 REGSET <10h,1,0>,<10h,4,0>,<10h,5,1>,<10h,8,0FFh>,<08h,2,0Fh>
vdata2end label byte
RGROUPDEF struc
port@ dw ?
regs@ dw ?
def@ dw ?
regscnt db 1
rmodify? db 0
RGROUPDEF ends
if USERIL ; -X-
even
videoregs@ label RGROUPDEF
RGROUPDEF <3D4h,regs_CRTC,def_CRTC,25> ; CRTC
RGROUPDEF <3C4h,regs_SEQC,def_SEQC,5> ; Sequencer
RGROUPDEF <3CEh,regs_GRC, def_GRC, 9> ; Graphics controller
RGROUPDEF <3C0h,regs_ATC, def_ATC, 20> ; VGA attrib controller
RGROUPDEF <3C2h,reg_MISC, def_MISC> ; VGA misc output and input
RGROUPDEF <3DAh,reg_FC, def_FC> ; Feature Control
RGROUPDEF <3CCh,reg_GPOS1,def_GPOS1> ; Graphics 1 Position
RGROUPDEF <3CAh,reg_GPOS2,def_GPOS2> ; Graphics 2 Position
endif ; -X- USERIL
;ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ IRQ HANDLERS ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
IRQhandler proc
assume ds:nothing,es:nothing
cld
push ds
push es
PUSHALL
MOVSEG ds,cs,,@TSRdata
; CODE_ MOV_CX IOdone,<db ?,0> ; processed bytes counter
OPCODE_MOV_CX
IOdone db ?,0
; -X- IRQproc label byte ; "mov al,OCW2<OCW2_EOI>"
; -X- j PS2proc ; if serial mode
; -X- out PIC1_OCW2,al ; {20h} end of interrupt
; out_ PIC1_OCW2,%OCW2<OCW2_EOI>
mov al,20h
out PIC1_OCW2,al
; CODE_ MOV_DX IO_address,<dw ?> ; UART IO address
OPCODE_MOV_DX
IO_address dw ?
push dx
movidx dx,LSR_index
in al,dx ; {3FDh} LSR: get status
xchg bx,ax ; OPTIMIZE: instead MOV BL,AL
pop dx
movidx dx,RBR_index
in al,dx ; {3F8h} flush receive buffer
test bl,mask LSR_break+mask LSR_FE+mask LSR_OE
; if_ nz ; if break/framing/overrun
jz @@irqhandlerz
xor cx,cx ; errors then restart
mov [IOdone],cl ; sequence: clear counter
; end_
@@irqhandlerz:
shr bl,LSR_RBF+1
; if_ carry ; process data if data ready
jnc @@irqhandlernc
call_ mouseproc,MSMproc ; never PS/2
; end_
@@irqhandlernc:
jmp rethandler
IRQhandler endp
assume ds:@TSRdata
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; Enable PS/2
;ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
;
; In: none
; Out: none
; Use: none
; Modf: AX, BX, DX, ES
; Call: INT 15/C2xx, -X- setRateTSR
; -X- @disablePS2, INT 21/25 --> no longer (re)hooks IRQ
;
enablePS2 proc
; -X- call @disablePS2 ; unhooked IRQ
MOVSEG es,cs,,@TSRcode
mov bx,TSRcref:PS2handler ; -X- real handler now
PS2serv 0C207h ; set mouse handler in ES:BX
mov bh,1
PS2serv 0C200h ; set mouse on (bh=1)
; -X- DOSSetIntr 68h+12,,,@TSRcode:IRQhandler
mov bh,5 ; -X- 100, KoKo uses 3 (60)
call setRateTSR ; -X-
ret
; -X- PS2dummy: retf
enablePS2 endp
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; Disable PS/2
;ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
;
; In: none
; Out: none
; Use: oldIRQaddr
; Modf: AX, BX, DX, ES
; Call: INT 15/C2xx, -X- setRateTSR
; -X- INT 21/25 --> no longer unhooks IRQ (irq 12, int 74)
;
disablePS2 proc
@disablePS2: xor bx,bx
PS2serv 0C200h ; set mouse off (bh=0)
MOVSEG es,bx,,nothing
PS2serv 0C207h ; clear mouse handler (ES:BX=0)
mov bh,5 ; -X- KoKo uses 15/C201 here
call setRateTSR ; -X-
ret
disablePS2 endp
assume ds:@TSRdata ; added...?
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; -X- A "light" version for the TSR... In: BH=0..6 for 20,40,60,80,100,200
; Set mouse sampling rate to "RATES[BH]" samples per second
setRateTSR proc
PS2serv 0C202h ; set rate, ignore errors
ret
setRateTSR endp
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; -X- this handler is called by the BIOS, it is no IRQ handler :-)
PS2handler proc
assume ds:nothing,es:nothing
push ds
push es
PUSHALL
MOVSEG ds,cs,,@TSRdata
mov bp,sp
PS2WHEELCODE label byte ; jump to wheel or plain: test 0/-1
; test sp,0 ; 2 byte opcode, sp always NZ here
; jnz PS2WHEEL
j @@PS2PLAIN
; stack for non-wheel mice: ... - - Y - X - BTN -
; stack for wheel mice: ... - - W - Y - BTN X
; flags: (yext) (xext) ysign xsign 1 btn3 btn1 btn2
; ("ext" flag could be used to trigger "xor value,100h")
@@PS2PLAIN: ; old cutemouse 1.9 PS/2 handler, non-wheel
; note: ctmouse 1.9 code uses only sign, not ext
mov al,[bp+_ARG_OFFS_+6] ; buttons and flags
if USE_286
mov bl,al ; backup, xchg will restore
shl al,3 ; CF=Y sign bit, MSB=X sign
else
mov cl,3
mov bl,al ; backup, xchg will restore
shl al,cl ; CF=Y sign bit, MSB=X sign
endif
; sbb ch,ch ; extend Y sign bit
db 1ah, 0edh ; JWASM and TASM use opposite encoding
cbw ; extend X sign bit
mov al,[bp+_ARG_OFFS_+4] ; AX=X movement
xchg bx,ax ; X to BX, buttons to AL
mov cl,[bp+_ARG_OFFS_+2] ; CX=Y movement
; wheelmask is 0 now, so no wheel data is expected in AH
j @@PS2DONE
; stack for non-wheel mice: ... - - Y - X - BTN -
; stack for wheel mice: ... - - W - Y - BTN X
; flags: (yext) (xext) ysign xsign 1 btn3 btn1 btn2
; "ext" flag can be used to trigger "xor value,100h"
PS2WHEEL:: ; handler based on public domain code from Konstantin Koll
; old KoKo code used only ext, not sign, ok on all but Alps
mov al,[bp+_ARG_OFFS_+6] ; buttons and flags
if USE_286
mov bl,al ; backup, xchg will restore
shl al,3 ; CF=Y sign bit, MSB=X sign
else
mov cl,3
mov bl,al ; backup, xchg will restore
shl al,cl ; CF=Y sign bit, MSB=X sign
endif
; sbb ch,ch ; extend Y sign bit
db 1ah, 0edh ; JWASM and TASM use opposite encoding
cbw ; extend X sign bit
mov al,[bp+_ARG_OFFS_+7] ; AX=X movement <--
xchg bx,ax ; X to BX, buttons to AL
mov cl,[bp+_ARG_OFFS_+4] ; CX=Y movement <--
mov ah,[bp+_ARG_OFFS_+2] ; AH=Wheel data <--
; reverseY does not seem to support 9th bit, must skip that
@@PS2DONE: call reverseY ; AL flags AH wheel BX X CX Y
POPALL
pop es
pop ds
retf
PS2handler endp
assume ds:@TSRdata ; added...?
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; Enable serial interrupt in PIC
;ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
;
; In: none
; Out: none
; Use: IO_address
; Modf: AX, DX, SI, IOdone, MSLTbuttons
; Call: INT 21/25
;
enableUART proc
;----- set new IRQ handler
mov dx,TSRcref:IRQhandler ; -X- IRQintnum 0 means none
; CODE_ MOV_AX IRQintnum,<db 0,25h> ; INT number of selected IRQ
OPCODE_MOV_AX
IRQintnum db 0,25h
int 21h ; set INT in DS:DX
;----- set communication parameters
mov si,[IO_address]
movidx dx,LCR_index,si
; out_ dx,%LCR{LCR_DLAB=1} ; {3FBh} LCR: DLAB on
; mov al,%LCR{LCR_DLAB=1} ; {3FBh} LCR: DLAB on
mov al,80h
out dx,al
; xchg dx,si ; 1200 baud rate
xchg si,dx ; JWASM and TASM use opposite encoding
mov ax,96
; outw dx,96 ; {3F8h},{3F9h} divisor latch
out dx,ax
; xchg dx,si
xchg si,dx ; JWASM and TASM use opposite encoding
; CODE_ MOV_AX
OPCODE_MOV_AX
LCRset db 00000010b ; LCR <0,,LCR_noparity,0,2> ; {3FBh} LCR: DLAB off, 7/8N1
db 00001111b ; MCR <,,,1,1,1,1> ; {3FCh} MCR: DTR/RTS/OUTx on
out dx,ax
;----- prepare UART for interrupts
movidx dx,RBR_index,si,LCR_index
in al,dx ; {3F8h} flush receive buffer
movidx dx,IER_index,si,RBR_index
; out_ dx,%IER{IER_DR=1},%FCR<>; {3F9h} IER: enable DR intr
; {3FAh} FCR: disable FIFO
; mov al,%IER{IER_DR=1}
; mov ah,%FCR<>
mov ax,1
out dx,ax
dec ax ; OPTIMIZE: instead MOV AL,0
mov [IOdone],al
mov [MSLTbuttons],al
;-----
in al,PIC1_IMR ; {21h} get IMR
; CODE_ AND_AL notPIC1state,<db ?> ; clear bit to enable interrupt
OPCODE_AND_AL
notPIC1state db ?
out PIC1_IMR,al ; {21h} enable serial interrupts
ret
enableUART endp
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; Disable serial interrupt of PIC
;ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
;
; In: none
; Out: none
; Use: IO_address, oldIRQaddr
; Modf: AX, DX
; Call: INT 21/25
;
disableUART proc
in al,PIC1_IMR ; {21h} get IMR
; CODE_ OR_AL PIC1state,<db ?> ; set bit to disable interrupt
OPCODE_OR_AL
PIC1state db ?
out PIC1_IMR,al ; {21h} disable serial interrupts
;-----
;!!! MS/Logitech ID bytes (4Dh)+PnP data looks as valid mouse packet, which
; moves mouse; to prevent unnecessary send of PnP data after disabling
; driver with following enabling, below DTR and RTS remained active
movidx dx,LCR_index,[IO_address] ; {3FBh} LCR: DLAB off
; out_ dx,%LCR<>,%MCR<,,,0,,1,1> ; {3FCh} MCR: DTR/RTS on, OUT2 off
; mov al,%LCR<>
; mov ah,%MCR<,,,0,,1,1>
mov ax,300h
out dx,ax
movidx dx,IER_index,,LCR_index
;mov al,IER<>
out dx,al ; {3F9h} IER: interrupts off
;----- restore old IRQ handler
push ds
mov ax,word ptr [IRQintnum] ; AH=25h
lds dx,[oldIRQaddr]
assume ds:nothing
int 21h ; set INT in DS:DX
pop ds
ret
disableUART endp
assume ds:@TSRdata
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; Process the Microsoft/Logitech packet bytes
;ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
MSLTproc proc
; CODE_ MOV_DL MSLTbuttons,<db ?> ; buttons state for MS3/LT/WM
OPCODE_MOV_DL
MSLTbuttons db ?
test al,01000000b ; =40h ; synchro check
; if_ nz ; if first byte
jz @@msltz
mov [IOdone],1 ; request next 2/3 bytes
mov [MSLT_1],al
MSLTCODE1 label byte ; "ret" if not LT/WM
xchg ax,cx ; OPTIMIZE: instead MOV AL,CL
sub al,3 ; if first byte after 3 bytes
jz @@LTWMbutton3 ; then release middle button
ret
; end_
@@msltz:
; if_ ncxz ; skip nonfirst byte at start
jcxz @@msltcxz
inc [IOdone] ; request next byte
loop @@MSLT_3
mov [MSLT_X],al ; keep X movement LO
; end_
@@msltcxz:
@@LTret: ret
@@MSLT_3: loop @@LTWM_4
;mov cl,0
; CODE_ MOV_BX MSLT_1,<db ?,0> ; mouse packet first byte
OPCODE_MOV_BX
MSLT_1 db ?,0
ror bx,2
; xchg cl,bh ; bits 1-0: X movement HI
xchg bh,cl ; TASM and JWASM use opposite encoding
ror bx,2 ; bits 5-4: LR buttons
or al,bh ; bits 3-2: Y movement HI
cbw
xchg cx,ax ; CX=Y movement
; CODE_ OR_AL MSLT_X,<db ?>
OPCODE_OR_AL
MSLT_X db ?
cbw
xchg bx,ax ; BX=X movement
;cbw ; clear wheel value
xor al,dl
and al,00000011b ; =3 ; LR buttons change mask
mov dh,al
or dh,bl ; nonzero if LR buttons state
or dh,cl ; changed or mouse moved
MSLTCODE2 label byte
j @@MSLTupdate ; "jnz" if MS3
or al,00000100b ; =4 ; empty event toggles button
j @@MSLTupdate
@@LTWM_4: ;mov ch,0
mov [IOdone],ch ; request next packet
MSLTCODE3 label byte ; if LT "mov cl,3" else
@@LTWMbutton3: mov cl,3 ; if WM "mov cl,2" else "ret"
mov ah,al
shr al,cl
xor al,dl
and ax,111100000100b ; =0F04h
if FASTER_CODE
jz @@LTret ; exit if button 3 not changed
endif
xor bx,bx
xor cx,cx
@@MSLTupdate: xor al,dl ; new buttons state
mov [MSLTbuttons],al
j swapbuttons
MSLTproc endp
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; Process the Mouse Systems packet bytes
;ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
MSMproc proc
jcxz @@MSM_1
cbw
dec cx
jz @@MSM_2
dec cx
jz @@MSM_3
loop @@MSM_5
@@MSM_4: add ax,[MSM_X]
@@MSM_2: mov [MSM_X],ax
j @@MSMnext
@@MSM_1: xor al,10000111b ; =87h ; sync check: AL should
test al,11111000b ; =0F8h ; be equal to 10000lmr
; if_ zero
jnz @@msmnz
test al,00000110b ; =6 ; check the L and M buttons
; if_ odd ; if buttons not same
jpe @@msmeven
xor al,00000110b ; =6 ; swap them
; end_
@@msmeven:
mov [MSM_buttons],al ; bits 2-0: MLR buttons
;j @@MSMnext
@@MSM_3: mov [MSM_Y],ax
@@MSMnext: inc [IOdone] ; request next byte
; end_
@@msmnz:
ret
@@MSM_5: ;mov ch,0
mov [IOdone],ch ; request next packet
; CODE_ ADD_AX MSM_Y,<dw ?>
OPCODE_ADD_AX
MSM_Y dw ?
; CODE_ MOV_BX MSM_X,<dw ?>
OPCODE_MOV_BX
MSM_X dw ?
xchg cx,ax ; OPTIMIZE: instead MOV CX,AX
; CODE_ MOV_AL MSM_buttons,<db ?>
OPCODE_MOV_AL
MSM_buttons db ?
;j reverseY ; reverseY is next line anyway
MSMproc endp
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; Update mouse status
;ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
;
; In: AL (new buttons state, 2 or 3 LSB used)
; AH (wheel movemement)
; BX (X mouse movement)
; CX (Y mouse movement)
; Out: none
; Use: callmask, granpos, mickeys, UIR@
; Modf: AX, CX, DX, BX, SI, DI, wheel, wheelUIR, UIRunlock
; Call: updateposition, updatebutton, refreshcursor
;
reverseY proc
neg cx ; reverse Y movement
;j swapbuttons
reverseY endp
swapbuttons proc
test al,00000011b ; =3 ; check the L and R buttons
; if_ odd ; if buttons not same
jpe @@swapeven
; CODE_ XOR_AL swapmask,<db 00000011b> ; 0 if (PS2 xor LEFTHAND)
OPCODE_XOR_AL
swapmask db 00000011b
; end_
@@swapeven:
;j mouseupdate
swapbuttons endp
mouseupdate proc
; CODE_ AND_AX
OPCODE_AND_AX
buttonsmask db 00000111b ; =8
wheelmask db 0
xchg di,ax ; keep btn, wheel state in DI
;----- update mickey counters and screen position
xchg ax,bx ; OPTIMIZE: instead MOV AX,BX
; MOVREG_ bx,<offset X>
xor bx,bx ; MOVREG optimizes mov bx,offset POINT.X into this
call updateposition
xchg ax,cx
; MOVREG_ bl,<offset Y> ; OPTIMIZE: BL instead BX
mov bl,offset POINT.Y
call updateposition
or cl,al ; bit 0=mickeys change flag
;----- update wheel movement
mov ax,[mickeys.Y]
xchg ax,di ; retrieve button, wheel info
xchg dx,ax ; OPTIMIZE: instead MOV DX,AX
mov al,dh ; wheel: signed 4 bit value
xor al,00001000b ; =8
sub al,00001000b ; =8 ; sign extension AL[0:3]->AL
; if_ nz ; if wheel moved
jz @@wheelz
cbw
mov si,TSRdref:wheel
add [si + offset BUTTLASTSTATE.counter],ax ; wheel counter
add [wheelUIR],al ; same, but used for the UIR
mov al,10000000b ; =80h ; bit 7=wheel movement flag
xor bx,bx
call @lastpos
; end_
@@wheelz:
;----- update buttons state
mov dh,dl ; DH=buttons new state
xchg dl,[buttstatus]
xor dl,dh ; DL=buttons change state
if FASTER_CODE
; if_ nz
jz @@btnfastz
endif
xor bx,bx ; buttpress array index
mov al,00000010b ; mask for button 1
call updatebutton
mov al,00001000b ; mask for button 2
call updatebutton
mov al,00100000b ; mask for button 3
call updatebutton
if FASTER_CODE
; end_
@@btnfastz:
endif
;----- call User Interrupt Routine (CX=events mask)
dec [UIRunlock]
; if_ zero ; if user proc not running
jnz @@uirnz
and cl,[callmask]
; if_ nz ; if there is a user events
jz @@maskz
; CODE_ MOV_BX buttstatus,<db 0,0> ; buttons status
OPCODE_MOV_BX
buttstatus db 0,0
xchg bh,[wheelUIR]
mov ax,[granpos.X]
mov dx,[granpos.Y]
xchg ax,cx
mov si,[mickeys.X]
;mov di,[mickeys.Y]
push ds
sti
call [UIR@]
pop ds
; end_
@@maskz:
call refreshcursor
; end_
@@uirnz:
;-----
inc [UIRunlock]
ret
mouseupdate endp
;ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
; In: AX (mouse movement)
; BX (offset X/offset Y)
; Out: AX (1 - mickey counter changed)
; Use: mickey8, rangemax, rangemin, granumask, senscoeff
; Modf: DX, SI, sensround, mickeys, rounderr, pos, granpos
;
updateposition proc
test ax,ax
jz @@uposret
mov si,ax
; if_ sign
jns @@upns
neg ax
; end_
@@upns:
;----- apply sensitivity (SI=movement, AX=abs(SI))
mov dx,word ptr senscoeff[bx] ; ~[1/3..3.0]*256
; cmp ax,4 ; JWASM uses "signed byte" variant
db 03dh, 4, 0 ; "cmp ax, word 4"
; if_ be
ja @@upa
mov ax,si
cmp dh,1 ; skip [-4..4] movements
jae @@newmickeys ; when sensitivity >= 1.0
imul dx ; =mickeys*sensitivity
; else_
jmp short @@upbe
@@upa:
; cmp ax,12 ; JWASM uses "signed byte" variant
db 03dh, 12, 0 ; "cmp ax, word 12"
; if_ ae