Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 9240 → Rev 9241

/programs/games/phenix/trunk/star2.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/programs/games/phenix/trunk/ascgl.inc
7,29 → 7,161
; Graphics
; Libary
;
; Ver 0.18 By Pavlushin Evgeni (RUSSIA)
; www.waptap@mail.ru
; Ver 0.18
;
 
;InfoList
;0.01 LoadImage
;0.02 SetBmp
;0.03 Bmptoimg, Setimg ~01.03.2004
;0.04 Bug deleted, copyimg ~03.05.2004
;0.05 fullimg, collimg ~05.05.2004
;0.06 getimg ~09.05.2004
;0.07 convbmp ~13.05.2004
;0.08 fps ~14.05.2004
;0.09 drawfbox ~03.06.2004
;0.10 all macros optimized by halyavin, add at ~07.06.2004
;0.11 many macros optimized by halyavin, add at ~30.08.2004
;0.12 bmptoimg ~07.09.2004
;0.13 imgtoimg ~08.09.2004
;0.14 imgtoimg modify not brake bmp pict! ~09.09.2004
;0.15 giftoimg, giftoani ~10.09.2004
;0.16 setframe, rgbtobgr, setbmp deleted ~20.09.2004
;0.17 modification giftoimg, giftoani, getframeoff ~01.10.2004
;0.18 aframetoimg,aimgtoimg,frametoimg ~03.10.2004
; draw image into image with alpha color mask
; image_draw_acimage dest, source, x, y, alpha_color
;
macro image_draw_acimage dest, source, x, y, alpha_color
{
local next_pix,next_line,skip_pix,no_skip
push dest
push source
push x
push y
push alpha_color
pop ebp ; alpha color
pop eax ; y
pop ebx ; x
pop esi ; src
pop edi ; dest
call image_draw_acimage_proc
 
if ~ defined image_draw_acimage_used
image_draw_acimage_used equ 1
 
jmp end_image_draw_acimage_proc
image_draw_acimage_proc:
mov ecx,dword [edi] ; ecx = canvas width
mul ecx ; edx:eax = ypos * canvas width
add eax,ebx ; eax = (ypos * canvas width) + xpos
lea eax,[eax+eax*2+8] ; eax=(y*xsize+x)*3+8 (8=skip xy size dwords)
 
mov edx,[esi] ; edx = img width
sub ecx,edx ; ecx = canvas width - img width
lea ebx,[ecx*2+ecx] ; ebx = how many pixels skip for new line
mov ecx,[esi+4] ; ecx = img height
add esi,8 ; esi + 8 for skip xy size dwords
add edi,eax ; edi = dest position
shl ebp,8 ; for fast compare with alpha color
cld ; set movs direction flag
next_line:
push edx
next_pix:
mov eax,[esi]
shl eax,8
cmp eax,ebp
je skip_pix
movsw
movsb
jmp no_skip
skip_pix:
add esi,3
add edi,3
no_skip:
dec edx
jnz next_pix
pop edx
add edi,ebx
dec ecx
jnz next_line
ret
end_image_draw_acimage_proc :
end if
 
}
 
macro image_set_size image,width,height
{
mov dword [image],width
mov dword [image+4],height
}
 
; label - draw label on window
; example:
; label 10,12,'Hello World!',cl_Green+font_size_x4+utf16
 
macro image_draw_label image,x,y,text,color
{
local label_text
draw_to_buffer equ 00001000b shl 24
jmp @f
label_text db text
@@:
words2reg ebx,x,y ; ebx - position
dword2reg ecx,color+draw_to_buffer ; ecx - color
mov edi,image
mov edx,label_text ; edx - address of label text
mov esi,@b-label_text ; esi - size of libel in bytes
mov eax,4
mcall
}
 
; draw_frect - draw filled rect
macro draw_frect x,y,xs,ys,color
{
wordstoreg ebx,x,xs ;x*65536+xs
wordstoreg ecx,y,ys ;y*65536+ys
mov edx,color
mov eax,13
mcall
}
 
; draw_label - Draw label in window
; example:
; draw_label 10,12,'Hello World!',cl_Green+font_size_x4+utf16
 
macro draw_label x,y,text,color
{
local label_text
words2reg ebx,x,y ; ebx - position
if text eqtype 123 | text eqtype eax
movt edx,text
mov ecx,color+(1 shl 31) ; ecx - color
else
mov edx,label_text ; edx - address of label text
jmp @f
label_text db text
@@:
mov esi,@b-label_text ; esi - size of libel in bytes
movt ecx,color ; ecx - color
end if
mov eax,4
mcall
}
 
hide_zeros equ (1 shl 31)
use_bg_color equ (1 shl 30)
use_big_font equ (1 shl 28)
 
macro draw_number data, x, y, color, numtype, bg_color
{
movt ecx,data
movt ebx,numtype
mov bl,0 ; if bl = 0, ecx is contain number
words2reg edx,x,y
if bg_color eq
movt esi,color
else
movt esi,color+use_bg_color
movt edi,bg_color
end if
mov eax,47
mcall
}
 
; draw_image - macro for draw image on window area
macro draw_image x, y, image
{
mov ecx,[image-2] ; -2 for except shl ecx,16
mov cx,[image+4] ; ecx = xsize*65536+ysize
wordstoreg edx, x, y ; edx = x*65536+y
lea ebx,[image+8] ; ebx = image data address
mov eax,7 ; eax = 7 is draw image function
mcall
}
 
aframetoimg_use_count=0
macro aframetoimg img, x, y, canvas,acol
{
81,7 → 213,6
add ebp,3
jmp nx
yx:
 
mov al,byte [edx]
mov byte [ebp],al
inc ebp
205,97 → 336,6
}
 
 
aimgtoimg_use_count=0
macro aimgtoimg img, x, y, canvas,acol
{
local loo,loo2,acolor
aimgtoimg_use_count=aimgtoimg_use_count+1
if aimgtoimg_use_count = 1
 
jmp end_aimgtoimg_proc
 
acolor dd 0
aimgtoimg_proc:
;getout coord
mov [acolor],ebp
 
mov eax,esi ;y cor
mul dword [ecx] ;canvas xsize
add eax,edi ;x cor
mov ebp,eax
shl eax,1
add ebp,eax
add ebp,ecx ;canvas+8;start
add ebp,8
;get img size
mov eax,ebx ;img ;xsize
mov esi,[eax]
add ebx,4
mov eax,ebx ; img+4 ;ysize
mov edi,[eax]
add ebx,4
mov edx,ebx ;img+8
loo2:
push esi
loo:
 
;test on alpha color
mov eax,[edx]
shl eax,8
shr eax,8
cmp eax,[acolor]
jne yx
add edx,3
add ebp,3
jmp nx
yx:
 
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
mov al,byte [edx]
mov byte [ebp],al
inc ebp
inc edx
nx:
dec esi
jnz loo
pop esi
sub ebp,3
mov eax,[ecx] ;offset = offset+((canxsize-imgxsize)*3)
sub eax,esi
add ebp,eax
shl eax,1
add ebp,eax
 
add ebp,3
 
dec edi
jnz loo2
ret
end_aimgtoimg_proc:
end if
push img
push canvas
push x
push y
push acol
pop ebp
pop esi
pop edi
pop ecx
pop ebx
call aimgtoimg_proc
}
 
 
 
 
imgtoimg_use_count=0
macro imgtoimg img, x, y, canvas
{
346,9 → 386,7
add ebp,eax
shl eax,1
add ebp,eax
 
add ebp,3
 
dec edi
jnz loo2
ret
365,17 → 403,6
call imgtoimg_proc
}
 
 
;DrawBox
macro drawfbox x,y,xs,ys,color
{
wordstoreg ebx,x,xs ;x*65536+xs
wordstoreg ecx,y,ys ;y*65536+ys
mov edx,color
mov eax,13
mcall
}
 
; FPS - Set Frame Per Second Display
fps_show_frequency=40
macro fps x,y,color,delcolor
422,60 → 449,13
no_out_fps:
}
 
; COLLIMG - Collusion image's
_1dbounce_count=0;
macro collimg img1_off,x1,y1,img2_off,x2,y2,otv
{
local bounce,exit,anot,bc,nbc
mov esi,[img1_off] ;xs1
mov edi,[img2_off] ;ys2
mov eax,x1 ;
mov ebx,x2 ;
call _1dbounce
mov edx,ecx
mov esi,[img1_off+4] ;ys1
mov edi,[img2_off+4] ;ys2
mov eax,y1 ;
mov ebx,y2 ;
call _1dbounce
add edx,ecx
cmp edx,2
je bounce
mov otv,0
jmp exit
_1dbounce_count=_1dbounce_count+1
if _1dbounce_count = 1
_1dbounce:
cmp ebx,eax
jb anot
add eax,esi
cmp eax,ebx
jbe nbc
bc:
mov ecx,1
ret
anot:
add ebx,edi
cmp ebx,eax
ja bc
nbc:
xor ecx,ecx
ret
end if
bounce:
mov otv,1
exit:
}
 
macro rgbtobgr image
{
local loo
mov eax,[image]
mul dword [image+4]
mov ecx,eax
mov esi,image+8
; add esi,8
loo:
@@:
mov al,[esi]
mov bl,[esi+2]
mov [esi],bl
482,23 → 462,9
mov [esi+2],al
add esi,3
dec ecx
jnz loo
jnz @b
}
 
 
macro setimg x , y ,arg3
{
mov eax,7
mov ebx,arg3
add ebx,8
mov cx,[arg3]
shl ecx,16
add cx,[arg3+4]
; wordstoreg ecx,[arg3],[arg3+4]
wordstoreg edx, x , y ;arg1*65536+arg2
mcall
}
 
macro setframe x , y ,arg3
{
mov eax,7
513,57 → 479,47
 
macro getimg imgsrc,x,y,xs,ys,imgdest
{
local cyc
if xs eqtype 0
local next_pixel,next_line
; store image size
if xs eqtype 0 | xs eqtype eax
mov dword [imgdest],xs
else
mov eax,xs
mov dword [imgdest],eax
end if
if ys eqtype 0
if ys eqtype 0 | ys eqtype eax
mov dword [imgdest+4],ys
else
;push ys
;pop dword [imgdest+4]
mov eax,ys
mov dword [imgdest+4],eax
end if
 
mov eax,dword [imgsrc] ;getx size
; lea ecx,[eax+2*eax]
mov ecx,eax
shl ecx,1
add ecx,eax
 
mov ebx,y
mul ebx
lea edi,[8+imgdest] ; edi = destinaton address
mov eax,dword [imgsrc] ; eax = xsize of source image in pixels
push eax ; store eax before mul operation
mov edx,y
mul edx ; edx:eax = eax*edx
add eax,x
mov edx,ecx
lea eax,[eax+2*eax] ;eax=offset on imsrc
; mov ebp,eax
; shl eax,1
; add eax,ebp
lea esi,[imgsrc+8+eax+2*eax] ; esi = start offset on img src
pop eax ; restore eax
sub eax,xs ; eax = src image xsize - crop fragment xsize
lea eax,[eax+eax*2] ; eax = eax * 3 (bytes per pixel)
 
mov ecx,xs
mov ebx,ys
 
mov edi,8+imgdest
lea esi,[eax+8+imgsrc]
; mov esi,eax
; add esi,8
; add esi,imgsrc
 
cld
cyc:
; this loop used esi,edi,ecx,edx,eax registers
mov edx,ys ; edx = ysize in pixels
cld ; set direction
next_line:
mov ecx,xs ; ecx = xsize in pixels
next_pixel:
movsw
movsb
movsb ; write 3 bytes pixel
dec ecx
jne cyc
add esi,edx
mov ecx,xs
sub esi,ecx
sub esi,ecx
sub esi,ecx
dec ebx
jne cyc
jnz next_pixel
add esi,eax
dec edx
jnz next_line
}
 
macro copyimg img2_off,img1_off
604,8 → 560,6
jne cop
}
 
 
 
; number of frame in ecx
; callculatin offset of raw data
 
630,13 → 584,11
mov dword offset_of_frame,esi
}
 
 
; BMPTOIMG -Convert BMP format TO IMG format
; (SYNTAX) BMPTOIMG BMP_source_offset,IMG_dest_ofset
; (SAMPLE) View BMPLS.ASM sample.
; ( NOTE ) This is macros is not brake bmp structure! Tested in 32,8,4 bits
; ( NOTE ) This is macro is not brake bmp structure! Tested in 32,8,4 bits
 
 
bmptoimg_data_area_count=0
macro bmptoimg bmp_load_area,img_dest_area
{
725,9 → 677,7
cmp esi,dword [bmptoimg_data_area_eos]
jae convert1
add edi,3
 
add ebp,3
 
jmp nextelem
 
convert4bpp:
737,9 → 687,7
movzx eax,ah
call converttable
add edi,3
 
add ebp,3
 
pop ax
movzx eax,al
call converttable
760,11 → 708,8
dec edx
js convert2
add edi,3
 
add ebp,3
 
jmp nextbit
 
converttable:
shl eax,2
add eax,ebx
/programs/games/phenix/trunk/ascgml.inc
7,33 → 7,83
; GaMe
; Libary
;
; Ver 0.03 By Pavlushin Evgeni (RUSSIA)
; www.waptap@mail.ru
; Ver 0.05
;
 
;InfoList
;0.01 correct
;0.02 control ~14.05.2004
;0.03 all macros optimized by halyavin, add at ~07.06.2004
; game_collision_2d - get collision of two 2d rectangles
; result of collision test placed in CF.
; if CF = 1, objects is collided
_1dbounce_count=0;
macro game_collision_2d xy1,wh1,xy2,wh2 ;img1_off,x1,y1,img2_off,x2,y2 ;,otv
{
movt eax,xy1
movt ebx,wh1
movt ecx,xy2
movt edx,wh2
call game_collision_proc
 
if ~ defined game_collision_used
game_collision_used equ 1
jmp exit
; eax = x1*65536+y1
; ebx = w1*65536+h1
; ecx = x2*65536+y2
; edx = w2*65536+h2
game_collision_proc:
; y h test
call _1dbounce
jnc @f
; x w test
shr eax,16 ;eax,y1 ;
shr ebx,16 ;mov ebx,[img1_off+4] ;h1
shr ecx,16 ;mov ecx,y2 ;
shr edx,16 ;mov edx,[img2_off+4] ;h2
call _1dbounce
@@:
ret
; ax - x1, bx - w1, cx - x2, dx - w2
; or
; ax - y1, bx - h1, cx - y2, dx - h2
; if collision ecx is incremented
_1dbounce:
cmp cx,ax ; if x2 < x1 jmp anot
jb anot
add ax,bx
cmp ax,cx ; if x1+xs <= x2 not coll
jbe not_coll
coll:
stc ; CF = 1
ret
anot:
add cx,dx
cmp cx,ax ; x2 + xs2 > x1
ja coll
not_coll:
clc ; CF = 0
ret
exit:
 
; corectiryemoe,corectnoe,step
macro correct arg1,arg2,arg3
end if
}
 
; approxto
macro approxto value,target_value,step
{
local plus,minus,equal
mov eax,arg2
cmp arg1,eax
mov eax,target_value
cmp value,eax
je equal
mov eax,arg3
mov eax,step
ja minus
plus:
add arg1,eax
add value,eax
jmp equal
minus:
sub arg1,eax
sub value,eax
equal:
}
 
macro control min,max,arg
macro clamp min,max,arg
{
local gr,low,norm
mov eax,max
/programs/games/phenix/trunk/ascguil.inc
0,0 → 1,120
lang equ ru
 
;
; Assembler
; SMALL
; CODE
; GUI
; Libary
;
; Ver 0.01
;
 
macro gui_text x,y,color,font_size,text {
db 4 ; type of gui element 4 - text
dw y, x
dd (1 shl 31)+color+((font_size-1) shl 24)
db text, 0
}
 
macro gui_button id,x,y,w,h,bcolor,tcolor,text {
db 8 ; type of gui element 8 - button with text
dw id, w, x, h, y
dd bcolor
dd (1 shl 31)+tcolor
db text, 0
}
 
macro gui_end {
db 255 ; type of gui element 255 - end of gui marker
}
 
macro draw_gui address
{
mov esi,address
call draw_gui_proc
 
if ~ defined draw_gui_used
draw_gui_used equ 1
jmp end_draw_gui_proc
draw_gui_proc:
next_element:
xor eax,eax
mov al,byte [esi]
; eax =4 draw label
cmp eax,4
jne no_label
mov ebx,[esi+1] ; x,y
mov ecx,[esi+1+4] ; color
lea edx,[esi+1+4+4] ; text offset
add esi,9
mcall
jmp skip_string
no_label:
; eax = 8 draw button
cmp eax,8
jne no_draw_button
xor edx,edx
mov dx,[esi+1] ; id
mov ebx,[esi+3] ; x,xs
mov ecx,[esi+7] ; y,ys
push esi
mov esi,[esi+11] ; button color
mcall
pop esi
 
lea ebp,[esi+19] ; start of text
call get_size_of_string
mov ebx,6
mul ebx
 
mov bx,[esi+3]
sub bx,ax
shr bx,1
add bx,[esi+5]
 
mov dx,[esi+7]
sub dx,7
shr dx,1
add dx,[esi+9]
 
shl ebx,16
mov bx,dx
 
mov ecx,[esi+15] ; text color
lea edx,[esi+19] ; text offset
mov eax,4
add esi,19
mcall
jmp skip_string
no_draw_button:
cmp eax,255
je end_of_gui
; unknown gui element
int3
end_of_gui:
ret
 
get_size_of_string:
xor eax,eax
next_bt:
cmp byte [ebp],0
jne no_en
ret
no_en:
inc ebp
inc eax
jmp next_bt
; function for skip string of text
next_byte:
inc esi
skip_string:
cmp byte [esi],0
jne next_byte
inc esi
jmp next_element
end_draw_gui_proc:
 
end if
 
}
/programs/games/phenix/trunk/ascl.inc
6,625 → 6,272
; CODE
; Libary
;
; Ver 0.14 By Pavlushin Evgeni (RUSSIA)
; www.waptap@mail.ru
; Ver 0.17 (for FASM v1.54 or higer)
;
 
;Please compile aplications on FASM ver1.54 or higer!!!
 
;InfoList
;0.01 scank,putpix,puttxt
;0.02 label,random,colors
;0.03 window,startwd,endwd,attributes
;0.04 close,delay,scevent ~30.04.2004
;0.05 small random, ~04.05.2004
;0.06 wtevent ~09.05.2004
;0.07 timeevent ~23.05.2004
;0.08 txtput ~14.06.2004
;0.09 opendialog,savedialog ~20.06.2004
;0.10 wordstoreg by halyavin, add at ~30.08.2004
; random bug deleted eax is use.
;0.11 loadfile from me +puttxt bug del ~07.09.2004
;0.12 open/save dialog ~13.09.2004
;0.13 dialogs bugs deleted
;0.14 drawlbut ~03.10.2004
;0.15 extendet label!
 
; LOADFILE
; (SYNTAX) LOADFILE 'full_path_to_file',file_load_area,file_temp_area
; (SAMPLE) LOADFILE '/rd/1/clock.bmp',load_area,temp_area
 
 
macro loadfile file_name,file_load_area,file_temp_area
macro movt op1,op2
{
local open,fileinfo,string
jmp open
fileinfo:
dd 0
dd 0
dd 1
dd file_load_area
dd file_temp_area
string:
db file_name,0
open:
mov dword [fileinfo+8],1 ; how many blocks to read (1)
mov eax,58
mov ebx,fileinfo
mcall
mov eax,[file_load_area+2]
shr eax,9 ; ¯®¤¥«¨¬ ­  512 ¨ ¯à¨¡ ¢¨¬ 1 - ¯®«ã稬 ç¨á«® ¡«®ª®¢
inc eax
mov dword [fileinfo+8],eax
mov eax,58
mov ebx,fileinfo
mcall
}
 
 
macro wordstoreg reg,hiword,loword
{
if hiword eqtype 0 & loword eqtype 0
mov reg,dword (hiword)*65536+(loword)
else if hiword eqtype 12 & loword eqtype eax
mov reg,dword (hiword)*65536
add reg,dword loword
else if hiword eqtype 12 & loword eqtype [123]
mov reg,dword (hiword)*65536
add reg,dword loword
if op2 eq
;display 'not set'
else
mov reg,dword hiword
shl reg,16
add reg,dword loword
if op1 eq op2
display '+'
;display 'skip mov ' # `op1 # ',' # `op2 , 10,13
else
mov op1,op2
end if
end if
}
 
 
 
macro dword2reg reg,doubleword
macro clear_buffer buffer, buf_size, value
{
if doubleword eq
; not changes
else
mov reg,dword doubleword
end if
}
movt edi,buffer ; edi = buffer adress
movt ecx,buf_size ; ecx = buffer size
movt al,value
call clear_buffer_proc
 
macro words2reg reg,hiword,lowword
{
if hiword eq
if lowword eq
; not changes
else
if lowword eqtype 12
and reg,dword 0xffff0000
add reg,dword lowword
else
and reg,dword 0xffff0000
add reg,dword lowword
if ~ defined clear_buffer_used
clear_buffer_used equ 1
jmp @f
clear_buffer_proc:
mov ah,al
push ax
shl eax,16
pop ax ; eax = al:al:al:al
push ecx
shr ecx,2 ; ecx = ecx/4 when we use stosd
cld ; set direction flag
rep stosd
pop ecx
and ecx,011b ; last two bits
rep stosb
ret
@@:
end if
end if
else
if lowword eq
if hiword eqtype 12
and reg,dword 0x0000ffff
add reg,dword hiword*65536
else
shl reg,16
add reg,dword hiword
ror reg,16
end if
else
if lowword eqtype 12 & hiword eqtype 12
if lowword eq 0 & hiword eq 0
xor reg,reg
else
mov reg,dword hiword*65536+lowword
end if
else
mov reg,dword hiword
shl reg,16
add reg,dword lowword
end if
end if
end if
}
 
; draw_button - function for draw button with label placed at center
 
 
 
; DRAW BUTTON with label
 
macro drawlbut x,y,xs,ys,text,id,bcolor,tcolor
macro draw_button button_id,x,y,xs,ys,text,button_color,text_color
{
local asd,lab
jmp asd
lab db text ;arg label
asd:
words2reg ebx,x,xs
words2reg ecx,y,ys
mov edx,id
mov esi,bcolor
mov eax,8
local end_of_data,label
jmp end_of_data
label db text ;arg label
end_of_data:
words2reg ebx,x,xs ; ebx = x * 65536 + xsize
words2reg ecx,y,ys ; ecx = y * 65536 + ysize
mov edx,button_id
mov esi,button_color
push dword end_of_data-label
push dword text_color
push dword label
call draw_button_proc
if ~ defined draw_button_used
draw_button_used equ 1
jmp @f
draw_button_proc:
mov eax,8 ; eax = 8 add button function
mcall
 
mov eax,asd-lab ;calc size
mov ebx,6
mul ebx
mov esi,eax
mov esi,[esp+12] ; esi = lenght of label
mov eax,esi
mov edx,6 ; 6 - width of one char
mul edx ; eax = size of label in pixels (chars number * 6)
 
mov eax,xs
sub eax,esi
shr eax,1
add eax,x
sub bx,ax
shr bx,1
mov edi,ebx
shr edi,16
add bx,di
 
mov edx,ys
sub edx,7
shr edx,1
add edx,y
sub cx,7
shr cx,1
mov edi,ecx
shr edi,16
add cx,di
 
mov ebx,eax
shl ebx,16
add ebx,edx
mov bx,cx ; ebx = bx * 65536 + edx
 
mov ecx,tcolor ;arg4 color
mov edx,lab
mov esi,asd-lab ;calc size
mov eax,4
mov ecx,[esp+8] ; text color
mov edx,[esp+4] ; set address of label
mov eax,4 ; eax = 4 draw label function
mcall
ret 3*4
@@:
end if
}
 
 
macro opendialog redproc,openoff,erroff,path
; scan_event - Scan event without wait
macro scan_event redraw,key,button
{
local new_d, get_loops, dlg_pid_get, DLGPID, num_of_proc
local run_fileinfo, param
local getmesloop, loox, mred, mkey, mbutton, mgetmes
local dlg_is_work, ready, procinfo
;
; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
;
 
cld
;; mov esi,path
mov edi,path
mov eax,0
mov ecx,200
rep stosb
 
;mov [get_loops],0
mov [dlg_pid_get],0
 
; Get my PID in dec format 4 bytes
mov eax,9
mov ebx,procinfo
mov ecx,-1
mov eax,11
mcall
dec eax
jz redraw
dec eax
jz key
dec eax
jz button
}
 
; convert eax bin to param dec
mov eax,dword [procinfo+30] ;offset of myPID
mov edi,param+4-1 ;offset to 4 bytes
mov ecx,4
mov ebx,10
cld
new_d:
xor edx,edx
div ebx
add dl,'0'
mov [edi],dl
dec edi
loop new_d
 
; wirite 1 byte space to param
mov [param+4],byte 32 ;Space for next parametr
; and 1 byte type of dialog to param
mov [param+5],byte 'O' ;Get Open dialog (Use 'S' for Save dialog)
 
;
; STEP2 prepare IPC area for get messages
;
 
; prepare IPC area
mov [path],dword 0
mov [path+4],dword 8
 
; define IPC memory
mov eax,60
mov ebx,1 ; define IPC
mov ecx,path ; offset of area
mov edx,150 ; size 150 bytes
; wait_event - Wait for event
macro wait_event redraw,key,button
{
mov eax,10
mcall
dec eax
jz redraw
dec eax
jz key
dec eax
jz button
}
 
; change wanted events list 7-bit IPC event
mov eax,40
mov ebx,01000111b
; time_event - Wait for event with timeout
macro time_event xfps,noevent,redraw,key,button
{
mov eax,23
mov ebx,xfps
mcall
;cmp eax,0
;je noevent
dec eax
js noevent
jz redraw
dec eax
jz key
dec eax
jz button
}
 
;
; STEP 3 run SYSTEM XTREE with parameters
;
 
mov eax,58
mov ebx,run_fileinfo
; function for set ascii or scan code keyboard input mode
macro keyboard_set_input_mode mode
{
mov eax,66 ; eax = 66 - keyboard service function
mov ebx,1 ; ebx = 1 - sub function for set input mode for keyboard
mov ecx,mode ; ecx = mode 0 - ASCII; 1 - scan codes;
mcall
}
 
call redproc
 
mov [get_loops],0
getmesloop:
mov eax,23
mov ebx,50 ;0.5 sec
; function for read layout to 128 byte array
macro keyboard_get_layout layout_type, layout_array
{
mov eax,26 ; eax = 26 - hardware service function
mov ebx,2 ; ebx = 2 - subfunction for get keyboard layout
mov ecx,layout_type ; ecx = layout type: 1 - for normal layout
mov edx,layout_array ; edx = address to 128 byte array
mcall
}
 
cmp eax,1
je mred
cmp eax,2
je mkey
cmp eax,3
je mbutton
cmp eax,7
je mgetmes
 
; Get number of procces
mov ebx,procinfo
mov ecx,-1
mov eax,9
; function for get key from keyboard buffer
macro window_get_key output
{
mov eax,2 ; eax = 2 - get keyboard pressed key function
mcall
mov ebp,eax
if ~output eq
mov output,eax
end if
}
 
loox:
mov eax,9
mov ebx,procinfo
mov ecx,ebp
; function for get id of button pressed in window
macro window_get_button output
{
mov eax,17 ; eax = 17 - get id of pressed button function
mcall
mov eax,[DLGPID]
cmp [procinfo+30],eax ;IF Dialog find
je dlg_is_work ;jmp to dlg_is_work
dec ebp
jnz loox
if ~output eq
mov output,eax
end if
}
 
jmp erroff
 
dlg_is_work:
cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
je erroff ;TESTODP2 terminated too
 
cmp [dlg_pid_get],dword 1
je getmesloop
inc [get_loops]
cmp [get_loops],4 ;2 sec if DLG_PID not get, TESTOP2 terminated
jae erroff
jmp getmesloop
 
mred:
call redproc
jmp getmesloop
mkey:
mov eax,2
mcall ; read (eax=2)
jmp getmesloop
mbutton:
mov eax,17 ; get id
macro draw_pixel x,y,color
{
mov ebx,x
mov ecx,y
mov edx,color
mov eax,1
mcall
cmp ah,1 ; button id=1 ?
jne getmesloop
mov eax,-1 ; close this program
mcall
mgetmes:
 
; If dlg_pid_get then second message get jmp to still
cmp [dlg_pid_get],dword 1
je ready
 
; First message is number of PID SYSXTREE dialog
 
; convert PID dec to PID bin
movzx eax,byte [path+16]
sub eax,48
imul eax,10
movzx ebx,byte [path+16+1]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+2]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+3]
add eax,ebx
sub eax,48
mov [DLGPID],eax
 
; Claear and prepare IPC area for next message
mov [path],dword 0
mov [path+4],dword 8
mov [path+8],dword 0
mov [path+12],dword 0
mov [path+16],dword 0
 
; Set dlg_pid_get for get next message
mov [dlg_pid_get],dword 1
call redproc ;show DLG_PID
jmp getmesloop
 
ready:
;
; The second message get
; Second message is 100 bytes path to SAVE/OPEN file
; shl path string on 16 bytes
;
cld
mov esi,path+16
mov edi,path
mov ecx,200
rep movsb
mov [edi],byte 0
 
jmp openoff
 
 
; DATA AREA
get_loops dd 0
dlg_pid_get dd 0
DLGPID dd 0
 
param:
dd 0 ; My dec PID
dd 0,0 ; Type of dialog
 
run_fileinfo:
dd 16
dd 0
dd param
dd 0
dd procinfo ; 0x10000
;run_filepath
db '/sys/SYSXTREE',0
 
procinfo:
times 256 db 0
}
 
 
macro savedialog redproc,openoff,erroff,path
macro puttxt x,y,offs,size,color
{
local new_d, get_loops, dlg_pid_get, DLGPID, num_of_proc
local run_fileinfo, run_filepath, param
local getmesloop, loox, mred, mkey, mbutton, mgetmes
local dlg_is_work, ready, procinfo
;
; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
;
 
cld
;; mov esi,path
mov edi,path
mov eax,0
mov ecx,200
rep stosb
 
;mov [get_loops],0
mov [dlg_pid_get],0
 
; Get my PID in dec format 4 bytes
mov eax,9
mov ebx,procinfo
mov ecx,-1
words2reg ebx,x,y
mov ecx,color
mov edx,offs
mov esi,size
mov eax,4
mcall
}
 
; convert eax bin to param dec
mov eax,dword [procinfo+30] ;offset of myPID
mov edi,param+4-1 ;offset to 4 bytes
mov ecx,4
mov ebx,10
cld
new_d:
xor edx,edx
div ebx
add dl,'0'
mov [edi],dl
dec edi
loop new_d
 
; wirite 1 byte space to param
mov [param+4],byte 32 ;Space for next parametr
; and 1 byte type of dialog to param
mov [param+5],byte 'S' ;Get Open dialog (Use 'S' for Save dialog)
 
;
; STEP2 prepare IPC area for get messages
;
 
; prepare IPC area
mov [path],dword 0
mov [path+4],dword 8
 
; define IPC memory
mov eax,60
mov ebx,1 ; define IPC
mov ecx,path ; offset of area
mov edx,120 ; size 150 bytes
; window_begin_draw - Begin of draw window
macro window_begin_draw
{
mov eax,12
mov ebx,1
mcall
}
 
; change wanted events list 7-bit IPC event
mov eax,40
mov ebx,01000111b
; window_end_draw - End draw of window
macro window_end_draw
{
mov eax,12
mov ebx,2
mcall
}
 
;
; STEP 3 run SYSTEM XTREE with parameters
;
; fs_read_file - read file from file system and save it to array
; example:
; fs_read_file '/rd/1/clock.bmp',load_area,temp_area
 
macro fs_read_file file_name,file_load_area,file_temp_area
{
local open,fileinfo,string
jmp open
fileinfo:
dd 0
dd 0
dd 1
dd file_load_area
dd file_temp_area
string:
db file_name,0
open:
mov dword [fileinfo+8],1 ; how many blocks to read (1)
mov eax,58
mov ebx,run_fileinfo
mov ebx,fileinfo
mcall
 
call redproc
 
mov [get_loops],0
getmesloop:
mov eax,23
mov ebx,50 ;0.5 sec
mov eax,[file_load_area+2]
shr eax,9 ; div to 512 and add 1 - for get number of blocks
inc eax
mov dword [fileinfo+8],eax
mov eax,58
mov ebx,fileinfo
mcall
 
cmp eax,1
je mred
cmp eax,2
je mkey
cmp eax,3
je mbutton
cmp eax,7
je mgetmes
 
; Get number of procces
mov ebx,procinfo
mov ecx,-1
mov eax,9
mcall
mov ebp,eax
 
loox:
mov eax,9
mov ebx,procinfo
mov ecx,ebp
mcall
mov eax,[DLGPID]
cmp [procinfo+30],eax ;IF Dialog find
je dlg_is_work ;jmp to dlg_is_work
dec ebp
jnz loox
 
jmp erroff
 
dlg_is_work:
cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
je erroff ;TESTODP2 terminated too
 
cmp [dlg_pid_get],dword 1
je getmesloop
inc [get_loops]
cmp [get_loops],4 ;2 sec if DLG_PID not get, TESTOP2 terminated
jae erroff
jmp getmesloop
 
mred:
call redproc
jmp getmesloop
mkey:
mcall ; read (eax=2)
jmp getmesloop
mbutton:
mov eax,17 ; get id
mcall
cmp ah,1 ; button id=1 ?
jne getmesloop
mov eax,-1 ; close this program
mcall
mgetmes:
 
; If dlg_pid_get then second message get jmp to still
cmp [dlg_pid_get],dword 1
je ready
 
; First message is number of PID SYSXTREE dialog
 
; convert PID dec to PID bin
movzx eax,byte [path+16]
sub eax,48
imul eax,10
movzx ebx,byte [path+16+1]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+2]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [path+16+3]
add eax,ebx
sub eax,48
mov [DLGPID],eax
 
; Claear and prepare IPC area for next message
mov [path],dword 0
mov [path+4],dword 8
mov [path+8],dword 0
mov [path+12],dword 0
mov [path+16],dword 0
 
; Set dlg_pid_get for get next message
mov [dlg_pid_get],dword 1
call redproc ;show DLG_PID
jmp getmesloop
 
ready:
;
; The second message get
; Second message is 100 bytes path to SAVE/OPEN file
; shl path string on 16 bytes
;
cld
mov esi,path+16
mov edi,path
mov ecx,200
rep movsb
mov [edi],byte 0
 
jmp openoff
 
 
; DATA AREA
get_loops dd 0
dlg_pid_get dd 0
DLGPID dd 0
 
param:
rb 4 ; My dec PID
rb 6 ; Type of dialog
 
run_fileinfo:
dd 16
dd 0
dd param
dd 0
dd procinfo
run_filepath:
db '/sys/SYSXTREE',0
 
procinfo:
times 256 db 0
}
 
; random - generate random count (small)
; example:
; random 10000,eax ; generate random value from 0 to 10000 and save it in eax
; note:
; max_value<65536
; only modificate eax register
 
 
 
; RANDOM - generate random count (small)
; (SYNTAX) RANDOM MaxCount,OutArgument
; (SAMPLE) RANDOM 10000,eax
; ( NOTE ) Maxint<65536 ; use random 65536,eax for more combinations
 
randomuse = 0
 
macro random arg1,arg2
macro random max_value,result
{
local rxproc
randomuse = randomuse + 1
 
jmp rxproc
 
if defined randomuse & randomuse = 1
randomproc:
jmp rnj
rsx1 dw 0x4321
rsx2 dw 0x1234
rnj:
; mov eax,arg1
push bx
push cx
push dx
push si
push di
;int3
;push bx
;push cx
;push dx
;push si
;push di
pushad
mov cx,ax
mov ax,word ptr rsx1
mov bx,word ptr rsx2
651,112 → 298,25
je nodiv
div cx
nodiv:
mov ax,dx
pop di
pop si
pop dx
pop cx
pop bx
and eax,0000ffffh
; mov arg2,0
; mov arg2,eax
mov [rnd_result],dx
popad
mov eax,dword [rnd_result]
ret
; data block after ret
rsx1 dw 0x4321
rsx2 dw 0x1234
rnd_result dw 0
dw 0
end if
 
rxproc:
mov eax,arg1
movt eax,max_value
call randomproc
mov arg2,eax
movt result,eax ;dword [rnd_result]
}
 
macro scank
{
mov eax,10
mcall
}
; close - Close application
 
macro putpix x,y,color
{
mov ebx,x
mov ecx,y
mov edx,color
mov eax,1
mcall
}
 
macro puttxt x,y,offs,size,color
{
; mov ebx,x
; shl ebx,16
; add ebx,y
words2reg ebx,x,y
mov ecx,color
mov edx,offs
mov esi,size
mov eax,4
mcall
}
 
macro outcount data, x, y, color, numtype
{
mov ecx,data
mov ebx,numtype
mov bl,0
; mov edx,x*65536+y
words2reg edx,x,y
mov esi,color
mov eax,47
mcall
}
 
; SCEVENT - Scan event
 
macro scevent red,key,but
{
mov eax,11
mcall
dec eax
jz red
dec eax
jz key
dec eax
jz but
}
 
; WTEVENT - Wait event
 
macro wtevent red,key,but
{
mov eax,10
mcall
dec eax
jz red
dec eax
jz key
dec eax
jz but
}
 
; TIMEEVENT - Wite for event with timeout
 
macro timeevent xfps,noevent,red,key,but
{
mov eax,23
mov ebx,xfps
mcall
cmp eax,0
je noevent
dec eax
jz red
dec eax
jz key
dec eax
jz but
}
 
 
; CLOSE - Close program
 
macro close
{
mov eax,-1
763,9 → 323,9
mcall
}
 
; DELAY - Create delay 1/100 sec
; (SYNTAX) Delay time
; (SAMPLE) Delay 100 ;delay 2 sec 1/100*200=2 sec
; delay - Create delay 1/100 sec
; example:
; delay 100 ;delay 2 sec 1/100*200=2 sec
 
macro delay arg1
{
774,14 → 334,13
mcall
}
 
; WINDOW - Draw window
; (SYNTAX) WINDOW Xstart,Ystart,'Text',Color
; (SAMPLE) WINDOW 10,10,640+8,480+24,window_Skinned
; window - Draw window
; window Xstart,Ystart,'Text',Color
; example:
; window 10,10,640+8,480+24,window_Skinned
 
macro window arg1,arg2,arg3,arg4,arg5
{
; mov ebx,arg1*65536+arg3
; mov ecx,arg2*65536+arg4
words2reg ebx,arg1,arg3
words2reg ecx,arg2,arg4
mov edx,arg5
800,77 → 359,112
mcall
}
 
;Key's scan codes
 
; STARTWD - Start of window draw
ErrorCode equ 0 ; 0x00
key_Esc equ 1 ; 0x01
key_1 equ 2 ; 0x02 !
key_2 equ 3 ; 0x03 @
key_3 equ 4 ; 0x04 #
key_4 equ 5 ; 0x05 $
key_5 equ 6 ; 0x06 %
key_6 equ 7 ; 0x07 "
key_7 equ 8 ; 0x08 &
key_8 equ 9 ; 0x09 *
key_9 equ 10 ; 0x0A (
key_0 equ 11 ; 0x0B )
 
macro startwd
{
mov eax,12
mov ebx,1
mcall
}
key_Backspace equ 14 ; 0x0E
key_Q equ 16 ; 0x10
key_W equ 17 ; 0x11
key_E equ 18 ; 0x12
key_R equ 19 ; 0x13
key_T equ 20 ; 0x14
key_Y equ 21 ; 0x15
key_U equ 22 ; 0x16
key_I equ 23 ; 0x17
key_O equ 24 ; 0x18
key_P equ 25 ; 0x19
 
; ENDWD - End window draw
key_Enter equ 28 ; 0x1C
key_A equ 30 ; 0x1E
key_S equ 31 ; 0x1F
key_D equ 32 ; 0x20
key_F equ 33 ; 0x21
key_G equ 34 ; 0x22
key_H equ 35 ; 0x23
key_J equ 36 ; 0x24
key_K equ 37 ; 0x25
key_L equ 38 ; 0x26
key_Colon equ 39 ; 0x27 ':;'
key_DQuotes equ 0x28 ; 40 '"''
key_Tilda equ 0x29 ; 41 '~`'
key_LShift equ 0x2A ; 42
key_Z equ 0x2C ; 44
key_X equ 0x2D ; 45
key_C equ 0x2E ; 46
key_V equ 0x2F ; 47
key_B equ 0x30 ; 48
key_N equ 0x31 ; 49
key_M equ 0x32 ; 50
key_Comma equ 0x33 ; 51 ',<'
key_Dot equ 0x34 ; 52 '.>'
key_Question equ 0x35 ; 53 '?/'
key_RShift equ 0x36 ; 54
key_NumStar equ 0x37 ; 55 '*'
key_LAlt equ 0x38 ; 56
key_Space equ 0x39 ; 57
key_CapsLock equ 0x3A ; 58
key_F1 equ 0x3B ; 59
key_F2 equ 0x3C ; 60
key_F3 equ 0x3D ; 61
key_F4 equ 62
key_F5 equ 63
key_F6 equ 64
key_F7 equ 65
key_F8 equ 66
key_F9 equ 67
key_F10 equ 0x44 ; 68
key_NumLock equ 0x45 ; 69
key_ScrollLock equ 0x46 ; 70
key_Up equ 0x48 ; 72
key_Num8 equ 0x48 ; 72
key_PageUp equ 0x49 ; 73
key_Num9 equ 0x49 ; 73
key_NumMinus equ 0x4A ; 74
key_Left equ 0x4B ; 75
key_Num4 equ 0x4B ; 75
key_Num5 equ 0x4C ; 76
key_Right equ 0x4D ; 77
key_Down equ 0x50 ; 80
key_Num2 equ 0x50 ; 80
key_F11 equ 0x57 ; 87
key_F12 equ 0x58 ; 88
key_PA1 equ 90 ; 0x5A
key_Lwin equ 91 ; 0x5B
key_F13 equ 91 ; 0x5B
key_Rwin equ 92 ; 0x5C
key_F14 equ 92 ; 0x5C
key_Menu equ 93 ; 0x5D
key_F15 equ 93 ; 0x5D
key_F16 equ 99 ; 0x63
key_F17 equ 100 ; 0x64
key_F18 equ 101 ; 0x65
key_F19 equ 102 ; 0x66
key_F20 equ 103 ; 0x67
key_F21 equ 104 ; 0x68
key_F22 equ 105 ; 0x69
key_F23 equ 106 ; 0x6A
key_F24 equ 107 ; 0x6B
key_EraseEOF equ 109 ; 0x6D
key_CopyPlay equ 111 ; 0x6F
key_CrSel equ 114 ; 0x72
key_Delta equ 115 ; 0x73
key_ExSel equ 116 ; 0x74
key_Clear equ 118 ; 0x76
 
macro endwd
{
mov eax,12
mov ebx,2
mcall
}
 
; LABEL - Put text to frame
; (SYNTAX) LABEL Xstart,Ystart,'Text',Color
; (SAMPLE) LABEL 10,12,'Hello World!',cl_Green+font_Big
 
macro label arg1,arg2,arg3,arg4
{
local asd,lab
jmp asd
lab db arg3 ;arg label
asd:
; mov ebx,arg1 ;arg1=y arg2=x
; shl ebx,16
; add ebx,arg2
 
 
words2reg ebx,arg1,arg2
 
dword2reg ecx,arg4
 
 
mov edx,lab
mov esi,asd-lab ;calc size
mov eax,4
mcall
}
 
;Key's
key_Up equ 178
key_Down equ 177
key_Right equ 179
key_Left equ 176
key_Esc equ 27
key_Space equ 32
key_Enter equ 13
key_Bspace equ 8
key_F1 equ 50
key_F2 equ 51
key_F3 equ 52
key_F4 equ 53
key_F5 equ 54
key_F6 equ 55
key_F7 equ 56
key_F8 equ 57
key_F9 equ 48
key_F10 equ 49
key_F11 equ 68
key_F12 equ 255
key_Home equ 180
key_End equ 181
key_PgUp equ 184
key_PgDown equ 183
 
;Attributes
 
;Window Attributes
879,8 → 473,21
window_Type1 equ 0x00000000
window_Reserve equ 0x01000000
 
;Font Attributes
font_Big equ 0x10000000
;Label Attributes
ends_by_zero equ 10000000b shl 24
fill_background equ 01000000b shl 24
cp866_small equ 00000000b shl 24
cp866 equ 00010000b shl 24
utf16 equ 00100000b shl 24
utf8 equ 00110000b shl 24
font_size_x1 equ 00000000b shl 24
font_size_x2 equ 00000001b shl 24
font_size_x3 equ 00000010b shl 24
font_size_x4 equ 00000011b shl 24
font_size_x5 equ 00000100b shl 24
font_size_x6 equ 00000101b shl 24
font_size_x7 equ 00000110b shl 24
font_size_x8 equ 00000111b shl 24
 
;Colors
cl_White equ 0x00ffffff
888,8 → 495,78
cl_Grey equ 0x00888888
cl_Red equ 0x00ff0000
cl_Lime equ 0x0000ff00
cl_Blue equ 0x000000ff
cl_Yellow equ 0x00ffff00
cl_Cyan equ 0x0000ffff
cl_Green equ 0x0000af00
cl_Blue equ 0x000000ff
cl_Purple equ 0x008080ff
cl_Violet equ 0x008040ff
cl_Cyan equ 0x0040e0ff
;cl_Cyan equ 0x0040e0ff
 
macro wordstoreg reg,hiword,loword
{
if hiword eqtype 0 & loword eqtype 0
mov reg,dword (hiword)*65536+(loword)
else if hiword eqtype 12 & loword eqtype eax
mov reg,dword (hiword)*65536
add reg,dword loword
else if hiword eqtype 12 & loword eqtype [123]
mov reg,dword (hiword)*65536
add reg,dword loword
else
mov reg,dword hiword
shl reg,16
add reg,dword loword
end if
}
 
macro dword2reg reg,doubleword
{
if doubleword eq
; not changes
else
mov reg,dword doubleword
end if
}
 
macro words2reg reg,hiword,lowword
{
if hiword eq
if lowword eq
; if operators empty nothing do
else
if lowword eqtype 12/4
and reg,dword 0xffff0000
add reg,dword lowword
else
and reg,dword 0xffff0000
add reg,dword lowword
end if
end if
else
if lowword eq
if hiword eqtype 12/4
and reg,dword 0x0000ffff
add reg,dword hiword*65536
else
shl reg,16
add reg,dword hiword
ror reg,16
end if
else
if lowword eqtype 12/4 & hiword eqtype 12/4
if lowword = 0 & hiword = 0
xor reg,reg
else
; use brackets for calcualtion without error!!!
mov reg,dword (hiword)*65536+(lowword)
end if
else
mov reg,dword hiword
shl reg,16
add reg,dword lowword
end if
end if
end if
}
/programs/games/phenix/trunk/ascpoal.inc
0,0 → 1,161
lang equ ru
 
;
; Assembler
; SMALL
; CODE
; Arrays
; Processing
; Libary
;
; Ver 0.04
;
 
; This macro iterates through an array of elements,
; processing each element using the specified process.
; modificate eax,{ebx},{ecx},edx,esi,[edi],[ebp]
 
macro array_processing object_array,process
{
 
movt edi,object_array
movt ebp,process
call array_processing_proc
 
if ~ defined array_processing_used
array_processing_used equ 1
jmp end_ap
array_processing_proc:
push ecx
push ebx
mov ecx,[edi] ; dword contain quantity of elements
mov ebx,[edi+4] ; dword contain size of each element
add edi,8
ap_read_next:
;pop ebx
;pop ecx
pushad
call ebp ;eax ;process
popad
;push ecx
;push ebx
add edi,ebx
dec ecx
jnz ap_read_next
pop ebx
pop ecx
ret
end_ap:
end if
}
 
; This macro iterates through an array of elements,
; processing each element using the specified process
; if object finded ina array macro returned
; with CF=0 and address of element in edi.
; if object not finded macro return CF=1
; process must be return CF=0 if value euqal finded value
; and CF=1 if value not equal
; modificate eax,{ebx},{ecx},edx,esi,[edi],[ebp]
 
macro array_find object_array,process
{
 
movt edi,object_array
movt ebp,process
call array_find_proc
 
if ~ defined array_find_used
array_find_used equ 1
jmp end_af
array_find_proc:
push ecx
push ebx
mov ecx,[edi] ; dword contain quantity of elements
mov ebx,[edi+4] ; dword contain size of each element
add edi,8
af_read_next:
pushad
call ebp ;eax ;process
popad
jnc af_finded
add edi,ebx
dec ecx
jnz af_read_next
; not finded
stc ; if not finded CF = 1
af_finded: ; if finded CF = 0
pop ebx
pop ecx
ret
end_af:
end if
}
 
;
; process may get offests of elements from registers.
 
macro compmas object_array_1,object_array_2,process
{
local loo,loo2
;lea,[oa+8]
mov esi,object_array_2 ; current position
add esi,8
mov ecx,[object_array_2] ; dword contain quantity of elements
mov ebx,[object_array_2+4] ; dword contain size of each element
mov eax,0
loo2:
push eax
mov edi,object_array_1 ; current position
add edi,8
mov ebp,[object_array_1] ; dword contain quantity of elements
mov edx,[object_array_1+4] ; dword contain size of each element
mov eax,0 ;count
loo:
pushad
call process
popad
add edi,edx
inc eax
cmp eax,ebp
jne loo
add esi,ebx
pop eax
inc eax
cmp eax,ecx
jne loo2
}
 
 
 
macro array_processing_nocall object_array,process
{
local read_next
lea edi,[object_array+8]
mov ecx,[object_array] ; dword contain quantity of elements
read_next:
pushad
call process
popad
add edi,[object_array+4] ; edi = edi + size of one element
dec ecx
jnz read_next
}
 
macro array_find_nocall object_array,process
{
local read_next,finded
lea edi,[object_array+8] ; edi = current position
mov ecx,[object_array] ; dword contain quantity of elements
read_next:
pushad
call process
popad
jnc finded
add edi,[object_array+4] ; dword contain size of each element
dec ecx
jnz read_next
; not finded
stc ; if not finded CF = 1
finded: ; if finded CF = 0
}
/programs/games/phenix/trunk/objects.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/games/phenix/trunk/phenix.asm
1,13 → 1,8
;
; Phenix Dynamic Game Created by Pavlushin Evgeni for ASCL
; Phoenix Game. Based on ASCL Library
;
; 100% Full relase!
;
; www.waptap@mail.ru
;
 
 
;******************************************************************************
;**********************************************************************
use32
org 0x0
db 'MENUET01' ; 8 byte id
15,1336 → 10,1223
dd START ; start of code
dd IM_END ; size of image
dd I_END ; memory for app
dd I_END ; esp
dd I_END ; esp stack position
dd 0x0 , 0x0 ; I_Param , I_Icon
;**********************************************************************
 
;******************************************************************************
include 'lang.inc' ; for SVN 'lang.inc'
include '../../../macros.inc' ; for SVN '..\..\..\macros.inc;'
include 'ascl.inc' ; main
include 'ascgl.inc' ; graphics
include 'ascpoal.inc' ; processing object array
include 'ascgml.inc' ; game library for collision detection
 
; debug flags
keyboard_debug=0 ; Set to 1 to view all keyboard keys state in game
light_space=0 ; May used for check canvas position in window
debug_scenario=0 ; May used for fast test of gameplay
stack_leak_debug=0 ; Show stack size on screen
debug_mode=1 ; Support keys:
; A - set player hp = 10000. Make player ship undestructible
; E - player hp / 2
; W - view final screen after game begin
 
include 'lang.inc'
include '../../../macros.inc'
include 'ascl.inc'
include 'ascgl.inc'
include 'ascml.inc'
screen_w equ 640
screen_h equ 440
;screen_w equ 1014
;screen_h equ 739
 
; Define special colors
cl_DarkRed equ 0x990000
cl_Orange equ 0xbbbb00
 
showmas:
cmp [edi+8],dword 0
je noshow
cmp [edi+8],dword 1
jne no_gun
mov eax,shoot
jmp outp
no_gun:
push edi
random 3,ebx
pop edi
cmp ebx,0
jne no_star
mov eax,star
jmp outp
no_star:
cmp ebx,1
jne no_star2
mov eax,star2
jmp outp
no_star2:
mov eax,star3
outp:
aimgtoimg eax,dword [edi],dword [edi+4],canvas,0x0
noshow:
ret
; Define objects type id
EmptyObject equ 0
; This numbers not possible for modify because draw_objects:
BlueWarShip equ 1
GreenWarShip equ 2
Asteroid equ 3
Box equ 4
 
showobjmas:
cmp [edi+8],dword 0
je noshow1
cmp [edi+4],dword 380
jg noshow1
cmp [edi+4],dword 0
jl noshow1
cmp [edi+8],dword 1
jne no_warship1
mov eax,warship1
jmp outws
no_warship1:
cmp [edi+8],dword 2
jne no_warship2
mov eax,warship2
jmp outws
no_warship2:
cmp [edi+8],dword 3
jne no_meteor
mov eax,meteor
jmp outws
no_meteor:
cmp [edi+8],dword 4
jne no_box
mov eax,box
jmp outws
no_box:
outws:
aimgtoimg eax,dword [edi],dword [edi+4],canvas,0x0
noshow1:
ret
Laser equ 1
Plasma equ 2
StaticPlasma equ 3
 
;**************************************************************
; Start of programm
;**************************************************************
 
moveobjmas:
cmp [edi+8],dword 0
je no_ws
mov eax,[edi+12]
add [edi],eax
mov eax,[edi+16]
add [edi+4],eax
START: ; start of execution
 
cmp dword [edi],600
jng xok1
sub dword [edi],20
neg dword [edi+12]
jmp xok2
xok1:
cmp dword [edi],0
jnl xok2
add dword [edi],20
neg dword [edi+12]
xok2:
cmp dword [edi+4],400
jng yok
mov dword [edi+8],0
ret
yok:
cmp dword [edi+8],2 ;green ship
jne no_grs
cmp dword [edi+4],100
jna no_grs
cmp dword [edi+4],103
jna grs
cmp dword [edi+4],200
jna no_grs
cmp dword [edi+4],203
jna grs
cmp dword [edi+4],300
jna no_grs
cmp dword [edi+4],303
ja no_grs
grs:
neg dword [edi+12]
mov [temp],edi
findmas massive,findzero
;in edi off to free element
jc close_app
mov esi,edi
mov edi,[temp]
mov eax,[edi]
mov [esi],eax
mov eax,[edi+4]
mov [esi+4],eax
mov [esi+8],dword 1
mov [esi+12],dword 0
mov [esi+16],dword 10
no_grs:
max_particles = 400
particle_size = 20
 
cmp dword [edi+8],1 ;blue ship
jne no_bls
cmp dword [edi+4],50
jna no_bls
cmp dword [edi+4],64
jna bls
cmp dword [edi+4],100
jna no_bls
cmp dword [edi+4],114
jna bls
cmp dword [edi+4],150
jna no_bls
cmp dword [edi+4],164
ja no_bls
bls:
mov [temp],edi
findmas massive,findzero
jc close_app
mov esi,edi
mov edi,[temp]
mov eax,[edi]
mov [esi],eax
mov eax,[edi+4]
mov [esi+4],eax
mov [esi+8],dword 2
mov [esi+12],dword 0
mov [esi+16],dword 5
no_bls:
mov [particles],dword max_particles
mov [particles+4],dword particle_size
 
no_ws:
ret
max_objects = 100
object_size = 20
 
mov [objects],dword max_objects
mov [objects+4],dword object_size
 
delfarshoot:
cmp [edi+4],dword 40
jb del
cmp [edi+4],dword 400
ja del
cmp [edi],dword 40
jb del
cmp [edi],dword 600
ja del
jmp nodel
del:
mov [edi+8],dword 0
nodel:
ret
keyboard_set_input_mode 1 ; 0 - ASCII; 1 - scancodes;
 
;giftoimg gif_file_area2,canvas
giftoimg gif_file_area,objects_image
 
movemas:
cmp [edi+8],dword 0
jne no_freeel
ret
no_freeel:
mov eax,[edi+12]
add [edi],eax
mov eax,[edi+16]
add [edi+4],eax
ret
; load sprites
mov cl,9 ; cl - counter
xor esi,esi ; esi = 0
lea edi,[ship_img] ; address of first sprite
load_sprite:
pushad
getimg objects_image,esi,0,32,32,edi
popad
add edi,8+32*32*3 ; incrase offest of image data
add esi,32 ; incrase x position
dec cl
jnz load_sprite
 
set_main_menu:
mov ebx,-1 ; at start event_mode = -1
lea ecx,[draw_main_window]
lea edx,[menu_keyboard]
set_draw_proc:
; assembler extract command ; for use only bl
mov [event_mode],ebx
mov [draw_proc],ecx
mov [keyboard_proc],edx
; at first draw window
main_menu:
redraw_event: ; redraw event appears if user move, show/hide window
call draw_window
no_event:
call [draw_proc] ; no event no requre draw_window for no flickering
if stack_leak_debug = 1
; stack memory leak debug
lea ebp,[I_END]
sub ebp,esp
outcount ebp,10,30,cl_Green,5*65536
end if
menu_loop:
;wait_event redraw_event,keyboard_event,button_event
mov eax,10 ; wait event
mov ebx,[event_mode]
cmp ebx,-1 ; ebx delay for mcall 23
je wait_ev
mov eax,23 ; time event
wait_ev:
mcall
dec eax
js no_event
jz redraw_event
dec eax
jz keyboard_event
dec eax
jz button_event
jmp menu_loop ; if unknown event, skip it
 
keyboard_event: ; keyboard event if user press button
call [keyboard_proc]
jmp menu_loop
button_event:
window_get_button
cmp ah,1 ; if button id=1 (Red X of window) then close app
je close_app
cmp ah,2 ; if button id=2 then close app
je close_app
cmp ah,3 ; if button id=3 then start game
je start_game
cmp ah,4 ; if button id=3 then show help menu
je set_help_window ; jmp with redraw window
cmp ah,5 ; if button id=5 then back to main menu
je set_main_menu ; jmp with redraw window
cmp ah,6
je next_level ; run next level
cmp ah,7
je restart_lev ; restart level from gameover
cmp ah,9
je set_game_window ; back to game from menu
jmp menu_loop
 
endshowmas:
cmp [edi+8],dword 0
je noshowem
mov eax,star2
aimgtoimg eax,dword [edi],dword [edi+4],canvas,0x0
noshowem:
ret
close_app:
mov eax,-1 ; close this program
mcall
 
 
 
endmovemas:
cmp [edi+8],dword 0
jne no_fr
menu_keyboard:
; nothing do
window_get_key
ret
no_fr:
mov eax,[edi+12]
add [edi],eax
mov eax,[edi+16]
add [edi+4],eax
ret
 
;***********************
; Main screen menu
;***********************
 
findzero:
cmp [edi+8],dword 0
je iz_zero
xor eax,eax
draw_main_window:
draw_label 160,160,'Phoenix',cl_Red+font_size_x8
draw_button 3,300,320,60,14,'START',cl_DarkRed,cl_Yellow
draw_button 4,300,340,60,14,'HELP',cl_DarkRed,cl_Yellow
draw_button 2,300,360,60,14,'EXIT',cl_DarkRed,cl_Yellow
ret
iz_zero:
mov eax,1
ret
 
compobr:
cmp [esi+8],dword 0
je no_crsh
cmp [edi+8],dword 0
je no_crsh
cmp [esi+16],dword 0
jg no_crsh
;**********************
; End level process
;**********************
 
mov eax,[esi]
mov [temp],eax
mov eax,[esi+4]
mov [temp2],eax
mov eax,[edi]
mov [temp3],eax
mov eax,[edi+4]
mov [temp4],eax
set_end_level_window_from_call:
add esp,4 ; remove call address from stack
set_end_level_window:
lea edx,[menu_keyboard]
mov ebx,-1
lea ecx,[draw_end_level_window]
jmp set_draw_proc
 
pushad
collimg imgsize,[temp],[temp2],imgsize,[temp3],[temp4],[otv]
popad
cmp [otv],dword 0
je no_crsh
draw_end_level_window:
draw_frect 170,130,300,190,cl_Grey
draw_label 280,150,'LEVEL COMPLETE',cl_Black
draw_button 2,180,300,80,14,'EXIT',cl_DarkRed,cl_Black
draw_button 5,280,300,80,14,'<MENU>',cl_DarkRed,cl_Black
draw_button 6,380,300,80,14,'NEXT >',cl_DarkRed,cl_Black
 
cmp [edi+8],dword 2
jne no_grship
inc [gship]
add [score],30
jmp setzero
no_grship:
cmp [edi+8],dword 1
jne no_blship
inc [bship]
add [score],20
jmp setzero
no_blship:
cmp [edi+8],dword 3
jne no_metr
dec dword [edi+16]
cmp dword [edi+16],0
jne mok
mov dword [edi+16],1
mok:
mov [esi+8],dword 0
ret
no_metr:
draw_image 180,170,bwarship_img
draw_number [bships_destroyed],240,185,cl_Blue,3*65536
 
setzero:
mov [esi+8],dword 0
mov [edi+8],dword 0
no_crsh:
ret
draw_image 180,210,gwarship_img
draw_number [gships_destroyed],240,225,cl_Green,3*65536
 
shipobjtest:
cmp [edi+8],dword 0
je no_obj
mov eax,[edi]
mov [temp3],eax
mov eax,[edi+4]
mov [temp4],eax
pushad
collimg imgsize,[shipx],[shipy],imgsize,[temp3],[temp4],[otv]
popad
cmp [otv],dword 0
je no_obj
cmp [edi+8],dword 4 ;if box
jne no_fbox
add [energy],5
add [score],50
mov [edi+8],dword 0
inc [boxget]
draw_image 180,250,box_img
draw_number [boxes_taken],240,265,cl_Orange,3*65536
ret
no_fbox:
sub [energy],16
mov [edi+8],dword 0
no_obj:
ret
 
shipguntest:
cmp [edi+8],dword 0
je no_gobj
cmp [edi+16],dword 0
jl no_gobj
mov eax,[edi]
mov [temp3],eax
mov eax,[edi+4]
mov [temp4],eax
pushad
collimg imgsize,[shipx],[shipy],imgsize,[temp3],[temp4],[otv]
popad
cmp [otv],dword 0
je no_gobj
sub [energy],4
mov [edi+8],dword 0
no_gobj:
ret
;**********************
; Game Over process
;**********************
 
restart_lev:
mov [next_wave_timer],0 ; Reset new wave timer
prevpart:
call get_wave_info_offset
xor eax,eax
mov ax,[ebp]
dec eax ; If eax = 0 then start of level finded
jz reset_all_varibles_and_restart_level
dec [level_wave]
jmp prevpart
 
START: ; start of execution
set_game_over_window_from_call:
add esp,4
set_game_over_window:
lea edx,[menu_keyboard]
mov ebx,-1
lea ecx,[draw_game_over_window]
jmp set_draw_proc
 
massize = 400
elemsize = 20
 
mov [massive],dword massize
mov [massive+4],dword elemsize
 
omassize = 100
oelemsize = 20
 
mov [objmas],dword omassize
mov [objmas+4],dword oelemsize
 
 
mov eax,66
mov ebx,1
mov ecx,1
mcall
 
mov eax,26
mov ebx,2
mov ecx,1
mov edx,keymap
mcall
 
startgame:
giftoimg gif_file_area2,canvas
giftoimg gif_file_area,img_area
 
getimg img_area,0,0,32,32,ship
getimg img_area,32,0,32,32,shoot
getimg img_area,64,0,32,32,warship1
getimg img_area,96,0,32,32,warship2
getimg img_area,128,0,32,32,meteor
getimg img_area,160,0,32,32,star
getimg img_area,192,0,32,32,star2
getimg img_area,224,0,32,32,star3
getimg img_area,0,32,32,32,box
 
 
 
main_menu:
call draw_logowindow
 
stillm:
wtevent redm,keym,buttonm
jmp stillm
redm:
call draw_logowindow
jmp stillm
keym:
mov eax,2
mcall
jmp stillm
buttonm:
mov eax,17 ; get id
mcall
cmp ah,1 ; button id=1 ?
je close_app
cmp ah,2 ; button id=1 ?
je start_game
cmp ah,3 ; button id=1 ?
je help
cmp ah,4 ; button id=1 ?
je close_app
jmp stillm
 
draw_logowindow:
call draw_window
mcall 9,proc_info,-1
test [proc_info+process_information.wnd_state], 0x04
jz @f
draw_game_over_window:
draw_frect 170,160,300,120,cl_Grey
draw_label 292,200,'GAME OVER',cl_Black
draw_button 2,180,260,80,14,'EXIT',cl_DarkRed,cl_Black
draw_button 5,280,260,80,14,'MENU',cl_DarkRed,cl_Black
draw_button 7,380,260,80,14,'RESTART',cl_DarkRed,cl_Black
ret
@@:
setimg 5,21,canvas
drawlbut 300,300,60,14,'START',2,0x990000,cl_Black
drawlbut 300,320,60,14,'HELP',3,0x990000,cl_Black
drawlbut 300,340,60,14,'EXIT',4,0x990000,cl_Black
ret
 
;***********************
; Draw help menu
; Main game loop
;***********************
 
help:
call draw_helpwindow
next_level:
mov [next_wave_timer],0 ; Reset next wave timer
inc [level_wave] ; Next wave
start_game:
; Set canvas size before logo is showed
image_set_size canvas,screen_w,screen_h
 
stillh:
wtevent redh,keyh,buttonh
jmp stillh
redh:
call draw_helpwindow
jmp stillh
keyh:
mov eax,2
mcall
jmp stillh
buttonh:
mov eax,17 ; get id
mcall
cmp ah,1 ; button id=1 ?
je close_app
cmp ah,2 ; button id=1 ?
je start_game
cmp ah,3 ; button id=1 ?
je help
cmp ah,4 ; button id=1 ?
je close_app
cmp ah,5 ; button id=1 ?
je main_menu
jmp stillh
; Clear all, and prepeare varibles before start
reset_all_varibles_and_restart_level:
 
draw_helpwindow:
call draw_window
mcall 9,proc_info,-1
test [proc_info+process_information.wnd_state], 0x04
jnz stillh
setimg 5,21,canvas
; Clear objects arrays
mov eax,0
cld
mov edi,particles+8
mov ecx,max_particles*particle_size/4
rep stosd
mov edi,objects+8
mov ecx,max_objects*object_size/4
rep stosd
 
drawfbox 40,50,580,380,cl_Grey
; Reset keyboard state array
clear_buffer keymap, 128, 0
 
mov ebp,4*7
mov ebx,180*65536+90
mov edx,helptext
mov esi,50
mov ecx,cl_White
dec ebp
looht:
mov eax,4
mcall
add edx,esi
add ebx,10
dec ebp
jnz looht
; Reset player ship state
mov [player_hp],100
mov [shipx],screen_w/2-16 ; Player ship x start position
mov [shipy],screen_h-40 ; Player ship y start position
mov [laser_shoots],1000 ; Laser projectiles at start
mov [plasma_shoots],500 ; Plasma projectiles at start
 
setimg 90,90,ship
setimg 90,130,shoot
setimg 90,170,star
setimg 90,210,warship1
setimg 90,250,warship2
setimg 90,290,meteor
setimg 90,330,box
; Reset counters and gun charge values
xor eax,eax
mov [boxes_taken],eax
mov [gships_destroyed],eax
mov [bships_destroyed],eax
mov [laser_charge],eax
mov [plasma_charge],eax
 
drawlbut 500,400,80,14,'<<BACK',5,0x990000,cl_Black
set_game_window:
lea edx,[ingame_keyboard]
lea ecx,[draw_game_window]
mov ebx,2 ; time_event ebx = 2 ms
jmp set_draw_proc
 
jmp stillh
draw_game_window:
draw_image 5,24,canvas
 
helptext:
db 'Phenix '
db 'Controls: Num1 move left, Num3 move right '
db ' P-pause (use for screen shooting) '
db ' '
xor eax,eax ; Use eax as zero for compare
cmp [pause_on],eax ; If pause = 0 nothing do
je no_pause
ret
no_pause:
 
db 'Lazer cannon '
db 'Press Num5 for shoot '
db 'Core fast, speed fast, reload slow '
db ' '
cmp [player_hp],eax ; If player_hp < 0 game over
jl set_game_over_window_from_call
 
db 'Plazma cannon '
db 'Press Num2 for Plazma Nuke and Num8 for shoot '
db 'Core slow, speed medium, reload fast '
db ' '
cmp [laser_charge],eax
je no_dec_laser_charge
dec dword [laser_charge] ; If laser_charge > 0 decrase it
no_dec_laser_charge:
cmp [plasma_charge],eax
je no_dec_plasma_charge
dec dword [plasma_charge] ; If plasma_charge > 0 decrase it
no_dec_plasma_charge:
 
db 'Blue warship '
db 'Speed fast '
db 'Attack method: plazma bomb '
db ' '
; new wave test
inc dword [next_wave_timer]
call get_wave_info_offset
mov ax,[ebp] ; [ebp] = time to activate string
cwde ; extend ax to eax
cmp [next_wave_timer],eax
jne no_next_wave
 
db 'Green warship '
db 'Speed slow '
db 'Attack method: laser shoot '
db ' '
add_new_wave_of_objects:
mov cl,[ebp+4+0] ; cl = count of ships
mov ch,GreenWarShip ; ch = type of object
mov ebx,0x09040302 ; ebx = [xmoving]:[xaccel]:[ymoving]:[yaccel]
call add_objects ; add objects
 
db 'Meteor '
db 'Dangeros object! '
db 'SuperSheld '
db ' '
mov cl,[ebp+4+1] ; cl = count of ships
mov ch,BlueWarShip ; ch = type of object
mov ebx,0x03010306 ; ebx = random ranges : x = -1..1 y = -6..-4
call add_objects ; add objects
 
db 'Fly Box '
db 'Sheld pack, sheld +5, score +30 '
db 'Get for sheld level up! '
db ' '
mov cl,[ebp+4+2] ; cl = count of asteroids
mov ch,Asteroid ; ch = type of object
mov ebx,0x05020502 ; ebx = [xmoving]:[xaccel]:[ymoving]:[yaccel]
call add_objects ; add objects
 
start_game:
mov cl,[ebp+4+3] ; cl = count of boxes
mov ch,Box ; ch = type of object
mov ebx,0x05020401 ; ebx = [xmoving]:[xaccel]:[ymoving]:[yaccel]
call add_objects ; add objects
 
; jmp end_gm
mov [next_wave_timer],0 ; Reset next wave timer
inc [level_wave] ; Next wave
no_next_wave:
 
mov [canvas],dword 640
mov [canvas+4],dword 440
; Calculate all active objects on screen
xor eax,eax ; Use eax as zero
mov [objects_num],eax
array_processing objects,endtest ; ar_proc not modify eax, ebx
xor eax,eax ; Use eax as zero
cmp [objects_num],eax ; If [objects_num] != 0, level is not complete
jnz level_not_complete
 
call draw_window
call get_wave_info_offset
mov ax,[ebp+2] ; ax = maxyrange
cwde ; extend ax to eax
xor ebx,ebx ; Use ebx as zero for compare
cmp eax,ebx ; If [ebp+2] of level = 0, this is end of level
je set_end_level_window_from_call ; Show player score
dec ebx ; Use ebx as -1 for compare
cmp eax,ebx
je set_final_screen_window_from_call ; Show final animation
level_not_complete:
 
;Main loop wait for event with 10msec
still:
; scevent red,key,button ;for full speed
no_end_lev:
 
timeevent 1,no_event,red,key,button
no_event:
mcall 9,proc_info,-1
test [proc_info+process_information.wnd_state], 0x04
jnz still
setimg 5,21,canvas
; Key state processing
cmp byte [keymap+key_Right],0
je no_key_right
add dword [shipx],6
no_key_right:
cmp byte [keymap+key_Left],0
je no_key_left
sub dword [shipx],6
no_key_left:
cmp byte [keymap+key_Space],0
je no_key_lshoot
call try_to_make_laser_shoot
;call try_to_make_plasma_shoot
no_key_lshoot:
cmp byte [keymap+key_Up],0
je no_key_pshoot
;call try_to_make_plasma_nuke
call try_to_make_plasma_shoot
no_key_pshoot:
cmp byte [keymap+key_Down],0
je no_key_pnuke
call try_to_make_plasma_nuke
;call try_to_make_laser_shoot
no_key_pnuke:
 
cmp [pause_on],0
jne still
; Ship position correction (clamp macro)
cmp [shipx],5
jnl @f
mov [shipx],5
@@:
cmp [shipx],screen_w-32-5
jng @f
mov [shipx],screen_w-32-5
@@:
 
cmp [energy],0
jl game_over
mov al,7
if light_space = 1
mov al,255
end if
clear_buffer canvas+8,canvas_end-canvas-8,al
 
cmp [ctime],dword 0
je no_dct
dec dword [ctime]
no_dct:
compmas objects,particles,objects_and_particles_hit_handling
; move objects and particles
array_processing objects,move_objects
array_processing particles,move_particles
; remove particles out of screen
array_processing particles,remove_outofscr_particles
; objects and particles collision test
array_processing objects,player_and_objects_collision_handling
array_processing particles,player_and_particles_collision_handling
; draw objects and particles
array_processing objects,draw_objects
array_processing particles,draw_particles
; draw player ship
image_draw_acimage canvas,ship_img,[shipx],[shipy],cl_Black
 
cmp [xtime],dword 0
je no_dxt
dec dword [xtime]
no_dxt:
; Draw info indicators
draw_frect 150,5,64,5,cl_Black
mov eax,[plasma_charge]
sub eax,256
neg eax
shr eax,2
draw_frect 150,5,eax,5,cl_Cyan
 
draw_frect 150,12,64,5,cl_Black
mov eax,[laser_charge]
sub eax,8
neg eax
shl eax,3
draw_frect 150,12,eax,5,cl_Yellow
 
;
; Add to level new ships
;
inc dword [pathtime]
mov ebp,[levelpart]
shl ebp,5
add ebp,levels
mov eax,[ebp]
cmp [pathtime],eax ;500
jne no_nextloc
draw_frect 220,2,6*5+2 ,9,cl_Grey
draw_number [plasma_shoots],221,3,cl_Cyan,5*65536
draw_frect 220,11,6*5+2 ,9,cl_Grey
draw_number [laser_shoots],221,12,cl_Yellow,5*65536
 
randobjmasx:
mov ebp,[levelpart]
shl ebp,5
add ebp,levels
draw_frect 280,6,6*5+2 ,9,cl_Grey
draw_number [gships_destroyed],281,7,cl_Green,5*65536
draw_frect 320,6,6*5+2 ,9,cl_Grey
draw_number [bships_destroyed],321,7,cl_Blue,5*65536
draw_frect 360,6,6*5+2 ,9,cl_Grey
draw_number [boxes_taken],361,7,0xffaa00,5*65536
 
mov ecx,[ebp+8]
mov [shiptype],2
mov [xmoving],9
mov [xaccel],4
mov [ymoving],3
mov [yaccel],2
call add_ships
; number of objects in scene
draw_frect 400,2,6*5+2 ,9,cl_Grey
draw_number [objects_num],401,2,cl_Lime,5*65536
 
mov ecx,[ebp+12]
mov [shiptype],1
mov [xmoving],3
mov [xaccel],1
mov [ymoving],3
mov [yaccel],6
call add_ships
draw_frect 400,11,6*5+2 ,9,cl_Grey
draw_number [player_hp],401,12,cl_Red,5*65536
 
mov ecx,[ebp+16]
mov [shiptype],3
mov [xmoving],5
mov [xaccel],2
mov [ymoving],5
mov [yaccel],2
call add_ships
draw_frect 450,11,6*5+2 ,9,cl_Grey
draw_number [score],451,12,cl_Yellow,5*65536 ;+hide_zeros
 
mov ecx,[ebp+20]
mov [shiptype],4
mov [xmoving],4
mov [xaccel],1
mov [ymoving],4
mov [yaccel],1
call add_ships
; print keyboard keys state as string for debug
if keyboard_debug = 1
mov ebx,10*65536+40
mov edx,keymap
mov esi,128
mov ecx,cl_White
mov eax,4
mcall
end if
ret
 
jmp newlocend
; Proc for calculate active objects on screen
; eax - empty object type = 0
endtest:
xor eax,eax
cmp dword [edi+8],eax ; object is empty ?
je is_free
inc [objects_num]
is_free:
ret
 
shiptype dd 0
xmoving dd 0
ymoving dd 0
xaccel dd 0
yaccel dd 0
 
add_ships:
looship:
cmp ecx,0
je no_ships
push ecx
findmas objmas,findzero
;in edi off to free element
jc close_app
mov ebp,[shiptype]
mov dword [edi+8],ebp ;2 ;green ship
; random x
push edi
random 600,eax
pop edi
mov [edi],eax
; random y
push edi
mov ebp,[levelpart]
shl ebp,5
add ebp,levels
mov esi,[ebp+4] ;get max range
random esi,eax
neg eax
pop edi
mov [edi+4],eax
; x moving
push edi ;planers
random [xmoving],eax
sub eax,[xaccel];4
pop edi
mov [edi+12],eax
; y moving
push edi
random [ymoving],eax ;slow
add eax,[yaccel] ;2
pop edi
mov [edi+16],eax
pop ecx
dec ecx
jnz looship
no_ships:
; Proc for get offest to current level wave information
get_wave_info_offset:
mov ebp,[level_wave]
shl ebp,3 ; ebp = ebp*8; 8 - lenght of one string in levels array
add ebp,levels ; ebp = offset to string in levels array
ret
 
; time_bwns - time before next wave start
; yrmax - y random position maximum value
macro objects_wave time_bnws, yrmax, gships, bships, asteroids, boxes{
dw time_bnws, yrmax
db gships, bships, asteroids, boxes
}
 
levelpart dd 0
level_wave dd 0
; this array may optimized
levels:
; for game not ended at start, each level must have objects set at start (1)
; test pattern
if debug_scenario = 1
; two levels for debug game
objects_wave 1, 10, 1, 2, 4, 8 ; objset at start
objects_wave 0, 0, 0, 0, 0, 0
objects_wave 1, 10, 3, 3, 3, 3 ; objset at start
objects_wave 0, -1, 0, 0, 0, 0
else
;level1
dd 1,800,0,0,5,8,0,0 ;one at start
dd 500,2000,4,20,30,0,0,0
dd 500,2000,4,20,0,8,0,0
dd 500,2000,10,0,0,4,0,0
dd 500,4000,0,30,0,0,0,0
dd 400,400,0,0,10,0,0,0
dd 400,400,0,0,10,0,0,0
dd 0,0,0,0,0,0,0,0 ;end of level
objects_wave 1, 4000, 3, 10, 10, 0 ; objset at start
objects_wave 800, 2000, 5, 3, 5, 3
objects_wave 400, 2000, 3, 7, 5, 3
objects_wave 400, 800, 3, 5, 3, 0
objects_wave 0, 0, 0, 0, 0, 0 ; end of level
;level2
dd 1,16000,0,30,0,0,0,0 ;one at start
dd 200,8000,0,20,0,0,0,0
dd 200,2000,0,10,0,8,0,0
dd 200,4000,0,10,0,0,0,0
dd 0,0,0,0,0,0,0,0 ;end of level
objects_wave 1, 4000, 10, 40, 0, 8 ; objset at start
objects_wave 400, 4000, 10, 10, 20, 6
objects_wave 400, 2000, 0, 20, 10, 2
objects_wave 400, 400, 10, 10, 20, 0
objects_wave 0, 0, 0, 0, 0, 0 ; end of game
;level3
dd 1,4000,0,20,30,8,0,0 ;one at start
dd 400,4000,10,10,20,6,0,0
dd 400,4000,0,20,10,2,0,0
dd 400,4000,10,10,20,0,0,0
dd 0,-1,0,0,0,0,0,0 ;end of game
objects_wave 1, 800, 0, 0, 5, 5 ; objset at start
objects_wave 500, 2000, 4, 20, 30, 0
objects_wave 500, 2000, 4, 20, 0, 8
objects_wave 500, 2000, 10, 0, 0, 4
objects_wave 500, 4000, 0, 30, 0, 0
objects_wave 400, 400, 3, 5, 15, 0
objects_wave 400, 400, 0, 0, 10, 0
objects_wave 0, -1, 0, 0, 0, 0 ; end of level
end if
 
;***********************************
; In game keyboard
;***********************************
 
newlocend:
mov [pathtime],0
inc [levelpart]
jmp no_nextloc
ingame_keyboard:
window_get_key ; read key (eax=2)
cmp al,0
jne this_is_hotkey
; ah - contain scan code, al = 0
shl eax,16
shr eax,24 ; equal shr eax,8 + and eax,0x0FF
; eax - contain scan code
 
endgame dd 0
objects dd 0
endtest:
cmp dword [edi+8],0
jne no_free
ret
no_free:
mov [endgame],0
inc [objects]
ret
cmp al,key_P+128
jne not_P_key_up_scan_code
not [pause_on]
not_P_key_up_scan_code:
 
if debug_mode = 1
cmp al,key_E ; player hp = player hp / 2
jne no_hp_test
shr [player_hp],1
no_hp_test:
cmp al,key_A ; player hp = 10000
jne no_hp_up
mov [player_hp],10000
no_hp_up:
cmp al,key_W ; Run final screen
je set_final_screen_window_from_call
end if
 
no_nextloc:
mov [objects],0
mov [endgame],1
readmas objmas,endtest
cmp [endgame],1
jne no_end_lev ;no_nextloc
; Keyboard array update, needs sub state
cmp al,01111111b
ja key_released
mov byte [keymap+eax],'1' ; If scan code of key down
jmp key_pressed
key_released:
and al,01111111b
mov byte [keymap+eax],0 ; If scan code of key up
key_pressed:
this_is_hotkey:
ret
 
mov ebp,[levelpart]
shl ebp,5
add ebp,levels
mov eax,[ebp+4]
cmp eax,dword 0
je end_lev ;end of level
cmp eax,dword -1
je end_gm ;end of game
;**********************
; Final screen process
;**********************
 
no_end_lev:
set_final_screen_window_from_call:
add esp,4 ; Remove call address from stack
set_final_screen_window:
lea edx,[menu_keyboard]
mov ebx,1
lea ecx,[draw_final_screen_window]
jmp set_draw_proc
 
cmp [num5],dword 0
je no_addsh
cmp [ctime],dword 0
jne no_addsh
cmp [lazer],dword 0
je no_addsh
findmas massive,findzero
;in edi off to free element
jc close_app
mov eax,[shipx]
mov [edi],eax
mov eax,[shipy]
mov [edi+4],eax
mov [edi+8],dword 1 ;show
mov [edi+12],dword 0
mov [edi+16],dword -12
mov [ctime],dword 8 ;wait for cannon
dec [lazer]
no_addsh:
you_won_text: db 'YOU WON!',0
 
cmp [num8],dword 0
je no_addplx
cmp [xtime],dword 256-16
jae no_addplx
cmp [plazma],0
je no_addplx
findmas massive,findzero
;in edi off to free element
jc close_app
mov eax,[shipx]
mov [edi],eax
mov eax,[shipy]
mov [edi+4],eax
mov [edi+8],dword 2 ;show
add [xtime],dword 8 ;wait for cannon
cmp [xtime],dword 256
jna okx
mov [xtime],256
okx:
mov [edi+12],dword 0 ;wait for cannon
mov [edi+16],dword -8 ;wait for cannon
dec [plazma]
no_addplx:
draw_final_screen_window:
draw_image 5,24,canvas
logo_font_size equ 5
logo_x = 5+(screen_w/2)-(6*logo_font_size*8/2)
logo_y = screen_h/16*5
draw_label logo_x,logo_y,you_won_text,cl_White+((logo_font_size-1) shl 24)
;image_draw_label canvas,200,8,'YOU WON!',cl_White
draw_button 5,(screen_w/2)-40+5,300,80,14,'BACK TO MENU',cl_DarkRed,cl_Black
 
clear_buffer canvas+8,canvas_end-canvas-8,7
 
image_draw_acimage canvas,ship_img,(screen_w/2)-16,220,cl_Black
array_processing particles,draw_particles
array_processing particles,move_particles ; move particles
array_processing particles,remove_outofscr_particles ; del_outscreen_particles
 
cmp [num2],dword 0
je no_addsh2
cmp [xtime],dword 0
jne no_addsh2
cmp [plazma],0
je no_addsh2
mov eax,[shipy]
mov [temp3],eax
mov [temp2],dword 5
loox2:
mov [temp],dword 10
loox:
findmas massive,findzero
;in edi off to free element
try_to_make_firework:
inc [next_wave_timer]
cmp [next_wave_timer],30
jna no_firework
mov [next_wave_timer],0 ; reset firework timer before make firework
random screen_w-60,eax
mov ebx,eax
random screen_h-60,eax
mov edx,eax
mov ecx,8 ; how much particles make in one fire explode
next_star:
array_find particles,find_empty_object
jc close_app
random 25,eax
mov ebp,eax
sub eax,12
add eax,[shipx]
mov [edi],eax
shr ebp,3
random ebp,eax
neg eax
add eax,[temp3] ;[shipy]
mov [edi+4],eax
mov [edi+8],dword 2 ;show hstar
mov [edi],ebx ; random x position
mov [edi+4],edx ; random y position
mov [edi+8],dword 3 ; type of partice = 3. final screen particle
rerand:
random 5,eax
sub eax,2
mov [edi+12],eax ;show hstar
jz rerand ; eax = -2...2 exclude 0
mov [edi+12],eax ; x velocity
rerand2:
random 7,eax
sub eax,8
mov [edi+16],eax ;show hstar
dec [temp]
jnz loox
sub [temp3],30
dec [temp2]
jnz loox2
mov [xtime],dword 256 ;wait for cannon
sub [plazma],50
no_addsh2:
sub eax,3
jz rerand2 ; eax = -3...3 exclude 0
mov [edi+16],eax ; y velocity
dec ecx
jnz next_star
no_firework:
ret
 
;***********************
; Help menu
;***********************
 
cmp [num1],dword 0
je no_left
sub dword [shipx],6
no_left:
set_help_window:
lea edx,[menu_keyboard]
mov ebx,-1
lea ecx,[draw_help_window]
jmp set_draw_proc
 
cmp [num3],dword 0
je no_right
add dword [shipx],6
no_right:
draw_help_window:
; draw background and gray rectangle for label
;draw_frect canvas size cl_Black
draw_frect 40,50,580,380,cl_Grey
 
;ship correct
cmp [shipx],5
jnl xl_ok
mov [shipx],5
xl_ok:
cmp [shipx],603
jng xr_ok
mov [shipx],603
xr_ok:
; draw labels
mov ebp,4*7+3 ; Set value to labels counter
mov ebx,180*65536+90
mov edx,helptext
mov esi,50
mov ecx,cl_White+(10000000b shl 24)
draw_next_string:
mov eax,4
mcall ; Draw label
@@:
mov al,[edx] ; Loop for find next zero
inc edx
cmp al,0
jne @b
 
add ebx,10 ; Incrase y position of label
dec ebp ; Decrase labels counter
jnz draw_next_string
 
;clear scrbuf
mov edi,canvas+8
cld
mov ecx,640*440*3/4
mov eax,0
rep stosd
; draw images of space objects
mov eax,90
mov ecx,7
@@:
mov esi,[(img_offset-4)+ecx*4]
pushad
draw_image 90,eax,esi
popad
add eax,40
dec ecx
jnz @b
 
compmas objmas,massive,compobr
draw_button 5,500,400,80,14,'< BACK',cl_DarkRed,cl_Black
ret
 
readmas objmas,shipobjtest
readmas massive,shipguntest
; Offset to images showed in help screen in reverse sequence
img_offset:
dd box_img,asteroid_img,gwarship_img,bwarship_img
dd plasma1_img,laser_img,ship_img
 
readmas objmas,showobjmas
readmas objmas,moveobjmas
helptext:
db 'Phoenix - player ship',0
db 'Controls:',0
db 'Left or Right Arrows for move ship, P - button for pause',0
db 0
db 'Laser gun',0
db 'Recharge fast, speed fast. Projectile speed is medium',0
db 'Press Space button for shoot',0
db 0
db 'Plasma gun',0
db 'Recharge slow, reload fast. Projectile speed is fast',0
db 'Press Up button for shoot or Down button for make Nuke',0
db 0
db 'Blue warship',0
db 'Moving speed is fast',0
db 'Armed with plasma bombs',0
db 0
db 'Green warship',0
db 'Moving speed is medium',0
db 'Armed with laser gun',0
db 0
db 'Asteroid',0
db 'Is not destructable dangeros object!',0
db 'Collision with asteroid damage ship to much',0
db 0
db 'Repear Box',0
db 'Shield pack. Shield +5, Score +30',0
db 'Take on board for shield level up!',0
db 0,0,0
db 'Developed by Pavlushin Evgeni 2004',0
 
readmas massive,showmas
readmas massive,movemas
readmas massive,delfarshoot
; findmas massive,findzero
;in edi off to free element
; jc close_app
; ****************************************
; GLOBAL DRAW WINDOW
; ****************************************
 
aimgtoimg ship,[shipx],[shipy],canvas,0x0
draw_window:
window_begin_draw
mcall 0, <40, screen_w+9>, <40, screen_h+24+4>, 0x14000000,, wtitle
window_end_draw
ret
 
drawfbox 150,5,64,5,0x000000
mov eax,[xtime]
sub eax,256
neg eax
shr eax,2
drawfbox 150,5,eax,5,0x0000ff
; ****************************************
; GAME PROCEDURE AREA
; ****************************************
 
drawfbox 150,12,64,5,0x000000
mov eax,[ctime]
sub eax,8
; Procedure for add ships to scene
; cl - number of ships which need to add 0..255
; ebp - offset to level string
add_objects:
; unpack values from ebx
xor eax,eax
mov al,ch
mov [shiptype],eax
mov al,bl
mov [yaccel],eax
mov al,bh
mov [ymoving],eax
shr ebx,16
mov al,bl
mov [xaccel],eax
mov al,bh
mov [xmoving],eax
next_ship:
cmp cl,0
je no_ships ; if ships quantity = 0, exit from proc
push ecx
push ebp
; find empty slot in space objects array
array_find objects,find_empty_object
jc close_app
; edi = offset to empty place in array
mov eax,[shiptype]
mov dword [edi+8],eax ; store ship type
; Randomize x position
random screen_w-32,eax
mov [edi],eax
; Randomize y position
pop ebp
mov ax,[ebp+2] ; get max range
cwde ; extend ax to eax
random eax,eax
neg eax
shl eax,3
drawfbox 150,12,eax,5,0xffff00
mov [edi+4],eax
; Randomize x moving
random [xmoving],eax
sub eax,[xaccel]
mov [edi+12],eax
; Randomize y moving
random [ymoving],eax
add eax,[yaccel]
mov [edi+16],eax
pop ecx
dec cl
jnz next_ship
no_ships:
ret
 
drawfbox 220,2,6*5+2 ,9,cl_Grey
outcount [plazma],221,3,cl_Blue,5*65536
drawfbox 220,11,6*5+2 ,9,cl_Grey
outcount [lazer],221,12,0xffff00,5*65536
; search empty slot in object array
find_empty_object:
cmp [edi+8],dword 0 ; if object type == 0 then it empty
je is_finded ; empty object is finded set CF = 0
; find_next
stc ; CF = 1
ret
is_finded:
clc ; CF = 0
ret
 
; Try to draw particle from particle array
draw_particles:
mov ecx,[edi+8] ; ecx - type of particle
cmp ecx,0 ; if type == 0 then do not draw object
je return
mov eax,laser_img
cmp ecx,Laser ; this is laser particle
je draw_space_object
mov eax,plasma2_img
cmp ecx,StaticPlasma ; particle type for final screen animation
je draw_space_object
random 3,ebx ; if else this is Plasma particle
mov eax,plasma1_img
dec ebx
jz draw_space_object
mov eax,plasma2_img
dec ebx
jz draw_space_object
mov eax,plasma3_img
jmp draw_space_object
 
drawfbox 280,6,6*5+2 ,9,cl_Grey
outcount [gship],281,7,cl_Green,5*65536
drawfbox 320,6,6*5+2 ,9,cl_Grey
outcount [bship],321,7,cl_Blue,5*65536
drawfbox 360,6,6*5+2 ,9,cl_Grey
outcount [boxget],361,7,0xffaa00,5*65536
; Draw space objects from array
draw_objects:
mov ecx,[edi+8] ; ecx = [edi+8] - type of ship
cmp ecx,0 ; if type of ship == 0 then not draw it
je return
cmp ecx,(ot_end-object_type)/4+1
jae return ; if type out of range ignore it
mov edx,[edi+4] ; edx = [edi+4] - y position of ship
cmp edx,screen_h-40
jg return
cmp edx,0 ; do not draw object if it y position is out of screen
jl return
mov eax,[(object_type-4)+ecx*4] ; -4 when types starts from 1 instead 0
draw_space_object:
image_draw_acimage canvas,eax,dword [edi],dword [edi+4],cl_Black
return:
ret
 
drawfbox 400,2,6*5+2 ,9,cl_Grey
outcount [objects],401,2,0x00ff00,5*65536
drawfbox 400,11,6*5+2 ,9,cl_Grey
outcount [energy],401,12,0xff0000,5*65536
object_type: dd bwarship_img,gwarship_img,asteroid_img,box_img
ot_end:
 
drawfbox 450,11,6*5+2 ,9,cl_Grey
outcount [score],451,12,0xffff00,5*65536
; Update (move) particles (laser,plasma)
move_particles:
xor eax,eax
cmp [edi+8],eax ; Is object not empty ?
je this_is_empty_particle
move_particle:
mov eax,[edi+12]
add [edi],eax ; objectx + [edi+12]
mov eax,[edi+16]
add [edi+4],eax ; objecty + [edi+16]
this_is_empty_particle:
ret
 
; update (move) space objects (ships,asteroids,boxes)
move_objects:
xor eax,eax
cmp [edi+8],eax
je object_is_empty
;call move_particle
mov eax,[edi+12]
add [edi],eax
mov eax,[edi+16]
add [edi+4],eax
 
jmp still
; Do not allow object to go out of screen from right side
mov eax,screen_w-32 ; eax = right side of screen
cmp dword [edi],eax
jng right_side_ok
mov dword [edi],eax
neg dword [edi+12]
jmp left_side_ok
right_side_ok:
; Do not allow object to go out of screen from left side
xor eax,eax ; eax = 0 - left side of screen
cmp dword [edi],eax
jnl left_side_ok
mov dword [edi],eax
neg dword [edi+12]
left_side_ok:
; If object out of screen remove it
cmp dword [edi+4],screen_h;-40
jng y_ok
mov dword [edi+8],0 ; Delete object
ret
y_ok:
cmp dword [edi+8],GreenWarShip ; Object is green enemy ship?
jne no_grs
mov eax,dword [edi+4] ; eax = y position of enemy ship
; alternative way is use random for shoot
cmp eax,100
jna no_grs
cmp eax,103
jna grs
cmp eax,200
jna no_grs
cmp eax,203
jna grs
cmp eax,300
jna no_grs
cmp eax,303
ja no_grs
grs:
; invert y moving direction and make shoot
neg dword [edi+12]
mov [temp],edi
array_find particles,find_empty_object
jc close_app
mov esi,[temp] ; edi contains address to free element
mov [edi+8],dword 1
mov [edi+12],dword 0
mov [edi+16],dword 10
jmp set_particle_position
no_grs:
cmp dword [edi+8],BlueWarShip ; object is blue enemy ship ?
jne no_bls
mov ecx,dword [edi+4]
cmp ecx,50
jna no_bls
cmp ecx,64
jna bls
cmp ecx,100
jna no_bls
cmp ecx,114
jna bls
cmp ecx,150
jna no_bls
cmp ecx,164
ja no_bls
bls:
; drop plasma mine
mov [temp],edi
array_find particles,find_empty_object
jc close_app
mov esi,[temp]
mov [edi+8],dword 2
mov [edi+12],dword 0
mov [edi+16],dword 5
set_particle_position:
mov eax,[esi]
mov [edi],eax ; Particle x = Ship x
mov eax,[esi+4]
mov [edi+4],eax ; Partcle y = Ship y
no_bls:
object_is_empty:
ret
 
red:
call draw_window
jmp still
; Remove particles that have gone out off screen
remove_outofscr_particles:
cmp dword [edi+4],40 ; test y position
jl del
cmp dword [edi+4],screen_h-40
jg del
cmp dword [edi],0 ; x test used for plasma shoots
jl del
cmp dword [edi],screen_w-32
jg del
ret ; do not delete
del:
xor eax,eax
mov [edi+8],eax ; [edi+8] = 0
not_del:
ret
 
key: ; key
mov eax,2
mcall ; read (eax=2)
objects_and_particles_hit_handling:
xor eax,eax
cmp [esi+8],eax
je no_hit
cmp [edi+8],eax ; If object is empty skip crush test
je no_hit
cmp [esi+16],eax
jg no_hit
 
shr eax,8
and eax,0xff
mov ah,al
mov eax,[esi]
shl eax,16
mov ax,word [esi+4]
mov ebx,32*65536+32
mov ecx,[edi]
shl ecx,16
mov cx,word [edi+4]
mov edx,32*65536+32
 
cmp ah,153
jne no_pause
not [pause_on]
jmp still
no_pause:
game_collision_2d eax,ebx,ecx,edx
jnc no_hit
 
 
cmp ah,76
jne no_num5d
mov [num5],1
jmp still
no_num5d:
cmp ah,204
jne no_num5u
mov [num5],0
jmp still
no_num5u:
 
cmp ah,80
jne no_num2d
mov [num2],1
jmp still
no_num2d:
cmp ah,208
jne no_num2u
mov [num2],0
jmp still
no_num2u:
 
cmp ah,79 ;key_Space 85 exit
jne no_num1d
mov [num1],1
jmp still
no_num1d:
cmp ah,207 ;key_Space 85 exit
jne no_num1u
mov [num1],0
jmp still
no_num1u:
 
cmp ah,81 ;key_Space 85 exit
jne no_num3d
mov [num3],1
jmp still
no_num3d:
cmp ah,209 ;key_Space 85 exit
jne no_num3u
mov [num3],0
jmp still
no_num3u:
 
cmp ah,72 ;key_Space 85 exit
jne no_num8d
mov [num8],1
jmp still
no_num8d:
cmp ah,200 ;key_Space 85 exit
jne no_num8u
mov [num8],0
jmp still
no_num8u:
 
jmp still ; not testing
 
button: ; button
mov eax,17 ; get id
mcall
cmp ah,1 ; button id=1 ?
jne noclose
close_app:
mov eax,-1 ; close this program
mcall
noclose:
jmp still
 
draw_window:
mcall 12,1 ;start window redraw
mcall 0, <40, 640+9>, <40, 440+26>, 0x14000000,, wtitle
mcall 12,2 ;end window redraw
; setimg 5,22,img_area
 
cmp dword [edi+8],GreenWarShip
jne not_grship
inc [gships_destroyed]
add [score],30
jmp remove_object_and_particle
not_grship:
cmp dword [edi+8],BlueWarShip
jne not_blship
inc [bships_destroyed]
add [score],20
jmp remove_object_and_particle
not_blship:
cmp dword [edi+8],Asteroid
jne not_asteroid
cmp dword [edi+16],1 ; Asteroid have minimal speed?
je remove_only_particle
dec dword [edi+16] ; Decrase speed of asteroid
jmp remove_only_particle
not_asteroid:
remove_object_and_particle: ; When hit to ship or box
mov [edi+8],dword 0
remove_only_particle: ; When hit to asteroid
mov [esi+8],dword 0
no_hit:
ret
 
;**********************
; Game Over process
;**********************
player_and_objects_collision_handling:
cmp [edi+8],dword 0
je no_obj_cr
 
game_over:
; close
call draw_gowindow
stillgo:
wtevent redgo,keygo,buttongo
jmp stillgo
redgo:
call draw_gowindow
jmp stillgo
keygo:
mov eax,2
mcall
jmp stillgo
buttongo:
mov eax,17 ; get id
mcall
cmp ah,1
je close_app
cmp ah,4
je close_app
cmp ah,5
je main_menu
cmp ah,7
je restart_lev
jmp stillgo
mov eax,[shipx]
shl eax,16
mov ax,word [shipy]
mov ebx,32*65536+32
mov ecx,[edi]
shl ecx,16
mov cx,word [edi+4]
mov edx,32*65536+32
 
restart_lev:
mov [pathtime],0
 
prevpart:
mov ebp,[levelpart]
shl ebp,5
add ebp,levels
mov eax,[ebp]
cmp eax,dword 1
je rest ;end of level
dec [levelpart]
jmp prevpart
 
 
rest:
;massives reset - clear massives
mov edi,massive+8
cld
mov ecx,massize*elemsize/4
mov eax,0
rep stosd
 
mov edi,objmas+8
cld
mov ecx,omassize*oelemsize/4
mov eax,0
rep stosd
 
;counters reset
mov [boxget],0
mov [gship],0
mov [bship],0
 
;ship reset
mov [energy],100
mov [shipx],300
mov [shipy],400
mov [lazer],1000
mov [plazma],500
 
 
; reset keyboard
mov [num1],0
mov [num5],0
mov [num3],0
mov [num2],0
mov [num8],0
jmp start_game
 
draw_gowindow:
startwd
call draw_window
mcall 9,proc_info,-1
test [proc_info+process_information.wnd_state], 0x04
jz @f
game_collision_2d eax,ebx,ecx,edx
jnc no_obj_cr
cmp dword [edi+8],Box ; if box
jne no_fbox
add [player_hp],5
add [score],50
mov [edi+8],dword 0 ; delete object
inc [boxes_taken]
ret
@@:
drawfbox 170,160,300,120,cl_Grey
drawlbut 180,260,80,14,'EXIT',4,0x990000,cl_Black
drawlbut 280,260,80,14,'MENU',5,0x990000,cl_Black
drawlbut 380,260,80,14,'RESTART',7,0x990000,cl_Black
 
label 280,200,' GAME OVER ',cl_Black
endwd
no_fbox:
sub [player_hp],16
mov [edi+8],dword 0 ; delete object
no_obj_cr:
ret
 
player_and_particles_collision_handling:
xor eax,eax ; use eax as zero
cmp [edi+8],eax ; empty object?
je no_gobj_cr
cmp [edi+16],eax ; is player ?
jl no_gobj_cr
 
;**********************
; End level process
;**********************
mov eax,[shipx]
shl eax,16
mov ax,word [shipy]
mov ebx,32*65536+32
mov ecx,[edi]
shl ecx,16
mov cx,word [edi+4]
mov edx,32*65536+32
 
end_lev:
; close
call draw_scorewindow
stilleg:
wtevent redeg,keyeg,buttoneg
jmp stilleg
redeg:
call draw_scorewindow
jmp stilleg
keyeg:
mov eax,2
mcall
jmp stilleg
buttoneg:
mov eax,17 ; get id
mcall
cmp ah,1
je close_app
cmp ah,2
je next_lev
cmp ah,3
je help
cmp ah,4
je close_app
cmp ah,5
je main_menu
jmp stilleg
game_collision_2d eax,ebx,ecx,edx
jnc no_gobj_cr
sub [player_hp],4
mov [edi+8],dword 0 ; delete object
no_gobj_cr:
ret
 
next_lev:
mov [pathtime],0
inc [levelpart]
;**************************
; Player ship shoot procs
;**************************
 
;ship reset
mov [energy],100
mov [shipx],300
mov [shipy],400
mov [lazer],1000
mov [plazma],500
 
;counters reset
mov [boxget],0
mov [gship],0
mov [bship],0
 
; reset keyboard
mov [num1],0
mov [num5],0
mov [num3],0
mov [num2],0
mov [num8],0
jmp start_game
 
draw_scorewindow:
call draw_window
mcall 9,proc_info,-1
test [proc_info+process_information.wnd_state], 0x04
jz @f
; Try to make laser shoot
try_to_make_laser_shoot:
cmp [laser_charge],dword 0
jne no_laser_shoot ; laser_shoots is heat, need time for recharge
cmp [laser_shoots],dword 0
je no_laser_shoot ; Don't shoot when so many laser particles on screen
array_find particles,find_empty_object ; edi = offset to emppty object
jc close_app ; ?
mov eax,[shipx]
mov [edi],eax ; 0 = x position of shoot
mov eax,[shipy]
mov [edi+4],eax ; 4 = y position of shoot
mov [edi+8],dword 1 ; 8 = 1 - laser type
mov [edi+12],dword 0 ; 12 = 0 - x speed
mov [edi+16],dword -12 ; 16 = -12 - y speed
mov [laser_charge],dword 8 ; Reset shoot timer
dec [laser_shoots] ; Decrase number of laser projectiles
no_laser_shoot:
ret
@@:
startwd
drawfbox 170,130,300,190,cl_Grey
drawlbut 180,300,80,14,'(X) EXIT',4,0x990000,cl_Black
drawlbut 280,300,80,14,'<MENU>',5,0x990000,cl_Black
drawlbut 380,300,80,14,'NEXT >>',2,0x990000,cl_Black
 
setimg 180,140,warship1
outcount [bship],241,151,cl_Blue,5*65536
 
setimg 180,180,warship2
outcount [gship],241,191,cl_Green,5*65536
 
setimg 180,220,meteor
setimg 180,260,box
outcount [boxget],241,271,0xbbbb00,5*65536
endwd
; Try to make plasma shoot
try_to_make_plasma_shoot:
cmp [plasma_charge],dword 256-16
jae no_plasma_shoot
cmp [plasma_shoots],0
je no_plasma_shoot
array_find particles,find_empty_object
; edi = off to free element
jc close_app ;?
mov eax,[shipx]
mov [edi],eax
mov eax,[shipy]
mov [edi+4],eax
mov [edi+8],dword 2 ; 8 = 2 - plasma
mov [edi+12],dword 0 ; 12 = 0 - x speed
mov [edi+16],dword -8 ; 16 = -8 - y speed
dec [plasma_shoots] ; Decrase number of plasma projectiles
add [plasma_charge],dword 8
cmp [plasma_charge],dword 256
jna no_plasma_shoot
mov [plasma_charge],256
no_plasma_shoot:
ret
 
 
;**********************
; End of game process
;**********************
 
end_gm:
mov [pathtime],0
call draw_window
label 200 ,8,'YOU WIN PRESS ANY KEY TO EXIT',cl_White+font_Big
 
stilleg2:
; scevent redeg2,keyeg2,buttoneg2
timeevent 1,no_event2,redeg2,keyeg2,buttoneg2
 
no_event2:
setimg 5,21,canvas
 
;clear scrbuf
mov edi,canvas+8
cld
mov ecx,640*440*3/4
mov eax,0
rep stosd
 
aimgtoimg ship,320,220,canvas,0x0
 
readmas massive,endshowmas
readmas massive,endmovemas
readmas massive,delfarshoot
; findmas massive,findzero
;in edi off to free element
; jc close_app
 
inc [pathtime]
cmp [pathtime],30
jne no_firework
mov [pathtime],0
random 400,eax
; Try to make plasma nuke
try_to_make_plasma_nuke:
xor eax,eax ; Use eax as zero
cmp [plasma_charge],eax
jne no_plasma_nuke
cmp [plasma_shoots],eax
je no_plasma_nuke
mov eax,[shipy]
mov [temp3],eax
random 600,eax
mov [temp2],eax
mov [temp],dword 8;10
xloox:
findmas massive,findzero
;in edi off to free element
mov [temp2],dword 5
loopx2:
mov [temp],dword 10
loopx:
array_find particles,find_empty_object ; edi = offset to empty element
jc close_app
 
mov eax,[temp2] ;[shipx]
mov [edi],eax
mov eax,[temp3] ;[shipy]
random 25,eax
mov ebp,eax
sub ebp,12
add ebp,[shipx]
mov [edi],ebp ; [edi] = random(0..25)-12+shipx
shr eax,3
random eax,eax
neg eax
add eax,[temp3]
mov [edi+4],eax
mov [edi+8],dword 2 ;show hstar
rerand:
mov [edi+8],dword 2 ; 8 = 2 - plasma
random 5,eax
sub eax,2
cmp eax,0
je rerand
mov [edi+12],eax ;show hstar
rerand2:
mov [edi+12],eax
random 7,eax
sub eax,3
cmp eax,0
je rerand2
mov [edi+16],eax ;show hstar
sub eax,8
mov [edi+16],eax
dec [temp]
jnz xloox
no_firework:
jmp stilleg2
jnz loopx
sub [temp3],30 ; shipy - 30
dec [temp2]
jnz loopx2
mov [plasma_charge],dword 256 ; Wait for cannon
sub [plasma_shoots],50 ; -50 plasma bullets after nuke
no_plasma_nuke:
ret
 
redeg2:
jmp end_gm ;stilleg2
keyeg2:
mov eax,2
mcall
jmp main_menu
buttoneg2:
mov eax,17 ; get id
mcall
jmp stilleg2
; DATA AREA
IM_END:
wtitle db 'Phoenix for KOS', 0
 
score dd 0 ; player score
 
; Pause state, if != 0 then game on pause
pause_on dd 0
 
; Frames countdown timer until start of next wave
; If = 0 then activate to next wave
; next_wave_timer
next_wave_timer dd 0
 
;gif_file_area ~21500
;gif_file_area2:
;file 'phoenix.gif'
gif_file_area:
file 'objects.gif' ; Include gif file to code
 
IncludeUGlobals
 
; DATA AREA
IM_END:
;global
pause_on dd 0
; Window drawing function delegate (pointer)
draw_proc rd 1
; Keyboard processing function delegate (pointer)
keyboard_proc rd 1
 
;massive
shipx dd 300
shipy dd 400
; Counter of objects on screen
objects_num rd 1
 
player_hp rd 1 ; Health points of player ship
shipx rd 1 ; Player ship x position
shipy rd 1 ; Player ship y position
;guns
lazer dd 1000
plazma dd 500
laser_shoots rd 1 ; laser bullets quantity
plasma_shoots rd 1 ; plasma bullets quantity
; Counters of player statistics
gships_destroyed rd 1 ; Number of green ships destroyed by player
bships_destroyed rd 1 ; Number of blue ships destroyed by player
boxes_taken rd 1 ; Number of repair boxes taken by player
; Gun recharge counters
; 0 = fully charged
; 256 = fully uncharged
laser_charge rd 1 ; Laser gun recharge counter
plasma_charge rd 1 ; Plasma gun recharge counter
 
;keys
num1 dd 0
num5 dd 0
num3 dd 0
num2 dd 0
num8 dd 0
; Tempory varibles
temp rd 1
temp2 rd 1
temp3 rd 1
 
;enemy countres
gship dd 0
bship dd 0
boxget dd 0
event_mode rd 1 ; if -1 wait, 0 scan, n - n delay between events
 
energy dd 100
score dd 0
; Tempory varibles for add_objects proc
shiptype rd 1
xmoving rd 1
ymoving rd 1
xaccel rd 1
yaccel rd 1
 
;delay for cannon
ctime dd 0
;delay for nuke gun
xtime dd 0
;path time
pathtime dd 0
;
temp dd 0
temp2 dd 0
temp3 dd 0
temp4 dd 0
otv dd 0
; Memory for contain not splitted image
objects_image: rb 8+288*32*3 ;8+256*64*3
; Images sequence extracted from objects_image
ship_img: rb 8+32*32*3 ; Player red space ship
laser_img: rb 8+32*32*3 ; Double laser beams
bwarship_img: rb 8+32*32*3 ; Blue enemy ship
gwarship_img: rb 8+32*32*3 ; Green enemy ship
asteroid_img: rb 8+32*32*3 ; Space asteroid
plasma1_img: rb 8+32*32*3 ; Plasma big flash
plasma2_img: rb 8+32*32*3 ; Plasma medium flash
plasma3_img: rb 8+32*32*3 ; Plasma small flash
box_img: rb 8+32*32*3 ; Repear kit box
 
;for collimg
imgsize:
dd 32
dd 32
; array for storing state of keyboard keys
keymap: rb 128
 
;massive:
;dd 400 ;elements num
;dd 20 ;size of element in bytes
;rb 400*20
particles:
rd max_particles ; dword = maximum number of particle objects
rd particle_size ; dword = size of each particle object in bytes
rb max_particles*particle_size
 
keymap:
rb 1000
objects:
rd max_objects ; dword = maximum number of particles
rd object_size ; dword = size of each object in bytes
rb max_objects*object_size
 
wtitle db 'Phenix for KolibriOS', 0
 
;gif_file_area ~21500
gif_file_area2:
file 'phenix.gif'
gif_file_area:
file 'star2.gif';include gif file
img_area:
rb 256*64*3+8
ship:
rb 32*32*3+8
shoot:
rb 32*32*3+8
warship1:
rb 32*32*3+8
warship2:
rb 32*32*3+8
meteor:
rb 32*32*3+8
star:
rb 32*32*3+8
star2:
rb 32*32*3+8
star3:
rb 32*32*3+8
box:
rb 32*32*3+8
 
IncludeUGlobals
 
massive:
rd massize ;elements num
rd elemsize ;size of element in bytes
rb massize*elemsize
 
objmas:
rd omassize ;elements num
rd oelemsize ;size of element in bytes
rb omassize*oelemsize
 
canvas:
canvas_x:
rd 1
canvas_y:
rd 1
rb (640*440*3)+2000
rb 8+(screen_w*screen_h*3)
canvas_end:
 
proc_info:
rb 1024
I_END:
; application stack size
align 16
stack_max:
rb 2048
I_END:
/programs/games/phenix/trunk/phenix.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream