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