Mouse interrupt handler + debug
This commit is contained in:
parent
c97c844329
commit
4cf1a0b7a2
6 changed files with 389 additions and 235 deletions
|
|
@ -58,6 +58,7 @@ struc mouse
|
|||
.buffer resb 4 ; i8042 input buffer 0..3
|
||||
.idx resb 1 ; index in the buffer 4
|
||||
.packetlen resb 1 ; max buffer len (3 ou 4) 5
|
||||
.blinker resb 1 ;
|
||||
|
||||
.status resb 1 ; mouse status (button etc) 6
|
||||
.wheel resb 1 ; if a packet size is 4; experimental 7
|
||||
|
|
@ -85,11 +86,7 @@ struc gfx
|
|||
.cur_y resw 1
|
||||
.cur_offset resw 1 ; offset calculé pour le prochain caractère
|
||||
.cur_line_ofs resw 1 ; "interligne" +2000h ou -2000h
|
||||
; .cur_xbyte resb 1 ; x>>3 (0..79)
|
||||
.cur_shift resb 1 ; x&7 (0..7)
|
||||
; .cur_parity resb 1
|
||||
; .cur_color resb 1 ; 0 = texte en noir, autre = texte en blanc
|
||||
; .cur_trans resb 1 ; 0 = fond transparent, autre = fond inversé .txt_color
|
||||
.cur_mode resb 1 ;
|
||||
endstruc
|
||||
|
||||
|
|
|
|||
36
src/boot.asm
36
src/boot.asm
|
|
@ -31,6 +31,13 @@ bits 16
|
|||
; initial stack
|
||||
%define STACK_SEG 0x0800 ; segment de base
|
||||
|
||||
;section .text
|
||||
; bits 16
|
||||
;
|
||||
; db 'EXTRA CODE Section',0
|
||||
;
|
||||
; times 0xFFFF - ($ - $$) db 0xFF
|
||||
|
||||
section .text
|
||||
bits 16
|
||||
|
||||
|
|
@ -41,7 +48,7 @@ section .text
|
|||
%include "./bda.asm"
|
||||
|
||||
; %include "./services/macros.asm"
|
||||
%include "./drivers/debug.asm"
|
||||
%include "./common/debug_cga.asm"
|
||||
%include "./drivers/gfx_cgam.asm"
|
||||
%include "./drivers/mouse_ps2.asm"
|
||||
%include "./drivers/keyboard_ps2.asm"
|
||||
|
|
@ -82,10 +89,6 @@ reset:
|
|||
; on vérifie que le BIOS VGA a installé une INT 10h
|
||||
call setup_check_vga
|
||||
|
||||
; on initialise le mode texte 80x25 par défaut DEBUG
|
||||
;mov ax, 0x0003
|
||||
;int 10h
|
||||
|
||||
; enable IRQ 0
|
||||
mov ah,IRQ_ENABLED
|
||||
mov al,0
|
||||
|
|
@ -135,7 +138,6 @@ reset:
|
|||
|
||||
mov cx,8
|
||||
mov dx,24
|
||||
|
||||
GFX_SET_WRTIE_MODE 0
|
||||
|
||||
.loopshift:
|
||||
|
|
@ -147,10 +149,28 @@ reset:
|
|||
cmp cx,16
|
||||
jbe .loopshift
|
||||
|
||||
endless:
|
||||
mov ax,BDA_DATA_SEG
|
||||
mov ds,ax
|
||||
mov ax,0
|
||||
endless:
|
||||
xor cx,cx
|
||||
mov dx,180
|
||||
GFX_DRV GFX_GOTOXY
|
||||
|
||||
mov ax, [BDA_MOUSE + mouse.x]
|
||||
call print_word_hex
|
||||
|
||||
mov al,' '
|
||||
call cga_putc
|
||||
|
||||
mov ax, [BDA_MOUSE + mouse.y]
|
||||
call print_word_hex
|
||||
|
||||
mov al,' '
|
||||
call cga_putc
|
||||
|
||||
xor ah,ah
|
||||
mov al, [BDA_MOUSE + mouse.blinker]
|
||||
call print_word_hex
|
||||
|
||||
jmp endless
|
||||
|
||||
|
|
|
|||
105
src/common/debug_cga.asm
Normal file
105
src/common/debug_cga.asm
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
; =============================================================================
|
||||
; Project : Custom BIOS / ROM
|
||||
; File : cga_debug.asm
|
||||
; Author : frater
|
||||
;
|
||||
; License : GNU General Public License v3.0 or later (GPL-3.0+)
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
;
|
||||
; =============================================================================
|
||||
|
||||
; =============================================================================
|
||||
; Fonction : dump_ram_words
|
||||
; Description : Lit des mots (16 bits) depuis DS:SI et les affiche en Hexa
|
||||
; Entrées :
|
||||
; DS:SI = Adresse de départ en RAM
|
||||
; CX = Nombre de mots (words) à lire et afficher
|
||||
; =============================================================================
|
||||
|
||||
dump_ram_words:
|
||||
jcxz .done ; Sécurité : si CX=0, on sort
|
||||
|
||||
.loop:
|
||||
lodsw ; Charge [DS:SI] dans AX et incrémente SI de 2
|
||||
; Note: x86 est Little Endian. Si RAM = 12 34,
|
||||
; AX vaudra 0x3412.
|
||||
|
||||
push cx ; Sauvegarde le compteur de boucle principal
|
||||
push si ; Sauvegarde le pointeur (si cga_putc le modifie)
|
||||
|
||||
call print_word_hex ; Affiche AX sous forme "XXXX"
|
||||
|
||||
; (Optionnel) Ajouter un espace entre chaque mot pour la lisibilité
|
||||
mov al, ' '
|
||||
call cga_putc
|
||||
|
||||
pop si ; Restaure SI
|
||||
pop cx ; Restaure CX
|
||||
|
||||
loop .loop ; Décrémente CX et boucle si != 0
|
||||
|
||||
.done:
|
||||
ret
|
||||
|
||||
; =============================================================================
|
||||
; Fonction : print_word_hex
|
||||
; Description : Convertit AX en 4 caractères Hexa et les affiche
|
||||
; Entrée : AX = Valeur 16 bits (ex: 0x1A2B)
|
||||
; Sortie : Affiche "1A2B" via cga_putc
|
||||
; =============================================================================
|
||||
print_word_hex:
|
||||
push ax ; Sauvegarde AX car on va le modifier (rotation)
|
||||
push cx
|
||||
push bx
|
||||
|
||||
mov cx, 4 ; 4 caractères hex dans un mot de 16 bits
|
||||
|
||||
.next_digit:
|
||||
; On veut afficher les bits 12-15 d'abord.
|
||||
; L'astuce est de faire une rotation à gauche de 4 bits.
|
||||
; Le quartet de poids fort se retrouve en bas (bits 0-3).
|
||||
rol ax, 4
|
||||
|
||||
mov bx, ax ; Copie temporaire
|
||||
and bl, 0x0F ; On isole les 4 derniers bits (0 à 15)
|
||||
|
||||
mov al, bl ; AL contient la valeur numérique (0-15)
|
||||
call nibble_to_ascii ; Convertit AL en caractère ASCII
|
||||
|
||||
call cga_putc ; Affiche le caractère
|
||||
|
||||
loop .next_digit ; Répète 4 fois
|
||||
|
||||
pop bx
|
||||
pop cx
|
||||
pop ax ; Restaure l'état original de AX
|
||||
ret
|
||||
|
||||
; =============================================================================
|
||||
; Fonction : nibble_to_ascii
|
||||
; Description : Convertit les 4 bits de poids faible de AL en ASCII Hex
|
||||
; Entrée : AL (valeur 0-15)
|
||||
; Sortie : AL (caractère '0'-'9' ou 'A'-'F')
|
||||
; =============================================================================
|
||||
nibble_to_ascii:
|
||||
cmp al, 9
|
||||
ja .letter ; Si > 9, c'est une lettre (A-F)
|
||||
|
||||
add al, '0' ; Sinon c'est un chiffre : 0x0 -> '0'
|
||||
ret
|
||||
|
||||
.letter:
|
||||
add al, 'A' - 10 ; Convertit 10 -> 'A', 11 -> 'B', etc.
|
||||
ret
|
||||
127
src/common/debug_txt.asm
Normal file
127
src/common/debug_txt.asm
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
; =============================================================================
|
||||
; Project : Custom BIOS / ROM
|
||||
; File : debug.asm
|
||||
; Author : frater
|
||||
; Created : 06 jan 2026
|
||||
;
|
||||
; License : GNU General Public License v3.0 or later (GPL-3.0+)
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
;
|
||||
; =============================================================================
|
||||
|
||||
debug_puts:
|
||||
.next:
|
||||
push dx
|
||||
mov dx, DEBUG_PORT
|
||||
lodsb ; AL = *SI++
|
||||
test al, al
|
||||
jz .done
|
||||
out dx, al
|
||||
jmp .next
|
||||
.done:
|
||||
pop dx
|
||||
ret
|
||||
|
||||
debug_putc:
|
||||
push dx
|
||||
mov dx, DEBUG_PORT
|
||||
out dx, al
|
||||
pop dx
|
||||
ret
|
||||
|
||||
; AL = 0..15 -> print hex digit
|
||||
debug_puthex4:
|
||||
and al, 0Fh
|
||||
cmp al, 9
|
||||
jbe .num
|
||||
add al, 'A' - 10
|
||||
jmp .pout
|
||||
.num:
|
||||
add al, '0'
|
||||
.pout:
|
||||
call debug_putc
|
||||
ret
|
||||
|
||||
; AL = byte -> print 2 hex digits
|
||||
debug_puthex8:
|
||||
push ax
|
||||
mov ah, al
|
||||
shr al, 4
|
||||
call debug_puthex4
|
||||
mov al, ah
|
||||
call debug_puthex4
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; AX = word -> print 4 hex digits
|
||||
debug_puthex16:
|
||||
push ax
|
||||
mov al, ah
|
||||
call debug_puthex8
|
||||
pop ax
|
||||
call debug_puthex8
|
||||
ret
|
||||
|
||||
|
||||
; --- screen text functions ---
|
||||
; AH = page
|
||||
; DH = row
|
||||
; DL = column
|
||||
scr_gotoxy:
|
||||
mov ah, 02h
|
||||
mov bh, 0 ; page 0
|
||||
int 10h
|
||||
ret
|
||||
|
||||
scr_putc:
|
||||
mov ah, 0x0E
|
||||
int 10h
|
||||
ret
|
||||
|
||||
; AL = 0..15 -> print hex digit
|
||||
scr_puthex4:
|
||||
and al, 0Fh ; mask 4 bits low
|
||||
cmp al, 9 ; is it 0..9 ?
|
||||
jbe .num ; yes
|
||||
add al, 'A' - 10 ; convert to 'A'..'F'
|
||||
jmp .pout
|
||||
.num:
|
||||
add al, '0' ; convert to '0'..'9'
|
||||
.pout:
|
||||
mov ah, 0x0E
|
||||
int 10h
|
||||
ret
|
||||
|
||||
; AL = byte -> print 2 hex digits
|
||||
scr_puthex8:
|
||||
push ax
|
||||
push bx
|
||||
mov bl, al ; save al
|
||||
shr al, 4 ; 4 bits plus significatifs
|
||||
call scr_puthex4
|
||||
mov al, bl ; restore al
|
||||
call scr_puthex4
|
||||
pop bx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; AX = word -> print 4 hex digits
|
||||
scr_puthex16:
|
||||
push ax
|
||||
mov al, ah
|
||||
call scr_puthex8
|
||||
pop ax
|
||||
call scr_puthex8
|
||||
ret
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
; =============================================================================
|
||||
; Project : Custom BIOS / ROM
|
||||
; File : debug.asm
|
||||
; Author : frater
|
||||
; Created : 06 jan 2026
|
||||
;
|
||||
; License : GNU General Public License v3.0 or later (GPL-3.0+)
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
;
|
||||
; =============================================================================
|
||||
|
||||
debug_puts:
|
||||
.next:
|
||||
push dx
|
||||
mov dx, DEBUG_PORT
|
||||
lodsb ; AL = *SI++
|
||||
test al, al
|
||||
jz .done
|
||||
out dx, al
|
||||
jmp .next
|
||||
.done:
|
||||
pop dx
|
||||
ret
|
||||
|
||||
debug_putc:
|
||||
push dx
|
||||
mov dx, DEBUG_PORT
|
||||
out dx, al
|
||||
pop dx
|
||||
ret
|
||||
|
||||
; AL = 0..15 -> print hex digit
|
||||
debug_puthex4:
|
||||
and al, 0Fh
|
||||
cmp al, 9
|
||||
jbe .num
|
||||
add al, 'A' - 10
|
||||
jmp .pout
|
||||
.num:
|
||||
add al, '0'
|
||||
.pout:
|
||||
call debug_putc
|
||||
ret
|
||||
|
||||
; AL = byte -> print 2 hex digits
|
||||
debug_puthex8:
|
||||
push ax
|
||||
mov ah, al
|
||||
shr al, 4
|
||||
call debug_puthex4
|
||||
mov al, ah
|
||||
call debug_puthex4
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; AX = word -> print 4 hex digits
|
||||
debug_puthex16:
|
||||
push ax
|
||||
mov al, ah
|
||||
call debug_puthex8
|
||||
pop ax
|
||||
call debug_puthex8
|
||||
ret
|
||||
|
||||
|
||||
; --- screen text functions ---
|
||||
; AH = page
|
||||
; DH = row
|
||||
; DL = column
|
||||
scr_gotoxy:
|
||||
mov ah, 02h
|
||||
mov bh, 0 ; page 0
|
||||
int 10h
|
||||
ret
|
||||
|
||||
scr_putc:
|
||||
mov ah, 0x0E
|
||||
int 10h
|
||||
ret
|
||||
|
||||
; AL = 0..15 -> print hex digit
|
||||
scr_puthex4:
|
||||
and al, 0Fh ; mask 4 bits low
|
||||
cmp al, 9 ; is it 0..9 ?
|
||||
jbe .num ; yes
|
||||
add al, 'A' - 10 ; convert to 'A'..'F'
|
||||
jmp .pout
|
||||
.num:
|
||||
add al, '0' ; convert to '0'..'9'
|
||||
.pout:
|
||||
mov ah, 0x0E
|
||||
int 10h
|
||||
ret
|
||||
|
||||
; AL = byte -> print 2 hex digits
|
||||
scr_puthex8:
|
||||
push ax
|
||||
push bx
|
||||
mov bl, al ; save al
|
||||
shr al, 4 ; 4 bits plus significatifs
|
||||
call scr_puthex4
|
||||
mov al, bl ; restore al
|
||||
call scr_puthex4
|
||||
pop bx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; AX = word -> print 4 hex digits
|
||||
scr_puthex16:
|
||||
push ax
|
||||
mov al, ah
|
||||
call scr_puthex8
|
||||
pop ax
|
||||
call scr_puthex8
|
||||
ret
|
||||
|
|
@ -66,6 +66,9 @@ mouse_reset:
|
|||
|
||||
; experiemntal
|
||||
mov byte [fs:BDA_MOUSE + mouse.wheel],0
|
||||
|
||||
; debug
|
||||
mov byte [fs:BDA_MOUSE + mouse.blinker],0
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------
|
||||
|
|
@ -85,6 +88,7 @@ mouse_init:
|
|||
call ps2_wait_ready_write
|
||||
mov al, I8042_CMD_DIS_MOUSE ; Disable Mouse
|
||||
out i8042_PS2_CTRL, al
|
||||
|
||||
; Vider tout ce qui traîne
|
||||
call ps2_flush_output
|
||||
; Activer le port souris (AUX)
|
||||
|
|
@ -283,6 +287,8 @@ isr_mouse_handler:
|
|||
; lire un octet depuis le contrôleur et le stocker dans le buffer
|
||||
in al, i8042_PS2_DATA ; lire octet souris
|
||||
|
||||
inc byte [BDA_MOUSE + mouse.blinker]
|
||||
|
||||
movzx bx, byte [BDA_MOUSE + mouse.idx]
|
||||
mov byte [BDA_MOUSE + mouse.buffer + bx], al
|
||||
inc byte [BDA_MOUSE + mouse.idx]
|
||||
|
|
@ -323,6 +329,32 @@ isr_mouse_handler:
|
|||
.y_pos:
|
||||
sub [BDA_MOUSE + mouse.y], ax
|
||||
|
||||
; --- CLAMPING X ---
|
||||
; Check minimum (0)
|
||||
cmp word [fs:BDA_MOUSE + mouse.x], 0
|
||||
jge .check_x_max
|
||||
mov word [fs:BDA_MOUSE + mouse.x], 0
|
||||
jmp .done_x
|
||||
.check_x_max:
|
||||
; Check maximum (e.g., 639 for graphics, or pixel width)
|
||||
cmp word [fs:BDA_MOUSE + mouse.x], GFX_WIDTH-1 ; Replace with variable or define
|
||||
jle .done_x
|
||||
mov word [fs:BDA_MOUSE + mouse.x], GFX_WIDTH-1
|
||||
.done_x:
|
||||
|
||||
; --- CLAMPING Y ---
|
||||
; Check minimum (0)
|
||||
cmp word [fs:BDA_MOUSE + mouse.y], 0
|
||||
jge .check_y_max
|
||||
mov word [fs:BDA_MOUSE + mouse.y], 0
|
||||
jmp .done_y
|
||||
.check_y_max:
|
||||
; Check maximum
|
||||
cmp word [fs:BDA_MOUSE + mouse.y], GFX_HEIGHT-1 ; Replace with variable or define
|
||||
jle .done_y
|
||||
mov word [fs:BDA_MOUSE + mouse.y], GFX_HEIGHT-1
|
||||
.done_y:
|
||||
|
||||
; check si il y a un 4eme byte a traiter
|
||||
mov al, [BDA_MOUSE + mouse.packetlen]
|
||||
cmp al,4
|
||||
|
|
|
|||
Loading…
Reference in a new issue