forked from offtopia/ponydos
Convert to use int 0x15 mouse routines
This commit is contained in:
parent
e03b6c0ef1
commit
42932c472f
1 changed files with 91 additions and 83 deletions
170
ponydos.asm
170
ponydos.asm
|
@ -3,8 +3,6 @@ bits 16
|
||||||
|
|
||||||
org 0x7c00
|
org 0x7c00
|
||||||
|
|
||||||
mouse_packet equ 0x500
|
|
||||||
|
|
||||||
jmp 0:start
|
jmp 0:start
|
||||||
start:
|
start:
|
||||||
cld
|
cld
|
||||||
|
@ -18,112 +16,124 @@ start:
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
mov sp, $$
|
mov sp, $$
|
||||||
|
|
||||||
; Hook up IRQ12
|
|
||||||
mov [0x01D0], word mouse_irq
|
|
||||||
mov [0x01D0 + 2], word 0
|
|
||||||
|
|
||||||
sti
|
sti
|
||||||
|
|
||||||
init_8042:
|
initialize_mouse:
|
||||||
; TODO: This does not make sure the input buffer has been emptied
|
; Initialize mouse
|
||||||
; before writing to it. Works fine in QEMU, but may fail on
|
; https://www.ctyme.com/intr/rb-1601.htm
|
||||||
; real hardware.
|
mov ax, 0xc205
|
||||||
; Disable devices
|
mov bh, 3 ; TODO: This is the usual PS/2 mouse packet size, but is it correct here?
|
||||||
mov al, 0xad
|
int 0x15
|
||||||
out 0x64, al
|
jc .error
|
||||||
mov al, 0xa7
|
|
||||||
out 0x64, al
|
|
||||||
|
|
||||||
; Flush output buffer
|
; Set handler address
|
||||||
in al, 0x60
|
; https://www.ctyme.com/intr/rb-1603.htm
|
||||||
|
mov ax, 0xc207
|
||||||
|
; es is already set correctly
|
||||||
|
mov bx, mouse_handler
|
||||||
|
int 0x15
|
||||||
|
jc .error
|
||||||
|
|
||||||
; Get controller config byte
|
; Enable mouse
|
||||||
mov al, 0x20
|
; https://www.ctyme.com/intr/rb-1596.htm
|
||||||
out 0x64, al
|
mov ax, 0xc200
|
||||||
.wait_config:
|
mov bh, 1
|
||||||
in al, 0x64
|
int 0x15
|
||||||
test al, 1<<0 ; Test whether output status buffer has data
|
jc .error
|
||||||
jz .wait_config
|
|
||||||
in al, 0x60
|
|
||||||
|
|
||||||
; Enable second PS/2 device (likely mouse) interrupt
|
jmp mainloop
|
||||||
or al, 1<<1
|
|
||||||
mov bl, al
|
|
||||||
mov al, 0x60
|
|
||||||
out 0x64, al
|
|
||||||
mov al, bl
|
|
||||||
out 0x60, al
|
|
||||||
|
|
||||||
; Enable devices
|
.error:
|
||||||
mov al, 0xae
|
; https://www.ctyme.com/intr/rb-1601.htm
|
||||||
out 0x64, al
|
mov ax, 0xc201
|
||||||
mov al, 0xa8
|
int 0x15
|
||||||
out 0x64, al
|
jmp initialize_mouse
|
||||||
|
|
||||||
init_mouse:
|
|
||||||
; Start packet streaming
|
|
||||||
mov al, 0xd4
|
|
||||||
out 0x64, al
|
|
||||||
mov al, 0xf4
|
|
||||||
out 0x60, al
|
|
||||||
|
|
||||||
mainloop:
|
mainloop:
|
||||||
; TODO: everything
|
; TODO: everything
|
||||||
|
|
||||||
hang:
|
hang:
|
||||||
hlt
|
hlt
|
||||||
|
;mov ax, 0x0e00 + '.'
|
||||||
|
;int 0x10
|
||||||
jmp hang
|
jmp hang
|
||||||
|
|
||||||
mouse_irq:
|
mouse_handler:
|
||||||
push ax
|
push ax
|
||||||
push bx
|
push bx
|
||||||
|
push bp
|
||||||
|
|
||||||
; Read mouse data
|
mov bp, sp
|
||||||
in al, 0x60
|
|
||||||
|
|
||||||
xor bh, bh
|
; status
|
||||||
mov bl, [mouse_packet_fill]
|
mov bx, [bp+16]
|
||||||
test bl, bl
|
|
||||||
jnz .store_byte
|
|
||||||
|
|
||||||
test al, 1<<3 ; Always-on bit in first byte
|
; X negative
|
||||||
jz .finish
|
test bl, 0x10
|
||||||
|
jz .no_x_negative
|
||||||
|
mov ax, 0x0e00 + '-'
|
||||||
|
int 0x10
|
||||||
|
.no_x_negative:
|
||||||
|
|
||||||
.store_byte:
|
; X overflow
|
||||||
mov [mouse_packet + bx], al
|
test bl, 0x40
|
||||||
inc bl
|
jz .no_x_overflow
|
||||||
cmp bl, 3
|
mov ax, 0x0e00 + 'o'
|
||||||
jne .finish
|
.no_x_overflow:
|
||||||
|
|
||||||
.full_packet:
|
; X
|
||||||
; TODO: Do something useful with the mouse packet
|
mov ax, [bp+14]
|
||||||
push si
|
|
||||||
mov si, mouse_packet
|
|
||||||
lodsb
|
|
||||||
call hexprint8
|
call hexprint8
|
||||||
lodsb
|
mov ax, 0x0e00 + ' '
|
||||||
call hexprint8
|
|
||||||
lodsb
|
|
||||||
call hexprint8
|
|
||||||
pop si
|
|
||||||
mov ax, 0x0e20
|
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
; Empty out the mouse packet buffer
|
; Y negative
|
||||||
xor bl, bl
|
test bl, 0x20
|
||||||
|
jz .no_y_negative
|
||||||
|
mov ax, 0x0e00 + '-'
|
||||||
|
int 0x10
|
||||||
|
.no_y_negative:
|
||||||
|
|
||||||
.finish:
|
; Y overflow
|
||||||
; Store back possibly updated mouse packet fill
|
test bl, 0x80
|
||||||
mov [mouse_packet_fill], bl
|
jz .no_y_overflow
|
||||||
|
mov ax, 0x0e00 + 'o'
|
||||||
|
.no_y_overflow:
|
||||||
|
|
||||||
; Reset PICs
|
; Y
|
||||||
mov al, 0x20
|
mov ax, [bp+12]
|
||||||
out 0xa0, al
|
call hexprint8
|
||||||
out 0x20, al
|
mov ax, 0x0e00 + ' '
|
||||||
|
int 0x10
|
||||||
|
|
||||||
|
; Left mouse
|
||||||
|
test bl, 0x01
|
||||||
|
jz .no_lmb
|
||||||
|
mov ax, 0x0e00 + 'L'
|
||||||
|
int 0x10
|
||||||
|
.no_lmb:
|
||||||
|
|
||||||
|
; Right mouse
|
||||||
|
test bl, 0x02
|
||||||
|
jz .no_rmb
|
||||||
|
mov ax, 0x0e00 + 'R'
|
||||||
|
int 0x10
|
||||||
|
.no_rmb
|
||||||
|
|
||||||
|
mov ax, 0x0e00 + 13
|
||||||
|
int 0x10
|
||||||
|
mov ax, 0x0e00 + 10
|
||||||
|
int 0x10
|
||||||
|
|
||||||
|
pop bp
|
||||||
pop bx
|
pop bx
|
||||||
pop ax
|
pop ax
|
||||||
iret
|
retf
|
||||||
|
|
||||||
|
hexprint16:
|
||||||
|
xchg ah, al
|
||||||
|
call hexprint8
|
||||||
|
xchg ah, al
|
||||||
|
|
||||||
hexprint8:
|
hexprint8:
|
||||||
push ax
|
push ax
|
||||||
|
@ -149,8 +159,6 @@ hexprint4:
|
||||||
pop ax
|
pop ax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
mouse_packet_fill db 0
|
|
||||||
|
|
||||||
times 510-($-$$) db 0
|
times 510-($-$$) db 0
|
||||||
db 0x55
|
db 0x55
|
||||||
db 0xaa
|
db 0xaa
|
||||||
|
|
Loading…
Reference in a new issue