diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b03b847 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +.vscode +.vscode/tasks.json diff --git a/build-elf.bat b/build-elf.bat new file mode 100644 index 0000000..6f66a3a --- /dev/null +++ b/build-elf.bat @@ -0,0 +1,11 @@ +@echo off + +if not exist build mkdir build +cd src +echo compiling +"C:\Program Files\NASM\nasm.exe" -f elf32 -g -F dwarf boot.asm -o ..\build\bios.o +echo LD +ld -m elf_i386 -T link.ld -o build\bios.elf build\bios.o +echo ObjectCopy +objcopy -O binary build\bios.elf build\bios.bin +cd .. diff --git a/roms/qemu-vgabios.bin b/roms/qemu-vgabios.bin new file mode 100644 index 0000000..3f71aae Binary files /dev/null and b/roms/qemu-vgabios.bin differ diff --git a/roms/vgabios.bin b/roms/vgabios.bin new file mode 100644 index 0000000..9adefcc Binary files /dev/null and b/roms/vgabios.bin differ diff --git a/src/bda.asm b/src/bda.asm index 9f586bf..5f73483 100644 --- a/src/bda.asm +++ b/src/bda.asm @@ -2,7 +2,6 @@ ; 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+) ; @@ -21,32 +20,31 @@ ; ; ============================================================================= - -; +; compatible with IBM PC BIOS Data Area (BDA): ; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/informations/bios_data_area ; %define BDA_SEGMENT 0x0040 ; segment BDA -; custom var +; custom vars %define BDA_INFO_MEM_SIZE 0x0014 ; Memory size in Kbytes %define BDA_INFO_MEM_SEG BDA_INFO_MEM_SIZE+2 ; highest Memory Segment ; video related information (compatible with VGA bios) %define BDA_VIDEO_CURR_MODE 0x0049 -%define BDA_VIDEO_COLUMNS 0x004A +%define BDA_VIDEO_COLUMNS 0x004A %define BDA_VIDEO_BUF_SIZE 0x004C %define BDA_VIDEO_OFS_PAGE 0x004E -; 40:50 8 words Cursor position of pages 1-8, high order byte=row low order byte=column; changing this data isn't reflected immediately on the display -; 40:60 byte Cursor ending (bottom) scan line (don't modify) -; 40:61 byte Cursor starting (top) scan line (don't modify) -; 40:62 byte Active display page number -; 40:63 word Base port address for active 6845 CRT controller 3B4h = mono, 3D4h = color -; 40:65 byte 6845 CRT mode control register value (port 3x8h) ; EGA/VGA values emulate those of the MDA/CGA -; 40:66 byte CGA current color palette mask setting (port 3d9h) ; EGA and VGA values emulate the CGA - +; 40:50 8 words Cursor position of pages 1-8, high order byte=row low order byte=column; +; changing this data isn't reflected immediately on the display +; 40:60 byte Cursor ending (bottom) scan line (don't modify) +; 40:61 byte Cursor starting (top) scan line (don't modify) +; 40:62 byte Active display page number +; 40:63 word Base port address for active 6845 CRT controller 3B4h = mono, 3D4h = color +; 40:65 byte 6845 CRT mode control register value (port 3x8h) ; EGA/VGA values emulate those of the MDA/CGA +; 40:66 byte CGA current color palette mask setting (port 3d9h) ; EGA and VGA values emulate the CGA ; ; information relative à la souris @@ -57,7 +55,18 @@ %define BDA_MOUSE_BUFFER 0x0000 ; dword; buffer (jusqu'à 4 octets) %define BDA_MOUSE_IDX 0x0004 ; byte 0..3 %define DBA_MOUSE_PACKETLEN 0x0005 -; 0x0006 +%define DBA_CURSOR_MASK 0x0006 ; byte pixels mask (bit per pixel) %define BDA_MOUSE_STATUS 0x0007 ; byte %define BDA_MOUSE_X 0x0008 ; word -%define BDA_MOUSE_Y 0x000A ; word \ No newline at end of file +%define BDA_MOUSE_Y 0x000A ; word +%define BDA_MOUSE_WHEEL 0x000C ; word + +%define BDA_CURSOR_VISIBLE 0x000E ; byte (0/1) +%define BDA_CURSOR_OLDX 0x000F ; word +%define BDA_CURSOR_OLDY 0x0011 ; word +%define BDA_CURSOR_NEWX 0x0013 ; word +%define BDA_CURSOR_NEWY 0x0015 ; word +%define BDA_CURSOR_BITOFF 0x0017 ; byte 0..7 bits d'offset (x&7) +%define BDA_CURSOR_BYTES 0x0019 ; byte 2 ou 3 bytes as source for cursor image +%define BDA_CURSOR_SAVED 0x001A ; flag if image saved +%define BDA_CURSOR_BG 0x001B ; 48 bytes max (3*16) diff --git a/src/boot.asm b/src/boot.asm index da5ec0b..c367df1 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -2,7 +2,6 @@ ; 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+) ; @@ -32,7 +31,7 @@ org 0 %define DEBUG_PORT 0xe9 ; 0x402 ou 0xe9 -; initial stack +; initial stack %define STACK_SEG 0x0030 ; compatible avec le BMM (Bios Memory Maps) %define STACK_TOP 0x0100 ; choix commun en RAM basse (pile descendante) @@ -45,12 +44,14 @@ org 0 jmp reset ; ce jump n'est pas sensé être executer, il est présent uniquement pour le debug ; definition du BDA -%include ".\bda.asm" +%include "./bda.asm" -%include ".\drivers\debug.asm" -%include ".\drivers\gfx_cgam.asm" -%include ".\drivers\mouse_ps2.asm" -%include ".\services\generic.asm" +%include "./services/macros.asm" + +%include "./drivers/debug.asm" +%include "./drivers/gfx_cgam.asm" +%include "./drivers/mouse_ps2.asm" +%include "./services/generic.asm" err_vganok db 'VGA Not Initialized',0 err_end db 'code completed successfully',0 @@ -61,27 +62,29 @@ reset: mov ax, STACK_SEG mov ss, ax mov sp, STACK_TOP ; haut du segment, mot-aligné - + ; detection de la mémoire totale - call setup_ram + call ram_setup ; modification du stack en "haut" de la RAM mov ax, dx - sub ax, 0x0400 ; réserver les 16 dernier KB + sub ax, 0x0400 ; réserver les 16 dernier KB mov ss, ax mov sp, 0x1000 ; sommet de pile - + ; installé une table d'interruption "dummy" - call setup_ivt + call ivt_setup sti ; load other Rom call setup_load_rom - + ; on vérifie que le BIOS VGA a installer l'INT 10h call setup_check_vga - + + ; on active le mode graphique call gfx_init - + +; test a line mov cx,50 .bcl: ; mov dx,cx mov bl,0 @@ -91,16 +94,16 @@ reset: inc cx cmp cx,150 jle .bcl - + call mouse_init - + mov ax,cs mov ds,ax mov si, err_end call debug_puts - -endless: hlt + +endless: nop jmp endless ; ------------------------------------------------------------------ @@ -113,6 +116,6 @@ times 0xFFF0 - ($ - $$) db 0xFF ; ------------------------------------------------------------------ reset_vector: jmp far 0xF000:reset -; filling +; filling builddate db '06/01/2026',0 diff --git a/src/drivers/gfx_cgam.asm b/src/drivers/gfx_cgam.asm index bdb6b05..028ae9c 100644 --- a/src/drivers/gfx_cgam.asm +++ b/src/drivers/gfx_cgam.asm @@ -2,7 +2,6 @@ ; Project : Custom BIOS / ROM ; File : gfx_cgam.asm ; Author : frater -; Created : 06 jan 2026 ; ; License : GNU General Public License v3.0 or later (GPL-3.0+) ; @@ -32,11 +31,10 @@ %define CGA_STRIDE 80 %define CGA_ODD_BANK 0x2000 -%define BG16_SIZE 48 ; ------------------------------------------------------------ ; initialise le mode graphique (via l'int 10h) -; +; ; ce mode est entrelacé, un bit/pixel, 8 pixels par octet ; ------------------------------------------------------------ gfx_init: @@ -45,59 +43,65 @@ gfx_init: mov al, GFX_MODE int 0x10 + mov [BDA_CURSOR_SAVED],0 ; flag image saved + + ; dessine un background "check-board" call gfx_background ret +; ------------------------------------------------------------ +; Calcule DI + AH=mask pour (CX=x, DX=y) en mode CGA 640x200 +; +; Out: ES=VIDEO_SEG, DI=offset, AH=bitmask (0x80 >> (x&7)) +; ------------------------------------------------------------ +gfx_calc_addr: + ; calcul de l'offset 'y': + ; si y est impaire, DI+=0x2000 + ; DI = (y>>1)*80 + (x>>3) + (y&1)*0x2000 + mov ax, dx + shr ax, 1 ; ax = y/2 + + mov di, ax + shl di, 4 ; (y/2)*16 + shl ax, 6 ; (y/2)*64 + add di, ax ; *80 + + mov ax, cx + shr ax, 3 + add di, ax + + test dl, 1 + jz .even + add di, CGA_ODD_BANK +.even: + ; masque bit = 0x80 >> (x&7) + push cx + and cl, 7 + mov ah, 080h + shr ah, cl + pop cx + ret + ; ------------------------------------------------------------ ; Dessine un pixel, accès VRAM direct. ; -; In: ; CX = x (0..639) ; DX = y (0..199) ; BL = color (0=black, !=0=white) -; ; ------------------------------------------------------------ gfx_putpixel: - push ax + PUSH_ABCD push di push es - + mov ax, VIDEO_SEG mov es,ax - - ; calcul de l'offset 'y': - ; si y est impaire, DI+=0x2000 - - ; DI = (y>>1)*80 + (x>>3) + (y&1)*0x2000 - mov ax, dx - shr ax, 1 ; ax = y/2 - - mov di, ax ; di = y/2 - shl di, 4 ; di = (y/2)*16 - - shl ax, 6 ; ax = (y/2)*64 - add di, ax ; di = (y/2)*(16+64) = *80 - - mov ax, cx ; x - shr ax, 3 ; AX = x/8 - add di, ax - - ; ligne paire/impaire - test dl, 1 - jz .ligne_paire - add di, CGA_ODD_BANK -.ligne_paire: - - ; masque bit = 0x80 >> (x&7) - and cl, 7 ; cl = x&7 - mov ah, 080h - shr ah, cl ; AH = bitmask + call gfx_calc_addr ; write cmp bl, 0 je .clear - .set: or byte [es:di], ah jmp .done @@ -109,6 +113,25 @@ gfx_putpixel: .done: pop es pop di + POP_ABCD + ret + +; ------------------------------------------------------------ +; Lit un pixel (CX=x, DX=y) +; Out: AL=0/1 +; ------------------------------------------------------------ +gfx_getpixel: + push ax + push di + push es + + call gfx_calc_addr + mov al, [es:di] + and al, ah + setnz al + + pop es + pop di pop ax ret @@ -127,3 +150,403 @@ gfx_background: mov cx,0x1000 ; 640/8/2 rep stosw ret + +; ------------------------------------------------------------ +; Calcule les infos de l'alignement du curseur, basé sur cx=X +; il est important que DS pointe sur le BDA_MOUSE_SEG +; Out: BDA_CURSOR_BITOFF, BDA_CURSOR_BYTES +; ------------------------------------------------------------ +gfx_cursor_calc_align: + mov al, cl + and al, 7 ; offset = x&7 + mov [BDA_CURSOR_BITOFF], al + cmp al, 0 + jne .unaligned + mov byte [BDA_CURSOR_BYTES], 2 + ret +.unaligned: + mov byte [BDA_CURSOR_BYTES], 3 + ret + +; ------------------------------------------------------------ +; Sauvegarde le background (24x16) sous le curseur (cx=X,dx=Y) +; +; utilise les variables du BDA pour stocker +; ------------------------------------------------------------ +gfx_cursor_savebg: + pusha ; sauvegarde registres + + mov ax, BDA_MOUSE_SEG + mov ds, ax + + mov ax, VIDEO_SEG + mov es, ax + + cmp [BDA_CURSOR_SAVED], 0 + jne .done ; déjà sauvé + + mov [BDA_CURSOR_SAVED], 1 ; flag image saved + + mov [BDA_CURSOR_NEWX], cx ; sauvegarde la nouvelle position + mov [BDA_CURSOR_NEWY], dx + + call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y) + mov dx,0x2000 ; offset pour lignes impaire + cmp di,dx + jl .no_odd_bank + neg dx ; Y est déja une ligne impaire, on retire l'offset +.no_odd_bank: + + mov si, BDA_CURSOR_BG ; DS:SI = buffer de sauvegarde + mov bx, 8 + + and cx,0x0007 ; alignement X + jnz .row3 + +.row3: ; sauve 3 bytes/ligne + mov [BDA_CURSOR_BYTES], 3 ; 3 bytes/ligne + ; ligne 'y', peut etre paire ou impaire + mov ax, word [es:di] ; charge first word + mov word [ds:si], ax ; sauvegarde + mov al, byte [es:di+2] ; charge 3ème byte + mov byte [ds:si+2], al + add si, 3 + + ; ligne 'y'+1; si paire +0x2000, si impaire -0x2000 + add di, dx ; charge first word other bank (+0x2000 ou -0x2000) + mov ax, word [es:di] + mov word [ds:si], ax + mov al, byte [es:di+2] + mov byte [ds:si+2], al + add si, 3 + sub di, dx + add di, CGA_STRIDE + dec bx + jnz .row3 + jmp .done + +.row2: ; sauve 2 bytes/ligne + mov [BDA_CURSOR_BYTES], 2 ; par défaut + ; ligne 'y', peut etre paire ou impaire + mov ax, word [es:di] ; charge first word + mov word [ds:si], ax ; sauvegarde + add si, 2 + + ; ligne 'y'+1; si paire +0x2000, si impaire -0x2000 + add di, dx ; charge first word other bank (+0x2000 ou -0x2000) + mov ax, word [es:di] + mov word [ds:si], ax + add si, 2 + sub di, dx + add di, CGA_STRIDE + dec bx + jnz .row3 +.done: + popa + ret + +; ------------------------------------------------------------ +; restore le background (24x16) +; +; utilise les variables du BDA pour stocker +; ------------------------------------------------------------ +gfx_cursor_restorebg: + pusha ; sauvegarde registres + + mov ax, BDA_MOUSE_SEG + mov ds, ax + + mov ax, VIDEO_SEG + mov es, ax + + cmp [BDA_CURSOR_SAVED], 0 ; pas de background sauvé + je .done + + mov cx,[BDA_CURSOR_OLDX] ; restore de la position + mov dx,[BDA_CURSOR_OLDY] + mov [BDA_CURSOR_SAVED], 0 ; le background a été restauré + + call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y) + mov dx,0x2000 ; offset pour lignes impaire + cmp di,dx + jl .no_odd_bank + neg dx ; Y est déja une ligne impaire, on retire l'offset +.no_odd_bank: + mov si, BDA_CURSOR_BG ; DS:SI = buffer de sauvegarde + mov bx, 8 + + cmp [BDA_CURSOR_BYTES], 2 ; si la sauvegarde est en 2 bytes/ligne + je .row2 + +.row3: ; restore en 3 bytes/ligne + ; ligne 'y', peut etre paire ou impaire + mov ax,word [ds:si] ; recupère le 1er word + mov word [es:di],ax + mov al,byte [ds:si+2] ; charge 3ème byte + mov byte [es:di+2],al + add si, 3 + + ; ligne 'y'+1; si paire +0x2000, si impaire -0x2000 + add di, dx ; charge first word other bank (+0x2000 ou -0x2000) + mov ax,word [ds:si] ; recupère le 1er word + mov word [es:di],ax + mov al,byte [ds:si+2] ; charge 3ème byte + mov byte [es:di+2],al + add si, 3 + sub di, dx + add di, CGA_STRIDE + dec bx + jnz .row3 + jmp .done + +.row2: ; restore en 2 bytes/ligne + ; ligne 'y', peut etre paire ou impaire + mov ax,word [ds:si] ; recupère le 1er word + mov word [es:di],ax + add si, 2 + + ; ligne 'y'+1; si paire +0x2000, si impaire -0x2000 + add di, dx ; charge first word other bank (+0x2000 ou -0x2000) + mov ax,word [ds:si] ; recupère le 1er word + mov word [es:di],ax + add si, 2 + sub di, dx + add di, CGA_STRIDE + dec bx + jnz .row2 +.done: + popa + ret + +; ------------------------------------------------------------ +; Dessine un pixel, en [ES:DI] accès VRAM direct. +; +; CX = x (0..639) +; DX = y (0..199) +; BL = color (0=black, !=0=white) +; ------------------------------------------------------------ +gfx_putpixel_fast: + cmp bl, 0 + je .clear +.set: + or byte [es:di], ah + jmp .done +.clear: + not ah + and byte [es:di], ah +.done: + ret + +; ------------------------------------------------------------ +; Lit un pixel, en [ES:DI] accès VRAM direct. +; +; ------------------------------------------------------------ +gfx_getpixel_fast: + mov al, [es:di] + and al, ah + setnz al + ret + +; ------------------------------------------------------------ +; Dessine le curseur 16x16 AND/XOR à [BDA_CURSOR_NEWX],[BDA_CURSOR_NEWY] +; +; CS:SI = base du sprite (AND[16] suivi de XOR[16] à +32 bytes) +; Uses: BDA_CURSOR_BITOFF/BDA_CURSOR_BYTES (via gfx_cursor_calc_align) +; ------------------------------------------------------------ +gfx_cursor_draw: + pusha + + mov ax, BDA_MOUSE_SEG + mov ds, ax + mov ax, VIDEO_SEG + mov es, ax + + mov cx, [BDA_CURSOR_NEWX] + mov dx, [BDA_CURSOR_NEWY] + + ; calcule offset et bytes/ligne (2 ou 3) + call gfx_cursor_calc_align + mov bl, [BDA_CURSOR_BITOFF] ; 0..7 + + ; calcule DI de départ (attention: gfx_calc_addr modifie CL) + push cx + call gfx_calc_addr ; DI ok, AH ignoré + pop cx + + ; dxbank = +0x2000 si DI < 0x2000, sinon dxbank = -0x2000 + mov bp, 02000h + cmp di, bp + jl .bank_ok + neg bp ; bp = -0x2000 +.bank_ok: + + ; on va dessiner 16 lignes: 8 paires (ligne dans bank courant + ligne dans autre bank) + mov bx, 0 ; row index (0..15) + + mov dh, 8 +.pair: + ; ----- ligne row (bank courant) ----- + push di + push si + call .draw_line ; utilise DI, row=BX + pop si + pop di + + ; ----- ligne row+1 (autre bank) ----- + add di, bp + inc bx + push di + push si + call .draw_line + pop si + pop di + sub di, bp + + ; avancer de 2 lignes (dans le bank courant): +80 bytes + add di, CGA_STRIDE + + inc bx + dec dh + jnz .pair + + popa + ret + +; ------------------------------------------------------------ +; .draw_line: applique AND/XOR sur une ligne de 16 pixels à ES:DI +; row index dans BX (0..15) +; offset dans BL (0..7) +; sprite base CS:SI +; ------------------------------------------------------------ +.draw_line: + push ax + push cx + push dx + push bp + push di + + ; charger masks de la ligne: AND = [SI + row*2], XOR = [SI + 32 + row*2] + mov ax, bx + shl ax, 1 ; row*2 + + push si + add si, ax + mov cx, [cs:si] ; AND mask + add si, 32 + mov dx, [cs:si] ; XOR mask + pop si + + ; lire bytes source + mov al, [es:di] ; b0 + inc di + mov ah, [es:di] ; b1 + dec di + ; w0 = (b0<<8)|b1 dans AX déjà + + cmp bl, 0 + je .aligned + + ; unaligned: besoin b2 et w1 = (b1<<8)|b2 + add di, 2 + mov dl, [es:di] ; b2 + sub di, 2 + mov dh, ah ; b1 + ; DX = w1 (b1<<8)|b2 + + ; seg = (w0<>(8-off)) + ; off = BL, rshift = (8-BL) + push bx ; sauvegarde row/off + mov cl, bl + shl ax, cl ; AX = w0<>(8-off) + + or ax, dx ; AX = seg (16 bits alignés) + pop bx + + jmp .apply_masks + +.aligned: + ; seg = w0 déjà dans AX +.apply_masks: + ; newseg = (seg & AND) ^ XOR + and ax, cx + xor ax, dx ; AX = newseg + + cmp bl, 0 + je .write_aligned + + ; --- write unaligned: impact sur b0 (bas 8-off bits), b1 (tout), b2 (haut off bits) --- + ; n = 8-off + mov cl, 8 + sub cl, bl ; cl = n (1..7) + + ; val0 = newseg >> (8+off) + ; (8+off) = 8 + BL + mov dx, ax + mov cl, bl + add cl, 8 + shr dx, cl ; DL = val0 (0..(2^(8-off)-1)) + + ; mask0 = (1<> off) & 0xFF + mov dx, ax + mov cl, bl + shr dx, cl + inc di + mov [es:di], dl + dec di + + ; b2 high off bits = (newseg & ((1< ID - mov bl, MOUSE_GET_ID - call mouse_sendcmd - call ps2_read ; AL = ID + ; Get ID + mov bl, MOUSE_GET_ID + call mouse_sendcmd + call ps2_read ; AL = ID - cmp al, 03h - je .is4 - cmp al, 04h - je .is4 + cmp al, 03h + je .is4 + cmp al, 04h + je .is4 ret .is4: - mov byte [DBA_MOUSE_PACKETLEN], 4 + mov byte [DBA_MOUSE_PACKETLEN], 4 ret - + ; ------------------------------------------------------------ ; fonction de gestion du i8042 ; @@ -190,25 +228,25 @@ ps2_wait_ready_write: in al, PS2_PORT_CTRL test al, 02h ; IBF jnz .wait - ret + ret -; attendre que le 8042 soit pret a lire de l'information +; attendre que le 8042 soit pret a lire de l'information ps2_wait_ready_read: -.wait: +.wait: in al, PS2_PORT_CTRL test al, 01h ; OBF jz .wait - ret - + ret + ; lire de l'information depuis le 8042 -ps2_read: +ps2_read: call ps2_wait_ready_read in al, PS2_PORT_BUFFER - ret + ret -; vide le buffer interne du 8042 (information(s) ignorée(s)) +; vide le buffer interne du 8042 (information(s) ignorée(s)) ps2_flush_output: -.flush: +.flush: in al, PS2_PORT_CTRL test al, 01h jz .done @@ -216,14 +254,12 @@ ps2_flush_output: jmp .flush .done: ret - - ; ------------------------------------------------------------ -; envoye une commande souris +; envoye une commande souris et attends le ACK ; ; BL = commande souris (ou data après une commande F3) -; +; ; renvoi CF=0 si ACK, CF=1 sinon ; ------------------------------------------------------------ mouse_sendcmd: @@ -231,11 +267,11 @@ mouse_sendcmd: mov al, I8042_CMD_WRITE_AUX out PS2_PORT_CTRL, al - + call ps2_wait_ready_write mov al, bl out PS2_PORT_BUFFER, al - + call ps2_wait_ready_read ; AL = réponse cmp al, MOUSE_ACK jne .bad @@ -244,48 +280,75 @@ mouse_sendcmd: .bad: stc ret - + ; ------------------------------------------------------------ ; interrupt handler -; +; ; buffer[0] = status ; buffer[1] = déplacement x ; buffer[2] = déplacement y (inversé) -; +; buffer[4] = molette (si PacketLen = 4) +; +; status byte : +; bit 0 = bouton gauche +; bit 1 = bouton droit +; bit 2 = bouton milieu +; bit 3 = toujours 1 +; bit 4 = X sign +; bit 5 = Y sign +; bit 6 = X overflow +; bit 7 = Y overflow ; ------------------------------------------------------------ mouse_handler: - push ax - push bx - - ; use BDA segment + PUSH_ABCD push ds - mov ax,BDA_SEGMENT + + ; use BDA segment + mov ax,BDA_MOUSE_SEG mov ds,ax - xor bx,bx in al, PS2_PORT_BUFFER ; lire octet souris mov [BDA_MOUSE_BUFFER + BDA_MOUSE_IDX], al inc [BDA_MOUSE_IDX] - - cmp [BDA_MOUSE_IDX], 3 + + mov al, [DBA_MOUSE_PACKETLEN] + cmp [BDA_MOUSE_IDX], al jne .done mov [BDA_MOUSE_IDX], 0 - ; decode buffer + + ; decode buffer manuallement + mov al, [BDA_MOUSE_BUFFER] + mov [BDA_MOUSE_STATUS], al + mov al, [BDA_MOUSE_BUFFER+1] cbw add [BDA_MOUSE_X], ax - + mov al, [BDA_MOUSE_BUFFER+2] cbw sub [BDA_MOUSE_Y], ax + ; si packetlen = 4, gérer la molette; experimental + mov al, [BDA_MOUSE_BUFFER+3] + cbw + sub [BDA_MOUSE_WHEEL], ax + + ; restaurer l'ancien arrière plan du curseur + call gfx_cursor_restorebg + + ; sauvegarder le nouvel arrière plan du curseur + mov cx, [BDA_MOUSE_X] + mov dx, [BDA_MOUSE_Y] + call gfx_cursor_savebg + + call gfx_cursor_draw + .done: mov al, 0x20 out 0xA0, al ; EOI PIC esclave out 0x20, al ; EOI PIC maître - + pop ds - pop bx - pop ax + POP_ABCD iret \ No newline at end of file diff --git a/src/services/generic.asm b/src/services/generic.asm index 50ee15a..0f3d3fd 100644 --- a/src/services/generic.asm +++ b/src/services/generic.asm @@ -2,7 +2,6 @@ ; Project : Custom BIOS / ROM ; File : generic.asm ; Author : frater -; Created : 06 jan 2026 ; ; License : GNU General Public License v3.0 or later (GPL-3.0+) ; @@ -23,7 +22,7 @@ ; --------------------------------------------------------------------------- ; Détection RAM conventionnelle -; Teste la RAM de MEM_SEG_DEB jusqu’à 0xA000 (640KB), par pas de 1KB. +; Teste la RAM de MEM_SEG_DEB -> MEM_SEG_END (0xA000, 640KB), par pas de 1KB. ; Méthode: sauvegarde 1 mot, écrit 2 patterns, relit, restaure. ; ; Résultats: @@ -33,9 +32,9 @@ ; Précautions: ; - Ne testez PAS une zone où se trouve votre pile / variables. ; - Si votre pile est à 0000:7C00 (phys 0x7C00), commencez au moins à 0x0800. -; - Ne testez pas au-delà de 0xA000 (début VGA/vidéo). +; - Ne testez pas au-delà de MEM_SEG_END (0xA000: début VGA/vidéo). ; --------------------------------------------------------------------------- -setup_ram: +ram_setup: xor ax, ax ; AX = compteur KB trouvés mov dx, MEM_SEG_DEB ; DX = segment courant testé mov cx, MEM_SEG_END ; CX = segment fin (exclu) @@ -155,7 +154,7 @@ setup_check_vga: ; --------------------------------------------------------------------------- ; IVT install (8088, mode réel) - remplit les 256 vecteurs avec un handler IRET ; --------------------------------------------------------------------------- -setup_ivt: +ivt_setup: ; installation de la table d'interrupts xor ax, ax mov es, ax ; ES = 0000h -> base IVT @@ -177,11 +176,11 @@ setup_ivt: ; --------------------------------------------------------------------------- ; IVT install (8088, mode réel) - installe un handler a une interrupt calculée ; -; ax = int ide +; ax = int id ; dx = segment handler ; bx = offset handler ; --------------------------------------------------------------------------- -setup_setvector: +ivt_setvector: push es push di @@ -192,9 +191,11 @@ setup_setvector: mov es, ax ; ES = 0000h -> base IVT mov ax, bx ; offset du handler + cli stosw ; write offset (AX) -> [ES:DI], DI += 2 xchg ax, dx ; AX = segment, DX = offset stosw ; write segment (AX) -> [ES:DI], DI += 2 + sti pop di pop es diff --git a/src/services/macros.asm b/src/services/macros.asm new file mode 100644 index 0000000..d8cc324 --- /dev/null +++ b/src/services/macros.asm @@ -0,0 +1,45 @@ +; ============================================================================= +; Project : Custom BIOS / ROM +; File : macros.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 . +; +; ============================================================================= + +%macro PUSH_ABCD 0 + push ax + push bx + push cx + push dx +%endmacro + +%macro PUSH_ID 0 + push di + push si +%endmacro + +%macro POP_ABCD 0 + pop dx + pop cx + pop bx + pop ax +%endmacro + +%macro POP_ID 0 + pop si + pop di +%endmacro