From a062803b7483611c21a0f2010ee7b1124df061fb Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Mon, 24 Nov 2014 20:00:42 +0000 Subject: [PATCH] Make invaders code a little less horrible. git-svn-id: svn://kolibrios.org@5188 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/games/invaders/ascgl.inc | 1388 ----------- programs/games/invaders/invaders.asm | 2349 ++++++++++-------- programs/games/invaders/invaders_kolibri.inc | 115 - 3 files changed, 1251 insertions(+), 2601 deletions(-) delete mode 100644 programs/games/invaders/ascgl.inc delete mode 100644 programs/games/invaders/invaders_kolibri.inc diff --git a/programs/games/invaders/ascgl.inc b/programs/games/invaders/ascgl.inc deleted file mode 100644 index c329fb3a45..0000000000 --- a/programs/games/invaders/ascgl.inc +++ /dev/null @@ -1,1388 +0,0 @@ -; -; Assembler -; SMALL -; CODE -; Graphics -; Libary -; -; Ver 0.18 By Pavlushin Evgeni (RUSSIA) -; www.waptap@mail.ru - -;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 - -aframetoimg_use_count=0 -macro aframetoimg img, x, y, canvas,acol -{ -local loo,loo2,acolor -aframetoimg_use_count=aframetoimg_use_count+1 -if aframetoimg_use_count = 1 - - jmp end_aframetoimg_proc - -acolor dd 0 -aframetoimg_proc: -;getout coord - mov [acolor],ebp - - mov edx,ebx ;img ;xsize - movzx eax,word [edx] - add eax,esi ;y cor - -; mov eax,esi ;y cor - mul dword [ecx] ;canvas xsize - add eax,edi ;x cor - - mov ebp,ebx ;img ;xsize - movzx edx,word [ebp] - add eax,edx - - mov ebp,eax - shl eax,1 - add ebp,eax - add ebp,ecx ;canvas+8;start - add ebp,8 -;get img size - add ebx,4 - mov eax,ebx ;img ;xsize - movzx esi,word [eax] - movzx edi,word [eax+2] - 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_aframetoimg_proc: -end if - push img - push canvas - push x - push y - push acol - pop ebp - pop esi - pop edi - pop ecx - pop ebx - call aframetoimg_proc -} - -frametoimg_use_count=0 -macro frametoimg img, x, y, canvas -{ -local loo,loo2 -frametoimg_use_count=frametoimg_use_count+1 -if frametoimg_use_count = 1 - - jmp end_frametoimg_proc - -frametoimg_proc: -;getout coord - mov edx,ebx ;img ;xsize - movzx eax,word [edx] - add eax,esi ;y cor - -; mov eax,esi ;y cor - mul dword [ecx] ;canvas xsize - add eax,edi ;x cor - - mov ebp,ebx ;img ;xsize - movzx edx,word [ebp] - add eax,edx - - mov ebp,eax - shl eax,1 - add ebp,eax - add ebp,ecx ;canvas+8;start - add ebp,8 -;get img size - add ebx,4 - mov eax,ebx ;img ;xsize - movzx esi,word [eax] - movzx edi,word [eax+2] - add ebx,4 - mov edx,ebx ;img+8 -loo2: -push esi -loo: - 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 - - 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_frametoimg_proc: -end if - push img - push canvas - push x - push y - pop esi - pop edi - pop ecx - pop ebx - call frametoimg_proc -} - - -aimgtoimg_use_count=0 -macro aimgtoimg img, x, y, canvas,acol,offset -{ -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 - push eax ;;;;;;;;;;;;;;;;;;; - 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 - pop eax - add edx,eax - -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 - push offset - pop eax - pop ebp - pop esi - pop edi - pop ecx - pop ebx - call aimgtoimg_proc -} - - - - -imgtoimg_use_count=0 -macro imgtoimg img, x, y, canvas -{ -local loo,loo2 -imgtoimg_use_count=imgtoimg_use_count+1 -if imgtoimg_use_count = 1 - - jmp end_imgtoimg_proc -imgtoimg_proc: -;getout coord - 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: - 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 - 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_imgtoimg_proc: -end if - push img - push canvas - push x - push y - pop esi - pop edi - pop ecx - pop ebx - call imgtoimg_proc -} - - -;DrawBox -macro drawfbox x,y,xs,ys,color -{ - words2reg ebx,x,xs ;x*65536+xs - words2reg ecx,y,ys ;y*65536+ys - mov edx,color - mov eax,13 - int 0x40 -} - -; FPS - Set Frame Per Second Display -fps_show_frequency=40 -macro fps x,y,color,delcolor -{ -local spdat,savetime,new_time,fps,fps_cntr,out_fps,new_time,ttt -local no_out_fps - jmp spdat -savetime dd 0 -fps_cntr dd 0 -fps dd 0 -ttt dd 0 -spdat: -get_time: - mov eax,3 - int 0x40 - cmp eax,[savetime] - jne new_time - inc [fps_cntr] - cmp dword [ttt],0 - je out_fps - dec dword [ttt] - jmp no_out_fps -new_time: - mov [savetime],eax - mov ebx,[fps_cntr] - mov [fps],ebx - mov [fps_cntr],0 -out_fps: -if ~(delcolor eq ) - mov ebx,x*65536+30 - mov ecx,y*65536+7 - mov edx,delcolor - mov eax,13 - int 0x40 -end if - mov dword [ttt],fps_show_frequency - mov eax,47 - mov ebx,5*65536 -; mov bl,0 - mov edx,x*65536+y - mov esi,color - mov ecx,[fps] - int 0x40 -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 - mov [esi+2],al - add esi,3 - dec ecx - jnz loo -} - - -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] - words2reg edx, x , y ;arg1*65536+arg2 - int 0x40 -} - -macro setframe x , y ,arg3 -{ - mov eax,7 - mov ebx,arg3 - add ebx,8 - words2reg edx, x , y ;arg1*65536+arg2 - add edx,dword [arg3] - mov ecx,dword [arg3+4] - int 0x40 -} - - -macro getimg imgsrc,x,y,xs,ys,imgdest -{ -local cyc -if xs eqtype 0 - mov dword [imgdest],xs -else - mov eax,xs - mov dword [imgdest],eax -end if -if ys eqtype 0 - mov dword [imgdest+4],ys -else - 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 - add eax,x - mov edx,ecx - lea eax,[eax+2*eax] ;eax=offset on imsrc -; mov ebp,eax -; shl eax,1 -; add eax,ebp - - 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: - movsw - movsb - dec ecx - jne cyc - add esi,edx - mov ecx,xs - sub esi,ecx - sub esi,ecx - sub esi,ecx - dec ebx - jne cyc -} - -macro copyimg img2_off,img1_off -{ - mov eax,dword [img1_off] - mov ebx,dword [img1_off+4] - mul ebx - lea ecx,[eax+2*eax] - lea esi,[img1_off+8] - lea edi,[img2_off+8] - cld - rep movsb -} - -macro fullimg img_off,xs,ys,color -{ -local cop - mov eax,xs - mov ebx,ys - mov dword [img_off],eax - mov dword [img_off+4],ebx - mul ebx - lea ebp,[eax+2*eax] - mov esi,color -if color eqtype 0 - mov ecx,color/65536 -else - mov ecx,esi - shr ecx,16 -end if - xor edi,edi -cop: - mov word [img_off+8+edi],si - add edi,2 - mov byte [img_off+8+edi],cl - inc edi - cmp edi,ebp - jne cop -} - - - - ; number of frame in ecx - ; callculatin offset of raw data - -macro getframeoff num_of_frame,offset_of_animation,offset_of_frame -{ -local loo,setpic - mov ebp,num_of_frame ;ecx - mov esi,offset_of_animation;Image -loo: - cmp ebp,0 - je setpic - movzx eax,word [esi+4] - movzx ebx,word [esi+6] - mul ebx ;dword [esi+4] - mov ebx,3 - mul ebx - add eax,8 - add esi,eax - dec ebp - jmp loo -setpic: - 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 - - -bmptoimg_data_area_count=0 -macro bmptoimg bmp_load_area,img_dest_area -{ -local fileinfo,string,end_bmp,nodix -local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2 -local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize -;local qwe,bmpfn - -; convert: - movzx eax,word [bmp_load_area+28] - mul dword [bmp_load_area+18] - add eax,31 - shr eax,5 - mov dword [bmptoimg_data_area_dwps],eax ;dwps-doublewords per string - shl eax,2 - mov dword [bmptoimg_data_area_bps],eax ;bps-bytes per string - - cmp dword [bmp_load_area+34],0 - jne yespicsize ;if picture size is defined - mul dword [bmp_load_area+22] - mov dword [bmp_load_area+34],eax - - yespicsize: - mov ebp,img_dest_area+8 - - mov eax,bmp_load_area - mov ebx,eax - add ebx, [bmp_load_area+2];file size - inc ebx - mov dword [bmptoimg_soi],ebx ;soi-start of image area for drawing - - add eax, [bmp_load_area+10] - mov dword [bmptoimg_data_area_sop],eax ;sop-start of picture in file - add eax, [bmp_load_area+34] - mov dword [bmptoimg_data_area_eop],eax ;eop-end of picture in file - mov eax, [bmp_load_area+18] - lea eax,[eax+2*eax] ;3x pixels in eax - - mov edi,dword [bmptoimg_soi] ;initializing - mov esi,dword [bmptoimg_data_area_eop] - sub esi,dword [bmptoimg_data_area_bps] - - - nextstring: - push edi - push ebp - cmp word [bmp_load_area+28],24 - jne convertno32 - - mov edi,ebp - mov ecx,[bmptoimg_data_area_dwps] - cld - rep movsd - - convert1: - pop ebp - pop edi - sub esi,dword [bmptoimg_data_area_bps] - sub esi,dword [bmptoimg_data_area_bps] - cmp esi,dword [bmptoimg_data_area_sop] - jb end_bmp - add edi,eax - add ebp,eax - jmp nextstring - - convertno32: - mov ebx,bmp_load_area - add ebx, [bmp_load_area+14] - add ebx,14 ;start of color table - push esi - add esi,dword [bmptoimg_data_area_bps] - mov dword [bmptoimg_data_area_eos],esi - pop esi - nextelem: - push eax - movzx eax,byte [esi] - cmp word [bmp_load_area+28],4 - je convert4bpp - cmp word [bmp_load_area+28],1 - je convert1bpp - call converttable - - convert2: - pop eax - inc esi - cmp esi,dword [bmptoimg_data_area_eos] - jae convert1 - add edi,3 - - add ebp,3 - - jmp nextelem - - convert4bpp: - shl ax,4 - shr al,4 - push ax - movzx eax,ah - call converttable - add edi,3 - - add ebp,3 - - pop ax - movzx eax,al - call converttable - jmp convert2 - - convert1bpp: - mov ecx,eax - mov edx,7 - nextbit: - xor eax,eax - bt ecx,edx - jnc noaddelem - inc eax - noaddelem: - push edx - call converttable - pop edx - dec edx - js convert2 - add edi,3 - - add ebp,3 - - jmp nextbit - - converttable: - shl eax,2 - add eax,ebx - mov edx, dword [eax] -; mov dword [edi],edx - mov [ebp],edx - ret - -bmptoimg_data_area_count=bmptoimg_data_area_count+1 -if bmptoimg_data_area_count = 1 -; DATA AREA -bmptoimg_soi dd 0 -bmptoimg_data_area_bps dd 0 -bmptoimg_data_area_dwps dd 0 -bmptoimg_data_area_sop dd 0 -bmptoimg_data_area_eop dd 0 -bmptoimg_data_area_eos dd 0 -end if - -end_bmp: - mov eax,dword [bmp_load_area+18] - mov ebx,dword [bmp_load_area+22] - mov dword [img_dest_area],eax - mov dword [img_dest_area+4],ebx -} - -; For convert RGB to BGR -COLOR_ORDER equ MENUETOS - -macro giftoani gifsrc,imgsrc,num_of_frames -{ -local hasharea, ReadGIF, nextblock,_null -local globalColor, img_count, cur_info, img_start -local codesize, compsize, bit_count, CC, EOI, Palette -local block_ofs, table_ptr, gifmacend -local no_gc, block_skip, no_comm, noextblock, uselocal -local setPal, filltable, reinit, cycle, zadd, noinc -local notintable, er, zend, nxt, continue, ex, Gif_skipmap -local Gif_get_sym, shift, nextbl, noblock, loop1, exx -local Gif_output, next, loop2 - -_null fix 1000h ; 0x1000 - -; jmp sss -; if defined gif_hash_offset -; else -; hasharea: -; times 4096 dd 0 ;4096 -; end if -;sss: - - mov esi,gifsrc ;Указатель на ГИФ фаил в памяти - mov edi,imgsrc ;Указатель на список картинок - - if defined gif_hash_offset - mov eax,gif_hash_offset ;Рабочая область минимум 4096*4 байт - else - mov eax,hasharea ;Рабочая область минимум 4096*4 байт - end if - - call ReadGIF - push ecx - pop dword num_of_frames - jmp gifmacend - - if defined gif_hash_offset - else - hasharea: - times 4096 dd 0 ;4096 - end if - -ReadGIF: - push esi edi - mov [table_ptr],eax - mov [cur_info],edi - xor eax,eax - mov [globalColor],eax - mov [img_count],eax - inc eax - cmp dword[esi],'GIF8' - jne er ; signature - mov ecx,[esi+0xa] - inc eax - add esi,0xd - mov edi,esi - bt ecx,7 - jnc nextblock - mov [globalColor],esi - call Gif_skipmap -nextblock: - cmp byte[edi],0x21 - jne noextblock - inc edi - cmp byte[edi],0xf9 ; Graphic Control Ext - jne no_gc - add edi,7 - jmp nextblock -no_gc: - cmp byte[edi],0xfe ; Comment Ext - jne no_comm - inc edi -block_skip: - movzx eax,byte[edi] - lea edi,[edi+eax+1] - cmp byte[edi],0 - jnz block_skip - inc edi - jmp nextblock -no_comm: - cmp byte[edi],0xff ; Application Ext - jne nextblock - add edi,13 - jmp block_skip -noextblock: - cmp byte[edi],0x2c ; image beginning - jne er - inc [img_count] - inc edi - mov esi,[cur_info] - xchg esi,edi - movsd - movsd - - push edi - movzx ecx,word[esi] - inc esi - bt ecx,7 - jc uselocal - push [globalColor] - mov edi,esi - jmp setPal -uselocal: - call Gif_skipmap - push esi -setPal: - movzx ecx,byte[edi] - inc ecx - mov [codesize],ecx - dec ecx - pop [Palette] - lea esi,[edi+1] - mov edi,[table_ptr] - xor eax,eax - cld - lodsb ; eax - block_count - add eax,esi - mov [block_ofs],eax - mov [bit_count],8 - mov eax,1 - shl eax,cl - mov [CC],eax - inc eax - mov [EOI],eax - lea ecx,[eax-1] - mov eax, _null shl 16 -filltable: - stosd - inc eax - loop filltable - pop edi - mov [img_start],edi -reinit: - mov edx,[EOI] - inc edx - push [codesize] - pop [compsize] - call Gif_get_sym - cmp eax,[CC] - je reinit - call Gif_output -cycle: - movzx ebx,ax - call Gif_get_sym - cmp eax,edx - jae notintable - cmp eax,[CC] - je reinit - cmp eax,[EOI] - je zend - call Gif_output -zadd: - push eax - mov eax,[table_ptr] - mov [eax+edx*4],ebx - pop eax - cmp edx,0xFFF - jae cycle - inc edx - bsr ebx,edx - cmp ebx,[compsize] - jne noinc - inc [compsize] -noinc: - jmp cycle -notintable: - push eax - mov eax,ebx - call Gif_output - push ebx - movzx eax,bx - call Gif_output - pop ebx eax - jmp zadd -er: - pop edi - jmp ex -zend: -; mov eax,[.cur_info] ; skip offset to next frame -; mov [eax],edi - mov [cur_info],edi - add esi,2 - xchg esi,edi -nxt: - cmp byte[edi],0 - jnz continue - inc edi - jmp nxt -continue: - cmp byte[edi],0x3b ;read next frame - jne nextblock - xor eax,eax - stosd - mov ecx,[img_count] -ex: - pop edi esi - ret - -Gif_skipmap: -; in: ecx - image descriptor, esi - pointer to colormap -; out: edi - pointer to area after colormap - - and ecx,111b - inc ecx ; color map size - mov ebx,1 - shl ebx,cl - lea ebx,[ebx*2+ebx] - lea edi,[esi+ebx] - ret - -Gif_get_sym: - mov ecx,[compsize] - push ecx - xor eax,eax -shift: - ror byte[esi],1 - rcr eax,1 - dec [bit_count] - jnz loop1 - inc esi - cmp esi,[block_ofs] - jb noblock - push eax - xor eax,eax - lodsb - test eax,eax - jnz nextbl - mov eax,[EOI] - sub esi,2 - add esp,8 - jmp exx -nextbl: - add eax,esi - mov [block_ofs],eax - pop eax -noblock: - mov [bit_count],8 -loop1: - loop shift - pop ecx - rol eax,cl -exx: - xor ecx,ecx - ret - -Gif_output: - push esi eax edx - mov edx,[table_ptr] -next: - push word[edx+eax*4] - mov ax,word[edx+eax*4+2] - inc ecx - cmp ax,_null - jnz next - shl ebx,16 - mov bx,[esp] -loop2: - pop ax - - lea esi,[eax+eax*2] - add esi,[Palette] - - if COLOR_ORDER eq MENUETOS - mov esi,[esi] - bswap esi - shr esi,8 - mov [edi],esi - add edi,3 - else - movsw - movsb - end if - - loop loop2 - pop edx eax esi - ret - - globalColor dd 1 - img_count dd 1 - cur_info dd 1 ; image table pointer - img_start dd 1 - codesize dd 1 - compsize dd 1 - bit_count dd 1 - CC dd 1 - EOI dd 1 - Palette dd 1 - block_ofs dd 1 - table_ptr dd 1 - -gifmacend: -} - - - -macro giftoimg gifsrc,imgsrc -{ -local hasharea, ReadGIF, nextblock,_null -local globalColor, img_count, cur_info, img_start -local codesize, compsize, bit_count, CC, EOI, Palette -local block_ofs, table_ptr, gifmacend -local no_gc, block_skip, no_comm, noextblock, uselocal -local setPal, filltable, reinit, cycle, zadd, noinc -local notintable, er, zend, nxt, continue, ex, Gif_skipmap -local Gif_get_sym, shift, nextbl, noblock, loop1, exx -local Gif_output, next, loop2 - -_null fix 0x1000 ; 0x1000 - - mov esi,gifsrc ;Указатель на ГИФ фаил в памяти - mov edi,imgsrc ;Указатель на список картинок - - if defined gif_hash_offset - mov eax,gif_hash_offset ;Рабочая область минимум 4096*4 байт - else - mov eax,hasharea ;Рабочая область минимум 4096*4 байт - end if - - call ReadGIF - jmp gifmacend - - if defined gif_hash_offset - else - hasharea: - times 4096 dd 0 ;4096 - end if - -ReadGIF: - push esi edi - mov [table_ptr],eax - mov [cur_info],edi - xor eax,eax - mov [globalColor],eax - mov [img_count],eax - inc eax - cmp dword[esi],'GIF8' - jne er ; signature - mov ecx,[esi+0xa] - inc eax - add esi,0xd - mov edi,esi - bt ecx,7 - jnc nextblock - mov [globalColor],esi - call Gif_skipmap -nextblock: - cmp byte[edi],0x21 - jne noextblock - inc edi - cmp byte[edi],0xf9 ; Graphic Control Ext - jne no_gc - add edi,7 - jmp nextblock -no_gc: - cmp byte[edi],0xfe ; Comment Ext - jne no_comm - inc edi -block_skip: - movzx eax,byte[edi] - lea edi,[edi+eax+1] - cmp byte[edi],0 - jnz block_skip - inc edi - jmp nextblock -no_comm: - cmp byte[edi],0xff ; Application Ext - jne nextblock - add edi,13 - jmp block_skip -noextblock: - cmp byte[edi],0x2c ; image beginning - jne er - inc [img_count] - inc edi - mov esi,[cur_info] - xchg esi,edi -; movsd -; movsd - - mov bp,word[esi+4] - movzx ebx,bp - mov [edi],ebx - - mov bp,word[esi+6] - movzx ebx,bp - mov [edi+4],ebx - - add edi,8 - add esi,8 - - push edi - movzx ecx,word[esi] - inc esi - bt ecx,7 - jc uselocal - push [globalColor] - mov edi,esi - jmp setPal -uselocal: - call Gif_skipmap - push esi -setPal: - movzx ecx,byte[edi] - inc ecx - mov [codesize],ecx - dec ecx - pop [Palette] - lea esi,[edi+1] - mov edi,[table_ptr] - xor eax,eax - cld - lodsb ; eax - block_count - add eax,esi - mov [block_ofs],eax - mov [bit_count],8 - mov eax,1 - shl eax,cl - mov [CC],eax - inc eax - mov [EOI],eax - lea ecx,[eax-1] - mov eax, _null shl 16 -filltable: - stosd - inc eax - loop filltable - pop edi - mov [img_start],edi -reinit: - mov edx,[EOI] - inc edx - push [codesize] - pop [compsize] - call Gif_get_sym - cmp eax,[CC] - je reinit - call Gif_output -cycle: - movzx ebx,ax - call Gif_get_sym - cmp eax,edx - jae notintable - cmp eax,[CC] - je reinit - cmp eax,[EOI] - je zend - call Gif_output -zadd: - push eax - mov eax,[table_ptr] - mov [eax+edx*4],ebx - pop eax - cmp edx,0xFFF - jae cycle - inc edx - bsr ebx,edx - cmp ebx,[compsize] - jne noinc - inc [compsize] -noinc: - jmp cycle -notintable: - push eax - mov eax,ebx - call Gif_output - push ebx - movzx eax,bx - call Gif_output - pop ebx eax - jmp zadd -er: - pop edi - jmp ex -zend: -; mov eax,[.cur_info] ; skip offset to next frame -; mov [eax],edi - mov [cur_info],edi - add esi,2 - xchg esi,edi -nxt: - cmp byte[edi],0 - jnz continue - inc edi - jmp nxt -continue: -; cmp byte[edi],0x3b ;read next frame -; jne nextblock - xor eax,eax - stosd - mov ecx,[img_count] -ex: - pop edi esi - ret - -Gif_skipmap: -; in: ecx - image descriptor, esi - pointer to colormap -; out: edi - pointer to area after colormap - - and ecx,111b - inc ecx ; color map size - mov ebx,1 - shl ebx,cl - lea ebx,[ebx*2+ebx] - lea edi,[esi+ebx] - ret - -Gif_get_sym: - mov ecx,[compsize] - push ecx - xor eax,eax -shift: - ror byte[esi],1 - rcr eax,1 - dec [bit_count] - jnz loop1 - inc esi - cmp esi,[block_ofs] - jb noblock - push eax - xor eax,eax - lodsb - test eax,eax - jnz nextbl - mov eax,[EOI] - sub esi,2 - add esp,8 - jmp exx -nextbl: - add eax,esi - mov [block_ofs],eax - pop eax -noblock: - mov [bit_count],8 -loop1: - loop shift - pop ecx - rol eax,cl -exx: - xor ecx,ecx - ret - -Gif_output: - push esi eax edx - mov edx,[table_ptr] -next: - push word[edx+eax*4] - mov ax,word[edx+eax*4+2] - inc ecx - cmp ax,_null - jnz next - shl ebx,16 - mov bx,[esp] -loop2: - pop ax - - lea esi,[eax+eax*2] - add esi,[Palette] - - if COLOR_ORDER eq MENUETOS - mov esi,[esi] - bswap esi - shr esi,8 - mov [edi],esi - add edi,3 - else - movsw - movsb - end if - - loop loop2 - pop edx eax esi - ret - - globalColor dd 1 - img_count dd 1 - cur_info dd 1 ; image table pointer - img_start dd 1 - codesize dd 1 - compsize dd 1 - bit_count dd 1 - CC dd 1 - EOI dd 1 - Palette dd 1 - block_ofs dd 1 - table_ptr dd 1 - -gifmacend: -} - diff --git a/programs/games/invaders/invaders.asm b/programs/games/invaders/invaders.asm index f9445ce2d4..e927329804 100644 --- a/programs/games/invaders/invaders.asm +++ b/programs/games/invaders/invaders.asm @@ -1,8 +1,8 @@ ;=============================================================================; -; Hidnplayr's invaders, Compilable for DexOs and Kolibrios ; +; Hidnplayr's invaders for Kolibrios ; ;-----------------------------------------------------------------------------; ; ; -; Copyright (C) hidnplayr 2007. All rights reserved. ; +; Copyright (C) hidnplayr 2007-2014. All rights reserved. ; ; ; ; Invaders is distributed in the hope that it will be useful, but WITHOUT ANY ; ; WARRANTY. No author or distributor accepts responsibility to anyone for the ; @@ -22,1143 +22,1346 @@ ; ; ;-----------------------------------------------------------------------------; +format binary as "" -SCREEN_X equ 640 -SCREEN_Y equ 480 +; Screen size +SCREEN_X = 640 +SCREEN_Y = 480 -SHIP_X equ 32 -SHIP_Y equ 32 +; Ship size +SHIP_X = 32 +SHIP_Y = 32 -SHIP_X_POS equ (SCREEN_X-SHIP_X)/2 -SHIP_Y_POS equ SCREEN_Y-SHIP_Y-27 +; Ship begin position +SHIP_X_POS = (SCREEN_X-SHIP_X)/2 +SHIP_Y_POS = SCREEN_Y-SHIP_Y-27 -ENEMY_X equ 32 -ENEMY_Y equ 32 +; Enemy size +ENEMY_X = 32 +ENEMY_Y = 32 -ALIEN_X equ 48 -ALIEN_Y equ 38 -ALIEN_Y_POS equ 1 +; Alien size and position +ALIEN_X = 48 +ALIEN_Y = 38 +ALIEN_Y_POS = 1 -BOUNDARY equ 10 -MOVEMENT equ 7 +; +BOUNDARY = 10 +MOVEMENT = 7 ; pixels/frame -TRANSPARENCY equ 0x00000000 +TRANSPARENCY = 0x00ffffff ; color used as transparant -WINDOW_X equ 100 -WINDOW_Y equ 100 +; Window start position +WINDOW_X = 100 +WINDOW_Y = 100 -BULLET_X equ 10 -BULLET_Y equ 10 +; Bullet size +BULLET_X = 10 +BULLET_Y = 10 -STARS_ equ 226 -STARLEVELS equ 3 +; Number of stars +STARS_ = 226 -ENEMY_STARTING_X equ 25 -ENEMY_STARTING_Y equ 50 +; Number of star levels (depth) +STARLEVELS = 3 -BULLETSPEED equ 12 +ENEMY_STARTING_X = 25 +ENEMY_STARTING_Y = 50 -SCREEN_X_POS equ 5 -SCREEN_Y_POS equ 25 +BULLETSPEED = 12 ; pixels/frame -gif_hash_offset = gif_hash_area + use32 + org 0x0 + db 'MENUET01' ; 8 byte id + dd 0x01 ; header version + dd START ; start of code + dd IM_END ; size of image + dd I_END+1000 ; memory for app + dd I_END+1000 ; esp + dd 0x0, 0x0 ; I_Param , I_Path -include 'ascgl.inc' -include 'invaders_kolibri.inc' +include '../../macros.inc' +include '../../proc32.inc' +include '../../dll.inc' +include '../../develop/libraries/libs-dev/libimg/libimg.inc' -decodegif: - giftoimg gif_bullet,bullet - giftoimg gif_bullet2,bullet2 - giftoimg gif_ship,ship - giftoimg gif_enemy1,enemy1 - giftoimg gif_enemy2,enemy2 - giftoimg gif_enemy3,enemy3 - giftoimg gif_enemy4,enemy4 - giftoimg gif_enemy5,enemy5 - giftoimg gif_alien,alien - giftoimg gif_menu1,menu1 - giftoimg gif_menu2,menu2 - giftoimg gif_menu3,menu3 - giftoimg gif_menu4,menu4 - giftoimg gif_logo,logo - giftoimg gif_pause,pause_ - giftoimg gif_levelup,levelup - giftoimg gif_gameover,gameover - giftoimg gif_highscore,highscore - giftoimg gif_smallfont,smallfont - giftoimg gif_bigfont,bigfont - giftoimg gif_numbers,numbers +KEY_RIGHT = 179 +KEY_LEFT = 176 +KEY_UP = 178 +KEY_P = 'p' +KEY_DOWN = 177 +KEY_ENTER = 13 +KEY_ESC = 27 - call createstars - call drawit - call [drawroutine] +proc aimgtoimg img, x, y, canvas, acolor + + pusha +; Calculate offset on canvas in edi + mov eax, [y] + mov ecx, [canvas] + mul dword[ecx] ; canvas xsize + add eax, [x] + + lea edi, [eax*2 + eax + 8] + add edi, [canvas] + +; get img size in ecx and edx + mov esi, [img] + mov ecx, dword[esi+0] ; img x size + mov edx, dword[esi+4] ; img y size + +; caluclate number of bytes between 2 lines in ebx + mov ebx, [canvas] + mov ebx, [ebx] ; canvas xsize + sub ebx, [esi] ; img xsize + lea ebx, [ebx*2 + ebx] + +; get image start ptr in esi + add esi, 8 + + .loop2: + push ecx edx + mov edx, [acolor] + .loop: + mov eax, [esi] + and eax, 0x00ffffff + cmp eax, edx + je @f + mov word[edi], ax + shr eax, 16 + mov byte[edi+2], al + @@: + add esi, 3 + add edi, 3 + dec ecx + jnz .loop + pop edx ecx + + add edi, ebx + dec edx + jnz .loop2 + + popa + ret + +endp + +proc aimgtoimg2 img, x, y, canvas, acolor + + pusha +; Calculate offset on canvas in edi + mov eax, [y] + mov ecx, [canvas] + mul dword[ecx] ; canvas xsize + add eax, [x] + + lea edi, [eax*2 + eax + 8] + add edi, [canvas] + +; get img size in ecx and edx + mov esi, [img] + mov ecx, dword[esi+0] ; img x size + mov edx, dword[esi+4] ; img y size + +; caluclate number of bytes between 2 lines in ebx + mov ebx, [canvas] + mov ebx, [ebx] ; canvas xsize + sub ebx, [esi] ; img xsize + lea ebx, [ebx*2 + ebx] + +; get image start ptr in esi + add esi, 8 + + .loop2: + push ecx edx + mov edx, [acolor] + .loop: + mov eax, [esi] + and eax, 0x00ffffff + cmp eax, edx + je @f + mov byte[edi+2], al + shr eax, 8 + mov word[edi], ax + @@: + add esi, 3 + add edi, 3 + dec ecx + jnz .loop + pop edx ecx + + add edi, ebx + dec edx + jnz .loop2 + + popa + ret + +endp + +proc getimg imgsrc, x, y, xs, ys, imgdest + + pusha + + mov esi, [imgsrc] + mov eax, dword[esi+0] ; xsize + mov ebx, [y] + mul ebx ; xsize*y + add eax, [x] ; xsize*y+x + lea eax, [eax+2*eax] ; (xsize*y+x)*3 + + mov edx, dword[esi+0] ; xsize + sub edx, [xs] ; xsize-xs + lea edx, [edx*2+edx] ; (xsize-xs)*3 + + lea esi, [esi + eax + 8] ; imgsrc + (xsize*y+x)*3 + 8 + + mov edi, [imgdest] + mov ecx, [xs] + mov dword[edi+0], ecx ; xsize + mov ebx, [ys] + mov dword[edi+4], ebx ; ysize + add edi, 8 ; imgdest + 8 + + cld + .loop: + movsw + movsb + dec ecx + jnz .loop + + add esi, edx + mov ecx, [xs] + dec ebx + jnz .loop + + popa + ret + +endp + +macro decodeimg source, size, dest { + + invoke img.decode, source, size, 0 + or eax, eax + jz exit + push [eax + Image.Width] + pop dword[dest+0] + push [eax + Image.Height] + pop dword[dest+4] + push eax + invoke img.to_rgb2, eax, dest+8 + pop eax + invoke img.destroy, eax +} + + +START: + mcall 68, 11 + + stdcall dll.Load, @IMPORT + or eax, eax + jz @f +exit: + mcall -1 + @@: + + call draw_window + + decodeimg gif_bullet,gif_bullet.size,img_bullet + decodeimg gif_bullet2,gif_bullet2.size,img_bullet2 + decodeimg gif_ship,gif_ship.size,img_ship + decodeimg gif_enemy1,gif_enemy1.size,img_enemy1 + decodeimg gif_enemy2,gif_enemy2.size,img_enemy2 + decodeimg gif_enemy3,gif_enemy3.size,img_enemy3 + decodeimg gif_enemy4,gif_enemy4.size,img_enemy4 + decodeimg gif_enemy5,gif_enemy5.size,img_enemy5 + decodeimg gif_alien,gif_alien.size,img_alien + decodeimg gif_menu1,gif_menu1.size,img_menu1 + decodeimg gif_menu2,gif_menu2.size,img_menu2 + decodeimg gif_menu3,gif_menu3.size,img_menu3 + decodeimg gif_menu4,gif_menu4.size,img_menu4 + decodeimg gif_logo,gif_logo.size,img_logo + decodeimg gif_pause,gif_pause.size,img_pause + decodeimg gif_levelup,gif_levelup.size,img_levelup + decodeimg gif_gameover,gif_gameover.size,img_gameover + decodeimg gif_highscore,gif_highscore.size,img_highscore + decodeimg gif_smallfont,gif_smallfont.size,img_smallfont + decodeimg gif_bigfont,gif_bigfont.size,img_bigfont + decodeimg gif_numbers,gif_numbers.size,img_numbers + + call init_starfield + call render_frame + call draw_to_screen mainloop: - cmp byte[status],3 ; if game is paused,... - je waitfordraw + call render_frame + call draw_to_screen + call bullet_collision_detection + + cmp [status], 3 ; if game is paused,... + jne .wait + + mcall 10 + jmp .switch + + .wait: + mcall 5, 1 ; wait 1/100 s + + mcall 11 ; check for events + .switch: + test eax, eax + jz mainloop + dec eax + jz .redraw + dec eax + jz .key + dec eax + jz .button + + .redraw: + call draw_window + jmp .wait + + .button: + mcall 17 ; get button id + + cmp ah, 1 + jne .wait + mcall -1 + + .key: + mcall 2 ; get key code + test ah, ah + jz mainloop + + cmp [status], 1 + je key_game + cmp [status], 0 + je key_menu + cmp [status], 3 + je key_pause + cmp [status], 6 + je key_levelup + cmp [status], 7 + je key_highscore + cmp [status], 2 + je key_gameover + + cmp ah, KEY_ESC + jne .no_escape + + mov [status], 0 + mov [intro], 0 + .no_escape: + + jmp mainloop + + +key_game: + cmp ah, KEY_RIGHT + jnz .no_right + + cmp [ship_x], SCREEN_X-SHIP_X-BOUNDARY + jge mainloop + add [ship_x], MOVEMENT + jmp mainloop + .no_right: + + cmp ah, KEY_LEFT + jne .no_left + + cmp [ship_x], BOUNDARY + jle mainloop + sub [ship_x], MOVEMENT + jmp mainloop + .no_left: + + cmp ah, KEY_UP + jne .no_up + + cmp [bullet_y], 1 + jg mainloop + + mov eax, [ship_x] + add eax, (SHIP_X-BULLET_X)/2 + mov [bullet_x], eax + mov [bullet_y], SHIP_Y_POS;-BULLET_Y + jmp mainloop + .no_up: + + cmp ah, KEY_P + jne no_pause + + mov [status], 3 + stdcall aimgtoimg, img_pause, 150, 180, vscreen, TRANSPARENCY + call draw_to_screen + + jmp mainloop + no_pause: + cmp ah, KEY_ESC + jne .no_escape + + mov [status], 0 + mov [intro], 0 + .no_escape: + jmp mainloop + + +key_menu: + cmp ah, KEY_DOWN + jne .no_down + + cmp [menu], 3 + jne @f + mov [menu], 0 + jmp mainloop + @@: + inc [menu] + jmp mainloop + .no_down: + + cmp ah, KEY_UP + jnz .no_up + + cmp [menu], 0 + jne @f + mov [menu], 3 + jmp mainloop + @@: + dec [menu] + jmp mainloop + .no_up: + + cmp ah, KEY_ESC + jne @f + mcall -1 + @@: + + cmp ah, KEY_ENTER + jnz .no_enter + + cmp [menu], 0 ;start + je new_game + + cmp [menu], 1 ;about + jne @f + mov [status], 4 + jmp mainloop + @@: + + cmp [menu], 2 ;highscores + jne @f + mov [status], 5 + call load_highscores + jmp mainloop + @@: + + cmp byte[menu], 3 ;exit + jne @f + mcall -1 + @@: + .no_enter: + jmp mainloop + + +key_pause: + cmp ah, KEY_P + jnz no_pause + + mov [status], 1 + .nopause: + jmp mainloop + + +key_levelup: + + cmp ah, KEY_ENTER + jne .no_enter + + inc [level] + + inc byte[levelnumb+1] + cmp byte[levelnumb+1], '9' + jle @f + mov byte[levelnumb+1], '0' + inc byte[levelnumb] + + @@: + mov eax,20 + mov ah,byte[level] + and ah,7 + mul ah + add eax,level1 + mov esi,eax + jmp load_level - call drawit - call [drawroutine] - call checkbullet + .no_enter: + cmp ah, KEY_ESC + jne .no_escape - waitfordraw: + mov [status], 0 + mov [intro], 0 + .no_escape: + jmp mainloop - call waitandgetkey ;;; - test ah,ah - jz mainloop - cmp byte[status],1 ; - jne nogame +key_highscore: - cmp ah, KEY_RIGHT - jnz noright - cmp dword[ship_x],SCREEN_X-SHIP_X-BOUNDARY - jge mainloop - add dword[ship_x],MOVEMENT + cmp ah, KEY_ENTER + jne @f - jmp mainloop + call load_highscores + mov eax, [score] + mov ebx, highscorebuffer+140 + .findscore: + cmp ebx, highscorebuffer+100 + je .topscore + sub ebx, 4 + cmp eax, dword[ebx] + jg .findscore - noright: - cmp ah, KEY_LEFT - jnz noleft - cmp dword[ship_x],BOUNDARY - jle mainloop - sub dword[ship_x],MOVEMENT + .topscore: + mov esi, name + mov edi, highscorebuffer + mov ecx, 10 + rep movsb - jmp mainloop + mov eax, [score] + mov dword[highscorebuffer+100], eax - noleft: - cmp ah, KEY_UP - jnz noup + call save_highscores + mov [status], 5 - cmp dword[bullet_y],1 - jg mainloop + @@: + cmp ah, 14 + jne @f - mov eax,dword[ship_x] - add eax,(SHIP_X-BULLET_X)/2 - mov dword[bullet_x],eax - mov dword[bullet_y],SHIP_Y_POS;-BULLET_Y + cmp byte[namepos],0 + je @f - jmp mainloop + dec byte[namepos] + movzx ebx,byte[namepos] + add ebx,name + mov byte[ebx], 0x11 ; this is a character we dont print - noup: - cmp ah,KEY_P - jnz no_pause1 + @@: + cmp byte[namepos],10 + jge mainloop - mov byte[status],3 - aimgtoimg pause_,150,180,vscreen,TRANSPARENCY,0 - call [drawroutine] + cmp al,'0' + jl mainloop + cmp al,'9' + jle @f - jmp mainloop + cmp al,'z' + jg mainloop + cmp al,'a' + jge @f - no_pause1: + cmp al,'Z' + jg mainloop + cmp al,'A' + jl mainloop + @@: -nogame: - cmp byte[status],0 - jne nomenu + movzx ebx, byte[namepos] + add ebx, name + mov byte[ebx], al - cmp ah, KEY_DOWN - jnz no_down + inc byte[namepos] - cmp byte[menu],3 - jne no_menu1 + jmp mainloop - mov byte[menu],0 - jmp nomenu - no_menu1: - inc byte[menu] +key_gameover: + cmp ah, KEY_ENTER + jne .no_enter - no_down: - cmp ah, KEY_UP - jnz no_up + ; TODO: test if score is high enough to put in highscore list... + mov [status],7 + jmp mainloop - cmp byte[menu],0 - jne no_menu0 + .no_enter: + jmp mainloop - mov byte[menu],3 - jmp nomenu - no_menu0: - dec byte[menu] +new_game: - no_up: + mov [score], 0 + mov eax, [score] + call convertscore - cmp ah, KEY_ESC - je exit + mov word[levelnumb], '01' + mov esi, level1 - no_esc: - cmp ah, KEY_ENTER - jnz no_enter +load_level: + mov [enemy_speed], 1 + mov [enemy_x], ENEMY_STARTING_X + mov [enemy_y], ENEMY_STARTING_Y - exemenu: - cmp byte[menu],0 ;start - jne exemenu1 + mov edi, enemy_table + mov ecx, 5 + rep movsd - new_game: - mov dword[score],0 - mov eax,[score] - call convertscore + mov [status],1 - mov esi, level1 - mov word[levelnumb],'01' - load_level: - mov byte[enemy_speed],1 - mov dword[enemy_x], ENEMY_STARTING_X - mov dword[enemy_y], ENEMY_STARTING_Y + jmp mainloop - mov edi, enemy_table - mov ecx, 5 - rep movsd - mov byte[status],1 +draw_window: - jmp mainloop + mcall 12, 1 ; Start of window draw - exemenu1: - cmp byte[menu],1 ;about - jne exemenu2 - mov byte[status],4 - jmp mainloop + mov ebx, WINDOW_X shl 16 + 9 + SCREEN_X ; [x start] shl 16 + [x size] + mov ecx, WINDOW_Y shl 16 + 25 + SCREEN_Y ; [y start] shl 16 + [y size] + mov edx, 0x64000000 ; color of work area RRGGBB + mov esi, 0x805080d0 ; color of grab bar RRGGBB + mov edi, 0x005080d0 ; color of frames RRGGBB + mcall 0 - exemenu2: - cmp byte[menu],2 ;highscores - jne exemenu3 - mov byte[status],5 - call load_highscores - jmp mainloop + mcall 71, 1, title - exemenu3: - cmp byte[menu],3 ;exit - je exit + call draw_to_screen - no_enter: -nomenu: - cmp byte[status],3 - jne nopause - - cmp ah, KEY_P - jnz nopause - - mov byte[status],1 - -nopause: - cmp byte[status],6 - jne nolevelup - - cmp ah, KEY_ENTER - jne nolevelup - - inc byte[level] - -; cmp byte[level],5 -; jne @f -; mov byte[level],0 - -;@@: - inc byte[levelnumb+1] - cmp byte[levelnumb+1],'9' - jle @f - mov byte[levelnumb+1],'0' - inc byte[levelnumb] - - @@: - mov eax,20 - mov ah,byte[level] - and ah,7 - mul ah - add eax,level1 - mov esi,eax - jmp load_level - -nolevelup: - cmp byte[status],7 - jne nohighscore - - cmp ah, KEY_ENTER - jne @f - - call load_highscores - mov eax,dword[score] - mov ebx,gif_hash_area+140 - .findscore: - cmp ebx,gif_hash_area+100 - je .topscore - sub ebx,4 - cmp eax,dword[ebx] - jg .findscore - - .topscore: - mov esi,name - mov edi,gif_hash_area - mov ecx,10 - rep movsb - - mov eax,dword[score] - mov dword[gif_hash_area+100],eax - - call save_highscores - mov byte[status],5 - -@@: - cmp ah,14 - jne @f - - cmp byte[namepos],0 - je @f - - dec byte[namepos] - movzx ebx,byte[namepos] - add ebx,name - mov byte[ebx],0x11 ; this is a character we dont print - -@@: - cmp byte[namepos],10 - jge nohighscore - - cmp al,'0' - jl nohighscore - cmp al,'9' - jle @f - - cmp al,'z' - jg nohighscore - cmp al,'a' - jge @f - - cmp al,'Z' - jg nohighscore - cmp al,'A' - jl nohighscore -@@: - - movzx ebx,byte[namepos] - add ebx,name - mov byte[ebx],al - - inc byte[namepos] - - jmp mainloop - -nohighscore: - cmp byte[status],2 ; gameover - jne nogameover - - cmp ah, KEY_ENTER - jne nogameover - - ; test if score is high enough to put in highscore list... - mov byte[status],7 - - jmp mainloop - -nogameover: - cmp byte[status],0 - je mainloop - - cmp ah, KEY_ESC - jnz mainloop - - mov byte[status],0 - mov word[intro],0 - - jmp mainloop - - ;----------------------------------------------------; - ; Drawing routine: create image in buffer ; - ;----------------------------------------------------; -drawit: - mov eax,0x00000000 - call fillscreen - call drawstars - - cmp byte[status],1 - jne @f - - call drawbullet - call drawenemys ; Draw the enemy's to buffer - aimgtoimg ship,dword[ship_x],SHIP_Y_POS,vscreen,TRANSPARENCY,0 ; Draw the ship to buffer - - mov esi,scoretext - mov ebx,0 - mov ecx,SCREEN_Y-24 - call printtext - - mov esi,leveltext - mov ebx,300 - call printtext - - ret - -@@: - cmp byte[status],2 ; game over, dude ! - jne @f - - aimgtoimg ship,dword[ship_x],SHIP_Y_POS,vscreen,TRANSPARENCY,0 ; Draw the ship to buffer - - mov esi,scoretext - mov ebx,0 - mov ecx,SCREEN_Y-24 - call printtext - - mov esi,leveltext - mov ebx,300 - call printtext - aimgtoimg gameover,150,180,vscreen,TRANSPARENCY,0 + mcall 12, 2 ; End of window draw ret -@@: - cmp byte[status],4 ; about screen - jne @f - mov esi,msgAbout - mov ebx,50 - mov ecx,100 - call printtext + +draw_to_screen: + + ; Draw buffer to the screen + mov ebx, vscreen+8 + mov ecx, SCREEN_X shl 16 + SCREEN_Y + mov edx, 0 shl 16 + 0 + mcall 7 ret -@@: - cmp byte[status],6 ; level up! - jne @f - aimgtoimg ship,dword[ship_x],SHIP_Y_POS,vscreen,TRANSPARENCY,0 ; Draw the ship to buffer - mov esi,scoretext - mov ebx,0 - mov ecx,SCREEN_Y-24 - call printtext - - mov esi,leveltext - mov ebx,300 - call printtext - aimgtoimg levelup,150,180,vscreen,TRANSPARENCY,0 +load_highscores: ret -@@: - cmp byte[status],0 ; menu! - jne @f - aimgtoimg logo,50,80,vscreen,TRANSPARENCY,0 +save_highscores: + + ret - cmp byte[menu],0 - jne .menu_0 - aimgtoimg menu1,30,200,vscreen,TRANSPARENCY,1 - jmp .menu_1 - .menu_0: - aimgtoimg menu1,30,200,vscreen,TRANSPARENCY,0 - .menu_1: - cmp byte[menu],1 - jne .menu_2 - aimgtoimg menu2,80,250,vscreen,TRANSPARENCY,1 - jmp .menu_3 - .menu_2: - aimgtoimg menu2,80,250,vscreen,TRANSPARENCY,0 - .menu_3: - cmp byte[menu],2 - jne .menu_4 - aimgtoimg menu3,120,300,vscreen,TRANSPARENCY,1 - jmp .menu_5 - .menu_4: - aimgtoimg menu3,120,300,vscreen,TRANSPARENCY,0 - .menu_5: - cmp byte[menu],3 - jne .menu_6 - aimgtoimg menu4,150,350,vscreen,TRANSPARENCY,1 - jmp .menu_7 - .menu_6: - aimgtoimg menu4,150,350,vscreen,TRANSPARENCY,0 - .menu_7: +render_frame: - cmp word[intro],200 - je .menu_75 - inc word[intro] + mov eax, 0x00000000 + call fillscreen + call render_starfield - .menu_75: - cmp word[intro],0 - jl .menu_8 - aimgtoimg enemy1,390,180,vscreen,TRANSPARENCY,0 + cmp [status], 1 + je render_game + cmp [status], 2 + je render_gameover + cmp [status], 4 + je render_about + cmp [status], 6 + je render_levelup + cmp [status], 0 + je render_menu + cmp [status], 5 + je render_highscorelist + cmp [status], 7 + je render_highscore - cmp word[intro],15 - jl .menu_8 - mov esi,points_50 - mov ebx,470 - mov ecx,180 - call printtext + ret - cmp word[intro],30 - jl .menu_8 - aimgtoimg enemy2,390,220,vscreen,TRANSPARENCY,0 - cmp word[intro],45 - jl .menu_8 - mov esi,points_100 - mov ebx,450 - mov ecx,220 - call printtext +render_game: - cmp word[intro],60 - jl .menu_8 - aimgtoimg enemy3,390,260,vscreen,TRANSPARENCY,0 + call render_bullet + call render_enemies ; Draw the enemies to buffer + stdcall aimgtoimg, img_ship, [ship_x], SHIP_Y_POS, vscreen, TRANSPARENCY; Draw the ship to buffer - cmp word[intro],75 - jl .menu_8 - mov esi,points_150 - mov ebx,450 - mov ecx,260 - call printtext + mov esi, scoretext + mov ebx, 0 + mov ecx, SCREEN_Y-24 + call printtext - cmp word[intro],90 - jl .menu_8 - aimgtoimg enemy4,390,300,vscreen,TRANSPARENCY,0 + mov esi, leveltext + mov ebx, 300 + call printtext - cmp word[intro],105 - jl .menu_8 - mov esi,points_200 - mov ebx,450 - mov ecx,300 - call printtext + ret - cmp word[intro],120 - jl .menu_8 - aimgtoimg enemy5,390,340,vscreen,TRANSPARENCY,0 - cmp word[intro],135 - jl .menu_8 - mov esi,points_250 - mov ebx,450 - mov ecx,340 - call printtext +render_gameover: - cmp word[intro],150 - jl .menu_8 - aimgtoimg alien,380,380,vscreen,TRANSPARENCY,0 + stdcall aimgtoimg, img_ship, [ship_x], SHIP_Y_POS, vscreen, TRANSPARENCY; Draw the ship to buffer - cmp word[intro],165 - jl .menu_8 - mov esi,points_1000 - mov ebx,430 - mov ecx,380 - call printtext + mov esi, scoretext + mov ebx, 0 + mov ecx, SCREEN_Y-24 + call printtext + + mov esi, leveltext + mov ebx, 300 + call printtext + stdcall aimgtoimg, img_gameover, 150, 180, vscreen, TRANSPARENCY + + ret + + +render_about: + + mov esi, msgAbout + mov ebx, 50 + mov ecx, 100 + call printtext + + ret + + +render_levelup: + + stdcall aimgtoimg, img_ship, [ship_x], SHIP_Y_POS, vscreen, TRANSPARENCY; Draw the ship to buffer + + mov esi, scoretext + mov ebx, 0 + mov ecx, SCREEN_Y-24 + call printtext + + mov esi, leveltext + mov ebx, 300 + call printtext + stdcall aimgtoimg, img_levelup, 150, 180, vscreen, TRANSPARENCY + + ret + + +render_menu: + + stdcall aimgtoimg, img_logo, 50, 80, vscreen, TRANSPARENCY + + cmp [menu], 0 + jne .menu_0 + stdcall aimgtoimg2, img_menu1, 30, 200, vscreen, TRANSPARENCY + jmp .menu_1 + .menu_0: + stdcall aimgtoimg, img_menu1, 30, 200, vscreen, TRANSPARENCY + .menu_1: + cmp [menu], 1 + jne .menu_2 + stdcall aimgtoimg2, img_menu2, 80, 250, vscreen, TRANSPARENCY + jmp .menu_3 + .menu_2: + stdcall aimgtoimg, img_menu2, 80, 250, vscreen, TRANSPARENCY + .menu_3: + cmp [menu], 2 + jne .menu_4 + stdcall aimgtoimg2, img_menu3, 120, 300, vscreen, TRANSPARENCY + jmp .menu_5 + .menu_4: + stdcall aimgtoimg, img_menu3, 120, 300, vscreen,TRANSPARENCY + .menu_5: + cmp [menu], 3 + jne .menu_6 + stdcall aimgtoimg2, img_menu4, 150, 350, vscreen, TRANSPARENCY + jmp .menu_7 + .menu_6: + stdcall aimgtoimg, img_menu4, 150, 350, vscreen, TRANSPARENCY + .menu_7: + + cmp [intro], 200 + je .menu_75 + inc [intro] + + .menu_75: + cmp [intro], 0 + jl .menu_8 + stdcall aimgtoimg, img_enemy1, 390, 180, vscreen, TRANSPARENCY + + cmp [intro], 15 + jl .menu_8 + mov esi, points_50 + mov ebx, 470 + mov ecx, 180 + call printtext + + cmp [intro],30 + jl .menu_8 + stdcall aimgtoimg, img_enemy2, 390, 220, vscreen, TRANSPARENCY + + cmp [intro], 45 + jl .menu_8 + mov esi, points_100 + mov ebx, 450 + mov ecx, 220 + call printtext + + cmp [intro], 60 + jl .menu_8 + stdcall aimgtoimg, img_enemy3, 390, 260, vscreen, TRANSPARENCY + + cmp [intro], 75 + jl .menu_8 + mov esi, points_150 + mov ebx, 450 + mov ecx, 260 + call printtext + + cmp [intro],90 + jl .menu_8 + stdcall aimgtoimg, img_enemy4, 390, 300, vscreen, TRANSPARENCY + + cmp [intro], 105 + jl .menu_8 + mov esi, points_200 + mov ebx, 450 + mov ecx, 300 + call printtext + + cmp [intro], 120 + jl .menu_8 + stdcall aimgtoimg, img_enemy5, 390, 340, vscreen, TRANSPARENCY + + cmp [intro],135 + jl .menu_8 + mov esi, points_250 + mov ebx, 450 + mov ecx, 340 + call printtext + + cmp [intro],150 + jl .menu_8 + stdcall aimgtoimg, img_alien, 380, 380, vscreen, TRANSPARENCY + + cmp [intro],165 + jl .menu_8 + mov esi, points_1000 + mov ebx, 430 + mov ecx, 380 + call printtext .menu_8: ret -@@: - cmp byte[status],5 ;highscorelist - jne @f - - aimgtoimg highscore,60,40,vscreen,TRANSPARENCY,0 - - mov ebx,100 ; print names - mov ecx,120 - mov esi,gif_hash_area - call printtext - - mov edi,gif_hash_area+100 ; print scores - mov esi,scorenumb - mov ebx,420 - mov ecx,120 - -.highscoreloop: - mov eax,[edi] - push ecx - call convertscore - pop ecx - push esi - call printtext - pop esi - add ecx,26 - add edi,4 - cmp edi,gif_hash_area+140 - jl .highscoreloop - -@@: - cmp byte[status],7 ;highscore - jne @f - - aimgtoimg highscore,60,40,vscreen,TRANSPARENCY,0 - - mov ebx,60 - mov ecx,200 - mov esi,entername - call printtext - - mov ebx,250 - mov ecx,250 - mov esi,name - call printtext - - mov esi,scoretext - mov ebx,0 - mov ecx,SCREEN_Y-24 - call printtext - - mov esi,leveltext - mov ebx,300 - call printtext -@@: - - ret -drawenemys: +render_highscorelist: + + stdcall aimgtoimg, img_highscore, 60, 40, vscreen, TRANSPARENCY + + mov ebx, 100 ; print names + mov ecx, 120 + mov esi, highscorebuffer + call printtext + + mov edi, highscorebuffer+100 ; print scores + mov esi, scorenumb + mov ebx, 420 + mov ecx, 120 + + .loop: + mov eax,[edi] + push ecx + call convertscore + pop ecx + push esi + call printtext + pop esi + add ecx, 26 + add edi, 4 + cmp edi, highscorebuffer+140 + jl .loop + + ret + + +render_highscore: + + stdcall aimgtoimg, img_highscore, 60, 40, vscreen, TRANSPARENCY + + mov ebx, 60 + mov ecx, 200 + mov esi, entername + call printtext + + mov ebx, 250 + mov ecx, 250 + mov esi, name + call printtext + + mov esi, scoretext + mov ebx, 0 + mov ecx, SCREEN_Y-24 + call printtext + + mov esi, leveltext + mov ebx, 300 + call printtext + + ret + + +render_enemies: ; check if direction should change - test byte[enemy_d],2 - jz @f + test [enemy_d], 2 + jz @f - add dword[enemy_y],5 + add [enemy_y], 5 - mov eax,[enemy_y] - shr eax,5 - add al, byte[level] - mov byte[enemy_speed],al + mov eax, [enemy_y] + shr eax, 5 + add al, [level] + mov [enemy_speed], al - and byte[enemy_d],1 + and [enemy_d], 1 @@: ; move the aliens to left or right - movzx eax,byte[enemy_speed] - test byte[enemy_d],1 - jz other_dir + movzx eax, [enemy_speed] + test [enemy_d], 1 + jz .other_dir - sub dword[enemy_x],eax - jmp no_other_dir + sub [enemy_x], eax + jmp .no_other_dir - other_dir: - add dword[enemy_x],eax - no_other_dir: + .other_dir: + add [enemy_x], eax + .no_other_dir: ; initialization - mov byte[alldeadb],1 - mov edi,enemy_table - mov eax,dword[enemy_x] - mov dword[current_enemy_x],eax - mov eax,dword[enemy_y] - mov dword[current_enemy_y],eax + mov [alldeadb],1 + mov edi, enemy_table + mov eax, [enemy_x] + mov [current_enemy_x], eax + mov eax, [enemy_y] + mov [current_enemy_y], eax - loopit: - cmp byte[edi],1 - je drawenemy1 - - cmp byte[edi],2 - je drawenemy2 - - cmp byte[edi],3 - je drawenemy3 - - cmp byte[edi],4 - je drawenemy4 - - cmp byte[edi],5 - je drawenemy5 - - jmp dead_alien - - drawenemy1: - mov byte[alldeadb],0 - pusha - aimgtoimg enemy1,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0 - popa - - jmp checknext - - drawenemy2: - mov byte[alldeadb],0 - pusha - aimgtoimg enemy2,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0 - popa - - jmp checknext - - drawenemy3: - mov byte[alldeadb],0 - pusha - aimgtoimg enemy3,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0 - popa - - jmp checknext - - drawenemy4: - mov byte[alldeadb],0 - pusha - aimgtoimg enemy4,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0 - popa - - jmp checknext - - drawenemy5: - mov byte[alldeadb],0 - pusha - aimgtoimg enemy5,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0 - popa + .loopit: + movzx eax, byte[edi] + test al, al + jz .next_alien + cmp al, 5 + ja .next_alien + dec eax + mov eax, [enemy_img_list+eax*4] + .drawenemy: + mov [alldeadb], 0 + stdcall aimgtoimg, eax, [current_enemy_x], [current_enemy_y], vscreen, TRANSPARENCY ; jmp checknext - checknext: - cmp byte[enemy_d],2 - jge dont_change_dir + .checknext: + cmp [enemy_d], 2 + jge .dont_change_dir - movzx eax,byte[enemy_speed] + movzx eax, [enemy_speed] - cmp byte[enemy_d],0 - jbe change_dir + cmp [enemy_d], 0 + jbe .change_dir - cmp dword[current_enemy_x],eax - jg dont_change_dir + cmp dword[current_enemy_x],eax + jg .dont_change_dir - mov byte[enemy_d],2 + mov [enemy_d], 2 + jmp .dont_change_dir - jmp dont_change_dir + .change_dir: + mov ebx, SCREEN_X-ENEMY_X + sub ebx, eax + cmp dword[current_enemy_x],ebx + jl .dont_change_dir - change_dir: - mov ebx, SCREEN_X-ENEMY_X - sub ebx, eax - cmp dword[current_enemy_x],ebx - jl dont_change_dir + mov [enemy_d], 3 - mov byte[enemy_d],3 + .dont_change_dir: + cmp [current_enemy_y], SHIP_Y_POS-ENEMY_Y-BOUNDARY + jle .next_alien ;;;;;; - dont_change_dir: - cmp dword[current_enemy_y],SHIP_Y_POS-ENEMY_Y-BOUNDARY - je gameover_ - - dead_alien: - cmp edi,enemy_table+20 - jge alldead - - inc edi - add dword[current_enemy_x],ENEMY_X+BOUNDARY - mov eax,dword[current_enemy_x] - sub eax,dword[enemy_x] - cmp eax,5*(ENEMY_X+BOUNDARY) - jl no_newline - - sub dword[current_enemy_x],5*(ENEMY_X+BOUNDARY) - add dword[current_enemy_y],ENEMY_Y+BOUNDARY - no_newline: - jmp loopit - - alldead: - cmp byte[alldeadb],0 - je enemy_end - - mov byte[status],6 - jmp mainloop - - enemy_end: -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - cmp dword[alien_x],5 ; - jge @f - - call random_generator - cmp eax,0xffffffff/50 ; one out of 500 chances that it appears during this frame - jl alien_end - - mov dword [alien_x],SCREEN_X-ALIEN_X - - @@: - push eax - - mov eax, SCREEN_X ; mov eax, SCREEN_X - sub eax, dword [alien_x] - - cmp eax, ALIEN_X - jle @f - mov eax, ALIEN_X - @@: - - getimg alien,0,0,10,ALIEN_Y,alienpiece - aimgtoimg alien,dword [alien_x],ALIEN_Y_POS,vscreen,TRANSPARENCY,0 - sub dword[alien_x],5 ; - ; - pop eax ; - ; - alien_end: ; - ; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + mov [status], 2 ret -drawbullet: - cmp dword[bullet_y],BULLETSPEED - jl nobullet - sub dword[bullet_y],BULLETSPEED + .next_alien: + cmp edi, enemy_table+20 + jge .alldead - aimgtoimg bullet,dword[bullet_x],dword[bullet_y],vscreen,TRANSPARENCY,0 + inc edi + add dword[current_enemy_x],ENEMY_X+BOUNDARY + mov eax,dword[current_enemy_x] + sub eax,dword[enemy_x] + cmp eax,5*(ENEMY_X+BOUNDARY) + jl .no_newline - nobullet: + sub [current_enemy_x], 5*(ENEMY_X+BOUNDARY) + add [current_enemy_y], ENEMY_Y+BOUNDARY + .no_newline: + jmp .loopit + + .alldead: + cmp [alldeadb], 0 + je .enemy_end + + mov [status], 6 ret -checkbullet: - cmp dword[bullet_y],BULLETSPEED ; does the bullet hit top of the screen? - jle hidebullet ; yes, hide bullet + .enemy_end: + cmp [alien_x], 5 + jge @f -; ; check if bullet is inside the enemy field (you can disble this if you want) -; mov eax,dword[enemy_y] -; cmp dword[bullet_y],eax -; jl nohit -; -; add eax,4*(ENEMY_Y+BOUNDARY) -; cmp dword[bullet_y],eax -; jg nohit -; -; mov eax,dword[enemy_x] -; cmp dword[bullet_x],eax -; jl nohit -; -; add eax,5*(ENEMY_Y+BOUNDARY) -; cmp dword[bullet_x],eax -; jg nohit -; - mov edi,enemy_table - mov eax,dword[enemy_x] - mov dword[current_enemy_x],eax - mov eax,dword[enemy_y] - mov dword[current_enemy_y],eax + call random_generator + cmp eax,0xffffffff/50 ; one out of 500 chances that it appears during this frame + jl .alien_end + mov [alien_x], SCREEN_X-ALIEN_X + @@: + push eax - check: - cmp byte[edi],0 ; is the enemy at this position alive? - je nextcheck ; no, try next enemy + mov eax, SCREEN_X ; mov eax, SCREEN_X + sub eax, dword [alien_x] + + cmp eax, ALIEN_X + jle @f + mov eax, ALIEN_X + @@: + +; stdcall getimg, img_alien, 0, 0, 10, ALIEN_Y, img_alienpiece + stdcall aimgtoimg, img_alien, [alien_x], ALIEN_Y_POS, vscreen, TRANSPARENCY + sub [alien_x], 5 + + pop eax + + .alien_end: + ret + + + +render_bullet: + cmp [bullet_y], BULLETSPEED + jl .nobullet + sub [bullet_y], BULLETSPEED + + stdcall aimgtoimg, img_bullet, [bullet_x], [bullet_y], vscreen, TRANSPARENCY + + .nobullet: + ret + + + +bullet_collision_detection: + + cmp [bullet_y], BULLETSPEED ; does the bullet hit top of the screen? + jle .hidebullet ; yes, hide bullet + + mov edi, enemy_table + mov eax, [enemy_x] + mov [current_enemy_x], eax + mov eax, [enemy_y] + mov [current_enemy_y], eax + + .check: + cmp byte[edi],0 ; is the enemy at this position alive? + je .nextcheck ; no, try next enemy ; check if bullet hits current enemy - mov eax,dword[current_enemy_y] ; move the enemy y position into eax - cmp dword[bullet_y],eax ; is the bullet's y position less than eax (enemy y pos) - jl nextcheck ; yes, bullet can't be colliding, check next enemy + mov eax, [current_enemy_y] ; move the enemy y position into eax + cmp [bullet_y], eax ; is the bullet's y position less than eax (enemy y pos) + jl .nextcheck ; yes, bullet can't be colliding, check next enemy - add eax,ENEMY_Y ; add the width of the enemy to the enemy's y position (wich is still stored in eax) - cmp dword[bullet_y],eax ; is the bullet's y position greater than eax (the end of the enemy) - jg nextcheck ; yes, bullet can't be colliding, check next enemy + add eax, ENEMY_Y ; add the width of the enemy to the enemy's y position (wich is still stored in eax) + cmp [bullet_y], eax ; is the bullet's y position greater than eax (the end of the enemy) + jg .nextcheck ; yes, bullet can't be colliding, check next enemy - mov eax,dword[current_enemy_x] ; now do the same but for the x positions - cmp dword[bullet_x],eax ; - jl nextcheck ; - ; - add eax,ENEMY_Y ; - cmp dword[bullet_x],eax ; - jg nextcheck ; + mov eax, [current_enemy_x] ; now do the same but for the x positions + cmp [bullet_x], eax ; + jl .nextcheck ; + ; + add eax, ENEMY_Y ; + cmp [bullet_x], eax ; + jg .nextcheck ; - jmp hit + jmp .hit - nextcheck: - inc edi - add dword[current_enemy_x],ENEMY_X+BOUNDARY - mov eax,dword[current_enemy_x] - sub eax,dword[enemy_x] - cmp eax,5*(ENEMY_X+BOUNDARY) - jl no_newline_ + .nextcheck: + inc edi + add [current_enemy_x], ENEMY_X+BOUNDARY + mov eax, [current_enemy_x] + sub eax, [enemy_x] + cmp eax, 5*(ENEMY_X+BOUNDARY) + jl .no_newline - sub dword[current_enemy_x],5*(ENEMY_X+BOUNDARY) - add dword[current_enemy_y],ENEMY_Y+BOUNDARY - no_newline_: + sub [current_enemy_x], 5*(ENEMY_X+BOUNDARY) + add [current_enemy_y], ENEMY_Y+BOUNDARY + .no_newline: - cmp edi,enemy_table+20 ; is this the last enemy? - jg nohit ; yes, none of them was hit - jmp check ; no, check if enemy is alive and draw it + cmp edi, enemy_table+20 ; is this the last enemy? + jg .nohit ; yes, none of them was hit + jmp .check ; no, check if enemy is alive and draw it - hit: - movzx ebx,byte[edi] ; mov the enemy number onto ebx - add dword[score],ebx ; add this number to the score dword + .hit: + movzx ebx, byte[edi] ; mov the enemy number onto ebx + add [score], ebx ; add this number to the score dword - mov eax,[score] - call convertscore + mov eax,[score] + call convertscore - mov byte[edi],0 ; hide the enemy - hidebullet: - mov dword[bullet_y],1 ; mov the bullet to top of screen (hide it) - jmp noalienhit + mov byte[edi],0 ; hide the enemy + .hidebullet: + mov [bullet_y], 1 ; mov the bullet to top of screen (hide it) + jmp .noalienhit - nohit: - mov eax,[alien_x] ; check if we hit the big alien in the ufo - cmp [bullet_x],eax - jl noalienhit - add eax,ALIEN_X-BULLET_X - cmp [bullet_x],eax - jg noalienhit - cmp [bullet_y],ALIEN_Y_POS+ALIEN_Y - jg noalienhit + .nohit: + mov eax, [alien_x] ; check if we hit the big alien in the ufo + cmp [bullet_x], eax + jl .noalienhit + add eax, ALIEN_X-BULLET_X + cmp [bullet_x], eax + jg .noalienhit + cmp [bullet_y], ALIEN_Y_POS+ALIEN_Y + jg .noalienhit - add dword[score],100/5 - mov eax,[score] - call convertscore + add [score], 100/5 + mov eax, [score] + call convertscore - mov [alien_x],0 + mov [alien_x], 0 + + .noalienhit: + ret - noalienhit: -ret convertscore: - test al,1 - jz .1 - mov byte[scorenumb+5],'5' - jmp .2 -.1: - mov byte[scorenumb+5],'0' -.2: - shr eax,1 - mov ecx,10 - xor edx,edx - div ecx - add dl,'0' - mov byte[scorenumb+4],dl - xor edx,edx - div ecx - add dl,'0' - mov byte[scorenumb+3],dl - xor edx,edx - div ecx - add dl,'0' - mov byte[scorenumb+2],dl - xor edx,edx - div ecx - add dl,'0' - mov byte[scorenumb+1],dl - xor edx,edx - div ecx - add dl,'0' - mov byte[scorenumb+0],dl -ret + test al,1 + jz .1 + mov byte[scorenumb+5],'5' + jmp .2 + .1: + mov byte[scorenumb+5],'0' + .2: + shr eax,1 + mov ecx,10 + xor edx,edx + div ecx + add dl,'0' + mov byte[scorenumb+4],dl + xor edx,edx + div ecx + add dl,'0' + mov byte[scorenumb+3],dl + xor edx,edx + div ecx + add dl,'0' + mov byte[scorenumb+2],dl + xor edx,edx + div ecx + add dl,'0' + mov byte[scorenumb+1],dl + xor edx,edx + div ecx + add dl,'0' + mov byte[scorenumb+0],dl + + ret fillscreen: ; eax - screen color ( 0x00RRGGBB ) - mov edi,vscreen+8 + mov edi, vscreen+8 cld - mov ecx,SCREEN_X*SCREEN_Y + mov ecx, SCREEN_X*SCREEN_Y .lab1: - mov [edi],eax - add edi,3 - loop .lab1 + mov [edi], eax + add edi, 3 + loop .lab1 ret printtext: - push ebx - loadbyte: - movzx eax, byte[esi] - test eax, eax - jnz checkbyte + push ebx - pop ebx + .loop: + lodsb + test al, al + jz .done + cmp al, 13 + je .nextline + cmp al,' ' + je .space + cmp al,'0' + jl .loop + cmp al,'9' + jle .usenumbers + + cmp al,'z' + jg .loop + cmp al,'a' + jge .usesmallfont + + cmp al,'Z' + jg .loop + cmp al,'A' + jge .usebigfont + jmp .loop + + .usesmallfont: + movzx edx, al + sub edx, 'a' + mov eax, 12 + mul edx + + stdcall getimg, img_smallfont, 0, eax, 20, 12, img_char + push ecx + add ecx, 4 + stdcall aimgtoimg, img_char, ebx, ecx, vscreen, TRANSPARENCY + pop ecx + add ebx, 20 + jmp .loop + + .usebigfont: + movzx edx, al + sub edx, 'A' + mov eax, 20 + mul edx + + stdcall getimg, img_bigfont, 0, eax, 28, 20, img_char + stdcall aimgtoimg, img_char, ebx, ecx, vscreen, TRANSPARENCY + add ebx, 28 + jmp .loop + + .usenumbers: + movzx edx, al + sub edx, '0' + mov eax, 20 + mul edx + + stdcall getimg, img_numbers, 0, eax, 16, 20, img_char + stdcall aimgtoimg, img_char, ebx, ecx, vscreen, TRANSPARENCY + add ebx, 20 + jmp .loop + + .space: + add ebx, 20 + jmp .loop + + .nextline: + pop ebx + push ebx + add ecx, 26 + jmp .loop + + .done: + pop ebx ret - checkbyte: - cmp al,13 - je nextline - cmp al,' ' - je space - cmp al,'0' - jl nextchar - cmp al,'9' - jle usenumbers +init_starfield: - cmp al,'z' - jg nextchar - cmp al,'a' - jge usesmallfont + mov ebx, STARS + .loop: + cmp ebx, STARS+(STARS_*5) + jge .done - cmp al,'Z' - jg nextchar - cmp al,'A' - jge usebigfont + call random_generator + and al, STARLEVELS + test al,al + jnz @f + inc al + @@: + mov byte[ebx],al - jmp nextchar + call random_generator + and eax, SCREEN_X-1 + inc eax + mov word[ebx+1],ax + + call random_generator + and eax, SCREEN_Y-1 + inc eax + mov word[ebx+3],ax + + add ebx, 5 + jmp .loop + .done: + ret - usesmallfont: - mov edx,eax - sub edx,'a' - mov eax,12 - mul edx - mov edx,eax +render_starfield: - pusha - getimg smallfont,0,edx,20,12,char - popa + mov esi, STARS + .loop: + cmp esi, STARS+(STARS_*5) + jge .done - pusha - add ecx,4 - aimgtoimg char,ebx,ecx,vscreen,TRANSPARENCY,0 - popa + movzx eax, byte[esi] ; z (speed, brightness) + movzx ebx, word[esi+1] ; x + movzx ecx, word[esi+3] ; y + add bx, ax + cmp bx, SCREEN_X + jl .moveit - add ebx,20 + xor ebx, ebx + inc ebx - jmp nextchar + call random_generator + mov ecx, [generator] + and ecx, SCREEN_Y-1 + inc ecx + mov word[esi+3], cx - usebigfont: - mov edx,eax - sub edx,'A' - mov eax,20 - mul edx - mov edx,eax - - pusha - getimg bigfont,0,edx,28,20,char - popa - - pusha - aimgtoimg char,ebx,ecx,vscreen,TRANSPARENCY,0 - popa - - add ebx,28 - - jmp nextchar - - usenumbers: - mov edx,eax - sub edx,'0' - mov eax,20 - mul edx - mov edx,eax - - pusha - getimg numbers,0,edx,16,20,char - popa - - pusha - aimgtoimg char,ebx,ecx,vscreen,TRANSPARENCY,0 - popa - - add ebx,20 - - jmp nextchar - - space: - add ebx,20 - - nextchar: - inc esi - - jmp loadbyte - - nextline: - pop ebx - push ebx - add ecx,26 - inc esi - - jmp loadbyte - -gameover_: - mov byte[status],2 - - ret - - -drawstars: - mov esi, STARS - -.loop: - cmp esi, STARS+(STARS_*5) - jge .done - - movzx eax, byte[esi] ; z (speed, brightness) - movzx ebx, word[esi+1] ; x - movzx ecx, word[esi+3] ; y - add bx , ax - cmp bx , SCREEN_X - jl .moveit - - xor ebx,ebx - inc ebx - - call random_generator - mov ecx, [generator] - and ecx, SCREEN_Y-1 - inc ecx - mov word[esi+3],cx - - call random_generator - and al, STARLEVELS - test al,al - jnz @f - inc al + call random_generator + and al, STARLEVELS + test al, al + jnz @f + inc al @@: - mov [esi],al + mov [esi], al -.moveit: - mov word [esi+1],bx + .moveit: + mov word[esi+1], bx - movzx eax, byte[esi] - inc eax - mov edx, 0xff/(STARLEVELS+1) - mul edx + movzx eax, byte[esi] + inc eax + mov edx, 0xff/(STARLEVELS+1) + mul edx - mov ah,al - shl eax,8 - mov al,ah - mov ebp, eax + mov ah, al + shl eax, 8 + mov al, ah + mov ebp, eax - mov eax, SCREEN_X - mul ecx - add eax, ebx - mov edx, 3 - mul edx + mov eax, SCREEN_X + mul ecx + add eax, ebx + mov edx, 3 + mul edx - cmp eax, SCREEN_X*SCREEN_Y*3 - jg @f - add eax, vscreen+8 - and dword[eax],0xff000000 - or dword[eax],ebp - @@: + cmp eax, SCREEN_X*SCREEN_Y*3 + jg @f + add eax, vscreen+8 + and dword[eax], 0xff000000 + or dword[eax], ebp + @@: - add esi, 5 - jmp .loop -.done: - - ret - - -createstars: - - mov ebx, STARS -.loop: - cmp ebx, STARS+(STARS_*5) - jge .done - - call random_generator - and al, STARLEVELS - test al,al - jnz @f - inc al - @@: - mov byte[ebx],al - - call random_generator - and eax, SCREEN_X-1 - inc eax - mov word[ebx+1],ax - - call random_generator - and eax, SCREEN_Y-1 - inc eax - mov word[ebx+3],ax - - add ebx, 5 - jmp .loop -.done: - - ret + add esi, 5 + jmp .loop + .done: + ret random_generator: ; (pseudo random, actually :) - xor eax,[generator] - imul eax,214013 - xor eax,0xdeadbeef - rol eax,9 - mov [generator],eax - ror eax,16 - and eax,0x7fff + xor eax, [generator] + imul eax, 214013 + xor eax, 0xdeadbeef + rol eax, 9 + mov [generator], eax + ror eax, 16 + and eax, 0x7fff - ret + ret @@ -1217,9 +1420,8 @@ db 0,0,0,0,0 db 0,0,0,0,0 db 0,0,0,0,0 - -msg1 db 'Vesa mode not supported',13,'Press any key to exit.',13,0 msgAbout db 'Hidnplayrs invaders',13,'KolibriOS version',13,13,'released under GPL',13,'make this game better',13,'if you want to',0 +title db 'Invaders',0 msgdone db 'You have saved the planet!',0 entername db 'Enter your name highscorer!',0 highscorefile db 'invaders.dat',0 @@ -1243,7 +1445,7 @@ status db 0 ; status: 0=menu 1=game 2=gameover 3=paused 4=a menu db 0 ; menu: 0=start 1=about 2=highscores 3=exit... generator dd 0x45dd4d15 alien_x dd 0 -drawroutine dd 0 +;drawroutine dd 0 returnaddr dd 0 intro dw 0 scoretext db 'score ' @@ -1256,153 +1458,104 @@ enemy_speed db 1 namepos db 0 name db 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x0d,0x00 +enemy_img_list: + dd img_enemy1 + dd img_enemy2 + dd img_enemy3 + dd img_enemy4 + dd img_enemy5 -gif_bullet file 'bullet2.gif' -rb 4 -gif_bullet2 file 'bullet2.gif' -rb 4 +gif_bullet file 'bullet2.gif' + .size = $ - gif_bullet +gif_bullet2 file 'bullet2.gif' + .size = $ - gif_bullet2 +gif_ship file 'ship.gif' + .size = $ - gif_ship +gif_enemy1 file 'enemy1.gif' + .size = $ - gif_enemy1 +gif_enemy2 file 'enemy2.gif' + .size = $ - gif_enemy2 +gif_enemy3 file 'enemy3.gif' + .size = $ - gif_enemy3 +gif_enemy4 file 'enemy4.gif' + .size = $ - gif_enemy4 +gif_enemy5 file 'enemy5.gif' + .size = $ - gif_enemy5 +gif_alien file 'alien.gif' + .size = $ - gif_alien +gif_menu1 file 'menu1.gif' + .size = $ - gif_menu1 +gif_menu2 file 'menu2.gif' + .size = $ - gif_menu2 +gif_menu3 file 'menu3.gif' + .size = $ - gif_menu3 +gif_menu4 file 'menu4.gif' + .size = $ - gif_menu3 +gif_logo file 'logo.gif' + .size = $ - gif_logo +gif_pause file 'pause.gif' + .size = $ - gif_pause +gif_highscore file 'highscores.gif' + .size = $ - gif_highscore +gif_smallfont file 'font_small.gif' + .size = $ - gif_smallfont +gif_bigfont file 'font_capital.gif' + .size = $ - gif_bigfont +gif_numbers file 'numbers.gif' + .size = $ - gif_numbers +gif_levelup file 'nextlevel.gif' + .size = $ - gif_levelup +gif_gameover file 'gameover.gif' + .size = $ - gif_gameover -gif_ship file 'ship.gif' -rb 4 +align 16 +@IMPORT: -gif_enemy1 file 'enemy1.gif' -rb 4 +library \ + libimg , 'libimg.obj' -gif_enemy2 file 'enemy2.gif' -rb 4 +import libimg , \ + libimg.init , 'lib_init' , \ + img.decode , 'img_decode' , \ + img.to_rgb2 , 'img_to_rgb2', \ + img.destroy , 'img_destroy' -gif_enemy3 file 'enemy3.gif' -rb 4 - -gif_enemy4 file 'enemy4.gif' -rb 4 - -gif_enemy5 file 'enemy5.gif' -rb 4 - -gif_alien file 'alien.gif' -rb 4 - -gif_menu1 file 'menu1.gif' -rb 4 - -gif_menu2 file 'menu2.gif' -rb 4 - -gif_menu3 file 'menu3.gif' -rb 4 - -gif_menu4 file 'menu4.gif' -rb 4 - -gif_logo file 'logo.gif' -rb 4 - -gif_pause file 'pause.gif' -rb 4 - -gif_highscore file 'highscores.gif' -rb 4 - -gif_smallfont file 'font_small.gif' -rb 4 - -gif_bigfont file 'font_capital.gif' -rb 4 - -gif_numbers file 'numbers.gif' -rb 4 - -gif_levelup file 'nextlevel.gif' -rb 4 - -gif_gameover file 'gameover.gif' -rb 4 vscreen: -dd SCREEN_X -dd SCREEN_Y -rb SCREEN_X*SCREEN_Y*3+10 + dd SCREEN_X + dd SCREEN_Y + rb SCREEN_X*SCREEN_Y*3 IM_END: -STARS: -rb STARS_*5 +STARS rb STARS_*5 -bullet: -rb BULLET_X*BULLET_Y*3+8+10 +img_bullet rb BULLET_X*BULLET_Y*3+8 +img_bullet2 rb BULLET_X*BULLET_Y*3+8 +img_ship rb SHIP_X*SHIP_Y*3+8 +img_enemy1 rb ENEMY_X*ENEMY_Y*3+8 +img_enemy2 rb ENEMY_X*ENEMY_Y*3+8 +img_enemy3 rb ENEMY_X*ENEMY_Y*3+8 +img_enemy4 rb ENEMY_X*ENEMY_Y*3+8 +img_enemy5 rb ENEMY_X*ENEMY_Y*3+8 +img_alien rb ALIEN_X*ALIEN_Y*3+8 +img_menu1 rb 220*18*3+8 +img_menu2 rb 135*18*3+8 +img_menu3 rb 245*18*3+8 +img_menu4 rb 110*18*3+8 +img_logo rb 40*540*3+8 +img_pause rb 40*320*3+8 +img_levelup rb 40*320*3+8 +img_gameover rb 40*320*3+8 +img_highscore rb 40*530*3+8 +img_smallfont rb 20*312*3+8 +img_bigfont rb 28*520*3+8 +img_numbers rb 16*200*3+8 -bullet2: -rb BULLET_X*BULLET_Y*3+8+10 +img_char rb 28*20*3+8 +img_alienpiece rb ALIEN_X*ALIEN_Y*3+8 -ship: -rb SHIP_X*SHIP_Y*3+10 - -enemy1: -rb ENEMY_X*ENEMY_Y*3+10 - -enemy2: -rb ENEMY_X*ENEMY_Y*3+10 - -enemy3: -rb ENEMY_X*ENEMY_Y*3+10 - -enemy4: -rb ENEMY_X*ENEMY_Y*3+10 - -enemy5: -rb ENEMY_X*ENEMY_Y*3+10 - -alien: -rb ALIEN_X*ALIEN_Y*3+10 - -menu1: -rb 220*18*3+10 - -menu2: -rb 135*18*3+10 - -menu3: -rb 245*18*3+10 - -menu4: -rb 110*18*3+10 - -logo: -rb 40*540*3+10 - -pause_: -rb 40*320*3+10 - -levelup: -rb 40*320*3+10 - -gameover: -rb 40*320*3+10 - -highscore: -rb 40*530*3+10 - -smallfont: -rb 20*312*3+10 - -bigfont: -rb 28*520*3+10 - -numbers: -rb 16*200*3+10 - -char: -rb 28*20*3+20 ; biggest char's are 28x20 - -alienpiece: -rb ALIEN_X*ALIEN_Y*3+20 - -gif_hash_area: -rd 4096+1 ;hash area size for unpacking GIF - -I_END: - -;include 'dex.inc' +highscorebuffer rb 1024 +I_END: \ No newline at end of file diff --git a/programs/games/invaders/invaders_kolibri.inc b/programs/games/invaders/invaders_kolibri.inc deleted file mode 100644 index f62ba74f9d..0000000000 --- a/programs/games/invaders/invaders_kolibri.inc +++ /dev/null @@ -1,115 +0,0 @@ - use32 - org 0x0 - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd START ; start of code - dd IM_END ; size of image - dd I_END+1000 ; memory for app - dd I_END+1000 ; esp - dd 0x0 , 0x0 ; I_Param , I_Icon - - -KEY_RIGHT equ 179 -KEY_LEFT equ 176 -KEY_UP equ 178 -KEY_P equ 'p' -KEY_DOWN equ 177 -KEY_ENTER equ 13 -KEY_ESC equ 27 - -START: - mov [drawroutine], draw_picture_kolibri - call draw_window - jmp decodegif - -draw_picture_kolibri: - - mov eax,7 ; Draw buffer to screen - mov ebx,vscreen+8 - mov ecx,SCREEN_X*65536+SCREEN_Y - mov edx,SCREEN_X_POS*65536+SCREEN_Y_POS - int 0x40 - -ret - -waitandgetkey: - - mov eax, 5 - mov ebx, 1 - int 0x40 - - mov eax, 11 ; check for event (no wait) - int 0x40 - - cmp eax,1 ; redraw request ? - je red - cmp eax,2 ; key in buffer ? - je key - cmp eax,3 ; button in buffer ? - je button - - xor ax,ax - - ret - - red: ; redraw - call draw_window - - jmp waitandgetkey - - key: ; key - mov eax,2 ; read it - int 0x40 - - mov al, ah - - ret - - button: ; button - mov eax,17 ; get id - int 0x40 - - cmp ah,1 ; button id=1 ? - jne noclose - - exit: - mov eax,-1 ; close this program - int 0x40 - noclose: - - jmp waitandgetkey - - -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,WINDOW_X*65536+10+SCREEN_X ; [x start] *65536 + [x size] - mov ecx,WINDOW_Y*65536+30+SCREEN_Y ; [y start] *65536 + [y size] - mov edx,0x04000000 ; color of work area RRGGBB,8->color gl - mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl - mov edi,0x005080d0 ; color of frames RRGGBB - int 0x40 - - mov eax,71 - mov ebx,1 - mov ecx,header - int 0x40 - - call [drawroutine] - - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,2 ; 2, end of draw - int 0x40 - -ret - -load_highscores: -ret - -save_highscores: -ret - -header db 'Invaders',0 \ No newline at end of file