1,12 → 1,4 |
;--------------------------------------------------------------------- |
; 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 |
36,6 → 28,15 |
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 |
48,22 → 49,17 |
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 |
88,325 → 84,240 |
add esi,4 |
fadd [sininc] |
loop .sinlp |
;--------------------------------------------------------------------- |
call cursor_to_screen_center |
call set_new_cursor_skin |
;--------------------------------------------------------------------- |
align 4 |
red: ; redraw |
call draw_window |
call draw_window ; at first, draw the window |
call draw_stuff |
;--------------------------------------------------------------------- |
;-------------------------------------- |
align 4 |
still: |
mcall 10 ; ask no wait for full speed |
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. |
|
cmp eax,1 ; window redraw request ? |
je red |
mcall 37,1 ; check mouseposition |
mov ebx,eax |
shr eax,16 |
and eax,0x0000FFFF ; mousex |
and ebx,0x0000FFFF ; mousey |
|
cmp eax,2 ; key in buffer ? |
je key |
cmp eax,5 ; mouse out of window ? |
jb check_refresh ; it will prevent an app-crash |
|
cmp eax,3 ; button in buffer ? |
je button |
cmp ebx,22 |
jb check_refresh |
|
cmp eax,6 |
jne still |
;--------------------------------------------------------------------- |
mouse: |
mcall 18,7 |
cmp [active_process],eax |
jne still |
cmp eax,640 |
jg check_refresh |
|
mcall 37,1 |
cmp ebx,501 |
jg check_refresh |
|
xor ebx,ebx |
mov bx,ax ; EBX mouse y |
shr eax,16 ; EAX mouse x |
cmp eax,315 ; navigating? |
jb m_left |
|
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 |
cmp eax,325 ; |
jg m_right |
;-------------------------------------- |
@@: |
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 |
continue: |
cmp ebx,220 ; |
jb s_up |
|
sub eax,edi ; newPx |
sub ebx,esi ; newPy |
cmp ebx,260 ; |
jg s_down |
;-------------------------------------- |
.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 |
;--------------------------------------------------------------------- |
; ******* END OF MOUSE CHECK ******* |
align 4 |
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 |
check_refresh: |
|
mov edi,3600 |
jmp .store |
;-------------------------------------- |
@@: |
cmp edi,3600 |
jle @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 |
|
xor edi,edi |
;-------------------------------------- |
@@: |
.store: |
mov [vheading],edi |
ret |
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 |
;--------------------------------------------------------------------- |
align 4 |
cursor_to_screen_center: |
mcall 18,15 |
mcall 37,1 |
mov [mouse_position_old],eax |
ret |
red2: ; redraw |
call draw_window |
call draw_stuff |
jmp gamestart |
;--------------------------------------------------------------------- |
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 |
key2: ; key |
mcall 2 |
cmp [extended_key],1 |
je .extended_key |
test al, al |
jnz still |
cmp al,1 |
je gamestart ; keybuffer empty |
|
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 |
cmp ah,178 ; up |
je s_up |
|
cmp ah,80 ; down arrow |
cmp ah,177 ; down |
je s_down |
|
cmp ah,75 ; left arrow |
cmp ah,176 ; left |
je s_left |
|
cmp ah,77 ; right arrow |
cmp ah,179 ; right |
je s_right |
|
jmp still |
jmp gamestart ; was any other key |
;--------------------------------------------------------------------- |
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 |
s_up: ; walk forward (key or mouse) |
mov eax,[vpx] |
mov ebx,[vpy] |
|
test al, al |
jnz .end |
mov ecx,[vheading] |
mov edi,[sinus+ecx*4] |
|
cmp ah, 0xE0 |
jne .end |
mov edx,[vheading] |
lea edx,[sinus+3600+edx*4] |
cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600 |
jb ok200 |
|
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 |
sub edx,14400 |
;-------------------------------------- |
ok200: |
mov esi,[edx] |
; 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 |
sal ecx,5 ; equal *32 |
lea ecx,[grid+ecx+edi] |
cmp [ecx],byte 0 |
jne smart_clr_key_buf ;cannotwalk |
|
cmp [ecx],byte 0 ; collision check |
jne cannotwalk0 |
mov [vpx],eax |
mov [vpy],ebx |
jmp smart_clr_key_buf |
mov [mouseya],dword 1 ; set refresh flag |
;-------------------------------------- |
cannotwalk0: |
jmp check_refresh |
;--------------------------------------------------------------------- |
align 4 |
prepare_1: |
s_down: ; walk backward |
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 @f |
|
jb ok201 |
sub edx,14400 |
;-------------------------------------- |
@@: |
ok201: |
mov esi,[edx] |
ret |
; 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 |
;--------------------------------------------------------------------- |
align 4 |
s_left: ; turn left (key) |
mov edi,[vheading] |
mov edi,[vheading] ; heading |
add edi,50 |
jmp s_right.1 |
cmp edi,3600 |
jb ok_heading0 |
|
sub edi,3600 |
;-------------------------------------- |
ok_heading0: |
mov [vheading],edi |
mov [mouseya],dword 1 |
jmp check_refresh |
;--------------------------------------------------------------------- |
align 4 |
s_right: ; turn right |
mov edi,[vheading] |
sub edi,50 |
.1: |
call check_range |
jmp smart_clr_key_buf |
cmp edi,-1 |
jg ok_heading1 |
|
add edi,3600 |
;-------------------------------------- |
ok_heading1: |
mov [vheading],edi |
mov [mouseya],dword 1 |
jmp check_refresh |
;--------------------------------------------------------------------- |
align 4 |
button: ; button |
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 |
mcall 17 |
cmp ah,1 ; button id=1 ? |
jne still ;gamestart |
jne gamestart |
;-------------------------------------- |
finish: |
mcall -1 ; close this program |
590,48 → 501,48 |
cmp eax,80 |
jg nodark0 |
; split rgb |
mov [blue_color],edx |
and [blue_color],dword 255 |
mov [blue],edx |
and [blue],dword 255 |
|
shr edx,8 |
mov [green_color],edx |
and [green_color],dword 255 |
mov [green],edx |
and [green],dword 255 |
|
shr edx,8 |
mov [red_color],edx |
and [red_color],dword 255 |
mov [red],edx |
and [red],dword 255 |
|
mov eax,81 ; darkness parameter |
sub eax,[vdd] |
sal eax,1 |
; reduce rgb |
sub [red_color],eax |
cmp [red_color],dword 0 |
sub [red],eax |
cmp [red],dword 0 |
jg notblack10 |
|
mov [red_color],dword 0 |
mov [red],dword 0 |
;-------------------------------------- |
notblack10: |
sub [green_color],eax |
cmp [green_color],dword 0 |
sub [green],eax |
cmp [green],dword 0 |
jg notblack20 |
|
mov [green_color],dword 0 |
mov [green],dword 0 |
;-------------------------------------- |
notblack20: |
mov edx,[blue_color] |
sub [blue_color],eax |
cmp [blue_color],dword 0 |
mov edx,[blue] |
sub [blue],eax |
cmp [blue],dword 0 |
jg notblack30 |
|
mov [blue_color],dword 0 |
mov [blue],dword 0 |
;-------------------------------------- |
notblack30: |
shl dword [red_color],16 ; reassemble rgb |
shl dword [green_color],8 |
mov edx,[red_color] |
or edx,[green_color] |
or edx,[blue_color] |
shl dword [red],16 ; reassemble rgb |
shl dword [green],8 |
mov edx,[red] |
or edx,[green] |
or edx,[blue] |
;-------------------------------------- |
nodark0: |
; eo custom darken floor |
976,16 → 887,16 |
cmp eax,50 |
jg nodark |
; split rgb |
mov [blue_color],edx |
and [blue_color],dword 255 |
mov [blue],edx |
and [blue],dword 255 |
|
shr edx,8 |
mov [green_color],edx |
and [green_color],dword 255 |
mov [green],edx |
and [green],dword 255 |
|
shr edx,8 |
mov [red_color],edx |
and [red_color],dword 255 |
mov [red],edx |
and [red],dword 255 |
|
mov eax,51 ; darkness parameter |
sub eax,[vdd] |
997,36 → 908,36 |
align 4 |
isdarkside: |
; reduce rgb |
sub [red_color],eax |
cmp [red_color],dword 0 |
sub [red],eax |
cmp [red], dword 0 |
jg notblack10b |
|
mov [red_color],dword 0 |
mov [red],dword 0 |
;-------------------------------------- |
align 4 |
notblack10b: |
sub [green_color],eax |
cmp [green_color],dword 0 |
sub [green],eax |
cmp [green],dword 0 |
jg notblack20b |
|
mov [green_color],dword 0 |
mov [green],dword 0 |
;-------------------------------------- |
align 4 |
notblack20b: |
mov edx,[blue_color] |
sub [blue_color],eax |
cmp [blue_color],dword 0 |
mov edx,[blue] |
sub [blue],eax |
cmp [blue],dword 0 |
jg notblack30b |
|
mov [blue_color],dword 0 |
mov [blue],dword 0 |
;-------------------------------------- |
align 4 |
notblack30b: |
shl dword [red_color],16 ; reassemble rgb |
shl dword [green_color],8 |
mov edx,[red_color] |
or edx,[green_color] |
or edx,[blue_color] |
shl dword [red],16 ; reassemble rgb |
shl dword [green],8 |
mov edx,[red] |
or edx,[green] |
or edx,[blue] |
mov eax,edx |
;-------------------------------------- |
align 4 |
1208,7 → 1119,7 |
vpy: |
dd 0x0001FFFF |
|
title db 'Free3D v0.6 - fisheye raycasting engine etc.',0 |
title db 'Free3D v0.5 - fisheye raycasting engine etc.',0 |
|
sindegree dd 0.0 |
sininc dd 0.0017453292519943295769236907684886 |
1215,9 → 1126,6 |
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: |
1334,10 → 1242,6 |
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: |
1396,8 → 1300,8 |
dd ? ;- |
vbottom: |
dd ? ;- |
;mouseya: |
; dd ? ;- |
mouseya: |
dd ? ;- |
remeax: |
dd ? ;- |
remebx: |
1410,11 → 1314,11 |
dd ? ;- |
remesi: |
dd ? ;- |
red_color: |
red: |
dd ? ;- |
green_color: |
green: |
dd ? ;- |
blue_color: |
blue: |
dd ? ;- |
pseudo: |
dd ? ;- |
1433,12 → 1337,9 |
; rd 16*1024*4 |
;--------------------------------------------------------------------- |
align 4 |
rb 4096 |
rb 1024 |
stacktop: |
;--------------------------------------------------------------------- |
procinfo: |
rb 1024 |
;--------------------------------------------------------------------- |
path: |
rb 4096 |
;--------------------------------------------------------------------- |