Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 949 → Rev 950

/programs/games/lines/ball_operations.inc
0,0 → 1,183
;ˆ‘Ž‚€ˆ… ˜€ˆŠ€, Ž ‡€„€ŽŒ“ ID ŠŽŠˆ (AX)
paint_ball:
pushad
 
movzx bx, byte [eax*2 + lineCoord - 4]
movzx cx, byte [eax*2 + lineCoord - 3]
 
movzx eax, byte [eax + lineBall - 2]
test eax, eax
jz @F
 
mov edx,[tableColor+eax*4]
 
imul bx, bx, 37
add bx, 11
shl ebx, 16
mov bx, 19 ; ebx=[x start]*65536+[x size]
 
imul cx, cx, 37
add cx, 57
shl ecx, 16
mov cx, 19 ; ecx=[y start]*65536+[y size]
 
mcall 13
@@:
popad
ret
 
 
;Žˆ‘Ž‚Š€ €ŒŠˆ ‚ŽŠ“ƒ ‚›€ŽƒŽ ˜€ˆŠ€ [current]
choice_ball:
pushad
mov eax, [current]
movzx bx, byte [eax*2 + lineCoord - 4]
movzx cx, byte [eax*2 + lineCoord - 3]
 
imul bx, bx, 37
add bx, 3
shl ebx, 16
mov bx, 34 ; ebx=[x start]*65536+[x size]
 
imul cx, cx, 37
add cx, 49
shl ecx, 16
mov cx, 34 ; ecx=[y start]*65536+[y size]
 
mov edx,0x0
mcall 13
popad
ret
 
;……ˆ‘Ž‚Š€ Ÿ—…‰Šˆ (eax)
redraw_cell:
pushad
or eax, 0x80000000
mov edx,eax
mcall 8
 
and edx, 0x7FFFFFFF
movzx bx, byte [edx*2 + lineCoord - 4]
movzx cx, byte [edx*2 + lineCoord - 3]
 
imul bx, bx, 37
add bx, 3
shl ebx, 16
mov bx, 34 ; ebx=[x start]*65536+[x size]
 
imul cx, cx, 37
add cx, 49
shl ecx, 16
mov cx, 34 ; ecx=[y start]*65536+[y size]
 
mov esi, 0x00B8C2D3
mcall 8
 
popad
ret
 
;Ž–…„“€ Ž‚…Šˆ „‹ˆ› ‹ˆˆ‰ ˆ ‘ˆ‚€ˆ… ˜€ˆŠŽ‚
vanish_balls:
 
mov [countVanishBall], 0
mov al, [findUpDown]
cmp al, 4
jb @F
 
add [countVanishBall], al
mov ah, 1
call zero_vanish_matrix
mov ah, 2
call zero_vanish_matrix
@@:
mov al, [findRightLeft]
cmp al, 4
jb @F
 
add [countVanishBall], al
mov ah, 3
call zero_vanish_matrix
mov ah, 4
call zero_vanish_matrix
@@:
mov al, [findUpRight_DownLeft]
cmp al, 4
jb @F
 
add [countVanishBall], al
mov ah, 7
call zero_vanish_matrix
mov ah, 8
call zero_vanish_matrix
@@:
mov al, [findUpLeft_DownRight]
cmp al, 4
jb @F
 
add [countVanishBall], al
mov ah, 5
call zero_vanish_matrix
mov ah, 6
call zero_vanish_matrix
@@:
ret
 
;®¡­ã«ï¥â ¬ âà¨æã ¯® ᮮ⢠§­ ç¥­¨î ah
zero_vanish_matrix:
 
mov ecx, 81
mov edi, lineBall
xor al, al
 
.cycle_zeros:
mov dl, [edi]
shr dl, 4
cmp dl, 0x0F
je @F
cmp dl, ah
je @F
inc edi
jmp .temp
@@:
stosb
push eax
mov eax, edi
sub eax, lineBall - 1
call redraw_cell
pop eax
.temp:
loop .cycle_zeros
ret
 
;ˆ‘“…Œ Ž‚›… –‚…’€
paint_new_color:
movzx eax, [newColor1]
mov edx, [tableColor + eax*4]
mov ebx, 123*65536 + 19
mov ecx, 15*65536 + 19
mcall 13
movzx eax, [newColor2]
mov edx, [tableColor + eax*4]
mov ebx, 160*65536 + 19
mov ecx, 15*65536 + 19
mcall 13
movzx eax, [newColor3]
mov edx, [tableColor + eax*4]
mov ebx, 197*65536 + 19
mov ecx, 15*65536 + 19
mcall 13
ret
 
;ˆ‘“…Œ Ž—Šˆ
redraw_score:
mov ebx, 8*65536 + 100
mov ecx, 20*65536 + 20
mov edx, 0x0
mcall 13
 
mov ebx, 0xB0000
mov ecx, [score]
mov edx, 15*65536 + 27
mov esi, 0x10ffffff
mcall 47
ret
/programs/games/lines/basic_alg.inc
0,0 → 1,128
;Ž–…„“€ Ž‚…Šˆ ‘“™…‘’‚Ž‚€ˆŸ “’ˆ „Ž ŠŽŠˆ [dest] ¨§ EAX
test_path:
pushad
mov cx, [lineCoord + eax*2 - 4]
mov edx, eax
cmp eax, [current]
je .recurs_call
 
cmp eax, [dest]
je .end_yes
 
cmp byte [eax + lineBall - 2], 0
jne .end_no
 
or byte [eax + lineBall - 2], 0x8 ;4-© ¡¨â - 1 (cheked)
 
.recurs_call:
;â㯮© ¢ë§®¢ ¤«ï á®á¥¤­¨å ª«¥â®ª
test cl, cl
jz @F
sub eax, 9
call test_path
jc .end_yes
 
@@:
test cl, 8
jnz @F
mov eax, edx
add eax, 9
call test_path
jc .end_yes
 
@@:
test ch, ch
jz @F
mov eax, edx
dec eax
call test_path
jc .end_yes
 
@@:
test ch, 8
jnz .end_no
mov eax, edx
inc eax
call test_path
jc .end_yes
 
.end_no:
clc
popad
ret
.end_yes:
stc
popad
ret
 
;Ž–…„“€ Žˆ‘Š€ ‘ˆ’›• ‹ˆˆ‰ ([dest] - ID ª­®¯ª¨ ¤«ï ¯®¨áª )
find_line:
mov dword [findRightLeft], 0 ;®¡­ã«ï¥¬ ­ ç «ì­ë¥ §­ ç¥­¨ï
 
mov eax, [dest]
add eax, lineBall - 2
mov dh, [eax]
mov [baseAddr], eax
or byte [eax], 0xF0
 
mov ecx, 8 ;¢ ecx - áç¥â稪
.cycle_find:
lea eax, [ecx*4 + ecx]
shl eax, 1 ;eax = ecx*10
mov edi, [eax + findTable - 4] ;edi - ªã¤ë § ¯¨á뢠âì १-âë
mov ebp, [eax + findTable - 8] ;ebp - ¯à¨¡ ¢«¥­¨¥  ¤à¥á 
mov bx, [eax + findTable - 10] ;bx - ¯à¨¡ ¢«¥­¨¥ ª®®à¤¨­ â
mov dl, cl
shl dl, 4
mov esi, [baseAddr]
mov eax, [dest]
mov ax, [eax*2 + lineCoord - 4]
.small_cycle_find:
add al, bh
cmp al, 8 ;¢ [0..8] ?
ja @F
add ah, bl
cmp ah, 8
ja @F
 
add esi, ebp
cmp byte [esi], dh
jne @F
 
or byte [esi], dl
inc byte [edi]
jmp .small_cycle_find
@@:
loop .cycle_find
ret
 
findRightLeft db ?
findUpRight_DownLeft db ?
findUpDown db ?
findUpLeft_DownRight db ?
 
findTable:
Up:
db -1, 0
dd -1, findUpDown
Down:
db +1, 0
dd +1, findUpDown
Left:
db 0, -1
dd -9, findRightLeft
Right:
db 0, +1
dd +9, findRightLeft
UpLeft:
db -1, -1
dd -10, findUpLeft_DownRight
DownRight:
db +1, +1
dd +10, findUpLeft_DownRight
UpRight:
db -1, +1
dd +8, findUpRight_DownLeft
DownLeft:
db +1, -1
dd -8, findUpRight_DownLeft
/programs/games/lines/build_en.bat
0,0 → 1,5
@erase lang.inc
@echo lang fix en >lang.inc
@fasm lines.asm lines.kex
@erase lang.inc
@pause
/programs/games/lines/build_ru.bat
0,0 → 1,5
@erase /s lang.inc > nul
@echo lang fix ru >lang.inc
@fasm lines.asm lines.kex
@erase lang.inc
@pause
/programs/games/lines/draw_window.inc
0,0 → 1,71
;======================================================================
;=============== WINDOW DEFINITIONS AND DRAW ========================
;======================================================================
macro draw_window {
mcall 12, 1 ;­ ç¨­ ¥¬ ¯¥à¥à¨á®ªã ®ª­ 
 
mov ebx, 100*65536 + 347 ; [x start] *65536 + [x size]
mov ecx, 100*65536 + 465 ; [y start] *65536 + [y size]
mov edx, 0x33D0D6C9 ; color of work area RRGGBB,8->color gl
mov edi, szTitle ; § £®«®¢®ª
mcall 0 ; ­ à¨á®¢ âì ®ª­®
 
 
mov ebx, 12*65536 + 7 ;ˆ‘“…Œ Ž—Šˆ
mov ecx, 0x90000000
mov edx, szScore
mcall 4
call redraw_score
 
mov ebx, 234*65536 + 7 ;ˆ‘“…Œ …ŠŽ„
mov ecx, 0x90000000
mov edx, szRecord
mcall 4
 
mov ebx, 230*65536 + 100
mov ecx, 20*65536 + 20
mov edx, 0x0
mcall 13
 
mov ebx, 0xB0000
mov ecx, [record]
mov edx, 237*65536 + 27
mov esi, 0x10ffffff
mcall 47
 
mov ebx, 115*65536 + 34 ;ˆ‘“…Œ Œ…‘’Ž Ž„ Ž‚›… –‚…’€
mov ecx, 7*65536 + 34
mov edx, 0x00B8C2D3
@@:
mcall 13
add ebx, 37*65536
cmp ebx, 189*65536 + 34
jbe @B
 
call paint_new_color
 
mov ebx, 20*65536 + 400 ;ˆ‘“…Œ “€‚‹Ÿž™ˆ… ŠŽŠˆ ‘ˆ‡“
mov ecx, 0x90000000
mov edx, szNewGame
mcall 4
 
mov ecx,9 ;ˆ‘“…Œ Ž‘Ž‚›… ŠŽŠˆ
mov edx, 82
 
.drm1:
mov ebx,ecx
mov ecx,9
.drm2:
mov eax, edx
call redraw_cell
cmp eax, [current]
jne @F
call choice_ball
@@:
call paint_ball
dec edx
loop .drm2
mov ecx,ebx
loop .drm1
mcall 12,2
}
/programs/games/lines/lines.asm
0,0 → 1,275
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 ;¯à¨­¨¬ ¥¬ ᪠­-ª®¤ë
mcall 3 ;randomize
ror eax, 16
mov [TC_U_SYSTEM_RANDSEED], eax ;from PPro "system.inc"
 
new_game:
;®¡­ã«¥­¨¥ ¬ âà¨æë
mov eax, 0
mov ecx, 81 / 4
mov edi, lineBall
rep stosd
stosb
 
mov [score], 0
mov [countAllBall], 0
mov [current], 0
mov ecx, 5
@@:
push ecx
mov ebx, 7
call random
inc dl
call add_new_ball
pop ecx
loop @B
call generate_new___new_color
 
START:
draw_window
still:
mcall 10
 
dec eax
jz START ; ¯¥à¥à¨á®¢ âì ®ª­®
dec eax
jnz button ;¥á«¨ ­¥ ª« ¢¨è  - §­ ç¨â ª­®¯ª 
 
key: ; ­ ¦ â¨¥ ª« ¢¨è¨
mcall 2 ; ¯®«ãç ¥¬ ª®¤ ª« ¢¨è¨
cmp ah, 60
je new_game
jmp still
 
button: ; ­ ¦ â¨¥ ª­®¯ª¨
mcall 17
shr eax, 8
cmp ax, 1 ; ¥á«¨ ª­®¯ª  ¢ë室 ?
je .exit
 
;¯à®¢¥à¨¬, ­¥ ¯ãáâ  «¨ ª«¥âª 
mov edx, [current]
test byte [eax + lineBall - 2], 0x7
jz .blank
 
;¯à®¢¥à¨¬ ­¥ ¡ë«  «¨ íâ  ª«¥âª  㦥 ¢ë¡à ­ 
cmp eax, edx
je .double_choice
 
mov [current], eax
call choice_ball
call paint_ball ;á­ ç «  ¯à®à¨á㥬 ­®¢ë© ¢ë¡à ­­ë© è à¨ª
 
test edx, edx ;cmp [current], 0
jz still
mov eax, edx
 
@@:
call redraw_cell ;  㦥 ¯®â®¬ 㡥६ à ¬ªã ®â áâ à®£®
call paint_ball
jmp still
 
.double_choice:
mov [current], 0
jmp @B
 
.blank: ;­ ¦ â ï ª­®¯ª  - ¯ãáâ 
test edx, edx ;cmp [current], 0
jz still
mov [dest], eax ;ª­®¯ªã ­ §­ ç¥­¨ï -> ¢ [dest]
mov eax, edx ;¯ à ¬¥âà ¢ eax
call test_path ;¢ë§ë¢ ¥¬ ४ãàá¨î 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 ;¢ë室¨¬
 
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: ;®¡­ã«¥­¨¥ ¬ âà¨æë 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: ;¢ dl - 梥â è à¨ª 
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
 
;⥯¥àì ã ­ á ¢ eax -  ¤à¥á ­ è¥£® è à¨ª 
mov edx, ebp
or byte [eax], dl
inc [countAllBall]
ret
 
test_new_ball:
;¯®«ã稬 ID ª­®¯ª¨
sub eax, lineBall-2
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 '–¢¥â­ë¥ «¨­¨¨ v 0.2',0
szNewGame db 'F2 - ­®¢ ï ¨£à ',0
szRecord db '¥ª®à¤',0
szScore db 'Žçª¨',0
else
szTitle db 'Color lines v 0.2',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:
/programs/games/lines/.
Property changes:
Added: tsvn:logminsize
+5
\ No newline at end of property