Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 30 → Rev 31

/programs/tetris/trunk/block.inc
0,0 → 1,376
;--------------------------------------------------------------
;DRAW BLOCK
;
;--------------------------------------------------------------
draw_block: mov eax,13
mov edx,[color_table+edx*4]
 
mov ebx,[current_block_x]
mov ecx,[current_block_y]
mov edi,[current_block_pointer]
 
sub ebx,BORDER_LEFT
imul ebx,ADOBE_SIZE
add ebx,X_LOCATION
shl ebx,16
mov bx,ADOBE_SIZE
 
sub ecx,BORDER_TOP
imul ecx,ADOBE_SIZE
add ecx,Y_LOCATION
shl ecx,16
mov cx,ADOBE_SIZE
 
mov dword [TMP_1],4
adr_122: mov dword [TMP_0],4
adr_121: cmp byte [edi],0
je adr_120
 
int 040h
 
call draw_frames
 
adr_120: inc edi
add ebx,ADOBE_SIZE*65536
dec dword [TMP_0]
jnz adr_121
sub ebx,4*ADOBE_SIZE*65536
add ecx,ADOBE_SIZE*65536
dec dword [TMP_1]
jnz adr_122
 
ret
 
draw_frames:
cmp edx,0
jne df1
ret
df1:
pusha
mov bx,1
add edx,0x282828
mov eax,13
int 0x40
popa
 
pusha
mov cx,1
add edx,0x282828
mov eax,13
int 0x40
popa
 
pusha
push ebx
sub bx,1
add [esp+2],bx
pop ebx
mov bx,1
shr edx,1
and edx,0x7f7f7f
mov eax,13
int 0x40
popa
 
pusha
push ecx
sub cx,1
add [esp+2],cx
pop ecx
mov cx,1
shr edx,1
and edx,0x7f7f7f
mov eax,13
int 0x40
popa
 
ret
 
;-------------------------------------------------------------
; FIX BLOCK
;-------------------------------------------------------------
fix_block: mov ebx,[current_block_pointer]
 
mov edx,[current_block_y]
imul edx,LEN_X
add edx,[current_block_x] ;find the offset in tetris_t
 
add edx,table_tetris
 
mov ecx,4
mov al,[current_block_color]
 
adr_21: cmp byte [ebx],1
jne adr_22
mov [edx],al
adr_22: inc ebx
inc edx
 
cmp byte [ebx],1
jne adr_23
mov [edx],al
adr_23: inc ebx
inc edx
 
cmp byte [ebx],1
jne adr_24
mov [edx],al
adr_24: inc ebx
inc edx
 
cmp byte [ebx],1
jne adr_25
mov [edx],al
adr_25: inc ebx
add edx,LEN_X-3
 
loop adr_21
ret
 
;-------------------------------------------------------------
;NEW BLOCK
;-------------------------------------------------------------
new_block: mov dword [current_block_y],1
mov dword [current_block_x],7
 
mov eax,dword [next_block_pointer]
mov dword [current_block_pointer],eax
 
mov eax,dword [next_block_color]
mov dword [current_block_color],eax
 
call random
and al,7
setz ah
add al,ah
mov [next_block_color],al
 
call random
;and eax,15
; ---- Ivan ----
and eax,0xff
@@:
cmp eax,_MAXBLOCKS_
jl @f
add eax,-(_MAXBLOCKS_)
jmp @b
@@:
; ---- Ivan ----
mov edx,[block_table+eax*4]
mov [next_block_pointer],edx
 
mov dword[delay],5
sub dword[delay],speed
 
ret
 
 
;-------------------------------------------------------------
;DRAW TITLE BLOCK
;-------------------------------------------------------------
draw_title_block:
; movzx edx,byte [current_block_color]
mov eax,13
 
; mov edx,[color_table+edx*4]
 
; mov ebx,[current_block_x]
; mov ecx,[current_block_y]
; mov edi,[current_block_pointer]
 
sub ebx,BORDER_LEFT
imul ebx,ADOBE_SIZE
add ebx,X_LOCATION
shl ebx,16
mov bx,ADOBE_SIZE
 
sub ecx,BORDER_TOP
imul ecx,ADOBE_SIZE
add ecx,Y_LOCATION
shl ecx,16
mov cx,ADOBE_SIZE
 
mov dword [TMP_1],5
call adr_122
 
ret
 
;-------------------------------------------------------------
;FIRST BLOCK
;-------------------------------------------------------------
first_block: call random
and al,7
setz ah
add al,ah
mov [next_block_color],al
 
call random
;and eax,15
; ---- Ivan ----
and eax,0xff
@@:
cmp eax,_MAXBLOCKS_
jl @f
add eax,-(_MAXBLOCKS_)
jmp @b
@@:
; ---- Ivan ----
mov edx,[block_table+eax*4]
mov [next_block_pointer],edx
 
; call draw_next_block
 
; mov byte [delay],5 ;19 ;!!! 15
ret
ret
 
;-------------------------------------------------------------
;DRAW NEXT BLOCK
;-------------------------------------------------------------
 
draw_next_block:
movzx edx,byte [next_block_color]
mov eax,13
mov edx,[color_table+edx*4]
 
mov ebx,LEN_X+1
mov ecx,5
mov edi,[next_block_pointer]
 
sub ebx,BORDER_LEFT
imul ebx,ADOBE_SIZE
add ebx,X_LOCATION
shl ebx,16
mov bx,ADOBE_SIZE
 
sub ecx,BORDER_TOP
imul ecx,ADOBE_SIZE
add ecx,Y_LOCATION
shl ecx,16
mov cx,ADOBE_SIZE
 
mov dword [TMP_1],4
jmp adr_122
 
ret
 
;-------------------------------------------------------------
; ROTATE BLOCK
;-------------------------------------------------------------
 
rotate_block:
mov edx,[current_block_pointer]
mov edx,[edx+16]
mov esi,[current_block_pointer]
mov [current_block_pointer],edx
call check_crash
call attesa
mov [current_block_pointer],esi
 
ret
 
 
;-------------------------------------------------------------
; CHECK CRASH
; output Z flag => OK
; NZ flag => NO
;-------------------------------------------------------------
 
check_crash: mov ebx,[current_block_pointer]
 
mov edx,[current_block_y]
imul edx,LEN_X
add edx,[current_block_x] ;find the offset in tetris_t
 
add edx,table_tetris
 
mov ecx,4
xor ax,ax
 
adr_1: cmp byte [ebx],1
jne adr_2
add al,[edx]
adc ah,0
adr_2: inc ebx
inc edx
 
cmp byte [ebx],1
jne adr_3
add al,[edx]
adc ah,0
adr_3: inc ebx
inc edx
 
cmp byte [ebx],1
jne adr_4
add al,[edx]
adc ah,0
adr_4: inc ebx
inc edx
 
cmp byte [ebx],1
jne adr_5
add al,[edx]
adc ah,0
adr_5: inc ebx
add edx,LEN_X-3
 
loop adr_1
or ax,ax
ret
 
;--------------------------------------------------------------
;CHECK LINE
;--------------------------------------------------------------
;edx = pointer
;ebx = contatore
check_full_line:
std
mov al,0
mov edx,table_tetris+LEN_X*(LEN_Y-BORDER_BOTTOM)-1
mov ebx,(LEN_Y-BORDER_TOP-BORDER_BOTTOM-1)*LEN_X
 
adr_5000: mov edi,edx
mov ecx,LEN_X-BORDER_LEFT-BORDER_RIGHT
repne scasb
jz no_full_line
 
lea esi,[edx-LEN_X]
mov edi,edx
mov ecx,ebx
rep movsb
sub edi,BORDER_RIGHT
mov ecx,LEN_X-BORDER_LEFT-BORDER_RIGHT
rep stosb
 
add dword [score],100
add dword [lines],1
 
; mov esi,dword[score]
;
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; mov esi,dword [speed]
; imul esi,linestonewlevel
; add esi,linestonewlevel
; cmp dword [lines],esi
; jne adr_5000 1 line : 100
; cmp dword[speed],4 2 lines: 300
; je adr_51 3 lines: 700
; inc dword[speed] 4 lines:1500
; jmp adr_5000
; adr_51:
; mov dword[speed],0
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
jmp adr_5000
 
no_full_line: sub edx,LEN_X
sub ebx,LEN_X
jnz adr_5000
 
ret
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/blocks.inc
0,0 → 1,235
;+---------------------------------+
;| DEFINITION BLOCKS |
;+---------------------------------+
 
t_block_0:
db 0,0,0,0
db 1,1,1,0
db 0,1,0,0
db 0,0,0,0
dd t_block_3
 
t_block_1:
db 0,1,0,0
db 1,1,0,0
db 0,1,0,0
db 0,0,0,0
dd t_block_0
 
t_block_2:
db 0,1,0,0
db 1,1,1,0
db 0,0,0,0
db 0,0,0,0
dd t_block_1
 
t_block_3:
db 0,1,0,0
db 0,1,1,0
db 0,1,0,0
db 0,0,0,0
dd t_block_2
 
;-----------------------------------
 
i_block_0:
db 0,1,0,0
db 0,1,0,0
db 0,1,0,0
db 0,1,0,0
dd i_block_1
 
i_block_1:
db 0,0,0,0
db 1,1,1,1
db 0,0,0,0
db 0,0,0,0
dd i_block_0
;-----------------------------------
 
q_block_0:
db 0,1,1,0
db 0,1,1,0
db 0,0,0,0
db 0,0,0,0
dd q_block_0
 
;-----------------------------------
 
s_block_0:
db 0,0,0,0
db 0,1,1,0
db 1,1,0,0
db 0,0,0,0
dd s_block_1
 
s_block_1:
db 1,0,0,0
db 1,1,0,0
db 0,1,0,0
db 0,0,0,0
dd s_block_0
 
;-----------------------------------
 
l_block_0:
db 0,0,0,0
db 1,1,1,0
db 1,0,0,0
db 0,0,0,0
dd l_block_3
 
l_block_1:
db 1,1,0,0
db 0,1,0,0
db 0,1,0,0
db 0,0,0,0
dd l_block_0
 
l_block_2:
db 0,0,1,0
db 1,1,1,0
db 0,0,0,0
db 0,0,0,0
dd l_block_1
 
l_block_3:
db 0,1,0,0
db 0,1,0,0
db 0,1,1,0
db 0,0,0,0
dd l_block_2
 
;-----------------------------------
 
g_block_0:
 
db 0,1,0,0
db 0,1,0,0
db 1,1,0,0
db 0,0,0,0
dd g_block_1
 
g_block_1:
db 0,0,0,0
db 1,1,1,0
db 0,0,1,0
db 0,0,0,0
dd g_block_2
 
g_block_2:
db 0,1,1,0
db 0,1,0,0
db 0,1,0,0
db 0,0,0,0
dd g_block_3
 
g_block_3:
db 1,0,0,0
db 1,1,1,0
db 0,0,0,0
db 0,0,0,0
dd g_block_0
 
;-----------------------------------
 
k_block_0:
db 0,0,0,0
db 1,1,0,0
db 0,1,1,0
db 0,0,0,0
dd k_block_1
 
k_block_1:
db 0,1,0,0
db 1,1,0,0
db 1,0,0,0
db 0,0,0,0
dd k_block_0
 
;-----------------------------------
;logo blocks
;-----------------------------------
 
tetris_t:
db 1,1,1,0
db 0,1,0,0
db 0,1,0,0
db 0,1,0,0
db 0,1,0,0
 
tetris_e:
db 1,1,1,0
db 1,0,0,0
db 1,1,0,0
db 1,0,0,0
db 1,1,1,0
 
tetris_r:
db 1,1,0,0
db 1,0,1,0
db 1,1,0,0
db 1,0,1,0
db 1,0,1,0
 
tetris_i:
db 0,1,0,0
db 0,0,0,0
db 0,1,0,0
db 0,1,0,0
db 0,1,0,0
 
tetris_s:
db 0,1,1,1
db 1,0,0,0
db 0,1,1,0
db 0,0,0,1
db 1,1,1,0
 
tetris_II:
db 1,1,1,1
db 0,1,1,0
db 0,1,1,0
db 0,1,1,0
db 1,1,1,1
 
;-----------------------------------
block_table:
dd t_block_0 ; t
dd t_block_1
dd t_block_2
dd t_block_3
dd i_block_0 ; i
dd i_block_1
dd i_block_0
dd i_block_1
dd q_block_0 ; q
dd q_block_0
dd q_block_0
dd q_block_0
dd s_block_0 ; s
dd s_block_1
dd s_block_0
dd s_block_1
dd l_block_0 ; l
dd l_block_1
dd l_block_2
dd l_block_3
dd g_block_0 ; g
dd g_block_1
dd g_block_2
dd g_block_3
dd k_block_0 ; k
dd k_block_1
dd k_block_0
dd k_block_1
 
color_table:
dd 00000000h ;black 0
dd 00cccccch ;white 1
dd 00cc0000h ;red 2
dd 0000cc00h ;green 3
dd 000000cch ;blue 4
dd 00cccc00h ;yellow 5
dd 0000cccch ;cyan 6
dd 00cc00cch ;pink 7
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm tetris.asm tetris
@pause
/programs/tetris/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm tetris.asm tetris
@pause
/programs/tetris/trunk/key.inc
0,0 → 1,161
UP_KEY equ 178 ; the ascii keycodes of some keys
DOWN_KEY equ 177
LEFT_KEY equ 176
RIGHT_KEY equ 179
ENTER_KEY equ 13
ESCAPE_KEY equ 27
 
key:
mov eax,2 ; Read key ascii and store it into ah
int 0x40
 
cmp ah,LEFT_KEY ; Check if left key is pressed
jne no_left
 
cmp byte[status],'1'
jne no_left
go_left:
dec dword [current_block_x]
call check_crash
jz no_left
inc dword [current_block_x]
 
no_left:
cmp ah,RIGHT_KEY ; Check if right key is pressed
jne no_right
 
cmp byte[status],'1'
jne no_right
go_right:
inc dword [current_block_x]
call check_crash
jz no_right
dec dword [current_block_x]
 
no_right:
cmp ah,UP_KEY ; Compare pressed key with up key
jne no_up ; Jump to nu_up if up key isnt pressed
 
cmp byte[status],'0' ; Check if menu is running
jne no_menu2 ; Jump to no_up ifgame isnt running
 
cmp byte[menu],'0' ; Compare menu state with 0
jne no_menu0 ; Jump to no_menu0 if menu state isnt zero
 
mov byte[menu],'3' ; Change menu state to 2
call draw_window ; Redraw the window
jmp no_menu2 ; Jump to no_menu2
 
no_menu0:
dec byte[menu] ; menu state = menu state - 1
call draw_window ; Redraw the window
 
no_menu2:
cmp byte[status],'1' ; Compare game state with 1
jne no_up ; Jump to no_up if game state isnt 1 (if game isnt running)
 
call rotate_block
 
no_up:
cmp ah,DOWN_KEY ; Check if down key is pressed
jne no_down
 
cmp byte[status],'0'
jne no_menu3
 
cmp byte[menu],'3'
jne no_menu1
 
mov byte[menu],'0'
call draw_window
jmp no_menu3
 
no_menu1:
inc byte[menu]
call draw_window
 
no_menu3:
cmp byte[status],'1'
jne no_down
 
inc dword [current_block_y]
call check_crash
jne block_crash
jmp still
 
 
no_down:
cmp ah,'n' ; Check if n key is pressed
jne no_n
jmp new_game
 
no_n:
cmp ah,'p' ; Check if p key is pressed
jne no_p
cmp byte[status],'2'
je unpause
cmp byte[status],'1' ; add this two line or p will work
jne no_p ; when your still in the menu
mov byte[status],'2'
call draw_window
jmp attesa
unpause:
mov byte[status],'1'
call draw_window
jmp still
 
no_p:
cmp byte[status],'0'
jne no_menu
 
no_menu:
cmp byte[status],'1'
jne no_game
 
no_game:
cmp byte[status],'2'
jne no_pause1
 
no_pause1:
cmp ah,ENTER_KEY ; Check if enter key is pressed
jne no_enter
cmp byte[status],'0'
jne no_enter
call exemenu
 
no_enter:
cmp ah,ESCAPE_KEY ; Check if escape key is pressed
jne no_escape
 
 
cmp byte[status],'0'
jne no_instr1
mov eax,-1
int 0x40
 
no_instr1:
cmp byte[status],'1'
jne no_menu4
mov byte[status],'0'
call draw_window
 
no_menu4:
cmp byte[status],'3'
jne no_menu5
mov byte[status],'0'
call draw_window
 
no_menu5:
cmp byte[status],'4'
jne no_escape
mov byte[status],'0'
call draw_window
 
no_escape:
 
cmp byte[status],'1'
jne still
jmp scendi
 
ret
 
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/macros.inc
0,0 → 1,265
; new application structure
macro meos_app_start
{
use32
org 0x0
 
db 'MENUET01'
dd 0x01
dd __start
dd __end
dd __memory
dd __stack
 
if used __params & ~defined __params
dd __params
else
dd 0x0
end if
 
dd 0x0
}
MEOS_APP_START fix meos_app_start
 
macro code
{
__start:
}
CODE fix code
 
macro data
{
__data:
}
DATA fix data
 
macro udata
{
if used __params & ~defined __params
__params:
db 0
__end:
rb 255
else
__end:
end if
__udata:
}
UDATA fix udata
 
macro meos_app_end
{
align 32
rb 2048
__stack:
__memory:
}
MEOS_APP_END fix meos_app_end
 
 
; macro for defining multiline text data
struc mstr [sstring]
{
forward
local ssize
virtual at 0
db sstring
ssize = $
end virtual
dd ssize
db sstring
common
dd -1
}
 
 
; strings
macro sz name,[data] { ; from MFAR [mike.dld]
common
if used name
label name
end if
forward
if used name
db data
end if
common
if used name
.size = $-name
end if
}
 
macro lsz name,[lng,data] { ; from MFAR [mike.dld]
common
if used name
label name
end if
forward
if (used name)&(lang eq lng)
db data
end if
common
if used name
.size = $-name
end if
}
 
 
 
; easy system call macro
macro mpack dest, hsrc, lsrc
{
if (hsrc eqtype 0) & (lsrc eqtype 0)
mov dest, (hsrc) shl 16 + lsrc
else
if (hsrc eqtype 0) & (~lsrc eqtype 0)
mov dest, (hsrc) shl 16
add dest, lsrc
else
mov dest, hsrc
shl dest, 16
add dest, lsrc
end if
end if
}
 
macro __mov reg,a { ; mike.dld
if ~a eq
mov reg,a
end if
}
 
macro mcall a,b,c,d,e,f { ; mike.dld
__mov eax,a
__mov ebx,b
__mov ecx,c
__mov edx,d
__mov esi,e
__mov edi,f
int 0x40
}
 
 
 
 
 
 
 
; optimize the code for size
__regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
macro add arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
inc arg1
else
add arg1,arg2
end if
else
add arg1,arg2
end if
}
 
macro sub arg1,arg2
{
if (arg2 eqtype 0)
if (arg2) = 1
dec arg1
else
sub arg1,arg2
end if
else
sub arg1,arg2
end if
}
 
macro mov arg1,arg2
{
if (arg1 in __regs) & (arg2 eqtype 0)
if (arg2) = 0
xor arg1,arg1
else if (arg2) = 1
xor arg1,arg1
inc arg1
else if (arg2) = -1
or arg1,-1
else if (arg2) > -128 & (arg2) < 128
push arg2
pop arg1
else
mov arg1,arg2
end if
else
mov arg1,arg2
end if
}
 
 
macro struct name
{
virtual at 0
name name
sizeof.#name = $ - name
end virtual
}
 
; structures used in MeOS
struc process_information
{
.cpu_usage dd ? ; +0
.window_stack_position dw ? ; +4
.window_stack_value dw ? ; +6
.not_used1 dw ? ; +8
.process_name rb 12 ; +10
.memory_start dd ? ; +22
.used_memory dd ? ; +26
.PID dd ? ; +30
.x_start dd ? ; +34
.y_start dd ? ; +38
.x_size dd ? ; +42
.y_size dd ? ; +46
.slot_state dw ? ; +50
rb (1024-52)
}
struct process_information
 
struc system_colors
{
.frame dd ?
.grab dd ?
.grab_button dd ?
.grab_button_text dd ?
.grab_text dd ?
.work dd ?
.work_button dd ?
.work_button_text dd ?
.work_text dd ?
.work_graph dd ?
}
struct system_colors
 
 
; constants
 
; events
EV_IDLE = 0
EV_TIMER = 0
EV_REDRAW = 1
EV_KEY = 2
EV_BUTTON = 3
EV_EXIT = 4
EV_BACKGROUND = 5
EV_MOUSE = 6
EV_IPC = 7
EV_STACK = 8
 
; event mask bits for function 40
EVM_REDRAW = 1b
EVM_KEY = 10b
EVM_BUTTON = 100b
EVM_EXIT = 1000b
EVM_BACKGROUND = 10000b
EVM_MOUSE = 100000b
EVM_IPC = 1000000b
EVM_STACK = 10000000b
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/menu.inc
0,0 → 1,137
draw_menu:
 
cmp byte[menu],'0'
jne menu1
 
mov eax,4
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-39)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*4)
mov ecx,0x10ffff00
mov edx,startgame
mov esi,instr-startgame
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-84)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*5)
mov ecx,0x10ff0000
mov edx,instr
mov esi,hist-instr
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-50)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*6)
mov ecx,0x10ff0000
mov edx,hist
mov esi,quit-hist
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-26)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*7)
mov ecx,0x10ff0000
mov edx,quit
mov esi,paused-quit
int 0x40
 
menu1:
cmp byte[menu],'1'
jne menu2
 
 
mov eax,4
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-39)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*4)
mov ecx,0x10ff0000
mov edx,startgame
mov esi,instr-startgame
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-84)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*5)
mov ecx,0x10ffff00
mov edx,instr
mov esi,hist-instr
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-50)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*6)
mov ecx,0x10ff0000
mov edx,hist
mov esi,quit-hist
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-26)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*7)
mov ecx,0x10ff0000
mov edx,quit
mov esi,paused-quit
int 0x40
 
menu2:
cmp byte[menu],'2'
jne menu3
 
mov eax,4
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-39)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*4)
mov ecx,0x10ff0000
mov edx,startgame
mov esi,instr-startgame
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-84)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*5)
mov ecx,0x10ff0000
mov edx,instr
mov esi,hist-instr
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-50)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*6)
mov ecx,0x10ffff00
mov edx,hist
mov esi,quit-hist
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-26)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*7)
mov ecx,0x10ff0000
mov edx,quit
mov esi,paused-quit
int 0x40
 
menu3:
cmp byte[menu],'3'
jne menu4
 
mov eax,4
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-39)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*4)
mov ecx,0x10ff0000
mov edx,startgame
mov esi,instr-startgame
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-84)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*5)
mov ecx,0x10ff0000
mov edx,instr
mov esi,hist-instr
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-50)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*6)
mov ecx,0x10ff0000
mov edx,hist
mov esi,quit-hist
int 0x40
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98-26)/2*65536+(((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-2)/8*7)
mov ecx,0x10ffff00
mov edx,quit
mov esi,paused-quit
int 0x40
 
menu4:
 
 
ret
 
exemenu:
cmp byte[menu],'0' ;start
jne exemenu1
call new_game
 
exemenu1:
cmp byte[menu],'1' ;instr
jne exemenu2
mov byte[status],'4'
call draw_window
 
exemenu2:
cmp byte[menu],'2' ;history
jne exemenu3
mov byte[status],'3'
call draw_window
 
exemenu3:
cmp byte[menu],'3' ;exit
jne exemenu4
mov eax,-1
int 0x40
 
exemenu4:
 
ret
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/mouse.inc
0,0 → 1,87
mouse:
 
 
mov eax,37 ; get mouse position ; EXPERIMENTAL !!!
mov ebx,1 ; window relative ;
int 0x40 ; ;
shr eax,16 ; we only need to know the x position ;
sub eax,X_LOCATION ;
;
cmp eax,ADOBE_SIZE*(LEN_X-2) ; check to see if mouse is in field ;
jg no_mouse ; ;
cmp eax,0 ; ;
jl no_mouse ; ;
;
mov ebx,0 ;
;
mouseloop: ;
cmp eax,ADOBE_SIZE ;
jl yes_mouse ;
sub eax,ADOBE_SIZE ;
inc ebx ;
jmp mouseloop ;
;
yes_mouse: ;
cmp ebx,[current_block_x]
jg go_right
jl go_left
; mov dword[current_block_x],ebx ;
 
mov eax,37 ; get mouse position ;
mov ebx,2 ; buttons pressed (1=left, 2=right, 3=both) ;
int 0x40 ;
;
cmp eax,0 ;
jne yes_mouse_button ;
mov byte[lastmousebutton],0 ;
jmp no_mouse ;
yes_mouse_button: ;
;
cmp eax,2 ;
jne no_left_mouse ;
cmp byte[status],'1' ;
jne no_left_mouse ;
mov byte[lastmousebutton],2 ;
inc dword [current_block_y] ;
call check_crash ;
jne block_crash ;
jmp no_mouse ;
;
no_left_mouse: ;
;
;
cmp eax,1 ;
jne no_right_mouse ;
cmp byte[status],'1' ;
jne no_right_mouse ;
cmp byte[lastmousebutton],1 ;
mov byte[lastmousebutton],1 ;
je no_right_mouse ;
call rotate_block ;
call check_crash ;
jne block_crash ;
call draw_block ;
jmp scendi ;
;
no_right_mouse: ;
;
;
cmp eax,3 ;
jne no_mouse ;
cmp byte[lastmousebutton],3 ;
mov byte[lastmousebutton],3 ;
je no_mouse ;
cmp byte[status],'2' ;
je unpause ;
mov byte[status],'2' ;
call draw_window ;
jmp attesa ;
; unpause: ;
; mov byte[status],'1' ;
; call draw_window ;
; jmp still ;
;
; ;
no_mouse: ;
 
ret
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/random.inc
0,0 → 1,18
;--------------------------------------------------------------
 
random: mov eax,[generator]
add eax,-43ab45b5h
ror eax,1
xor eax,32c4324fh
ror eax,1
mov [generator],eax
; --- IVAN ---
push ebx
mov eax,22
mov ebx,9
int 0x40
pop ebx
xor eax,0xdeadbeef
add eax,[generator]
; --- IVAN ---
ret
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/score.inc
0,0 → 1,100
write_score:
 
mov eax,13
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2-3)*65536+95 ;clear box to write new score
mov ecx,20*65536+((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION-20)
mov edx,0x00000000
int 40h
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2)*65536+25 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,scoretext
mov esi,linestext-scoretext
mov eax,4
int 0x40
 
mov eax,[score]
call number_to_str
 
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+35)*65536+25 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,number_str
mov esi,[size_of_number_str]
mov eax,4
int 0x40
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2)*65536+35 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,linestext
mov esi,speedtext-linestext
mov eax,4
int 0x40
 
mov eax,[lines]
call number_to_str
 
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+35)*65536+35 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,number_str
mov esi,[size_of_number_str]
mov eax,4
int 0x40
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2)*65536+45 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,speedtext
mov esi,leveltext-speedtext
mov eax,4
int 0x40
 
mov eax,[speed]
call number_to_str
 
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+35)*65536+45 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,number_str
mov esi,[size_of_number_str]
mov eax,4
int 0x40
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2)*65536+55 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,leveltext
mov esi,startgame-leveltext
mov eax,4
int 0x40
 
mov eax,[level]
call number_to_str
 
 
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+35)*65536+55 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,number_str
mov esi,[size_of_number_str]
mov eax,4
int 0x40
 
call draw_next_block
 
ret
 
 
number_to_str:
 
mov edi,end_number_str-1
mov ecx,9;size_of_number_str
mov ebx,10
cld
new_digit:
xor edx,edx
div ebx
add dl,'0'
mov [edi],dl
dec edi
loop new_digit
 
ret
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/table.inc
0,0 → 1,56
;--------------------------------------------------------------
; DRAW_TABLE
;--------------------------------------------------------------
draw_table: mov esi,table_tetris+LEN_X*BORDER_TOP+BORDER_LEFT
 
mov ebx,X_LOCATION*65536+ADOBE_SIZE
mov ecx,Y_LOCATION*65536+ADOBE_SIZE
mov edi,LEN_Y-BORDER_TOP-BORDER_BOTTOM
y_draw: push edi
 
mov edi,LEN_X-BORDER_LEFT-BORDER_RIGHT
x_draw: push edi
mov ax,13
movzx edx,byte [esi]
mov edx,[color_table+edx*4]
int 0x40
call draw_frames
inc esi
add ebx,65536*ADOBE_SIZE
pop edi
dec edi
jnz x_draw
 
add esi,BORDER_LEFT+BORDER_RIGHT
mov ebx,X_LOCATION*65536+ADOBE_SIZE
add ecx,65536*ADOBE_SIZE
pop edi
dec edi
jnz y_draw
 
ret
 
;--------------------------------------------------------------
 
clear_table_tetris:
cld
mov al,1
mov edi,table_tetris
mov ecx,LEN_X*BORDER_TOP
rep stosb
 
mov edx,LEN_Y-BORDER_TOP-BORDER_BOTTOM
adr300: mov cl,BORDER_LEFT
rep stosb
dec ax ;AL=0
mov cl,LEN_X-BORDER_LEFT-BORDER_RIGHT
rep stosb
inc ax ;AL=1
mov cl,BORDER_RIGHT
rep stosb
dec dx
jne adr300
 
mov ecx,LEN_X*BORDER_BOTTOM
rep stosb
ret
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/tetris.asm
0,0 → 1,253
; Date : 1st April 2001
; TETRIS for MENUET
; Author : Paolo Minazzi (email paolo.minazzi@inwind.it)
;
; -Note-
; 1. This program requires a PENTIUM or higher because uses the RDTSC
; instrucion for get a random number.
; 2. You must use NASM to compile. Compiling is OK with NASM 0.98, I
; don't know what happen with other versions.
; 3. You must use the arrow key to move and rotate a block.
; 4. In the near future there will be a new version of TETRIS. This is
; only the beginning.
;
; Thanks to Ville, the author of this wonderful OS !
; Join with us to code !
;
;
; Changelog:
;
; 28.06.2001 - fasm port & framed blocks - Ville Turjanmaa
; 31.10.2001 - rdtsc replaced - quickcode <quickcode@mail.ru>
; 03.11.2003 - added new blocks & random - Ivan Poddubny
;
 
LEN_X equ 14
LEN_Y equ 24
BORDER_LEFT equ 2
BORDER_RIGHT equ 2
BORDER_TOP equ 1
BORDER_BOTTOM equ 1
ADOBE_SIZE equ 12
X_LOCATION equ 6
Y_LOCATION equ 21
_MAXBLOCKS_ = 7*4
SCORE_TO_NEW_LEVEL equ 100000
 
 
use32
 
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; program start
dd I_END ; program image size
dd IM_END ; reguired amount of memory
dd IM_END ; esp
dd 0x0,0x0 ; I_PARAM, I_ICON
include 'lang.inc'
START: ; start of execution
 
mov eax,3 ;
int 0x40 ;
mov cl,16 ;
ror eax,cl ; to make seconds more significant
mov [generator],eax ;
call random ;
 
mov byte[status],'0'
mov byte[menu],'0'
call draw_window ; at first, draw the window
 
still:
 
cmp byte[status],'2'
je attesa
 
cmp byte[status],'1'
 
jne attesa
xor edx,edx
 
call draw_block
 
 
attesa:
 
call mouse
;disabled because of bug
;EDIT: the bug is somewhere else..
;NOTE: dont release this without fixing the bug you lazy bastard!
 
mov eax,11 ; get event
int 0x40
 
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jnz check_button
jmp key
check_button:
cmp eax,3 ; button in buffer ?
jnz scendi
mov eax,-1 ; close this program
int 0x40
 
red: ; redraw
call draw_window
jmp still
 
parallel dd 1
 
scendi: cmp byte[status],'1'
jne still
 
cmp byte[blabla],10
je blabla_0
inc byte[blabla]
jmp blabla_1
blabla_0:
mov byte[blabla],0
inc dword [current_block_y]
call check_crash
jne block_crash
blabla_1:
 
 
draw: movzx edx,byte [current_block_color]
call draw_block
mov eax,5
mov ebx,5
sub ebx,[speed]
int 0x40
jmp still
 
block_crash: dec dword [current_block_y]
movzx edx,byte [current_block_color]
call draw_block
call fix_block
call check_full_line
call draw_table
call new_block
call write_score
call check_crash
jz adr400
aspetta: mov eax,10
int 0x40
cmp eax,1
jne adr10000
call draw_window
adr10000: cmp eax,3
jne aspetta
 
new_game: mov dword [score],0
mov dword [lines],0
mov dword [level],0
mov dword [speed],0
mov byte [status],'1'
call clear_table_tetris
call first_block
call new_block
call draw_window
 
adr400: movzx edx,byte [current_block_color]
call draw_block
jmp still
 
include 'key.inc'
include 'mouse.inc'
include 'menu.inc'
include 'window.inc'
include 'block.inc'
include 'table.inc'
include 'random.inc'
include 'score.inc'
 
; DATA AREA
 
include 'blocks.inc'
 
labelt: db 'TETRIS II'
scoretext: db 'Score:'
linestext: db 'Lines:'
speedtext: db 'Speed:'
leveltext: db 'Level:'
startgame: db 'START'
instr: db 'INSTRUCTIONS'
hist: db 'HISTORY'
quit: db 'EXIT'
paused: db 'PAUSED'
txt_end:
 
history:
db 'TETRIS for MENUET v2.0 '
db ' '
db ' '
db 'Originally made '
db ' by Paolo Minazzi '
db ' '
db 'Port & framed blocks '
db ' by Ville Turjanmaa '
db ' '
db 'RDTSC replaced '
db ' by quickcode '
db ' '
db 'New blocks & better random '
db ' by Ivan Poddubny '
db ' '
db 'Better control, logo, menu, pause '
db ' by Jeffrey Amelynck'
 
db 'x <- END MARKER, DONT DELETE '
 
instructions:
db 'TETRIS for MENUET v2.0 '
db ' '
db 'Controls: '
db ' '
db 'Use left & right key to navigate '
db 'Use up key to turn the block '
db 'Use down key to make block fall '
db 'Use P to pause game '
db 'Use N to start a new game '
db 'Use ESC to go back to menu or exit'
db 'You can also use the mouse to move'
db 'the blocks, left button to let the'
db 'blocks fall and right button to '
db 'rotate them '
db 'you can pause the game by pressing'
db 'both mouse buttons '
db ' '
db 'DONT FORGET: move mouse out of the'
db 'window if you want to use keyboard'
 
db 'x <- END MARKER, DONT DELETE '
 
I_END:
 
score: dd 0
level: dd 0
speed: dd 0
lines: dd 0
TMP_0: dd 0
TMP_1: dd 0
generator: dd 0
current_block_x: dd 0
current_block_y: dd 0
current_block_pointer: dd 0
current_block_color: db 0
next_block_pointer: dd 0
next_block_color: db 0
blabla dd 0
lastmousebutton dd 0
number_str: db 0,0,0,0,0,0,0,0,0
end_number_str:
size_of_number_str dd 7
delay: dd 5
status: dd 0 ; 0=menu, 1=playing, 2=paused, 3=history , 4=instructions
menu: dd 0 ; 0=start, 1=instructions, 2=history, 3=exit
 
table_tetris: rb 2048+55
 
IM_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/tetris/trunk/window.inc
0,0 → 1,142
draw_window:
 
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
 
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,320*65536+(LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2+98
mov ecx,25*65536+ (LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION+4
mov edx,0x03000000 ; color of work area RRGGBB
mov esi,0x006688ee ; color of grab bar RRGGBB,8->col
mov edi,0x007799ff ; color of frames RRGGBB
int 0x40
 
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+5 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,scoretext-labelt ; text length
int 0x40
 
cmp byte[status],'0'
jne status1
call draw_logo
call draw_menu
 
status1:
cmp byte[status],'1'
jne status2
 
call draw_game
 
status2:
cmp byte[status],'2'
jne status3
 
call draw_game
 
mov eax,4 ; function 4 : write text to window
mov ebx,80*65536+170 ; [x start] *65536 + [y start]
mov ecx,0x10ff0000 ; color of text RRGGBB
mov edx,paused ; pointer to text beginning
mov esi,txt_end-paused ; text length
int 0x40
 
status3:
cmp byte[status],'3'
jne status4
 
call draw_logo
mov edx,history
call show_text
 
status4:
cmp byte[status],'4'
jne status5
 
call draw_logo
mov edx,instructions
call show_text
 
status5:
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
draw_game:
 
call draw_table
movzx edx,byte [current_block_color]
call draw_block
 
call write_score
 
mov eax,38
mov ebx,((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2-4) shl 16 + ((LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2-4)
mov ecx,20 shl 16 + ((LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION+2-4)
mov edx,0x00ffffff
int 0x40
 
ret
 
draw_logo:
 
mov ebx,2
mov ecx,2
mov edx,[color_table+1*4]
mov edi,tetris_t
call draw_title_block
mov ebx,5
mov ecx,3
mov edx,[color_table+2*4]
mov edi,tetris_e
call draw_title_block
mov ebx,8
mov ecx,2
mov edx,[color_table+3*4]
mov edi,tetris_t
call draw_title_block
mov ebx,11
mov ecx,3
mov edx,[color_table+4*4]
mov edi,tetris_r
call draw_title_block
mov ebx,13
mov ecx,2
mov edx,[color_table+5*4]
mov edi,tetris_i
call draw_title_block
mov ebx,15
mov ecx,3
mov edx,[color_table+6*4]
mov edi,tetris_s
call draw_title_block
mov ebx,20
mov ecx,2
mov edx,[color_table+7*4]
mov edi,tetris_II
call draw_title_block
 
ret
 
show_text:
mov ebx,6*65536+120 ; draw info text with function 4
mov ecx,0xff0000
mov esi,34
newline:
mov eax,4
int 0x40
add ebx,10
add edx,34
cmp [edx],byte 'x'
jne newline
ret
 
 
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property