Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1880 → Rev 1881

/programs/demos/free3d/trunk/free3d.asm
1,4 → 1,12
;---------------------------------------------------------------------
; Free3D version 0.6
;
; last update: 21/02/2011
; written by: Marat Zakiyanov aka Mario79, aka Mario
; changes: advanced control for mouse
; advanced control for keyboard:
; W,A,S,D adn Arrow UP,Down,Left,Right
;---------------------------------------------------------------------
; Free3D version 0.5
;
; last update: 20/02/2011
28,15 → 36,6
ICON_SIZE_Y equ 128 ;64
 
Floors_Height equ 32000
;ceil = sinus+TEX_SIZE ;16*1024
;wall = ceil+TEX_SIZE*1
;wall2 = ceil+TEX_SIZE*2
;wall3 = ceil+TEX_SIZE*3
;wall4 = ceil+TEX_SIZE*4
;wall5 = ceil+TEX_SIZE*5
;wall6 = ceil+TEX_SIZE*6
;wall7 = ceil+TEX_SIZE*7
;APP_MEM equ 0x400000
;---------------------------------------------------------------------
use32
org 0x0
49,17 → 48,22
dd 0x0
dd path
;---------------------------------------------------------------------
include '..\..\..\macros.inc'
include '../../../macros.inc'
;include 'macros.inc'
include '../../../develop/libraries/box_lib/load_lib.mac'
;include 'load_lib.mac'
@use_library
;COLOR_ORDER equ OTHER
;include 'gif_lite.inc'
;---------------------------------------------------------------------
START: ; start of execution
mcall 68,11
mcall 66,1,1
mcall 40,0x27
 
mcall 9,procinfo,-1
mov ecx,[ebx+30] ; PID
mcall 18,21
mov [active_process],eax ; WINDOW SLOT
 
load_libraries l_libs_start,end_l_libs
test eax,eax
jnz finish
84,240 → 88,325
add esi,4
fadd [sininc]
loop .sinlp
call draw_window ; at first, draw the window
;---------------------------------------------------------------------
call cursor_to_screen_center
call set_new_cursor_skin
;---------------------------------------------------------------------
align 4
red: ; redraw
call draw_window
call draw_stuff
;--------------------------------------
;---------------------------------------------------------------------
align 4
gamestart:
; ******* MOUSE CHECK *******
; mov eax,37 ; check mouse (use mouse over window to navigate)
; mov ebx,2 ; check mousebuttons
; mcall
; cmp eax,0 ; only use mouse when button down
; je noneed ; deactivated cause of disappear-bug etc.
still:
mcall 10 ; ask no wait for full speed
 
mcall 37,1 ; check mouseposition
mov ebx,eax
shr eax,16
and eax,0x0000FFFF ; mousex
and ebx,0x0000FFFF ; mousey
cmp eax,1 ; window redraw request ?
je red
 
cmp eax,5 ; mouse out of window ?
jb check_refresh ; it will prevent an app-crash
cmp eax,2 ; key in buffer ?
je key
 
cmp ebx,22
jb check_refresh
cmp eax,3 ; button in buffer ?
je button
 
cmp eax,640
jg check_refresh
cmp eax,6
jne still
;---------------------------------------------------------------------
mouse:
mcall 18,7
cmp [active_process],eax
jne still
 
cmp ebx,501
jg check_refresh
mcall 37,1
 
cmp eax,315 ; navigating?
jb m_left
xor ebx,ebx
mov bx,ax ; EBX mouse y
shr eax,16 ; EAX mouse x
 
cmp eax,325 ;
jg m_right
mov ecx,[mouse_position_old]
xor edx,edx
mov dx,cx ; EDX mouse y old
shr ecx,16 ; ECX mouse x old
cmp eax,ecx
je .y ;still
ja .turn_left
;---------------------------------------------------------------------
.turn_right:
xchg eax,ecx
sub eax,ecx
mov edi,[vheading]
add edi,eax
jmp @f
;---------------------------------------------------------------------
.turn_left:
sub eax,ecx
mov edi,[vheading]
sub edi,eax
;--------------------------------------
continue:
cmp ebx,220 ;
jb s_up
@@:
call check_range
;---------------------------------------------------------------------
.y:
cmp ebx,edx
je .red
ja .walk_down
;--------------------------------------
.walk_up:
sub edx,ebx
mov ecx,edx
call prepare_2
jz .1
;--------------------------------------
add eax,edi ; newPx
add ebx,esi ; newPy
jmp .1
;---------------------------------------------------------------------
.walk_down:
sub ebx,edx
mov ecx,ebx
call prepare_2
jz .1
 
cmp ebx,260 ;
jg s_down
sub eax,edi ; newPx
sub ebx,esi ; newPy
;--------------------------------------
; ******* END OF MOUSE CHECK *******
.1:
mov edi,eax ; newPx / ffff
mov esi,ebx ; newPy / ffff
sar edi,16
sar esi,16
mov ecx,esi
sal ecx,5
lea ecx,[grid+ecx+edi]
cmp [ecx],byte 0
je @f
call cursor_to_screen_center
jmp still ;cannotwalk
;---------------------------------------------------------------------
@@:
mov [vpx],eax
mov [vpy],ebx
;--------------------------------------
.red:
call cursor_to_screen_center
jmp red
;---------------------------------------------------------------------
align 4
check_refresh:
prepare_2:
shr ecx,4
push ecx
call prepare_1
pop ecx
cmp ecx,3
jb @f
mov ecx,3
@@:
shl edi,cl
shl esi,cl
test ecx,ecx
ret
;---------------------------------------------------------------------
align 4
check_range:
cmp edi,0
jge @f
 
; mov eax,23 ; wait for system event with 10 ms timeout
; mov ebx,1 ; thats max 100 FPS
mcall 11 ; ask no wait for full speed
mov edi,3600
jmp .store
;--------------------------------------
@@:
cmp edi,3600
jle @f
 
cmp eax,1 ; window redraw request ?
je red2
 
cmp eax,2 ; key in buffer ?
je key2
 
cmp eax,3 ; button in buffer ?
je button2
 
mov edi,[mouseya] ; check flag if a refresh has to be done
cmp edi,1
jne gamestart
 
mov [mouseya],dword 0
call draw_stuff
jmp gamestart
xor edi,edi
;--------------------------------------
@@:
.store:
mov [vheading],edi
ret
;---------------------------------------------------------------------
align 4
red2: ; redraw
call draw_window
call draw_stuff
jmp gamestart
cursor_to_screen_center:
mcall 18,15
mcall 37,1
mov [mouse_position_old],eax
ret
;---------------------------------------------------------------------
set_new_cursor_skin:
mcall 68,12,32*32*4
mov ecx,eax
mcall 37,4,,2
mov ecx,eax
mcall 37,5
ret
;---------------------------------------------------------------------
align 4
key2: ; key
key: ; key
mcall 2
cmp al,1
je gamestart ; keybuffer empty
cmp [extended_key],1
je .extended_key
test al, al
jnz still
 
cmp ah, 0xE0
jne @f
 
mov [extended_key],1
jmp still
;---------------------------------------------------------------------
@@:
cmp ah,1 ; Esc
je finish
 
cmp ah,17 ; W up
je s_up
 
cmp ah,31 ; S down
je s_down
 
cmp ah,30 ; A left
je w_left ;s_left
 
cmp ah,32 ; D right
je w_right ;s_right
 
jmp still
;---------------------------------------------------------------------
.extended_key:
mov [extended_key],0
mov [current_key_code],ah
 
cmp ah,27 ; esc=End App
je finish
 
cmp ah,178 ; up
cmp ah,72 ; up arrow
je s_up
 
cmp ah,177 ; down
cmp ah,80 ; down arrow
je s_down
 
cmp ah,176 ; left
cmp ah,75 ; left arrow
je s_left
 
cmp ah,179 ; right
cmp ah,77 ; right arrow
je s_right
 
jmp gamestart ; was any other key
jmp still
;---------------------------------------------------------------------
align 4
s_up: ; walk forward (key or mouse)
mov eax,[vpx]
mov ebx,[vpy]
smart_clr_key_buf:
mov al,[old_key_code]
mov ah,[current_key_code]
mov [old_key_code],ah
cmp al,ah
jne .end
;--------------------------------------
.still:
mcall 2
cmp [extended_key],1
je .extended_key
 
mov ecx,[vheading]
mov edi,[sinus+ecx*4]
test al, al
jnz .end
 
mov edx,[vheading]
lea edx,[sinus+3600+edx*4]
cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600
jb ok200
cmp ah, 0xE0
jne .end
 
sub edx,14400
;--------------------------------------
ok200:
mov esi,[edx]
mov [extended_key],1
jmp .still
.end:
call draw_stuff
jmp still
;---------------------------------------------------------------------
.extended_key:
mov [extended_key],0
mov [current_key_code],ah
jmp smart_clr_key_buf
;---------------------------------------------------------------------
align 4
w_left: ; walk left
call prepare_1
add eax,esi ; newPx
sub ebx,edi ; newPy
jmp s_down.1
;---------------------------------------------------------------------
align 4
w_right: ; walk right
call prepare_1
sub eax,esi ; newPx
add ebx,edi ; newPy
jmp s_down.1
;---------------------------------------------------------------------
align 4
s_up: ; walk forward (key or mouse)
call prepare_1
; sal esi,1 ; edit walking speed here
; sal edi,1
add eax,edi ; newPx
add ebx,esi ; newPy
jmp s_down.1
;---------------------------------------------------------------------
align 4
s_down: ; walk backward
call prepare_1
; sal esi,1 ; edit walking speed here
; sal edi,1
sub eax,edi ; newPx
sub ebx,esi ; newPy
.1:
mov edi,eax ; newPx / ffff
mov esi,ebx ; newPy / ffff
sar edi,16
sar esi,16
mov ecx,esi
sal ecx,5 ; equal *32
sal ecx,5
lea ecx,[grid+ecx+edi]
cmp [ecx],byte 0 ; collision check
jne cannotwalk0
cmp [ecx],byte 0
jne smart_clr_key_buf ;cannotwalk
 
mov [vpx],eax
mov [vpy],ebx
mov [mouseya],dword 1 ; set refresh flag
;--------------------------------------
cannotwalk0:
jmp check_refresh
jmp smart_clr_key_buf
;---------------------------------------------------------------------
align 4
s_down: ; walk backward
prepare_1:
mov eax,[vpx]
mov ebx,[vpy]
mov ecx,[vheading]
mov edx,ecx
mov edi,[sinus+ecx*4]
mov edx,[vheading]
lea edx,[sinus+3600+edx*4]
cmp edx,eosinus ; cosinus taken from (sinus plus 900) mod 3600
jb ok201
jb @f
 
sub edx,14400
;--------------------------------------
ok201:
@@:
mov esi,[edx]
; sal esi,1 ; edit walking speed here
; sal edi,1
sub eax,edi ; newPx
sub ebx,esi ; newPy
mov edi,eax ; newPx / ffff
mov esi,ebx ; newPy / ffff
sar edi,16
sar esi,16
mov ecx,esi
sal ecx,5
lea ecx,[grid+ecx+edi]
cmp [ecx],byte 0
jne cannotwalk1
mov [vpx],eax
mov [vpy],ebx
mov [mouseya],dword 1
;--------------------------------------
cannotwalk1:
jmp check_refresh
ret
;---------------------------------------------------------------------
align 4
s_left: ; turn left (key)
mov edi,[vheading] ; heading
mov edi,[vheading]
add edi,50
cmp edi,3600
jb ok_heading0
 
sub edi,3600
;--------------------------------------
ok_heading0:
mov [vheading],edi
mov [mouseya],dword 1
jmp check_refresh
jmp s_right.1
;---------------------------------------------------------------------
align 4
s_right: ; turn right
mov edi,[vheading]
sub edi,50
cmp edi,-1
jg ok_heading1
 
add edi,3600
;--------------------------------------
ok_heading1:
mov [vheading],edi
mov [mouseya],dword 1
jmp check_refresh
.1:
call check_range
jmp smart_clr_key_buf
;---------------------------------------------------------------------
align 4
m_left: ; turn left (mouse)
mov edi,[vheading] ; heading
mov ecx,315
sub ecx,eax
sar ecx,2
add edi,ecx
cmp edi,3600
jb ok_heading2
 
sub edi,3600
;--------------------------------------
ok_heading2:
mov [vheading],edi
mov [mouseya],dword 1
jmp continue ; allow both: walk and rotate
;---------------------------------------------------------------------
align 4
m_right: ; turn right
mov edi,[vheading]
sub eax,325
sar eax,2
sub edi,eax
cmp edi,-1
jg ok_heading3
 
add edi,3600
;--------------------------------------
ok_heading3:
mov [vheading],edi
mov [mouseya],dword 1
jmp continue
;---------------------------------------------------------------------
align 4
button2: ; button
button: ; button
mcall 17
cmp ah,1 ; button id=1 ?
jne gamestart
jne still ;gamestart
;--------------------------------------
finish:
mcall -1 ; close this program
501,48 → 590,48
cmp eax,80
jg nodark0
; split rgb
mov [blue],edx
and [blue],dword 255
mov [blue_color],edx
and [blue_color],dword 255
 
shr edx,8
mov [green],edx
and [green],dword 255
mov [green_color],edx
and [green_color],dword 255
 
shr edx,8
mov [red],edx
and [red],dword 255
mov [red_color],edx
and [red_color],dword 255
 
mov eax,81 ; darkness parameter
sub eax,[vdd]
sal eax,1
; reduce rgb
sub [red],eax
cmp [red],dword 0
sub [red_color],eax
cmp [red_color],dword 0
jg notblack10
 
mov [red],dword 0
mov [red_color],dword 0
;--------------------------------------
notblack10:
sub [green],eax
cmp [green],dword 0
sub [green_color],eax
cmp [green_color],dword 0
jg notblack20
 
mov [green],dword 0
mov [green_color],dword 0
;--------------------------------------
notblack20:
mov edx,[blue]
sub [blue],eax
cmp [blue],dword 0
mov edx,[blue_color]
sub [blue_color],eax
cmp [blue_color],dword 0
jg notblack30
 
mov [blue],dword 0
mov [blue_color],dword 0
;--------------------------------------
notblack30:
shl dword [red],16 ; reassemble rgb
shl dword [green],8
mov edx,[red]
or edx,[green]
or edx,[blue]
shl dword [red_color],16 ; reassemble rgb
shl dword [green_color],8
mov edx,[red_color]
or edx,[green_color]
or edx,[blue_color]
;--------------------------------------
nodark0:
; eo custom darken floor
887,16 → 976,16
cmp eax,50
jg nodark
; split rgb
mov [blue],edx
and [blue],dword 255
mov [blue_color],edx
and [blue_color],dword 255
 
shr edx,8
mov [green],edx
and [green],dword 255
mov [green_color],edx
and [green_color],dword 255
 
shr edx,8
mov [red],edx
and [red],dword 255
mov [red_color],edx
and [red_color],dword 255
 
mov eax,51 ; darkness parameter
sub eax,[vdd]
908,36 → 997,36
align 4
isdarkside:
; reduce rgb
sub [red],eax
cmp [red], dword 0
sub [red_color],eax
cmp [red_color],dword 0
jg notblack10b
 
mov [red],dword 0
mov [red_color],dword 0
;--------------------------------------
align 4
notblack10b:
sub [green],eax
cmp [green],dword 0
sub [green_color],eax
cmp [green_color],dword 0
jg notblack20b
 
mov [green],dword 0
mov [green_color],dword 0
;--------------------------------------
align 4
notblack20b:
mov edx,[blue]
sub [blue],eax
cmp [blue],dword 0
mov edx,[blue_color]
sub [blue_color],eax
cmp [blue_color],dword 0
jg notblack30b
 
mov [blue],dword 0
mov [blue_color],dword 0
;--------------------------------------
align 4
notblack30b:
shl dword [red],16 ; reassemble rgb
shl dword [green],8
mov edx,[red]
or edx,[green]
or edx,[blue]
shl dword [red_color],16 ; reassemble rgb
shl dword [green_color],8
mov edx,[red_color]
or edx,[green_color]
or edx,[blue_color]
mov eax,edx
;--------------------------------------
align 4
1119,7 → 1208,7
vpy:
dd 0x0001FFFF
 
title db 'Free3D v0.5 - fisheye raycasting engine etc.',0
title db 'Free3D v0.6 - fisheye raycasting engine etc.',0
 
sindegree dd 0.0
sininc dd 0.0017453292519943295769236907684886
1126,6 → 1215,9
sindiv dd 6553.5
;textures:
;file 'texture.gif'
current_key_code db 0
old_key_code db 0
extended_key db 0
;---------------------------------------------------------------------
align 4
fileinfo:
1242,6 → 1334,10
wall6 rd 1
wall7 rd 1
;screen_buffer rd 1
active_process rd 1
 
;mouse_position rd 1
mouse_position_old rd 1
;---------------------------------------------------------------------
align 4
col1:
1300,8 → 1396,8
dd ? ;-
vbottom:
dd ? ;-
mouseya:
dd ? ;-
;mouseya:
; dd ? ;-
remeax:
dd ? ;-
remebx:
1314,11 → 1410,11
dd ? ;-
remesi:
dd ? ;-
red:
red_color:
dd ? ;-
green:
green_color:
dd ? ;-
blue:
blue_color:
dd ? ;-
pseudo:
dd ? ;-
1337,9 → 1433,12
; rd 16*1024*4
;---------------------------------------------------------------------
align 4
rb 1024
rb 4096
stacktop:
;---------------------------------------------------------------------
procinfo:
rb 1024
;---------------------------------------------------------------------
path:
rb 4096
;---------------------------------------------------------------------