diff --git a/src/bda.asm b/src/bda.asm
index 3d452b8..95729d1 100644
--- a/src/bda.asm
+++ b/src/bda.asm
@@ -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
diff --git a/src/boot.asm b/src/boot.asm
index bf8c84b..25dd99e 100644
--- a/src/boot.asm
+++ b/src/boot.asm
@@ -20,158 +20,178 @@
;
; =============================================================================
-bits 16
+ bits 16
; ---------------------------------------------------------------------------
;
; configuration du bios
;
; ---------------------------------------------------------------------------
-%define DEBUG_PORT 0xe9 ; 0x402 ou 0xe9
+%define DEBUG_PORT 0xe9 ; 0x402 ou 0xe9
; initial stack
-%define STACK_SEG 0x0800 ; segment de base
+%define STACK_SEG 0x0800 ; segment de base
+
+;section .text
+; bits 16
+;
+; db 'EXTRA CODE Section',0
+;
+; times 0xFFFF - ($ - $$) db 0xFF
section .text
bits 16
-;%include "./common/chartable.asm"
-;%include "./common/cursor.asm"
+;%include "./common/chartable.asm"
+;%include "./common/cursor.asm"
; definition du BDA
-%include "./bda.asm"
+%include "./bda.asm"
-; %include "./services/macros.asm"
-%include "./drivers/debug.asm"
-%include "./drivers/gfx_cgam.asm"
-%include "./drivers/mouse_ps2.asm"
-%include "./drivers/keyboard_ps2.asm"
-%include "./services/generic.asm"
+; %include "./services/macros.asm"
+%include "./common/debug_cga.asm"
+%include "./drivers/gfx_cgam.asm"
+%include "./drivers/mouse_ps2.asm"
+%include "./drivers/keyboard_ps2.asm"
+%include "./services/generic.asm"
-err_vganok db 'VGA Not Initialized',0
+err_vganok db 'VGA Not Initialized',0
-cpt_txt db '0123456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789',0
-helloworld db 'Hello World !',0
-centre db 'TEXTEAUCENTR',0
+cpt_txt db '0123456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789',0
+helloworld db 'Hello World !',0
+centre db 'TEXTEAUCENTR',0
reset:
- cli
- ; il n'existe aucun 'stack' par défaut
- mov ax, STACK_SEG
- mov ss, ax
- mov sp, 0xFFFE ; haut du segment (64ko de stack), mot-aligné
- cld
+ cli
+ ; il n'existe aucun 'stack' par défaut
+ mov ax, STACK_SEG
+ mov ss, ax
+ mov sp, 0xFFFE ; haut du segment (64ko de stack), mot-aligné
+ cld
- ; installé une table d'interruption "dummy"
- call ivt_setup
- call bda_setup
+ ; installé une table d'interruption "dummy"
+ call ivt_setup
+ call bda_setup
- ; Install IRQ 0 : timer_isr
- mov ax,cs
- mov dx,ax
- mov bx,timer_isr
- mov ax,i8259_MASTER_INT
+ ; Install IRQ 0 : timer_isr
+ mov ax,cs
+ mov dx,ax
+ mov bx,timer_isr
+ mov ax,i8259_MASTER_INT
- call ivt_setvector
+ call ivt_setvector
- ; initialisation des PIC 8259A
- call pic_init
+ ; initialisation des PIC 8259A
+ call pic_init
- ; load Roms
- call setup_load_rom
+ ; load Roms
+ call setup_load_rom
- ; on vérifie que le BIOS VGA a installé une INT 10h
- call setup_check_vga
+ ; 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
+ call pic_set_irq_mask
- ; enable IRQ 0
- mov ah,IRQ_ENABLED
- mov al,0
- call pic_set_irq_mask
+ call kbd_init
+ sti
- call kbd_init
- sti
+ ; on active le mode graphique
+ GFX_DRV GFX_INIT
- ; on active le mode graphique
- GFX_DRV GFX_INIT
+ mov cx, 300
+ mov dx, 102
+ GFX_DRV GFX_GOTOXY
- mov cx, 300
- mov dx, 102
- GFX_DRV GFX_GOTOXY
+ GFX_SET_WRTIE_MODE GFX_TXT_WHITE_TRANSPARENT
- GFX_SET_WRTIE_MODE GFX_TXT_WHITE_TRANSPARENT
+ push cs
+ pop ds
+ mov si, centre
+ GFX_DRV GFX_WRITE
- push cs
- pop ds
- mov si, centre
- GFX_DRV GFX_WRITE
+ ; call mouse_reset
+ call mouse_init
- ; call mouse_reset
- call mouse_init
+ GFX_DRV GFX_CRS_UPDATE
- GFX_DRV GFX_CRS_UPDATE
+ GFX_SET_WRTIE_MODE GFX_TXT_BLACK_ON_WHITE
- GFX_SET_WRTIE_MODE GFX_TXT_BLACK_ON_WHITE
+ xor cx,cx
+ mov dx,0
+ GFX_DRV GFX_GOTOXY
- xor cx,cx
- mov dx,0
- GFX_DRV GFX_GOTOXY
+ push cs
+ pop ds
+ mov si, cpt_txt
+ GFX_DRV GFX_WRITE
- push cs
- pop ds
- mov si, cpt_txt
- GFX_DRV GFX_WRITE
+ GFX_SET_WRTIE_MODE GFX_TXT_WHITE_TRANSPARENT
- GFX_SET_WRTIE_MODE GFX_TXT_WHITE_TRANSPARENT
+ mov cx,8
+ mov dx,8
+ GFX_DRV GFX_GOTOXY
- mov cx,8
- mov dx,8
- GFX_DRV GFX_GOTOXY
+ mov si, helloworld
+ GFX_DRV GFX_WRITE
- mov si, helloworld
- GFX_DRV GFX_WRITE
-
- mov cx,8
- mov dx,24
-
- GFX_SET_WRTIE_MODE 0
+ mov cx,8
+ mov dx,24
+ GFX_SET_WRTIE_MODE 0
.loopshift:
- GFX_DRV GFX_GOTOXY
- mov si, helloworld
- GFX_DRV GFX_WRITE
- add dx,8
- inc cx
- cmp cx,16
- jbe .loopshift
+ GFX_DRV GFX_GOTOXY
+ mov si, helloworld
+ GFX_DRV GFX_WRITE
+ add dx,8
+ inc cx
+ cmp cx,16
+ jbe .loopshift
+ mov ax,BDA_DATA_SEG
+ mov ds,ax
endless:
- mov ax,BDA_DATA_SEG
- mov ds,ax
- mov ax,0
+ xor cx,cx
+ mov dx,180
+ GFX_DRV GFX_GOTOXY
- jmp endless
+ 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
; -----------------------------------------------------------
; timer ISR (IRQ -> INT)
; -----------------------------------------------------------
timer_isr:
- push ax
+ push ax
- push fs
- mov ax,BDA_DATA_SEG
- mov fs,ax
+ push fs
+ mov ax,BDA_DATA_SEG
+ mov fs,ax
; inc byte [fs:BDA_TIMER]
- mov al, PIC_EOI ; EOI master
- out i8259_MASTER_CMD, al
- pop fs
+ mov al, PIC_EOI ; EOI master
+ out i8259_MASTER_CMD, al
+ pop fs
- pop ax
- iret
+ pop ax
+ iret
; ------------------------------------------------------------------
; Padding jusqu'au reset vector
@@ -181,16 +201,16 @@ times 0xFFF0 - ($ - $$) db 0xFF
; ------------------------------------------------------------------
; RESET VECTOR (exécuté par le CPU)
; ------------------------------------------------------------------
-section .resetvect
+section .resetvect
bits 16
-global reset_vector
+global reset_vector
reset_vector:
- ; code minimal au reset
- jmp 0xF000:reset
+ ; code minimal au reset
+ jmp 0xF000:reset
builddate:
- db '06/01/2026'
- times 16-($-$$) db 0 ; le stub tient dans 16 octets (ou moins)
+ db '06/01/2026'
+ times 16-($-$$) db 0 ; le stub tient dans 16 octets (ou moins)
diff --git a/src/common/debug_cga.asm b/src/common/debug_cga.asm
new file mode 100644
index 0000000..e67c499
--- /dev/null
+++ b/src/common/debug_cga.asm
@@ -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 .
+;
+; =============================================================================
+
+; =============================================================================
+; 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
\ No newline at end of file
diff --git a/src/common/debug_txt.asm b/src/common/debug_txt.asm
new file mode 100644
index 0000000..1999bd5
--- /dev/null
+++ b/src/common/debug_txt.asm
@@ -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 .
+;
+; =============================================================================
+
+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
diff --git a/src/drivers/debug.asm b/src/drivers/debug.asm
deleted file mode 100644
index 87fe27b..0000000
--- a/src/drivers/debug.asm
+++ /dev/null
@@ -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 .
-;
-; =============================================================================
-
-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
diff --git a/src/drivers/mouse_ps2.asm b/src/drivers/mouse_ps2.asm
index 8e4bb2c..b3b60df 100644
--- a/src/drivers/mouse_ps2.asm
+++ b/src/drivers/mouse_ps2.asm
@@ -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