From 36e72bb3992706daec9902243ea653d204dd1822 Mon Sep 17 00:00:00 2001
From: Frater <13979047+saintfrater@users.noreply.github.com>
Date: Sun, 22 Feb 2026 23:52:33 +0100
Subject: [PATCH] widget bug fixing
---
src/boot-cga.asm | 274 ---------------------------------------
src/boot-vga.asm | 280 ----------------------------------------
src/boot.asm | 262 ++++++++++++++++++++++++++++++++++++-
src/common/bda.asm | 4 +-
src/common/string.asm | 8 +-
src/drivers/gfx_vga.asm | 69 +++++-----
src/gui/lib-api.asm | 96 +++++++++-----
src/gui/lib-draw.asm | 7 +-
src/gui/lib-logic.asm | 6 +-
9 files changed, 376 insertions(+), 630 deletions(-)
delete mode 100644 src/boot-cga.asm
delete mode 100644 src/boot-vga.asm
diff --git a/src/boot-cga.asm b/src/boot-cga.asm
deleted file mode 100644
index 5ada805..0000000
--- a/src/boot-cga.asm
+++ /dev/null
@@ -1,274 +0,0 @@
-; =============================================================================
-; Project : Custom BIOS / ROM
-; File : boot.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 .
-;
-; =============================================================================
-
- bits 16
-; ---------------------------------------------------------------------------
-;
-; configuration du bios
-;
-; ---------------------------------------------------------------------------
-
-; initial stack
-%define STACK_SEG 0x0800 ; segment de base
-%define GFX_DRIVERS 'CGA'
-
-section .text
- bits 16
-
-%include "./common/chartable.asm"
-%include "./common/cursor.asm"
-%include "./common/patterns.asm"
-%include "./common/generic.asm"
-%include "./common/string.asm"
-
-; definition du BDA
-%include "./common/bda.asm"
-
-; drivers
-%if GFX_DRIVERS == 'VGA'
- %include "./drivers/gfx_vga.asm"
-%else
- ; default drivers
- %include "./drivers/gfx_cgam.asm"
-%endif
-
-%include "./drivers/mouse_ps2.asm"
-%include "./drivers/keyboard_ps2.asm"
-
-%include "./common/debug_gfx.asm"
-
-; GUI
-%include "./gui/lib-api.asm"
-
-; --- Données texte ---
-str_quit db "Quitter", 0
-str_hello db "Hello", 0
-str_option1 db "option 1", 0
-str_option2 db "option 2", 0
-str_option3 db "option 3", 0
-
-entrycode:
- cli
- mov ax, STACK_SEG ; creation du stack par défaut
- mov ss, ax
- mov sp, 0xFFFE ; haut du segment (64ko de stack), mot-aligné
- cld
-
- call ivt_setup ; configuration d'une table d'interruption "dummy"
- call bda_setup ; initialisation du BDA
-
- ISADBG ISA_GREEN, 0x01
-
- ; Install IRQ 0 : timer_isr
- mov ax,cs
- mov dx,ax
- mov bx,timer_isr
- mov ax,i8259_MASTER_INT
-
- call ivt_setvector
-
- ISADBG ISA_GREEN, 0x02
-
- ; initialisation des PIC 8259A
- call pic_init
-
- ISADBG ISA_GREEN, 0x04
-
- ; load Roms
- call setup_load_rom
-
- ISADBG ISA_GREEN, 0x08
-
- ; on vérifie que le BIOS VGA a installé une INT 10h
- call setup_check_vga
-
- ISADBG ISA_GREEN, 0x10
-
- ; enable IRQ 0
- mov ah,IRQ_ENABLED
- mov al,0
- call pic_set_irq_mask
-
- call kbd_init
- sti
-
- DEBUG 0xFADE
- ISADBG ISA_GREEN, 0x20
-
- ; on active le mode graphique
- GFX INIT
- ISADBG ISA_GREEN, 0xFF
-
- ; call mouse_reset
- call mouse_init
-
- GFX MOUSE_MOVE
- GFX MOUSE_SHOW
-
- ISADBG ISA_RED, 0x81
-
- xor ax,ax
-
- .loops:
- call main_loop
-
- nop
- jmp .loops
-
-; --- Callbacks (Fonctions appelées par le moteur) ---
-on_click_quit:
- hlt
- jmp on_click_quit
- ret
-
-on_click_hello:
- ret
-
-%define .oldval word [bp-2]
-%define .my_slider word [bp-4]
-%define .value word [bp-6]
-main_loop:
- push bp
- mov bp, sp
- sub sp, 6
-
- push cs
- pop ds
-
- DEBUG 1
- ISADBG ISA_LEFT, 1
-
- ; Init du système GUI
- call gui_init_system
- DEBUG 2
- ISADBG ISA_LEFT, 2
-
- ; --- CRÉATION DYNAMIQUE DES BOUTONS ---
-
- ; Créer Bouton 1 "QUITTER"
- GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 10, 10, 80, 16
- GUI OBJ_SET_TEXT, ax, cs, str_quit
- ; Créer Bouton 2 "HELLO"
- GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 100, 50, 80, 16
- GUI OBJ_SET_TEXT, ax, cs, str_hello
-
- ; Créer 3 checkbox "option"
- GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50, 100, 15
- GUI OBJ_SET_TEXT, ax, cs, str_option1
-
- GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16, 100, 15
- GUI OBJ_SET_TEXT, ax, cs, str_option2
-
- GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16*2, 100, 15
- GUI OBJ_SET_TEXT, ax, cs, str_option3
-
- DEBUG 3
- ISADBG ISA_LEFT, 3
-
- ; Créer Slider (Drag)
- GUI OBJ_CREATE, OBJ_TYPE_SLIDER, 10, 100, 150, 12
- GUI OBJ_SET_MODE, ax, SLIDER_HORIZONTAL
- GUI OBJ_SLIDER_SET_ATTR, ax, 10, 140, 10, 15
-
- GUI OBJ_CREATE, OBJ_TYPE_SLIDER, 400, 10, 16, 150
- mov .my_slider, ax
-
- GUI OBJ_SET_MODE, .my_slider, SLIDER_VERTICAL
- GUI OBJ_SLIDER_SET_ATTR, .my_slider, 0, 31, 0, 12
-
- mov .oldval, 0x1256
- mov .value, 0xFADE
-
- DEBUG 4
- ISADBG ISA_LEFT, 4
-
- .loop:
- call gui_process_all
- GUI OBJ_GET_VAL, .my_slider
- mov .value, ax
-
- cmp ax,.oldval
- je .loop
-
- ; debug
- mov .oldval, ax
- GFX RECTANGLE_FILL,0,148,50,166, PATTERN_WHITE
- GFX GOTOXY, 8, 150
-
- mov ax, .value
- call print_word_hex
- ; end debug
-
- ; change palette...
- ;and ax, 0x00FF
- ;mov bh, 0x00
- ;mov bl, al
- ;mov ah, 0x0b
- ;mov al, 0x00
- ;int 0x10
-
- mov dx, CRTC_COLOR_DATA
- and ax, 0x001F
- out dx, ax
-
- jmp .loop
- leave
- ret
-
-; -----------------------------------------------------------
-; timer ISR (IRQ -> INT)
-; -----------------------------------------------------------
-timer_isr:
- push ax
-
- push fs
- mov ax,SEG_BDA_CUSTOM
- mov fs,ax
-; exemple de fonctionnement:
-; inc byte [fs:BDA_TIMER]
-
- mov al, PIC_EOI ; EOI master
- out i8259_MASTER_CMD, al
- pop fs
-
- pop ax
- iret
-
-; ------------------------------------------------------------------
-; Padding jusqu'au reset vector
-; ------------------------------------------------------------------
-times 0xFFF0 - ($ - $$) db 0xFF
-
-; ------------------------------------------------------------------
-; RESET VECTOR (exécuté par le CPU)
-; ------------------------------------------------------------------
-section .resetvect
-bits 16
-global reset_vector
-
-reset_vector:
- ; code minimal au reset
- jmp 0xF000:entrycode
-
-builddate:
- db __DATE__
- times 16-($-$$) db 0 ; le stub tient dans 16 octets (ou moins)
diff --git a/src/boot-vga.asm b/src/boot-vga.asm
deleted file mode 100644
index 510d45c..0000000
--- a/src/boot-vga.asm
+++ /dev/null
@@ -1,280 +0,0 @@
-; =============================================================================
-; Project : Custom BIOS / ROM
-; File : boot.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 .
-;
-; =============================================================================
-
- bits 16
-; ---------------------------------------------------------------------------
-;
-; configuration du bios
-;
-; ---------------------------------------------------------------------------
-
-; initial stack
-%define STACK_SEG 0x0800 ; segment de base
-%define GFX_DRIVERS 'VGA'
-
-%define DEBUGER_ENABLED
-
-section .text
- bits 16
-
-%include "./common/chartable.asm"
-%include "./common/cursor.asm"
-%include "./common/patterns.asm"
-%include "./common/generic.asm"
-%include "./common/string.asm"
-
-; definition du BDA
-%include "./common/bda.asm"
-
-; drivers
-%if GFX_DRIVERS == 'VGA'
- %include "./drivers/gfx_vga.asm"
-%else
- ; default drivers
- %include "./drivers/gfx_cgam.asm"
-%endif
-
-%include "./drivers/mouse_ps2.asm"
-%include "./drivers/keyboard_ps2.asm"
-
-%include "./common/debug_gfx.asm"
-%include "./common/debug_txt.asm"
-
-; GUI
-%include "./gui/lib-api.asm"
-
-; --- Données texte ---
-str_quit db "Quitter", 0
-str_hello db "Hello", 0
-str_option1 db "option 1", 0
-str_option2 db "option 2", 0
-str_option3 db "option 3", 0
-
-entrycode:
- cli
- mov ax, STACK_SEG ; creation du stack par défaut
- mov ss, ax
- mov sp, 0xFFFE ; haut du segment (64ko de stack), mot-aligné
- cld
-
- call ivt_setup ; configuration d'une table d'interruption "dummy"
- call bda_setup ; initialisation du BDA
-
- ISADBG ISA_GREEN, 1
-
- ; Install IRQ 0 : timer_isr
- mov ax,cs
- mov dx,ax
- mov bx,timer_isr
- mov ax,i8259_MASTER_INT
-
- call ivt_setvector
- ; initialisation des PIC 8259A
- call pic_init
- ; load Roms
- call setup_load_rom
- ; on vérifie que le BIOS VGA a installé une INT 10h
- call setup_check_vga
- ; enable IRQ 0
- mov ah,IRQ_ENABLED
- mov al,0
- call pic_set_irq_mask
-
- call kbd_init
- sti
- ; on active le mode graphique
- GFX INIT
- call mouse_init
- GFX MOUSE_SHOW
-
-
- call main_loop
- .loops:
- hlt
- jmp .loops
-
-; --- Callbacks (Fonctions appelées par le moteur) ---
-on_click_quit:
- hlt
- jmp on_click_quit
- ret
-
-on_click_hello:
- ret
-
-
-main_test:
- ; GFX RECTANGLE_FILL, 10,10,50,20, PATTERN_WHITE, 15, 0
-
-
-
- ; GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50, 100, 15
- mov ax, 200
- add ax, 4
- mov bx, 50
-
- ; centrage vertical
- mov cx, 15
- sub cx, GUI_CHECKBOX_SIZE
- shr cx, 1
- add bx, cx ; bx = Y1 + (h/2)
-
- mov cx, ax ; x
- add cx, GUI_CHECKBOX_SIZE ; cx = X2
-
- mov dx, bx
- add dx, GUI_CHECKBOX_SIZE ; Y2
-
- ; Fond blanc + Bordure noire
- GFX RECTANGLE_FILL, ax, bx, cx, dx, PATTERN_WHITE, 15, 0
- GFX RECTANGLE, ax, bx, cx, dx, 0
-
-; Dessin du X (Diagonales)
- add ax, 2 ; x1
- add bx, 2 ; y1
- sub cx, 2 ; x2
- sub dx, 2 ; y2
- ; Optimisation : Utilisation de LINE au lieu de PUTPIXEL en boucle
- ; Diagonale 1 : (ax, bx) -> (cx, dx)
- GFX LINE, ax, bx, cx, dx, 0
- ; Diagonale 2 : (ax, dx) -> (cx, bx)
- GFX LINE, ax, dx, cx, bx, 0
-
- ret
-
-%define .oldval word [bp-2]
-%define .my_slider word [bp-4]
-%define .value word [bp-6]
-main_loop:
- push bp
- mov bp, sp
- sub sp, 6
-
- push cs
- pop ds
- ; Init du système GUI
- call gui_init_system
-
- ; --- CRÉATION DYNAMIQUE DES BOUTONS ---
-
- ; Créer Bouton 1 "QUITTER"
- GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 10, 10, 80, 16
- GUI OBJ_SET_TEXT, ax, cs, str_quit
- ; Créer Bouton 2 "HELLO"
- GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 100, 50, 80, 16
- GUI OBJ_SET_TEXT, ax, cs, str_hello
-
- ; Créer 3 checkbox "option"
- GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50, 100, 15
- GUI OBJ_SET_TEXT, ax, cs, str_option1
-
- GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16, 100, 15
- GUI OBJ_SET_TEXT, ax, cs, str_option2
-
- GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16*2, 100, 15
- GUI OBJ_SET_TEXT, ax, cs, str_option3
-
- ; Créer Slider (Drag)
- GUI OBJ_CREATE, OBJ_TYPE_SLIDER, 10, 100, 150, 12
- GUI OBJ_SET_MODE, ax, SLIDER_HORIZONTAL
- GUI OBJ_SLIDER_SET_ATTR, ax, 10, 140, 10, 15
-
- GUI OBJ_CREATE, OBJ_TYPE_SLIDER, 400, 10, 16, 150
- mov .my_slider, ax
-
- GUI OBJ_SET_MODE, .my_slider, SLIDER_VERTICAL
- GUI OBJ_SLIDER_SET_ATTR, .my_slider, 0, 31, 0, 12
-
- mov .oldval, 0x1256
- mov .value, 0xFADE
-
- .loop:
- call gui_process_all
- GUI OBJ_GET_VAL, .my_slider
- mov .value, ax
-
- cmp ax,.oldval
- je .loop
-
- ; debug
- ;mov .oldval, ax
- ;GFX RECTANGLE_FILL,0,148,50,166, PATTERN_WHITE
- ;GFX GOTOXY, 8, 150
-
- ;mov ax, .value
- ;call print_word_hex
- ; end debug
-
- ; change palette...
- ;and ax, 0x00FF
- ;mov bh, 0x00
- ;mov bl, al
- ;mov ah, 0x0b
- ;mov al, 0x00
- ;int 0x10
-
- mov dx, CRTC_COLOR_DATA
- and ax, 0x001F
- out dx, ax
-
- jmp .loop
- leave
- ret
-
-; -----------------------------------------------------------
-; timer ISR (IRQ -> INT)
-; -----------------------------------------------------------
-timer_isr:
- push ax
-
- push fs
- mov ax,SEG_BDA_CUSTOM
- mov fs,ax
- ; exemple de fonctionnement:
- ; inc byte [fs:BDA_TIMER]
-
- mov al, PIC_EOI ; EOI master
- out i8259_MASTER_CMD, al
- pop fs
-
- pop ax
- iret
-
-; ------------------------------------------------------------------
-; Padding jusqu'au reset vector
-; ------------------------------------------------------------------
-times 0xFFF0 - ($ - $$) db 0xFF
-
-; ------------------------------------------------------------------
-; RESET VECTOR (exécuté par le CPU)
-; ------------------------------------------------------------------
-section .resetvect
-bits 16
-global reset_vector
-
-reset_vector:
- ; code minimal au reset
- jmp 0xF000:entrycode
-
-builddate:
- db __DATE__
- times 16-($-$$) db 0 ; le stub tient dans 16 octets (ou moins)
diff --git a/src/boot.asm b/src/boot.asm
index 2698dd9..4e197d7 100644
--- a/src/boot.asm
+++ b/src/boot.asm
@@ -19,4 +19,264 @@
; along with this program. If not, see .
;
; =============================================================================
-%include "./boot-vga.asm"
+
+ bits 16
+; ---------------------------------------------------------------------------
+;
+; configuration du bios
+;
+; ---------------------------------------------------------------------------
+
+; initial stack
+%define STACK_SEG 0x0800 ; segment de base
+
+; pilote graphique de base: CGA, VGA
+%define GFX_DRIVERS 'VGA'
+
+%define DEBUGER_ENABLED
+
+section .text
+ bits 16
+
+%include "./common/chartable.asm"
+%include "./common/cursor.asm"
+%include "./common/patterns.asm"
+%include "./common/generic.asm"
+%include "./common/string.asm"
+
+; definition du BDA
+%include "./common/bda.asm"
+
+; drivers
+%if GFX_DRIVERS == 'VGA'
+ %include "./drivers/gfx_vga.asm"
+%else
+ ; default drivers
+ %include "./drivers/gfx_cgam.asm"
+%endif
+
+%include "./drivers/mouse_ps2.asm"
+%include "./drivers/keyboard_ps2.asm"
+
+%include "./common/debug_gfx.asm"
+%include "./common/debug_txt.asm"
+
+; GUI
+%include "./gui/lib-api.asm"
+
+; --- Données texte ---
+str_quit db "Quitter", 0
+str_hello db "Hello", 0
+str_option1 db "option 1", 0
+str_option2 db "option 2", 0
+str_option3 db "option 3", 0
+
+entrycode:
+ cli
+ mov ax, STACK_SEG ; creation du stack par défaut
+ mov ss, ax
+ mov sp, 0xFFFE ; haut du segment (64ko de stack), mot-aligné
+ cld
+
+ call ivt_setup ; configuration d'une table d'interruption "dummy"
+ call bda_setup ; initialisation du BDA
+
+ ISADBG ISA_GREEN, 1
+
+ ; Install IRQ 0 : timer_isr
+ mov ax,cs
+ mov dx,ax
+ mov bx,timer_isr
+ mov ax,i8259_MASTER_INT
+
+ call ivt_setvector
+ ; initialisation des PIC 8259A
+ call pic_init
+ ; load Roms
+ call setup_load_rom
+ ; on vérifie que le BIOS VGA a installé une INT 10h
+ call setup_check_vga
+ ; enable IRQ 0
+ mov ah,IRQ_ENABLED
+ mov al,0
+ call pic_set_irq_mask
+
+ call kbd_init
+ sti
+ ; on active le mode graphique
+ GFX INIT
+ call mouse_init
+ GFX MOUSE_SHOW
+
+
+ call main_loop
+ .loops:
+ hlt
+ jmp .loops
+
+; --- Callbacks (Fonctions appelées par le moteur) ---
+on_click_quit:
+ hlt
+ jmp on_click_quit
+ ret
+
+on_click_hello:
+ ret
+
+
+main_test:
+ ; GFX RECTANGLE_FILL, 10,10,50,20, PATTERN_WHITE, 15, 0
+
+
+
+ ; GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50, 100, 15
+ mov ax, 200
+ add ax, 4
+ mov bx, 50
+
+ ; centrage vertical
+ mov cx, 15
+ sub cx, GUI_CHECKBOX_SIZE
+ shr cx, 1
+ add bx, cx ; bx = Y1 + (h/2)
+
+ mov cx, ax ; x
+ add cx, GUI_CHECKBOX_SIZE ; cx = X2
+
+ mov dx, bx
+ add dx, GUI_CHECKBOX_SIZE ; Y2
+
+ ; Fond blanc + Bordure noire
+ GFX RECTANGLE_FILL, ax, bx, cx, dx, PATTERN_WHITE, 15, 0
+ GFX RECTANGLE, ax, bx, cx, dx, 0
+
+; Dessin du X (Diagonales)
+ add ax, 2 ; x1
+ add bx, 2 ; y1
+ sub cx, 2 ; x2
+ sub dx, 2 ; y2
+ ; Optimisation : Utilisation de LINE au lieu de PUTPIXEL en boucle
+ ; Diagonale 1 : (ax, bx) -> (cx, dx)
+ GFX LINE, ax, bx, cx, dx, 0
+ ; Diagonale 2 : (ax, dx) -> (cx, bx)
+ GFX LINE, ax, dx, cx, bx, 0
+
+ ret
+
+%define .oldval word [bp-2]
+%define .my_slider word [bp-4]
+%define .value word [bp-6]
+main_loop:
+ push bp
+ mov bp, sp
+ sub sp, 6
+
+ push cs
+ pop ds
+ ; Init du système GUI
+ call gui_init_system
+
+ ; --- CRÉATION DYNAMIQUE DES BOUTONS ---
+
+ ; Créer Bouton 1 "QUITTER"
+ GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 10, 10, 80, 16
+ GUI OBJ_SET_TEXT, ax, cs, str_quit
+ ; Créer Bouton 2 "HELLO"
+ GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 100, 50, 80, 16
+ GUI OBJ_SET_TEXT, ax, cs, str_hello
+
+ ; Créer 3 checkbox "option"
+ GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50, 100, 15
+ GUI OBJ_SET_TEXT, ax, cs, str_option1
+
+ GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16, 100, 15
+ GUI OBJ_SET_TEXT, ax, cs, str_option2
+
+ GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16*2, 100, 15
+ GUI OBJ_SET_TEXT, ax, cs, str_option3
+
+ ; Créer Slider (Drag)
+ GUI OBJ_CREATE, OBJ_TYPE_SLIDER, 10, 100, 150, 12
+ GUI OBJ_SET_MODE, ax, SLIDER_HORIZONTAL
+ GUI OBJ_SLIDER_SET_ATTR, ax, 10, 140, 10, 15
+
+ GUI OBJ_CREATE, OBJ_TYPE_SLIDER, 400, 10, 16, 150
+ mov .my_slider, ax
+
+ GUI OBJ_SET_MODE, .my_slider, SLIDER_VERTICAL
+ GUI OBJ_SLIDER_SET_ATTR, .my_slider, 0, 31, 0, 12
+
+ mov .oldval, 0x1256
+ mov .value, 0xFADE
+
+ .loop:
+ call gui_process_all
+ GUI OBJ_GET_VAL, .my_slider
+ mov .value, ax
+
+ cmp ax,.oldval
+ je .loop
+
+ ; debug
+ ;mov .oldval, ax
+ ;GFX RECTANGLE_FILL,0,148,50,166, PATTERN_WHITE
+ ;GFX GOTOXY, 8, 150
+
+ ;mov ax, .value
+ ;call print_word_hex
+ ; end debug
+
+ ; change palette...
+ ;and ax, 0x00FF
+ ;mov bh, 0x00
+ ;mov bl, al
+ ;mov ah, 0x0b
+ ;mov al, 0x00
+ ;int 0x10
+
+ mov dx, CRTC_COLOR_DATA
+ and ax, 0x001F
+ out dx, ax
+
+ jmp .loop
+ leave
+ ret
+
+; -----------------------------------------------------------
+; timer ISR (IRQ -> INT)
+; -----------------------------------------------------------
+timer_isr:
+ push ax
+
+ push fs
+ mov ax,SEG_BDA_CUSTOM
+ mov fs,ax
+ ; exemple de fonctionnement:
+ ; inc byte [fs:BDA_TIMER]
+
+ mov al, PIC_EOI ; EOI master
+ out i8259_MASTER_CMD, al
+ pop fs
+
+ pop ax
+ iret
+
+; ------------------------------------------------------------------
+; Padding jusqu'au reset vector
+; ------------------------------------------------------------------
+times 0xFFF0 - ($ - $$) db 0xFF
+
+; ------------------------------------------------------------------
+; RESET VECTOR (exécuté par le CPU)
+; ------------------------------------------------------------------
+section .resetvect
+bits 16
+global reset_vector
+
+reset_vector:
+ ; code minimal au reset
+ jmp 0xF000:entrycode
+
+builddate:
+ db __DATE__
+ times 16-($-$$) db 0 ; le stub tient dans 16 octets (ou moins)
diff --git a/src/common/bda.asm b/src/common/bda.asm
index b08a4e8..68aa575 100644
--- a/src/common/bda.asm
+++ b/src/common/bda.asm
@@ -24,9 +24,9 @@
; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/informations/bios_data_area
;
-%define BDA_SEGMENT 0x0040 ; segment BDA (historically)
+%define SEG_BDA 0x0040 ; segment BDA (historically)
%define SEG_BDA_CUSTOM 0x0050 ; custom data (mouse, gfx cursor, etc..)
-%define BDA_GUI_WIDGET 0x0070 ; Segment de données UI (Safe: après Stack, avant Heap)
+%define SEG_GUI 0x0070 ; Segment de données UI (Safe: après Stack, avant Heap)
%define PTR_MOUSE 0x0000
%define PTR_GFX (PTR_MOUSE + mouse_size)
diff --git a/src/common/string.asm b/src/common/string.asm
index 74b4474..2187277 100644
--- a/src/common/string.asm
+++ b/src/common/string.asm
@@ -39,20 +39,20 @@ strcpy:
%undef .src_seg
%undef .src_ofs
-
; -----------------------------------------------------------------------------
; strlen
; Calcule la longueur d'une chaine [es:di]
-; Out: CX = Length
+; Out: AX = Length
; -----------------------------------------------------------------------------
%define .str_seg word [bp+4]
%define .str_ofs word [bp+6]
strlen:
push bp
mov bp, sp
- push ax
+ push ax
push es
push di
+
xor cx, cx
mov ax, .str_seg
mov es, ax
@@ -68,7 +68,7 @@ strlen:
.done:
pop di
pop es
- pop ax
+ pop ax
leave
ret
%undef .str_seg
diff --git a/src/drivers/gfx_vga.asm b/src/drivers/gfx_vga.asm
index a10a7a2..67a8f1b 100644
--- a/src/drivers/gfx_vga.asm
+++ b/src/drivers/gfx_vga.asm
@@ -121,8 +121,6 @@ themes:
db 0,4,12,15 ; HELL
db 0,3,11,15 ; Hi Sky
-
-
; ------------------------------------------------------------
; dummy function
;
@@ -151,6 +149,7 @@ vga_init:
PATTERN_PTR PATTERN_GRAY_LIGHT
mov bl, 15
call vga_background
+
ret
; ------------------------------------------------------------
@@ -289,8 +288,9 @@ vga_set_writemode:
pop ax
pop fs
leave
- ret
%undef .mode
+ ret
+
; ---------------------------------------------------------------------------
; gfx_set_charpos (x,y)
@@ -330,10 +330,10 @@ vga_set_charpos:
popa
leave
- ret
; clean defs
%undef .x
%undef .y
+ ret
; ---------------------------------------------------------------------------
; vga_putc_unalign (car)
@@ -472,10 +472,10 @@ vga_putc:
pop gs
popa
leave
- ret
; clean defs
%undef .cpt
%undef .glyph_row
+ ret
; ---------------------------------------------------------------------------
; write string from [DS:SI] to screen
@@ -499,16 +499,16 @@ vga_write:
je .done
push ax
call vga_putc
- ; pop ax
+ pop ax
jmp .loops
.done:
pop ds
pop ax
leave
- ret
%undef .txt_seg
%undef .txt_ofs
+ ret
; ------------------------------------------------------------
; vga_line (x1, y1, x2, y2, color)
@@ -577,13 +577,13 @@ vga_line:
call vga_mouse_show
popa
leave
- ret
; clean defs
%undef .x1
%undef .y1
%undef .x2
%undef .y2
%undef .color
+ ret
%ifdef ____CLASSIC_LINE_____
; ------------------------------------------------------------
@@ -709,7 +709,7 @@ vga_line_bresenham:
pop es
popa
leave
- ret
+ ; clean defs
%undef .x1
%undef .y1
%undef .x2
@@ -721,7 +721,7 @@ vga_line_bresenham:
%undef _sy
%undef _err
%undef _e2
- ; clean defs
+ ret
%endif
; ------------------------------------------------------------
@@ -902,7 +902,6 @@ vga_line_fast:
pop es
popa
leave
- ret
; clean defs
%undef .x1
%undef .y1
@@ -914,6 +913,7 @@ vga_line_fast:
%undef _err
%undef _sy_offset
%undef _count
+ ret
; ------------------------------------------------------------
; vga_line_horizontal (y, x1, x2, color)
@@ -1042,12 +1042,12 @@ vga_line_horizontal:
pop es
popa
leave
- ret
; clean defs
%undef .y
%undef .x1
%undef .x2
%undef .color
+ ret
; ------------------------------------------------------------
; vga_line_vertical (x, y1, y2, color)
@@ -1118,13 +1118,13 @@ vga_line_vertical:
pop es
popa
leave ; Nettoie la variable locale (mov sp, bp / pop bp)
- ret
; clean defs
%undef .x
%undef .y1
%undef .y2
%undef .color
%undef .height
+ ret
; ------------------------------------------------------------
; vga_draw_rect
@@ -1176,13 +1176,13 @@ vga_draw_rect:
call vga_mouse_show
popa
leave
- ret
; clean defs
%undef .x1
%undef .y1
%undef .x2
%undef .y2
%undef .color
+ ret
; ------------------------------------------------------------
; cga_draw_rounded_frame
@@ -1254,12 +1254,14 @@ vga_draw_rounded_frame:
popa
leave
- ret
%undef .x1
%undef .y1
%undef .x2
%undef .y2
%undef .color
+ %undef .coord1
+ %undef .coord2
+ ret
; ------------------------------------------------------------
; vga_fill_rect
@@ -1282,6 +1284,8 @@ vga_fill_rect:
pusha
push es
+ call vga_mouse_hide
+
; --- 1. Trier Y1 et Y2 ---
mov ax, .y1
mov bx, .y2
@@ -1414,11 +1418,11 @@ vga_fill_rect:
mov ax, 0xFF08 ; Reset Bit Mask
out dx, ax
+ call vga_mouse_show
+
pop es
popa
leave
- ret
-
; Clean defs
%undef .x1
%undef .y1
@@ -1428,8 +1432,7 @@ vga_fill_rect:
%undef _left_mask
%undef _right_mask
%undef _width
-
-
+ ret
; ------------------------------------------------------------
; vga_fill_rect_32
@@ -1456,10 +1459,12 @@ vga_fill_rect_32:
push es
push fs
- push cs
- pop fs
+ call vga_mouse_hide
- ; calcul de l'offset du pattern
+ push cs
+ pop fs ; fs = CS
+
+ ; calcul de l'offset du pattern
mov ax, .pat_id
shl ax, 3
add ax, pattern_8x8
@@ -1656,12 +1661,12 @@ vga_fill_rect_32:
mov ax, 0x0001 ; Reset Enable Set/Reset
out dx, ax
+ call vga_mouse_show
+
pop fs
pop es
popad
leave
- ret
-
; Clean defs
%undef .x1
%undef .y1
@@ -1673,6 +1678,8 @@ vga_fill_rect_32:
%undef _left_mask
%undef _right_mask
%undef _width
+ ret
+
; ------------------------------------------------------------
; vga_putpixel
%define .x word [bp+4]
@@ -1727,11 +1734,11 @@ vga_putpixel:
pop es
popa
leave
- ret
; clean defs
%undef .x
%undef .y
%undef .color
+ ret
; ------------------------------------------------------------
; GESTION DU CURSEUR
@@ -1805,6 +1812,7 @@ vga_mouse_cursor_move:
pusha
push ds
push es
+ cld
; BDA Data Segment
mov ax, SEG_BDA_CUSTOM
@@ -1837,6 +1845,7 @@ vga_cursor_savebg:
push es
mov ax, SEG_VIDEO
mov es, ax
+ cld
; Calculer l'adresse de départ (y * 80 + x / 8)
mov cx, [PTR_MOUSE + mouse.x]
@@ -1889,6 +1898,7 @@ vga_cursor_restorebg:
push es
mov ax, SEG_VIDEO
mov es, ax
+ cld
mov di, [PTR_MOUSE + mouse.cur_addr_start]
lea si, [PTR_MOUSE + mouse.bkg_buffer]
@@ -1945,7 +1955,7 @@ vga_cursor_restorebg:
; ============================================================
; vga_cursor_draw
-; Détruit: registres sauvegardés/restaurés (PUSHA/POPA)
+; Détruit: registres sauvegardés/restaurés (PUSHAD/POPAD)
; ============================================================
%define BYTES_SHIFT 3
vga_cursor_draw:
@@ -1961,9 +1971,8 @@ vga_cursor_draw:
push ds
push es
push gs
- ; Note: pushad sauvegarde déjà tous les registres généraux (EAX...EDI)
-
cld ; Sécurité : Direction avant
+
mov ax, SEG_BDA_CUSTOM
mov ds, ax
mov ax, SEG_VIDEO
@@ -2110,7 +2119,7 @@ vga_cursor_draw:
pop ds
popad
leave
- ret
%undef .height
%undef .bit_ofs
- %undef .mask
\ No newline at end of file
+ %undef .mask
+ ret
diff --git a/src/gui/lib-api.asm b/src/gui/lib-api.asm
index bdac613..54e5905 100644
--- a/src/gui/lib-api.asm
+++ b/src/gui/lib-api.asm
@@ -137,10 +137,11 @@ endstruc
gui_api_slider_attr:
push bp
mov bp, sp
+ push gs
push ax
- push .id ; ID
- call gui_get_widget_ptr
+ mov ax, .id
+ call gui_get_widget_ptr_internal
jc .err
mov ax, .min
@@ -156,6 +157,7 @@ gui_api_slider_attr:
.err:
pop ax
+ pop gs
leave
ret
%undef .id
@@ -169,16 +171,18 @@ gui_api_slider_attr:
gui_api_set_mode:
push bp
mov bp, sp
+ push gs
push ax
- push .id
- call gui_get_widget_ptr
+ mov ax, .id
+ call gui_get_widget_ptr_internal
jc .err
mov ax, .mode
mov byte [gs:si + widget.attr_mode], al
.err:
+ pop gs
pop ax
leave
ret
@@ -194,10 +198,11 @@ gui_api_set_mode:
gui_api_set_text:
push bp
mov bp, sp
+ push gs
push ax
- push .id
- call gui_get_widget_ptr
+ mov ax, .id
+ call gui_get_widget_ptr_internal
jc .err
mov ax, .segmt
@@ -206,6 +211,7 @@ gui_api_set_text:
mov word [gs:si + widget.text_ofs], ax
.err:
+ pop gs
pop ax
leave
ret
@@ -231,7 +237,7 @@ gui_api_create:
mov bp, sp
push gs
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov gs, ax
call gui_alloc_widget ; Returns GS:SI
mov ax, -1
@@ -275,9 +281,10 @@ gui_api_create:
gui_api_get_state:
push bp
mov bp, sp
+ push gs
- mov ax, .id ; ID
- call gui_get_widget_ptr
+ mov ax, .id
+ call gui_get_widget_ptr_internal
jc .err
xor ax, ax
@@ -287,6 +294,7 @@ gui_api_get_state:
.err:
mov ax, -1
.done:
+ pop gs
leave
ret
%undef .id
@@ -300,9 +308,10 @@ gui_api_get_state:
gui_api_get_type:
push bp
mov bp, sp
+ push gs
- mov ax, .id ; ID
- call gui_get_widget_ptr
+ mov ax,.id
+ call gui_get_widget_ptr_internal
jc .err
xor ax, ax
@@ -312,6 +321,7 @@ gui_api_get_type:
.err:
mov ax, -1
.done:
+ pop gs
leave
ret
%undef .id
@@ -325,9 +335,11 @@ gui_api_get_type:
gui_api_get_val:
push bp
mov bp, sp
+ push gs
- call gui_get_widget_ptr
- ;jc .err
+ mov ax,.id
+ call gui_get_widget_ptr_internal
+ jc .err
call gui_slider_update_value
mov ax, [gs:si + widget.attr_val]
@@ -336,6 +348,7 @@ gui_api_get_val:
.err:
mov ax, -1
.done:
+ pop gs
leave
ret
%undef .id
@@ -350,15 +363,17 @@ gui_api_get_val:
gui_api_set_val:
push bp
mov bp, sp
+ push gs
- mov ax, .id ; ID
- call gui_get_widget_ptr
+ mov ax,.id
+ call gui_get_widget_ptr_internal
jc .err
mov ax, .val
mov [gs:si + widget.thumb_pos], ax
.err:
+ pop gs
leave
ret
%undef .id
@@ -374,9 +389,10 @@ gui_api_set_val:
gui_api_destroy:
push bp
mov bp, sp
+ push gs
- mov ax, .id ; ID
- call gui_get_widget_ptr
+ mov ax,.id
+ call gui_get_widget_ptr_internal
jc .err
call gui_free_widget
@@ -386,6 +402,7 @@ gui_api_destroy:
.err:
mov ax, -1
.done:
+ pop gs
leave
ret
%undef .id
@@ -393,17 +410,29 @@ gui_api_destroy:
; -----------------------------------------------------------------------------
; gui_get_widget_ptr
; Helper interne : Convertit ID en Pointeur
-; In: ID
; Out: GS:SI = Ptr, CF=1 if error
-; -----------------------------------------------------------------------------
%define .id word [bp+4]
+; -----------------------------------------------------------------------------
gui_get_widget_ptr:
push bp
mov bp, sp
push ax
- push cx
-
mov ax, .id
+ call gui_get_widget_ptr_internal
+ pop ax
+ leave
+ ret
+%undef .id
+
+; -----------------------------------------------------------------------------
+; gui_get_widget_ptr_internal
+; Helper interne : Convertit ax en Pointeur
+; Out: GS:SI = Ptr, CF=1 if error
+; -----------------------------------------------------------------------------
+gui_get_widget_ptr_internal:
+ push cx
+ push dx
+
cmp ax, GUI_MAX_WIDGETS
jae .error
@@ -412,7 +441,7 @@ gui_get_widget_ptr:
mul cx ; AX = Offset
mov si, ax
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov gs, ax
clc
@@ -420,12 +449,9 @@ gui_get_widget_ptr:
.error:
stc
.done:
+ pop dx
pop cx
- pop ax
- leave
ret
-%undef .id
-
; =============================================================================
; SECTION : GESTION MÉMOIRE (ALLOCATION / LIBÉRATION)
@@ -434,7 +460,7 @@ gui_get_widget_ptr:
; -----------------------------------------------------------------------------
; gui_init_system
; Initialise toute la mémoire des widgets à 0 (Libre)
-; Entrée : DS doit pointer vers BDA_GUI_WIDGET
+; Entrée : DS doit pointer vers SEG_GUI
; -----------------------------------------------------------------------------
gui_init_system:
push eax
@@ -442,7 +468,7 @@ gui_init_system:
push es
push di
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov es, ax
cld
@@ -468,8 +494,9 @@ gui_alloc_widget:
push ax
push cx
push bx
+ push gs
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov gs, ax
mov si, 0 ; Début du pool
@@ -496,9 +523,12 @@ gui_alloc_widget:
mov word [gs:si + widget.event_click], 0
mov word [gs:si + widget.event_drag], 0
mov byte [gs:si + widget.thumb_pct], 10 ; 10% par défaut
+ mov word [gs:si + widget.thumb_pos], 0
+ mov word [gs:si + widget.attr_val], 0
clc ; Clear Carry Flag
.done:
+ pop gs
pop bx
pop cx
pop ax
@@ -513,15 +543,15 @@ gui_free_widget:
push eax
push es
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov es, ax
cld
mov di, si
mov cx, (widget_size)
- shr cx, 2 ; cx / 4
- xor eax, eax
- rep stosd ; Remplit tout de 0
+ shr cx, 1 ; cx / 4
+ xor ax, ax
+ rep stosw ; Remplit tout de 0
; On efface le widget
mov byte [es:si + widget.state], GUI_STATE_FREE
diff --git a/src/gui/lib-draw.asm b/src/gui/lib-draw.asm
index 0d53a0c..fc432a9 100644
--- a/src/gui/lib-draw.asm
+++ b/src/gui/lib-draw.asm
@@ -37,10 +37,11 @@
gui_draw_single_widget:
pusha
push es
+ push gs
GFX MOUSE_HIDE ; On cache la souris AVANT de commencer le dessin du widget
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov gs, ax
mov al, [gs:si + widget.state]
@@ -98,6 +99,7 @@ gui_draw_single_widget:
.done:
GFX MOUSE_SHOW ; On réaffiche la souris APRES, capturant le widget fini
+ pop gs
pop es
popa
ret
@@ -447,7 +449,7 @@ draw_checkbox:
GFX RECTANGLE, ax, bx, cx, dx, 0
; Check if checked
- cmp word [gs:si + widget.thumb_pos], 0
+ cmp word [gs:si + widget.attr_val], 0
je .draw_label
push ax
@@ -509,7 +511,6 @@ draw_text:
; --- Centrage Texte ---
mov es, [gs:si + widget.text_seg]
mov di, [gs:si + widget.text_ofs]
- xor cx, cx
push di
push es
diff --git a/src/gui/lib-logic.asm b/src/gui/lib-logic.asm
index 2c7e05d..48bdfce 100644
--- a/src/gui/lib-logic.asm
+++ b/src/gui/lib-logic.asm
@@ -16,7 +16,7 @@ gui_process_all:
push ds
push gs
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov gs, ax
; Charger l'état de la souris pour toute la passe
@@ -87,7 +87,7 @@ gui_update_logic:
mov ax, SEG_BDA_CUSTOM
mov ds, ax
- mov ax, BDA_GUI_WIDGET
+ mov ax, SEG_GUI
mov gs, ax
mov al, byte [gs:si + widget.state]
@@ -520,7 +520,7 @@ gui_logic_checkbox:
jne .hover
; Clic validé ! Toggle value
- xor word [gs:si + widget.thumb_pos], 1
+ xor word [gs:si + widget.attr_val], 1
mov byte [gs:si + widget.oldstate], 255 ; Force redraw
mov al, 1