Files
kolibrios/programs/games/snake/functions.asm
Aleksey Surkov f969aec650
Some checks failed
Build system / Check kernel codestyle (pull_request) Successful in 21s
Build system / Build (pull_request) Failing after 2m23s
translating and fixing comments
2026-02-22 15:06:18 +04:00

161 lines
5.6 KiB
NASM

; -----------------------------
; Draws a button with a text label
; input: pLabel - pointer to the LABEL structure
; id - button identifier
; xPosition - button position X
; yPosition - button position Y
; bWidth - button width
; bHeight - button height
; -----------------------------
proc draw.Button pLabel, id, xPosition, yPosition, bWidth, bHeight
mcall 8, <[xPosition], [bWidth]>, <[yPosition], [bHeight]>, [id], [button_color]
; position X for text positioning
mov eax, [bHeight]
shr eax, 1
add [yPosition], eax
; position Y for text positioning
mov eax, [pLabel]
mov eax, [eax+LABEL.size]
neg eax
mul [configFont.width]
add eax, [bWidth]
add eax, 4
shr eax, 1
add [xPosition], eax
; draw text on the button
stdcall draw.Label, [pLabel], [xPosition], [yPosition]
ret
endp
; -----------------------------
; Draws text on position yPosition and centered on the width of the screen
; considering the length of the text and the offset in symbols
; input: pLabel - pointer to the LABEL structure
; yPosition - text position Y
; countOffset - number of symbols for offset
; -----------------------------
proc draw.Label pLabel, yPosition, countOffset
mov eax, [pLabel]
mov eax, [eax + LABEL.size]
sub eax, [countOffset]
stdcall draw.GetNavigationX, eax
stdcall draw.Label, [pLabel], eax, [yPosition], 0
ret
endp
; -----------------------------
; Draws a number on position yPosition and centered on the width of the screen
; considering the length of the number and the offset in symbols
; input: pLabel - pointer to the LABEL structure
; yPosition - text position Y
; countOffset - number of symbols for offset
; -----------------------------
proc draw.NavigationNumber pLabel, yPosition, countOffset
mov eax, [pLabel]
mov eax, [eax + LABEL.size]
sub eax, [countOffset]
stdcall draw.GetNavigationX, eax
stdcall draw.Number, [pLabel], eax, [yPosition], 0
ret
endp
; -----------------------------
; Returns the X coordinate for the text positioning on the center of the screen
; considering the offset in symbols
; input: countOffset - number of symbols for offset
; output: eax - X coordinate
; -----------------------------
proc draw.GetNavigationX countOffset
mov eax, [countOffset]
neg eax
mul [configFont.width]
add eax, [window_width]
sub eax, 10
shr eax, 1
ret
endp
; -----------------------------
; Builds the coordinates of the text label adding the offset in symbols along X
; input: xPosition - X coordinate
; yPosition - Y coordinate
; countOffset - number of symbols for offset
; output: eax - X coordinate in format X*65536+Y
; -----------------------------
proc draw._prepareCoord xPosition, yPosition, countOffset
mov eax, [countOffset]
mul [configFont.width]
add eax, [xPosition]
shl eax, 16
mov ebx, [configFont.height]
shr ebx, 1
sub [yPosition], ebx
add eax, [yPosition]
ret
endp
; -----------------------------
; Draws the text at the X and Y positions and shifts the offset in symbols along X
; input: pLabel - pointer to the LABEL structure
; xPosition - text position X
; yPosition - text position Y
; countOffset - number of symbols for offset
; -----------------------------
proc draw.Label pLabel, xPosition, yPosition, countOffset
stdcall draw._prepareCoord, [xPosition], [yPosition], [countOffset]
mov ebx, eax
mov eax, [pLabel]
mov ecx, [configFont.mask]
or ecx, [eax + LABEL.color]
mov edx, [eax + LABEL.value]
mcall 4
ret
endp
; -----------------------------
; Draws the number at the X and Y positions and shifts the offset in symbols along X
; input: pLabel - pointer to the LABEL structure
; xPosition - text position X
; yPosition - text position Y
; countOffset - number of symbols for offset
; -----------------------------
proc draw.Number pLabel, xPosition, yPosition, countOffset
stdcall draw._prepareCoord, [xPosition], [yPosition], [countOffset]
mov edx, eax
mov eax, [pLabel]
mov ebx, [eax + LABEL.size]
shl ebx, 16
mov ecx, [eax + LABEL.value]
mov esi, [configFont.maskNumber]
or esi, [eax + LABEL.color]
mcall 47, , , , ,[background_color]
ret
endp
; -----------------------------
; Set configuration of the font depending on the size of the square side
; setting the font size and the font mask text and number
; input: squareSideLength - size of the square side
; -----------------------------
proc draw.setConfigFont squareSideLength
cmp [squareSideLength], MIN_SQUARE_SIDE_LENGTH_FONT
jg @f
cmp [configFont.flag], FONT_SMALL
je .return
mov [configFont.flag], FONT_SMALL
jmp .set
@@:
cmp [configFont.flag], FONT_LARGE
je .return
mov [configFont.flag], FONT_LARGE
.set:
mov eax, [configFont.flag]
lea ebx, [eax + 8]
shl ebx, 28
mov [configFont.mask], ebx
lea ebx, [eax*2 + 6]
mov [configFont.width], ebx
lea ebx, [7 + eax*4]
lea ebx, [ebx + eax*2]
mov [configFont.height], ebx
lea ebx, [eax + 4]
shl ebx, 28
mov [configFont.maskNumber], ebx
.return:
ret
endp