diff --git a/data/Tupfile.lua b/data/Tupfile.lua index d915d070b..41f57b192 100644 --- a/data/Tupfile.lua +++ b/data/Tupfile.lua @@ -450,9 +450,9 @@ tup.append_table(img_files, { {"TIMER", VAR_PROGS .. "/other/Timer/Timer"}, {"UNZ", VAR_PROGS .. "/fs/unz/unz"}, {"ZKEY", VAR_PROGS .. "/system/zkey/trunk/ZKEY"}, - {"3D/3DWAV", VAR_PROGS .. "/demos/3dwav/trunk/3dwav"}, + {"3D/3DWAV", VAR_PROGS .. "/demos/3dwav/3dwav"}, {"3D/CROWNSCR", VAR_PROGS .. "/demos/crownscr/trunk/crownscr"}, - {"3D/3DCUBE2", VAR_PROGS .. "/demos/3dcube2/trunk/3DCUBE2"}, + {"3D/3DCUBE2", VAR_PROGS .. "/demos/3dcube2/3DCUBE2"}, {"3D/FREE3D04", VAR_PROGS .. "/demos/free3d04/trunk/free3d04"}, {"3D/GEARS", VAR_PROGS .. "/develop/libraries/TinyGL/asm_fork/examples/gears"}, {"3D/RAY", VAR_PROGS .. "/demos/ray/ray"}, @@ -598,7 +598,7 @@ tup.append_table(extra_files, { {"HD_Load/USB_Boot/", VAR_PROGS .. "/hd_load/usb_boot/setmbr.exe"}, {"HD_Load/USB_boot_old/", VAR_PROGS .. "/hd_load/usb_boot_old/MeOSload.com"}, {"HD_Load/USB_boot_old/", VAR_PROGS .. "/hd_load/usb_boot_old/enable.exe"}, - {"kolibrios/3D/3dsheart", VAR_PROGS .. "/demos/3dsheart/trunk/3dsheart"}, + {"kolibrios/3D/3dsheart", VAR_PROGS .. "/demos/3dsheart/3dsheart"}, {"kolibrios/3D/flatwav", VAR_PROGS .. "/demos/flatwav/trunk/flatwav"}, {"kolibrios/3D/mos3de", VAR_PROGS .. "/demos/mos3de/mos3de"}, {"kolibrios/3D/info3ds/INFO3DS", VAR_PROGS .. "/develop/info3ds/info3ds"}, diff --git a/programs/build_all.bat b/programs/build_all.bat index a28779620..6fbd8b172 100644 --- a/programs/build_all.bat +++ b/programs/build_all.bat @@ -201,9 +201,9 @@ rem fasm games\hunter\trunk\hunter.asm %BIN%\games\hunter echo * echo Building demos echo * -fasm demos\3dcube2\trunk\3dcube2.asm %BIN%\3d\3dcube2 -rem fasm demos\3detx60b\trunk\3detx60b.asm %BIN%\3d\3detx60b -fasm demos\3dtcub10\trunk\3dtcub10.asm %BIN%\3d\3dtcub10 +fasm demos\3dcube2\3dcube2.asm %BIN%\3d\3dcube2 +rem fasm demos\3detx60b\3detx60b.asm %BIN%\3d\3detx60b +fasm demos\3dtcub10\3dtcub10.asm %BIN%\3d\3dtcub10 cd demos\aclock\trunk\ nasmw -t -f bin -o ..\..\..\%BIN%\demos\aclock aclock.asm cd ..\..\.. diff --git a/programs/demos/3dcube2/trunk/3DCUBE2.ASM b/programs/demos/3dcube2/3DCUBE2.ASM similarity index 93% rename from programs/demos/3dcube2/trunk/3DCUBE2.ASM rename to programs/demos/3dcube2/3DCUBE2.ASM index 565d64826..52e4f5ae7 100644 --- a/programs/demos/3dcube2/trunk/3DCUBE2.ASM +++ b/programs/demos/3dcube2/3DCUBE2.ASM @@ -1,685 +1,688 @@ -; -; 3D POLYGONAL CUBE - ASCL -; -; Pavlushin Evgeni -; mail: waptap@mail.ru site: www.deck4.narod.ru -; -; Create on base 3D test sample -; Mikolaj Felix mfelix@polbox.com -; - -use32 - org 0x0 - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd START ; start of code - dd I_END ; size of image - dd 0x30000 ; memory for app - dd 0x30000 ; esp - dd 0x0 , 0x0 ; I_Param , I_Icon - -MAX_POINTS equ 8 -MAX_TRIANGLES equ 12 -SCREEN_X equ 320 -SCREEN_Y equ 200 - -include '..\..\..\macros.inc' -;purge mov - -START: -init_sin_cos: - finit - fldz - xor edi,edi - mov ecx,512 -isc_make: - fld st0 - fsincos - fmul [fixed_point_const] - fistp word [cos_table+edi] - fmul [fixed_point_const] - fistp word [sin_table+edi] - - fadd [inc_angle] - - add edi,2 - loop isc_make - fstp st0 -red: - call draw_window - -still: - mov eax,11 - mcall - - dec eax -; cmp eax,1 ; window redraw request ? - jz red - dec eax -; cmp eax,2 ; key in buffer ? - jz key - dec eax -; cmp eax,3 ; button in buffer ? - jz button - - -; 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 - mcall - 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: - mov dword [ttt],fps_show_frequency - mov eax,47 - mov ebx,5*65536 - mov edx,(x+1)*65536+y - mov esi,color+0xD0000000 - mov edi,delcolor - mov ecx,[fps] - mcall -no_out_fps: -} - - fps 220,5,0x00FFFfff,0x00000000 - -main_loop: - - mov esi,object - mov edi,object_rotated - mov ecx,MAX_POINTS*3 - cld - rep movsw - - mov esi,angle_x - mov edi,object_rotated - mov ecx,MAX_POINTS - call rotate_points - - mov esi,object_rotated - mov edi,object_translated - mov ecx,MAX_POINTS - call translate_points - - call draw_faces - - call clear_screen_buffer - - add [angle_x],2 - add [angle_y],3 - add [angle_z],1 - - jmp still - -key: - mov eax,2 - mcall - jmp still -button: - mov eax,17 - mcall - cmp ah,1 - jne still -exit: - mov eax,-1 - mcall - -;Draw window -draw_window: - mcall 12, 1 ;Start window redraw - - mcall 48, 4 - - lea ecx,[100*65536+SCREEN_Y+4+eax]; [y start] *65536 + [y size] + [skin_height] - xor eax,eax ;Draw window - mov ebx,100*65536+(SCREEN_X+9) ;x start*65536+x size - mov edx,0x54000000 ;0x03 use skinned window - mov edi,title - mcall - - mcall 12, 2 ;End window redraw - - ret - -title db '3D Cube Sample',0 - - -; Draw faces procedure - -draw_faces: - - mov esi,link - mov ecx,MAX_TRIANGLES -df_draw: - push ecx - mov ecx,3 - mov edi,@@tx1 ;bp -df_get_point: - movzx ebx, byte [esi] - movzx eax, word [object_translated + ebx*4] - stosd - movzx eax, word [object_translated + ebx*4 + 2] - stosd - inc esi - dec ecx - jnz df_get_point - - mov eax,[@@ty1] - sub eax,[@@ty3] - mov ebx,[@@tx2] - sub ebx,[@@tx1] - imul ebx - push eax - mov eax,[@@tx1] - sub eax,[@@tx3] - mov ebx,[@@ty2] - sub ebx,[@@ty1] - imul ebx - pop ebx - sub ebx,eax - jge df_next - - movzx eax, byte [esi] - - mov [@@xcol], eax - - call filled_triangle -df_next: - inc esi - pop ecx - dec ecx - jnz df_draw - ret - -;modify -;include graphlib.asm - -clear_screen_buffer: - -;outscrbuf - mcall 48, 4 - mov ebx,scrbuf - mov ecx,SCREEN_X*65536+SCREEN_Y - lea edx,[5*65536+eax] - mov eax,7 - mcall - -;White background - mov edi,scrbuf - mov ecx,(SCREEN_X*SCREEN_Y*3)/4 - mov eax,0xffffffff - cld - rep stosd - - ret - -;include triangle.asm -; Mikolaj Felix 14/5/2001 -; mfelix@polbox.com - -;filled trangle procedure - -align 4 -@@tx1 dd 0 -@@ty1 dd 0 -@@tx2 dd 0 -@@ty2 dd 0 -@@tx3 dd 0 -@@ty3 dd 0 -@@xcol dd 0 - -@@dx12 dd 0 -@@dx13 dd 0 -@@dx23 dd 0 - -filled_triangle: - - mov eax,[@@xcol] ;trnsforming color - mov bl,al ;byte bbbggrrx - mov dl,al ;to 3 byte - mov dh,al ;bbbxxxxx ggxxxxxx rrxxxxxx - and dh,00000001b - - and al,11100000b - and bl,00011000b - and dl,00000110b - shl bl,3 - shl dl,5 - - cmp dh,1 - jne no_bitup - or al,00011111b - or bl,00111111b - or dl,00111111b -no_bitup: - - shl eax,8 ;puck colors - mov al,bl - shl eax,8 - mov al,dl - mov dword [@@rgb],eax - - mov eax,[@@ty1] - cmp eax,[@@ty3] - jb ft_check1 - - xchg eax,[@@ty3] - mov [@@ty1],eax - - mov eax,[@@tx1] - xchg eax,[@@tx3] - mov [@@tx1],eax -ft_check1: - mov eax,[@@ty2] - cmp eax,[@@ty3] - jb ft_check2 - - xchg eax,[@@ty3] - mov [@@ty2],eax - - mov eax,[@@tx2] - xchg eax,[@@tx3] - mov [@@tx2],eax -ft_check2: - mov eax,[@@ty1] - cmp eax,[@@ty2] - jb ft_check3 - - xchg eax,[@@ty2] - mov [@@ty1],eax - - mov eax,[@@tx1] - xchg eax,[@@tx2] - mov [@@tx1],eax -ft_check3: - - mov ebx,[@@ty2] - sub ebx,[@@ty1] - jnz ft_dx12_make - - mov [@@dx12],dword 0 - jmp ft_dx12_done -ft_dx12_make: - mov eax,[@@tx2] - sub eax,[@@tx1] - shl eax,7 - cdq - idiv ebx - mov [@@dx12],eax ; dx12 = (x2-x1)/(y2-y1) -ft_dx12_done: - - mov ebx,[@@ty3] - sub ebx,[@@ty1] - jnz ft_dx13_make - - mov [@@dx13],dword 0 - jmp ft_dx13_done -ft_dx13_make: - mov eax,[@@tx3] - sub eax,[@@tx1] - shl eax,7 - cdq - idiv ebx - mov [@@dx13],eax ; dx13 = (x3-x1)/(y3-y1) -ft_dx13_done: - - mov ebx,[@@ty3] - sub ebx,[@@ty2] - jnz ft_dx23_make - - mov [@@dx23],dword 0 - jmp ft_dx23_done -ft_dx23_make: - mov eax,[@@tx3] - sub eax,[@@tx2] - shl eax,7 - cdq - idiv ebx - mov [@@dx23],eax ; dx23 = (x3-x2)/(y3-y2) -ft_dx23_done: - - mov eax,[@@tx1] - shl eax,7 - mov ebx,eax - - mov ecx,[@@ty1] -ft_loop1: - - pushad - - mov [@@ly],ecx - mov edx,ebx - shr edx,7 - mov [@@lx2],edx - mov edx,eax - shr edx,7 - mov [@@lx1],edx - mov eax,[@@xcol] - mov [@@lcol],eax - call horizontal_line - - popad - - add eax,[@@dx13] - add ebx,[@@dx12] - inc ecx - cmp ecx,[@@ty2] - jb ft_loop1 - - - mov ebx,[@@tx2] - shl ebx,7 - mov ecx,[@@ty2] -ft_loop2: - - pushad - - mov [@@ly],ecx - mov edx,ebx - shr edx,7 - mov [@@lx2],edx - mov edx,eax - shr edx,7 - mov [@@lx1],edx - mov eax,[@@xcol] - mov [@@lcol],eax - call horizontal_line - - popad - - add eax,[@@dx13] - add ebx,[@@dx23] - inc ecx - cmp ecx,[@@ty3] - jb ft_loop2 - - ret - -;horizontal line subproc - -align 4 -@@lx1 dd 0 -@@lx2 dd 0 -@@ly dd 0 -@@lcol dd 0 - -@@rgb dd 0 - -horizontal_line: - - mov ecx,[@@lx1] - sub ecx,[@@lx2] - ja x12 - je ext -; ret - neg ecx - mov edi,3 - jmp xx -x12: - mov edi,-3 - jmp xx -ext: - mov ecx,-1 ;1 -; sub ebp,3 -xx: - mov eax,[@@ly] - mov ebx,SCREEN_X ;320 - mul ebx - add eax,[@@lx1] - lea ebp,[eax*3-3] ; for delete white dots - add ecx,2 -loo: - - mov eax,dword [@@rgb] - mov bl,al - shr eax,8 ;puck colors - - mov byte [scrbuf+ebp],ah - mov byte [scrbuf+ebp+1],al - mov byte [scrbuf+ebp+2],bl - add ebp,edi - dec ecx - jnz loo - - ret - -;include fixed3d.asm -; Mikolaj Felix 25/5/2001 -; mfelix@polbox.com - -;------------------------------------------------------------ -; ds:si - offset to angles -; ds:di - offset to 3d points -; cx - number of points -;------------------------------------------------------------ - -@@sin_x dw 0 -@@cos_x dw 0 -@@sin_y dw 0 -@@cos_y dw 0 -@@sin_z dw 0 -@@cos_z dw 0 - -@@px equ word [edi] -@@py equ word [edi+2] -@@pz equ word [edi+4] - -rotate_points: - - push edi - mov edi,@@sin_x - mov edx,3 -rp_sin_cos: - mov ebx, [esi] - and ebx,511 - mov ax,word [sin_table+ebx*2] - mov word [edi],ax - mov ax,word [cos_table+ebx*2] - mov word [edi+2],ax - - add esi,2 - add edi,4 - dec edx - jnz rp_sin_cos - pop edi - -rp_rotate: - - ; rotate around x-axis - - mov ax,@@py - imul [@@cos_x] - mov bx,ax - mov si,dx - - mov ax,@@pz - imul [@@sin_x] - sub bx,ax - sbb si,dx - shrd bx,si,14 - push bx - - mov ax,@@py - imul [@@sin_x] - mov bx,ax - mov si,dx - - mov ax,@@pz - imul [@@cos_x] - add bx,ax - adc si,dx - shrd bx,si,14 - - pop @@py - mov @@pz,bx - - ; rotate around y-axis - - mov ax,@@px - imul [@@cos_y] - mov bx,ax - mov si,dx - - mov ax,@@pz - imul [@@sin_y] - sub bx,ax - sbb si,dx - shrd bx,si,14 - push bx - - mov ax,@@px - imul [@@sin_y] - mov bx,ax - mov si,dx - - mov ax,@@pz - imul [@@cos_y] - add bx,ax - adc si,dx - shrd bx,si,14 - - pop @@px - mov @@pz,bx - - ; rotate around z-axis - - mov ax,@@px - imul [@@cos_z] - mov bx,ax - mov si,dx - - mov ax,@@py - imul [@@sin_z] - sub bx,ax - sbb si,dx - shrd bx,si,14 - push bx - - mov ax,@@px - imul [@@sin_z] - mov bx,ax - mov si,dx - - mov ax,@@py - imul [@@cos_z] - add bx,ax - adc si,dx - shrd bx,si,14 - - pop @@px - mov @@py,bx - - add edi,6 - dec ecx - jnz rp_rotate - - ret - -;------------------------------------------------------------ -; ds:si - offset to 3d points -; es:di - offset to 2d points -; cx - number of points -;------------------------------------------------------------ - - mx dw 0 - my dw 0 - -translate_points: - pushad - mov eax,37 - mov ebx,1 - mcall - mov ebx,eax - shr eax,16 - and ebx,0xffff - cmp ax,SCREEN_X - jna x_n - mov ax,0 ;SCREEN_X -x_n: - cmp bx,SCREEN_Y - jna y_n - mov bx,0 ;SCREEN_Y -y_n: - mov [mx],ax - mov [my],bx - popad - - movzx ebx,word [esi+4] - mov ax,[my] - cmp ax,0 - jng no_m - shl ax,3 - add bx,ax -no_m: - add bx,256 ; Z factor (zoom) - - movsx eax,word [esi] - shl eax,8 - cdq - idiv ebx - add eax,(SCREEN_X/2) ;160 ;X factor (center X) - stosw - - movsx eax,word [esi+2] - shl eax,8 - cdq - idiv ebx - add eax,(SCREEN_Y/2) ;100 ;Y factor (center Y) - stosw - - add esi,6 - dec ecx - jnz translate_points - ret - -fixed_point_const dd 16384.0 -inc_angle dd 0.01227184630309 ; pi/256 - -angle_x dw 0 -angle_y dw 0 -angle_z dw 0 - -object dw -50,-50,-50, 50,-50,-50, 50,50,-50, -50,50,-50 - dw -50,-50, 50, 50,-50, 50, 50,50, 50, -50,50, 50 - -link: - db 0,1,2,10000011b, 0,2,3,10000011b ;purpure side - db 5,4,7,00000111b, 5,7,6,00000111b ;soft-red side - db 1,5,6,00011000b, 1,6,2,00011000b ;soft-lime side - db 4,0,3,11100001b, 4,3,7,11100001b ;soft-blue side - db 4,5,1,00011111b, 1,0,4,00011111b ;yellow side - db 3,2,6,00000000b, 3,6,7,00000000b ;black side - -sin_table: -rw 512 -cos_table: -rw 512 - -object_rotated: -rw MAX_POINTS*3 -object_translated: -rw MAX_POINTS*2 - -scrbuf: -I_END: \ No newline at end of file +; SPDX-License-Identifier: NOASSERTION +; + +; +; 3D POLYGONAL CUBE - ASCL +; +; Pavlushin Evgeni +; mail: waptap@mail.ru site: www.deck4.narod.ru +; +; Create on base 3D test sample +; Mikolaj Felix mfelix@polbox.com +; + +use32 + org 0x0 + db 'MENUET01' ; 8 byte id + dd 0x01 ; header version + dd START ; start of code + dd I_END ; size of image + dd 0x30000 ; memory for app + dd 0x30000 ; esp + dd 0x0 , 0x0 ; I_Param , I_Icon + +MAX_POINTS equ 8 +MAX_TRIANGLES equ 12 +SCREEN_X equ 320 +SCREEN_Y equ 200 + +include '..\..\macros.inc' +;purge mov + +START: +init_sin_cos: + finit + fldz + xor edi,edi + mov ecx,512 +isc_make: + fld st0 + fsincos + fmul [fixed_point_const] + fistp word [cos_table+edi] + fmul [fixed_point_const] + fistp word [sin_table+edi] + + fadd [inc_angle] + + add edi,2 + loop isc_make + fstp st0 +red: + call draw_window + +still: + mov eax,11 + mcall + + dec eax +; cmp eax,1 ; window redraw request ? + jz red + dec eax +; cmp eax,2 ; key in buffer ? + jz key + dec eax +; cmp eax,3 ; button in buffer ? + jz button + + +; 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 + mcall + 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: + mov dword [ttt],fps_show_frequency + mov eax,47 + mov ebx,5*65536 + mov edx,(x+1)*65536+y + mov esi,color+0xD0000000 + mov edi,delcolor + mov ecx,[fps] + mcall +no_out_fps: +} + + fps 220,5,0x00FFFfff,0x00000000 + +main_loop: + + mov esi,object + mov edi,object_rotated + mov ecx,MAX_POINTS*3 + cld + rep movsw + + mov esi,angle_x + mov edi,object_rotated + mov ecx,MAX_POINTS + call rotate_points + + mov esi,object_rotated + mov edi,object_translated + mov ecx,MAX_POINTS + call translate_points + + call draw_faces + + call clear_screen_buffer + + add [angle_x],2 + add [angle_y],3 + add [angle_z],1 + + jmp still + +key: + mov eax,2 + mcall + jmp still +button: + mov eax,17 + mcall + cmp ah,1 + jne still +exit: + mov eax,-1 + mcall + +;Draw window +draw_window: + mcall 12, 1 ;Start window redraw + + mcall 48, 4 + + lea ecx,[100*65536+SCREEN_Y+4+eax]; [y start] *65536 + [y size] + [skin_height] + xor eax,eax ;Draw window + mov ebx,100*65536+(SCREEN_X+9) ;x start*65536+x size + mov edx,0x54000000 ;0x03 use skinned window + mov edi,title + mcall + + mcall 12, 2 ;End window redraw + + ret + +title db '3D Cube Sample',0 + + +; Draw faces procedure + +draw_faces: + + mov esi,link + mov ecx,MAX_TRIANGLES +df_draw: + push ecx + mov ecx,3 + mov edi,@@tx1 ;bp +df_get_point: + movzx ebx, byte [esi] + movzx eax, word [object_translated + ebx*4] + stosd + movzx eax, word [object_translated + ebx*4 + 2] + stosd + inc esi + dec ecx + jnz df_get_point + + mov eax,[@@ty1] + sub eax,[@@ty3] + mov ebx,[@@tx2] + sub ebx,[@@tx1] + imul ebx + push eax + mov eax,[@@tx1] + sub eax,[@@tx3] + mov ebx,[@@ty2] + sub ebx,[@@ty1] + imul ebx + pop ebx + sub ebx,eax + jge df_next + + movzx eax, byte [esi] + + mov [@@xcol], eax + + call filled_triangle +df_next: + inc esi + pop ecx + dec ecx + jnz df_draw + ret + +;modify +;include graphlib.asm + +clear_screen_buffer: + +;outscrbuf + mcall 48, 4 + mov ebx,scrbuf + mov ecx,SCREEN_X*65536+SCREEN_Y + lea edx,[5*65536+eax] + mov eax,7 + mcall + +;White background + mov edi,scrbuf + mov ecx,(SCREEN_X*SCREEN_Y*3)/4 + mov eax,0xffffffff + cld + rep stosd + + ret + +;include triangle.asm +; Mikolaj Felix 14/5/2001 +; mfelix@polbox.com + +;filled trangle procedure + +align 4 +@@tx1 dd 0 +@@ty1 dd 0 +@@tx2 dd 0 +@@ty2 dd 0 +@@tx3 dd 0 +@@ty3 dd 0 +@@xcol dd 0 + +@@dx12 dd 0 +@@dx13 dd 0 +@@dx23 dd 0 + +filled_triangle: + + mov eax,[@@xcol] ;trnsforming color + mov bl,al ;byte bbbggrrx + mov dl,al ;to 3 byte + mov dh,al ;bbbxxxxx ggxxxxxx rrxxxxxx + and dh,00000001b + + and al,11100000b + and bl,00011000b + and dl,00000110b + shl bl,3 + shl dl,5 + + cmp dh,1 + jne no_bitup + or al,00011111b + or bl,00111111b + or dl,00111111b +no_bitup: + + shl eax,8 ;puck colors + mov al,bl + shl eax,8 + mov al,dl + mov dword [@@rgb],eax + + mov eax,[@@ty1] + cmp eax,[@@ty3] + jb ft_check1 + + xchg eax,[@@ty3] + mov [@@ty1],eax + + mov eax,[@@tx1] + xchg eax,[@@tx3] + mov [@@tx1],eax +ft_check1: + mov eax,[@@ty2] + cmp eax,[@@ty3] + jb ft_check2 + + xchg eax,[@@ty3] + mov [@@ty2],eax + + mov eax,[@@tx2] + xchg eax,[@@tx3] + mov [@@tx2],eax +ft_check2: + mov eax,[@@ty1] + cmp eax,[@@ty2] + jb ft_check3 + + xchg eax,[@@ty2] + mov [@@ty1],eax + + mov eax,[@@tx1] + xchg eax,[@@tx2] + mov [@@tx1],eax +ft_check3: + + mov ebx,[@@ty2] + sub ebx,[@@ty1] + jnz ft_dx12_make + + mov [@@dx12],dword 0 + jmp ft_dx12_done +ft_dx12_make: + mov eax,[@@tx2] + sub eax,[@@tx1] + shl eax,7 + cdq + idiv ebx + mov [@@dx12],eax ; dx12 = (x2-x1)/(y2-y1) +ft_dx12_done: + + mov ebx,[@@ty3] + sub ebx,[@@ty1] + jnz ft_dx13_make + + mov [@@dx13],dword 0 + jmp ft_dx13_done +ft_dx13_make: + mov eax,[@@tx3] + sub eax,[@@tx1] + shl eax,7 + cdq + idiv ebx + mov [@@dx13],eax ; dx13 = (x3-x1)/(y3-y1) +ft_dx13_done: + + mov ebx,[@@ty3] + sub ebx,[@@ty2] + jnz ft_dx23_make + + mov [@@dx23],dword 0 + jmp ft_dx23_done +ft_dx23_make: + mov eax,[@@tx3] + sub eax,[@@tx2] + shl eax,7 + cdq + idiv ebx + mov [@@dx23],eax ; dx23 = (x3-x2)/(y3-y2) +ft_dx23_done: + + mov eax,[@@tx1] + shl eax,7 + mov ebx,eax + + mov ecx,[@@ty1] +ft_loop1: + + pushad + + mov [@@ly],ecx + mov edx,ebx + shr edx,7 + mov [@@lx2],edx + mov edx,eax + shr edx,7 + mov [@@lx1],edx + mov eax,[@@xcol] + mov [@@lcol],eax + call horizontal_line + + popad + + add eax,[@@dx13] + add ebx,[@@dx12] + inc ecx + cmp ecx,[@@ty2] + jb ft_loop1 + + + mov ebx,[@@tx2] + shl ebx,7 + mov ecx,[@@ty2] +ft_loop2: + + pushad + + mov [@@ly],ecx + mov edx,ebx + shr edx,7 + mov [@@lx2],edx + mov edx,eax + shr edx,7 + mov [@@lx1],edx + mov eax,[@@xcol] + mov [@@lcol],eax + call horizontal_line + + popad + + add eax,[@@dx13] + add ebx,[@@dx23] + inc ecx + cmp ecx,[@@ty3] + jb ft_loop2 + + ret + +;horizontal line subproc + +align 4 +@@lx1 dd 0 +@@lx2 dd 0 +@@ly dd 0 +@@lcol dd 0 + +@@rgb dd 0 + +horizontal_line: + + mov ecx,[@@lx1] + sub ecx,[@@lx2] + ja x12 + je ext +; ret + neg ecx + mov edi,3 + jmp xx +x12: + mov edi,-3 + jmp xx +ext: + mov ecx,-1 ;1 +; sub ebp,3 +xx: + mov eax,[@@ly] + mov ebx,SCREEN_X ;320 + mul ebx + add eax,[@@lx1] + lea ebp,[eax*3-3] ; for delete white dots + add ecx,2 +loo: + + mov eax,dword [@@rgb] + mov bl,al + shr eax,8 ;puck colors + + mov byte [scrbuf+ebp],ah + mov byte [scrbuf+ebp+1],al + mov byte [scrbuf+ebp+2],bl + add ebp,edi + dec ecx + jnz loo + + ret + +;include fixed3d.asm +; Mikolaj Felix 25/5/2001 +; mfelix@polbox.com + +;------------------------------------------------------------ +; ds:si - offset to angles +; ds:di - offset to 3d points +; cx - number of points +;------------------------------------------------------------ + +@@sin_x dw 0 +@@cos_x dw 0 +@@sin_y dw 0 +@@cos_y dw 0 +@@sin_z dw 0 +@@cos_z dw 0 + +@@px equ word [edi] +@@py equ word [edi+2] +@@pz equ word [edi+4] + +rotate_points: + + push edi + mov edi,@@sin_x + mov edx,3 +rp_sin_cos: + mov ebx, [esi] + and ebx,511 + mov ax,word [sin_table+ebx*2] + mov word [edi],ax + mov ax,word [cos_table+ebx*2] + mov word [edi+2],ax + + add esi,2 + add edi,4 + dec edx + jnz rp_sin_cos + pop edi + +rp_rotate: + + ; rotate around x-axis + + mov ax,@@py + imul [@@cos_x] + mov bx,ax + mov si,dx + + mov ax,@@pz + imul [@@sin_x] + sub bx,ax + sbb si,dx + shrd bx,si,14 + push bx + + mov ax,@@py + imul [@@sin_x] + mov bx,ax + mov si,dx + + mov ax,@@pz + imul [@@cos_x] + add bx,ax + adc si,dx + shrd bx,si,14 + + pop @@py + mov @@pz,bx + + ; rotate around y-axis + + mov ax,@@px + imul [@@cos_y] + mov bx,ax + mov si,dx + + mov ax,@@pz + imul [@@sin_y] + sub bx,ax + sbb si,dx + shrd bx,si,14 + push bx + + mov ax,@@px + imul [@@sin_y] + mov bx,ax + mov si,dx + + mov ax,@@pz + imul [@@cos_y] + add bx,ax + adc si,dx + shrd bx,si,14 + + pop @@px + mov @@pz,bx + + ; rotate around z-axis + + mov ax,@@px + imul [@@cos_z] + mov bx,ax + mov si,dx + + mov ax,@@py + imul [@@sin_z] + sub bx,ax + sbb si,dx + shrd bx,si,14 + push bx + + mov ax,@@px + imul [@@sin_z] + mov bx,ax + mov si,dx + + mov ax,@@py + imul [@@cos_z] + add bx,ax + adc si,dx + shrd bx,si,14 + + pop @@px + mov @@py,bx + + add edi,6 + dec ecx + jnz rp_rotate + + ret + +;------------------------------------------------------------ +; ds:si - offset to 3d points +; es:di - offset to 2d points +; cx - number of points +;------------------------------------------------------------ + + mx dw 0 + my dw 0 + +translate_points: + pushad + mov eax,37 + mov ebx,1 + mcall + mov ebx,eax + shr eax,16 + and ebx,0xffff + cmp ax,SCREEN_X + jna x_n + mov ax,0 ;SCREEN_X +x_n: + cmp bx,SCREEN_Y + jna y_n + mov bx,0 ;SCREEN_Y +y_n: + mov [mx],ax + mov [my],bx + popad + + movzx ebx,word [esi+4] + mov ax,[my] + cmp ax,0 + jng no_m + shl ax,3 + add bx,ax +no_m: + add bx,256 ; Z factor (zoom) + + movsx eax,word [esi] + shl eax,8 + cdq + idiv ebx + add eax,(SCREEN_X/2) ;160 ;X factor (center X) + stosw + + movsx eax,word [esi+2] + shl eax,8 + cdq + idiv ebx + add eax,(SCREEN_Y/2) ;100 ;Y factor (center Y) + stosw + + add esi,6 + dec ecx + jnz translate_points + ret + +fixed_point_const dd 16384.0 +inc_angle dd 0.01227184630309 ; pi/256 + +angle_x dw 0 +angle_y dw 0 +angle_z dw 0 + +object dw -50,-50,-50, 50,-50,-50, 50,50,-50, -50,50,-50 + dw -50,-50, 50, 50,-50, 50, 50,50, 50, -50,50, 50 + +link: + db 0,1,2,10000011b, 0,2,3,10000011b ;purpure side + db 5,4,7,00000111b, 5,7,6,00000111b ;soft-red side + db 1,5,6,00011000b, 1,6,2,00011000b ;soft-lime side + db 4,0,3,11100001b, 4,3,7,11100001b ;soft-blue side + db 4,5,1,00011111b, 1,0,4,00011111b ;yellow side + db 3,2,6,00000000b, 3,6,7,00000000b ;black side + +sin_table: +rw 512 +cos_table: +rw 512 + +object_rotated: +rw MAX_POINTS*3 +object_translated: +rw MAX_POINTS*2 + +scrbuf: +I_END: diff --git a/programs/demos/3dcube2/trunk/Tupfile.lua b/programs/demos/3dcube2/Tupfile.lua similarity index 69% rename from programs/demos/3dcube2/trunk/Tupfile.lua rename to programs/demos/3dcube2/Tupfile.lua index f5bd68245..58f836a53 100644 --- a/programs/demos/3dcube2/trunk/Tupfile.lua +++ b/programs/demos/3dcube2/Tupfile.lua @@ -1,5 +1,5 @@ if tup.getconfig("NO_FASM") ~= "" then return end -HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR") +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_fasm.lua") add_include(tup.getvariantdir()) diff --git a/programs/demos/3dcube2/trunk/build.bat b/programs/demos/3dcube2/build.bat similarity index 100% rename from programs/demos/3dcube2/trunk/build.bat rename to programs/demos/3dcube2/build.bat diff --git a/programs/demos/3detx60b/trunk/3DETX60B.ASM b/programs/demos/3detx60b/3DETX60B.ASM similarity index 95% rename from programs/demos/3detx60b/trunk/3DETX60B.ASM rename to programs/demos/3detx60b/3DETX60B.ASM index 4b0f68046..05c375e40 100644 --- a/programs/demos/3detx60b/trunk/3DETX60B.ASM +++ b/programs/demos/3detx60b/3DETX60B.ASM @@ -1,2540 +1,2545 @@ -; -; 3D ТЕКСТУРИРОВАНЫЙ ДВИЖОК 3D TEXTURED ENGINE -; АВТОР: Павлюшин Евгений AUTOR: Pavlushin Evgeni -; -; Компилируется с помощью FASM ассемблера для MenuetOS -; Compile with FASM assembler for MenuetOS -; -; 20.11.04 Fast point calc & triangle draw -; Little matrix no (trangle massive) -; Fast triangle, del triangle out of screen -; 16.12.04 Fast triangle with MMX -; 20.12.04 Out triangle fatal bug's deleted, "black zones" deleted -; Matrix move support -; 24.12.04 Fast keyboard scanning -; Z-ground level map work -; Texture draw correction deleted "black zones" -; 04.01.05 Moveing texture -; 05.01.05 Water dynamic texture -; 06.01.05 Texture pack (many textures in one file) -; 07.01.05 Z-sorting -; 08.01.05 Triangle good clipping calculating (speed up) -; 4 byte Z-sorting, more dynamic of water -; 09.01.05 Texture map from 256 color bmp file -; Pixel Z-buffer, good speed! -; 21.01.05 Models buffer add. -; 25.01.05 Models buffer update, Add 2 new models. -; 29.01.05 Dynamic model array -; 01.02.05 1 picture MipMap calculation -; 04.02.05 All picture MipMap calculation, proc speed up. -; Simple Triangel MipMap chose. -; 05.02.05 Normal Triangel MipMap chose. -; 12.02.05 Best QUALITY of Textured TRIANGEL! -; 13.02.05 add new models. All camera axis calculating -; 16.02.05 Simple model turning -; 17.02.05 Advanced model turning, model tmpoints massive deleted -; New map size 128, add new models. -; 25.02.05 Left side clipping bug deleted -; 26.02.05 Optimization of textured line algorythm -; 24.04.05 Test pixel z-buffer it's work. Use new textri algorythm -; 30.04.05 Fast Y-clipping - -use32 - -SCREEN_X equ 800 ;320 ;Screen size easy change -SCREEN_Y equ 600 ;200 -DSCREEN_X equ SCREEN_X-1 ;320 ;For triangle clipping -DSCREEN_Y equ SCREEN_Y-1 ;200 -MATRIX_XSIZE equ 64;32;64;100 ;Ground matrix size -MATRIX_YSIZE equ 64;32;64;100 -SECTOR_SIZE equ 100 ;Size of matrix sector -MAP_XSIZE equ 128 ;Rezolution of map file -MAP_YSIZE equ 128 - - org 0x0 - db 'MENUET01' ; 8 байт интдефикатор - dd 0x01 ; версия заголовка - dd START ; адресс начала кода - dd I_END ; размер программы - dd I_END+(SCREEN_X*SCREEN_Y*3+50000) ; размер памяти для прогграммы - dd I_END+(SCREEN_X*SCREEN_Y*3+10000) ; esp - dd 0x0 , 0x0 ; I_Param , I_Icon - -include 'lang.inc' -include '..\..\..\macros.inc' -include 'ascgl.inc' -include 'ascl.inc' - -START: ; начало приложения -; Draw window at first - call draw_window - - ; Decoding groud texture and ground level map - gif_hash_offset = gif_hash_area - ;texture's - giftoimg texpack_gif,texpack_img-8 - ;ground level map - giftoimg gif_file_area5,glm_img_area - -;get 8bitmap from 256 colors bmp file - mov ebp,128;64 - mov esi,0x043a+128*128-4;64*64-4 - sub esi,128;64 - mov edi,0 - mov ecx,128;64 -texmap_unp: - mov al,[bmp_texmap+esi] - mov [img_area+edi],al - inc esi - inc edi - dec ecx - jnz texmap_unp - mov ecx,128;64 - sub esi,256;128 - dec ebp - jnz texmap_unp - - -;Unpack textures - - mov esi,texpack_img - mov edi,texture_img - mov edx,16 - mov ecx,16 -tpuckloop: - pushad - call unpuck - popad - add esi,32*3 - add edi,4095 - dec ecx - jnz tpuckloop - add esi,31*32*16*3 - mov ecx,16 - dec edx - jnz tpuckloop - -; -; Unpuck one texture procendure -; - jmp skip_unpuck -unpuck: - mov ecx,32 - mov edx,32 -tunploop: - mov ax,[esi] - mov [edi],ax - mov al,[esi+2] - mov [edi+2],al - add esi,3 - add edi,3 - dec ecx - jnz tunploop - mov ecx,32 - add esi,(32*16*3)-(32*3) - dec edx - jnz tunploop - ret -skip_unpuck: - - -;calculating all mipmaps - mov esi,texture_img - mov ecx,256 ;quantity of textures -mmaploop: - mov ebp,32 ;max mipmap texture - pusha - call texgen - popa - add esi,4095 ;next mipmap block - dec ecx - jnz mmaploop - - jmp skip_texgen - -;******************************** -; MIPMAP TEXTURE GENERATION -; -; in put: -; esi - offset to texture -; ebp - mipmap max size (32 for this sample) -;******************************** - -texgen: - push esi - mov eax,ebp - imul eax,ebp - imul eax,3 - add eax,esi - mov edi,eax - - mov eax,ebp - shr eax,1 - mov dh,al - mov dl,al - mov cl,dl - - mov ecx,ebp - mov eax,ebp - shl eax,1 - add ecx,eax - -miploop: -; Red - xor bx,bx ;for add - xor ax,ax ;for add - mov al,[esi+0] - add bx,ax - mov al,[esi+3+0] - add bx,ax - mov al,[esi+ecx+0] - add bx,ax - mov al,[esi+ecx+3+0] - add bx,ax - shr bx,2 ;/4 - mov [edi+0],bl -;Green - xor bx,bx ;for add - xor ax,ax ;for add - mov al,[esi+1] - add bx,ax - mov al,[esi+3+1] - add bx,ax - mov al,[esi+ecx+1] - add bx,ax - mov al,[esi+ecx+3+1] - add bx,ax - shr bx,2 ;/4 - mov [edi+1],bl -;Blue - xor bx,bx ;for add - xor ax,ax ;for add - mov al,[esi+2] - add bx,ax - mov al,[esi+3+2] - add bx,ax - mov al,[esi+ecx+2] - add bx,ax - mov al,[esi+ecx+3+2] - add bx,ax - shr bx,2 ;/4 - mov [edi+2],bl - - add esi,6 - add edi,3 - dec dl - jnz miploop - mov ax,bp - shr ax,1 - mov dl,al - add esi,ecx - dec dh - jnz miploop - pop esi - - mov eax,ebp - imul eax,ebp - imul eax,3 - add esi,eax - shr ebp,1 - cmp ebp,1 - jne texgen - ret -skip_texgen: - - -;Copy dynamic water texture -; ???????????? - mov ecx,32*32*3 - mov esi,texture_img+4095 ;32*32*3 - mov edi,texture_limg - cld - rep movsb - - ; init sine wave for dynamic water texture - finit - mov edi,sinwave - mov ecx,32;256 - isv_loop: - fld [angle] - fld st - fsin - fmul [mul_wave] - fistp word [edi] - fadd [d_angle] - fstp [angle] - add edi,2 - dec ecx - jnz isv_loop - - -;Initalize keyboard - mov eax,66 - mov ebx,1 - mov ecx,1 - mcall - - mov eax,26 - mov ebx,2 - mov ecx,1 - mov edx,keymap+100 - mcall - -;Build triangle matrix - mov esi,points - mov eax,-(MATRIX_XSIZE/2)*SECTOR_SIZE - mov ebx,-(MATRIX_YSIZE/2)*SECTOR_SIZE - mov ebp,img_area+8 -loomat: - mov [esi],eax ;x-set - mov [esi+4],ebx ;y-set - mov [esi+8],ecx ;z-set - add ebp,3 - add esi,4*3 - add eax,SECTOR_SIZE - cmp eax,((MATRIX_YSIZE/2)+1)*SECTOR_SIZE - jnge loomat - mov eax,-(MATRIX_YSIZE/2)*SECTOR_SIZE - add ebx,SECTOR_SIZE - cmp ebx,((MATRIX_XSIZE/2)+1)*SECTOR_SIZE - jnge loomat - -; Create z-ground good algorythm not already yet (64x64 map) - mov esi,glm_img_area+8 - mov edi,ground_level_map -loox: -; draw_courner_points - mov eax,[esi] - call get_z -; mov [edi],eax - - mov eax,[esi+((MATRIX_XSIZE-1)*4)] - call get_z -; mov [edi+((MATRIX_XSIZE)*4)],eax - - mov eax,[esi+(((MATRIX_XSIZE)*(MATRIX_YSIZE-1)+1)*4)] - call get_z -; mov [edi+(((MATRIX_XSIZE+1)*(MATRIX_YSIZE)-0)*4)],eax - - mov eax,[esi+(((MATRIX_XSIZE)*(MATRIX_YSIZE)-1)*4)] - call get_z -; mov [edi+(((MATRIX_XSIZE+1)*(MATRIX_YSIZE+1)-1)*4)],eax - - - jmp skip_gz -get_z: - xor ebx,ebx - xor ecx,ecx - mov bl,al - add ecx,ebx - mov bl,ah - add ecx,ebx - shr eax,16 - mov bl,al - add ecx,ebx - mov eax,ecx - xor edx,edx - mov ebx,3 - cdq - div ebx - neg eax - ret -skip_gz: - -; z-ground livel facking method (65x65 map) - mov esi,glm_img_area+8 - mov edi,ground_level_map - mov ebp,(MAP_XSIZE+1)*(MAP_YSIZE+1) -looglm: - mov eax,[esi] -; and eax,0x000000ff - call get_z - mov [edi],eax - add esi,3 - add edi,1 - dec ebp - jnz looglm - -;Fill model massive - mov ecx,[model_mas_start] - imul ecx,8 - add ecx,4 - mov esi,model_mas_start - mov edi,model_mas - cld - rep movsd - - jmp skip_moddata -model_mas_start: -dd 12 ;quantity of models -dd 0,0,-150,0,0,0,0,bunker -dd 60,-250,-190,0,0,64,0,tank -dd 0,180,-150,0,0,0,0,cannon -dd 0,480,-150,0,0,0,0,outpost -dd 260,60,-150,0,0,0,0,bunker -dd 60,260,-150,0,0,0,0,outpost -dd 210,410,-150,0,0,0,0,cannon -dd 160,260,-150,0,0,0,0,tree -dd 100,-360,-150,0,0,192,0,gqfa -dd 10,580,-150,0,0,0,0,repear -dd 460,160,-100,0,0,0,0,red_flag -dd 60,360,-170,0,0,40,0,cannon -skip_moddata: - - -;Main loop -still: ; основной цикл - mov eax,11 ; проверка состояния окна - mcall - - cmp eax,1 ; окно сдвинули его нужно перерисовать - je red - cmp eax,2 ; нажата клавиша на клавиатуре - je key - cmp eax,3 ; нажата кнопка в окне - je button - -; delay 10 -; cmp [autorot],0 ;frize no fps show when autorot off -; je still - -cycle: - call clrscr ; clear screen buffer - call clrzbuf ; clear z-buffer - call render_scene ; calculating scene - call dispimg ; show buffer - - fps_show_frequency=0 - fps 10,10,cl_White,cl_Black - - -;turn model on z-axis - inc dword [model_mas+4*6] - and dword [model_mas+4*6],011111111b - - -; Sin wave dynamic texture for water -; jmp ndt - xor edi,edi - mov dx,32 - mov bp,word [sin_pos] -dp_ver: - mov cx,32 ;320 - mov si,word [sin_pos] -dp_hor: - and ebp,0000ffffh - mov ax,word [sinwave+ebp] - add ax,cx - and ax,31 - - and esi,0000ffffh - mov bx,word [sinwave+esi] - add bx,dx - and bx,31 - shl bx,5 - add bx,ax - - push bx - imul bx,3 - and ebx,0000ffffh - mov ax,[texture_limg+ebx] - mov [texture_img2+edi],ax - mov al,[texture_limg+ebx+2] - mov [texture_img2+edi+2],al - pop bx - - add edi,3 - add si,2 - and si,63;511 - - dec cx - jnz dp_hor - add bp,2 - and bp,63;511 - dec dx - jnz dp_ver - -; update sine position for next frame - add word [sin_pos],2 - and word [sin_pos],63;511 - -;Move water texture - jmp ndt - mov esi,texture_limg - mov ecx,32*32-1 -loodt: - mov al,byte [esi] - mov bl,byte [esi+1] - mov dl,byte [esi+2] - mov ah,byte [esi+3] - mov bh,byte [esi+4] - mov dh,byte [esi+5] - mov byte [esi],ah - mov byte [esi+1],bh - mov byte [esi+2],dh - mov byte [esi+3],al - mov byte [esi+4],bl - mov byte [esi+5],dl - add esi,3 - dec ecx - jnz loodt -ndt: - -;Creat mipmap pack for dynamic texture - mov ebp,32 - mov esi,texture_img+4095 - call texgen - - - mov eax,4 ; function 4 : write text to window - mov ebx,8*65536+8 ; [x start] *65536 + [y start] - mov ecx,0x0000ff00 ; font 1 & color ( 0xF0RRGGBB ) - mov edx,keymap ; pointer to text beginning - mov esi,100 ; text length - mcall - add edx,100 - add ebx,10 - mov esi,60 ; text length - mov ecx,0x00dddddd ; font 1 & color ( 0xF0RRGGBB ) - mcall - mov edx,usemap - mov esi,60 ; text length - mov ecx,0x0000ff00 - mcall - jmp rx - ;01234567890123456789012345678901234567890123456789 -usemap db ' E wer u [] asd zxc ' - db ' ' -rx: - - cmp byte [keymap+1],0 - je n_esc - jmp exit -n_esc: - - cmp byte [keymap+22],0 - je n_u - mov [Xangle],0 - mov [Yangle],0 - mov [Zangle],0 -n_u: - -; t,y - mipmap cntrol - cmp byte [keymap+20],0 - je n_t - inc [mipzoom] -n_t: - cmp byte [keymap+21],0 - je n_y - dec [mipzoom] -n_y: - cmp byte [keymap+23],0 - je n_i - mov byte [keymap+23],0 ; reset key - cmp [mipmapwork],1 - je i_1 -i_0: - mov [mipmapwork],1 - jmp n_i -i_1: - mov [mipmapwork],0 -n_i: - - - cmp byte [keymap+26],0 - je n_lsk - add [Xcam],1 -n_lsk: - cmp byte [keymap+27],0 - je n_rsk - sub [Xcam],1 -n_rsk: - cmp byte [keymap+18],0 - je n_e - add [Yangle],1 -n_e: - cmp byte [keymap+45],0 - je n_x - sub [Yangle],1 -n_x: - cmp byte [keymap+31],0 - je n_s - add [Xangle],1 -n_s: - cmp byte [keymap+32],0 - je n_d - sub [Xangle],1 -n_d: - cmp byte [keymap+44],0 - je n_z - add [Zangle],1 -n_z: - cmp byte [keymap+46],0 - je n_c - sub [Zangle],1 -n_c: - cmp byte [keymap+17],0 - je n_w - add [Zcam],25 ;250 -n_w: - cmp byte [keymap+19],0 - je n_r - sub [Zcam],25 ;250 -n_r: - - cmp byte [keymap+75],0 - je n_lk - add [Zcamangle],1 - and [Zcamangle],011111111b -n_lk: - cmp byte [keymap+77],0 - je n_rk - sub [Zcamangle],1 - and [Zcamangle],011111111b -n_rk: - - cmp byte [keymap+79],0 - je n_num1 - add [Xcamangle],1 - and [Xcamangle],011111111b -n_num1: - cmp byte [keymap+81],0 - je n_num3 - sub [Xcamangle],1 - and [Xcamangle],011111111b -n_num3: - cmp byte [keymap+71],0 - je n_num7 - add [Ycamangle],1 - and [Ycamangle],011111111b -n_num7: - cmp byte [keymap+73],0 - je n_num9 - sub [Ycamangle],1 - and [Ycamangle],011111111b -n_num9: - - - - cmp byte [keymap+30],0 - je n_a - mov byte [keymap+30],0 ; reset key - cmp [autorot],1 - je a_1 -a_0: - mov [autorot],1 - jmp n_a -a_1: - mov [autorot],0 -n_a: - -; for camera -; mov ebx,[Xcamangle] -; call GetSinCos -; mov [Xcamsin],eax -; mov [Xcamcos],ebx - -; mov ebx,[Ycamangle] -; call GetSinCos -; mov [Ycamsin],eax -; mov [Ycamcos],ebx - - mov ebx,[Zcamangle] - call GetSinCos - mov [Zcamsin],eax - mov [Zcamcos],ebx - - mov eax,[Zcamsin] - mov ebx,[Zcamcos] -; mov ecx,[Xcamsin] -; mov edx,[Xcamcos] -; mov esi,[Ycamsin] -; mov edi,[Ycamcos] - - sar eax,4 - sar ebx,4 -; sar ecx,4 -; sar edx,4 -; sar esi,4 -; sar edi,4 - - cmp byte [keymap+72],0 - je n_uk - sub [Xcam],eax - sub [Ycam],ebx - -; sub [Zcam],ecx -; sub [Ycam],edx - -; sub [Xcam],esi -; add [Zcam],edi - -n_uk: - cmp byte [keymap+80],0 - je n_dk - add [Xcam],eax - add [Ycam],ebx - -; add [Zcam],ecx -; add [Ycam],edx - -; add [Xcam],esi -; sub [Zcam],edi - -n_dk: - - xor ebp,ebp -move_test: - cmp [Xcam],-SECTOR_SIZE/2 - jnl ok1 - add [Xcam],SECTOR_SIZE - dec [Xmap] - jmp move_test -ok1: - cmp [Xcam],SECTOR_SIZE/2 - jng ok2 - sub [Xcam],SECTOR_SIZE - inc [Xmap] - jmp ok1 -ok2: - cmp [Ycam],-SECTOR_SIZE/2 - jnl ok3 - add [Ycam],SECTOR_SIZE - dec [Ymap] - jmp ok2 -ok3: - cmp [Ycam],SECTOR_SIZE/2 - jng ok4 - sub [Ycam],SECTOR_SIZE - inc [Ymap] - jmp ok3 -ok4: - - and [Xangle],011111111b - and [Yangle],011111111b - and [Zangle],011111111b - - jmp still - - red: ; redraw - call draw_window - jmp still - - key: ; key - mov eax,2 ; just read it and ignore - mcall - - shr eax,8 - and eax,0xff - mov ah,al - - mov ebx,0 - mov bl,ah - cmp bl,224 - je noisa ; ignore Ext code - cmp bl,170 - je noisa ; ignore Key Up code - cmp bl,128 - ja isa - mov [keymap+ebx],byte 'X' ; set press marker to key id - jmp noisa -isa: - sub bl,128 - mov [keymap+ebx],byte 0 ; reset key marker -noisa: - jmp n_a - - jmp still ; cycle - - button: ; button - mov eax,17 ; get id - mcall - cmp ah,1 - jz exit - jmp cycle - -exit: - or eax,-1 - mcall - -; ********************************************* -; ******* WINDOW DEFINITIONS AND DRAW ******** -; ********************************************* - -draw_window: - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,1 ; 1, start of draw - mcall - ; DRAW WINDOW - mov eax,0 ; function 0 : define and draw window - mov ebx,0*65536+SCREEN_X-1 ; [x start] *65536 + [x size] - mov ecx,0*65536+SCREEN_Y-1 ; [y start] *65536 + [y size] - mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl - mov esi,0x005080d0 ; color of grab bar RRGGBB,8->color gl - mov edi,0x005080d0 ; color of frames RRGGBB - mcall - ; WINDOW LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,8*65536+8 ; [x start] *65536 + [y start] - mov ecx,0x10ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelt ; pointer to text beginning - mov esi,labellen-labelt ; text length - mcall - - mov eax,12 - mov ebx,2 - mcall - ret - -dispimg: - mov eax,7 - mov ebx,I_END ;zbuffer - mov ecx,SCREEN_X*65536+SCREEN_Y - xor edx,edx ;0*65536+0 - mcall -; ret - - mov eax,8 - mov ebx,(SCREEN_X-30)*65536+20 - mov ecx,10*65536+20 - mov edx,1 - mov esi,0x0000aa00 - mcall - ret - -clrscr: ; clear screen buffer -; cld -; mov edi,I_END -; xor eax,eax -; mov ecx,SCREEN_X*SCREEN_Y*3/4 -; rep stosd -; ret - -; clear screen buffer with MMX technology +1,5 fps - mov edi,I_END - mov ecx,SCREEN_X*SCREEN_Y*3/32 - xor eax,eax - movd mm0,eax - movd mm1,eax - movd mm2,eax - movd mm3,eax -csloo: - movq qword [edi],mm0 - movq qword [edi+8],mm1 - movq qword [edi+16],mm2 - movq qword [edi+24],mm3 - add edi,32 - dec ecx - jnz csloo - ret - -clrzbuf: ; clear zbuf - cld - mov edi,zbuffer - mov eax,-1 - mov ecx,SCREEN_X*SCREEN_Y*3/4 - rep stosd - ret - - -; mov [@@atx1],dword 0xffffffff -; mov [@@aty1],dword 0xffffffff -; movq mm0,qword [@@atx1] -; movq mm1,qword [@@atx1] -; movq mm2,qword [@@atx1] -; movq mm3,qword [@@atx1] -;czbloo: -; movq qword [edi],mm0 -; movq qword [edi+8],mm1 -; movq qword [edi+16],mm2 -; movq qword [edi+24],mm3 -; add edi,32 -; dec ecx -; jnz czbloo - ret - -@@atx1: dd 0 -@@aty1: dd 0 - -;=========================================================================== -; -; 3D-system example. Use the following formulas to rotate a point: -; -; Rotate around x-axis -; Y = Y * COS(xang) - Z * SIN(xang) / 256 -; Z = Y * SIN(xang) + Z * COS(xang) / 256 -; -; Rotate around y-axis -; X = X * COS(yang) - Z * SIN(yang) / 256 -; Z = X * SIN(yang) + Z * COS(yang) / 256 -; -; Rotate around z-axis -; X = X * COS(zang) - Y * SIN(zang) / 256 -; Y = X * SIN(zang) + Y * COS(zang) / 256 -; -; Divide by 256 coz we have multiplyd our sin values with 256 too. -; This example isn't too fast right now but it'll work just fine. -; -;=========================================================================== - -;*************************************************************************** -; \\\ MAIN 3D LOOP /// -; ****************** -render_scene: - -;******************** -; Turn matrix points -;******************** - - cmp [autorot],0 - je no_autorot - call UpdateAngles ; Calculate new angles -no_autorot: - call SetRotation ; Find sine & cosine of those angles - - mov edi,tpoints - mov esi,points - mov [mapoff],-1 ;-1 at start - mov ebp,[Ymap] - imul ebp,MAP_XSIZE+1 - mov eax,[Xmap] - add ebp,eax - - mov ecx,(MATRIX_XSIZE+1)*(MATRIX_YSIZE+1) -ShowLoop: - push ecx - push esi - mov eax,[esi] - sub eax,[Xcam] - mov [X],eax - mov eax,[esi+4] - sub eax,[Ycam] - mov [Y],eax - mov eax,[ebp+ground_level_map] ;color - and eax,0x000000ff - sub eax,[Zcam] - mov [Z],eax - push ebp - push edi - call TranslatePoint ; Rotates the point using above formulas - pop edi - mov [edi],ebp ;x - mov [edi+4],eax ;y - mov eax,[Z] ;z - add eax,[Zoff] - mov [edi+8],eax - pop ebp - pop esi - pop ecx - - add esi,4*3 ;next in point - add edi,4*3 ;next out point - - inc [mapoff] - cmp [mapoff],MATRIX_XSIZE+1 - jne no_shift_glm - mov [mapoff],dword 0 - add ebp,(MAP_XSIZE-MATRIX_XSIZE) -no_shift_glm: - add ebp,1 - - dec ecx - jnz ShowLoop - - -; Show, how many polygons on screen. - outcount [massize],50,10,cl_White,8*65536 - - -;***************** -; out triangles -;***************** - - mov [mapoff],-1 ;-1 at start - mov [massize],0 ;restet triangle massive counter - - mov ebp,[Ymap] - imul ebp,MAP_XSIZE;64;3*64 ;MAP_XSIZE - mov eax,[Xmap] - add ebp,eax - - mov edi,tpoints - mov ecx,MATRIX_YSIZE ;64 -lootpy: - push ecx - mov ecx,MATRIX_XSIZE ;64 -lootpx: -;draw four angle (two triangles) - -Z_MAX = 10 ;maximal z range for triangles - -; get texture offset at start - inc [mapoff] - cmp [mapoff],MATRIX_XSIZE - jne no_shift - mov [mapoff],dword 0 - add ebp,(MAP_XSIZE-MATRIX_XSIZE) -no_shift: - xor eax,eax - mov al,[ebp+img_area];+8] - inc ebp - imul eax,4095;32*32*3 - add eax,texture_img - mov ebx,eax - -;first triangle - mov eax,[edi+8] ;z1 - cmp eax,Z_MAX - jl no_add1 - mov [@@tz1],eax - mov eax,[edi+8+12] ;z2 - cmp eax,Z_MAX - jl no_add1 - mov [@@tz2],eax - mov eax,[edi+8+(4*3*(MATRIX_XSIZE+2))] ;z3 - cmp eax,Z_MAX - jl no_add1 - mov [@@tz3],eax - - cmp dword [edi],SCREEN_X - ja p11 - cmp dword [edi+4],SCREEN_Y - jna yes_add1 -p11: - cmp dword [edi+12],SCREEN_X - ja p12 - cmp dword [edi+4+12],SCREEN_Y - jna yes_add1 -p12: - cmp dword [edi+(4*3*(MATRIX_XSIZE+2))],SCREEN_X - ja p13 - cmp dword [edi+4+(4*3*(MATRIX_XSIZE+2))],SCREEN_Y - jna yes_add1 -p13: - jmp no_add1 -yes_add1: - - movq mm0,qword [edi] ;x1 - movq mm1,qword [edi+12] ;x2 - movq mm2,qword [edi+(4*3*(MATRIX_XSIZE+2))] ;x3 - movq qword [@@tx1],mm0 - movq qword [@@tx2],mm1 - movq qword [@@tx3],mm2 - - mov eax,ebx;+1 shl 31;[ebp] - mov [@@tex_off],eax ;0x0000ff00 - inc [massize] - pushad - mov [@@tex_x1],0 - mov [@@tex_y1],0 - mov [@@tex_x3],(32 shl 16) -1;128 - mov [@@tex_y3],(32 shl 16) -1;128 - mov [@@tex_x2],0 - mov [@@tex_y2],(32 shl 16) -1;128 - call textured_triangle - popad - -no_add1: - - - -;second triangle - mov eax,[edi+8] ;z1 - cmp eax,Z_MAX - jl no_add2 - mov [@@tz1],eax - mov eax,[edi+8+(4*3*(MATRIX_XSIZE+1))] ;z2 - cmp eax,Z_MAX - jl no_add2 - mov [@@tz2],eax - mov eax,[edi+8+(4*3*(MATRIX_XSIZE+2))] ;z3 - cmp eax,Z_MAX - jl no_add2 - mov [@@tz3],eax - - cmp dword [edi],SCREEN_X - ja p21 - cmp dword [edi+4],SCREEN_Y - jna yes_add2 -p21: - cmp dword [edi+(4*3*(MATRIX_XSIZE+1))],SCREEN_X - ja p22 - cmp dword [edi+4+(4*3*(MATRIX_XSIZE+1))],SCREEN_Y - jna yes_add2 -p22: - cmp dword [edi+(4*3*(MATRIX_XSIZE+2))],SCREEN_X - ja p23 - cmp dword [edi+4+(4*3*(MATRIX_XSIZE+2))],SCREEN_Y - jna yes_add2 -p23: - jmp no_add2 -yes_add2: - - movq mm0,qword [edi] ;x1 - movq mm1,qword [edi+(4*3*(MATRIX_XSIZE+1))] ;x2 - movq mm2,qword [edi+(4*3*(MATRIX_XSIZE+2))] ;x3 - movq qword [@@tx1],mm0 - movq qword [@@tx2],mm1 - movq qword [@@tx3],mm2 - - - mov eax,ebx - mov [@@tex_off],eax ;0x0000ff00 - inc [massize] -; add esi,4*10 - - pushad - mov [@@tex_x1],0 - mov [@@tex_y1],0 - mov [@@tex_x3],(32 shl 16) -1;128 - mov [@@tex_y3],(32 shl 16) -1;128 - mov [@@tex_x2],(32 shl 16) -1 - mov [@@tex_y2],0 - call textured_triangle - popad - - -no_add2: - - add edi,4*3 ;next triangle - dec ecx - jnz lootpx - add edi,4*3 ;next string - pop ecx - dec ecx - jnz lootpy - -;********************************** -;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -;********************************** -; For good models quality -5% speed -; call clrzbuf - - jmp skip_modmas -mmcnt dd 0 ;counter of model read number -modeloff dd 0 ;offset of model structure -modelmoff dd 0 ;offset in model mas -modeltmpoff dd 0 ;tmpoints offset -; massive of models -; format: X,Y,Z coordoinats,offset to model structure - -skip_modmas: - -; Rendering models on map - - mov eax,[model_mas] - mov [mmcnt],eax - -ModelRenderLoop: - - mov ebx,[mmcnt] - dec ebx - imul ebx,4*8 - add ebx,model_mas+4 - mov ebp,ebx ;edi=model offset X,Y,Z,Xturn,Yturn,Zturn,zero,modeloff - - mov ebx,[ebp+4*3];[Xangle] ; Grab angle - call GetSinCos ; Get the sine&cosine - mov [Xsin],eax ; Save sin - mov [Xcos],ebx ; Save cos - mov ebx,[ebp+4*4];[Yangle] - call GetSinCos - mov [Ysin],eax - mov [Ycos],ebx - mov ebx,[ebp+4*5];[Zangle] - call GetSinCos - mov [Zsin],eax - mov [Zcos],ebx - - mov ebx,[mmcnt] - imul ebx,4*8 - add ebx,model_mas+4-4 - mov eax,[ebx] - - mov [modeloff],eax - sub ebx,4*7;3 - mov [modelmoff],ebx - - mov edi,modelpoints - mov esi,eax ;bunker+8 - add esi,8 - mov ecx,[eax] ;[bunker] ;MODEL_POINTS - -TurnModelLoop: - push ecx - push esi - mov eax,[esi] - mov [X],eax - mov eax,[esi+4] - mov [Y],eax - mov eax,[esi+8] - mov [Z],eax - push ebp - push edi - -;RotatePoint - - mov esi,[Y] - mov ebx,[Xcos] - mov edi,[Z] - mov ecx,[Xsin] - call math - mov [Y],esi - mov [Z],edi - mov esi,[X] - mov ebx,[Ycos] - mov ecx,[Ysin] - call math - mov [X],esi - mov [Z],edi - mov ebx,[Zcos] - mov edi,[Y] - mov ecx,[Zsin] - call math - mov [X],esi - mov [Y],edi - - pop edi - - mov eax,[X] - mov [edi],eax - mov eax,[Y] - mov [edi+4],eax - - mov eax,[Z] ;z -; add eax,[Zoff] - mov [edi+8],eax - pop ebp - pop esi - pop ecx - - add esi,4*3 ;next in point - add edi,4*3 ;next out point - - dec ecx - jnz TurnModelLoop - -modxxx: - - -;Turn model off map - - call SetRotation - - mov ebx,[mmcnt] - imul ebx,4*8 - add ebx,model_mas+4-4 - mov eax,[ebx] - - mov [modeloff],eax - sub ebx,4*7;3 - mov [modelmoff],ebx - - mov edi,modelpoints - mov ecx,[eax] ;[bunker] ;MODEL_POINTS - -ShowModelLoop: - push ecx - mov eax,[edi] ;esi] - - mov ebx,[modelmoff] - sub eax,[ebx] ;[Xmod] - - sub eax,[Xcam] - mov ebx,[Xmap] - imul ebx,SECTOR_SIZE - sub eax,ebx - mov [X],eax - mov eax,[edi+4] ;esi+4] - - mov ebx,[modelmoff] - sub eax,[ebx+4] ;[Ymod] - - sub eax,[Ycam] - mov ebx,[Ymap] - imul ebx,SECTOR_SIZE - sub eax,ebx - mov [Y],eax - mov eax,[edi+8];esi+8] - - mov ebx,[modelmoff] - sub eax,[ebx+8] ;[Zmod] - - sub eax,[Zcam] - mov [Z],eax - push ebp - push edi - call TranslatePoint ; Rotates the point using above formulas - pop edi - mov [edi],ebp ;x - mov [edi+4],eax ;y - mov eax,[Z] ;z - add eax,[Zoff] - mov [edi+8],eax - pop ebp - pop ecx - - add edi,4*3 ;next out point - - dec ecx - jnz ShowModelLoop - - -; add [model_mas+8],dword 3 - - - - mov esi,[massize] - imul esi,4*10 - - mov eax,[modeloff] - mov ecx,[eax+4] ;MODEL_TRIANGELS - -;calc tmpoints offset - mov edi,modelpoints - mov [modeltmpoff],edi - -;calc postlink offset - mov edi,[eax] - imul edi,3*4;*2 ;X,Y,Z (3) points dd format (4) 2 masives (2) - add edi,eax - add edi,8 ;skip dd points, dd triangels -msloo: - - mov ebx,[edi] - imul ebx,4*3 - add ebx,[modeltmpoff] ;tmpoints - mov eax,[ebx] - mov [@@tx1],eax - mov eax,[ebx+4] - mov [@@ty1],eax - mov eax,[ebx+8] - mov [@@tz1],eax - - mov ebx,[edi+4] - imul ebx,4*3 - add ebx,[modeltmpoff] ;tmpoints - mov eax,[ebx] - mov [@@tx2],eax - mov eax,[ebx+4] - mov [@@ty2],eax - mov eax,[ebx+8] - mov [@@tz2],eax - - mov ebx,[edi+8] - imul ebx,4*3 - add ebx,[modeltmpoff] ;tmpoints - mov eax,[ebx] - mov [@@tx3],eax - mov eax,[ebx+4] - mov [@@ty3],eax - mov eax,[ebx+8] - mov [@@tz3],eax - - - cmp dword [@@tz1],Z_MAX - jl no_add - cmp dword [@@tz2],Z_MAX - jl no_add - cmp dword [@@tz3],Z_MAX - jl no_add - cmp dword [@@tx1],SCREEN_X - ja pm1 - cmp dword [@@ty1],SCREEN_Y - jna yes_madd -pm1: - cmp dword [@@tx2],SCREEN_X - ja pm2 - cmp dword [@@ty2],SCREEN_Y - jna yes_madd -pm2: - cmp dword [@@tx3],SCREEN_X - ja pm3 - cmp dword [@@ty3],SCREEN_Y - jna yes_madd -pm3: - jmp no_add -yes_madd: - - - - - mov ebx,[edi+12] - dec ebx - js ttex - mov eax,1 shl 31 - jmp posit -ttex: - add ebx,2 - mov eax,0 - neg ebx -posit: - imul ebx,4095;32*32*3 - add ebx,texture_img - mov [@@tex_off],ebx - - pushad - mov [@@tex_x1],0 - mov [@@tex_y1],0 - mov [@@tex_x3],(32 shl 16) -1;128 - mov [@@tex_y3],(32 shl 16) -1;128 - cmp eax,0 - je nez - mov [@@tex_x2],0 - mov [@@tex_y2],(32 shl 16) -1 - jmp isz -nez: - mov [@@tex_x2],(32 shl 16) -1 - mov [@@tex_y2],0 -isz: - call textured_triangle - popad - -; mov [esi+8+24+4],eax -; add esi,4*10 - inc [massize] -no_add: - add edi,4*4; *9 - dec ecx - jnz msloo - - dec [mmcnt] - jnz ModelRenderLoop - - - jmp skip_mdata - -bunker: -dd 8 ;model points -dd 10 ;model triagels -;mpoints: -dd -105,-105,0, -105,105,0, 105,105,0, 105,-105,0 -dd -70,-70,-50, -70,70,-50, 70,70,-50, 70,-70,-50 - -; 4-------7 Points structure -; |\0---3/| -; | | | | -; | | | | -; |/1---2\| -; 5-------6 - -;pointslink: -;dd 0,1,2, -3, 0,3,2, 3 ;far side -dd 4,0,1, -5, 4,5,1, 5 ;left side -dd 6,2,3, -5, 6,7,3, 5 ;right side -dd 4,0,3, -5, 4,7,3, 5 ;up side -dd 5,1,2, -5, 5,6,2, 5 ;down side -dd 4,5,6, -6, 4,7,6, 6 ;far side - -;model 2 outpost -outpost: -dd 8 ;model points -dd 10 ;model triagels -;mpoints: -dd -45,-45,0, -45,45,0, 45,45,0, 45,-45,0 -dd -30,-30,-20, -30,30,-20, 30,30,-20, 30,-30,-20 -;pointslink: -;dd 0,1,2, -3, 0,3,2, 3 ;far side -dd 4,0,1, -8, 4,5,1, 8 ;left side -dd 6,2,3, -8, 6,7,3, 8 ;right side -dd 4,0,3, -8, 4,7,3, 8 ;up side -dd 5,1,2, -8, 5,6,2, 8 ;down side -dd 4,5,6, -7, 4,7,6, 7 ;near side - -;model 3 cannon -cannon: -dd 12 ;model points -dd 12 ;model triagels -;mpoints: -dd -10,-20,0, -10,20,0, 10,20,0, 10,-20,0 -dd -10,-10,-15, -10,10,-15, 10,10,-15, 10,-10,-15 -dd -2,15,-8, 2,15,-8, -2,45,-8, 2,45,-8 -;pointslink: -;dd 0,1,2, -3, 0,3,2, 3 ;far side -dd 4,0,1, -10, 4,5,1, 10 ;left side -dd 6,2,3, -10, 6,7,3, 10 ;right side -dd 4,0,3, -10, 4,7,3, 10 ;up side -dd 5,1,2, -10, 5,6,2, 10 ;down side -dd 4,5,6, -11, 4,7,6, 11 ;near side -dd 8,9,10,-10, 9,10,11,10 ;cannon 1 - -;model 4 red flag -red_flag: -dd 12 ;model points -dd 6*2 ;model triagels -;mpoints: -dd -1,-1,0, -1,1,0, 1,1,0, 1,-1,0 -dd -1,-1,-30, -1,1,-30, 1,1,-30, 1,-1,-30 -dd 1,1,-30, 10,1,-30, 10,1,-20, 1,1,-20 -;pointslink: -dd 4,0,1, -10, 4,5,1, 15 ;left side -dd 6,2,3, -10, 6,7,3, 15 ;right side -dd 4,0,3, -10, 4,7,3, 15 ;up side -dd 5,1,2, -10, 5,6,2, 15 ;down side -dd 4,5,6, -10, 4,7,6, 15 ;near side -dd 8,11,10,-49, 8,9,10,49 ;flag - -repear: -dd 8 ;model points -dd 10 ;model triagels -;mpoints: -dd -45,-45,0, -45,45,0, 45,45,0, 45,-45,0 -dd -30,-30,-20, -30,30,-20, 30,30,-20, 30,-30,-20 -;pointslink: -dd 4,0,1, -5, 4,5,1, 5 ;left side -dd 6,2,3, -5, 6,7,3, 5 ;right side -dd 4,0,3, -5, 4,7,3, 5 ;up side -dd 5,1,2, -5, 5,6,2, 5 ;down side -dd 4,5,6, -3, 4,7,6, 3 ;far side - -;model 5 tree (elka) -tree: -dd 16 ;model points -dd 8*2 ;model triagels -;mpoints: -dd -2,-2,0, -2,2,0, 2,2,0, 2,-2,0 -dd -1,-1,-8, -1,1,-8, 1,1,-8, 1,-1,-8 -dd -10,-10,-8, -10,10,-8, 10,10,-8, 10,-10,-8 -dd -1,-1,-40, -1,1,-40, 1,1,-40, 1,-1,-40 -;pointslink: -dd 4,0,1, -16, 4,5,1, 16 ;left side -dd 6,2,3, -16, 6,7,3, 16 ;right side -dd 4,0,3, -16, 4,7,3, 16 ;up side -dd 5,1,2, -16, 5,6,2, 16 ;down side - -dd 12,8,9, -14, 12,13,9, 14 ;left side -dd 14,10,11, -14, 14,15,11, 14 ;right side -dd 12,8,11, -14, 12,15,11, 14 ;up side -dd 13,9,10, -14, 13,14,10, 14 ;down side - -;model tank -tank: -dd 20 ;model points -dd 12+10 ;model triagels -;mpoints: -dd -10,-20,-10, -10,20,-10, 10,20,-10, 10,-20,-10 -dd -10,-10,-20, -10,10,-20, 10,10,-20, 10,-10,-20 -dd -2,15,-15, 2,15,-15, -2,45,-15, 2,45,-15 - -dd -20,-20,0, -20,20,0, 20,20,0, 20,-20,0 -dd -20,-30,-10, -20,30,-10, 20,30,-10, 20,-30,-10 - -;pointslink: -;dd 0,1,2, -3, 0,3,2, 3 ;far side -dd 4,0,1, -10, 4,5,1, 10 ;left side -dd 6,2,3, -10, 6,7,3, 10 ;right side -dd 4,0,3, -10, 4,7,3, 10 ;up side -dd 5,1,2, -10, 5,6,2, 10 ;down side -dd 4,5,6, -11, 4,7,6, 11 ;near side -dd 8,9,10,-10, 9,10,11,10 ;cannon 1 - -dd 16,12,13, -11, 16,17,13, 11 ;left side -dd 18,14,15, -11, 18,19,15, 11 ;right side -dd 16,12,15, -11, 16,19,15, 11 ;up side -dd 17,13,14, -11, 17,18,14, 11 ;down side -dd 16,17,18, -11, 16,19,18, 11 ;near side - -;Test model -gqfa: ;Good quality four angle -dd 5 ;model points -dd 4 ;model triagels -;mpoints: -;dd -45,-145,0, -45,145,0, 45,45,0, 45,-45,0 -dd -0,-105,0, -0,105,0, 45,45,0, 45,-45,0 -dd 30,0,0 -;pointslink: -dd 1,4,0, 50 ;left side -dd 1,4,2, 51 ;right side -dd 3,4,2, -50 ;up side -dd 3,4,0, -51 ;down side - -skip_mdata: - -;*************** -; Add new models -;*************** -; jmp no_addmodel - - random 20,eax - sub eax,10 - imul eax,SECTOR_SIZE - add eax,SECTOR_SIZE/2 - mov [temp1],eax - random 20,eax - sub eax,10 - imul eax,SECTOR_SIZE - add eax,SECTOR_SIZE/2 - mov [temp2],eax - - mov eax,dword [model_mas] - cmp eax,40;00 - jae no_addmodel - imul eax,4*8; - add eax,4+model_mas - inc dword [model_mas] - mov ebx,[temp1] - mov [eax],ebx - mov ebx,[temp2] - mov [eax+4],ebx - mov [eax+8],dword -170 - mov ebx,0 - mov [eax+12],ebx - mov [eax+16],ebx - mov [eax+20],ebx - mov ebx,tree;red_flag - mov [eax+28],ebx - jmp skip_mdata ;use for auto filling at start -no_addmodel: - - ret - - -UpdateAngles: -; Calculates new x,y,z angles -; to autorotate around - - mov eax,[Xangle] ; Load current angles - mov ebx,[Yangle] - mov ecx,[Zangle] - - add eax,[DeltaX] ; Add velocity - and eax,011111111b ; Range from 0..255 - mov [Xangle],eax ; Update X - add ebx,[DeltaY] ; Add velocity - and ebx,011111111b ; Range from 0..255 - mov [Yangle],ebx ; Update Y - add ecx,[DeltaZ] ; Add velocity - and ecx,011111111b ; Range from 0..255 - mov [Zangle],ecx ; Update Z - ret - -GetSinCos: -; Needed : bx=angle (0..255) -; Returns: ax=Sin bx=Cos - push ebx ; Save angle (use as pointer) - shl ebx,2 ; Grab a word so bx=bx*2 - mov eax,[SinCos + ebx] ; Get sine - pop ebx ; Restore pointer into bx - push eax ; Save sine on stack - add ebx,64 ; Add 64 to get cosine - and ebx,11111111b ; Range from 0..255 - shl ebx,2 ; *2 coz it's a word - mov eax,[SinCos + ebx] ; Get cosine - mov ebx,eax ; Save it bx=Cos - pop eax ; Restore ax=Sin - ret - -; Get sin & cos of x,y,z angle -SetRotation: - mov ebx,[Xangle] ; Grab angle - call GetSinCos ; Get the sine&cosine - mov [Xsin],eax ; Save sin - mov [Xcos],ebx ; Save cos - - mov ebx,[Yangle] - call GetSinCos - mov [Ysin],eax - mov [Ycos],ebx - - mov ebx,[Zangle] - call GetSinCos - mov [Zsin],eax - mov [Zcos],ebx -; for camera - mov ebx,[Xcamangle] - call GetSinCos - mov [Xcamsin],eax - mov [Xcamcos],ebx - - mov ebx,[Ycamangle] - call GetSinCos - mov [Ycamsin],eax - mov [Ycamcos],ebx - - mov ebx,[Zcamangle] - call GetSinCos - mov [Zcamsin],eax - mov [Zcamcos],ebx - - ret - -TranslatePoint: ; Rotates the point around x,y,z -; Gets original x,y,z values -; This can be done elsewhere - - mov esi,[X] - mov edi,[Y] - mov ebx,[Zcamcos] - mov ecx,[Zcamsin] - call math - mov [X],esi - mov [Y],edi - - mov esi,[Y] - mov edi,[Z] - mov ebx,[Xcamcos] - mov ecx,[Xcamsin] - call math - mov [Y],esi - mov [Z],edi - - mov esi,[X] - mov edi,[Z] - mov ebx,[Ycamcos] - mov ecx,[Ycamsin] - call math - mov [X],esi - mov [Z],edi - - mov esi,[Y] - mov ebx,[Xcos] - mov edi,[Z] - mov ecx,[Xsin] - call math - mov [Y],esi - mov [Z],edi - mov esi,[X] - mov ebx,[Ycos] - mov ecx,[Ysin] - call math - mov [X],esi - mov [Z],edi - mov ebx,[Zcos] - mov edi,[Y] - mov ecx,[Zsin] - call math - -;************* -; ShowPoint -;************* - -; Calculates screenposition and -; plots the point on the screen - mov eax,[Xoff] ; Xoff*X / Z+Zoff = screen x - mov ecx,esi - imul ecx - - mov ebx,[Z] - add ebx,[Zoff] ; Distance - - cmp ebx,0 - je notout - idiv ebx - add eax,[Mx] ; Center on screen - mov ebp,eax ;ebp =Xp - - mov eax,[Yoff] ; Yoff*Y / Z+Zoff = screen y - mov ecx,edi - imul ecx - - cmp ebx,0 - je notout - idiv ebx ;eax =Yp - add eax,[My] ; Center on screen - -notout: - ret - -math: - mov eax,esi - imul ebx ; ax = X * Cos(zang) - mov ebp,eax - mov eax,edi - imul ecx ; ax = Y * Sin(zang) - sub ebp,eax ; bp = X * Cos(zang) - Y * Sin(zang) - sar ebp,8 ; bp = X * Cos(zang) - Y * Sin(zang) / 256 - - mov eax,esi - mov esi,ebp - imul ecx ; ax = X * Sin(zang) - mov ebp,eax - mov eax,edi - imul ebx ; ax = Y * Cos(zang) - add ebp,eax ; bp = X * SIN(zang) + Y * COS(zang) - sar ebp,8 ; bp = X * SIN(zang) + Y * COS(zang) / 256 - mov edi,ebp - ret - -SinCos: -dd 0,6,13,19,25,31,38,44,50,56 -dd 62,68,74,80,86,92,98,104,109,115 -dd 121,126,132,137,142,147,152,157,162,167 -dd 172,177,181,185,190,194,198,202,206,209 -dd 213,216,220,223,226,229,231,234,237,239 -dd 241,243,245,247,248,250,251,252,253,254 -dd 255,255,256,256,256,256,256,255,255,254 -dd 253,252,251,250,248,247,245,243,241,239 -dd 237,234,231,229,226,223,220,216,213,209 -dd 206,202,198,194,190,185,181,177,172,167 -dd 162,157,152,147,142,137,132,126,121,115 -dd 109,104,98,92,86,80,74,68,62,56 -dd 50,44,38,31,25,19,13,6,0,-6 -dd -13,-19,-25,-31,-38,-44,-50,-56,-62,-68 -dd -74,-80,-86,-92,-98,-104,-109,-115,-121,-126 -dd -132,-137,-142,-147,-152,-157,-162,-167,-172,-177 -dd -181,-185,-190,-194,-198,-202,-206,-209,-213,-216 -dd -220,-223,-226,-229,-231,-234,-237,-239,-241,-243 -dd -245,-247,-248,-250,-251,-252,-253,-254,-255,-255 -dd -256,-256,-256,-256,-256,-255,-255,-254,-253,-252 -dd -251,-250,-248,-247,-245,-243,-241,-239,-237,-234 -dd -231,-229,-226,-223,-220,-216,-213,-209,-206,-202 -dd -198,-194,-190,-185,-181,-177,-172,-167,-162,-157 -dd -152,-147,-142,-137,-132,-126,-121,-115,-109,-104 -dd -98,-92,-86,-80,-74,-68,-62,-56,-50,-44 -dd -38,-31,-25,-19,-13,-6 - -mipzoom dd 0 -mipmapwork dd 0 -temp1 dd 0 -temp2 dd 0 - -; 4.24.2005 Textured triangle algorythm -; created by Pavlushin Evgeni waptap[at]mail.ru -; on base tex3 from Mikolaj Felix mfelix@polbox.com - -align 512 -@@tx1 dd 0 ;equ [bp+4] -@@ty1 dd 0 ;equ [bp+6] -align 512 -@@tx2 dd 0 ;equ [bp+8] -@@ty2 dd 0 ;equ [bp+10] -align 512 -@@tx3 dd 0 ;equ [bp+12] -@@ty3 dd 0 ;equ [bp+14] - -@@tz1 dd 0 -@@tz2 dd 0 -@@tz3 dd 0 - -@@z_dy12 dd 0 -@@z_dy13 dd 0 -@@z_dy23 dd 0 - -@@tex_off dd 0 ;equ [bp+16] -@@tex_x1 dd 0 ;equ [bp+18] -@@tex_y1 dd 0 ;equ [bp+20] -@@tex_x2 dd 0 ;equ [bp+22] -@@tex_y2 dd 0 ;equ [bp+24] -@@tex_x3 dd 0 ;equ [bp+26] -@@tex_y3 dd 0 ;equ [bp+28] - -@@dx12 dd 0 ;equ [bp-2] -@@dx13 dd 0 ;equ [bp-4] -@@dx23 dd 0 ;equ [bp-6] - -@@tex_dx12 dd 0 ;equ [bp-8] -@@tex_dy12 dd 0 ;equ [bp-10] -@@tex_dx13 dd 0 ;equ [bp-12] -@@tex_dy13 dd 0 ;equ [bp-14] -@@tex_dx23 dd 0 ;equ [bp-16] -@@tex_dy23 dd 0 ;equ [bp-18] - -@@scan_x1 dd 0 -@@scan_y1 dd 0 -@@scan_x2 dd 0 -@@scan_y2 dd 0 - -@@scan_z1 dd 0 -@@scan_z2 dd 0 - -SHIFT=16 - -textured_triangle: - - mov eax,[@@ty1] - cmp eax,[@@ty3] - jle tt_check1 - - xchg eax,[@@ty3] - mov [@@ty1],eax - - mov eax,[@@tx1] - xchg eax,[@@tx3] - mov [@@tx1],eax - - mov eax,[@@tz1] - xchg eax,[@@tz3] - mov [@@tz1],eax - - mov eax,[@@tex_y1] - xchg eax,[@@tex_y3] - mov [@@tex_y1],eax - - mov eax,[@@tex_x1] - xchg eax,[@@tex_x3] - mov [@@tex_x1],eax -tt_check1: - mov eax,[@@ty2] - cmp eax,[@@ty3] - jle tt_check2 - - xchg eax,[@@ty3] - mov [@@ty2],eax - - mov eax,[@@tx2] - xchg eax,[@@tx3] - mov [@@tx2],eax - - mov eax,[@@tz2] - xchg eax,[@@tz3] - mov [@@tz2],eax - - mov eax,[@@tex_y2] - xchg eax,[@@tex_y3] - mov [@@tex_y2],eax - - mov eax,[@@tex_x2] - xchg eax,[@@tex_x3] - mov [@@tex_x2],eax -tt_check2: - mov eax,[@@ty1] - cmp eax,[@@ty2] - jle tt_check3 - - xchg eax,[@@ty2] - mov [@@ty1],eax - - mov eax,[@@tx1] - xchg eax,[@@tx2] - mov [@@tx1],eax - - mov eax,[@@tz1] - xchg eax,[@@tz2] - mov [@@tz1],eax - - mov eax,[@@tex_y1] - xchg eax,[@@tex_y2] - mov [@@tex_y1],eax - - mov eax,[@@tex_x1] - xchg eax,[@@tex_x2] - mov [@@tex_x1],eax -tt_check3: - - mov ebx,[@@ty2] - sub ebx,[@@ty1] - jnz tt_dx12_make - - mov [@@dx12],0 - mov [@@tex_dx12],0 - mov [@@tex_dy12],0 - mov [@@z_dy12],0 - jmp tt_dx12_done -tt_dx12_make: - mov eax,[@@tx2] - sub eax,[@@tx1] - shl eax,SHIFT - cdq - idiv ebx - mov [@@dx12],eax ; dx12 = (x2-x1)/(y2-y1) - - mov eax,[@@tex_x2] - sub eax,[@@tex_x1] - cdq - idiv ebx - mov [@@tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1) - - mov eax,[@@tex_y2] - sub eax,[@@tex_y1] - cdq - idiv ebx - mov [@@tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1) - - mov eax,[@@tz2] - sub eax,[@@tz1] - shl eax,SHIFT - cdq - idiv ebx - mov [@@z_dy12],eax - -tt_dx12_done: - - mov ebx,[@@ty3] - sub ebx,[@@ty1] - jnz tt_dx13_make - - mov [@@dx13],0 - mov [@@tex_dx13],0 - mov [@@tex_dy13],0 - mov [@@z_dy13],0 - jmp tt_dx13_done -tt_dx13_make: - mov eax,[@@tx3] - sub eax,[@@tx1] - shl eax,SHIFT - cdq - idiv ebx - mov [@@dx13],eax ; dx13 = (x3-x1)/(y3-y1) - - mov eax,[@@tex_x3] - sub eax,[@@tex_x1] - cdq - idiv ebx - mov [@@tex_dx13],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1) - - mov eax,[@@tex_y3] - sub eax,[@@tex_y1] - cdq - idiv ebx - mov [@@tex_dy13],eax ; tex_dy13 = (tex_y3-tex_x1)/(y3-y1) - - mov eax,[@@tz3] - sub eax,[@@tz1] - shl eax,SHIFT - cdq - idiv ebx - mov [@@z_dy13],eax -tt_dx13_done: - - mov ebx,[@@ty3] - sub ebx,[@@ty2] - jnz tt_dx23_make - - mov [@@dx23],0 - mov [@@tex_dx23],0 - mov [@@tex_dy23],0 - mov [@@z_dy23],0 - jmp tt_dx23_done -tt_dx23_make: - mov eax,[@@tx3] - sub eax,[@@tx2] - shl eax,SHIFT - cdq - idiv ebx - mov [@@dx23],eax ; dx23 = (x3-x2)/(y3-y2) - - mov eax,[@@tex_x3] - sub eax,[@@tex_x2] - cdq - idiv ebx - mov [@@tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2) - - mov eax,[@@tex_y3] - sub eax,[@@tex_y2] - cdq - idiv ebx - mov [@@tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2) - - mov eax,[@@tz3] - sub eax,[@@tz2] - shl eax,SHIFT - cdq - idiv ebx - mov [@@z_dy23],eax -tt_dx23_done: - - - mov eax,[@@tx1] - shl eax,SHIFT - mov ebx,eax - mov ecx,[@@ty1] - - mov edx,[@@tz1] - shl edx,SHIFT - mov [@@scan_z1],edx - mov [@@scan_z2],edx - - mov edx,[@@tex_x1] - mov [@@scan_x1],edx - mov [@@scan_x2],edx - mov edx,[@@tex_y1] - mov [@@scan_y1],edx - mov [@@scan_y2],edx - -; **************** - mov edx,[@@ty1] ;skip equals - cmp [@@ty2],edx - je tt_loop1_end - - mov ebp,[@@ty1] - cmp ebp,0 - jg no_up_clip - neg ebp - mov edx,[@@ty2] - cmp edx,0 - jg no_sbx - neg edx - sub ebp,edx -no_sbx: - - mov edx,[@@tex_dx13] - imul edx,ebp - add [@@scan_x1],edx - mov edx,[@@tex_dx12] - imul edx,ebp - add [@@scan_x2],edx - mov edx,[@@tex_dy13] - imul edx,ebp - add [@@scan_y1],edx - mov edx,[@@tex_dy12] - imul edx,ebp - add [@@scan_y2],edx - - mov edx,[@@z_dy13] - imul edx,ebp - add [@@scan_z1],edx - mov edx,[@@z_dy12] - imul edx,ebp - add [@@scan_z2],edx - - mov edx,[@@dx13] - imul edx,ebp - add eax,edx - mov edx,[@@dx12] - imul edx,ebp - add ebx,edx - add ecx,ebp -no_up_clip: - - cmp [@@ty2],0 - jl tt_loop1_end - -tt_loop1: - cmp ecx,SCREEN_Y - jge tt_loop2_end - - pushad - mov edx,[@@scan_y2] - mov [@@tex_ly2],edx ;push dx - mov edx,[@@scan_x2] - mov [@@tex_lx2],edx ;push dx - mov edx,[@@scan_y1] - mov [@@tex_ly1],edx ;push dx - mov edx,[@@scan_x1] - mov [@@tex_lx1],edx ;push dx - - mov edx,[@@scan_z1] - mov [@@lz1],edx - mov edx,[@@scan_z2] - mov [@@lz2],edx - - mov [@@ly],ecx ;push cx - mov edx,ebx - sar edx,SHIFT - mov [@@lx2],edx ;push dx - mov edx,eax - sar edx,SHIFT - mov [@@lx1],edx ; push dx - call textured_horizontal_line - popad - - mov edx,[@@tex_dx13] - add [@@scan_x1],edx - mov edx,[@@tex_dx12] - add [@@scan_x2],edx - mov edx,[@@tex_dy13] - add [@@scan_y1],edx - mov edx,[@@tex_dy12] - add [@@scan_y2],edx - - mov edx,[@@z_dy13] - add [@@scan_z1],edx - mov edx,[@@z_dy12] - add [@@scan_z2],edx - - add eax,[@@dx13] - add ebx,[@@dx12] - inc ecx - cmp ecx,[@@ty2] - jl tt_loop1 - -tt_loop1_end: - - mov ebx,[@@tx2] - shl ebx,SHIFT - mov ecx,[@@ty2] - - mov edx,[@@tz2] - shl edx,SHIFT - mov [@@scan_z2],edx - - mov edx,[@@tex_x2] - mov [@@scan_x2],edx - mov edx,[@@tex_y2] - mov [@@scan_y2],edx - - mov ebp,[@@ty2] - cmp ebp,0 - jg no_down_clip - neg ebp - dec ebp - - mov edx,[@@tex_dx13] - imul edx,ebp - add [@@scan_x1],edx - mov edx,[@@tex_dx23] - imul edx,ebp - add [@@scan_x2],edx - mov edx,[@@tex_dy13] - imul edx,ebp - add [@@scan_y1],edx - mov edx,[@@tex_dy23] - imul edx,ebp - add [@@scan_y2],edx - - mov edx,[@@z_dy13] - imul edx,ebp - add [@@scan_z1],edx - mov edx,[@@z_dy23] - imul edx,ebp - add [@@scan_z2],edx - - mov edx,[@@dx13] - imul edx,ebp - add eax,edx - mov edx,[@@dx23] - imul edx,ebp - add ebx,edx - add ecx,ebp -no_down_clip: - -tt_loop2: - cmp ecx,SCREEN_Y - jge tt_loop2_end - - pushad - mov edx,[@@scan_y2] - mov [@@tex_ly2],edx ;push dx - mov edx,[@@scan_x2] - mov [@@tex_lx2],edx ;push dx - mov edx,[@@scan_y1] - mov [@@tex_ly1],edx ;push dx - mov edx,[@@scan_x1] - mov [@@tex_lx1],edx ;push dx - - mov edx,[@@scan_z1] - mov [@@lz1],edx - mov edx,[@@scan_z2] - mov [@@lz2],edx - - mov [@@ly],ecx ;push cx - mov edx,ebx - sar edx,SHIFT - mov [@@lx2],edx ;push dx - mov edx,eax - sar edx,SHIFT - mov [@@lx1],edx ; push dx - call textured_horizontal_line - popad - - mov edx,[@@tex_dx13] - add [@@scan_x1],edx - mov edx,[@@tex_dx23] - add [@@scan_x2],edx - mov edx,[@@tex_dy13] - add [@@scan_y1],edx - mov edx,[@@tex_dy23] - add [@@scan_y2],edx - - mov edx,[@@z_dy13] - add [@@scan_z1],edx - mov edx,[@@z_dy23] - add [@@scan_z2],edx - - add eax,[@@dx13] - add ebx,[@@dx23] - inc ecx - cmp ecx,[@@ty3] - jl tt_loop2 - -tt_loop2_end: - ret - -align 512 -@@lx1 dd 0 -align 512 -@@lx2 dd 0 -align 512 -@@ly dd 0 - -@@lz1 dd 0 -@@lz2 dd 0 -@@z_dx dd 0 - -align 512 -@@tex_loff dd 0 ;equ [bp+10] -@@tex_lx1 dd 0 ;equ [bp+12] -@@tex_ly1 dd 0 ;equ [bp+14] -@@tex_lx2 dd 0 ;equ [bp+16] -@@tex_ly2 dd 0 ;equ [bp+18] - -align 512 -@@tex_ldx dd 0 ;equ [bp-2] -@@tex_ldy dd 0 ;equ [bp-4] - -align 1024 -textured_horizontal_line: - - mov eax,[@@lx1] - cmp eax,[@@lx2] - je thl_quit - jl thl_ok - - xchg eax,[@@lx2] - mov [@@lx1],eax - - mov eax,[@@lz1] - xchg eax,[@@lz2] - mov [@@lz1],eax - - mov eax,[@@tex_lx1] - xchg eax,[@@tex_lx2] - mov [@@tex_lx1],eax - - mov eax,[@@tex_ly1] - xchg eax,[@@tex_ly2] - mov [@@tex_ly1],eax - -thl_ok: - - cmp [@@lx2],0 - jle thl_quit - mov eax,SCREEN_X - cmp [@@lx1],eax - jge thl_quit - - mov ecx,[@@lx2] - sub ecx,[@@lx1] - - ; Uneversal method - mov edi,[@@ly] - mov eax,SCREEN_X ;di = ly*320+lx1 - imul edi - add eax,[@@lx1] - imul eax,3 - mov edi,eax - add edi,I_END - - ;Right side clipping - mov eax,SCREEN_X - cmp [@@lx2],eax - jnge x1ok - mov edx,SCREEN_X - dec edx - sub edx,[@@lx1] - cmp edx,0 - jle thl_quit - mov ecx,edx -x1ok: - - ;Left side clipping - cmp [@@lx1],0 - jg x2ok - mov ecx,[@@lx2] ;cmp lx2 screen x if above cut (for future) - mov edi,[@@ly] - mov eax,SCREEN_X - imul edi,eax - imul edi,3 - add edi,I_END -x2ok: - - mov ebx,[@@lx2] - sub ebx,[@@lx1] - - mov eax,[@@tex_lx2] - sub eax,[@@tex_lx1] - cdq - idiv ebx - mov [@@tex_ldx],eax ; tex_dx = (tex_x2-tex_x1)/(x2-x1) - - mov eax,[@@tex_ly2] - sub eax,[@@tex_ly1] - cdq - idiv ebx - mov [@@tex_ldy],eax ; tex_dy = (tex_y2-tex_y1)/(x2-x1) - - mov eax,[@@lz2] - sub eax,[@@lz1] - cdq - idiv ebx - mov [@@z_dx],eax ; tex_dx = (tex_x2-tex_x1)/(x2-x1) - - ; Left clipping post correction - cmp [@@lx1],0 - jg no_lcpc - mov eax,[@@lx1] - neg eax - mov ebp,[@@tex_ldx] - imul ebp,eax - add [@@tex_lx1],ebp - mov ebp,[@@tex_ldy] - imul ebp,eax - add [@@tex_ly1],ebp - mov ebp,[@@z_dx] - imul ebp,eax - add [@@lz1],ebp -no_lcpc: - - inc ecx ;for equal correction - mov edx,[@@tex_lx1] - mov ebx,[@@tex_ly1] - mov esi,[@@lz1] - -thl_loop: - mov ebp,esi - shr ebp,SHIFT - mov eax,dword [edi-I_END+zbuffer] - cmp ax,bp - jb no_set - mov [edi-I_END+zbuffer],bp - - mov eax,edx -; and eax,0x0fff0000 - ror ebx,16 - mov ax,bx - ror ebx,16 - shl ax,11 ; 8 for 256*256, 9 for 128*128 ... - shr eax,11 - lea eax,[eax*2+eax] ; equ imul eax,3 - add eax,[@@tex_off] - mov ebp,eax - - mov ax,word [ebp] - mov [edi],ax - mov al,byte [ebp+2] - mov [edi+2],al - -no_set: - add edi,3 - - add esi,[@@z_dx] - add edx,[@@tex_ldx] - add ebx,[@@tex_ldy] - dec ecx - jnz thl_loop -thl_quit: - ret - - -@@rgb dd 0 -@@rgbax dw 0 -@@rgbbl db 0 - -; === DATA === - -d_angle dd 0.19634954 ;pi/16 -angle dd 0.0 -mul_wave dd 1.5 - -sin_pos dw 0 -sinwave rw 256 - -Xmap dd 0 -Ymap dd 0 -mapoff dd 0 - -Xcam dd 0 -Ycam dd 0 -Zcam dd -400 - -Xcamangle dd 0 -Ycamangle dd 0 -Zcamangle dd 0 - -Xcamsin dd 0 -Xcamcos dd 0 -Ycamsin dd 0 -Ycamcos dd 0 -Zcamsin dd 0 -Zcamcos dd 0 - -X dd ? ; X,Y,Z variable for formula -Y dd ? -Z dd ? - -Xp dd ? -Yp dd ? - -Xangle dd 0 ; Angle to rotate around x -Yangle dd 0 -Zangle dd 0 - -DeltaX dd 1 ; x,y,z rotation angle -DeltaY dd 1 -DeltaZ dd 1 - -Xoff dd 256 ; x-cord -Yoff dd 256 ; y-cord -Zoff dd 0;800 ; Distance from viewer - -Xsin dd ? ; Sine and cosine of angle to rotate around -Xcos dd ? -Ysin dd ? -Ycos dd ? -Zsin dd ? -Zcos dd ? - -Mx dd SCREEN_X/2 ; Center of the screen -My dd SCREEN_Y/2 - -autorot db 0 ;Auto rotation flag -massize dd 0 ;Size of triangle massive -id dd 0 -temp dd 0 - -; DATA AREA -labelt: - db '3D TEXTURED ENGINE' -labellen: - - -;Texture pusck 32*32 256 -texpack_gif: -file 'texpack.gif' -rb 50 - -;Ground texture -bmp_texmap: -file 'texmap.bmp' -rb 50 - - -; Ground livel map -gif_file_area5: -file 'map.gif' ;level map -rb 50 - -rb 8 -texture_limg: -rb 4095 -texture_img: -rb 4095 -texture_img2: -rb 4095 - -rb (4095)*16*16 - -img_area: -rb 128*128*3+8 - -glm_img_area: -rb (MAP_XSIZE+1)*(MAP_YSIZE+1)*3+8 - -rb 8 - -texpack_img: -rb 512*512*3+8 - -keymap: -rb 1000 - -model_mas: -rb 4+8*100 - -; Hash area for decoding GIF -gif_hash_area: -rd 4096+1 - -MAX_MODEL_POINTS = 100 -modelpoints: -rb MAX_MODEL_POINTS*3*4 - -; Matrix points massive -points: -; Massive of turn matrix points -tpoints=points+((MATRIX_XSIZE+1)*(MATRIX_YSIZE+1)*3*4) -; Ground level map massive -ground_level_map=tpoints+((MATRIX_XSIZE+1)*(MATRIX_YSIZE+1)*3*4) -; zbuffer -zbuffer=ground_level_map+((MAP_XSIZE+1)*(MAP_YSIZE+1)*4) -I_END=zbuffer+(SCREEN_X*SCREEN_Y)*3 +; SPDX-License-Identifier: NOASSERTION +; + +; Text encoded with Code Page 866 - Cyrillic + +; +; 3D ТЕКСТУРИРОВАНЫЙ ДВИЖОК 3D TEXTURED ENGINE +; АВТОР: Павлюшин Евгений AUTOR: Pavlushin Evgeni +; +; Компилируется с помощью FASM ассемблера для MenuetOS +; Compile with FASM assembler for MenuetOS +; +; 20.11.04 Fast point calc & triangle draw +; Little matrix no (trangle massive) +; Fast triangle, del triangle out of screen +; 16.12.04 Fast triangle with MMX +; 20.12.04 Out triangle fatal bug's deleted, "black zones" deleted +; Matrix move support +; 24.12.04 Fast keyboard scanning +; Z-ground level map work +; Texture draw correction deleted "black zones" +; 04.01.05 Moveing texture +; 05.01.05 Water dynamic texture +; 06.01.05 Texture pack (many textures in one file) +; 07.01.05 Z-sorting +; 08.01.05 Triangle good clipping calculating (speed up) +; 4 byte Z-sorting, more dynamic of water +; 09.01.05 Texture map from 256 color bmp file +; Pixel Z-buffer, good speed! +; 21.01.05 Models buffer add. +; 25.01.05 Models buffer update, Add 2 new models. +; 29.01.05 Dynamic model array +; 01.02.05 1 picture MipMap calculation +; 04.02.05 All picture MipMap calculation, proc speed up. +; Simple Triangel MipMap chose. +; 05.02.05 Normal Triangel MipMap chose. +; 12.02.05 Best QUALITY of Textured TRIANGEL! +; 13.02.05 add new models. All camera axis calculating +; 16.02.05 Simple model turning +; 17.02.05 Advanced model turning, model tmpoints massive deleted +; New map size 128, add new models. +; 25.02.05 Left side clipping bug deleted +; 26.02.05 Optimization of textured line algorythm +; 24.04.05 Test pixel z-buffer it's work. Use new textri algorythm +; 30.04.05 Fast Y-clipping + +use32 + +SCREEN_X equ 800 ;320 ;Screen size easy change +SCREEN_Y equ 600 ;200 +DSCREEN_X equ SCREEN_X-1 ;320 ;For triangle clipping +DSCREEN_Y equ SCREEN_Y-1 ;200 +MATRIX_XSIZE equ 64;32;64;100 ;Ground matrix size +MATRIX_YSIZE equ 64;32;64;100 +SECTOR_SIZE equ 100 ;Size of matrix sector +MAP_XSIZE equ 128 ;Rezolution of map file +MAP_YSIZE equ 128 + + org 0x0 + db 'MENUET01' ; 8 байт интдефикатор + dd 0x01 ; версия заголовка + dd START ; адресс начала кода + dd I_END ; размер программы + dd I_END+(SCREEN_X*SCREEN_Y*3+50000) ; размер памяти для прогграммы + dd I_END+(SCREEN_X*SCREEN_Y*3+10000) ; esp + dd 0x0 , 0x0 ; I_Param , I_Icon + +include 'lang.inc' +include '..\..\macros.inc' +include 'ascgl.inc' +include 'ascl.inc' + +START: ; начало приложения +; Draw window at first + call draw_window + + ; Decoding groud texture and ground level map + gif_hash_offset = gif_hash_area + ;texture's + giftoimg texpack_gif,texpack_img-8 + ;ground level map + giftoimg gif_file_area5,glm_img_area + +;get 8bitmap from 256 colors bmp file + mov ebp,128;64 + mov esi,0x043a+128*128-4;64*64-4 + sub esi,128;64 + mov edi,0 + mov ecx,128;64 +texmap_unp: + mov al,[bmp_texmap+esi] + mov [img_area+edi],al + inc esi + inc edi + dec ecx + jnz texmap_unp + mov ecx,128;64 + sub esi,256;128 + dec ebp + jnz texmap_unp + + +;Unpack textures + + mov esi,texpack_img + mov edi,texture_img + mov edx,16 + mov ecx,16 +tpuckloop: + pushad + call unpuck + popad + add esi,32*3 + add edi,4095 + dec ecx + jnz tpuckloop + add esi,31*32*16*3 + mov ecx,16 + dec edx + jnz tpuckloop + +; +; Unpuck one texture procendure +; + jmp skip_unpuck +unpuck: + mov ecx,32 + mov edx,32 +tunploop: + mov ax,[esi] + mov [edi],ax + mov al,[esi+2] + mov [edi+2],al + add esi,3 + add edi,3 + dec ecx + jnz tunploop + mov ecx,32 + add esi,(32*16*3)-(32*3) + dec edx + jnz tunploop + ret +skip_unpuck: + + +;calculating all mipmaps + mov esi,texture_img + mov ecx,256 ;quantity of textures +mmaploop: + mov ebp,32 ;max mipmap texture + pusha + call texgen + popa + add esi,4095 ;next mipmap block + dec ecx + jnz mmaploop + + jmp skip_texgen + +;******************************** +; MIPMAP TEXTURE GENERATION +; +; in put: +; esi - offset to texture +; ebp - mipmap max size (32 for this sample) +;******************************** + +texgen: + push esi + mov eax,ebp + imul eax,ebp + imul eax,3 + add eax,esi + mov edi,eax + + mov eax,ebp + shr eax,1 + mov dh,al + mov dl,al + mov cl,dl + + mov ecx,ebp + mov eax,ebp + shl eax,1 + add ecx,eax + +miploop: +; Red + xor bx,bx ;for add + xor ax,ax ;for add + mov al,[esi+0] + add bx,ax + mov al,[esi+3+0] + add bx,ax + mov al,[esi+ecx+0] + add bx,ax + mov al,[esi+ecx+3+0] + add bx,ax + shr bx,2 ;/4 + mov [edi+0],bl +;Green + xor bx,bx ;for add + xor ax,ax ;for add + mov al,[esi+1] + add bx,ax + mov al,[esi+3+1] + add bx,ax + mov al,[esi+ecx+1] + add bx,ax + mov al,[esi+ecx+3+1] + add bx,ax + shr bx,2 ;/4 + mov [edi+1],bl +;Blue + xor bx,bx ;for add + xor ax,ax ;for add + mov al,[esi+2] + add bx,ax + mov al,[esi+3+2] + add bx,ax + mov al,[esi+ecx+2] + add bx,ax + mov al,[esi+ecx+3+2] + add bx,ax + shr bx,2 ;/4 + mov [edi+2],bl + + add esi,6 + add edi,3 + dec dl + jnz miploop + mov ax,bp + shr ax,1 + mov dl,al + add esi,ecx + dec dh + jnz miploop + pop esi + + mov eax,ebp + imul eax,ebp + imul eax,3 + add esi,eax + shr ebp,1 + cmp ebp,1 + jne texgen + ret +skip_texgen: + + +;Copy dynamic water texture +; ???????????? + mov ecx,32*32*3 + mov esi,texture_img+4095 ;32*32*3 + mov edi,texture_limg + cld + rep movsb + + ; init sine wave for dynamic water texture + finit + mov edi,sinwave + mov ecx,32;256 + isv_loop: + fld [angle] + fld st + fsin + fmul [mul_wave] + fistp word [edi] + fadd [d_angle] + fstp [angle] + add edi,2 + dec ecx + jnz isv_loop + + +;Initalize keyboard + mov eax,66 + mov ebx,1 + mov ecx,1 + mcall + + mov eax,26 + mov ebx,2 + mov ecx,1 + mov edx,keymap+100 + mcall + +;Build triangle matrix + mov esi,points + mov eax,-(MATRIX_XSIZE/2)*SECTOR_SIZE + mov ebx,-(MATRIX_YSIZE/2)*SECTOR_SIZE + mov ebp,img_area+8 +loomat: + mov [esi],eax ;x-set + mov [esi+4],ebx ;y-set + mov [esi+8],ecx ;z-set + add ebp,3 + add esi,4*3 + add eax,SECTOR_SIZE + cmp eax,((MATRIX_YSIZE/2)+1)*SECTOR_SIZE + jnge loomat + mov eax,-(MATRIX_YSIZE/2)*SECTOR_SIZE + add ebx,SECTOR_SIZE + cmp ebx,((MATRIX_XSIZE/2)+1)*SECTOR_SIZE + jnge loomat + +; Create z-ground good algorythm not already yet (64x64 map) + mov esi,glm_img_area+8 + mov edi,ground_level_map +loox: +; draw_courner_points + mov eax,[esi] + call get_z +; mov [edi],eax + + mov eax,[esi+((MATRIX_XSIZE-1)*4)] + call get_z +; mov [edi+((MATRIX_XSIZE)*4)],eax + + mov eax,[esi+(((MATRIX_XSIZE)*(MATRIX_YSIZE-1)+1)*4)] + call get_z +; mov [edi+(((MATRIX_XSIZE+1)*(MATRIX_YSIZE)-0)*4)],eax + + mov eax,[esi+(((MATRIX_XSIZE)*(MATRIX_YSIZE)-1)*4)] + call get_z +; mov [edi+(((MATRIX_XSIZE+1)*(MATRIX_YSIZE+1)-1)*4)],eax + + + jmp skip_gz +get_z: + xor ebx,ebx + xor ecx,ecx + mov bl,al + add ecx,ebx + mov bl,ah + add ecx,ebx + shr eax,16 + mov bl,al + add ecx,ebx + mov eax,ecx + xor edx,edx + mov ebx,3 + cdq + div ebx + neg eax + ret +skip_gz: + +; z-ground livel facking method (65x65 map) + mov esi,glm_img_area+8 + mov edi,ground_level_map + mov ebp,(MAP_XSIZE+1)*(MAP_YSIZE+1) +looglm: + mov eax,[esi] +; and eax,0x000000ff + call get_z + mov [edi],eax + add esi,3 + add edi,1 + dec ebp + jnz looglm + +;Fill model massive + mov ecx,[model_mas_start] + imul ecx,8 + add ecx,4 + mov esi,model_mas_start + mov edi,model_mas + cld + rep movsd + + jmp skip_moddata +model_mas_start: +dd 12 ;quantity of models +dd 0,0,-150,0,0,0,0,bunker +dd 60,-250,-190,0,0,64,0,tank +dd 0,180,-150,0,0,0,0,cannon +dd 0,480,-150,0,0,0,0,outpost +dd 260,60,-150,0,0,0,0,bunker +dd 60,260,-150,0,0,0,0,outpost +dd 210,410,-150,0,0,0,0,cannon +dd 160,260,-150,0,0,0,0,tree +dd 100,-360,-150,0,0,192,0,gqfa +dd 10,580,-150,0,0,0,0,repear +dd 460,160,-100,0,0,0,0,red_flag +dd 60,360,-170,0,0,40,0,cannon +skip_moddata: + + +;Main loop +still: ; основной цикл + mov eax,11 ; проверка состояния окна + mcall + + cmp eax,1 ; окно сдвинули его нужно перерисовать + je red + cmp eax,2 ; нажата клавиша на клавиатуре + je key + cmp eax,3 ; нажата кнопка в окне + je button + +; delay 10 +; cmp [autorot],0 ;frize no fps show when autorot off +; je still + +cycle: + call clrscr ; clear screen buffer + call clrzbuf ; clear z-buffer + call render_scene ; calculating scene + call dispimg ; show buffer + + fps_show_frequency=0 + fps 10,10,cl_White,cl_Black + + +;turn model on z-axis + inc dword [model_mas+4*6] + and dword [model_mas+4*6],011111111b + + +; Sin wave dynamic texture for water +; jmp ndt + xor edi,edi + mov dx,32 + mov bp,word [sin_pos] +dp_ver: + mov cx,32 ;320 + mov si,word [sin_pos] +dp_hor: + and ebp,0000ffffh + mov ax,word [sinwave+ebp] + add ax,cx + and ax,31 + + and esi,0000ffffh + mov bx,word [sinwave+esi] + add bx,dx + and bx,31 + shl bx,5 + add bx,ax + + push bx + imul bx,3 + and ebx,0000ffffh + mov ax,[texture_limg+ebx] + mov [texture_img2+edi],ax + mov al,[texture_limg+ebx+2] + mov [texture_img2+edi+2],al + pop bx + + add edi,3 + add si,2 + and si,63;511 + + dec cx + jnz dp_hor + add bp,2 + and bp,63;511 + dec dx + jnz dp_ver + +; update sine position for next frame + add word [sin_pos],2 + and word [sin_pos],63;511 + +;Move water texture + jmp ndt + mov esi,texture_limg + mov ecx,32*32-1 +loodt: + mov al,byte [esi] + mov bl,byte [esi+1] + mov dl,byte [esi+2] + mov ah,byte [esi+3] + mov bh,byte [esi+4] + mov dh,byte [esi+5] + mov byte [esi],ah + mov byte [esi+1],bh + mov byte [esi+2],dh + mov byte [esi+3],al + mov byte [esi+4],bl + mov byte [esi+5],dl + add esi,3 + dec ecx + jnz loodt +ndt: + +;Creat mipmap pack for dynamic texture + mov ebp,32 + mov esi,texture_img+4095 + call texgen + + + mov eax,4 ; function 4 : write text to window + mov ebx,8*65536+8 ; [x start] *65536 + [y start] + mov ecx,0x0000ff00 ; font 1 & color ( 0xF0RRGGBB ) + mov edx,keymap ; pointer to text beginning + mov esi,100 ; text length + mcall + add edx,100 + add ebx,10 + mov esi,60 ; text length + mov ecx,0x00dddddd ; font 1 & color ( 0xF0RRGGBB ) + mcall + mov edx,usemap + mov esi,60 ; text length + mov ecx,0x0000ff00 + mcall + jmp rx + ;01234567890123456789012345678901234567890123456789 +usemap db ' E wer u [] asd zxc ' + db ' ' +rx: + + cmp byte [keymap+1],0 + je n_esc + jmp exit +n_esc: + + cmp byte [keymap+22],0 + je n_u + mov [Xangle],0 + mov [Yangle],0 + mov [Zangle],0 +n_u: + +; t,y - mipmap cntrol + cmp byte [keymap+20],0 + je n_t + inc [mipzoom] +n_t: + cmp byte [keymap+21],0 + je n_y + dec [mipzoom] +n_y: + cmp byte [keymap+23],0 + je n_i + mov byte [keymap+23],0 ; reset key + cmp [mipmapwork],1 + je i_1 +i_0: + mov [mipmapwork],1 + jmp n_i +i_1: + mov [mipmapwork],0 +n_i: + + + cmp byte [keymap+26],0 + je n_lsk + add [Xcam],1 +n_lsk: + cmp byte [keymap+27],0 + je n_rsk + sub [Xcam],1 +n_rsk: + cmp byte [keymap+18],0 + je n_e + add [Yangle],1 +n_e: + cmp byte [keymap+45],0 + je n_x + sub [Yangle],1 +n_x: + cmp byte [keymap+31],0 + je n_s + add [Xangle],1 +n_s: + cmp byte [keymap+32],0 + je n_d + sub [Xangle],1 +n_d: + cmp byte [keymap+44],0 + je n_z + add [Zangle],1 +n_z: + cmp byte [keymap+46],0 + je n_c + sub [Zangle],1 +n_c: + cmp byte [keymap+17],0 + je n_w + add [Zcam],25 ;250 +n_w: + cmp byte [keymap+19],0 + je n_r + sub [Zcam],25 ;250 +n_r: + + cmp byte [keymap+75],0 + je n_lk + add [Zcamangle],1 + and [Zcamangle],011111111b +n_lk: + cmp byte [keymap+77],0 + je n_rk + sub [Zcamangle],1 + and [Zcamangle],011111111b +n_rk: + + cmp byte [keymap+79],0 + je n_num1 + add [Xcamangle],1 + and [Xcamangle],011111111b +n_num1: + cmp byte [keymap+81],0 + je n_num3 + sub [Xcamangle],1 + and [Xcamangle],011111111b +n_num3: + cmp byte [keymap+71],0 + je n_num7 + add [Ycamangle],1 + and [Ycamangle],011111111b +n_num7: + cmp byte [keymap+73],0 + je n_num9 + sub [Ycamangle],1 + and [Ycamangle],011111111b +n_num9: + + + + cmp byte [keymap+30],0 + je n_a + mov byte [keymap+30],0 ; reset key + cmp [autorot],1 + je a_1 +a_0: + mov [autorot],1 + jmp n_a +a_1: + mov [autorot],0 +n_a: + +; for camera +; mov ebx,[Xcamangle] +; call GetSinCos +; mov [Xcamsin],eax +; mov [Xcamcos],ebx + +; mov ebx,[Ycamangle] +; call GetSinCos +; mov [Ycamsin],eax +; mov [Ycamcos],ebx + + mov ebx,[Zcamangle] + call GetSinCos + mov [Zcamsin],eax + mov [Zcamcos],ebx + + mov eax,[Zcamsin] + mov ebx,[Zcamcos] +; mov ecx,[Xcamsin] +; mov edx,[Xcamcos] +; mov esi,[Ycamsin] +; mov edi,[Ycamcos] + + sar eax,4 + sar ebx,4 +; sar ecx,4 +; sar edx,4 +; sar esi,4 +; sar edi,4 + + cmp byte [keymap+72],0 + je n_uk + sub [Xcam],eax + sub [Ycam],ebx + +; sub [Zcam],ecx +; sub [Ycam],edx + +; sub [Xcam],esi +; add [Zcam],edi + +n_uk: + cmp byte [keymap+80],0 + je n_dk + add [Xcam],eax + add [Ycam],ebx + +; add [Zcam],ecx +; add [Ycam],edx + +; add [Xcam],esi +; sub [Zcam],edi + +n_dk: + + xor ebp,ebp +move_test: + cmp [Xcam],-SECTOR_SIZE/2 + jnl ok1 + add [Xcam],SECTOR_SIZE + dec [Xmap] + jmp move_test +ok1: + cmp [Xcam],SECTOR_SIZE/2 + jng ok2 + sub [Xcam],SECTOR_SIZE + inc [Xmap] + jmp ok1 +ok2: + cmp [Ycam],-SECTOR_SIZE/2 + jnl ok3 + add [Ycam],SECTOR_SIZE + dec [Ymap] + jmp ok2 +ok3: + cmp [Ycam],SECTOR_SIZE/2 + jng ok4 + sub [Ycam],SECTOR_SIZE + inc [Ymap] + jmp ok3 +ok4: + + and [Xangle],011111111b + and [Yangle],011111111b + and [Zangle],011111111b + + jmp still + + red: ; redraw + call draw_window + jmp still + + key: ; key + mov eax,2 ; just read it and ignore + mcall + + shr eax,8 + and eax,0xff + mov ah,al + + mov ebx,0 + mov bl,ah + cmp bl,224 + je noisa ; ignore Ext code + cmp bl,170 + je noisa ; ignore Key Up code + cmp bl,128 + ja isa + mov [keymap+ebx],byte 'X' ; set press marker to key id + jmp noisa +isa: + sub bl,128 + mov [keymap+ebx],byte 0 ; reset key marker +noisa: + jmp n_a + + jmp still ; cycle + + button: ; button + mov eax,17 ; get id + mcall + cmp ah,1 + jz exit + jmp cycle + +exit: + or eax,-1 + mcall + +; ********************************************* +; ******* WINDOW DEFINITIONS AND DRAW ******** +; ********************************************* + +draw_window: + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,1 ; 1, start of draw + mcall + ; DRAW WINDOW + mov eax,0 ; function 0 : define and draw window + mov ebx,0*65536+SCREEN_X-1 ; [x start] *65536 + [x size] + mov ecx,0*65536+SCREEN_Y-1 ; [y start] *65536 + [y size] + mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl + mov esi,0x005080d0 ; color of grab bar RRGGBB,8->color gl + mov edi,0x005080d0 ; color of frames RRGGBB + mcall + ; WINDOW LABEL + mov eax,4 ; function 4 : write text to window + mov ebx,8*65536+8 ; [x start] *65536 + [y start] + mov ecx,0x10ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelt ; pointer to text beginning + mov esi,labellen-labelt ; text length + mcall + + mov eax,12 + mov ebx,2 + mcall + ret + +dispimg: + mov eax,7 + mov ebx,I_END ;zbuffer + mov ecx,SCREEN_X*65536+SCREEN_Y + xor edx,edx ;0*65536+0 + mcall +; ret + + mov eax,8 + mov ebx,(SCREEN_X-30)*65536+20 + mov ecx,10*65536+20 + mov edx,1 + mov esi,0x0000aa00 + mcall + ret + +clrscr: ; clear screen buffer +; cld +; mov edi,I_END +; xor eax,eax +; mov ecx,SCREEN_X*SCREEN_Y*3/4 +; rep stosd +; ret + +; clear screen buffer with MMX technology +1,5 fps + mov edi,I_END + mov ecx,SCREEN_X*SCREEN_Y*3/32 + xor eax,eax + movd mm0,eax + movd mm1,eax + movd mm2,eax + movd mm3,eax +csloo: + movq qword [edi],mm0 + movq qword [edi+8],mm1 + movq qword [edi+16],mm2 + movq qword [edi+24],mm3 + add edi,32 + dec ecx + jnz csloo + ret + +clrzbuf: ; clear zbuf + cld + mov edi,zbuffer + mov eax,-1 + mov ecx,SCREEN_X*SCREEN_Y*3/4 + rep stosd + ret + + +; mov [@@atx1],dword 0xffffffff +; mov [@@aty1],dword 0xffffffff +; movq mm0,qword [@@atx1] +; movq mm1,qword [@@atx1] +; movq mm2,qword [@@atx1] +; movq mm3,qword [@@atx1] +;czbloo: +; movq qword [edi],mm0 +; movq qword [edi+8],mm1 +; movq qword [edi+16],mm2 +; movq qword [edi+24],mm3 +; add edi,32 +; dec ecx +; jnz czbloo + ret + +@@atx1: dd 0 +@@aty1: dd 0 + +;=========================================================================== +; +; 3D-system example. Use the following formulas to rotate a point: +; +; Rotate around x-axis +; Y = Y * COS(xang) - Z * SIN(xang) / 256 +; Z = Y * SIN(xang) + Z * COS(xang) / 256 +; +; Rotate around y-axis +; X = X * COS(yang) - Z * SIN(yang) / 256 +; Z = X * SIN(yang) + Z * COS(yang) / 256 +; +; Rotate around z-axis +; X = X * COS(zang) - Y * SIN(zang) / 256 +; Y = X * SIN(zang) + Y * COS(zang) / 256 +; +; Divide by 256 coz we have multiplyd our sin values with 256 too. +; This example isn't too fast right now but it'll work just fine. +; +;=========================================================================== + +;*************************************************************************** +; \\\ MAIN 3D LOOP /// +; ****************** +render_scene: + +;******************** +; Turn matrix points +;******************** + + cmp [autorot],0 + je no_autorot + call UpdateAngles ; Calculate new angles +no_autorot: + call SetRotation ; Find sine & cosine of those angles + + mov edi,tpoints + mov esi,points + mov [mapoff],-1 ;-1 at start + mov ebp,[Ymap] + imul ebp,MAP_XSIZE+1 + mov eax,[Xmap] + add ebp,eax + + mov ecx,(MATRIX_XSIZE+1)*(MATRIX_YSIZE+1) +ShowLoop: + push ecx + push esi + mov eax,[esi] + sub eax,[Xcam] + mov [X],eax + mov eax,[esi+4] + sub eax,[Ycam] + mov [Y],eax + mov eax,[ebp+ground_level_map] ;color + and eax,0x000000ff + sub eax,[Zcam] + mov [Z],eax + push ebp + push edi + call TranslatePoint ; Rotates the point using above formulas + pop edi + mov [edi],ebp ;x + mov [edi+4],eax ;y + mov eax,[Z] ;z + add eax,[Zoff] + mov [edi+8],eax + pop ebp + pop esi + pop ecx + + add esi,4*3 ;next in point + add edi,4*3 ;next out point + + inc [mapoff] + cmp [mapoff],MATRIX_XSIZE+1 + jne no_shift_glm + mov [mapoff],dword 0 + add ebp,(MAP_XSIZE-MATRIX_XSIZE) +no_shift_glm: + add ebp,1 + + dec ecx + jnz ShowLoop + + +; Show, how many polygons on screen. + outcount [massize],50,10,cl_White,8*65536 + + +;***************** +; out triangles +;***************** + + mov [mapoff],-1 ;-1 at start + mov [massize],0 ;restet triangle massive counter + + mov ebp,[Ymap] + imul ebp,MAP_XSIZE;64;3*64 ;MAP_XSIZE + mov eax,[Xmap] + add ebp,eax + + mov edi,tpoints + mov ecx,MATRIX_YSIZE ;64 +lootpy: + push ecx + mov ecx,MATRIX_XSIZE ;64 +lootpx: +;draw four angle (two triangles) + +Z_MAX = 10 ;maximal z range for triangles + +; get texture offset at start + inc [mapoff] + cmp [mapoff],MATRIX_XSIZE + jne no_shift + mov [mapoff],dword 0 + add ebp,(MAP_XSIZE-MATRIX_XSIZE) +no_shift: + xor eax,eax + mov al,[ebp+img_area];+8] + inc ebp + imul eax,4095;32*32*3 + add eax,texture_img + mov ebx,eax + +;first triangle + mov eax,[edi+8] ;z1 + cmp eax,Z_MAX + jl no_add1 + mov [@@tz1],eax + mov eax,[edi+8+12] ;z2 + cmp eax,Z_MAX + jl no_add1 + mov [@@tz2],eax + mov eax,[edi+8+(4*3*(MATRIX_XSIZE+2))] ;z3 + cmp eax,Z_MAX + jl no_add1 + mov [@@tz3],eax + + cmp dword [edi],SCREEN_X + ja p11 + cmp dword [edi+4],SCREEN_Y + jna yes_add1 +p11: + cmp dword [edi+12],SCREEN_X + ja p12 + cmp dword [edi+4+12],SCREEN_Y + jna yes_add1 +p12: + cmp dword [edi+(4*3*(MATRIX_XSIZE+2))],SCREEN_X + ja p13 + cmp dword [edi+4+(4*3*(MATRIX_XSIZE+2))],SCREEN_Y + jna yes_add1 +p13: + jmp no_add1 +yes_add1: + + movq mm0,qword [edi] ;x1 + movq mm1,qword [edi+12] ;x2 + movq mm2,qword [edi+(4*3*(MATRIX_XSIZE+2))] ;x3 + movq qword [@@tx1],mm0 + movq qword [@@tx2],mm1 + movq qword [@@tx3],mm2 + + mov eax,ebx;+1 shl 31;[ebp] + mov [@@tex_off],eax ;0x0000ff00 + inc [massize] + pushad + mov [@@tex_x1],0 + mov [@@tex_y1],0 + mov [@@tex_x3],(32 shl 16) -1;128 + mov [@@tex_y3],(32 shl 16) -1;128 + mov [@@tex_x2],0 + mov [@@tex_y2],(32 shl 16) -1;128 + call textured_triangle + popad + +no_add1: + + + +;second triangle + mov eax,[edi+8] ;z1 + cmp eax,Z_MAX + jl no_add2 + mov [@@tz1],eax + mov eax,[edi+8+(4*3*(MATRIX_XSIZE+1))] ;z2 + cmp eax,Z_MAX + jl no_add2 + mov [@@tz2],eax + mov eax,[edi+8+(4*3*(MATRIX_XSIZE+2))] ;z3 + cmp eax,Z_MAX + jl no_add2 + mov [@@tz3],eax + + cmp dword [edi],SCREEN_X + ja p21 + cmp dword [edi+4],SCREEN_Y + jna yes_add2 +p21: + cmp dword [edi+(4*3*(MATRIX_XSIZE+1))],SCREEN_X + ja p22 + cmp dword [edi+4+(4*3*(MATRIX_XSIZE+1))],SCREEN_Y + jna yes_add2 +p22: + cmp dword [edi+(4*3*(MATRIX_XSIZE+2))],SCREEN_X + ja p23 + cmp dword [edi+4+(4*3*(MATRIX_XSIZE+2))],SCREEN_Y + jna yes_add2 +p23: + jmp no_add2 +yes_add2: + + movq mm0,qword [edi] ;x1 + movq mm1,qword [edi+(4*3*(MATRIX_XSIZE+1))] ;x2 + movq mm2,qword [edi+(4*3*(MATRIX_XSIZE+2))] ;x3 + movq qword [@@tx1],mm0 + movq qword [@@tx2],mm1 + movq qword [@@tx3],mm2 + + + mov eax,ebx + mov [@@tex_off],eax ;0x0000ff00 + inc [massize] +; add esi,4*10 + + pushad + mov [@@tex_x1],0 + mov [@@tex_y1],0 + mov [@@tex_x3],(32 shl 16) -1;128 + mov [@@tex_y3],(32 shl 16) -1;128 + mov [@@tex_x2],(32 shl 16) -1 + mov [@@tex_y2],0 + call textured_triangle + popad + + +no_add2: + + add edi,4*3 ;next triangle + dec ecx + jnz lootpx + add edi,4*3 ;next string + pop ecx + dec ecx + jnz lootpy + +;********************************** +;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +;********************************** +; For good models quality -5% speed +; call clrzbuf + + jmp skip_modmas +mmcnt dd 0 ;counter of model read number +modeloff dd 0 ;offset of model structure +modelmoff dd 0 ;offset in model mas +modeltmpoff dd 0 ;tmpoints offset +; massive of models +; format: X,Y,Z coordoinats,offset to model structure + +skip_modmas: + +; Rendering models on map + + mov eax,[model_mas] + mov [mmcnt],eax + +ModelRenderLoop: + + mov ebx,[mmcnt] + dec ebx + imul ebx,4*8 + add ebx,model_mas+4 + mov ebp,ebx ;edi=model offset X,Y,Z,Xturn,Yturn,Zturn,zero,modeloff + + mov ebx,[ebp+4*3];[Xangle] ; Grab angle + call GetSinCos ; Get the sine&cosine + mov [Xsin],eax ; Save sin + mov [Xcos],ebx ; Save cos + mov ebx,[ebp+4*4];[Yangle] + call GetSinCos + mov [Ysin],eax + mov [Ycos],ebx + mov ebx,[ebp+4*5];[Zangle] + call GetSinCos + mov [Zsin],eax + mov [Zcos],ebx + + mov ebx,[mmcnt] + imul ebx,4*8 + add ebx,model_mas+4-4 + mov eax,[ebx] + + mov [modeloff],eax + sub ebx,4*7;3 + mov [modelmoff],ebx + + mov edi,modelpoints + mov esi,eax ;bunker+8 + add esi,8 + mov ecx,[eax] ;[bunker] ;MODEL_POINTS + +TurnModelLoop: + push ecx + push esi + mov eax,[esi] + mov [X],eax + mov eax,[esi+4] + mov [Y],eax + mov eax,[esi+8] + mov [Z],eax + push ebp + push edi + +;RotatePoint + + mov esi,[Y] + mov ebx,[Xcos] + mov edi,[Z] + mov ecx,[Xsin] + call math + mov [Y],esi + mov [Z],edi + mov esi,[X] + mov ebx,[Ycos] + mov ecx,[Ysin] + call math + mov [X],esi + mov [Z],edi + mov ebx,[Zcos] + mov edi,[Y] + mov ecx,[Zsin] + call math + mov [X],esi + mov [Y],edi + + pop edi + + mov eax,[X] + mov [edi],eax + mov eax,[Y] + mov [edi+4],eax + + mov eax,[Z] ;z +; add eax,[Zoff] + mov [edi+8],eax + pop ebp + pop esi + pop ecx + + add esi,4*3 ;next in point + add edi,4*3 ;next out point + + dec ecx + jnz TurnModelLoop + +modxxx: + + +;Turn model off map + + call SetRotation + + mov ebx,[mmcnt] + imul ebx,4*8 + add ebx,model_mas+4-4 + mov eax,[ebx] + + mov [modeloff],eax + sub ebx,4*7;3 + mov [modelmoff],ebx + + mov edi,modelpoints + mov ecx,[eax] ;[bunker] ;MODEL_POINTS + +ShowModelLoop: + push ecx + mov eax,[edi] ;esi] + + mov ebx,[modelmoff] + sub eax,[ebx] ;[Xmod] + + sub eax,[Xcam] + mov ebx,[Xmap] + imul ebx,SECTOR_SIZE + sub eax,ebx + mov [X],eax + mov eax,[edi+4] ;esi+4] + + mov ebx,[modelmoff] + sub eax,[ebx+4] ;[Ymod] + + sub eax,[Ycam] + mov ebx,[Ymap] + imul ebx,SECTOR_SIZE + sub eax,ebx + mov [Y],eax + mov eax,[edi+8];esi+8] + + mov ebx,[modelmoff] + sub eax,[ebx+8] ;[Zmod] + + sub eax,[Zcam] + mov [Z],eax + push ebp + push edi + call TranslatePoint ; Rotates the point using above formulas + pop edi + mov [edi],ebp ;x + mov [edi+4],eax ;y + mov eax,[Z] ;z + add eax,[Zoff] + mov [edi+8],eax + pop ebp + pop ecx + + add edi,4*3 ;next out point + + dec ecx + jnz ShowModelLoop + + +; add [model_mas+8],dword 3 + + + + mov esi,[massize] + imul esi,4*10 + + mov eax,[modeloff] + mov ecx,[eax+4] ;MODEL_TRIANGELS + +;calc tmpoints offset + mov edi,modelpoints + mov [modeltmpoff],edi + +;calc postlink offset + mov edi,[eax] + imul edi,3*4;*2 ;X,Y,Z (3) points dd format (4) 2 masives (2) + add edi,eax + add edi,8 ;skip dd points, dd triangels +msloo: + + mov ebx,[edi] + imul ebx,4*3 + add ebx,[modeltmpoff] ;tmpoints + mov eax,[ebx] + mov [@@tx1],eax + mov eax,[ebx+4] + mov [@@ty1],eax + mov eax,[ebx+8] + mov [@@tz1],eax + + mov ebx,[edi+4] + imul ebx,4*3 + add ebx,[modeltmpoff] ;tmpoints + mov eax,[ebx] + mov [@@tx2],eax + mov eax,[ebx+4] + mov [@@ty2],eax + mov eax,[ebx+8] + mov [@@tz2],eax + + mov ebx,[edi+8] + imul ebx,4*3 + add ebx,[modeltmpoff] ;tmpoints + mov eax,[ebx] + mov [@@tx3],eax + mov eax,[ebx+4] + mov [@@ty3],eax + mov eax,[ebx+8] + mov [@@tz3],eax + + + cmp dword [@@tz1],Z_MAX + jl no_add + cmp dword [@@tz2],Z_MAX + jl no_add + cmp dword [@@tz3],Z_MAX + jl no_add + cmp dword [@@tx1],SCREEN_X + ja pm1 + cmp dword [@@ty1],SCREEN_Y + jna yes_madd +pm1: + cmp dword [@@tx2],SCREEN_X + ja pm2 + cmp dword [@@ty2],SCREEN_Y + jna yes_madd +pm2: + cmp dword [@@tx3],SCREEN_X + ja pm3 + cmp dword [@@ty3],SCREEN_Y + jna yes_madd +pm3: + jmp no_add +yes_madd: + + + + + mov ebx,[edi+12] + dec ebx + js ttex + mov eax,1 shl 31 + jmp posit +ttex: + add ebx,2 + mov eax,0 + neg ebx +posit: + imul ebx,4095;32*32*3 + add ebx,texture_img + mov [@@tex_off],ebx + + pushad + mov [@@tex_x1],0 + mov [@@tex_y1],0 + mov [@@tex_x3],(32 shl 16) -1;128 + mov [@@tex_y3],(32 shl 16) -1;128 + cmp eax,0 + je nez + mov [@@tex_x2],0 + mov [@@tex_y2],(32 shl 16) -1 + jmp isz +nez: + mov [@@tex_x2],(32 shl 16) -1 + mov [@@tex_y2],0 +isz: + call textured_triangle + popad + +; mov [esi+8+24+4],eax +; add esi,4*10 + inc [massize] +no_add: + add edi,4*4; *9 + dec ecx + jnz msloo + + dec [mmcnt] + jnz ModelRenderLoop + + + jmp skip_mdata + +bunker: +dd 8 ;model points +dd 10 ;model triagels +;mpoints: +dd -105,-105,0, -105,105,0, 105,105,0, 105,-105,0 +dd -70,-70,-50, -70,70,-50, 70,70,-50, 70,-70,-50 + +; 4-------7 Points structure +; |\0---3/| +; | | | | +; | | | | +; |/1---2\| +; 5-------6 + +;pointslink: +;dd 0,1,2, -3, 0,3,2, 3 ;far side +dd 4,0,1, -5, 4,5,1, 5 ;left side +dd 6,2,3, -5, 6,7,3, 5 ;right side +dd 4,0,3, -5, 4,7,3, 5 ;up side +dd 5,1,2, -5, 5,6,2, 5 ;down side +dd 4,5,6, -6, 4,7,6, 6 ;far side + +;model 2 outpost +outpost: +dd 8 ;model points +dd 10 ;model triagels +;mpoints: +dd -45,-45,0, -45,45,0, 45,45,0, 45,-45,0 +dd -30,-30,-20, -30,30,-20, 30,30,-20, 30,-30,-20 +;pointslink: +;dd 0,1,2, -3, 0,3,2, 3 ;far side +dd 4,0,1, -8, 4,5,1, 8 ;left side +dd 6,2,3, -8, 6,7,3, 8 ;right side +dd 4,0,3, -8, 4,7,3, 8 ;up side +dd 5,1,2, -8, 5,6,2, 8 ;down side +dd 4,5,6, -7, 4,7,6, 7 ;near side + +;model 3 cannon +cannon: +dd 12 ;model points +dd 12 ;model triagels +;mpoints: +dd -10,-20,0, -10,20,0, 10,20,0, 10,-20,0 +dd -10,-10,-15, -10,10,-15, 10,10,-15, 10,-10,-15 +dd -2,15,-8, 2,15,-8, -2,45,-8, 2,45,-8 +;pointslink: +;dd 0,1,2, -3, 0,3,2, 3 ;far side +dd 4,0,1, -10, 4,5,1, 10 ;left side +dd 6,2,3, -10, 6,7,3, 10 ;right side +dd 4,0,3, -10, 4,7,3, 10 ;up side +dd 5,1,2, -10, 5,6,2, 10 ;down side +dd 4,5,6, -11, 4,7,6, 11 ;near side +dd 8,9,10,-10, 9,10,11,10 ;cannon 1 + +;model 4 red flag +red_flag: +dd 12 ;model points +dd 6*2 ;model triagels +;mpoints: +dd -1,-1,0, -1,1,0, 1,1,0, 1,-1,0 +dd -1,-1,-30, -1,1,-30, 1,1,-30, 1,-1,-30 +dd 1,1,-30, 10,1,-30, 10,1,-20, 1,1,-20 +;pointslink: +dd 4,0,1, -10, 4,5,1, 15 ;left side +dd 6,2,3, -10, 6,7,3, 15 ;right side +dd 4,0,3, -10, 4,7,3, 15 ;up side +dd 5,1,2, -10, 5,6,2, 15 ;down side +dd 4,5,6, -10, 4,7,6, 15 ;near side +dd 8,11,10,-49, 8,9,10,49 ;flag + +repear: +dd 8 ;model points +dd 10 ;model triagels +;mpoints: +dd -45,-45,0, -45,45,0, 45,45,0, 45,-45,0 +dd -30,-30,-20, -30,30,-20, 30,30,-20, 30,-30,-20 +;pointslink: +dd 4,0,1, -5, 4,5,1, 5 ;left side +dd 6,2,3, -5, 6,7,3, 5 ;right side +dd 4,0,3, -5, 4,7,3, 5 ;up side +dd 5,1,2, -5, 5,6,2, 5 ;down side +dd 4,5,6, -3, 4,7,6, 3 ;far side + +;model 5 tree (elka) +tree: +dd 16 ;model points +dd 8*2 ;model triagels +;mpoints: +dd -2,-2,0, -2,2,0, 2,2,0, 2,-2,0 +dd -1,-1,-8, -1,1,-8, 1,1,-8, 1,-1,-8 +dd -10,-10,-8, -10,10,-8, 10,10,-8, 10,-10,-8 +dd -1,-1,-40, -1,1,-40, 1,1,-40, 1,-1,-40 +;pointslink: +dd 4,0,1, -16, 4,5,1, 16 ;left side +dd 6,2,3, -16, 6,7,3, 16 ;right side +dd 4,0,3, -16, 4,7,3, 16 ;up side +dd 5,1,2, -16, 5,6,2, 16 ;down side + +dd 12,8,9, -14, 12,13,9, 14 ;left side +dd 14,10,11, -14, 14,15,11, 14 ;right side +dd 12,8,11, -14, 12,15,11, 14 ;up side +dd 13,9,10, -14, 13,14,10, 14 ;down side + +;model tank +tank: +dd 20 ;model points +dd 12+10 ;model triagels +;mpoints: +dd -10,-20,-10, -10,20,-10, 10,20,-10, 10,-20,-10 +dd -10,-10,-20, -10,10,-20, 10,10,-20, 10,-10,-20 +dd -2,15,-15, 2,15,-15, -2,45,-15, 2,45,-15 + +dd -20,-20,0, -20,20,0, 20,20,0, 20,-20,0 +dd -20,-30,-10, -20,30,-10, 20,30,-10, 20,-30,-10 + +;pointslink: +;dd 0,1,2, -3, 0,3,2, 3 ;far side +dd 4,0,1, -10, 4,5,1, 10 ;left side +dd 6,2,3, -10, 6,7,3, 10 ;right side +dd 4,0,3, -10, 4,7,3, 10 ;up side +dd 5,1,2, -10, 5,6,2, 10 ;down side +dd 4,5,6, -11, 4,7,6, 11 ;near side +dd 8,9,10,-10, 9,10,11,10 ;cannon 1 + +dd 16,12,13, -11, 16,17,13, 11 ;left side +dd 18,14,15, -11, 18,19,15, 11 ;right side +dd 16,12,15, -11, 16,19,15, 11 ;up side +dd 17,13,14, -11, 17,18,14, 11 ;down side +dd 16,17,18, -11, 16,19,18, 11 ;near side + +;Test model +gqfa: ;Good quality four angle +dd 5 ;model points +dd 4 ;model triagels +;mpoints: +;dd -45,-145,0, -45,145,0, 45,45,0, 45,-45,0 +dd -0,-105,0, -0,105,0, 45,45,0, 45,-45,0 +dd 30,0,0 +;pointslink: +dd 1,4,0, 50 ;left side +dd 1,4,2, 51 ;right side +dd 3,4,2, -50 ;up side +dd 3,4,0, -51 ;down side + +skip_mdata: + +;*************** +; Add new models +;*************** +; jmp no_addmodel + + random 20,eax + sub eax,10 + imul eax,SECTOR_SIZE + add eax,SECTOR_SIZE/2 + mov [temp1],eax + random 20,eax + sub eax,10 + imul eax,SECTOR_SIZE + add eax,SECTOR_SIZE/2 + mov [temp2],eax + + mov eax,dword [model_mas] + cmp eax,40;00 + jae no_addmodel + imul eax,4*8; + add eax,4+model_mas + inc dword [model_mas] + mov ebx,[temp1] + mov [eax],ebx + mov ebx,[temp2] + mov [eax+4],ebx + mov [eax+8],dword -170 + mov ebx,0 + mov [eax+12],ebx + mov [eax+16],ebx + mov [eax+20],ebx + mov ebx,tree;red_flag + mov [eax+28],ebx + jmp skip_mdata ;use for auto filling at start +no_addmodel: + + ret + + +UpdateAngles: +; Calculates new x,y,z angles +; to autorotate around + + mov eax,[Xangle] ; Load current angles + mov ebx,[Yangle] + mov ecx,[Zangle] + + add eax,[DeltaX] ; Add velocity + and eax,011111111b ; Range from 0..255 + mov [Xangle],eax ; Update X + add ebx,[DeltaY] ; Add velocity + and ebx,011111111b ; Range from 0..255 + mov [Yangle],ebx ; Update Y + add ecx,[DeltaZ] ; Add velocity + and ecx,011111111b ; Range from 0..255 + mov [Zangle],ecx ; Update Z + ret + +GetSinCos: +; Needed : bx=angle (0..255) +; Returns: ax=Sin bx=Cos + push ebx ; Save angle (use as pointer) + shl ebx,2 ; Grab a word so bx=bx*2 + mov eax,[SinCos + ebx] ; Get sine + pop ebx ; Restore pointer into bx + push eax ; Save sine on stack + add ebx,64 ; Add 64 to get cosine + and ebx,11111111b ; Range from 0..255 + shl ebx,2 ; *2 coz it's a word + mov eax,[SinCos + ebx] ; Get cosine + mov ebx,eax ; Save it bx=Cos + pop eax ; Restore ax=Sin + ret + +; Get sin & cos of x,y,z angle +SetRotation: + mov ebx,[Xangle] ; Grab angle + call GetSinCos ; Get the sine&cosine + mov [Xsin],eax ; Save sin + mov [Xcos],ebx ; Save cos + + mov ebx,[Yangle] + call GetSinCos + mov [Ysin],eax + mov [Ycos],ebx + + mov ebx,[Zangle] + call GetSinCos + mov [Zsin],eax + mov [Zcos],ebx +; for camera + mov ebx,[Xcamangle] + call GetSinCos + mov [Xcamsin],eax + mov [Xcamcos],ebx + + mov ebx,[Ycamangle] + call GetSinCos + mov [Ycamsin],eax + mov [Ycamcos],ebx + + mov ebx,[Zcamangle] + call GetSinCos + mov [Zcamsin],eax + mov [Zcamcos],ebx + + ret + +TranslatePoint: ; Rotates the point around x,y,z +; Gets original x,y,z values +; This can be done elsewhere + + mov esi,[X] + mov edi,[Y] + mov ebx,[Zcamcos] + mov ecx,[Zcamsin] + call math + mov [X],esi + mov [Y],edi + + mov esi,[Y] + mov edi,[Z] + mov ebx,[Xcamcos] + mov ecx,[Xcamsin] + call math + mov [Y],esi + mov [Z],edi + + mov esi,[X] + mov edi,[Z] + mov ebx,[Ycamcos] + mov ecx,[Ycamsin] + call math + mov [X],esi + mov [Z],edi + + mov esi,[Y] + mov ebx,[Xcos] + mov edi,[Z] + mov ecx,[Xsin] + call math + mov [Y],esi + mov [Z],edi + mov esi,[X] + mov ebx,[Ycos] + mov ecx,[Ysin] + call math + mov [X],esi + mov [Z],edi + mov ebx,[Zcos] + mov edi,[Y] + mov ecx,[Zsin] + call math + +;************* +; ShowPoint +;************* + +; Calculates screenposition and +; plots the point on the screen + mov eax,[Xoff] ; Xoff*X / Z+Zoff = screen x + mov ecx,esi + imul ecx + + mov ebx,[Z] + add ebx,[Zoff] ; Distance + + cmp ebx,0 + je notout + idiv ebx + add eax,[Mx] ; Center on screen + mov ebp,eax ;ebp =Xp + + mov eax,[Yoff] ; Yoff*Y / Z+Zoff = screen y + mov ecx,edi + imul ecx + + cmp ebx,0 + je notout + idiv ebx ;eax =Yp + add eax,[My] ; Center on screen + +notout: + ret + +math: + mov eax,esi + imul ebx ; ax = X * Cos(zang) + mov ebp,eax + mov eax,edi + imul ecx ; ax = Y * Sin(zang) + sub ebp,eax ; bp = X * Cos(zang) - Y * Sin(zang) + sar ebp,8 ; bp = X * Cos(zang) - Y * Sin(zang) / 256 + + mov eax,esi + mov esi,ebp + imul ecx ; ax = X * Sin(zang) + mov ebp,eax + mov eax,edi + imul ebx ; ax = Y * Cos(zang) + add ebp,eax ; bp = X * SIN(zang) + Y * COS(zang) + sar ebp,8 ; bp = X * SIN(zang) + Y * COS(zang) / 256 + mov edi,ebp + ret + +SinCos: +dd 0,6,13,19,25,31,38,44,50,56 +dd 62,68,74,80,86,92,98,104,109,115 +dd 121,126,132,137,142,147,152,157,162,167 +dd 172,177,181,185,190,194,198,202,206,209 +dd 213,216,220,223,226,229,231,234,237,239 +dd 241,243,245,247,248,250,251,252,253,254 +dd 255,255,256,256,256,256,256,255,255,254 +dd 253,252,251,250,248,247,245,243,241,239 +dd 237,234,231,229,226,223,220,216,213,209 +dd 206,202,198,194,190,185,181,177,172,167 +dd 162,157,152,147,142,137,132,126,121,115 +dd 109,104,98,92,86,80,74,68,62,56 +dd 50,44,38,31,25,19,13,6,0,-6 +dd -13,-19,-25,-31,-38,-44,-50,-56,-62,-68 +dd -74,-80,-86,-92,-98,-104,-109,-115,-121,-126 +dd -132,-137,-142,-147,-152,-157,-162,-167,-172,-177 +dd -181,-185,-190,-194,-198,-202,-206,-209,-213,-216 +dd -220,-223,-226,-229,-231,-234,-237,-239,-241,-243 +dd -245,-247,-248,-250,-251,-252,-253,-254,-255,-255 +dd -256,-256,-256,-256,-256,-255,-255,-254,-253,-252 +dd -251,-250,-248,-247,-245,-243,-241,-239,-237,-234 +dd -231,-229,-226,-223,-220,-216,-213,-209,-206,-202 +dd -198,-194,-190,-185,-181,-177,-172,-167,-162,-157 +dd -152,-147,-142,-137,-132,-126,-121,-115,-109,-104 +dd -98,-92,-86,-80,-74,-68,-62,-56,-50,-44 +dd -38,-31,-25,-19,-13,-6 + +mipzoom dd 0 +mipmapwork dd 0 +temp1 dd 0 +temp2 dd 0 + +; 4.24.2005 Textured triangle algorythm +; created by Pavlushin Evgeni waptap[at]mail.ru +; on base tex3 from Mikolaj Felix mfelix@polbox.com + +align 512 +@@tx1 dd 0 ;equ [bp+4] +@@ty1 dd 0 ;equ [bp+6] +align 512 +@@tx2 dd 0 ;equ [bp+8] +@@ty2 dd 0 ;equ [bp+10] +align 512 +@@tx3 dd 0 ;equ [bp+12] +@@ty3 dd 0 ;equ [bp+14] + +@@tz1 dd 0 +@@tz2 dd 0 +@@tz3 dd 0 + +@@z_dy12 dd 0 +@@z_dy13 dd 0 +@@z_dy23 dd 0 + +@@tex_off dd 0 ;equ [bp+16] +@@tex_x1 dd 0 ;equ [bp+18] +@@tex_y1 dd 0 ;equ [bp+20] +@@tex_x2 dd 0 ;equ [bp+22] +@@tex_y2 dd 0 ;equ [bp+24] +@@tex_x3 dd 0 ;equ [bp+26] +@@tex_y3 dd 0 ;equ [bp+28] + +@@dx12 dd 0 ;equ [bp-2] +@@dx13 dd 0 ;equ [bp-4] +@@dx23 dd 0 ;equ [bp-6] + +@@tex_dx12 dd 0 ;equ [bp-8] +@@tex_dy12 dd 0 ;equ [bp-10] +@@tex_dx13 dd 0 ;equ [bp-12] +@@tex_dy13 dd 0 ;equ [bp-14] +@@tex_dx23 dd 0 ;equ [bp-16] +@@tex_dy23 dd 0 ;equ [bp-18] + +@@scan_x1 dd 0 +@@scan_y1 dd 0 +@@scan_x2 dd 0 +@@scan_y2 dd 0 + +@@scan_z1 dd 0 +@@scan_z2 dd 0 + +SHIFT=16 + +textured_triangle: + + mov eax,[@@ty1] + cmp eax,[@@ty3] + jle tt_check1 + + xchg eax,[@@ty3] + mov [@@ty1],eax + + mov eax,[@@tx1] + xchg eax,[@@tx3] + mov [@@tx1],eax + + mov eax,[@@tz1] + xchg eax,[@@tz3] + mov [@@tz1],eax + + mov eax,[@@tex_y1] + xchg eax,[@@tex_y3] + mov [@@tex_y1],eax + + mov eax,[@@tex_x1] + xchg eax,[@@tex_x3] + mov [@@tex_x1],eax +tt_check1: + mov eax,[@@ty2] + cmp eax,[@@ty3] + jle tt_check2 + + xchg eax,[@@ty3] + mov [@@ty2],eax + + mov eax,[@@tx2] + xchg eax,[@@tx3] + mov [@@tx2],eax + + mov eax,[@@tz2] + xchg eax,[@@tz3] + mov [@@tz2],eax + + mov eax,[@@tex_y2] + xchg eax,[@@tex_y3] + mov [@@tex_y2],eax + + mov eax,[@@tex_x2] + xchg eax,[@@tex_x3] + mov [@@tex_x2],eax +tt_check2: + mov eax,[@@ty1] + cmp eax,[@@ty2] + jle tt_check3 + + xchg eax,[@@ty2] + mov [@@ty1],eax + + mov eax,[@@tx1] + xchg eax,[@@tx2] + mov [@@tx1],eax + + mov eax,[@@tz1] + xchg eax,[@@tz2] + mov [@@tz1],eax + + mov eax,[@@tex_y1] + xchg eax,[@@tex_y2] + mov [@@tex_y1],eax + + mov eax,[@@tex_x1] + xchg eax,[@@tex_x2] + mov [@@tex_x1],eax +tt_check3: + + mov ebx,[@@ty2] + sub ebx,[@@ty1] + jnz tt_dx12_make + + mov [@@dx12],0 + mov [@@tex_dx12],0 + mov [@@tex_dy12],0 + mov [@@z_dy12],0 + jmp tt_dx12_done +tt_dx12_make: + mov eax,[@@tx2] + sub eax,[@@tx1] + shl eax,SHIFT + cdq + idiv ebx + mov [@@dx12],eax ; dx12 = (x2-x1)/(y2-y1) + + mov eax,[@@tex_x2] + sub eax,[@@tex_x1] + cdq + idiv ebx + mov [@@tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1) + + mov eax,[@@tex_y2] + sub eax,[@@tex_y1] + cdq + idiv ebx + mov [@@tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1) + + mov eax,[@@tz2] + sub eax,[@@tz1] + shl eax,SHIFT + cdq + idiv ebx + mov [@@z_dy12],eax + +tt_dx12_done: + + mov ebx,[@@ty3] + sub ebx,[@@ty1] + jnz tt_dx13_make + + mov [@@dx13],0 + mov [@@tex_dx13],0 + mov [@@tex_dy13],0 + mov [@@z_dy13],0 + jmp tt_dx13_done +tt_dx13_make: + mov eax,[@@tx3] + sub eax,[@@tx1] + shl eax,SHIFT + cdq + idiv ebx + mov [@@dx13],eax ; dx13 = (x3-x1)/(y3-y1) + + mov eax,[@@tex_x3] + sub eax,[@@tex_x1] + cdq + idiv ebx + mov [@@tex_dx13],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1) + + mov eax,[@@tex_y3] + sub eax,[@@tex_y1] + cdq + idiv ebx + mov [@@tex_dy13],eax ; tex_dy13 = (tex_y3-tex_x1)/(y3-y1) + + mov eax,[@@tz3] + sub eax,[@@tz1] + shl eax,SHIFT + cdq + idiv ebx + mov [@@z_dy13],eax +tt_dx13_done: + + mov ebx,[@@ty3] + sub ebx,[@@ty2] + jnz tt_dx23_make + + mov [@@dx23],0 + mov [@@tex_dx23],0 + mov [@@tex_dy23],0 + mov [@@z_dy23],0 + jmp tt_dx23_done +tt_dx23_make: + mov eax,[@@tx3] + sub eax,[@@tx2] + shl eax,SHIFT + cdq + idiv ebx + mov [@@dx23],eax ; dx23 = (x3-x2)/(y3-y2) + + mov eax,[@@tex_x3] + sub eax,[@@tex_x2] + cdq + idiv ebx + mov [@@tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2) + + mov eax,[@@tex_y3] + sub eax,[@@tex_y2] + cdq + idiv ebx + mov [@@tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2) + + mov eax,[@@tz3] + sub eax,[@@tz2] + shl eax,SHIFT + cdq + idiv ebx + mov [@@z_dy23],eax +tt_dx23_done: + + + mov eax,[@@tx1] + shl eax,SHIFT + mov ebx,eax + mov ecx,[@@ty1] + + mov edx,[@@tz1] + shl edx,SHIFT + mov [@@scan_z1],edx + mov [@@scan_z2],edx + + mov edx,[@@tex_x1] + mov [@@scan_x1],edx + mov [@@scan_x2],edx + mov edx,[@@tex_y1] + mov [@@scan_y1],edx + mov [@@scan_y2],edx + +; **************** + mov edx,[@@ty1] ;skip equals + cmp [@@ty2],edx + je tt_loop1_end + + mov ebp,[@@ty1] + cmp ebp,0 + jg no_up_clip + neg ebp + mov edx,[@@ty2] + cmp edx,0 + jg no_sbx + neg edx + sub ebp,edx +no_sbx: + + mov edx,[@@tex_dx13] + imul edx,ebp + add [@@scan_x1],edx + mov edx,[@@tex_dx12] + imul edx,ebp + add [@@scan_x2],edx + mov edx,[@@tex_dy13] + imul edx,ebp + add [@@scan_y1],edx + mov edx,[@@tex_dy12] + imul edx,ebp + add [@@scan_y2],edx + + mov edx,[@@z_dy13] + imul edx,ebp + add [@@scan_z1],edx + mov edx,[@@z_dy12] + imul edx,ebp + add [@@scan_z2],edx + + mov edx,[@@dx13] + imul edx,ebp + add eax,edx + mov edx,[@@dx12] + imul edx,ebp + add ebx,edx + add ecx,ebp +no_up_clip: + + cmp [@@ty2],0 + jl tt_loop1_end + +tt_loop1: + cmp ecx,SCREEN_Y + jge tt_loop2_end + + pushad + mov edx,[@@scan_y2] + mov [@@tex_ly2],edx ;push dx + mov edx,[@@scan_x2] + mov [@@tex_lx2],edx ;push dx + mov edx,[@@scan_y1] + mov [@@tex_ly1],edx ;push dx + mov edx,[@@scan_x1] + mov [@@tex_lx1],edx ;push dx + + mov edx,[@@scan_z1] + mov [@@lz1],edx + mov edx,[@@scan_z2] + mov [@@lz2],edx + + mov [@@ly],ecx ;push cx + mov edx,ebx + sar edx,SHIFT + mov [@@lx2],edx ;push dx + mov edx,eax + sar edx,SHIFT + mov [@@lx1],edx ; push dx + call textured_horizontal_line + popad + + mov edx,[@@tex_dx13] + add [@@scan_x1],edx + mov edx,[@@tex_dx12] + add [@@scan_x2],edx + mov edx,[@@tex_dy13] + add [@@scan_y1],edx + mov edx,[@@tex_dy12] + add [@@scan_y2],edx + + mov edx,[@@z_dy13] + add [@@scan_z1],edx + mov edx,[@@z_dy12] + add [@@scan_z2],edx + + add eax,[@@dx13] + add ebx,[@@dx12] + inc ecx + cmp ecx,[@@ty2] + jl tt_loop1 + +tt_loop1_end: + + mov ebx,[@@tx2] + shl ebx,SHIFT + mov ecx,[@@ty2] + + mov edx,[@@tz2] + shl edx,SHIFT + mov [@@scan_z2],edx + + mov edx,[@@tex_x2] + mov [@@scan_x2],edx + mov edx,[@@tex_y2] + mov [@@scan_y2],edx + + mov ebp,[@@ty2] + cmp ebp,0 + jg no_down_clip + neg ebp + dec ebp + + mov edx,[@@tex_dx13] + imul edx,ebp + add [@@scan_x1],edx + mov edx,[@@tex_dx23] + imul edx,ebp + add [@@scan_x2],edx + mov edx,[@@tex_dy13] + imul edx,ebp + add [@@scan_y1],edx + mov edx,[@@tex_dy23] + imul edx,ebp + add [@@scan_y2],edx + + mov edx,[@@z_dy13] + imul edx,ebp + add [@@scan_z1],edx + mov edx,[@@z_dy23] + imul edx,ebp + add [@@scan_z2],edx + + mov edx,[@@dx13] + imul edx,ebp + add eax,edx + mov edx,[@@dx23] + imul edx,ebp + add ebx,edx + add ecx,ebp +no_down_clip: + +tt_loop2: + cmp ecx,SCREEN_Y + jge tt_loop2_end + + pushad + mov edx,[@@scan_y2] + mov [@@tex_ly2],edx ;push dx + mov edx,[@@scan_x2] + mov [@@tex_lx2],edx ;push dx + mov edx,[@@scan_y1] + mov [@@tex_ly1],edx ;push dx + mov edx,[@@scan_x1] + mov [@@tex_lx1],edx ;push dx + + mov edx,[@@scan_z1] + mov [@@lz1],edx + mov edx,[@@scan_z2] + mov [@@lz2],edx + + mov [@@ly],ecx ;push cx + mov edx,ebx + sar edx,SHIFT + mov [@@lx2],edx ;push dx + mov edx,eax + sar edx,SHIFT + mov [@@lx1],edx ; push dx + call textured_horizontal_line + popad + + mov edx,[@@tex_dx13] + add [@@scan_x1],edx + mov edx,[@@tex_dx23] + add [@@scan_x2],edx + mov edx,[@@tex_dy13] + add [@@scan_y1],edx + mov edx,[@@tex_dy23] + add [@@scan_y2],edx + + mov edx,[@@z_dy13] + add [@@scan_z1],edx + mov edx,[@@z_dy23] + add [@@scan_z2],edx + + add eax,[@@dx13] + add ebx,[@@dx23] + inc ecx + cmp ecx,[@@ty3] + jl tt_loop2 + +tt_loop2_end: + ret + +align 512 +@@lx1 dd 0 +align 512 +@@lx2 dd 0 +align 512 +@@ly dd 0 + +@@lz1 dd 0 +@@lz2 dd 0 +@@z_dx dd 0 + +align 512 +@@tex_loff dd 0 ;equ [bp+10] +@@tex_lx1 dd 0 ;equ [bp+12] +@@tex_ly1 dd 0 ;equ [bp+14] +@@tex_lx2 dd 0 ;equ [bp+16] +@@tex_ly2 dd 0 ;equ [bp+18] + +align 512 +@@tex_ldx dd 0 ;equ [bp-2] +@@tex_ldy dd 0 ;equ [bp-4] + +align 1024 +textured_horizontal_line: + + mov eax,[@@lx1] + cmp eax,[@@lx2] + je thl_quit + jl thl_ok + + xchg eax,[@@lx2] + mov [@@lx1],eax + + mov eax,[@@lz1] + xchg eax,[@@lz2] + mov [@@lz1],eax + + mov eax,[@@tex_lx1] + xchg eax,[@@tex_lx2] + mov [@@tex_lx1],eax + + mov eax,[@@tex_ly1] + xchg eax,[@@tex_ly2] + mov [@@tex_ly1],eax + +thl_ok: + + cmp [@@lx2],0 + jle thl_quit + mov eax,SCREEN_X + cmp [@@lx1],eax + jge thl_quit + + mov ecx,[@@lx2] + sub ecx,[@@lx1] + + ; Uneversal method + mov edi,[@@ly] + mov eax,SCREEN_X ;di = ly*320+lx1 + imul edi + add eax,[@@lx1] + imul eax,3 + mov edi,eax + add edi,I_END + + ;Right side clipping + mov eax,SCREEN_X + cmp [@@lx2],eax + jnge x1ok + mov edx,SCREEN_X + dec edx + sub edx,[@@lx1] + cmp edx,0 + jle thl_quit + mov ecx,edx +x1ok: + + ;Left side clipping + cmp [@@lx1],0 + jg x2ok + mov ecx,[@@lx2] ;cmp lx2 screen x if above cut (for future) + mov edi,[@@ly] + mov eax,SCREEN_X + imul edi,eax + imul edi,3 + add edi,I_END +x2ok: + + mov ebx,[@@lx2] + sub ebx,[@@lx1] + + mov eax,[@@tex_lx2] + sub eax,[@@tex_lx1] + cdq + idiv ebx + mov [@@tex_ldx],eax ; tex_dx = (tex_x2-tex_x1)/(x2-x1) + + mov eax,[@@tex_ly2] + sub eax,[@@tex_ly1] + cdq + idiv ebx + mov [@@tex_ldy],eax ; tex_dy = (tex_y2-tex_y1)/(x2-x1) + + mov eax,[@@lz2] + sub eax,[@@lz1] + cdq + idiv ebx + mov [@@z_dx],eax ; tex_dx = (tex_x2-tex_x1)/(x2-x1) + + ; Left clipping post correction + cmp [@@lx1],0 + jg no_lcpc + mov eax,[@@lx1] + neg eax + mov ebp,[@@tex_ldx] + imul ebp,eax + add [@@tex_lx1],ebp + mov ebp,[@@tex_ldy] + imul ebp,eax + add [@@tex_ly1],ebp + mov ebp,[@@z_dx] + imul ebp,eax + add [@@lz1],ebp +no_lcpc: + + inc ecx ;for equal correction + mov edx,[@@tex_lx1] + mov ebx,[@@tex_ly1] + mov esi,[@@lz1] + +thl_loop: + mov ebp,esi + shr ebp,SHIFT + mov eax,dword [edi-I_END+zbuffer] + cmp ax,bp + jb no_set + mov [edi-I_END+zbuffer],bp + + mov eax,edx +; and eax,0x0fff0000 + ror ebx,16 + mov ax,bx + ror ebx,16 + shl ax,11 ; 8 for 256*256, 9 for 128*128 ... + shr eax,11 + lea eax,[eax*2+eax] ; equ imul eax,3 + add eax,[@@tex_off] + mov ebp,eax + + mov ax,word [ebp] + mov [edi],ax + mov al,byte [ebp+2] + mov [edi+2],al + +no_set: + add edi,3 + + add esi,[@@z_dx] + add edx,[@@tex_ldx] + add ebx,[@@tex_ldy] + dec ecx + jnz thl_loop +thl_quit: + ret + + +@@rgb dd 0 +@@rgbax dw 0 +@@rgbbl db 0 + +; === DATA === + +d_angle dd 0.19634954 ;pi/16 +angle dd 0.0 +mul_wave dd 1.5 + +sin_pos dw 0 +sinwave rw 256 + +Xmap dd 0 +Ymap dd 0 +mapoff dd 0 + +Xcam dd 0 +Ycam dd 0 +Zcam dd -400 + +Xcamangle dd 0 +Ycamangle dd 0 +Zcamangle dd 0 + +Xcamsin dd 0 +Xcamcos dd 0 +Ycamsin dd 0 +Ycamcos dd 0 +Zcamsin dd 0 +Zcamcos dd 0 + +X dd ? ; X,Y,Z variable for formula +Y dd ? +Z dd ? + +Xp dd ? +Yp dd ? + +Xangle dd 0 ; Angle to rotate around x +Yangle dd 0 +Zangle dd 0 + +DeltaX dd 1 ; x,y,z rotation angle +DeltaY dd 1 +DeltaZ dd 1 + +Xoff dd 256 ; x-cord +Yoff dd 256 ; y-cord +Zoff dd 0;800 ; Distance from viewer + +Xsin dd ? ; Sine and cosine of angle to rotate around +Xcos dd ? +Ysin dd ? +Ycos dd ? +Zsin dd ? +Zcos dd ? + +Mx dd SCREEN_X/2 ; Center of the screen +My dd SCREEN_Y/2 + +autorot db 0 ;Auto rotation flag +massize dd 0 ;Size of triangle massive +id dd 0 +temp dd 0 + +; DATA AREA +labelt: + db '3D TEXTURED ENGINE' +labellen: + + +;Texture pusck 32*32 256 +texpack_gif: +file 'texpack.gif' +rb 50 + +;Ground texture +bmp_texmap: +file 'texmap.bmp' +rb 50 + + +; Ground livel map +gif_file_area5: +file 'map.gif' ;level map +rb 50 + +rb 8 +texture_limg: +rb 4095 +texture_img: +rb 4095 +texture_img2: +rb 4095 + +rb (4095)*16*16 + +img_area: +rb 128*128*3+8 + +glm_img_area: +rb (MAP_XSIZE+1)*(MAP_YSIZE+1)*3+8 + +rb 8 + +texpack_img: +rb 512*512*3+8 + +keymap: +rb 1000 + +model_mas: +rb 4+8*100 + +; Hash area for decoding GIF +gif_hash_area: +rd 4096+1 + +MAX_MODEL_POINTS = 100 +modelpoints: +rb MAX_MODEL_POINTS*3*4 + +; Matrix points massive +points: +; Massive of turn matrix points +tpoints=points+((MATRIX_XSIZE+1)*(MATRIX_YSIZE+1)*3*4) +; Ground level map massive +ground_level_map=tpoints+((MATRIX_XSIZE+1)*(MATRIX_YSIZE+1)*3*4) +; zbuffer +zbuffer=ground_level_map+((MAP_XSIZE+1)*(MAP_YSIZE+1)*4) +I_END=zbuffer+(SCREEN_X*SCREEN_Y)*3 diff --git a/programs/demos/3detx60b/trunk/Tupfile.lua b/programs/demos/3detx60b/Tupfile.lua similarity index 79% rename from programs/demos/3detx60b/trunk/Tupfile.lua rename to programs/demos/3detx60b/Tupfile.lua index ebb3a7362..df5818f2e 100644 --- a/programs/demos/3detx60b/trunk/Tupfile.lua +++ b/programs/demos/3detx60b/Tupfile.lua @@ -1,5 +1,5 @@ if tup.getconfig("NO_FASM") ~= "" then return end -HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR") +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_fasm.lua") add_include(tup.getvariantdir()) diff --git a/programs/demos/3detx60b/trunk/ascgl.inc b/programs/demos/3detx60b/ascgl.inc similarity index 100% rename from programs/demos/3detx60b/trunk/ascgl.inc rename to programs/demos/3detx60b/ascgl.inc diff --git a/programs/demos/3detx60b/trunk/ascl.inc b/programs/demos/3detx60b/ascl.inc similarity index 100% rename from programs/demos/3detx60b/trunk/ascl.inc rename to programs/demos/3detx60b/ascl.inc diff --git a/programs/demos/3detx60b/trunk/build_en.bat b/programs/demos/3detx60b/build_en.bat similarity index 100% rename from programs/demos/3detx60b/trunk/build_en.bat rename to programs/demos/3detx60b/build_en.bat diff --git a/programs/demos/3detx60b/trunk/build_ru.bat b/programs/demos/3detx60b/build_ru.bat similarity index 100% rename from programs/demos/3detx60b/trunk/build_ru.bat rename to programs/demos/3detx60b/build_ru.bat diff --git a/programs/demos/3detx60b/trunk/map.gif b/programs/demos/3detx60b/map.gif similarity index 100% rename from programs/demos/3detx60b/trunk/map.gif rename to programs/demos/3detx60b/map.gif diff --git a/programs/demos/3detx60b/trunk/texmap.bmp b/programs/demos/3detx60b/texmap.bmp similarity index 100% rename from programs/demos/3detx60b/trunk/texmap.bmp rename to programs/demos/3detx60b/texmap.bmp diff --git a/programs/demos/3detx60b/trunk/texpack.gif b/programs/demos/3detx60b/texpack.gif similarity index 100% rename from programs/demos/3detx60b/trunk/texpack.gif rename to programs/demos/3detx60b/texpack.gif diff --git a/programs/demos/3dsheart/trunk/3dmath.asm b/programs/demos/3dsheart/3dmath.asm similarity index 100% rename from programs/demos/3dsheart/trunk/3dmath.asm rename to programs/demos/3dsheart/3dmath.asm diff --git a/programs/demos/3dsheart/trunk/3dsheart.asm b/programs/demos/3dsheart/3dsheart.asm similarity index 100% rename from programs/demos/3dsheart/trunk/3dsheart.asm rename to programs/demos/3dsheart/3dsheart.asm diff --git a/programs/demos/3dsheart/trunk/Tupfile.lua b/programs/demos/3dsheart/Tupfile.lua similarity index 100% rename from programs/demos/3dsheart/trunk/Tupfile.lua rename to programs/demos/3dsheart/Tupfile.lua diff --git a/programs/demos/3dsheart/trunk/b_procs.asm b/programs/demos/3dsheart/b_procs.asm similarity index 100% rename from programs/demos/3dsheart/trunk/b_procs.asm rename to programs/demos/3dsheart/b_procs.asm diff --git a/programs/demos/3dsheart/trunk/build.bat b/programs/demos/3dsheart/build.bat similarity index 100% rename from programs/demos/3dsheart/trunk/build.bat rename to programs/demos/3dsheart/build.bat diff --git a/programs/demos/3dsheart/trunk/bump3.asm b/programs/demos/3dsheart/bump3.asm similarity index 100% rename from programs/demos/3dsheart/trunk/bump3.asm rename to programs/demos/3dsheart/bump3.asm diff --git a/programs/demos/3dsheart/trunk/bump_cat.ASM b/programs/demos/3dsheart/bump_cat.ASM similarity index 100% rename from programs/demos/3dsheart/trunk/bump_cat.ASM rename to programs/demos/3dsheart/bump_cat.ASM diff --git a/programs/demos/3dsheart/trunk/flat3.asm b/programs/demos/3dsheart/flat3.asm similarity index 100% rename from programs/demos/3dsheart/trunk/flat3.asm rename to programs/demos/3dsheart/flat3.asm diff --git a/programs/demos/3dsheart/trunk/flat_cat.ASM b/programs/demos/3dsheart/flat_cat.ASM similarity index 100% rename from programs/demos/3dsheart/trunk/flat_cat.ASM rename to programs/demos/3dsheart/flat_cat.ASM diff --git a/programs/demos/3dsheart/trunk/grd3.asm b/programs/demos/3dsheart/grd3.asm similarity index 100% rename from programs/demos/3dsheart/trunk/grd3.asm rename to programs/demos/3dsheart/grd3.asm diff --git a/programs/demos/3dsheart/trunk/grd_cat.ASM b/programs/demos/3dsheart/grd_cat.ASM similarity index 100% rename from programs/demos/3dsheart/trunk/grd_cat.ASM rename to programs/demos/3dsheart/grd_cat.ASM diff --git a/programs/demos/3dsheart/trunk/hrt.3ds b/programs/demos/3dsheart/hrt.3ds similarity index 100% rename from programs/demos/3dsheart/trunk/hrt.3ds rename to programs/demos/3dsheart/hrt.3ds diff --git a/programs/demos/3dsheart/trunk/tex3.ASM b/programs/demos/3dsheart/tex3.ASM similarity index 100% rename from programs/demos/3dsheart/trunk/tex3.ASM rename to programs/demos/3dsheart/tex3.ASM diff --git a/programs/demos/3dsheart/trunk/tex_cat.ASM b/programs/demos/3dsheart/tex_cat.ASM similarity index 100% rename from programs/demos/3dsheart/trunk/tex_cat.ASM rename to programs/demos/3dsheart/tex_cat.ASM diff --git a/programs/demos/3dspiral/trunk/3dspiral.asm b/programs/demos/3dspiral/3dspiral.asm similarity index 100% rename from programs/demos/3dspiral/trunk/3dspiral.asm rename to programs/demos/3dspiral/3dspiral.asm diff --git a/programs/demos/3dspiral/trunk/Tupfile.lua b/programs/demos/3dspiral/Tupfile.lua similarity index 100% rename from programs/demos/3dspiral/trunk/Tupfile.lua rename to programs/demos/3dspiral/Tupfile.lua diff --git a/programs/demos/3dspiral/trunk/build.bat b/programs/demos/3dspiral/build.bat similarity index 100% rename from programs/demos/3dspiral/trunk/build.bat rename to programs/demos/3dspiral/build.bat diff --git a/programs/demos/3dtcub10/trunk/3DTCUB10.ASM b/programs/demos/3dtcub10/3DTCUB10.ASM similarity index 93% rename from programs/demos/3dtcub10/trunk/3DTCUB10.ASM rename to programs/demos/3dtcub10/3DTCUB10.ASM index bd1776280..2fd9912b2 100644 --- a/programs/demos/3dtcub10/trunk/3DTCUB10.ASM +++ b/programs/demos/3dtcub10/3DTCUB10.ASM @@ -1,939 +1,942 @@ -; -; 9 Ver Screen saver -; 5 Ver 24 bit texture. -; 23/8/2004 -; Pavlushin Evgeni 3d cube screen saver -; mail: waptap@mail.ru site: www.deck4.narod.ru -; -; This programm develop on sample text3d to Mikolaj Felix 25/5/2001 -; mfelix@polbox.com -; - -use32 - org 0x0 - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd START ; start of code - dd I_END ; size of image - dd 0x200000 ; memory for app - dd 0x200000 ; esp - dd 0x0 , 0x0 ; I_Param , I_Icon - -include 'lang.inc' -include '..\..\..\macros.inc' -MAX_DEGS equ 512 ;quantity of angels 2^n.Minimize for speedup -MAX_POINTS equ 8 ;quantity of points -MAX_FACES equ 6 ;quantity of points - -START: - finit - call draw_window - call clear_screen - call init_sincos - -still: - mov eax,23 ; wait for system event with 2 ms timeout - mov ebx,2 ; wait 2 ms, then continue - mcall - -; mov eax,11 ;If you want maximum speed! :) -; mcall - - dec eax ; window redraw request ? - je red - dec eax ; key in buffer ? - je key - dec eax ; button in buffer ? - je button - -main_loop: - call fade_texture - - mov esi,cube - mov edi,cube_rotated - mov ecx,MAX_POINTS*3 -copy_object: - fild word [esi] - fstp dword [edi] - add esi,2 - add edi,4 - dec ecx - jnz copy_object - - mov esi,angle_x - mov edi,cube_rotated - mov ecx,MAX_POINTS - call rotate_points - - mov esi,cube_rotated - mov edi,coord2d - mov ecx,MAX_POINTS - call translate_points - - call draw_textured_faces - call clear_screen_buffer - - add [angle_x],1 - add [angle_y],3 - add [angle_z],1 - - jmp still - -red: - call draw_window - jmp still -key: - mov eax,2 - jmp exit -button: - mov eax,17 - mcall - cmp ah,1 - jne still -exit: - mov eax,-1 - mcall - -;Draw window -draw_window: - mov eax,12 ;Start - mov ebx,1 - mcall - - mov eax,0 ;Draw window - mov ebx,0*65536+(799) ;x start*65536+x size - mov ecx,0*65536+(599) ;y start*65536+y size - mov edx,0x00000000 ;0x03 use skinned window - mcall - - call clear_screen - - mov eax,12 ;End - mov ebx,2 - mcall - ret - -head_label: db "3D TEXTURED CUBE THE LITTLE SCREEN SAVER FOR MENUETOS. USE " - db "800x600 SCREEN MODE FROM VIEW. PRESS ANY KEY FOR EXIT" -hl_end: - -;FADE IN FADE OUT TEXTURE - -x_step db 0 -x_num db 1 - -fade_texture: - mov ecx,0 -loox: - mov al,[file_texture+ecx] - mov [texture+ecx],al - inc ecx - cmp ecx,128*128*3 - jnae loox - - mov ecx,0 -loox2: - mov al,[file_texture+ecx] - cmp [x_step],al - jae xxx - sub al,[x_step] - jmp nnn -xxx: - mov al,0 -nnn: - mov [texture+ecx],al - inc ecx - cmp ecx,128*128*3 - jnae loox2 - - cmp [x_step],255 - jne no_max - mov [x_num],-1 -no_max: - cmp [x_step],0 - jne no_min - mov [x_num],1 -no_min: - mov al,[x_num] - add [x_step],al - ret - -; Clear Screen -clear_screen: - mov eax,13 - mov ebx,0*65536+800 - mov ecx,0*65536+600 - mov edx,0 - mcall - - mov eax,4 ;Out Text - mov ebx,8*65536+8 ;x start*65536+y start - mov ecx,0x00ffffff ;color White - mov edx,head_label - mov esi,hl_end-head_label - mcall - ret - -clear_screen_buffer: - mov ebx,scrbuf - mov ecx,800*65536+(600-40) ;sub 40 for antiflickering title - mov edx,0*65536+40 - mov eax,7 - mcall - - mov eax,4 ;Out Text - mov ebx,8*65536+580 ;x start*65536+y start - mov ebp,[n_step] - shl ebp,16 - sub ebx,ebp - mov ecx,0x0000ff00 ;color White - mov edx,move_text - add edx,[step] - mov esi,130 ;mt_end-move_text - mcall - - inc [n_step] - cmp [n_step],6 - jna t_ok - mov [n_step],0 - inc [step] - cmp [step],mt_end-move_text-130 - jng t_ok - mov [step],0 -t_ok: - - mov edi,scrbuf - mov eax,0 ;black background - mov ecx,800*600*3/4 ; 16000 - cld - rep stosd - ret - -n_step dd 0 -step dd 0 - -move_text: db " " - db " " - db " " - db "***** 3D TEXTURED CUBE THE LITTLE SCREEN SAVER FOR " - db "MENUET OS. SET 800x600 SCREEN MODE FROM VIEW THIS SCREEN " - db "SAVER ***** " - db "SITE OF THE RUSSIAN DEVELOPERS TO MENUETOS: " - db "www.menuet.narod.ru " - db "RUSSIAN MENUET APLICATION ARCHIVE PAGE ON: " - db "www.meosfiles.narod.ru " - db "AUTOR OF THIS SCREEN SAVER Pavlushin Evgeni " - db "MY SITE: www.deck4.narod.ru (Slow update) " - db "AND MAIL BOX: waptap@mail.ru " - db "THANK YOU FOR USE! " - db " " - db " " - db " " -mt_end: - - -;include graphlib.asm Mikolaj Felix 9/12/2000 mfelix@polbox.com -;Draw textured faces proc - -@@rx1 dw 0 ;equ [bp-2] -@@ry1 dw 0 ;equ [bp-4] -@@rx2 dw 0 ;equ [bp-6] -@@ry2 dw 0 ;equ [bp-8] -@@rx3 dw 0 ;equ [bp-10] -@@ry3 dw 0 ;equ [bp-12] -@@rx4 dw 0 ;equ [bp-14] -@@ry4 dw 0 ;equ [bp-16] - -draw_textured_faces: - - mov esi,link - mov ecx,MAX_FACES -dtf_loop: - push ecx - - xor ebx,ebx - mov bl,byte [esi] ; point 1 - shl bx,2 - mov eax,dword [coord2d+bx] ;COPY 1 FOURANGLE POINT - mov dword [@@rx1],eax - - xor ebx,ebx - mov bl,byte [esi+1] ; point 2 - shl bx,2 - mov eax,dword [coord2d+bx] ;COPY 2 FOURANGLE POINT - mov dword [@@rx2],eax - - xor ebx,ebx - mov bl,byte [esi+2] ; point 3 - shl bx,2 - mov eax,dword [coord2d+bx] ;COPY 3 FOURANGLE POINT - mov dword [@@rx3],eax - - xor bh,bh ; point 4 - mov bl,byte [esi+3] - shl bx,2 - mov eax,dword [coord2d+bx] ;COPY 4 FOURANGLE POINT - mov dword [@@rx4],eax - - mov ax,[@@ry1] - sub ax,[@@ry3] - mov bx,[@@rx2] - sub bx,[@@rx1] - imul bx - shl edx,16 - mov dx,ax - push edx - mov ax,[@@rx1] - sub ax,[@@rx3] - mov bx,[@@ry2] - sub bx,[@@ry1] - imul bx - shl edx,16 - mov dx,ax - pop ebx - sub ebx,edx ; normal_z = (y1-y3)*(x2-x1)-(x1-x3)*(y2-y1) - or ebx,ebx - jl dtf_next_face ; normal_z < 0 - - ; FIRST PICE OF FOUR ANGLE - - ; Set 3 triangel puts for texture ycoord*65536+xcoord - mov dword [@@tex_x3],127*65536+127 ;3 point - mov dword [@@tex_x2],0*65536+127 ;2 point - mov dword [@@tex_x1],0*65536+0 ;1 point - ; Set texture bitmap offset - mov [@@tex_off],texture - ; Set 3 triangel puts coordinates - mov eax,dword [@@rx3] - mov dword [@@x3],eax - mov eax,dword [@@rx2] - mov dword [@@x2],eax - mov eax,dword [@@rx1] - mov dword [@@x1],eax - call textured_triangle - - ; SECOND PICE OF FOUR ANGLE - - ; Set 3 triangel puts for texture ycoord*65536+xcoord - mov dword [@@tex_x3],127*65536+0 ;3 point - mov dword [@@tex_x2],127*65536+127 ;2 point - mov dword [@@tex_x1],0*65536+0 ;1 point - ; Set texture bitmap offset - mov [@@tex_off],texture - ; Set 3 triangel puts coordinates - mov eax,dword [@@rx4] - mov dword [@@x3],eax - mov eax,dword [@@rx3] - mov dword [@@x2],eax - mov eax,dword [@@rx1] - mov dword [@@x1],eax - call textured_triangle - -dtf_next_face: - add esi,4 - pop ecx - dec ecx - jnz dtf_loop - ret - -;include tex3.asm Mikolaj Felix 15/5/2001 mfelix@polbox.com - -@@x1 dw 0 ;equ [bp+4] -@@y1 dw 0 ;equ [bp+6] -@@x2 dw 0 ;equ [bp+8] -@@y2 dw 0 ;equ [bp+10] -@@x3 dw 0 ;equ [bp+12] -@@y3 dw 0 ;equ [bp+14] - -@@tex_off dd 0 ;equ [bp+16] -@@tex_x1 dw 0 ;equ [bp+18] -@@tex_y1 dw 0 ;equ [bp+20] -@@tex_x2 dw 0 ;equ [bp+22] -@@tex_y2 dw 0 ;equ [bp+24] -@@tex_x3 dw 0 ;equ [bp+26] -@@tex_y3 dw 0 ;equ [bp+28] - -@@dx12 dw 0 ;equ [bp-2] -@@dx13 dw 0 ;equ [bp-4] -@@dx23 dw 0 ;equ [bp-6] - -@@tex_dx12 dw 0 ;equ [bp-8] -@@tex_dy12 dw 0 ;equ [bp-10] -@@tex_dx13 dw 0 ;equ [bp-12] -@@tex_dy13 dw 0 ;equ [bp-14] -@@tex_dx23 dw 0 ;equ [bp-16] -@@tex_dy23 dw 0 ;equ [bp-18] - -@@scan_x1 dw 0 ;equ [bp-20] -@@scan_y1 dw 0 ;equ [bp-22] -@@scan_x2 dw 0 ;equ [bp-24] -@@scan_y2 dw 0 ;equ [bp-26] - - -textured_triangle: - - mov ax,[@@y1] - cmp ax,[@@y3] - jb tt_check1 - - xchg ax,[@@y3] - mov [@@y1],ax - - mov ax,[@@x1] - xchg ax,[@@x3] - mov [@@x1],ax - - mov ax,[@@tex_y1] - xchg ax,[@@tex_y3] - mov [@@tex_y1],ax - - mov ax,[@@tex_x1] - xchg ax,[@@tex_x3] - mov [@@tex_x1],ax -tt_check1: - mov ax,[@@y2] - cmp ax,[@@y3] - jb tt_check2 - - xchg ax,[@@y3] - mov [@@y2],ax - - mov ax,[@@x2] - xchg ax,[@@x3] - mov [@@x2],ax - - mov ax,[@@tex_y2] - xchg ax,[@@tex_y3] - mov [@@tex_y2],ax - - mov ax,[@@tex_x2] - xchg ax,[@@tex_x3] - mov [@@tex_x2],ax -tt_check2: - mov ax,[@@y1] - cmp ax,[@@y2] - jb tt_check3 - - xchg ax,[@@y2] - mov [@@y1],ax - - mov ax,[@@x1] - xchg ax,[@@x2] - mov [@@x1],ax - - mov ax,[@@tex_y1] - xchg ax,[@@tex_y2] - mov [@@tex_y1],ax - - mov ax,[@@tex_x1] - xchg ax,[@@tex_x2] - mov [@@tex_x1],ax -tt_check3: - - mov bx,[@@y2] - sub bx,[@@y1] - jnz tt_dx12_make - - mov word [@@dx12],0 - mov word [@@tex_dx12],0 - mov word [@@tex_dy12],0 - jmp tt_dx12_done -tt_dx12_make: - mov ax,[@@x2] - sub ax,[@@x1] - shl ax,7 - cwd - idiv bx - mov [@@dx12],ax ; dx12 = (x2-x1)/(y2-y1) - - mov ax,[@@tex_x2] - sub ax,[@@tex_x1] - shl ax,7 - cwd - idiv bx - mov [@@tex_dx12],ax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1) - - mov ax,[@@tex_y2] - sub ax,[@@tex_y1] - shl ax,7 - cwd - idiv bx - mov [@@tex_dy12],ax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1) -tt_dx12_done: - - mov bx,[@@y3] - sub bx,[@@y1] - jnz tt_dx13_make - - mov word [@@dx13],0 - mov word [@@tex_dx13],0 - mov word [@@tex_dy13],0 - jmp tt_dx13_done -tt_dx13_make: - mov ax,[@@x3] - sub ax,[@@x1] - shl ax,7 - cwd - idiv bx - mov [@@dx13],ax ; dx13 = (x3-x1)/(y3-y1) - - mov ax,[@@tex_x3] - sub ax,[@@tex_x1] - shl ax,7 - cwd - idiv bx - mov [@@tex_dx13],ax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1) - - mov ax,[@@tex_y3] - sub ax,[@@tex_y1] - shl ax,7 - cwd - idiv bx - mov [@@tex_dy13],ax ; tex_dy13 = (tex_y3-tex_x1)/(y3-y1) -tt_dx13_done: - - mov bx,[@@y3] - sub bx,[@@y2] - jnz tt_dx23_make - - mov word [@@dx23],0 - mov word [@@tex_dx23],0 - mov word [@@tex_dy23],0 - jmp tt_dx23_done -tt_dx23_make: - mov ax,[@@x3] - sub ax,[@@x2] - shl ax,7 - cwd - idiv bx - mov [@@dx23],ax ; dx23 = (x3-x2)/(y3-y2) - - mov ax,[@@tex_x3] - sub ax,[@@tex_x2] - shl ax,7 - cwd - idiv bx - mov [@@tex_dx23],ax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2) - - mov ax,[@@tex_y3] - sub ax,[@@tex_y2] - shl ax,7 - cwd - idiv bx - mov [@@tex_dy23],ax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2) -tt_dx23_done: - - - mov ax,[@@x1] - shl ax,7 - mov bx,ax - mov cx,[@@y1] - - mov dx,[@@tex_x1] - shl dx,7 - mov [@@scan_x1],dx - mov [@@scan_x2],dx - mov dx,[@@tex_y1] - shl dx,7 - mov [@@scan_y1],dx - mov [@@scan_y2],dx -tt_loop1: - pushad -; push ax -; push bx -; push cx - - mov dx,[@@scan_y2] - shr dx,7 - mov [@@tex_ly2],dx ;push dx - mov dx,[@@scan_x2] - shr dx,7 - mov [@@tex_lx2],dx ;push dx - mov dx,[@@scan_y1] - shr dx,7 - mov [@@tex_ly1],dx ;push dx - mov dx,[@@scan_x1] - shr dx,7 - mov [@@tex_lx1],dx ;push dx - mov ebp,dword [@@tex_off] ;push word ptr @@tex_off - mov [@@tex_loff],ebp - - mov [@@ly],cx ;push cx - mov dx,bx - shr dx,7 - mov [@@lx2],dx ;push dx - mov dx,ax - shr dx,7 - mov [@@lx1],dx ; push dx - call textured_horizontal_line - -; pop cx -; pop bx -; pop ax - popad - - mov dx,[@@tex_dx13] - add [@@scan_x1],dx - mov dx,[@@tex_dx12] - add [@@scan_x2],dx - mov dx,[@@tex_dy13] - add [@@scan_y1],dx - mov dx,[@@tex_dy12] - add [@@scan_y2],dx - - add ax,[@@dx13] - add bx,[@@dx12] - inc cx - cmp cx,[@@y2] - jb tt_loop1 - - mov bx,[@@x2] - shl bx,7 - mov cx,[@@y2] - - mov dx,[@@tex_x2] - shl dx,7 - mov [@@scan_x2],dx - mov dx,[@@tex_y2] - shl dx,7 - mov [@@scan_y2],dx -tt_loop2: - - pushad -; push ax -; push bx -; push cx - - mov dx,[@@scan_y2] - shr dx,7 - mov [@@tex_ly2],dx ;push dx - mov dx,[@@scan_x2] - shr dx,7 - mov [@@tex_lx2],dx ;push dx - mov dx,[@@scan_y1] - shr dx,7 - mov [@@tex_ly1],dx ;push dx - mov dx,[@@scan_x1] - shr dx,7 - mov [@@tex_lx1],dx ;push dx - mov ebp,dword [@@tex_off] ;push word ptr @@tex_off - mov [@@tex_loff],ebp - - mov [@@ly],cx ;push cx - mov dx,bx - shr dx,7 - mov [@@lx2],dx ;push dx - mov dx,ax - shr dx,7 - mov [@@lx1],dx ; push dx - call textured_horizontal_line - -; pop cx -; pop bx -; pop ax - popad - - mov dx,[@@tex_dx13] - add [@@scan_x1],dx - mov dx,[@@tex_dx23] - add [@@scan_x2],dx - mov dx,[@@tex_dy13] - add [@@scan_y1],dx - mov dx,[@@tex_dy23] - add [@@scan_y2],dx - - add ax,[@@dx13] - add bx,[@@dx23] - inc cx - cmp cx,[@@y3] - jb tt_loop2 - ret - -@@lx1 dw 0 ;equ [bp+4] -@@lx2 dw 0 ;equ [bp+6] -@@ly dw 0 ;equ [bp+8] - -@@tex_loff dd 0 ;equ [bp+10] -@@tex_lx1 dw 0 ;equ [bp+12] -@@tex_ly1 dw 0 ;equ [bp+14] -@@tex_lx2 dw 0 ;equ [bp+16] -@@tex_ly2 dw 0 ;equ [bp+18] - -@@tex_ldx dw 0 ;equ [bp-2] -@@tex_ldy dw 0 ;equ [bp-4] - -textured_horizontal_line: - - mov ax,[@@lx1] - cmp ax,[@@lx2] - je thl_quit - jb thl_ok - - xchg ax,[@@lx2] - mov [@@lx1],ax - - mov ax,[@@tex_lx1] - xchg ax,[@@tex_lx2] - mov [@@tex_lx1],ax - - mov ax,[@@tex_ly1] - xchg ax,[@@tex_ly2] - mov [@@tex_ly1],ax -thl_ok: - - ; Fast method -; mov edi,0 -; mov di,[@@ly] ;edi = calculating start of line -; mov ax,di -; shl di,6 ;ly*64 -; shl ax,8 ;ly*256 -; add di,ax ;di = (ly*64)+(ly*256) -; add di,[@@lx1] ;di = ly*320+lx1 -; mov eax,edi -; shl eax,1 -; add edi,eax -; add edi,scrbuf - - ; Uneversal method - movsx edi,[@@ly] - mov eax,800 ;di = ly*320+lx1 - mul edi - movsx ebx,[@@lx1] - add eax,ebx ;[@@lx1] - mov edi,3 - mul edi - mov edi,eax - add edi,scrbuf - - mov cx,[@@lx2] - sub cx,[@@lx1] - - mov ax,[@@tex_lx2] - sub ax,[@@tex_lx1] - shl ax,7 - cwd - idiv cx - mov [@@tex_ldx],ax ; tex_dx = (tex_x2-tex_x1)/(x2-x1) - - mov ax,[@@tex_ly2] - sub ax,[@@tex_ly1] - shl ax,7 - cwd - idiv cx - mov [@@tex_ldy],ax ; tex_dy = (tex_y2-tex_y1)/(x2-x1) - - cld - inc cx - mov ax,[@@tex_lx1] - shl ax,7 - mov bx,[@@tex_ly1] - shl bx,7 - -thl_loop: - mov dx,ax - push bx - - and bx,0ff80h - shr ax,7 - add bx,ax - mov ebp,0 - mov bp,bx - mov eax,ebp - shl eax,1 - add ebp,eax - add ebp,[@@tex_loff] - - mov al,byte [ebp+2] - stosb - mov al,byte [ebp+1] - stosb - mov al,byte [ebp] - stosb - - pop bx - mov ax,dx - - add ax,[@@tex_ldx] - add bx,[@@tex_ldy] - dec cx - jnz thl_loop -thl_quit: - ret - -;include math3d_2.asm -; Mikolaj Felix 20/06/2001 -; mfelix@polbox.com - -;------------------------------------------------------------ -; ds:si - offset to angles (int) -; ds:di - offset to array of 3d points -; cx - number of points -;------------------------------------------------------------ - -@@sin_x dd 0 ;equ dword ptr [bp-4] -@@cos_x dd 0 ;equ dword ptr [bp-8] -@@sin_y dd 0 ;equ dword ptr [bp-12] -@@cos_y dd 0 ;equ dword ptr [bp-16] -@@sin_z dd 0 ;equ dword ptr [bp-20] -@@cos_z dd 0 ;equ dword ptr [bp-24] - -@@x equ dword [edi] -@@y equ dword [edi+4] -@@z equ dword [edi+8] - -rotate_points: - - push edi - mov edi,@@sin_x - mov edx,3 -rp_sin_cos: - mov bx,word [esi] - and bx,MAX_DEGS-1 - shl bx,2 - mov eax,dword [sintab+bx] - mov dword [edi],eax - mov eax,dword [costab+bx] - mov dword [edi+4],eax - add edi,8 - add esi,2 - dec edx - jnz rp_sin_cos - pop edi - -rp_rotate: - fld @@y - fmul [@@cos_x] - fld @@z - fmul [@@sin_x] - fsubp st1,st - fld @@y - fxch st1 - fstp @@y ; Yrotated = Cos (A)*Y - Sin (A)*Z - fmul [@@sin_x] - fld @@z - fmul [@@cos_x] - faddp st1,st - fstp @@z ; Zrotated = Sin (A)*Y + Cos (A)*Z - - fld @@x - fmul [@@cos_y] - fld @@z - fmul [@@sin_y] - fsubp st1,st - fld @@x - fxch st1 - fstp @@x ; Xrotated = Cos (A)*X - Sin (A)*Z - fmul [@@sin_y] - fld @@z - fmul [@@cos_y] - faddp st1,st - fstp @@z ; Zrotated = Sin (A)*X + Cos (A)*Z - - fld @@x - fmul [@@cos_z] - fld @@y - fmul [@@sin_z] - fsubp st1,st - fld @@x - fxch st1 - fstp @@x ; Xrotated = Cos (A)*X - Sin (A)*Y - fmul [@@sin_z] - fld @@y - fmul [@@cos_z] - faddp st1,st - fstp @@y ; Yrotated = Sin (A)*X + Cos (A)*Y - - add edi,12 - dec ecx - jnz rp_rotate - ret - -;------------------------------------------------------------ -; ds:si - offset to array of 3d points -; ds:di - offset to 2d points -; cx - number of points -;------------------------------------------------------------ - -translate_points: - - fld dword [esi+8] - fadd [perspective] - - fld dword [esi] - fmul [perspective] - fdiv st,st1 - fadd [correct_x] - fistp word [edi] ; x2d = (x*persp)/(z+persp)+correct_x - - fld dword [esi+4] - fmul [perspective] - fdivrp st1,st - fadd [correct_y] - fistp word [edi+2] ; y2d = (y*persp)/(z+persp)+correct_y - - add esi,12 - add edi,4 - dec ecx - jnz translate_points - ret - -; initalize SIN&COS table - -@@temp1 dd 0 ;dword ptr [bp-4] -@@temp2 dd 0 ;dword ptr [bp-8] - -init_sincos: - mov [@@temp1],0 - fldpi - mov [@@temp2],MAX_DEGS/2 - fidiv [@@temp2] - fstp [@@temp2] - - xor edi,edi - mov ecx,MAX_DEGS -isc_loop: - fld [@@temp1] - fld st0 - fld st0 - fsin - fstp dword [sintab+edi] - fcos - fstp dword [costab+edi] - fadd [@@temp2] - fstp [@@temp1] - - add edi,4 - dec ecx - jnz isc_loop - ret - -perspective dd 256.0 -correct_x dd 400.0 -correct_y dd 300.0 - -angle_x dw 0 -angle_y dw 0 -angle_z dw 0 - -file_texture: -file 'texture.raw' - -cube dw -50,-50,50, 50,-50,50, 50,50,50, -50,50,50 - dw -50,-50,-50, 50,-50,-50, 50,50,-50, -50,50,-50 - -link db 0,1,2,3, 5,4,7,6, 1,5,6,2, 4,0,3,7, 4,5,1,0, 3,2,6,7 - -sintab: -rd MAX_DEGS -costab: -rd MAX_DEGS - -cube_rotated: -rd MAX_POINTS*3 -coord2d: -rw MAX_POINTS*2 -texture: -rb 128*128*3 -scrbuf: - -I_END: \ No newline at end of file +; SPDX-License-Identifier: NOASSERTION +; + +; +; 9 Ver Screen saver +; 5 Ver 24 bit texture. +; 23/8/2004 +; Pavlushin Evgeni 3d cube screen saver +; mail: waptap@mail.ru site: www.deck4.narod.ru +; +; This programm develop on sample text3d to Mikolaj Felix 25/5/2001 +; mfelix@polbox.com +; + +use32 + org 0x0 + db 'MENUET01' ; 8 byte id + dd 0x01 ; header version + dd START ; start of code + dd I_END ; size of image + dd 0x200000 ; memory for app + dd 0x200000 ; esp + dd 0x0 , 0x0 ; I_Param , I_Icon + +include 'lang.inc' +include '..\..\macros.inc' +MAX_DEGS equ 512 ;quantity of angels 2^n.Minimize for speedup +MAX_POINTS equ 8 ;quantity of points +MAX_FACES equ 6 ;quantity of points + +START: + finit + call draw_window + call clear_screen + call init_sincos + +still: + mov eax,23 ; wait for system event with 2 ms timeout + mov ebx,2 ; wait 2 ms, then continue + mcall + +; mov eax,11 ;If you want maximum speed! :) +; mcall + + dec eax ; window redraw request ? + je red + dec eax ; key in buffer ? + je key + dec eax ; button in buffer ? + je button + +main_loop: + call fade_texture + + mov esi,cube + mov edi,cube_rotated + mov ecx,MAX_POINTS*3 +copy_object: + fild word [esi] + fstp dword [edi] + add esi,2 + add edi,4 + dec ecx + jnz copy_object + + mov esi,angle_x + mov edi,cube_rotated + mov ecx,MAX_POINTS + call rotate_points + + mov esi,cube_rotated + mov edi,coord2d + mov ecx,MAX_POINTS + call translate_points + + call draw_textured_faces + call clear_screen_buffer + + add [angle_x],1 + add [angle_y],3 + add [angle_z],1 + + jmp still + +red: + call draw_window + jmp still +key: + mov eax,2 + jmp exit +button: + mov eax,17 + mcall + cmp ah,1 + jne still +exit: + mov eax,-1 + mcall + +;Draw window +draw_window: + mov eax,12 ;Start + mov ebx,1 + mcall + + mov eax,0 ;Draw window + mov ebx,0*65536+(799) ;x start*65536+x size + mov ecx,0*65536+(599) ;y start*65536+y size + mov edx,0x00000000 ;0x03 use skinned window + mcall + + call clear_screen + + mov eax,12 ;End + mov ebx,2 + mcall + ret + +head_label: db "3D TEXTURED CUBE THE LITTLE SCREEN SAVER FOR MENUETOS. USE " + db "800x600 SCREEN MODE FROM VIEW. PRESS ANY KEY FOR EXIT" +hl_end: + +;FADE IN FADE OUT TEXTURE + +x_step db 0 +x_num db 1 + +fade_texture: + mov ecx,0 +loox: + mov al,[file_texture+ecx] + mov [texture+ecx],al + inc ecx + cmp ecx,128*128*3 + jnae loox + + mov ecx,0 +loox2: + mov al,[file_texture+ecx] + cmp [x_step],al + jae xxx + sub al,[x_step] + jmp nnn +xxx: + mov al,0 +nnn: + mov [texture+ecx],al + inc ecx + cmp ecx,128*128*3 + jnae loox2 + + cmp [x_step],255 + jne no_max + mov [x_num],-1 +no_max: + cmp [x_step],0 + jne no_min + mov [x_num],1 +no_min: + mov al,[x_num] + add [x_step],al + ret + +; Clear Screen +clear_screen: + mov eax,13 + mov ebx,0*65536+800 + mov ecx,0*65536+600 + mov edx,0 + mcall + + mov eax,4 ;Out Text + mov ebx,8*65536+8 ;x start*65536+y start + mov ecx,0x00ffffff ;color White + mov edx,head_label + mov esi,hl_end-head_label + mcall + ret + +clear_screen_buffer: + mov ebx,scrbuf + mov ecx,800*65536+(600-40) ;sub 40 for antiflickering title + mov edx,0*65536+40 + mov eax,7 + mcall + + mov eax,4 ;Out Text + mov ebx,8*65536+580 ;x start*65536+y start + mov ebp,[n_step] + shl ebp,16 + sub ebx,ebp + mov ecx,0x0000ff00 ;color White + mov edx,move_text + add edx,[step] + mov esi,130 ;mt_end-move_text + mcall + + inc [n_step] + cmp [n_step],6 + jna t_ok + mov [n_step],0 + inc [step] + cmp [step],mt_end-move_text-130 + jng t_ok + mov [step],0 +t_ok: + + mov edi,scrbuf + mov eax,0 ;black background + mov ecx,800*600*3/4 ; 16000 + cld + rep stosd + ret + +n_step dd 0 +step dd 0 + +move_text: db " " + db " " + db " " + db "***** 3D TEXTURED CUBE THE LITTLE SCREEN SAVER FOR " + db "MENUET OS. SET 800x600 SCREEN MODE FROM VIEW THIS SCREEN " + db "SAVER ***** " + db "SITE OF THE RUSSIAN DEVELOPERS TO MENUETOS: " + db "www.menuet.narod.ru " + db "RUSSIAN MENUET APLICATION ARCHIVE PAGE ON: " + db "www.meosfiles.narod.ru " + db "AUTOR OF THIS SCREEN SAVER Pavlushin Evgeni " + db "MY SITE: www.deck4.narod.ru (Slow update) " + db "AND MAIL BOX: waptap@mail.ru " + db "THANK YOU FOR USE! " + db " " + db " " + db " " +mt_end: + + +;include graphlib.asm Mikolaj Felix 9/12/2000 mfelix@polbox.com +;Draw textured faces proc + +@@rx1 dw 0 ;equ [bp-2] +@@ry1 dw 0 ;equ [bp-4] +@@rx2 dw 0 ;equ [bp-6] +@@ry2 dw 0 ;equ [bp-8] +@@rx3 dw 0 ;equ [bp-10] +@@ry3 dw 0 ;equ [bp-12] +@@rx4 dw 0 ;equ [bp-14] +@@ry4 dw 0 ;equ [bp-16] + +draw_textured_faces: + + mov esi,link + mov ecx,MAX_FACES +dtf_loop: + push ecx + + xor ebx,ebx + mov bl,byte [esi] ; point 1 + shl bx,2 + mov eax,dword [coord2d+bx] ;COPY 1 FOURANGLE POINT + mov dword [@@rx1],eax + + xor ebx,ebx + mov bl,byte [esi+1] ; point 2 + shl bx,2 + mov eax,dword [coord2d+bx] ;COPY 2 FOURANGLE POINT + mov dword [@@rx2],eax + + xor ebx,ebx + mov bl,byte [esi+2] ; point 3 + shl bx,2 + mov eax,dword [coord2d+bx] ;COPY 3 FOURANGLE POINT + mov dword [@@rx3],eax + + xor bh,bh ; point 4 + mov bl,byte [esi+3] + shl bx,2 + mov eax,dword [coord2d+bx] ;COPY 4 FOURANGLE POINT + mov dword [@@rx4],eax + + mov ax,[@@ry1] + sub ax,[@@ry3] + mov bx,[@@rx2] + sub bx,[@@rx1] + imul bx + shl edx,16 + mov dx,ax + push edx + mov ax,[@@rx1] + sub ax,[@@rx3] + mov bx,[@@ry2] + sub bx,[@@ry1] + imul bx + shl edx,16 + mov dx,ax + pop ebx + sub ebx,edx ; normal_z = (y1-y3)*(x2-x1)-(x1-x3)*(y2-y1) + or ebx,ebx + jl dtf_next_face ; normal_z < 0 + + ; FIRST PICE OF FOUR ANGLE + + ; Set 3 triangel puts for texture ycoord*65536+xcoord + mov dword [@@tex_x3],127*65536+127 ;3 point + mov dword [@@tex_x2],0*65536+127 ;2 point + mov dword [@@tex_x1],0*65536+0 ;1 point + ; Set texture bitmap offset + mov [@@tex_off],texture + ; Set 3 triangel puts coordinates + mov eax,dword [@@rx3] + mov dword [@@x3],eax + mov eax,dword [@@rx2] + mov dword [@@x2],eax + mov eax,dword [@@rx1] + mov dword [@@x1],eax + call textured_triangle + + ; SECOND PICE OF FOUR ANGLE + + ; Set 3 triangel puts for texture ycoord*65536+xcoord + mov dword [@@tex_x3],127*65536+0 ;3 point + mov dword [@@tex_x2],127*65536+127 ;2 point + mov dword [@@tex_x1],0*65536+0 ;1 point + ; Set texture bitmap offset + mov [@@tex_off],texture + ; Set 3 triangel puts coordinates + mov eax,dword [@@rx4] + mov dword [@@x3],eax + mov eax,dword [@@rx3] + mov dword [@@x2],eax + mov eax,dword [@@rx1] + mov dword [@@x1],eax + call textured_triangle + +dtf_next_face: + add esi,4 + pop ecx + dec ecx + jnz dtf_loop + ret + +;include tex3.asm Mikolaj Felix 15/5/2001 mfelix@polbox.com + +@@x1 dw 0 ;equ [bp+4] +@@y1 dw 0 ;equ [bp+6] +@@x2 dw 0 ;equ [bp+8] +@@y2 dw 0 ;equ [bp+10] +@@x3 dw 0 ;equ [bp+12] +@@y3 dw 0 ;equ [bp+14] + +@@tex_off dd 0 ;equ [bp+16] +@@tex_x1 dw 0 ;equ [bp+18] +@@tex_y1 dw 0 ;equ [bp+20] +@@tex_x2 dw 0 ;equ [bp+22] +@@tex_y2 dw 0 ;equ [bp+24] +@@tex_x3 dw 0 ;equ [bp+26] +@@tex_y3 dw 0 ;equ [bp+28] + +@@dx12 dw 0 ;equ [bp-2] +@@dx13 dw 0 ;equ [bp-4] +@@dx23 dw 0 ;equ [bp-6] + +@@tex_dx12 dw 0 ;equ [bp-8] +@@tex_dy12 dw 0 ;equ [bp-10] +@@tex_dx13 dw 0 ;equ [bp-12] +@@tex_dy13 dw 0 ;equ [bp-14] +@@tex_dx23 dw 0 ;equ [bp-16] +@@tex_dy23 dw 0 ;equ [bp-18] + +@@scan_x1 dw 0 ;equ [bp-20] +@@scan_y1 dw 0 ;equ [bp-22] +@@scan_x2 dw 0 ;equ [bp-24] +@@scan_y2 dw 0 ;equ [bp-26] + + +textured_triangle: + + mov ax,[@@y1] + cmp ax,[@@y3] + jb tt_check1 + + xchg ax,[@@y3] + mov [@@y1],ax + + mov ax,[@@x1] + xchg ax,[@@x3] + mov [@@x1],ax + + mov ax,[@@tex_y1] + xchg ax,[@@tex_y3] + mov [@@tex_y1],ax + + mov ax,[@@tex_x1] + xchg ax,[@@tex_x3] + mov [@@tex_x1],ax +tt_check1: + mov ax,[@@y2] + cmp ax,[@@y3] + jb tt_check2 + + xchg ax,[@@y3] + mov [@@y2],ax + + mov ax,[@@x2] + xchg ax,[@@x3] + mov [@@x2],ax + + mov ax,[@@tex_y2] + xchg ax,[@@tex_y3] + mov [@@tex_y2],ax + + mov ax,[@@tex_x2] + xchg ax,[@@tex_x3] + mov [@@tex_x2],ax +tt_check2: + mov ax,[@@y1] + cmp ax,[@@y2] + jb tt_check3 + + xchg ax,[@@y2] + mov [@@y1],ax + + mov ax,[@@x1] + xchg ax,[@@x2] + mov [@@x1],ax + + mov ax,[@@tex_y1] + xchg ax,[@@tex_y2] + mov [@@tex_y1],ax + + mov ax,[@@tex_x1] + xchg ax,[@@tex_x2] + mov [@@tex_x1],ax +tt_check3: + + mov bx,[@@y2] + sub bx,[@@y1] + jnz tt_dx12_make + + mov word [@@dx12],0 + mov word [@@tex_dx12],0 + mov word [@@tex_dy12],0 + jmp tt_dx12_done +tt_dx12_make: + mov ax,[@@x2] + sub ax,[@@x1] + shl ax,7 + cwd + idiv bx + mov [@@dx12],ax ; dx12 = (x2-x1)/(y2-y1) + + mov ax,[@@tex_x2] + sub ax,[@@tex_x1] + shl ax,7 + cwd + idiv bx + mov [@@tex_dx12],ax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1) + + mov ax,[@@tex_y2] + sub ax,[@@tex_y1] + shl ax,7 + cwd + idiv bx + mov [@@tex_dy12],ax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1) +tt_dx12_done: + + mov bx,[@@y3] + sub bx,[@@y1] + jnz tt_dx13_make + + mov word [@@dx13],0 + mov word [@@tex_dx13],0 + mov word [@@tex_dy13],0 + jmp tt_dx13_done +tt_dx13_make: + mov ax,[@@x3] + sub ax,[@@x1] + shl ax,7 + cwd + idiv bx + mov [@@dx13],ax ; dx13 = (x3-x1)/(y3-y1) + + mov ax,[@@tex_x3] + sub ax,[@@tex_x1] + shl ax,7 + cwd + idiv bx + mov [@@tex_dx13],ax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1) + + mov ax,[@@tex_y3] + sub ax,[@@tex_y1] + shl ax,7 + cwd + idiv bx + mov [@@tex_dy13],ax ; tex_dy13 = (tex_y3-tex_x1)/(y3-y1) +tt_dx13_done: + + mov bx,[@@y3] + sub bx,[@@y2] + jnz tt_dx23_make + + mov word [@@dx23],0 + mov word [@@tex_dx23],0 + mov word [@@tex_dy23],0 + jmp tt_dx23_done +tt_dx23_make: + mov ax,[@@x3] + sub ax,[@@x2] + shl ax,7 + cwd + idiv bx + mov [@@dx23],ax ; dx23 = (x3-x2)/(y3-y2) + + mov ax,[@@tex_x3] + sub ax,[@@tex_x2] + shl ax,7 + cwd + idiv bx + mov [@@tex_dx23],ax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2) + + mov ax,[@@tex_y3] + sub ax,[@@tex_y2] + shl ax,7 + cwd + idiv bx + mov [@@tex_dy23],ax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2) +tt_dx23_done: + + + mov ax,[@@x1] + shl ax,7 + mov bx,ax + mov cx,[@@y1] + + mov dx,[@@tex_x1] + shl dx,7 + mov [@@scan_x1],dx + mov [@@scan_x2],dx + mov dx,[@@tex_y1] + shl dx,7 + mov [@@scan_y1],dx + mov [@@scan_y2],dx +tt_loop1: + pushad +; push ax +; push bx +; push cx + + mov dx,[@@scan_y2] + shr dx,7 + mov [@@tex_ly2],dx ;push dx + mov dx,[@@scan_x2] + shr dx,7 + mov [@@tex_lx2],dx ;push dx + mov dx,[@@scan_y1] + shr dx,7 + mov [@@tex_ly1],dx ;push dx + mov dx,[@@scan_x1] + shr dx,7 + mov [@@tex_lx1],dx ;push dx + mov ebp,dword [@@tex_off] ;push word ptr @@tex_off + mov [@@tex_loff],ebp + + mov [@@ly],cx ;push cx + mov dx,bx + shr dx,7 + mov [@@lx2],dx ;push dx + mov dx,ax + shr dx,7 + mov [@@lx1],dx ; push dx + call textured_horizontal_line + +; pop cx +; pop bx +; pop ax + popad + + mov dx,[@@tex_dx13] + add [@@scan_x1],dx + mov dx,[@@tex_dx12] + add [@@scan_x2],dx + mov dx,[@@tex_dy13] + add [@@scan_y1],dx + mov dx,[@@tex_dy12] + add [@@scan_y2],dx + + add ax,[@@dx13] + add bx,[@@dx12] + inc cx + cmp cx,[@@y2] + jb tt_loop1 + + mov bx,[@@x2] + shl bx,7 + mov cx,[@@y2] + + mov dx,[@@tex_x2] + shl dx,7 + mov [@@scan_x2],dx + mov dx,[@@tex_y2] + shl dx,7 + mov [@@scan_y2],dx +tt_loop2: + + pushad +; push ax +; push bx +; push cx + + mov dx,[@@scan_y2] + shr dx,7 + mov [@@tex_ly2],dx ;push dx + mov dx,[@@scan_x2] + shr dx,7 + mov [@@tex_lx2],dx ;push dx + mov dx,[@@scan_y1] + shr dx,7 + mov [@@tex_ly1],dx ;push dx + mov dx,[@@scan_x1] + shr dx,7 + mov [@@tex_lx1],dx ;push dx + mov ebp,dword [@@tex_off] ;push word ptr @@tex_off + mov [@@tex_loff],ebp + + mov [@@ly],cx ;push cx + mov dx,bx + shr dx,7 + mov [@@lx2],dx ;push dx + mov dx,ax + shr dx,7 + mov [@@lx1],dx ; push dx + call textured_horizontal_line + +; pop cx +; pop bx +; pop ax + popad + + mov dx,[@@tex_dx13] + add [@@scan_x1],dx + mov dx,[@@tex_dx23] + add [@@scan_x2],dx + mov dx,[@@tex_dy13] + add [@@scan_y1],dx + mov dx,[@@tex_dy23] + add [@@scan_y2],dx + + add ax,[@@dx13] + add bx,[@@dx23] + inc cx + cmp cx,[@@y3] + jb tt_loop2 + ret + +@@lx1 dw 0 ;equ [bp+4] +@@lx2 dw 0 ;equ [bp+6] +@@ly dw 0 ;equ [bp+8] + +@@tex_loff dd 0 ;equ [bp+10] +@@tex_lx1 dw 0 ;equ [bp+12] +@@tex_ly1 dw 0 ;equ [bp+14] +@@tex_lx2 dw 0 ;equ [bp+16] +@@tex_ly2 dw 0 ;equ [bp+18] + +@@tex_ldx dw 0 ;equ [bp-2] +@@tex_ldy dw 0 ;equ [bp-4] + +textured_horizontal_line: + + mov ax,[@@lx1] + cmp ax,[@@lx2] + je thl_quit + jb thl_ok + + xchg ax,[@@lx2] + mov [@@lx1],ax + + mov ax,[@@tex_lx1] + xchg ax,[@@tex_lx2] + mov [@@tex_lx1],ax + + mov ax,[@@tex_ly1] + xchg ax,[@@tex_ly2] + mov [@@tex_ly1],ax +thl_ok: + + ; Fast method +; mov edi,0 +; mov di,[@@ly] ;edi = calculating start of line +; mov ax,di +; shl di,6 ;ly*64 +; shl ax,8 ;ly*256 +; add di,ax ;di = (ly*64)+(ly*256) +; add di,[@@lx1] ;di = ly*320+lx1 +; mov eax,edi +; shl eax,1 +; add edi,eax +; add edi,scrbuf + + ; Uneversal method + movsx edi,[@@ly] + mov eax,800 ;di = ly*320+lx1 + mul edi + movsx ebx,[@@lx1] + add eax,ebx ;[@@lx1] + mov edi,3 + mul edi + mov edi,eax + add edi,scrbuf + + mov cx,[@@lx2] + sub cx,[@@lx1] + + mov ax,[@@tex_lx2] + sub ax,[@@tex_lx1] + shl ax,7 + cwd + idiv cx + mov [@@tex_ldx],ax ; tex_dx = (tex_x2-tex_x1)/(x2-x1) + + mov ax,[@@tex_ly2] + sub ax,[@@tex_ly1] + shl ax,7 + cwd + idiv cx + mov [@@tex_ldy],ax ; tex_dy = (tex_y2-tex_y1)/(x2-x1) + + cld + inc cx + mov ax,[@@tex_lx1] + shl ax,7 + mov bx,[@@tex_ly1] + shl bx,7 + +thl_loop: + mov dx,ax + push bx + + and bx,0ff80h + shr ax,7 + add bx,ax + mov ebp,0 + mov bp,bx + mov eax,ebp + shl eax,1 + add ebp,eax + add ebp,[@@tex_loff] + + mov al,byte [ebp+2] + stosb + mov al,byte [ebp+1] + stosb + mov al,byte [ebp] + stosb + + pop bx + mov ax,dx + + add ax,[@@tex_ldx] + add bx,[@@tex_ldy] + dec cx + jnz thl_loop +thl_quit: + ret + +;include math3d_2.asm +; Mikolaj Felix 20/06/2001 +; mfelix@polbox.com + +;------------------------------------------------------------ +; ds:si - offset to angles (int) +; ds:di - offset to array of 3d points +; cx - number of points +;------------------------------------------------------------ + +@@sin_x dd 0 ;equ dword ptr [bp-4] +@@cos_x dd 0 ;equ dword ptr [bp-8] +@@sin_y dd 0 ;equ dword ptr [bp-12] +@@cos_y dd 0 ;equ dword ptr [bp-16] +@@sin_z dd 0 ;equ dword ptr [bp-20] +@@cos_z dd 0 ;equ dword ptr [bp-24] + +@@x equ dword [edi] +@@y equ dword [edi+4] +@@z equ dword [edi+8] + +rotate_points: + + push edi + mov edi,@@sin_x + mov edx,3 +rp_sin_cos: + mov bx,word [esi] + and bx,MAX_DEGS-1 + shl bx,2 + mov eax,dword [sintab+bx] + mov dword [edi],eax + mov eax,dword [costab+bx] + mov dword [edi+4],eax + add edi,8 + add esi,2 + dec edx + jnz rp_sin_cos + pop edi + +rp_rotate: + fld @@y + fmul [@@cos_x] + fld @@z + fmul [@@sin_x] + fsubp st1,st + fld @@y + fxch st1 + fstp @@y ; Yrotated = Cos (A)*Y - Sin (A)*Z + fmul [@@sin_x] + fld @@z + fmul [@@cos_x] + faddp st1,st + fstp @@z ; Zrotated = Sin (A)*Y + Cos (A)*Z + + fld @@x + fmul [@@cos_y] + fld @@z + fmul [@@sin_y] + fsubp st1,st + fld @@x + fxch st1 + fstp @@x ; Xrotated = Cos (A)*X - Sin (A)*Z + fmul [@@sin_y] + fld @@z + fmul [@@cos_y] + faddp st1,st + fstp @@z ; Zrotated = Sin (A)*X + Cos (A)*Z + + fld @@x + fmul [@@cos_z] + fld @@y + fmul [@@sin_z] + fsubp st1,st + fld @@x + fxch st1 + fstp @@x ; Xrotated = Cos (A)*X - Sin (A)*Y + fmul [@@sin_z] + fld @@y + fmul [@@cos_z] + faddp st1,st + fstp @@y ; Yrotated = Sin (A)*X + Cos (A)*Y + + add edi,12 + dec ecx + jnz rp_rotate + ret + +;------------------------------------------------------------ +; ds:si - offset to array of 3d points +; ds:di - offset to 2d points +; cx - number of points +;------------------------------------------------------------ + +translate_points: + + fld dword [esi+8] + fadd [perspective] + + fld dword [esi] + fmul [perspective] + fdiv st,st1 + fadd [correct_x] + fistp word [edi] ; x2d = (x*persp)/(z+persp)+correct_x + + fld dword [esi+4] + fmul [perspective] + fdivrp st1,st + fadd [correct_y] + fistp word [edi+2] ; y2d = (y*persp)/(z+persp)+correct_y + + add esi,12 + add edi,4 + dec ecx + jnz translate_points + ret + +; initalize SIN&COS table + +@@temp1 dd 0 ;dword ptr [bp-4] +@@temp2 dd 0 ;dword ptr [bp-8] + +init_sincos: + mov [@@temp1],0 + fldpi + mov [@@temp2],MAX_DEGS/2 + fidiv [@@temp2] + fstp [@@temp2] + + xor edi,edi + mov ecx,MAX_DEGS +isc_loop: + fld [@@temp1] + fld st0 + fld st0 + fsin + fstp dword [sintab+edi] + fcos + fstp dword [costab+edi] + fadd [@@temp2] + fstp [@@temp1] + + add edi,4 + dec ecx + jnz isc_loop + ret + +perspective dd 256.0 +correct_x dd 400.0 +correct_y dd 300.0 + +angle_x dw 0 +angle_y dw 0 +angle_z dw 0 + +file_texture: +file 'texture.raw' + +cube dw -50,-50,50, 50,-50,50, 50,50,50, -50,50,50 + dw -50,-50,-50, 50,-50,-50, 50,50,-50, -50,50,-50 + +link db 0,1,2,3, 5,4,7,6, 1,5,6,2, 4,0,3,7, 4,5,1,0, 3,2,6,7 + +sintab: +rd MAX_DEGS +costab: +rd MAX_DEGS + +cube_rotated: +rd MAX_POINTS*3 +coord2d: +rw MAX_POINTS*2 +texture: +rb 128*128*3 +scrbuf: + +I_END: diff --git a/programs/demos/3dtcub10/trunk/Tupfile.lua b/programs/demos/3dtcub10/Tupfile.lua similarity index 79% rename from programs/demos/3dtcub10/trunk/Tupfile.lua rename to programs/demos/3dtcub10/Tupfile.lua index d51936b61..ea973e423 100644 --- a/programs/demos/3dtcub10/trunk/Tupfile.lua +++ b/programs/demos/3dtcub10/Tupfile.lua @@ -1,5 +1,5 @@ if tup.getconfig("NO_FASM") ~= "" then return end -HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR") +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_fasm.lua") add_include(tup.getvariantdir()) diff --git a/programs/demos/3dtcub10/trunk/build_en.bat b/programs/demos/3dtcub10/build_en.bat similarity index 100% rename from programs/demos/3dtcub10/trunk/build_en.bat rename to programs/demos/3dtcub10/build_en.bat diff --git a/programs/demos/3dtcub10/trunk/build_ru.bat b/programs/demos/3dtcub10/build_ru.bat similarity index 100% rename from programs/demos/3dtcub10/trunk/build_ru.bat rename to programs/demos/3dtcub10/build_ru.bat diff --git a/programs/demos/3dtcub10/trunk/texture.raw b/programs/demos/3dtcub10/texture.raw similarity index 100% rename from programs/demos/3dtcub10/trunk/texture.raw rename to programs/demos/3dtcub10/texture.raw diff --git a/programs/demos/3dwav/trunk/3dwav.asm b/programs/demos/3dwav/3dwav.asm similarity index 100% rename from programs/demos/3dwav/trunk/3dwav.asm rename to programs/demos/3dwav/3dwav.asm diff --git a/programs/demos/3dwav/trunk/Tupfile.lua b/programs/demos/3dwav/Tupfile.lua similarity index 100% rename from programs/demos/3dwav/trunk/Tupfile.lua rename to programs/demos/3dwav/Tupfile.lua diff --git a/programs/demos/3dwav/trunk/build.bat b/programs/demos/3dwav/build.bat similarity index 100% rename from programs/demos/3dwav/trunk/build.bat rename to programs/demos/3dwav/build.bat