;//--------------------------------------------------------------- ;// trymouse.s ;// ;// This program calls ROM-BIOS services that enable the PS/2 ;// mouse to generate interrupts whenever the mouse is moved, ;// or when one of the mouse-buttons is pressed or released. ;// ;// assemble with: $ as86 trymouse.s -b trymouse.b ;// install using: $ dd if=trymouse.b of=/dev/fd0 seek=1 ;// ;// NOTE: This code begins executing with CS:IP = 1000:0002. ;// ;// programmer: ALLAN CRUSE ;// written on: 09 APR 2004 ;//--------------------------------------------------------------- ;----------------------------------------------------------------- .WORD 0xABCD ; programming signature ;----------------------------------------------------------------- main: mov ax, cs ; address this segment mov ds, ax ; with DS register pop dword return_address ; store return-address mov ss, ax ; adjust SS register lea esp, tos0 ; and set new stacktop call exec_our_ps2_demo push dword return_address ; recover our exit-address retf ; exit to program launcher ;----------------------------------------------------------------- return_address: .LONG 0 ; to store exit-address ;----------------------------------------------------------------- ;================================================================= ;----------------------------------------------------------------- vramptr: .WORD 640, 0xB800 ; pointer to video window ;----------------------------------------------------------------- isrPS2: pusha push ds push es mov ax, cs ; address this segment mov ds, ax ; with DS register les di, [vramptr] ; point ES:DI to window cld ; do forward processing mov ax, #0x2F4D ; setup character/color stosw ; store character/color mov [vramptr], di ; update window pointer pop es pop ds popa retf ; far return to ROM-BIOS ;----------------------------------------------------------------- ;----------------------------------------------------------------- exec_our_ps2_demo: ; install mouse-event handler for ROM-BIOS mov ax, cs ; address this segment mov es, ax ; with ES register lea bx, isrPS2 ; point ES:BX to handler mov ax, #0xC207 ; install mouse-handler int 0x15 ; request BIOS service call ax2hex ; show diagnostic status ; reset and enable the mouse mov ax, #0xC201 ; reset the mouse int 0x15 ; request BIOS service call ax2hex ; show diagnostic status mov ax, #0xC200 ; enable/disable mouse mov bh, #1 ; select enable int 0x15 ; request BIOS service call ax2hex ; show diagnostic status ; await keypress (while user tries moving the mouse) xor ah, ah ; get_keyboard_data int 0x16 ; request BIOS service ; disable mouse-interrupts mov ax, #0xC200 ; enable/disable mouse mov bh, #0 ; select disable int 0x15 ; request BIOS interface call ax2hex ; show diagnostic status ret ;----------------------------------------------------------------- ax2hex: pusha ; preserve cpu registers push es CSEG les di, [vramptr] ; point ES:DI to window cld ; do forward processing mov dx, ax ; copy the data into DX mov ah, #0x6E ; setup color-attribute mov cx, #4 ; setup count of nybbles .L0: rol dx, #4 ; next nybble into DL mov al, dl ; copy the nybble to AL and al, #0x0F ; isolate nybble's bits cmp al, #10 ; -- Lopez algorithm -- sbb al, #0x69 ; -- to convert from -- das ; -- binary to hex -- stosw ; store character/color loop .L0 ; process other nybbles mov al, #0x20 ; append one blank space stosw ; as a visual separator CSEG mov [vramptr], di ; update window pointer pop es ; restore cpu registers popa ret ;----------------------------------------------------------------- ;----------------------------------------------------------------- .ALIGN 16 ; alignment at paragraph .SPACE 512 ; reserved for stack use tos0: ; label fop top-of-stack ;----------------------------------------------------------------- END