fix mouse management
This commit is contained in:
parent
82724598ee
commit
9621566036
4 changed files with 98 additions and 88 deletions
41
src/bda.asm
41
src/bda.asm
|
|
@ -49,26 +49,31 @@
|
||||||
;
|
;
|
||||||
|
|
||||||
%define BDA_DATA_SEG 0x0050
|
%define BDA_DATA_SEG 0x0050
|
||||||
|
%define BDA_MOUSE 0x0000
|
||||||
|
|
||||||
%define BDA_MOUSE_BUFFER 0x0000 ; dword; buffer (jusqu'à 4 octets)
|
struc mouse
|
||||||
%define BDA_MOUSE_IDX 0x0004 ; byte 0..3
|
.buffer resb 4 ; i8042 input buffer
|
||||||
%define DBA_MOUSE_PACKETLEN 0x0005
|
.idx resb 1 ; index in the buffer
|
||||||
%define DBA_CURSOR_MASK 0x0006 ; byte pixels mask (bit per pixel)
|
.packetlen resb 1 ; max buffer len (3 ou 4)
|
||||||
%define BDA_MOUSE_STATUS 0x0007 ; byte
|
|
||||||
%define BDA_MOUSE_X 0x0008 ; word
|
|
||||||
%define BDA_MOUSE_Y 0x000A ; word
|
|
||||||
%define BDA_MOUSE_WHEEL 0x000C ; word
|
|
||||||
|
|
||||||
%define BDA_CURSOR_VISIBLE 0x000E ; byte (0/1)
|
.status resb 1 ; mouse status (button etc)
|
||||||
%define BDA_CURSOR_OLDX 0x000F ; word
|
.wheel resb 1 ; if a packet size is 4; experimental
|
||||||
%define BDA_CURSOR_OLDY 0x0011 ; word
|
.x resw 1 ;
|
||||||
%define BDA_CURSOR_NEWX 0x0013 ; word
|
.y resw 1
|
||||||
%define BDA_CURSOR_NEWY 0x0015 ; word
|
; cursor management
|
||||||
%define BDA_CURSOR_BITOFF 0x0017 ; byte 0..7 bits d'offset (x&7)
|
.cur_oldx resw 1
|
||||||
%define BDA_CURSOR_BYTES 0x0019 ; byte 2 ou 3 bytes as source for cursor image
|
.cur_oldy resw 1
|
||||||
%define BDA_CURSOR_SAVED 0x001A ; flag if image saved
|
.cur_newx resw 1
|
||||||
%define BDA_CURSOR_PTR 0x001B ; pointeur vers l'image du curseur
|
.cur_newy resw 1
|
||||||
%define BDA_CURSOR_BG 0x0020 ; 48 bytes max (3*16)
|
.cur_visible resb 1
|
||||||
|
.cur_seg resw 1 ; segment / offset of the pointer
|
||||||
|
.cur_ofs resw 1
|
||||||
|
.cur_mask resb 1 ; pixels mask (bit per pixel)
|
||||||
|
.cur_bit_ofs resb 1 ; 0..7 bits d'offset (x&7)
|
||||||
|
.cur_bytes resb 1 ; byte 2 ou 3 bytes as source for cursor image
|
||||||
|
.bkg_saved resb 1 ; background saved
|
||||||
|
.bkg_buffer resb 48 ; buffer for saved background
|
||||||
|
endstruc
|
||||||
|
|
||||||
; -----------------------------------------------------------------------------------
|
; -----------------------------------------------------------------------------------
|
||||||
; PC components I/O ports
|
; PC components I/O ports
|
||||||
|
|
|
||||||
14
src/boot.asm
14
src/boot.asm
|
|
@ -137,18 +137,16 @@ endless:
|
||||||
; -----------------------------------------------------------
|
; -----------------------------------------------------------
|
||||||
test_isr:
|
test_isr:
|
||||||
push ax
|
push ax
|
||||||
push fs
|
|
||||||
|
|
||||||
mov ax,BDA_DATA_SEG
|
; push fs
|
||||||
mov fs,ax
|
;mov ax,BDA_DATA_SEG
|
||||||
inc byte [fs:0x000F]
|
;mov fs,ax
|
||||||
|
;inc byte [fs:0x0005]
|
||||||
inc byte [fs:0x0005]
|
|
||||||
|
|
||||||
mov al, PIC_EOI ; EOI master
|
mov al, PIC_EOI ; EOI master
|
||||||
out i8259_MASTER_CMD, al
|
out i8259_MASTER_CMD, al
|
||||||
|
; pop fs
|
||||||
pop fs
|
|
||||||
pop ax
|
pop ax
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ gfx_init:
|
||||||
mov al, GFX_MODE
|
mov al, GFX_MODE
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
mov byte [BDA_CURSOR_SAVED],0 ; flag image saved
|
mov byte [BDA_MOUSE + mouse.bkg_saved],0 ; flag image saved
|
||||||
|
|
||||||
; dessine un background "check-board"
|
; dessine un background "check-board"
|
||||||
call gfx_background
|
call gfx_background
|
||||||
|
|
@ -159,13 +159,13 @@ gfx_background:
|
||||||
gfx_cursor_calc_align:
|
gfx_cursor_calc_align:
|
||||||
mov al, cl
|
mov al, cl
|
||||||
and al, 7 ; offset = x&7
|
and al, 7 ; offset = x&7
|
||||||
mov byte [BDA_CURSOR_BITOFF], al
|
mov byte [BDA_MOUSE + mouse.cur_bit_ofs], al
|
||||||
cmp al, 0
|
cmp al, 0
|
||||||
jne .unaligned
|
jne .unaligned
|
||||||
mov byte [BDA_CURSOR_BYTES], 2
|
mov byte [BDA_MOUSE + mouse.cur_bytes], 2
|
||||||
ret
|
ret
|
||||||
.unaligned:
|
.unaligned:
|
||||||
mov byte [BDA_CURSOR_BYTES], 3
|
mov byte [BDA_MOUSE + mouse.cur_bytes], 3
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
|
|
@ -211,15 +211,15 @@ gfx_cursor_draw:
|
||||||
mov ax, VIDEO_SEG
|
mov ax, VIDEO_SEG
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
|
||||||
mov ax, word [BDA_CURSOR_PTR]
|
mov ax, word [BDA_MOUSE + mouse.cur_ofs]
|
||||||
mov si, ax
|
mov si, ax
|
||||||
|
|
||||||
mov cx, word [BDA_CURSOR_NEWX]
|
mov cx, word [BDA_MOUSE + mouse.cur_newx]
|
||||||
mov dx, word [BDA_CURSOR_NEWY]
|
mov dx, word [BDA_MOUSE + mouse.cur_newy]
|
||||||
|
|
||||||
; calcule offset et bytes/ligne (2 ou 3)
|
; calcule offset et bytes/ligne (2 ou 3)
|
||||||
call gfx_cursor_calc_align
|
call gfx_cursor_calc_align
|
||||||
mov bl, byte [BDA_CURSOR_BITOFF]; 0..7
|
mov bl, byte [BDA_MOUSE + mouse.cur_bit_ofs]; 0..7
|
||||||
|
|
||||||
; calcule DI de départ (attention: gfx_calc_addr modifie CL)
|
; calcule DI de départ (attention: gfx_calc_addr modifie CL)
|
||||||
push cx
|
push cx
|
||||||
|
|
@ -417,16 +417,16 @@ gfx_cursor_savebg:
|
||||||
mov ax, VIDEO_SEG
|
mov ax, VIDEO_SEG
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
|
||||||
cmp byte [BDA_CURSOR_SAVED], 0
|
cmp byte [BDA_MOUSE + mouse.bkg_saved], 0
|
||||||
jne .done ; déjà sauvé
|
jne .done ; déjà sauvé
|
||||||
|
|
||||||
mov cx, [BDA_MOUSE_X]
|
mov cx, [BDA_MOUSE + mouse.x]
|
||||||
mov dx, [BDA_MOUSE_Y]
|
mov dx, [BDA_MOUSE + mouse.y]
|
||||||
|
|
||||||
mov byte [BDA_CURSOR_SAVED], 1 ; flag image saved
|
mov byte [BDA_MOUSE + mouse.bkg_saved], 1 ; flag image saved
|
||||||
|
|
||||||
mov word [BDA_CURSOR_NEWX], cx ; sauvegarde la nouvelle position
|
mov word [BDA_MOUSE + mouse.cur_newx], cx ; sauvegarde la nouvelle position
|
||||||
mov word [BDA_CURSOR_NEWY], dx
|
mov word [BDA_MOUSE + mouse.cur_newy], dx
|
||||||
|
|
||||||
call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y)
|
call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y)
|
||||||
mov dx,0x2000 ; offset pour lignes impaire
|
mov dx,0x2000 ; offset pour lignes impaire
|
||||||
|
|
@ -434,15 +434,15 @@ gfx_cursor_savebg:
|
||||||
jl .no_odd_bank
|
jl .no_odd_bank
|
||||||
neg dx ; Y est déja une ligne impaire, on retire l'offset
|
neg dx ; Y est déja une ligne impaire, on retire l'offset
|
||||||
.no_odd_bank:
|
.no_odd_bank:
|
||||||
|
mov ax, BDA_MOUSE + mouse.bkg_buffer
|
||||||
mov si, BDA_CURSOR_BG ; DS:SI = buffer de sauvegarde
|
mov si, ax ; DS:SI = buffer de sauvegarde
|
||||||
mov bx, 8
|
mov bx, 8
|
||||||
|
|
||||||
and cx,0x0007 ; alignement X
|
and cx,0x0007 ; alignement X
|
||||||
jnz .row3
|
jnz .row3
|
||||||
|
|
||||||
.row3: ; sauve 3 bytes/ligne
|
.row3: ; sauve 3 bytes/ligne
|
||||||
mov byte [BDA_CURSOR_BYTES], 3 ; 3 bytes/ligne
|
mov byte [BDA_MOUSE + mouse.cur_bytes], 3 ; 3 bytes/ligne
|
||||||
; ligne 'y', peut etre paire ou impaire
|
; ligne 'y', peut etre paire ou impaire
|
||||||
mov ax, word [es:di] ; charge first word
|
mov ax, word [es:di] ; charge first word
|
||||||
mov word [ds:si], ax ; sauvegarde
|
mov word [ds:si], ax ; sauvegarde
|
||||||
|
|
@ -464,7 +464,7 @@ gfx_cursor_savebg:
|
||||||
jmp .done
|
jmp .done
|
||||||
|
|
||||||
.row2: ; sauve 2 bytes/ligne
|
.row2: ; sauve 2 bytes/ligne
|
||||||
mov byte [BDA_CURSOR_BYTES], 2 ; par défaut
|
mov byte [BDA_MOUSE + mouse.cur_bytes], 2 ; par défaut
|
||||||
; ligne 'y', peut etre paire ou impaire
|
; ligne 'y', peut etre paire ou impaire
|
||||||
mov ax, word [es:di] ; charge first word
|
mov ax, word [es:di] ; charge first word
|
||||||
mov word [ds:si], ax ; sauvegarde
|
mov word [ds:si], ax ; sauvegarde
|
||||||
|
|
@ -497,12 +497,12 @@ gfx_cursor_restorebg:
|
||||||
mov ax, VIDEO_SEG
|
mov ax, VIDEO_SEG
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
|
||||||
cmp byte [BDA_CURSOR_SAVED], 0 ; pas de background sauvé
|
cmp byte [BDA_MOUSE + mouse.bkg_saved], 0 ; pas de background sauvé
|
||||||
je .done
|
je .done
|
||||||
|
|
||||||
mov cx,word [BDA_CURSOR_OLDX] ; restore de la position
|
mov cx,word [BDA_MOUSE + mouse.cur_oldx] ; restore de la position
|
||||||
mov dx,word [BDA_CURSOR_OLDY]
|
mov dx,word [BDA_MOUSE + mouse.cur_oldy]
|
||||||
mov byte [BDA_CURSOR_SAVED], 0 ; le background a été restauré
|
mov byte [BDA_MOUSE + mouse.bkg_saved], 0 ; le background a été restauré
|
||||||
|
|
||||||
call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y)
|
call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y)
|
||||||
mov dx,0x2000 ; offset pour lignes impaire
|
mov dx,0x2000 ; offset pour lignes impaire
|
||||||
|
|
@ -510,10 +510,12 @@ gfx_cursor_restorebg:
|
||||||
jl .no_odd_bank
|
jl .no_odd_bank
|
||||||
neg dx ; Y est déja une ligne impaire, on retire l'offset
|
neg dx ; Y est déja une ligne impaire, on retire l'offset
|
||||||
.no_odd_bank:
|
.no_odd_bank:
|
||||||
mov si, BDA_CURSOR_BG ; DS:SI = buffer de sauvegarde
|
|
||||||
|
mov ax, BDA_MOUSE + mouse.bkg_buffer
|
||||||
|
mov si, ax ; DS:SI = buffer de sauvegarde
|
||||||
mov bx, 8
|
mov bx, 8
|
||||||
|
|
||||||
cmp byte [BDA_CURSOR_BYTES], 2 ; si la sauvegarde est en 2 bytes/ligne
|
cmp byte [BDA_MOUSE + mouse.cur_bytes], 2 ; si la sauvegarde est en 2 bytes/ligne
|
||||||
je .row2
|
je .row2
|
||||||
|
|
||||||
.row3: ; restore en 3 bytes/ligne
|
.row3: ; restore en 3 bytes/ligne
|
||||||
|
|
|
||||||
|
|
@ -82,25 +82,27 @@ mouse_arrow:
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
mouse_reset:
|
mouse_reset:
|
||||||
mov ax, BDA_DATA_SEG
|
mov ax, BDA_DATA_SEG
|
||||||
mov ds,ax
|
mov fs,ax
|
||||||
|
|
||||||
; effacer les variables du drivers
|
; effacer les variables du drivers
|
||||||
mov byte [BDA_MOUSE_IDX],0
|
mov byte [fs:BDA_MOUSE + mouse.idx],0
|
||||||
mov dword [BDA_MOUSE_BUFFER],0
|
mov dword [fs:BDA_MOUSE + mouse.buffer],0
|
||||||
mov byte [DBA_MOUSE_PACKETLEN],3
|
mov byte [fs:BDA_MOUSE + mouse.packetlen],3
|
||||||
|
|
||||||
mov byte [BDA_MOUSE_STATUS],0
|
mov byte [fs:BDA_MOUSE + mouse.status],0
|
||||||
mov word [BDA_MOUSE_X],320 ; vous pouvez aussi préciser le centre
|
mov word [fs:BDA_MOUSE + mouse.x],320 ; vous pouvez aussi préciser le centre
|
||||||
mov word [BDA_MOUSE_Y],100 ; vous pouvez aussi préciser le centre
|
mov word [fs:BDA_MOUSE + mouse.y],100 ; vous pouvez aussi préciser le centre
|
||||||
|
|
||||||
; experiemntal
|
; experiemntal
|
||||||
mov word [BDA_MOUSE_WHEEL],0
|
mov word [fs:BDA_MOUSE + mouse.wheel],0
|
||||||
|
|
||||||
mov byte [BDA_CURSOR_VISIBLE], 1
|
mov byte [fs:BDA_MOUSE + mouse.cur_visible], 1
|
||||||
mov word [BDA_CURSOR_OLDX], 0
|
mov word [fs:BDA_MOUSE + mouse.cur_oldx], 0
|
||||||
mov word [BDA_CURSOR_OLDY], 0
|
mov word [fs:BDA_MOUSE + mouse.cur_oldy], 0
|
||||||
|
|
||||||
mov word [BDA_CURSOR_PTR], mouse_arrow
|
mov ax, cs
|
||||||
|
mov word [fs:BDA_MOUSE + mouse.cur_seg], ax
|
||||||
|
mov word [fs:BDA_MOUSE + mouse.cur_ofs], mouse_arrow
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
|
|
@ -200,7 +202,10 @@ mouse_init:
|
||||||
;
|
;
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
mouse_detect_packet_len:
|
mouse_detect_packet_len:
|
||||||
mov byte [DBA_MOUSE_PACKETLEN], 3
|
mov ax, BDA_DATA_SEG
|
||||||
|
mov fs,ax
|
||||||
|
|
||||||
|
mov byte [fs:BDA_MOUSE + mouse.packetlen], 3
|
||||||
|
|
||||||
; SET_RATE + 200
|
; SET_RATE + 200
|
||||||
mov bl, MOUSE_SET_RATE
|
mov bl, MOUSE_SET_RATE
|
||||||
|
|
@ -231,7 +236,7 @@ mouse_detect_packet_len:
|
||||||
je .is4
|
je .is4
|
||||||
ret
|
ret
|
||||||
.is4:
|
.is4:
|
||||||
mov byte [DBA_MOUSE_PACKETLEN], 4
|
mov byte [fs:BDA_MOUSE + mouse.packetlen], 4
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
|
|
@ -332,51 +337,51 @@ isr_mouse_handler:
|
||||||
|
|
||||||
; lire un octet depuis le contrôleur et le stocker dans le buffer
|
; lire un octet depuis le contrôleur et le stocker dans le buffer
|
||||||
in al, i8042_PS2_DATA ; lire octet souris
|
in al, i8042_PS2_DATA ; lire octet souris
|
||||||
movzx bx, byte [BDA_MOUSE_IDX]
|
movzx bx, byte [BDA_MOUSE + mouse.idx]
|
||||||
mov byte [BDA_MOUSE_BUFFER + bx], al
|
mov byte [BDA_MOUSE + mouse.buffer + bx], al
|
||||||
inc byte [BDA_MOUSE_IDX]
|
inc byte [BDA_MOUSE + mouse.idx]
|
||||||
|
|
||||||
; vérifier si le packet est complet
|
; vérifier si le packet est complet
|
||||||
mov al, [DBA_MOUSE_PACKETLEN]
|
mov al, [BDA_MOUSE + mouse.packetlen]
|
||||||
cmp byte [BDA_MOUSE_IDX], al
|
cmp byte [BDA_MOUSE + mouse.idx], al
|
||||||
jne .done
|
jne .done
|
||||||
|
|
||||||
; packet complet, on decode les données
|
; packet complet, on decode les données
|
||||||
mov byte [BDA_MOUSE_IDX], 0
|
mov byte [BDA_MOUSE + mouse.idx], 0
|
||||||
mov al, [BDA_MOUSE_BUFFER] ; status
|
mov al, [BDA_MOUSE + mouse.buffer] ; status
|
||||||
mov [BDA_MOUSE_STATUS], al
|
mov [BDA_MOUSE + mouse.status], al
|
||||||
|
|
||||||
mov al, [BDA_MOUSE_BUFFER+1] ; delta X
|
mov al, [BDA_MOUSE + mouse.buffer+1] ; delta X
|
||||||
cbw
|
cbw
|
||||||
add [BDA_MOUSE_X], ax
|
add [BDA_MOUSE + mouse.x], ax
|
||||||
|
|
||||||
mov al, [BDA_MOUSE_BUFFER+2] ; delta Y
|
mov al, [BDA_MOUSE + mouse.buffer+2] ; delta Y
|
||||||
cbw
|
cbw
|
||||||
sub [BDA_MOUSE_Y], ax
|
sub [BDA_MOUSE + mouse.y], ax
|
||||||
|
|
||||||
; si packetlen = 4, gérer la molette; experimental
|
; si packetlen = 4, gérer la molette; experimental
|
||||||
mov al, [BDA_MOUSE_BUFFER+3] ; delta Wheel
|
mov al, [BDA_MOUSE + mouse.buffer+3] ; delta Wheel
|
||||||
cbw
|
cbw
|
||||||
add word [BDA_MOUSE_WHEEL], ax
|
add word [BDA_MOUSE + mouse.wheel], ax
|
||||||
|
|
||||||
; clamp X
|
; clamp X
|
||||||
cmp word [BDA_MOUSE_X], 0
|
cmp word [BDA_MOUSE + mouse.x], 0
|
||||||
jge .x_ok_low
|
jge .x_ok_low
|
||||||
mov word [BDA_MOUSE_X], 0
|
mov word [BDA_MOUSE + mouse.x], 0
|
||||||
.x_ok_low:
|
.x_ok_low:
|
||||||
cmp word [BDA_MOUSE_X], 639
|
cmp word [BDA_MOUSE + mouse.x], 639
|
||||||
jle .x_ok_high
|
jle .x_ok_high
|
||||||
mov word [BDA_MOUSE_X], 639
|
mov word [BDA_MOUSE + mouse.x], 639
|
||||||
.x_ok_high:
|
.x_ok_high:
|
||||||
|
|
||||||
; clamp Y
|
; clamp Y
|
||||||
cmp word [BDA_MOUSE_Y], 0
|
cmp word [BDA_MOUSE + mouse.y], 0
|
||||||
jge .y_ok_low
|
jge .y_ok_low
|
||||||
mov word [BDA_MOUSE_Y], 0
|
mov word [BDA_MOUSE + mouse.y], 0
|
||||||
.y_ok_low:
|
.y_ok_low:
|
||||||
cmp word [BDA_MOUSE_Y], 199
|
cmp word [BDA_MOUSE + mouse.y], 199
|
||||||
jle .y_ok_high
|
jle .y_ok_high
|
||||||
mov word [BDA_MOUSE_Y], 199
|
mov word [BDA_MOUSE + mouse.y], 199
|
||||||
.y_ok_high:
|
.y_ok_high:
|
||||||
; restaurer l'ancien arrière plan du curseur
|
; restaurer l'ancien arrière plan du curseur
|
||||||
;call gfx_cursor_restorebg
|
;call gfx_cursor_restorebg
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue