Free3D version 0.6

1) advanced control for mouse
2) advanced control for keyboard: W,A,S,D and Arrow Up,Down,Left,Right

git-svn-id: svn://kolibrios.org@1881 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Marat Zakiyanov (Mario79) 2011-02-21 12:56:29 +00:00
parent 8f38b2b58b
commit 39faeeed84

View File

@ -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 ; Free3D version 0.5
; ;
; last update: 20/02/2011 ; last update: 20/02/2011
@ -28,15 +36,6 @@ ICON_SIZE_X equ 128 ;64
ICON_SIZE_Y equ 128 ;64 ICON_SIZE_Y equ 128 ;64
Floors_Height equ 32000 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 use32
org 0x0 org 0x0
@ -49,16 +48,21 @@ org 0x0
dd 0x0 dd 0x0
dd path dd path
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
include '..\..\..\macros.inc' include '../../../macros.inc'
;include 'macros.inc' ;include 'macros.inc'
include '../../../develop/libraries/box_lib/load_lib.mac' include '../../../develop/libraries/box_lib/load_lib.mac'
;include 'load_lib.mac' ;include 'load_lib.mac'
@use_library @use_library
;COLOR_ORDER equ OTHER
;include 'gif_lite.inc'
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
START: ; start of execution START: ; start of execution
mcall 68,11 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 load_libraries l_libs_start,end_l_libs
test eax,eax test eax,eax
@ -84,158 +88,91 @@ load_libraries l_libs_start,end_l_libs
add esi,4 add esi,4
fadd [sininc] fadd [sininc]
loop .sinlp loop .sinlp
call draw_window ; at first, draw the 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.
mcall 37,1 ; check mouseposition
mov ebx,eax
shr eax,16
and eax,0x0000FFFF ; mousex
and ebx,0x0000FFFF ; mousey
cmp eax,5 ; mouse out of window ?
jb check_refresh ; it will prevent an app-crash
cmp ebx,22
jb check_refresh
cmp eax,640
jg check_refresh
cmp ebx,501
jg check_refresh
cmp eax,315 ; navigating?
jb m_left
cmp eax,325 ;
jg m_right
;--------------------------------------
continue:
cmp ebx,220 ;
jb s_up
cmp ebx,260 ;
jg s_down
;--------------------------------------
; ******* END OF MOUSE CHECK *******
align 4
check_refresh:
; 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
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
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
call cursor_to_screen_center
call set_new_cursor_skin
;---------------------------------------------------------------------
align 4 align 4
red2: ; redraw red: ; redraw
call draw_window call draw_window
call draw_stuff call draw_stuff
jmp gamestart
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
key2: ; key still:
mcall 2 mcall 10 ; ask no wait for full speed
cmp al,1
je gamestart ; keybuffer empty
cmp ah,27 ; esc=End App cmp eax,1 ; window redraw request ?
je finish je red
cmp ah,178 ; up cmp eax,2 ; key in buffer ?
je s_up je key
cmp ah,177 ; down cmp eax,3 ; button in buffer ?
je s_down je button
cmp ah,176 ; left cmp eax,6
je s_left jne still
cmp ah,179 ; right
je s_right
jmp gamestart ; was any other key
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 mouse:
s_up: ; walk forward (key or mouse) mcall 18,7
mov eax,[vpx] cmp [active_process],eax
mov ebx,[vpy] jne still
mov ecx,[vheading] mcall 37,1
mov edi,[sinus+ecx*4]
mov edx,[vheading] xor ebx,ebx
lea edx,[sinus+3600+edx*4] mov bx,ax ; EBX mouse y
cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600 shr eax,16 ; EAX mouse x
jb ok200
sub edx,14400 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
;-------------------------------------- ;--------------------------------------
ok200: @@:
mov esi,[edx] call check_range
; sal esi,1 ; edit walking speed here ;---------------------------------------------------------------------
; sal edi,1 .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 eax,edi ; newPx
add ebx,esi ; newPy add ebx,esi ; newPy
mov edi,eax ; newPx / ffff jmp .1
mov esi,ebx ; newPy / ffff
sar edi,16
sar esi,16
mov ecx,esi
sal ecx,5 ; equal *32
lea ecx,[grid+ecx+edi]
cmp [ecx],byte 0 ; collision check
jne cannotwalk0
mov [vpx],eax
mov [vpy],ebx
mov [mouseya],dword 1 ; set refresh flag
;--------------------------------------
cannotwalk0:
jmp check_refresh
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 .walk_down:
s_down: ; walk backward sub ebx,edx
mov eax,[vpx] mov ecx,ebx
mov ebx,[vpy] call prepare_2
mov ecx,[vheading] jz .1
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
sub edx,14400
;--------------------------------------
ok201:
mov esi,[edx]
; sal esi,1 ; edit walking speed here
; sal edi,1
sub eax,edi ; newPx sub eax,edi ; newPx
sub ebx,esi ; newPy sub ebx,esi ; newPy
;--------------------------------------
.1:
mov edi,eax ; newPx / ffff mov edi,eax ; newPx / ffff
mov esi,ebx ; newPy / ffff mov esi,ebx ; newPy / ffff
sar edi,16 sar edi,16
@ -244,80 +181,232 @@ ok201:
sal ecx,5 sal ecx,5
lea ecx,[grid+ecx+edi] lea ecx,[grid+ecx+edi]
cmp [ecx],byte 0 cmp [ecx],byte 0
jne cannotwalk1 je @f
call cursor_to_screen_center
jmp still ;cannotwalk
;---------------------------------------------------------------------
@@:
mov [vpx],eax mov [vpx],eax
mov [vpy],ebx mov [vpy],ebx
mov [mouseya],dword 1
;-------------------------------------- ;--------------------------------------
cannotwalk1: .red:
jmp check_refresh call cursor_to_screen_center
jmp red
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
s_left: ; turn left (key) prepare_2:
mov edi,[vheading] ; heading shr ecx,4
add edi,50 push ecx
cmp edi,3600 call prepare_1
jb ok_heading0 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
sub edi,3600 mov edi,3600
jmp .store
;-------------------------------------- ;--------------------------------------
ok_heading0: @@:
cmp edi,3600
jle @f
xor edi,edi
;--------------------------------------
@@:
.store:
mov [vheading],edi mov [vheading],edi
mov [mouseya],dword 1 ret
jmp check_refresh ;---------------------------------------------------------------------
align 4
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
key: ; key
mcall 2
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,72 ; up arrow
je s_up
cmp ah,80 ; down arrow
je s_down
cmp ah,75 ; left arrow
je s_left
cmp ah,77 ; right arrow
je s_right
jmp still
;---------------------------------------------------------------------
align 4
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
test al, al
jnz .end
cmp ah, 0xE0
jne .end
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
lea ecx,[grid+ecx+edi]
cmp [ecx],byte 0
jne smart_clr_key_buf ;cannotwalk
mov [vpx],eax
mov [vpy],ebx
jmp smart_clr_key_buf
;---------------------------------------------------------------------
align 4
prepare_1:
mov eax,[vpx]
mov ebx,[vpy]
mov ecx,[vheading]
mov edx,ecx
mov edi,[sinus+ecx*4]
lea edx,[sinus+3600+edx*4]
cmp edx,eosinus ; cosinus taken from (sinus plus 900) mod 3600
jb @f
sub edx,14400
;--------------------------------------
@@:
mov esi,[edx]
ret
;---------------------------------------------------------------------
align 4
s_left: ; turn left (key)
mov edi,[vheading]
add edi,50
jmp s_right.1
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
s_right: ; turn right s_right: ; turn right
mov edi,[vheading] mov edi,[vheading]
sub edi,50 sub edi,50
cmp edi,-1 .1:
jg ok_heading1 call check_range
jmp smart_clr_key_buf
add edi,3600
;--------------------------------------
ok_heading1:
mov [vheading],edi
mov [mouseya],dword 1
jmp check_refresh
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
m_left: ; turn left (mouse) button: ; button
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
mcall 17 mcall 17
cmp ah,1 ; button id=1 ? cmp ah,1 ; button id=1 ?
jne gamestart jne still ;gamestart
;-------------------------------------- ;--------------------------------------
finish: finish:
mcall -1 ; close this program mcall -1 ; close this program
@ -501,48 +590,48 @@ nodouble:
cmp eax,80 cmp eax,80
jg nodark0 jg nodark0
; split rgb ; split rgb
mov [blue],edx mov [blue_color],edx
and [blue],dword 255 and [blue_color],dword 255
shr edx,8 shr edx,8
mov [green],edx mov [green_color],edx
and [green],dword 255 and [green_color],dword 255
shr edx,8 shr edx,8
mov [red],edx mov [red_color],edx
and [red],dword 255 and [red_color],dword 255
mov eax,81 ; darkness parameter mov eax,81 ; darkness parameter
sub eax,[vdd] sub eax,[vdd]
sal eax,1 sal eax,1
; reduce rgb ; reduce rgb
sub [red],eax sub [red_color],eax
cmp [red],dword 0 cmp [red_color],dword 0
jg notblack10 jg notblack10
mov [red],dword 0 mov [red_color],dword 0
;-------------------------------------- ;--------------------------------------
notblack10: notblack10:
sub [green],eax sub [green_color],eax
cmp [green],dword 0 cmp [green_color],dword 0
jg notblack20 jg notblack20
mov [green],dword 0 mov [green_color],dword 0
;-------------------------------------- ;--------------------------------------
notblack20: notblack20:
mov edx,[blue] mov edx,[blue_color]
sub [blue],eax sub [blue_color],eax
cmp [blue],dword 0 cmp [blue_color],dword 0
jg notblack30 jg notblack30
mov [blue],dword 0 mov [blue_color],dword 0
;-------------------------------------- ;--------------------------------------
notblack30: notblack30:
shl dword [red],16 ; reassemble rgb shl dword [red_color],16 ; reassemble rgb
shl dword [green],8 shl dword [green_color],8
mov edx,[red] mov edx,[red_color]
or edx,[green] or edx,[green_color]
or edx,[blue] or edx,[blue_color]
;-------------------------------------- ;--------------------------------------
nodark0: nodark0:
; eo custom darken floor ; eo custom darken floor
@ -887,16 +976,16 @@ dark_distance:
cmp eax,50 cmp eax,50
jg nodark jg nodark
; split rgb ; split rgb
mov [blue],edx mov [blue_color],edx
and [blue],dword 255 and [blue_color],dword 255
shr edx,8 shr edx,8
mov [green],edx mov [green_color],edx
and [green],dword 255 and [green_color],dword 255
shr edx,8 shr edx,8
mov [red],edx mov [red_color],edx
and [red],dword 255 and [red_color],dword 255
mov eax,51 ; darkness parameter mov eax,51 ; darkness parameter
sub eax,[vdd] sub eax,[vdd]
@ -908,36 +997,36 @@ dark_distance:
align 4 align 4
isdarkside: isdarkside:
; reduce rgb ; reduce rgb
sub [red],eax sub [red_color],eax
cmp [red], dword 0 cmp [red_color],dword 0
jg notblack10b jg notblack10b
mov [red],dword 0 mov [red_color],dword 0
;-------------------------------------- ;--------------------------------------
align 4 align 4
notblack10b: notblack10b:
sub [green],eax sub [green_color],eax
cmp [green],dword 0 cmp [green_color],dword 0
jg notblack20b jg notblack20b
mov [green],dword 0 mov [green_color],dword 0
;-------------------------------------- ;--------------------------------------
align 4 align 4
notblack20b: notblack20b:
mov edx,[blue] mov edx,[blue_color]
sub [blue],eax sub [blue_color],eax
cmp [blue],dword 0 cmp [blue_color],dword 0
jg notblack30b jg notblack30b
mov [blue],dword 0 mov [blue_color],dword 0
;-------------------------------------- ;--------------------------------------
align 4 align 4
notblack30b: notblack30b:
shl dword [red],16 ; reassemble rgb shl dword [red_color],16 ; reassemble rgb
shl dword [green],8 shl dword [green_color],8
mov edx,[red] mov edx,[red_color]
or edx,[green] or edx,[green_color]
or edx,[blue] or edx,[blue_color]
mov eax,edx mov eax,edx
;-------------------------------------- ;--------------------------------------
align 4 align 4
@ -1119,13 +1208,16 @@ vpx:
vpy: vpy:
dd 0x0001FFFF 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 sindegree dd 0.0
sininc dd 0.0017453292519943295769236907684886 sininc dd 0.0017453292519943295769236907684886
sindiv dd 6553.5 sindiv dd 6553.5
;textures: ;textures:
;file 'texture.gif' ;file 'texture.gif'
current_key_code db 0
old_key_code db 0
extended_key db 0
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
fileinfo: fileinfo:
@ -1242,6 +1334,10 @@ wall5 rd 1
wall6 rd 1 wall6 rd 1
wall7 rd 1 wall7 rd 1
;screen_buffer rd 1 ;screen_buffer rd 1
active_process rd 1
;mouse_position rd 1
mouse_position_old rd 1
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
col1: col1:
@ -1300,8 +1396,8 @@ h_old:
dd ? ;- dd ? ;-
vbottom: vbottom:
dd ? ;- dd ? ;-
mouseya: ;mouseya:
dd ? ;- ; dd ? ;-
remeax: remeax:
dd ? ;- dd ? ;-
remebx: remebx:
@ -1314,11 +1410,11 @@ remedi:
dd ? ;- dd ? ;-
remesi: remesi:
dd ? ;- dd ? ;-
red: red_color:
dd ? ;- dd ? ;-
green: green_color:
dd ? ;- dd ? ;-
blue: blue_color:
dd ? ;- dd ? ;-
pseudo: pseudo:
dd ? ;- dd ? ;-
@ -1337,9 +1433,12 @@ eosinus:
; rd 16*1024*4 ; rd 16*1024*4
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
align 4 align 4
rb 1024 rb 4096
stacktop: stacktop:
;--------------------------------------------------------------------- ;---------------------------------------------------------------------
procinfo:
rb 1024
;---------------------------------------------------------------------
path: path:
rb 4096 rb 4096
;--------------------------------------------------------------------- ;---------------------------------------------------------------------