migrating to Cdecl function type
This commit is contained in:
parent
5837a8983e
commit
0a5d791808
5 changed files with 138 additions and 114 deletions
10
src/bda.asm
10
src/bda.asm
|
|
@ -24,6 +24,16 @@
|
||||||
; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/informations/bios_data_area
|
; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/informations/bios_data_area
|
||||||
;
|
;
|
||||||
|
|
||||||
|
; Définition globale des parametres
|
||||||
|
%define arg1 [bp+4]
|
||||||
|
%define arg2 [bp+6]
|
||||||
|
%define arg3 [bp+8]
|
||||||
|
%define arg4 [bp+10]
|
||||||
|
%define arg5 [bp+12]
|
||||||
|
%define arg6 [bp+14]
|
||||||
|
%define arg7 [bp+16]
|
||||||
|
%define arg8 [bp+18]
|
||||||
|
|
||||||
%define BDA_SEGMENT 0x0040 ; segment BDA
|
%define BDA_SEGMENT 0x0040 ; segment BDA
|
||||||
|
|
||||||
; custom vars
|
; custom vars
|
||||||
|
|
|
||||||
96
src/boot.asm
96
src/boot.asm
|
|
@ -102,85 +102,44 @@ reset:
|
||||||
sti
|
sti
|
||||||
|
|
||||||
; on active le mode graphique
|
; on active le mode graphique
|
||||||
GFX_DRV GFX_INIT
|
GFX INIT
|
||||||
|
|
||||||
mov cx, 290
|
GFX GOTOXY, 290, 80
|
||||||
mov dx, 80
|
GFX TXT_MODE, GFX_TXT_WHITE_TRANSPARENT
|
||||||
GFX_DRV GFX_GOTOXY
|
|
||||||
|
|
||||||
GFX_WRITE_MODE GFX_TXT_WHITE_TRANSPARENT
|
GFX WRITE, cs, W_T
|
||||||
|
|
||||||
push cs
|
GFX GOTOXY, 290, 90
|
||||||
pop ds
|
GFX TXT_MODE, GFX_TXT_BLACK_TRANSPARENT
|
||||||
mov si, W_T
|
GFX WRITE, cs, B_T
|
||||||
GFX_DRV GFX_WRITE
|
|
||||||
|
|
||||||
mov cx, 290
|
GFX GOTOXY, 290, 100
|
||||||
mov dx, 90
|
GFX TXT_MODE, GFX_TXT_WHITE
|
||||||
GFX_DRV GFX_GOTOXY
|
GFX WRITE, cs, W_B
|
||||||
|
|
||||||
GFX_WRITE_MODE GFX_TXT_BLACK_TRANSPARENT
|
GFX GOTOXY, 290, 110
|
||||||
|
GFX TXT_MODE, GFX_TXT_BLACK
|
||||||
push cs
|
GFX WRITE, cs, B_W
|
||||||
pop ds
|
|
||||||
mov si, B_T
|
|
||||||
GFX_DRV GFX_WRITE
|
|
||||||
|
|
||||||
mov cx, 290
|
|
||||||
mov dx, 100
|
|
||||||
GFX_DRV GFX_GOTOXY
|
|
||||||
|
|
||||||
GFX_WRITE_MODE GFX_TXT_WHITE
|
|
||||||
|
|
||||||
push cs
|
|
||||||
pop ds
|
|
||||||
mov si, W_B
|
|
||||||
GFX_DRV GFX_WRITE
|
|
||||||
|
|
||||||
mov cx, 290
|
|
||||||
mov dx, 110
|
|
||||||
GFX_DRV GFX_GOTOXY
|
|
||||||
|
|
||||||
GFX_WRITE_MODE GFX_TXT_BLACK
|
|
||||||
|
|
||||||
push cs
|
|
||||||
pop ds
|
|
||||||
mov si, B_W
|
|
||||||
GFX_DRV GFX_WRITE
|
|
||||||
|
|
||||||
; call mouse_reset
|
; call mouse_reset
|
||||||
call mouse_init
|
call mouse_init
|
||||||
|
|
||||||
GFX_WRITE_MODE GFX_TXT_BLACK
|
GFX TXT_MODE, GFX_TXT_BLACK
|
||||||
|
GFX GOTOXY, 0, 0
|
||||||
|
GFX WRITE, cs, cpt_txt
|
||||||
|
|
||||||
xor cx,cx
|
GFX TXT_MODE, GFX_TXT_WHITE_TRANSPARENT
|
||||||
mov dx,0
|
GFX GOTOXY, 8,8
|
||||||
GFX_DRV GFX_GOTOXY
|
GFX WRITE, cs, helloworld
|
||||||
|
|
||||||
push cs
|
GFX GFX_CRS_UPDATE
|
||||||
pop ds
|
|
||||||
mov si, cpt_txt
|
|
||||||
GFX_DRV GFX_WRITE
|
|
||||||
|
|
||||||
GFX_WRITE_MODE GFX_TXT_WHITE_TRANSPARENT
|
|
||||||
|
|
||||||
mov cx,8
|
|
||||||
mov dx,8
|
|
||||||
GFX_DRV GFX_GOTOXY
|
|
||||||
|
|
||||||
mov si, helloworld
|
|
||||||
GFX_DRV GFX_WRITE
|
|
||||||
|
|
||||||
mov cx,8
|
mov cx,8
|
||||||
mov dx,24
|
mov dx,24
|
||||||
GFX_WRITE_MODE 0
|
|
||||||
|
|
||||||
GFX_DRV GFX_CRS_UPDATE
|
|
||||||
|
|
||||||
.loopshift:
|
.loopshift:
|
||||||
GFX_DRV GFX_GOTOXY
|
GFX GOTOXY, cx, dx
|
||||||
mov si, helloworld
|
GFX WRITE, cs, helloworld
|
||||||
GFX_DRV GFX_WRITE
|
|
||||||
add dx,8
|
add dx,8
|
||||||
inc cx
|
inc cx
|
||||||
cmp cx,16
|
cmp cx,16
|
||||||
|
|
@ -189,16 +148,13 @@ reset:
|
||||||
mov ax,BDA_DATA_SEG
|
mov ax,BDA_DATA_SEG
|
||||||
mov ds,ax
|
mov ds,ax
|
||||||
endless:
|
endless:
|
||||||
GFX_WRITE_MODE GFX_TXT_BLACK
|
GFX TXT_MODE, GFX_TXT_BLACK
|
||||||
xor cx,cx
|
GFX GOTOXY, 0, 180
|
||||||
mov dx,180
|
|
||||||
GFX_DRV GFX_GOTOXY
|
|
||||||
|
|
||||||
mov ax, [BDA_MOUSE + mouse.x]
|
mov ax, [BDA_MOUSE + mouse.x]
|
||||||
call print_word_hex
|
call print_word_hex
|
||||||
|
|
||||||
mov al,' '
|
GFX PUTCH, ' '
|
||||||
call cga_putc
|
|
||||||
|
|
||||||
mov ax, [BDA_MOUSE + mouse.y]
|
mov ax, [BDA_MOUSE + mouse.y]
|
||||||
call print_word_hex
|
call print_word_hex
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ print_word_hex:
|
||||||
mov dx, ax
|
mov dx, ax
|
||||||
mov cx, 4 ; 4 caractères hex dans un mot de 16 bits
|
mov cx, 4 ; 4 caractères hex dans un mot de 16 bits
|
||||||
|
|
||||||
.next_digit:
|
.next_digit:
|
||||||
; On veut afficher les bits 12-15 d'abord.
|
; On veut afficher les bits 12-15 d'abord.
|
||||||
; L'astuce est de faire une rotation à gauche de 4 bits.
|
; L'astuce est de faire une rotation à gauche de 4 bits.
|
||||||
; Le quartet de poids fort se retrouve en bas (bits 0-3).
|
; Le quartet de poids fort se retrouve en bas (bits 0-3).
|
||||||
|
|
@ -75,8 +75,12 @@ print_word_hex:
|
||||||
|
|
||||||
call nibble_to_ascii ; Convertit AL en caractère ASCII
|
call nibble_to_ascii ; Convertit AL en caractère ASCII
|
||||||
|
|
||||||
call cga_putc ; Affiche le caractère
|
; call cga_putc ; Affiche le caractère
|
||||||
|
xor bx, bx
|
||||||
|
mov bl, al
|
||||||
|
push bx
|
||||||
|
call cga_putc
|
||||||
|
add sp, 2
|
||||||
loop .next_digit ; Répète 4 fois
|
loop .next_digit ; Répète 4 fois
|
||||||
|
|
||||||
popa
|
popa
|
||||||
|
|
|
||||||
|
|
@ -46,47 +46,62 @@
|
||||||
%define GFX_TXT_WHITE 00000010b
|
%define GFX_TXT_WHITE 00000010b
|
||||||
%define GFX_TXT_BLACK 00000011b
|
%define GFX_TXT_BLACK 00000011b
|
||||||
|
|
||||||
%macro GFX_DRV 1-*
|
%macro GFX_DRV 1
|
||||||
call word [cs:graph_driver + ((%1)*2)]
|
call word [cs:graph_driver + ((%1)*2)]
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
|
%macro GFX 1-*
|
||||||
|
; %1 est l'index de la fonction
|
||||||
|
; On itère sur les arguments suivants en sens inverse (Convention C)
|
||||||
|
|
||||||
|
%rep %0 - 1 ; Répéter pour (Nombre d'args - 1)
|
||||||
|
%rotate -1 ; Prend le dernier argument
|
||||||
|
push %1 ; L'empile
|
||||||
|
%endrep
|
||||||
|
|
||||||
|
%rotate -1 ; On revient au premier argument (l'index de fonction)
|
||||||
|
call word [cs:graph_driver + ((%1)*2)]
|
||||||
|
|
||||||
|
; Nettoyage de la pile (Convention CDECL: l'appelant nettoie)
|
||||||
|
; Chaque argument = 2 octets (1 word).
|
||||||
|
add sp, (%0 - 1) * 2
|
||||||
|
%endmacro
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
; TABLE DE SAUT (VECTEURS API)
|
; TABLE DE SAUT (VECTEURS API)
|
||||||
; Cette table doit être située au début du driver pour être
|
; Cette table doit être située au début du driver pour être
|
||||||
; accessible par la GUI à des offsets fixes.
|
; accessible par la GUI à des offsets fixes.
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
%define GFX_INIT 0
|
%define INIT 0
|
||||||
%define GFX_PUTPIXEL 1
|
%define GFX_PUTPIXEL 1
|
||||||
%define GFX_GETPIXEL 2
|
%define GFX_GETPIXEL 2
|
||||||
%define GFX_GOTOXY 3
|
%define GOTOXY 3
|
||||||
%define GFX_PUTCH 4
|
%define TXT_MODE 4
|
||||||
%define GFX_WRITE 5
|
%define PUTCH 5
|
||||||
%define GFX_CRS_UPDATE 6
|
%define WRITE 6
|
||||||
|
%define GFX_CRS_UPDATE 7
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
; COMMENTAIRE SUR LA MÉTHODE D'APPEL
|
; COMMENTAIRE SUR LA MÉTHODE D'APPEL
|
||||||
;
|
;
|
||||||
; Pour appeler une fonction du driver depuis votre GUI :
|
; GFX FUNCTION, Arg1, Arg2, Arg3
|
||||||
; 1. Définissez l'adresse de base du driver (ex: GFX_DRIVER_BASE)
|
|
||||||
; 2. Utilisez un call indirect via l'offset de la table.
|
|
||||||
;
|
;
|
||||||
; Exemple en ASM pour remplir un rectangle :
|
; GFX GFX_PUTPIXEL, 320, 100, 1
|
||||||
; call [GFX_DRIVER_BASE + 9] ; Appelle gfx_fill_rect
|
|
||||||
;
|
;
|
||||||
; Cette méthode isole totalement votre bibliothèque GUI du driver.
|
|
||||||
; Si vous changez le code du driver, tant que la table au début
|
; Si vous changez le code du driver, tant que la table au début
|
||||||
; ne change pas d'ordre, la GUI n'a pas besoin d'être recompilée.
|
; ne change pas d'ordre, la GUI n'a pas besoin d'être recompilée.
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
|
|
||||||
graph_driver:
|
graph_driver:
|
||||||
dw cga_init ; init de la carte graphique
|
dw cga_init ; init de la carte graphique
|
||||||
dw cga_putpixel ; dessin d'un pixel
|
dw cga_putpixel ; dessin d'un pixel
|
||||||
dw cga_getpixel ; lecture d'un pixel
|
dw cga_getpixel ; lecture d'un pixel
|
||||||
dw cga_set_charpos ; gotoxy
|
dw cga_set_charpos ; gotoxy
|
||||||
dw cga_putc ; dessin d'un caractère
|
dw cga_set_writemode ; mode texte
|
||||||
dw cga_write ; dessin d'une chaine de caractère
|
dw cga_putc ; dessin d'un caractère
|
||||||
dw cga_mouse_cursor_move ; déplacement du curseur
|
dw cga_write ; dessin d'une chaine de caractère
|
||||||
dw cga_line_vertical ; dessin d'une ligne verticale
|
dw cga_mouse_cursor_move ; déplacement du curseur
|
||||||
|
dw cga_line_vertical ; dessin d'une ligne verticale
|
||||||
|
|
||||||
|
|
||||||
; jmp gfx_fill_rect ; Remplissage rectangle (Nouveau)
|
; jmp gfx_fill_rect ; Remplissage rectangle (Nouveau)
|
||||||
|
|
@ -105,19 +120,6 @@ graph_driver:
|
||||||
|
|
||||||
xchg ah,al
|
xchg ah,al
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
%macro GFX_WRITE_MODE 1
|
|
||||||
push fs
|
|
||||||
|
|
||||||
push BDA_DATA_SEG
|
|
||||||
pop fs
|
|
||||||
|
|
||||||
mov byte [fs:BDA_GFX + gfx.cur_mode], %1
|
|
||||||
|
|
||||||
pop fs
|
|
||||||
pop ax
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
; initialise le mode graphique (via l'int 10h)
|
; initialise le mode graphique (via l'int 10h)
|
||||||
;
|
;
|
||||||
|
|
@ -172,6 +174,24 @@ cga_calc_addr:
|
||||||
pop cx
|
pop cx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
cga_set_writemode:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
|
push fs
|
||||||
|
push ax
|
||||||
|
mov ax, BDA_DATA_SEG
|
||||||
|
mov fs,ax
|
||||||
|
|
||||||
|
mov ax, word arg1
|
||||||
|
|
||||||
|
mov byte [fs:BDA_GFX + gfx.cur_mode], al
|
||||||
|
|
||||||
|
pop ax
|
||||||
|
pop fs
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; gfx_set_charpos
|
; gfx_set_charpos
|
||||||
; In : CX = x (pixels), DX = y (pixels)
|
; In : CX = x (pixels), DX = y (pixels)
|
||||||
|
|
@ -181,6 +201,9 @@ cga_calc_addr:
|
||||||
; - stocke aussi shift = x&7
|
; - stocke aussi shift = x&7
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
cga_set_charpos:
|
cga_set_charpos:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
push fs
|
push fs
|
||||||
|
|
||||||
|
|
@ -188,6 +211,9 @@ cga_set_charpos:
|
||||||
mov fs,ax
|
mov fs,ax
|
||||||
|
|
||||||
; store x,y en pixel
|
; store x,y en pixel
|
||||||
|
mov cx, word arg1
|
||||||
|
mov dx, word arg2
|
||||||
|
|
||||||
mov [fs:BDA_GFX + gfx.cur_x], cx
|
mov [fs:BDA_GFX + gfx.cur_x], cx
|
||||||
mov [fs:BDA_GFX + gfx.cur_y], dx
|
mov [fs:BDA_GFX + gfx.cur_y], dx
|
||||||
|
|
||||||
|
|
@ -221,6 +247,7 @@ cga_set_charpos:
|
||||||
|
|
||||||
pop fs
|
pop fs
|
||||||
popa
|
popa
|
||||||
|
leave
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
|
|
@ -256,6 +283,10 @@ get_glyph_offset:
|
||||||
; - écrit sur 2 bytes (di et di+1) dans chaque banque
|
; - écrit sur 2 bytes (di et di+1) dans chaque banque
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
cga_putc:
|
cga_putc:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
sub sp, 2 ; variable locale
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
push fs
|
push fs
|
||||||
push es
|
push es
|
||||||
|
|
@ -265,6 +296,8 @@ cga_putc:
|
||||||
mov bx, BDA_DATA_SEG
|
mov bx, BDA_DATA_SEG
|
||||||
mov fs, bx
|
mov fs, bx
|
||||||
|
|
||||||
|
mov ax, [bp+4] ; arg1
|
||||||
|
|
||||||
call get_glyph_offset
|
call get_glyph_offset
|
||||||
|
|
||||||
; Base offset VRAM pour la scanline Y
|
; Base offset VRAM pour la scanline Y
|
||||||
|
|
@ -272,7 +305,8 @@ cga_putc:
|
||||||
mov bx, [fs:BDA_GFX + gfx.cur_line_ofs]
|
mov bx, [fs:BDA_GFX + gfx.cur_line_ofs]
|
||||||
mov ch, [fs:BDA_GFX + gfx.cur_mode]
|
mov ch, [fs:BDA_GFX + gfx.cur_mode]
|
||||||
mov cl, [fs:BDA_GFX + gfx.cur_shift]
|
mov cl, [fs:BDA_GFX + gfx.cur_shift]
|
||||||
mov bp,4
|
|
||||||
|
mov word [bp-2], 4
|
||||||
|
|
||||||
.row_loop:
|
.row_loop:
|
||||||
; gestion du fond de texte
|
; gestion du fond de texte
|
||||||
|
|
@ -331,7 +365,7 @@ cga_putc:
|
||||||
.next:
|
.next:
|
||||||
add di,CGA_STRIDE
|
add di,CGA_STRIDE
|
||||||
|
|
||||||
dec bp
|
dec word [bp-2]
|
||||||
jnz .row_loop
|
jnz .row_loop
|
||||||
|
|
||||||
; Avancer curseur d'un caractère (8 pixels)
|
; Avancer curseur d'un caractère (8 pixels)
|
||||||
|
|
@ -341,23 +375,32 @@ cga_putc:
|
||||||
pop es
|
pop es
|
||||||
pop fs
|
pop fs
|
||||||
popa
|
popa
|
||||||
|
leave
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;
|
;
|
||||||
; write string from [DS:SI] to screen
|
; write string from [DS:SI] to screen
|
||||||
;
|
;
|
||||||
cga_write:
|
cga_write:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
|
mov ax, arg1
|
||||||
|
mov ds, ax
|
||||||
|
mov si, arg2
|
||||||
|
|
||||||
.loops:
|
.loops:
|
||||||
lodsb
|
lodsb
|
||||||
cmp al,0
|
cmp al,0
|
||||||
je .done
|
je .done
|
||||||
|
push ax
|
||||||
call cga_putc
|
call cga_putc
|
||||||
jmp .loops
|
jmp .loops
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
pop ax
|
pop ax
|
||||||
|
leave
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
|
|
@ -486,9 +529,18 @@ cga_getpixel_fast:
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
; cga_line_vertical
|
; cga_line_vertical
|
||||||
; Dessine une ligne de (AX, BX) à (AX, DX) cl: color
|
; Dessine une ligne x, y0, y1, color
|
||||||
; ------------------------------------------------------------
|
; ------------------------------------------------------------
|
||||||
cga_line_vertical:
|
cga_line_vertical:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
|
||||||
|
; --- Définition des arguments ---
|
||||||
|
%define .x word [bp+4]
|
||||||
|
%define .y1 word [bp+6]
|
||||||
|
%define .y2 word [bp+8]
|
||||||
|
%define .color byte [bp+10] ; (Attention à l'alignement sur pile)
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
push es
|
push es
|
||||||
|
|
||||||
|
|
@ -498,6 +550,9 @@ cga_line_vertical:
|
||||||
|
|
||||||
call cga_mouse_hide
|
call cga_mouse_hide
|
||||||
|
|
||||||
|
mov bx, .y1
|
||||||
|
mov dx, .y2
|
||||||
|
|
||||||
; Ordonner Y (BX < DX)
|
; Ordonner Y (BX < DX)
|
||||||
cmp bx, dx
|
cmp bx, dx
|
||||||
jle .y_sorted
|
jle .y_sorted
|
||||||
|
|
@ -505,11 +560,11 @@ cga_line_vertical:
|
||||||
.y_sorted:
|
.y_sorted:
|
||||||
|
|
||||||
; Calculer l'adresse du premier point (X, Y_Start)
|
; Calculer l'adresse du premier point (X, Y_Start)
|
||||||
push dx ; Sauve Y_Fin
|
; push dx ; Sauve Y_Fin
|
||||||
push cx ; Sauve Couleur
|
; push cx ; Sauve Couleur
|
||||||
|
|
||||||
mov cx, ax ; CX = X (pour cga_calc_addr)
|
mov cx, arg1 ; CX = X (pour cga_calc_addr)
|
||||||
mov dx, bx ; DX = Y_Start (pour cga_calc_addr)
|
mov dx, arg3 ; DX = Y_Start (pour cga_calc_addr)
|
||||||
call cga_calc_addr ; Return: DI=Offset, AH=BitMask (ex: 00100000)
|
call cga_calc_addr ; Return: DI=Offset, AH=BitMask (ex: 00100000)
|
||||||
|
|
||||||
pop cx ; Récup Couleur
|
pop cx ; Récup Couleur
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
;
|
;
|
||||||
; =============================================================================
|
; =============================================================================
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; Détection les ROM supplementaires
|
; Détection les ROM supplementaires
|
||||||
; Teste la RAM de 0xC000 jusqu’à 0xE000, par pas de 2KB.
|
; Teste la RAM de 0xC000 jusqu’à 0xE000, par pas de 2KB.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue