Mouse interrupt handler + debug

This commit is contained in:
Frater 2026-01-29 13:46:35 +01:00
commit 4cf1a0b7a2
6 changed files with 389 additions and 235 deletions

View file

@ -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

View file

@ -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