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