Subversion Repositories Kolibri OS

Rev

Rev 1416 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;   Fisheye Raycasting Engine Etc. FREE3D for MENUETOS by Dieter Marfurt
  3. ;   Version 0.4 (requires some texture-files to compile (see Data Section))
  4. ;   dietermarfurt@angelfire.com - www.melog.ch/mos_pub/
  5. ;   Don't hit me - I'm an ASM-Newbie... since years :)
  6. ;
  7. ;   Compile with FASM for Menuet (requires .INC files - see DATA Section)
  8. ;
  9. ;   Willow - greatly srinked code size by using GIF texture and FPU to calculate sine table
  10. ;
  11. ;   !!!! Don't use GIF_LITE.INC in your apps - it's modified for FREE3D !!!!
  12. ;
  13. ;   Heavyiron - new 0-function of drawing window from kolibri (do not work correctly with menuet)
  14.  
  15.  
  16. TEX_SIZE equ 64*64*4
  17. ceil = sinus+16*1024
  18. wall = ceil+TEX_SIZE*1
  19. wall2 = ceil+TEX_SIZE*2
  20. wall3 = ceil+TEX_SIZE*3
  21. wall4 = ceil+TEX_SIZE*4
  22. wall5 = ceil+TEX_SIZE*5
  23. wall6 = ceil+TEX_SIZE*6
  24. wall7 = ceil+TEX_SIZE*7
  25. APP_MEM equ 0x200000
  26.  
  27. use32
  28.  
  29.                org    0x0
  30.  
  31.                db     'MENUET01'              ; 8 byte id
  32.                dd     0x01                    ; header version
  33.                dd     START                   ; start of code
  34.                dd     I_END                   ; size of image
  35.                dd     APP_MEM;0x100000        ; memory for app
  36.                dd     APP_MEM;0x100000        ; esp
  37.                dd     0x0 , 0x0               ; I_Param , I_Icon
  38. include 'lang.inc'
  39. include '..\..\..\macros.inc'
  40. COLOR_ORDER equ OTHER
  41. include 'gif_lite.inc'
  42.  
  43. START:                          ; start of execution
  44.                 mov  esi,textures
  45.                 mov  edi,ceil-8
  46.                 call ReadGIF
  47.                 mov  esi,sinus
  48.                 mov  ecx,360*10
  49.                 fninit
  50.                 fld  [sindegree]
  51.         .sinlp:
  52.                 fst  st1
  53.                 fsin
  54.                 fmul [sindiv]
  55.                 fistp dword[esi]
  56.                 add  esi,4
  57.                 fadd [sininc]
  58.                 loop .sinlp
  59.     call draw_window            ; at first, draw the window
  60.     call draw_stuff
  61.  
  62. gamestart:
  63. ;   ******* MOUSE CHECK *******
  64. ;    mov eax,37    ; check mouse (use mouse over window to navigate)
  65. ;    mov ebx,2     ; check mousebuttons
  66. ;    mcall
  67. ;    cmp eax,0    ; only use mouse when button down
  68. ;    je noneed    ; deactivated cause of disappear-bug etc.
  69.     mov eax,37
  70.     mov ebx,1     ; check mouseposition
  71.     mcall
  72.  
  73.     mov ebx,eax
  74.     shr eax,16
  75.     and eax,0x0000FFFF  ; mousex
  76.     and ebx,0x0000FFFF  ; mousey
  77.  
  78.     cmp eax,5  ; mouse out of window ?
  79.     jb check_refresh  ; it will prevent an app-crash
  80.     cmp ebx,22
  81.     jb check_refresh
  82.     cmp eax, 640
  83.     jg check_refresh
  84.     cmp ebx,501
  85.     jg check_refresh
  86.  
  87.     cmp eax,315 ; navigating?
  88.     jb m_left
  89.     cmp eax,325 ;
  90.     jg m_right
  91. continue:
  92.     cmp ebx,220 ;
  93.     jb s_up
  94.     cmp ebx,260 ;
  95.     jg s_down
  96. ;   ******* END OF MOUSE CHECK *******
  97. check_refresh:
  98.  
  99. ;    mov eax,23  ; wait for system event with 10 ms timeout
  100. ;    mov ebx,1   ; thats max 100 FPS
  101.     mov eax,11 ; ask no wait for full speed
  102.     mcall
  103.  
  104.     cmp  eax,1                  ; window redraw request ?
  105.     je   red2
  106.     cmp  eax,2                  ; key in buffer ?
  107.     je   key2
  108.     cmp  eax,3                  ; button in buffer ?
  109.     je   button2
  110.  
  111.     mov edi,[mouseya] ; check flag if a refresh has to be done
  112.     cmp edi,1
  113.     jne gamestart
  114.     mov [mouseya],dword 0
  115.     call draw_stuff
  116.  
  117.  
  118.     jmp gamestart
  119.  
  120. ; END OF MAINLOOP
  121.  
  122. red2:                          ; redraw
  123.     call draw_window
  124.     call draw_stuff
  125.     jmp  gamestart
  126.  
  127. key2:                          ; key
  128.     mov  eax,2
  129.     mcall
  130.     cmp  al,1
  131.     je   gamestart     ; keybuffer empty
  132.  
  133.     cmp ah,27    ; esc=End App
  134.     je finish
  135.  
  136.     cmp  ah,178  ; up
  137.     je   s_up
  138.     cmp  ah,177  ; down
  139.     je   s_down
  140.     cmp  ah,176  ; left
  141.     je   s_left
  142.     cmp  ah,179  ; right
  143.     je   s_right
  144.  
  145.     jmp gamestart ; was any other key
  146.  
  147.  
  148. s_up:             ; walk forward (key or mouse)
  149.     mov eax,[vpx]
  150.     mov ebx,[vpy]
  151.  
  152.  
  153.     mov ecx,[vheading]
  154.     mov edi,[sinus+ecx*4]
  155.  
  156.     mov edx,[vheading]
  157. ;    imul edx,4
  158. ;    add edx,sinus
  159. ;    add edx,3600
  160.     lea edx, [sinus+3600+edx*4]
  161.     cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600
  162.     jb ok200
  163.     sub edx,14400
  164.     ok200:
  165.     mov esi,[edx]
  166. ;    sal esi,1  ; edit walking speed here
  167. ;    sal edi,1
  168.  
  169.     add eax,edi ; newPx
  170.     add ebx,esi ; newPy
  171.     mov edi,eax ; newPx / ffff
  172.     mov esi,ebx ; newPy / ffff
  173.     sar edi,16
  174.     sar esi,16
  175.     mov ecx,esi
  176.     sal ecx,5 ; equal *32
  177. ;    add ecx,edi
  178. ;    add ecx,grid
  179.     lea ecx, [grid+ecx+edi]
  180.     cmp [ecx],byte 0  ; collision check
  181.     jne cannotwalk0
  182.     mov [vpx],eax
  183.     mov [vpy],ebx
  184.     mov [mouseya],dword 1 ; set refresh flag
  185. cannotwalk0:
  186.     jmp check_refresh
  187.  
  188. s_down:                    ; walk backward
  189.     mov eax,[vpx]
  190.     mov ebx,[vpy]
  191.  
  192.     mov ecx,[vheading]
  193.     mov edi,[sinus+ecx*4]
  194.  
  195.     mov edx,[vheading]
  196. ;    imul edx,4
  197. ;    add edx,sinus
  198. ;    add edx,3600
  199.     lea edx, [sinus+3600+edx*4]
  200.     cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600
  201.     jb ok201
  202.     sub edx,14400
  203.     ok201:
  204.  
  205.     mov esi,[edx]
  206. ;    sal esi,1  ; edit walking speed here
  207. ;    sal edi,1
  208.  
  209.     sub eax,edi ; newPx
  210.     sub ebx,esi ; newPy
  211.     mov edi,eax ; newPx / ffff
  212.     mov esi,ebx ; newPy / ffff
  213.     sar edi,16
  214.     sar esi,16
  215.     mov ecx,esi
  216.     sal ecx,5
  217. ;    add ecx,edi
  218. ;    add ecx,grid
  219.     lea ecx, [grid+ecx+edi]
  220.     cmp [ecx],byte 0
  221.     jne cannotwalk1
  222.     mov [vpx],eax
  223.     mov [vpy],ebx
  224.     mov [mouseya],dword 1
  225. cannotwalk1:
  226.     jmp check_refresh
  227.  
  228. s_left:                                   ; turn left (key)
  229.     mov edi,[vheading]  ; heading
  230.     add edi,50
  231.     cmp edi,3600
  232.     jb ok_heading0
  233.     sub edi,3600
  234.     ok_heading0:
  235.     mov [vheading],edi
  236.     mov [mouseya],dword 1
  237.     jmp check_refresh
  238.  
  239. s_right:                                  ; turn right
  240.     mov edi,[vheading]
  241.     sub edi,50
  242.     cmp edi,-1
  243.     jg ok_heading1
  244.     add edi,3600
  245.     ok_heading1:
  246.     mov [vheading],edi
  247.     mov [mouseya],dword 1
  248.     jmp check_refresh
  249.  
  250. m_left:                                   ; turn left (mouse)
  251.     mov edi,[vheading]  ; heading
  252.     mov ecx,315
  253.     sub ecx,eax
  254.     sar ecx,2
  255.     add edi,ecx
  256.     cmp edi,3600
  257.     jb ok_heading2
  258.     sub edi,3600
  259.     ok_heading2:
  260.     mov [vheading],edi
  261.     mov [mouseya],dword 1
  262.     jmp continue    ; allow both: walk and rotate
  263.  
  264. m_right:                                  ; turn right
  265.     mov edi,[vheading]
  266.     sub eax,325
  267.     sar eax,2
  268.     sub edi,eax
  269.     cmp edi,-1
  270.     jg ok_heading3
  271.     add edi,3600
  272.     ok_heading3:
  273.     mov [vheading],edi
  274.     mov [mouseya],dword 1
  275.     jmp continue
  276.  
  277.  
  278.  
  279.   button2:                       ; button
  280.     mov  eax,17                  ; get id
  281.     mcall
  282.     cmp  ah,1                   ; button id=1 ?
  283.     jne  gamestart
  284.  
  285. ; eo GAME mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
  286.  finish:
  287.     mov  eax,-1                 ; close this program
  288.     mcall
  289.  
  290.  
  291. ;   *********************************************
  292. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  293. ;   *********************************************
  294.  
  295.  
  296. draw_window:
  297.  
  298.         mcall   12,1
  299.        
  300.         mcall 48, 4                             ;get skin width
  301.         lea     ecx, [50*65536+484+eax]             ;[y start] *65536 + [y size] + [skin_height]
  302.         mcall   0,<50,649>,,0x34ffffff,,title   ;draw window
  303.  
  304.         mcall   12,2
  305.  
  306.     ret
  307.  
  308. ;   *********************************************
  309. ;   *******       COMPUTE 3D-VIEW        ********
  310. ;   *********************************************
  311. draw_stuff:
  312.  
  313.  
  314. mov [step1],dword 1
  315. ;mov [step64],dword 64
  316.     mov esi,[vheading]
  317.     add esi,320
  318.     mov [va],esi
  319.     mov eax,[vheading]
  320.     sub eax,320
  321.     mov [vacompare],eax
  322. ;------------------------------------ CAST 640 PIXEL COLUMNS ---------------
  323. ; FOR A=320+heading to -319+heading step -1 (a is stored in [va])
  324. ;---------------------------------------------------------------------------
  325. ;    mov edx,5
  326.     mov [vx1],dword 0  ;5  ;edx        ; init x1 ... pixelcolumn
  327. for_a:
  328. mov edx,[vx1]
  329. mov [vx1b],edx
  330. sub [vx1b],dword 320
  331.     mov edx,[va]  ; a2
  332.     cmp edx,-1   ; a2 is a mod 3600
  333.     jg ok1
  334.     add edx,3600
  335. ok1:
  336.     cmp edx,3600
  337.     jb ok2
  338.     sub edx,3600
  339. ok2:
  340.  
  341. ; get stepx and stepy
  342. ;    mov ecx,edx
  343. ;    imul ecx,4
  344. ;    add ecx,sinus     ; pointer to stepx
  345.     lea ecx, [sinus+edx*4]
  346.     mov esi,[ecx]
  347.     sar esi,4         ; accuracy
  348.     mov [vstepx],esi  ; store stepx
  349.  
  350. ;    mov esi,edx
  351. ;    imul esi,4
  352. ;    add esi,sinus  ; pointer to stepy
  353. ;    add esi,3600
  354.     lea esi, [sinus+3600+edx*4]
  355.     cmp esi,eosinus ;cosinus taken from ((sinus plus 900) mod 3600)
  356.     jb ok202
  357.     sub esi,14400
  358.     ok202:
  359.  
  360.     mov ecx,[esi]
  361.     sar ecx,4
  362.     mov [vstepy],ecx ; store stepy
  363.  
  364.  
  365.     mov eax,[vpx]    ; get Camera Position
  366.     mov ebx,[vpy]
  367.     mov [vxx],eax    ; init caster position
  368.     mov [vyy],ebx
  369.  
  370.     mov edi,0        ; init L (number of raycsting-steps)
  371.     mov [step1],dword 1  ; init Caster stepwidth for L
  372.  
  373.  ;  raycast a pixel column.................................
  374. raycast:
  375.     add edi,[step1]  ; count caster steps
  376. ;jmp nodouble ; use this to prevent blinking/wobbling textures: much slower!
  377.  
  378.     cmp edi,32
  379.     je double
  380.     cmp edi,512
  381.     je double
  382.     cmp edi,1024
  383.     je double
  384.     jmp nodouble
  385.  
  386.     double:
  387.     mov edx,[step1]
  388.     sal edx,1
  389.     mov [step1],edx
  390.  
  391.     mov edx,[vstepx]
  392.     sal edx,1
  393.     mov [vstepx],edx
  394.  
  395.     mov edx,[vstepy]
  396.     sal edx,1
  397.     mov [vstepy],edx
  398.  
  399. nodouble:
  400.  
  401.     mov eax,32000 ; 3600 ; determine Floors Height based on distance
  402.     mov edx,0
  403.     mov ebx,edi
  404.  
  405.     div ebx
  406.     mov esi,eax
  407.     mov [vdd],esi
  408.     mov edx,260
  409.     sub edx,esi
  410.     mov [vh],edx
  411.  
  412.     cmp edx,22
  413.     jb no_nu_pixel
  414.     cmp edx,259
  415.     jg no_nu_pixel ; draw only new pixels
  416.     cmp edx,[h_old]
  417.     je no_nu_pixel
  418.  
  419.     mov eax,[vxx] ; calc floor pixel
  420.     mov ebx,[vyy]
  421.  
  422.     and eax,0x0000FFFF
  423.     and ebx,0x0000FFFF
  424.  
  425.     shr eax,10
  426.     shr ebx,10    ; pixel coords inside Texture x,y 64*64
  427.     mov [xfrac],eax
  428.     mov [yfrac],ebx
  429.  
  430.  
  431.  
  432.     ; plot floor pixel !!!!
  433.     mov [vl],edi      ; save L
  434.     mov [ytemp],esi ; remember L bzw. H
  435.  
  436.     mov edi,[yfrac] ; get pixel color of this floor pixel
  437.     sal edi,8
  438.     mov esi,[xfrac]
  439.     sal esi,2
  440. ;    add edi,esi
  441. ;    add edi,wall ; in fact its floor, just using the wall texture :)
  442.     lea edi, [wall+edi+esi]
  443.  
  444.     mov edx,[edi]
  445.     mov [remesi],esi
  446.  
  447.     ;**** calculate pixel adress:****
  448.     mov esi,[ytemp]
  449.     add esi,240
  450.     imul esi,1920
  451. ;    add esi,[vx1]
  452. ;    add esi,[vx1]
  453. ;    add esi,[vx1]
  454. ;    add esi,0x80000
  455.     mov eax, [vx1]
  456.     lea eax, [eax+eax*2]
  457.     lea esi, [0x80000+eax+esi]
  458.  
  459.     cmp esi,0x80000+1920*480
  460.     jg foff0
  461.     cmp esi,0x80000
  462.     jb foff0
  463.     ; now we have the adress of the floor-pixel color in edi
  464.     ; and the adress of the pixel in the image in esi
  465.  
  466.     mov edx,[edi]
  467.     ;******************** custom distance DARKEN Floor
  468.  
  469.     mov eax,[vdd]
  470.  
  471. ; jmp nodark0 ; use this to deactivate darkening floor (a bit faster)
  472.  
  473.     cmp eax,80
  474.     jg nodark0
  475.     ;                split rgb
  476.  
  477.     mov [blue],edx
  478.     and [blue],dword 255
  479.  
  480.     shr edx,8
  481.     mov [green],edx
  482.     and [green],dword 255
  483.  
  484.     shr edx,8
  485.     mov [red],edx
  486.     and [red],dword 255
  487.  
  488.     mov eax,81    ; darkness parameter
  489.     sub eax,[vdd]
  490.     sal eax,1
  491.  
  492. ;                        reduce rgb
  493.     sub [red],eax
  494.     cmp [red], dword 0
  495.     jg notblack10
  496.     mov [red],dword 0
  497.     notblack10:
  498.  
  499.     sub [green],eax
  500.     cmp [green],dword 0
  501.     jg notblack20
  502.     mov [green],dword 0
  503.     notblack20:
  504.  
  505.     mov edx,[blue]
  506.     sub [blue],eax
  507.     cmp [blue],dword 0
  508.     jg notblack30
  509.     mov [blue],dword 0
  510.     notblack30:
  511.  
  512.     shl dword [red],16  ; reassemble rgb
  513.     shl dword [green],8
  514.     mov edx,[red]
  515.     or edx,[green]
  516.     or edx,[blue]
  517.  
  518. nodark0:
  519. ;   eo custom darken floor
  520.  
  521.  
  522.     mov eax,edx
  523.     mov [esi],eax ; actually draw the floor pixel
  524.  
  525.  ; paint "forgotten" pixels
  526.  
  527.     mov edx,[lasty]
  528.     sub edx,1920
  529.     cmp esi,edx
  530.     je foff0
  531.     mov [esi+1920],eax
  532.  
  533.     sub edx,1920
  534.     cmp esi,edx
  535.     je foff0
  536.     mov [edx+1920],eax
  537.  
  538.     sub edx,1920
  539.     cmp esi,edx
  540.     je foff0
  541.     mov [edx+1920],eax
  542.  
  543. foff0:
  544. mov [lasty],esi
  545. ;**** end of draw floor pixel ****
  546.  
  547.     mov esi,[remesi]
  548.     mov edi,[vl] ; restore L
  549.  
  550. no_nu_pixel:
  551.  
  552.  
  553.     mov esi,[vh]
  554.     mov [h_old],esi
  555.  
  556.     mov eax,[vxx]
  557.     mov ebx,[vyy]
  558.  
  559.     add eax,[vstepx]  ; casting...
  560.     add ebx,[vstepy]
  561.  
  562.     mov [vxx],eax
  563.     mov [vyy],ebx
  564.  
  565.     sar eax,16
  566.     sar ebx,16
  567.  
  568.     mov [vpxi],eax    ; casters position in Map Grid
  569.     mov [vpyi],ebx
  570.  
  571.     mov edx,ebx
  572. ;    imul edx,32
  573.     shl edx,5
  574. ;    add edx,grid
  575. ;    add edx,eax
  576.     lea edx, [grid+edx+eax]
  577.  
  578.     cmp [edx],byte 0   ; raycaster reached a wall? (0=no)
  579.     jne getout
  580.     cmp edi,10000        ; limit view range
  581.     jb raycast
  582. ;................................................
  583. getout:
  584.     mov eax,[edx]      ; store Grid Wall Value for Texture Selection
  585.     mov [vk],eax
  586.  
  587.  call blur  ; deactivate this (blurs the near floor) : a bit faster
  588.  
  589. ; simply copy floor to ceil pixel column here
  590. ;jmp nocopy ; use this for test purposes
  591.  
  592.     pusha
  593.     mov eax,0x80000+1920*240
  594.     mov ebx,0x80000+1920*240
  595.  
  596. copyfloor:
  597.     sub eax,1920
  598.     add ebx,1920
  599.  
  600. ;    mov ecx,0
  601. ;    add ecx,[vx1]
  602. ;    add ecx,[vx1]
  603. ;    add ecx,[vx1]
  604.     mov ecx, [vx1]
  605.     lea ecx, [ecx+ecx*2]
  606.  
  607. ;    mov edx,ecx
  608. ;    add ecx,eax
  609. ;    add edx,ebx
  610.     lea edx, [ecx+ebx]
  611.     add ecx,eax
  612.  
  613.     mov esi,[edx]
  614.     mov [ecx],esi
  615.  
  616.     cmp eax,0x80000
  617.     jg copyfloor
  618.  
  619.     popa
  620. ; *** end of copy floor to ceil
  621. ;nocopy:
  622. ;__________________________________________________________________________
  623.  
  624.  
  625. ; draw this pixelrows wall
  626.     mov [vl],edi
  627.  
  628.     mov edi,260
  629.     sub edi,[vdd]
  630.     cmp edi,0
  631.     jg ok3
  632.     xor edi,edi
  633.     ok3:
  634.     mov [vbottom],edi  ; end wall ceil (or window top)
  635.  
  636.     mov esi,262
  637.     add esi,[vdd]  ; start wall floor
  638.  
  639.     xor edi,edi
  640.  
  641. ; somethin is wrong with xfrac,so recalc...
  642.  
  643.     mov eax,[vxx]
  644.     and eax,0x0000FFFF
  645.     shr eax,10
  646.     mov [xfrac],eax
  647.  
  648.     mov eax,[vyy]
  649.     and eax,0x0000FFFF
  650.     shr eax,10
  651.     mov [yfrac],eax
  652.  
  653.     pixelrow:
  654.  
  655. ; find each pixels color:
  656.  
  657.     add edi,64
  658.     sub esi,1
  659.     cmp esi, 502  ; dont calc offscreen-pixels
  660.     jg speedup
  661.  
  662.     xor edx,edx
  663.     mov eax, edi
  664.     mov ebx,[vdd]
  665. ;    add ebx,[vdd]
  666.     add ebx, ebx
  667.     div ebx
  668.     and eax,63
  669.     mov [ytemp],eax   ; get y of texture for wall
  670.  
  671.     mov eax,[xfrac]
  672.     add eax,[yfrac]
  673.  
  674.     and eax,63
  675.     mov [xtemp],eax   ; get x of texture for wall
  676.  
  677.     ; now prepare to plot that wall-pixel...
  678.     mov [remedi],edi
  679.  
  680.     mov edi,[ytemp]
  681.     sal edi,8
  682.     mov edx,[xtemp]
  683.     sal edx,2
  684.     add edi,edx
  685.  
  686.     mov eax,[vk] ; determine which texture should be used
  687.     and eax,255
  688.  
  689.     cmp eax,1
  690.     jne checkmore1
  691.     add edi,ceil
  692.     jmp foundtex
  693.     checkmore1:
  694.  
  695.     cmp eax,2
  696.     jne checkmore2
  697.     add edi,wall
  698.     jmp foundtex
  699.     checkmore2:
  700.  
  701.     cmp eax,3
  702.     jne checkmore3
  703.     add edi,wall2
  704.     jmp foundtex
  705.     checkmore3:
  706.  
  707.     cmp eax,4
  708.     jne checkmore4
  709.     add edi,wall3
  710.     jmp foundtex
  711.     checkmore4:
  712.  
  713.     cmp eax,5
  714.     jne checkmore5
  715.     add edi,wall4
  716.     jmp foundtex
  717.     checkmore5:
  718.  
  719.     cmp eax,6
  720.     jne checkmore6
  721.     add edi,wall5
  722.     jmp foundtex
  723.     checkmore6:
  724.  
  725.     cmp eax,7
  726.     jne checkmore7
  727.     add edi,wall6
  728.     jmp foundtex
  729.     checkmore7:
  730.  
  731.     cmp eax,8
  732.     jne checkmore8
  733.     add edi,wall7
  734.     jmp foundtex
  735.     checkmore8:
  736.  
  737.     foundtex:
  738.  
  739.     mov edx,[edi]    ; get pixel color inside texture
  740.  
  741. ; ***pseudoshade south-west
  742. jmp east ; activate this for southwest pseudoshade : a bit slower + blink-bug
  743.     mov edi,[yfrac]
  744.     mov [pseudo],dword 0 ; store flag for custom distance darkening
  745.     cmp edi,[xfrac]
  746.     jge east
  747.     and edx,0x00FEFEFE
  748.     shr edx,1
  749.     mov [pseudo],dword 1
  750. east:
  751.  
  752.  call dark_distance ; deactivate wall distance darkening: a bit faster
  753.  
  754. ; ******* DRAW WALL PIXEL *******
  755.     mov eax,esi
  756. ;    sub eax,22
  757.     lea eax, [esi-22]
  758.     imul eax,1920
  759. ;    add eax,[vx1]
  760. ;    add eax,[vx1]
  761. ;    add eax,[vx1]
  762. ;    add eax,0x80000
  763.     mov ebx, [vx1]
  764.     lea ebx, [ebx+ebx*2]
  765.     lea eax, [eax+0x80000+ebx]
  766.  
  767.     cmp eax,0x80000+1920*480
  768.     jg dont_draw
  769.     cmp eax,0x80000
  770.     jb dont_draw
  771.     mov [eax],edx ; actually set the pixel in the image
  772. ; *** eo draw wall pixel
  773. dont_draw:
  774.     mov edi,[remedi]
  775. speedup:
  776.     cmp esi,[vbottom]  ; end of this column?
  777.     jg pixelrow
  778.  
  779.     mov edi,[vl]  ; restoring
  780.     mov eax,[vx1] ; inc X1
  781.     add eax,1
  782.     mov [vx1],eax
  783.  
  784.     ;*** NEXT A ***
  785.     mov esi,[va]
  786.     sub esi,1
  787.     mov [va],esi
  788.     cmp esi,[vacompare]
  789.     jg for_a
  790.     ;*** EO NEXT A ***
  791. ;---------------------------------------------------------------------------
  792.  
  793.  
  794. ; **** put image !!!!!****
  795. ; ***********************
  796.     mov eax,7
  797.     mov ebx,0x80000
  798.     mov ecx,640*65536+480
  799.     xor edx,edx
  800.     mcall
  801.  
  802.     ret
  803.  
  804. blur:
  805.  
  806. pusha
  807. mov eax,0x080000+360*1920
  808.  
  809. copyfloor2:
  810.     add eax,1920
  811. ;    mov ebx,eax
  812. ;    add ebx,[vx1]
  813. ;    add ebx,[vx1]
  814. ;    add ebx,[vx1]
  815.     mov ebx,[vx1]
  816.     lea ebx, [ebx+ebx*2]
  817.     add ebx, eax
  818.  
  819.  
  820.     mov ecx,[ebx-15]
  821.     and ecx,0x00FEFEFE
  822.     shr ecx,1
  823.     mov edx,[ebx-12]
  824.     and edx,0x00FEFEFE
  825.     shr edx,1
  826.     add edx,ecx
  827.     and edx,0x00FEFEFE
  828.     shr edx,1
  829.  
  830.      mov ecx,[ebx-9]
  831.      and ecx,0x00FEFEFE
  832.      shr ecx,1
  833.      add edx,ecx
  834.  
  835.       and edx,0x00FEFEFE
  836.       shr edx,1
  837.  
  838.       mov ecx,[ebx-6]
  839.       and ecx,0x00FEFEFE
  840.       shr ecx,1
  841.       add edx,ecx
  842.  
  843.        and edx,0x00FEFEFE
  844.        shr edx,1
  845.  
  846.        mov ecx,[ebx-3]
  847.        and ecx,0x00FEFEFE
  848.        shr ecx,1
  849.        add edx,ecx
  850.  
  851.         and edx,0x00FEFEFE
  852.         shr edx,1
  853.  
  854.         mov ecx,[ebx]
  855.         and ecx,0x00FEFEFE
  856.         shr ecx,1
  857.         add edx,ecx
  858.  
  859.     mov [ebx],edx
  860.  
  861.     cmp eax,0x80000+478*1920
  862.     jb copyfloor2
  863.  
  864. popa
  865.  
  866. ret
  867.  
  868.  
  869.  
  870. ; ******* Darken by Distance *******
  871. dark_distance:
  872.  
  873. ; color must be in edx, wall height in [vdd]
  874.  
  875.     mov eax,[vdd]
  876.     cmp eax,50
  877.     jg nodark
  878.     ;                split rgb
  879.  
  880.     mov [blue],edx
  881.     and [blue],dword 255
  882.  
  883.     shr edx,8
  884.     mov [green],edx
  885.     and [green],dword 255
  886.  
  887.     shr edx,8
  888.     mov [red],edx
  889.     and [red],dword 255
  890.  
  891.     mov eax,51    ; darkness parameter
  892.     sub eax,[vdd]
  893.     cmp [pseudo],dword 1
  894.     je isdarkside
  895.     sal eax,2
  896. isdarkside:
  897.  
  898. ;                        reduce rgb
  899.     sub [red],eax
  900.     cmp [red], dword 0
  901.     jg notblack10b
  902.     mov [red],dword 0
  903.     notblack10b:
  904.  
  905.     sub [green],eax
  906.     cmp [green],dword 0
  907.     jg notblack20b
  908.     mov [green],dword 0
  909.     notblack20b:
  910.  
  911.     mov edx,[blue]
  912.     sub [blue],eax
  913.     cmp [blue],dword 0
  914.     jg notblack30b
  915.     mov [blue],dword 0
  916.     notblack30b:
  917.  
  918.     shl dword [red],16 ; reassemble rgb
  919.     shl dword [green],8
  920.     mov edx,[red]
  921.     or edx,[green]
  922.     or edx,[blue]
  923.     mov eax,edx
  924.  
  925. nodark:
  926.  
  927.     ret
  928.  
  929.  
  930. ; DATA AREA
  931.  
  932. ;ceil=ceil
  933. ;wall=wall floor
  934. ;2 corner stone
  935. ;3 leaf mosaic
  936. ;4 closed window
  937. ;5 greek mosaic
  938. ;6 old street stones
  939. ;7 maya wall
  940.  
  941. grid:  ; 32*32 Blocks, Map: 0 = Air, 1 to 8 = Wall
  942. db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
  943. db 1,0,0,0,1,0,0,0,0,0,0,3,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8
  944. db 5,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8
  945. db 1,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,1,0,0,0,0,3,3,3,3,0,0,0,0,0,0,8
  946. db 5,0,1,2,3,4,5,6,7,8,2,1,3,3,3,0,5,0,2,1,2,3,0,0,0,0,0,0,0,0,0,8
  947. db 1,0,0,0,0,0,0,0,0,0,2,3,0,0,0,0,5,0,0,0,0,3,0,0,0,0,0,0,0,0,0,8
  948. db 5,0,0,0,1,0,0,4,0,0,0,1,0,0,0,0,5,0,0,0,0,3,3,0,3,3,0,0,0,0,0,8
  949. db 1,1,0,1,1,1,1,4,1,0,1,3,0,0,0,0,5,2,1,2,0,3,0,0,0,3,0,0,0,0,0,8
  950. db 5,0,0,0,1,0,0,0,0,0,0,1,0,3,3,3,5,0,0,0,0,3,0,0,0,3,0,0,0,0,0,8
  951. db 1,0,0,0,1,0,0,5,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,3,0,0,0,0,0,8
  952. db 5,0,0,0,0,0,0,5,0,0,0,1,0,0,0,0,5,0,0,0,0,3,0,0,0,0,0,0,0,0,0,8
  953. db 1,4,4,4,4,4,4,4,4,4,4,3,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,8,8
  954. db 2,2,2,2,2,2,8,8,8,8,8,8,8,8,8,0,0,0,6,6,0,7,7,7,7,7,7,7,7,7,8,8
  955. db 1,0,0,0,1,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,1
  956. db 5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,2,2,2,2,0,0,0,0,3,3,3,3,3,1
  957. db 1,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,6,0,0,0,0,2,0,0,0,0,3,0,0,0,0,1
  958. db 5,0,2,3,2,3,2,3,2,3,2,1,0,0,0,0,6,0,2,2,0,2,0,0,0,0,3,0,5,5,0,1
  959. db 1,0,0,0,0,0,0,4,0,0,0,3,0,0,0,0,6,0,0,2,0,2,0,2,0,0,3,0,0,0,0,1
  960. db 5,0,0,0,1,0,0,4,0,0,0,1,0,0,0,0,6,0,0,2,2,2,0,2,0,0,3,3,3,3,0,1
  961. db 1,1,0,1,1,1,1,4,1,0,1,3,7,7,7,0,6,0,0,0,0,0,0,2,0,0,0,0,0,3,0,1
  962. db 5,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,6,0,0,0,0,2,2,2,0,0,0,0,0,3,0,1
  963. db 1,0,0,0,1,0,0,5,0,0,0,3,0,0,0,0,6,0,0,0,0,2,0,0,0,0,0,0,0,0,0,1
  964. db 5,0,0,0,0,0,0,5,0,0,0,1,0,0,0,0,6,0,5,1,0,2,0,0,4,4,0,4,4,0,0,1
  965. db 1,4,1,4,1,4,1,4,1,4,1,3,0,0,0,0,6,0,0,5,0,2,0,0,0,4,0,4,0,0,0,1
  966. db 1,0,0,0,0,0,0,4,0,0,0,3,0,3,3,3,6,0,0,1,0,1,0,0,4,4,0,4,4,0,0,1
  967. db 5,0,0,0,1,0,0,4,0,0,0,1,0,0,0,0,6,0,0,5,0,1,0,4,4,0,0,0,4,4,0,1
  968. db 1,1,0,1,1,1,1,4,1,0,1,3,0,0,0,0,6,0,0,1,0,1,0,4,0,0,0,0,0,4,0,1
  969. db 5,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,6,0,0,5,0,1,0,4,0,0,0,0,0,4,0,1
  970. db 1,0,0,0,1,0,0,5,0,0,0,3,0,0,0,0,6,1,5,1,0,1,0,4,4,0,0,0,4,4,0,1
  971. db 5,0,0,0,0,0,0,5,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,4,4,4,4,4,0,0,1
  972. db 1,4,1,4,1,4,1,4,1,4,1,3,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1
  973. db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
  974.  
  975. vpx:
  976. dd 0x0001FFFF ; initial player position * 0xFFFF
  977.  vpy:
  978. dd 0x0001FFFF
  979.  
  980. title    db   'FISHEYE RAYCASTING ENGINE ETC. FREE3D',0
  981.  
  982. sindegree dd 0.0
  983. sininc    dd 0.0017453292519943295769236907684886
  984. sindiv    dd 6553.5
  985. textures:
  986.         file 'texture.gif'
  987.  
  988. align 4
  989.  
  990. col1:
  991.  dd ?;-
  992. ; misc raycaster vars:
  993. vxx:
  994.  dd ?;-
  995. vyy:
  996.  dd ?;-
  997. vl:
  998.  dd ?;-
  999. vstepx:
  1000.  dd ?;-
  1001. vstepy:
  1002.  dd ?;-
  1003. vxxint:
  1004.  dd ?;-
  1005. vyyint:
  1006.  dd ?;-
  1007. vk:
  1008.  dd ?;-
  1009. va:
  1010.  dd ?;-
  1011. va2:
  1012.  dd ?;-
  1013. vdd:
  1014.  dd ?;-
  1015. vx1:
  1016.  dd ?;-
  1017. vx1b:
  1018.  dd ?;-
  1019. vh:
  1020.  dd ?;-
  1021. vdt:
  1022.  dd ?;-
  1023. vheading: ; initial heading: 0 to 3599
  1024.  dd ?;-
  1025. vacompare:
  1026.  dd ?;-
  1027. vpxi:
  1028.  dd ?;-
  1029. vpyi:
  1030.  dd ?;-
  1031. wtolong:
  1032.  dw ?,?;-,?;-
  1033.  
  1034. xtemp:
  1035.  dd ?;-
  1036. ytemp:
  1037.  dd ?;-
  1038. xfrac:
  1039.  dd ?;-
  1040. yfrac:
  1041.  dd ?;-
  1042. h_old:
  1043.  dd ?;-
  1044. vbottom:
  1045.  dd ?;-
  1046. mouseya:
  1047.  dd ?;-
  1048. remeax:
  1049.  dd ?;-
  1050. remebx:
  1051.  dd ?;-
  1052. remecx:
  1053.  dd ?;-
  1054. remedx:
  1055.  dd ?;-
  1056. remedi:
  1057.  dd ?;-
  1058. remesi:
  1059.  dd ?;-
  1060. red:
  1061.  dd ?;-
  1062. green:
  1063.  dd ?;-
  1064. blue:
  1065.  dd ?;-
  1066. pseudo:
  1067.  dd ?;-
  1068. step1:
  1069.  dd ?;-
  1070. step64:
  1071.  dd ?;-
  1072. lasty:
  1073.  dd ?;-
  1074.  
  1075. I_END:
  1076. IncludeUGlobals
  1077. sinus rd 360*10
  1078. eosinus:
  1079.