Files
kolibrios/programs/games/snake/functions.asm
Aleksey Surkov 82c9cca556
Some checks failed
Build system / Check kernel codestyle (pull_request) Successful in 43s
Build system / Build (pull_request) Failing after 2m23s
convert utf-8 and refactoring draw buttons
2026-02-17 00:18:12 +04:00

164 lines
6.6 KiB
NASM
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
; -----------------------------
; Рисует кнопку с текстовой меткой
; input: pLabel - указатель на структуру LABEL
; id - идентификатор кнопки
; xPosition - позиция X
; yPosition - позиция Y
; bWidth - ширина кнопки
; bHeight - высота кнопки
; -----------------------------
proc draw.Button pLabel, id, xPosition, yPosition, bWidth, bHeight
mcall 8, <[xPosition], [bWidth]>, <[yPosition], [bHeight]>, [id], [button_color]
; позиция X для размещения текста
mov eax, [bHeight]
shr eax, 1
add [yPosition], eax
; позиция Y для размещения текста
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
; размещаем текст на кнопке
stdcall draw.Label, [pLabel], [xPosition], [yPosition]
ret
endp
; -----------------------------
; Рисует текст по yPosition и центрируя текст по ширине экрана
; с учетом длины текста и указанного смещения в символах
; input: pLabel - указатель на структуру LABEL
; yPosition - позиция Y
; countOffset - кол-во символов для смещения
; -----------------------------
proc draw.Navigation 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
; -----------------------------
; Рисует число по yPosition и центрируя число по ширине экрана
; с учетом длины числа и указанного смещения в символах
; input: pLabel - указатель на структуру LABEL
; yPosition - позиция Y
; countOffset - кол-во символов для смещения
; -----------------------------
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
; -----------------------------
; Возвращает координату X для размещения текста по центру экрана
; с учетом указанного смещения в символах
; input: countOffset - кол-во символов для смещения
; output: eax - координата X
; -----------------------------
proc draw.GetNavigationX countOffset
mov eax, [countOffset]
neg eax
mul [configFont.width]
add eax, [window_width]
sub eax, 10
shr eax, 1
ret
endp
; -----------------------------
; Формирует в одном регистре координаты в нужном формате добавляя
; ширину смещения символов по X если указано кол-во
; input: xPosition - позиция по X
; yPosition - позиция по Y
; countOffset - кол-во символов для смещения
; output: eax - координата в формате 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
; -----------------------------
; Рисует текст по указанной позиции X и Y
; и смещает на ширину символов по X если указано
; input: pLabel - указатель на структуру LABEL
; xPosition - позиция X
; yPosition - позиция Y
; countOffset - кол-во символов для смещения
; -----------------------------
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
; -----------------------------
; Рисует число по указанной позиции X и Y
; и смещает на ширину символов по X если указано
; input: pLabel - указатель на структуру LABEL
; xPosition - позиция X
; yPosition - позиция Y
; countOffset - кол-во символов для смещения
; -----------------------------
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
; -----------------------------
; Установить настройки шрифта в зависимости от размера ячейки
; устанавливает высоту, ширину символа и маску для рисования текста и числа
; input: squareSideLength - размер ячейки
; -----------------------------
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