Code: Select all
;************************************
; By Dex
; Entry for the 512b compo.
;
; Assemble with fasm
; c:\fasm MouseB.asm MouseB.bin
;
; Use partcopy and the installM.bat
; or rawrite to put it on the
; boot sector of floppy.
;
; Once rebooted move mouse and press
; any one of the 3 buttons to print
; B in the top corner.
;
; Code is freeware
;************************************
org 0x7C00
use16
;====================================================;
; Start. ;
;====================================================;
start:
;====================================================;
; Set the stack etc ;
;====================================================;
xor ax,ax
mov ds,ax
mov ss,ax
mov sp,0x7C00
push 0xb800
pop es
cli
;====================================================;
; Hook into isr. ;
;====================================================;
mov WORD[ds:74h*4+0],Mouse_isr
mov WORD[ds:74h*4+2],cs
;====================================================;
; Set mouse up. ;
;====================================================;
mov bl,0xa8
call KeyboardCommand
call KeyboardRead
mov bl,0x20
call KeyboardCommand
call KeyboardRead
or al,3
mov bl,0x60
push ax
call KeyboardCommand
pop ax
call KeyboardWrite
mov bl,0xd4
call KeyboardCommand
mov al,0f4h
call KeyboardWrite
call KeyboardRead
mov bl,0a7h
call KeyboardCommand
;SetMouseOn
mov bl,0a8h
call KeyboardCommand
sti
;====================================================;
; Clear screen. ;
;====================================================;
mov ax,0x0600
mov bh,0x07
mov cx,0x0000
mov dx,0x184f
int 10h
;====================================================;
; Simulate int. ;
;====================================================;
int 74h
;====================================================;
; Main loop. ;
;====================================================;
jmp $
;====================================================;
; KeyboardRead. ;
;====================================================;
KeyboardRead:
mov cx,0xffff
KeyReadLoop:
in al,0x64
test al,1
jnz KeyReadReady
loop KeyReadLoop
mov ah,1
jmp KeyReadExit
KeyReadReady:
mov cx,32
KeyReadDelay:
loop KeyReadDelay
in al,0x60
xor ah,ah
KeyReadExit:
ret
;====================================================;
; keyboardWrite. ;
;====================================================;
KeyboardWrite:
mov dl,al
mov ch,0xff
KbdWaitLoop1:
in al,0x64
test al,0x20
jz KbdWaitOk1
loop KbdWaitLoop1
mov ah,1
jmp KbdWaitExit
KbdWaitOk1:
in al,0x60
KbdWaitLoop:
in al,0x64
test al,2
jz KbdWriteOk
jmp KbdWaitLoop
KbdWriteOk:
mov al,dl
out 0x60,al
mov ch,0xff
KbdWaitLoop3:
in al,64h
test al,2
jz KbdWriteOk3
loop KbdWaitLoop3
mov ah,1
ret
KbdWriteOk3:
KbdWaitLoop4:
mov ch,0xff
KbdWaitLoop5:
in al,64h
test al,1
jnz KbdWriteOk4
loop KbdWaitLoop5
KbdWriteOk4:
KbdWaitExit:
ret
;====================================================;
; KeyboardCommand. ;
;====================================================;
KeyboardCommand:
mov ch,0xff
CommandWait:
in al,64h
test al,2
jz CommandSend
loop CommandWait
jmp CommandError
CommandSend:
mov al,bl
out 64h,al
mov ch,0xff
CommandAccept:
in al,0x64
test al,2
jz CommandOk
loop CommandAccept
CommandError:
mov ah,1
jmp CommandExit
CommandOk:
CommandExit:
ret
;----------------------------------------------------;
; Mouse ISR ;
;----------------------------------------------------;
Mouse_isr:
push cs
pop ds
mov byte[es:0000],' '
mov bl,0xad
call KeyboardCommand
xor di,di
mov cx,3
PS2MouseISR_ReadPacket:
push cx
call KeyboardRead
pop cx
or ah,ah
jnz PS2MouseISR_ExitReadPacket
mov byte[ds:buffer+di],al
inc di
loop PS2MouseISR_ReadPacket
PS2MouseISR_ExitReadPacket:
mov al,[ds:buffer]
and al,7h
mov ah,al
and ah,1
shl ah,2
mov bl,al
and bl,6
shr bl,1
or ah,bl
mov al,[buttons]
mov [buttons],ah
xor ah,al
shl ah,1
or [eventmsk],ah
mov al,[ds:buffer+1]
mov ah,[ds:buffer]
and ah,10h
shr ah,4
neg ah
add [current_x],ax
or ax,ax
setnz bl
or [eventmsk],bl
mov al,[ds:buffer+2]
mov ah,[ds:buffer]
and ah,0x20
shr ah,5
neg ah
neg ax
add [current_y], ax
or ax,ax
setnz bl
or [eventmsk],bl
;----------------------------------------------------;
; check boundaries ;
;----------------------------------------------------;
mov dx,[current_x]
cmp dx,[min_x]
jnl PS2MouseISR_CheckMaxX
mov dx,[min_x]
jmp PS2MouseISR_StoreNewX
PS2MouseISR_CheckMaxX:
cmp dx,[max_x]
jl PS2MouseISR_StoreNewX
mov dx,[max_x]
PS2MouseISR_StoreNewX:
mov [current_x],dx
mov dx,[current_y]
cmp dx,[min_y]
jnl PS2MouseISR_CheckMaxY
mov dx,[min_y]
jmp PS2MouseISR_StoreNewY
PS2MouseISR_CheckMaxY:
cmp dx,[max_y]
jl PS2MouseISR_StoreNewY
mov dx,[max_y]
PS2MouseISR_StoreNewY:
mov [current_y],dx
call PutMousePointer
@@:
mov al,[buttons]
cmp al,0
je NoButton
mov byte[es:0000],'B'
NoButton:
mov bl,0aeh
call KeyboardCommand
mov al, 0x20
out 0xa0, al
out 0x20,al
iret
;----------------------------------------------------;
; PutMousePointer ;
;----------------------------------------------------;
PutMousePointer:
mov bx,[current_x1]
shl bx,1
mov di, bx
mov bx,[current_y1]
mov ax,0xa0
mul bx
add di,ax
mov ax,[SaveChar]
mov [es:di],ax
mov bx,[current_x]
shl bx,1
mov di, bx
mov bx,[current_y]
mov ax,0xa0
mul bx
add di,ax
mov ax,word[es:di]
mov [SaveChar],ax
not ah
xor ah,0x80
mov [es:di],ax
mov ax,[current_x]
mov [current_x1],ax
mov ax,[current_y]
mov [current_y1],ax
ret
;====================================================;
; Data. ;
;====================================================;
min_x dw 0
max_x dw 79
min_y dw 0
max_y dw 24
eventmsk db 0
current_x dw 40
current_y dw 12
current_x1 dw 40
current_y1 dw 12
;====================================================;
; Make program 510 byte's + 0xaa55 ;
;====================================================;
times 510- ($-start) db 0
dw 0xaa55
;====================================================;
; Put uninitialized data here. ;
;====================================================;
MouseShow rb 1
SaveChar rw 1
buttons rb 1
buffer rb 10
Good luck everyone.