From 3a7382c7611794babe7a5b44c7209aaf36c4f28e Mon Sep 17 00:00:00 2001 From: Frater <13979047+saintfrater@users.noreply.github.com> Date: Thu, 8 Jan 2026 11:46:04 +0100 Subject: [PATCH] add comment / corrections --- build.bat | 2 +- src/bda.asm | 25 +++++++++ src/boot.asm | 61 ++++++++++++---------- src/drivers/debug.asm | 23 ++++++++- src/drivers/gfx.asm | 24 +++++++++ src/drivers/gfx_cgam.asm | 104 ++++++++++++++++++++++++++++++++++---- src/drivers/mouse_ps2.asm | 26 +++++++++- src/drivers/textmode.asm | 23 +++++++++ 8 files changed, 247 insertions(+), 41 deletions(-) diff --git a/build.bat b/build.bat index b0af759..f78e9d9 100644 --- a/build.bat +++ b/build.bat @@ -4,4 +4,4 @@ cd src "c:\program files\NASM\nasm" -f bin boot.asm -o ..\build\bios.bin cd .. -qemu-system-x86_64 -bios build/bios.bin -device loader,file=build/vgabios.bin,addr=0xC0000,force-raw=on -device isa-debugcon,chardev=myconsole -chardev stdio,id=myconsole -k be -display sdl +qemu-system-x86_64 -bios build/bios.bin -device loader,file=roms/vgabios.bin,addr=0xC0000,force-raw=on -device isa-debugcon,chardev=myconsole -chardev stdio,id=myconsole -k be -display sdl diff --git a/src/bda.asm b/src/bda.asm index 23e22f0..bd6a704 100644 --- a/src/bda.asm +++ b/src/bda.asm @@ -1,6 +1,31 @@ +; ============================================================================= +; Project : Custom BIOS / ROM +; File : bda.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://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/informations/bios_data_area ; + %define BDA_SEGMENT 0x0040 ; segment BDA ; custom var diff --git a/src/boot.asm b/src/boot.asm index 7dec420..9ec7168 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -1,37 +1,56 @@ +; ============================================================================= +; Project : Custom BIOS / ROM +; File : boot.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 . +; +; ============================================================================= + BITS 16 org 0 +; --------------------------------------------------------------------------- ; ; configuration du bios ; +; --------------------------------------------------------------------------- %define DEBUG_PORT 0xe9 ; 0x402 ou 0xe9 -%define VIDEO_SEG 0xB800 ; ou 0xB000 -%define VIDEO_ATTR 0x07 ; initial stack -%define STACK_SEG 0x0030 -%define STACK_TOP 0x0100 ; choix commun en RAM basse (pile descend) +%define STACK_SEG 0x0030 ; compatible avec le BMM (Bios Memory Maps) +%define STACK_TOP 0x0100 ; choix commun en RAM basse (pile descendante) %define MEM_SEG_DEB 0x0800 ; 0x0800:0000 = 0x8000 (32KB) évite IVT/BDA + stack 7C00 %define MEM_SEG_END 0xA000 ; 0xA000:0000 = 0xA0000 (début zone vidéo) %define MEM_SEG_STEP 0x0040 ; 1KB = 0x400 bytes = 0x40 paragraphs + + + jmp reset ; ce jump n'est pas sensé être executer, il est présent uniquement pour le debug + ; definition du BDA %include ".\bda.asm" - - jmp reset - %include ".\drivers\debug.asm" %include ".\drivers\gfx_cgam.asm" %include ".\drivers\mouse_ps2.asm" -err_novga db 'No VGA Card BIOS',0 err_vganok db 'VGA Not Initialized',0 err_end db 'code completed successfully',0 @@ -74,10 +93,10 @@ endless: nop jmp endless ; --------------------------------------------------------------------------- -; Détection les ROM supplementaires -; Teste la RAM de 0xC000 jusqu’à 0xE000, par pas de 2KB. +; Test si le vecteur INT 10h à été modifié (par la ROM) ; -; Si une ROM est détectée, le code de la ROM sera appelé. +; Si le vecteur n'a pas été modifiée, on considère que la ROM video n'a pas +; été chargée. ; --------------------------------------------------------------------------- setup_check_vga: ; vérification de l'offset 0x0000:0x0040 qui DOIT etre différent de @default_isr @@ -91,12 +110,11 @@ setup_check_vga: ; Comparer avec default_isr (offset) et CS (segment) mov dx, default_isr ; DX = offset default_isr (dans notre CS) cmp bx, dx - jne .init_ok ; interrupt different + jne .init_ok ; vecteur different, bios initialisé cmp cx, ax jne .init_ok - ; no VGA init - mov ax,cs + mov ax,cs ; vecteur identique, sans doute pas d'initialisation mov ds,ax mov si, err_vganok @@ -112,7 +130,6 @@ setup_check_vga: ; --------------------------------------------------------------------------- setup_load_rom: mov bx, 0xC000 - mov al,'*' .scanloop: mov ds, bx cmp word[0x0000],0xAA55 ; ROM signature @@ -133,20 +150,11 @@ setup_load_rom: add bx, 0x80 ; add 2kb cmp bx, 0xE000 jbe .scanloop - - cmp al,'.' - je .end - ; no rom found : - mov bx,cs - mov ds,bx - - mov si, err_novga - call debug_puts .end: ret ; --------------------------------------------------------------------------- -; Détection RAM conventionnelle (8088, BIOS maison) — sans BIOS +; Détection RAM conventionnelle ; Teste la RAM de MEM_SEG_DEB jusqu’à 0xA000 (640KB), par pas de 1KB. ; Méthode: sauvegarde 1 mot, écrit 2 patterns, relit, restaure. ; @@ -217,9 +225,6 @@ setup_ram: ; --------------------------------------------------------------------------- ; IVT install (8088, mode réel) - remplit les 256 vecteurs avec un handler IRET -; Hypothèses: -; - code en ROM (CS typiquement = 0xF000), handler réside dans ce même segment -; - interruptions désactivées (CLI) pendant l'installation ; --------------------------------------------------------------------------- setup_ivt: ; installation de la table d'interrupts diff --git a/src/drivers/debug.asm b/src/drivers/debug.asm index c4df9a8..4ef712d 100644 --- a/src/drivers/debug.asm +++ b/src/drivers/debug.asm @@ -1,4 +1,25 @@ - +; ============================================================================= +; 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: diff --git a/src/drivers/gfx.asm b/src/drivers/gfx.asm index 70856f8..8f12e4c 100644 --- a/src/drivers/gfx.asm +++ b/src/drivers/gfx.asm @@ -1,3 +1,27 @@ +; ============================================================================= +; Project : Custom BIOS / ROM +; File : boot.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 . +; +; ============================================================================= + + %define GFX_MODE 0x06 ; MCGA HiRes (B/W) %define GFX_WIDTH 640 %define GFX_HEIGHT 200 diff --git a/src/drivers/gfx_cgam.asm b/src/drivers/gfx_cgam.asm index b1f8c21..279243d 100644 --- a/src/drivers/gfx_cgam.asm +++ b/src/drivers/gfx_cgam.asm @@ -1,6 +1,31 @@ +; ============================================================================= +; Project : Custom BIOS / ROM +; File : gfx_cgam.asm +; Author : frater +; Created : 06 jan 2026 ; -; graphics drivers for CGA 640x200x2 +; 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 . +; +; ============================================================================= + +; +; graphics drivers pour carte video/mode CGA-Mono (640x200x2) +; +%define VIDEO_SEG 0xB800 ; ou 0xB000 + %define GFX_MODE 0x06 ; MCGA HiRes (B/W) %define GFX_WIDTH 640 %define GFX_HEIGHT 200 @@ -9,8 +34,12 @@ %define CGA_ODD_BANK 0x2000 %define BG16_SIZE 48 -; ce mode est entrelacé, un bit/pixel, 8 pixels par octet +; ------------------------------------------------------------ +; initialise le mode graphique (via l'int 10h) +; +; ce mode est entrelacé, un bit/pixel, 8 pixels par octet +; ------------------------------------------------------------ gfx_init: ; init graphics mode mov ah, 0x00 ; AH=00h set video mode @@ -21,17 +50,72 @@ gfx_init: ret -; PutPixel(x=cx, y=dx, color=al) sur page bh +; ------------------------------------------------------------ +; Dessine un pixel, accès VRAM direct. +; +; In: +; CX = x (0..639) +; DX = y (0..199) +; AL = color (0=black, !=0=white) +; +; ------------------------------------------------------------ gfx_putpixel: - mov ah, 0Ch - ;mov al, 0Fh ; couleur (0..15) - ;mov bh, 00h ; page - ;mov cx, 100 ; x - ;mov dx, 50 ; y - int 10h + push bx + push di + push es + + mov ax, VIDEO_SEG + mov es, ax + + ; DI = (y>>1)*80 + (x>>3) + (y&1)*0x2000 + mov bx, dx + and bx, 1 ; BX = y&1 + + mov ax, dx + shr ax, 1 ; AX = y>>1 + mov di, ax + mov ax, di + mov di, CGA_STRIDE + mul di ; DX:AX = (y>>1)*80 + mov di, ax + + test bx, 1 + jz .bank_ok + add di, CGA_ODD_BANK +.bank_ok: + mov ax, cx + shr ax, 3 ; AX = x>>3 + add di, ax + + ; masque bit = 0x80 >> (x&7) + mov bl, cl + and bl, 7 ; BL = x&7 + mov ah, 080h + mov cl, bl + shr ah, cl ; AH = bitmask + + ; write + cmp al, 0 + je .clear + +.set: + or byte [es:di], ah + jmp .done + +.clear: + not ah + and byte [es:di], ah + +.done: + pop es + pop di + pop bx ret -; draw background pattern +; ------------------------------------------------------------ +; Dessine un background "check-board", accès VRAM direct. +; +; ------------------------------------------------------------ gfx_background: mov ax,VIDEO_SEG mov es,ax diff --git a/src/drivers/mouse_ps2.asm b/src/drivers/mouse_ps2.asm index 64ffcb8..b13a574 100644 --- a/src/drivers/mouse_ps2.asm +++ b/src/drivers/mouse_ps2.asm @@ -1,5 +1,29 @@ +; ============================================================================= +; Project : Custom BIOS / ROM +; File : mouse_ps2.asm +; Author : frater +; Created : 06 jan 2026 ; -; controlleur de souris via le i8042 (PC Classique) +; 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 . +; +; ============================================================================= + + +; +; controleur de souris via le i8042 (PC Classique) ; %define PS2_PORT_BUFFER 0x60 diff --git a/src/drivers/textmode.asm b/src/drivers/textmode.asm index 7f7b42c..5a29244 100644 --- a/src/drivers/textmode.asm +++ b/src/drivers/textmode.asm @@ -1,3 +1,26 @@ +; ============================================================================= +; Project : Custom BIOS / ROM +; File : textmode.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 . +; +; ============================================================================= + ; ; text mod functions ;