Files
kolibrios/programs/games/snake/functions.asm
Aleksey Surkov 8e006128c8
Some checks failed
Build system / Check kernel codestyle (pull_request) Successful in 2m5s
Build system / Build (pull_request) Failing after 2m57s
game snake refactoring
2026-02-01 18:49:13 +04:00

144 lines
4.7 KiB
NASM
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
macro defLabel name, color, [text]
{
common
local ..str
..str db text, 0
name#.len = $ - ..str - 1
name LABEL color, name#.len, ..str
}
macro defNumber name, color, size
{
common
name#.len = size
name LABEL color, name#.len, 0
}
; -----------------------------
; <20>¨áã¥â ⥪áâ ¯® yPosition ¨ 業âà¨àãï ⥪áâ ¯® è¨à¨­¥ íªà ­ 
; á ãç¥â®¬ ¤«¨­ë ⥪áâ  ¨ 㪠§ ­­®£® ᬥ饭¨ï ¢ ᨬ¢®« å
; input: pText - 㪠§ â¥«ì ­  áâàãªâãàã
; yPosition - ¯®§¨æ¨ï Y
; countOffset - ª®«-¢® ᨬ¢®«®¢ ¤«ï ᬥ饭¨ï
; -----------------------------
proc draw.Navigation pText, yPosition, countOffset
mov eax, [pText]
mov eax, [eax + LABEL.size]
sub eax, [countOffset]
stdcall draw.GetNavigationX, eax
stdcall draw.Label, [pText], eax, [yPosition], 0
ret
endp
; -----------------------------
; <20>¨áã¥â ç¨á«® ¯® yPosition ¨ 業âà¨àãï ç¨á«® ¯® è¨à¨­¥ íªà ­ 
; á ãç¥â®¬ ¤«¨­ë ç¨á«  ¨ 㪠§ ­­®£® ᬥ饭¨ï ¢ ᨬ¢®« å
; input: pNumber - 㪠§ â¥«ì ­  áâàãªâãàã
; yPosition - ¯®§¨æ¨ï Y
; countOffset - ª®«-¢® ᨬ¢®«®¢ ¤«ï ᬥ饭¨ï
; -----------------------------
proc draw.NavigationNumber pNumber, yPosition, countOffset
mov eax, [pNumber]
mov eax, [eax + LABEL.size]
sub eax, [countOffset]
stdcall draw.GetNavigationX, eax
stdcall draw.Number, [pNumber], 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
add eax, [yPosition]
ret
endp
; -----------------------------
; <20>¨áã¥â ⥪áâ ¯® 㪠§ ­­®© ¯®§¨æ¨¨ X ¨ Y
; ¨ ᬥ頥⠭  è¨à¨­ã ᨬ¢®«®¢ ¯® X ¥á«¨ 㪠§ ­®
; input: pText - 㪠§ â¥«ì ­  áâàãªâãàã
; xPosition - ¯®§¨æ¨ï X
; yPosition - ¯®§¨æ¨ï Y
; countOffset - ª®«-¢® ᨬ¢®«®¢ ¤«ï ᬥ饭¨ï
; -----------------------------
proc draw.Label pText, xPosition, yPosition, countOffset
stdcall draw._prepareCoord, [xPosition], [yPosition], [countOffset]
mov ebx, eax
mov eax, [pText]
mov ecx, [configFont.mask]
or ecx, [eax + LABEL.color]
mov edx, [eax + LABEL.value]
mcall 4
ret
endp
; -----------------------------
; <20>¨áã¥â ç¨á«® ¯® 㪠§ ­­®© ¯®§¨æ¨¨ X ¨ Y
; ¨ ᬥ頥⠭  è¨à¨­ã ᨬ¢®«®¢ ¯® X ¥á«¨ 㪠§ ­®
; input: pNumber - 㪠§ â¥«ì ­  áâàãªâãàã
; xPosition - ¯®§¨æ¨ï X
; yPosition - ¯®§¨æ¨ï Y
; countOffset - ª®«-¢® ᨬ¢®«®¢ ¤«ï ᬥ饭¨ï
; -----------------------------
proc draw.Number pNumber, xPosition, yPosition, countOffset
stdcall draw._prepareCoord, [xPosition], [yPosition], [countOffset]
mov edx, eax
mov eax, [pNumber]
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, [8 + eax*4]
mov [configFont.height], ebx
lea ebx, [eax + 4]
shl ebx, 28
mov [configFont.maskNumber], ebx
.return:
ret
endp