kolibrios/programs/games/lines/lines.asm

275 lines
4.6 KiB
NASM
Raw Normal View History

use32
org 0x0
db 'MENUET01'
dd 0x01
dd _preSTART
dd I_END
dd 0x4000
dd 0x4000
dd 0x0,0x0
include 'macros.inc'
include 'lang.inc'
include 'draw_window.inc'
include 'ball_operations.inc'
include 'basic_alg.inc'
_preSTART:
mcall 66, 1, 1 ;<3B><EFBFBD><E0A8AD><EFBFBD><EFBFBD><EFBFBD><>-<2D><><EFBFBD><EFBFBD>
mcall 3 ;randomize
ror eax, 16
mov [TC_U_SYSTEM_RANDSEED], eax ;from PPro "system.inc"
new_game:
;<3B><><EFBFBD><EFBFBD><E3ABA5><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mov eax, 0
mov ecx, 81 / 4
mov edi, lineBall
rep stosd
stosb
mov [score], 0
mov [countAllBall], 0
mov [current], 0
@@:
mov ebx, 7
call random
inc dl
call add_new_ball
call test_new_ball
cmp [countAllBall], 5
jb @b
call generate_new___new_color
START:
draw_window
still:
mcall 10
dec eax
jz START ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1AEA2><EFBFBD> <20><><EFBFBD><EFBFBD>
dec eax
jnz button ;<3B><20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
key: ; <20><><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mcall 2 ; <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cmp ah, 60
je new_game
jmp still
button: ; <20><><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mcall 17
shr eax, 8
cmp ax, 1 ; <20><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>?
je .exit
;<3B><EFBFBD>ਬ, <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD>
mov edx, [current]
test byte [eax + lineBall - 2], 0x7
jz .blank
;<3B><EFBFBD><20><> <20><20><> <20><><EFBFBD> <20><><EFBFBD>⪠ 㦥 <20><><EFBFBD><EFBFBD>
cmp eax, edx
je .double_choice
mov [current], eax
call choice_ball
call paint_ball ;᭠砫<E1ADA0> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><E0A0AD><EFBFBD> <20><>
test edx, edx ;cmp [current], 0
jz still
mov eax, edx
@@:
call redraw_cell ;<3B><20><>⮬ 㡥६ ࠬ<><E0A0AC> <20><> <20><><EFBFBD><EFBFBD>
call paint_ball
jmp still
.double_choice:
mov [current], 0
jmp @B
.blank: ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD>
test edx, edx ;cmp [current], 0
jz still
mov [dest], eax ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7A5AD> -> <20> [dest]
mov eax, edx ;<3B><><EFBFBD><E0A0AC><EFBFBD> <20> eax
call test_path ;<3B><><EFBFBD><EFBFBD><EBA2A0><><E0A5AA><EFBFBD><EFBFBD><EFBFBD> test_path
call zero_cheked
jnc still
;^^^^^^^^^^^^^^^^^ move_ball proc
mov eax, [current]
mov cl, byte [eax + lineBall - 2]
mov byte [eax + lineBall - 2], 0
mov eax, [dest]
mov byte [eax + lineBall - 2], cl
mov eax, [current]
call redraw_cell
mov eax, [dest]
call paint_ball
mov [current], 0
;^^^^^^^^^^^^^^^^^ move_ball endp
call find_line
call vanish_balls
call zero_cheked
cmp [countVanishBall], 0
je new_3_balls
movzx eax, [countVanishBall]
inc eax
add [score], eax
sub [countAllBall], al
call redraw_score
jmp still
.exit:
mcall -1 ;<3B><><EFBFBD><E5AEA4>
new_3_balls:
rept 3 num
{
mov dl, [newColor#num]
call add_new_ball
call test_new_ball
cmp [countAllBall],81
je .record_li
}
call generate_new___new_color
call paint_new_color
jmp still
.record_li:
mov eax, [score]
cmp eax, [record]
jbe still
mov [record], eax
jmp START
zero_cheked: ;<3B><><EFBFBD><EFBFBD><E3ABA5><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cheked
pushfd
mov eax, lineBall
mov ecx, 81
@@:
and byte [eax], 0x7
inc eax
loop @B
popfd
ret
random: ; edx := random [0..(ebx-1)]
mov eax, 134775813
mul [TC_U_SYSTEM_RANDSEED]
inc eax
mov [ TC_U_SYSTEM_RANDSEED], eax
xor edx, edx
div ebx
ret
generate_new___new_color:
rept 3 num
{
mov ebx, 7
call random
inc dl
mov [newColor#num], dl
}
ret
add_new_ball: ;<3B> dl - 梥<> <20><><EFBFBD>
mov ebp, edx
mov ebx, 81
sub bl, [countAllBall]
call random
mov ecx, edx
mov eax, lineBall-1
inc ecx
@@:
inc eax
test byte [eax], 0x7
jnz @B
loop @B
;⥯<><E2A5AF><EFBFBD> <20> <20><><EFBFBD> <20> eax - <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD>
mov edx, ebp
or byte [eax], dl
inc [countAllBall]
;<3B><><EFBFBD><EFBFBD>稬 ID <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sub eax, lineBall-2
mov [dest], eax
ret
test_new_ball:
call paint_ball
call find_line
call vanish_balls
call zero_cheked
cmp [countVanishBall], 0
je @F
movzx eax, [countVanishBall]
inc eax
add [score], eax
sub [countAllBall], al
call redraw_score
@@:
ret
if lang eq ru
szTitle db '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> v 0.3',0
szNewGame db 'F2 - <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>',0
szRecord db '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',0
szScore db '<27>窨',0
else
szTitle db 'Color lines v 0.3',0
szNewGame db 'F2 - new game',0
szRecord db 'Record',0
szScore db 'Score',0
end if
blank = 0xB8C2D3
brown = 0x804000
red = 0xff0000
yellow = 0xffff00
green = 0x008000
cyan = 0x00ffff
blue = 0x0000ff
purple = 0x800080
tableColor dd blank,brown,red,yellow,green,cyan,blue,purple
lineCoord:
rept 9 coory:0
{
rept 9 coorx:0
\{
dw coorx*256+coory
\}
}
record dd 25
lineBall db 81 dup ?
score dd ?
baseAddr dd ?
current dd ?
dest dd ?
newColor1 db ?
newColor2 db ?
newColor3 db ?
countVanishBall db ?
countAllBall db ?
TC_U_SYSTEM_RANDSEED dd ?
bitID dd ?
I_END: