initial cammit
[qbasicapps.git] / modules / qbExt / qbext.asm
1 ; TSR hack that allows QBasic programs to use mouse.\r
2 ; Made by Svjatoslav Agejenko\r
3 ; in 2004.01\r
4 ; Homepage: http://svjatoslav.eu\r
5  \r
6 \r
7 org 100h\r
8 \r
9 myint = 79h     ; interrupt to hook, becomes pointer to data table\r
10 \r
11 \r
12         mov     dx, msg\r
13         mov     ah, 9\r
14         int     21h\r
15 \r
16         mov     ax, 0           ; Saves old interrupt vector\r
17         mov     es, ax\r
18         mov     eax, [es:32]\r
19         mov     [oldVector], eax \r
20 \r
21         cli\r
22         mov     ax, cs          ; Set new interrupt vector for IRQ 0\r
23         shl     eax, 16\r
24         mov     ax, custom\r
25         mov     [es:32], eax\r
26         mov     ax, dataTable   ; Set interrupt vector for INT 79 (default)\r
27         mov     [es:4 * myint], eax\r
28         sti\r
29 \r
30         mov     ax, endPointer  ; Calculate needed memory size, become TSR\r
31         add     ax, 32\r
32         mov     dx, 0\r
33         mov     bx, 16\r
34         div     bx\r
35         mov     dx, ax\r
36         mov     ax, 3100h\r
37         int     21h\r
38 \r
39 custom:\r
40         pushf                   ; Execute default code in old int vector\r
41         call    dword [cs:oldVector]\r
42 \r
43         cmp     [cs:isRunning], 0 ; Check if custom routine is already active\r
44         jne     EndOfRoutine\r
45 \r
46         mov     [cs:isRunning], 1 ; Set active flag\r
47         pusha\r
48         push    ds\r
49         push    es\r
50 \r
51         cli \r
52         mov     ax, 0bh         ; Read Mouse Motion Counters\r
53         int     33h\r
54         add     [CS:mouseHorisontal], cx\r
55         add     [CS:mouseVertical], dx\r
56         mov     ax, 3           ; read mouse buttons\r
57         int     33h\r
58         or      [CS:mouseButtons], bx\r
59         inc     byte [CS:updated]\r
60         sti\r
61 \r
62         pop     es\r
63         pop     ds\r
64         popa\r
65         mov     [cs:isRunning], 0 ; Terminate active flag\r
66         EndOfRoutine:\r
67         iret\r
68 \r
69 oldVector       dd 0\r
70 isRunning       db 0\r
71 \r
72 dataTable:\r
73         dw 1983                 ; check number, indicates that module is loaded\r
74         mouseHorisontal dw 0\r
75         mouseVertical   dw 0\r
76         mouseButtons    dw 0\r
77         updated         db 0\r
78         \r
79 \r
80 endPointer:\r
81         \r
82 msg:\r
83 file 'readme.txt'\r
84         db '$'\r