Subversion Repositories Kolibri OS

Rev

Rev 552 | Rev 2493 | 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.     mov  eax,12                    ; function 12:tell os about windowdraw
  299.     mov  ebx,1                     ; 1, start of draw
  300.     mcall
  301.  
  302.                                    ; DRAW WINDOW
  303.     mov  eax,0                     ; function 0 : define and draw window
  304.     mov  ebx,50*65536+649         ; [x start] *65536 + [x size]
  305.     mov  ecx,50*65536+506         ; [y start] *65536 + [y size]
  306.     mov  edx,0x74ffffff            ; color of work area RRGGBB,8->color gl
  307.     mov  edi,title
  308.     mcall
  309.  
  310.     mov  eax,12                    ; function 12:tell os about windowdraw
  311.     mov  ebx,2                     ; 2, end of draw
  312.     mcall
  313.  
  314.     ret
  315.  
  316. ;   *********************************************
  317. ;   *******       COMPUTE 3D-VIEW        ********
  318. ;   *********************************************
  319. draw_stuff:
  320.  
  321.  
  322. mov [step1],dword 1
  323. ;mov [step64],dword 64
  324.     mov esi,[vheading]
  325.     add esi,320
  326.     mov [va],esi
  327.     mov eax,[vheading]
  328.     sub eax,320
  329.     mov [vacompare],eax
  330. ;------------------------------------ CAST 640 PIXEL COLUMNS ---------------
  331. ; FOR A=320+heading to -319+heading step -1 (a is stored in [va])
  332. ;---------------------------------------------------------------------------
  333. ;    mov edx,5
  334.     mov [vx1],dword 0  ;5  ;edx        ; init x1 ... pixelcolumn
  335. for_a:
  336. mov edx,[vx1]
  337. mov [vx1b],edx
  338. sub [vx1b],dword 320
  339.     mov edx,[va]  ; a2
  340.     cmp edx,-1   ; a2 is a mod 3600
  341.     jg ok1
  342.     add edx,3600
  343. ok1:
  344.     cmp edx,3600
  345.     jb ok2
  346.     sub edx,3600
  347. ok2:
  348.  
  349. ; get stepx and stepy
  350. ;    mov ecx,edx
  351. ;    imul ecx,4
  352. ;    add ecx,sinus     ; pointer to stepx
  353.     lea ecx, [sinus+edx*4]
  354.     mov esi,[ecx]
  355.     sar esi,4         ; accuracy
  356.     mov [vstepx],esi  ; store stepx
  357.  
  358. ;    mov esi,edx
  359. ;    imul esi,4
  360. ;    add esi,sinus  ; pointer to stepy
  361. ;    add esi,3600
  362.     lea esi, [sinus+3600+edx*4]
  363.     cmp esi,eosinus ;cosinus taken from ((sinus plus 900) mod 3600)
  364.     jb ok202
  365.     sub esi,14400
  366.     ok202:
  367.  
  368.     mov ecx,[esi]
  369.     sar ecx,4
  370.     mov [vstepy],ecx ; store stepy
  371.  
  372.  
  373.     mov eax,[vpx]    ; get Camera Position
  374.     mov ebx,[vpy]
  375.     mov [vxx],eax    ; init caster position
  376.     mov [vyy],ebx
  377.  
  378.     mov edi,0        ; init L (number of raycsting-steps)
  379.     mov [step1],dword 1  ; init Caster stepwidth for L
  380.  
  381.  ;  raycast a pixel column.................................
  382. raycast:
  383.     add edi,[step1]  ; count caster steps
  384. ;jmp nodouble ; use this to prevent blinking/wobbling textures: much slower!
  385.  
  386.     cmp edi,32
  387.     je double
  388.     cmp edi,512
  389.     je double
  390.     cmp edi,1024
  391.     je double
  392.     jmp nodouble
  393.  
  394.     double:
  395.     mov edx,[step1]
  396.     sal edx,1
  397.     mov [step1],edx
  398.  
  399.     mov edx,[vstepx]
  400.     sal edx,1
  401.     mov [vstepx],edx
  402.  
  403.     mov edx,[vstepy]
  404.     sal edx,1
  405.     mov [vstepy],edx
  406.  
  407. nodouble:
  408.  
  409.     mov eax,32000 ; 3600 ; determine Floors Height based on distance
  410.     mov edx,0
  411.     mov ebx,edi
  412.  
  413.     div ebx
  414.     mov esi,eax
  415.     mov [vdd],esi
  416.     mov edx,260
  417.     sub edx,esi
  418.     mov [vh],edx
  419.  
  420.     cmp edx,22
  421.     jb no_nu_pixel
  422.     cmp edx,259
  423.     jg no_nu_pixel ; draw only new pixels
  424.     cmp edx,[h_old]
  425.     je no_nu_pixel
  426.  
  427.     mov eax,[vxx] ; calc floor pixel
  428.     mov ebx,[vyy]
  429.  
  430.     and eax,0x0000FFFF
  431.     and ebx,0x0000FFFF
  432.  
  433.     shr eax,10
  434.     shr ebx,10    ; pixel coords inside Texture x,y 64*64
  435.     mov [xfrac],eax
  436.     mov [yfrac],ebx
  437.  
  438.  
  439.  
  440.     ; plot floor pixel !!!!
  441.     mov [vl],edi      ; save L
  442.     mov [ytemp],esi ; remember L bzw. H
  443.  
  444.     mov edi,[yfrac] ; get pixel color of this floor pixel
  445.     sal edi,8
  446.     mov esi,[xfrac]
  447.     sal esi,2
  448. ;    add edi,esi
  449. ;    add edi,wall ; in fact its floor, just using the wall texture :)
  450.     lea edi, [wall+edi+esi]
  451.  
  452.     mov edx,[edi]
  453.     mov [remesi],esi
  454.  
  455.     ;**** calculate pixel adress:****
  456.     mov esi,[ytemp]
  457.     add esi,240
  458.     imul esi,1920
  459. ;    add esi,[vx1]
  460. ;    add esi,[vx1]
  461. ;    add esi,[vx1]
  462. ;    add esi,0x80000
  463.     mov eax, [vx1]
  464.     lea eax, [eax+eax*2]
  465.     lea esi, [0x80000+eax+esi]
  466.  
  467.     cmp esi,0x80000+1920*480
  468.     jg foff0
  469.     cmp esi,0x80000
  470.     jb foff0
  471.     ; now we have the adress of the floor-pixel color in edi
  472.     ; and the adress of the pixel in the image in esi
  473.  
  474.     mov edx,[edi]
  475.     ;******************** custom distance DARKEN Floor
  476.  
  477.     mov eax,[vdd]
  478.  
  479. ; jmp nodark0 ; use this to deactivate darkening floor (a bit faster)
  480.  
  481.     cmp eax,80
  482.     jg nodark0
  483.     ;                split rgb
  484.  
  485.     mov [blue],edx
  486.     and [blue],dword 255
  487.  
  488.     shr edx,8
  489.     mov [green],edx
  490.     and [green],dword 255
  491.  
  492.     shr edx,8
  493.     mov [red],edx
  494.     and [red],dword 255
  495.  
  496.     mov eax,81    ; darkness parameter
  497.     sub eax,[vdd]
  498.     sal eax,1
  499.  
  500. ;                        reduce rgb
  501.     sub [red],eax
  502.     cmp [red], dword 0
  503.     jg notblack10
  504.     mov [red],dword 0
  505.     notblack10:
  506.  
  507.     sub [green],eax
  508.     cmp [green],dword 0
  509.     jg notblack20
  510.     mov [green],dword 0
  511.     notblack20:
  512.  
  513.     mov edx,[blue]
  514.     sub [blue],eax
  515.     cmp [blue],dword 0
  516.     jg notblack30
  517.     mov [blue],dword 0
  518.     notblack30:
  519.  
  520.     shl dword [red],16  ; reassemble rgb
  521.     shl dword [green],8
  522.     mov edx,[red]
  523.     or edx,[green]
  524.     or edx,[blue]
  525.  
  526. nodark0:
  527. ;   eo custom darken floor
  528.  
  529.  
  530.     mov eax,edx
  531.     mov [esi],eax ; actually draw the floor pixel
  532.  
  533.  ; paint "forgotten" pixels
  534.  
  535.     mov edx,[lasty]
  536.     sub edx,1920
  537.     cmp esi,edx
  538.     je foff0
  539.     mov [esi+1920],eax
  540.  
  541.     sub edx,1920
  542.     cmp esi,edx
  543.     je foff0
  544.     mov [edx+1920],eax
  545.  
  546.     sub edx,1920
  547.     cmp esi,edx
  548.     je foff0
  549.     mov [edx+1920],eax
  550.  
  551. foff0:
  552. mov [lasty],esi
  553. ;**** end of draw floor pixel ****
  554.  
  555.     mov esi,[remesi]
  556.     mov edi,[vl] ; restore L
  557.  
  558. no_nu_pixel:
  559.  
  560.  
  561.     mov esi,[vh]
  562.     mov [h_old],esi
  563.  
  564.     mov eax,[vxx]
  565.     mov ebx,[vyy]
  566.  
  567.     add eax,[vstepx]  ; casting...
  568.     add ebx,[vstepy]
  569.  
  570.     mov [vxx],eax
  571.     mov [vyy],ebx
  572.  
  573.     sar eax,16
  574.     sar ebx,16
  575.  
  576.     mov [vpxi],eax    ; casters position in Map Grid
  577.     mov [vpyi],ebx
  578.  
  579.     mov edx,ebx
  580. ;    imul edx,32
  581.     shl edx,5
  582. ;    add edx,grid
  583. ;    add edx,eax
  584.     lea edx, [grid+edx+eax]
  585.  
  586.     cmp [edx],byte 0   ; raycaster reached a wall? (0=no)
  587.     jne getout
  588.     cmp edi,10000        ; limit view range
  589.     jb raycast
  590. ;................................................
  591. getout:
  592.     mov eax,[edx]      ; store Grid Wall Value for Texture Selection
  593.     mov [vk],eax
  594.  
  595.  call blur  ; deactivate this (blurs the near floor) : a bit faster
  596.  
  597. ; simply copy floor to ceil pixel column here
  598. ;jmp nocopy ; use this for test purposes
  599.  
  600.     pusha
  601.     mov eax,0x80000+1920*240
  602.     mov ebx,0x80000+1920*240
  603.  
  604. copyfloor:
  605.     sub eax,1920
  606.     add ebx,1920
  607.  
  608. ;    mov ecx,0
  609. ;    add ecx,[vx1]
  610. ;    add ecx,[vx1]
  611. ;    add ecx,[vx1]
  612.     mov ecx, [vx1]
  613.     lea ecx, [ecx+ecx*2]
  614.  
  615. ;    mov edx,ecx
  616. ;    add ecx,eax
  617. ;    add edx,ebx
  618.     lea edx, [ecx+ebx]
  619.     add ecx,eax
  620.  
  621.     mov esi,[edx]
  622.     mov [ecx],esi
  623.  
  624.     cmp eax,0x80000
  625.     jg copyfloor
  626.  
  627.     popa
  628. ; *** end of copy floor to ceil
  629. ;nocopy:
  630. ;__________________________________________________________________________
  631.  
  632.  
  633. ; draw this pixelrows wall
  634.     mov [vl],edi
  635.  
  636.     mov edi,260
  637.     sub edi,[vdd]
  638.     cmp edi,0
  639.     jg ok3
  640.     xor edi,edi
  641.     ok3:
  642.     mov [vbottom],edi  ; end wall ceil (or window top)
  643.  
  644.     mov esi,262
  645.     add esi,[vdd]  ; start wall floor
  646.  
  647.     xor edi,edi
  648.  
  649. ; somethin is wrong with xfrac,so recalc...
  650.  
  651.     mov eax,[vxx]
  652.     and eax,0x0000FFFF
  653.     shr eax,10
  654.     mov [xfrac],eax
  655.  
  656.     mov eax,[vyy]
  657.     and eax,0x0000FFFF
  658.     shr eax,10
  659.     mov [yfrac],eax
  660.  
  661.     pixelrow:
  662.  
  663. ; find each pixels color:
  664.  
  665.     add edi,64
  666.     sub esi,1
  667.     cmp esi, 502  ; dont calc offscreen-pixels
  668.     jg speedup
  669.  
  670.     xor edx,edx
  671.     mov eax, edi
  672.     mov ebx,[vdd]
  673. ;    add ebx,[vdd]
  674.     add ebx, ebx
  675.     div ebx
  676.     and eax,63
  677.     mov [ytemp],eax   ; get y of texture for wall
  678.  
  679.     mov eax,[xfrac]
  680.     add eax,[yfrac]
  681.  
  682.     and eax,63
  683.     mov [xtemp],eax   ; get x of texture for wall
  684.  
  685.     ; now prepare to plot that wall-pixel...
  686.     mov [remedi],edi
  687.  
  688.     mov edi,[ytemp]
  689.     sal edi,8
  690.     mov edx,[xtemp]
  691.     sal edx,2
  692.     add edi,edx
  693.  
  694.     mov eax,[vk] ; determine which texture should be used
  695.     and eax,255
  696.  
  697.     cmp eax,1
  698.     jne checkmore1
  699.     add edi,ceil
  700.     jmp foundtex
  701.     checkmore1:
  702.  
  703.     cmp eax,2
  704.     jne checkmore2
  705.     add edi,wall
  706.     jmp foundtex
  707.     checkmore2:
  708.  
  709.     cmp eax,3
  710.     jne checkmore3
  711.     add edi,wall2
  712.     jmp foundtex
  713.     checkmore3:
  714.  
  715.     cmp eax,4
  716.     jne checkmore4
  717.     add edi,wall3
  718.     jmp foundtex
  719.     checkmore4:
  720.  
  721.     cmp eax,5
  722.     jne checkmore5
  723.     add edi,wall4
  724.     jmp foundtex
  725.     checkmore5:
  726.  
  727.     cmp eax,6
  728.     jne checkmore6
  729.     add edi,wall5
  730.     jmp foundtex
  731.     checkmore6:
  732.  
  733.     cmp eax,7
  734.     jne checkmore7
  735.     add edi,wall6
  736.     jmp foundtex
  737.     checkmore7:
  738.  
  739.     cmp eax,8
  740.     jne checkmore8
  741.     add edi,wall7
  742.     jmp foundtex
  743.     checkmore8:
  744.  
  745.     foundtex:
  746.  
  747.     mov edx,[edi]    ; get pixel color inside texture
  748.  
  749. ; ***pseudoshade south-west
  750. jmp east ; activate this for southwest pseudoshade : a bit slower + blink-bug
  751.     mov edi,[yfrac]
  752.     mov [pseudo],dword 0 ; store flag for custom distance darkening
  753.     cmp edi,[xfrac]
  754.     jge east
  755.     and edx,0x00FEFEFE
  756.     shr edx,1
  757.     mov [pseudo],dword 1
  758. east:
  759.  
  760.  call dark_distance ; deactivate wall distance darkening: a bit faster
  761.  
  762. ; ******* DRAW WALL PIXEL *******
  763.     mov eax,esi
  764. ;    sub eax,22
  765.     lea eax, [esi-22]
  766.     imul eax,1920
  767. ;    add eax,[vx1]
  768. ;    add eax,[vx1]
  769. ;    add eax,[vx1]
  770. ;    add eax,0x80000
  771.     mov ebx, [vx1]
  772.     lea ebx, [ebx+ebx*2]
  773.     lea eax, [eax+0x80000+ebx]
  774.  
  775.     cmp eax,0x80000+1920*480
  776.     jg dont_draw
  777.     cmp eax,0x80000
  778.     jb dont_draw
  779.     mov [eax],edx ; actually set the pixel in the image
  780. ; *** eo draw wall pixel
  781. dont_draw:
  782.     mov edi,[remedi]
  783. speedup:
  784.     cmp esi,[vbottom]  ; end of this column?
  785.     jg pixelrow
  786.  
  787.     mov edi,[vl]  ; restoring
  788.     mov eax,[vx1] ; inc X1
  789.     add eax,1
  790.     mov [vx1],eax
  791.  
  792.     ;*** NEXT A ***
  793.     mov esi,[va]
  794.     sub esi,1
  795.     mov [va],esi
  796.     cmp esi,[vacompare]
  797.     jg for_a
  798.     ;*** EO NEXT A ***
  799. ;---------------------------------------------------------------------------
  800.  
  801.  
  802. ; **** put image !!!!!****
  803. ; ***********************
  804.     mov eax,7
  805.     mov ebx,0x80000
  806.     mov ecx,640*65536+480
  807.     xor edx,edx
  808.     mcall
  809.  
  810.     ret
  811.  
  812. blur:
  813.  
  814. pusha
  815. mov eax,0x080000+360*1920
  816.  
  817. copyfloor2:
  818.     add eax,1920
  819. ;    mov ebx,eax
  820. ;    add ebx,[vx1]
  821. ;    add ebx,[vx1]
  822. ;    add ebx,[vx1]
  823.     mov ebx,[vx1]
  824.     lea ebx, [ebx+ebx*2]
  825.     add ebx, eax
  826.  
  827.  
  828.     mov ecx,[ebx-15]
  829.     and ecx,0x00FEFEFE
  830.     shr ecx,1
  831.     mov edx,[ebx-12]
  832.     and edx,0x00FEFEFE
  833.     shr edx,1
  834.     add edx,ecx
  835.     and edx,0x00FEFEFE
  836.     shr edx,1
  837.  
  838.      mov ecx,[ebx-9]
  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-6]
  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-3]
  855.        and ecx,0x00FEFEFE
  856.        shr ecx,1
  857.        add edx,ecx
  858.  
  859.         and edx,0x00FEFEFE
  860.         shr edx,1
  861.  
  862.         mov ecx,[ebx]
  863.         and ecx,0x00FEFEFE
  864.         shr ecx,1
  865.         add edx,ecx
  866.  
  867.     mov [ebx],edx
  868.  
  869.     cmp eax,0x80000+478*1920
  870.     jb copyfloor2
  871.  
  872. popa
  873.  
  874. ret
  875.  
  876.  
  877.  
  878. ; ******* Darken by Distance *******
  879. dark_distance:
  880.  
  881. ; color must be in edx, wall height in [vdd]
  882.  
  883.     mov eax,[vdd]
  884.     cmp eax,50
  885.     jg nodark
  886.     ;                split rgb
  887.  
  888.     mov [blue],edx
  889.     and [blue],dword 255
  890.  
  891.     shr edx,8
  892.     mov [green],edx
  893.     and [green],dword 255
  894.  
  895.     shr edx,8
  896.     mov [red],edx
  897.     and [red],dword 255
  898.  
  899.     mov eax,51    ; darkness parameter
  900.     sub eax,[vdd]
  901.     cmp [pseudo],dword 1
  902.     je isdarkside
  903.     sal eax,2
  904. isdarkside:
  905.  
  906. ;                        reduce rgb
  907.     sub [red],eax
  908.     cmp [red], dword 0
  909.     jg notblack10b
  910.     mov [red],dword 0
  911.     notblack10b:
  912.  
  913.     sub [green],eax
  914.     cmp [green],dword 0
  915.     jg notblack20b
  916.     mov [green],dword 0
  917.     notblack20b:
  918.  
  919.     mov edx,[blue]
  920.     sub [blue],eax
  921.     cmp [blue],dword 0
  922.     jg notblack30b
  923.     mov [blue],dword 0
  924.     notblack30b:
  925.  
  926.     shl dword [red],16 ; reassemble rgb
  927.     shl dword [green],8
  928.     mov edx,[red]
  929.     or edx,[green]
  930.     or edx,[blue]
  931.     mov eax,edx
  932.  
  933. nodark:
  934.  
  935.     ret
  936.  
  937.  
  938. ; DATA AREA
  939.  
  940. ;ceil=ceil
  941. ;wall=wall floor
  942. ;2 corner stone
  943. ;3 leaf mosaic
  944. ;4 closed window
  945. ;5 greek mosaic
  946. ;6 old street stones
  947. ;7 maya wall
  948.  
  949. grid:  ; 32*32 Blocks, Map: 0 = Air, 1 to 8 = Wall
  950. 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
  951. 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
  952. 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
  953. 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
  954. 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
  955. 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
  956. 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
  957. 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
  958. 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
  959. 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
  960. 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
  961. 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
  962. 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
  963. 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
  964. 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
  965. 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
  966. 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
  967. 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
  968. 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
  969. 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
  970. 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
  971. 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
  972. 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
  973. 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
  974. 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
  975. 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
  976. 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
  977. 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
  978. 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
  979. 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
  980. 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
  981. 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
  982.  
  983. vpx:
  984. dd 0x0001FFFF ; initial player position * 0xFFFF
  985.  vpy:
  986. dd 0x0001FFFF
  987.  
  988. title    db   'FISHEYE RAYCASTING ENGINE ETC. FREE3D',0
  989.  
  990. sindegree dd 0.0
  991. sininc    dd 0.0017453292519943295769236907684886
  992. sindiv    dd 6553.5
  993. textures:
  994.         file 'texture.gif'
  995.  
  996. align 4
  997.  
  998. col1:
  999.  dd ?;-
  1000. ; misc raycaster vars:
  1001. vxx:
  1002.  dd ?;-
  1003. vyy:
  1004.  dd ?;-
  1005. vl:
  1006.  dd ?;-
  1007. vstepx:
  1008.  dd ?;-
  1009. vstepy:
  1010.  dd ?;-
  1011. vxxint:
  1012.  dd ?;-
  1013. vyyint:
  1014.  dd ?;-
  1015. vk:
  1016.  dd ?;-
  1017. va:
  1018.  dd ?;-
  1019. va2:
  1020.  dd ?;-
  1021. vdd:
  1022.  dd ?;-
  1023. vx1:
  1024.  dd ?;-
  1025. vx1b:
  1026.  dd ?;-
  1027. vh:
  1028.  dd ?;-
  1029. vdt:
  1030.  dd ?;-
  1031. vheading: ; initial heading: 0 to 3599
  1032.  dd ?;-
  1033. vacompare:
  1034.  dd ?;-
  1035. vpxi:
  1036.  dd ?;-
  1037. vpyi:
  1038.  dd ?;-
  1039. wtolong:
  1040.  dw ?,?;-,?;-
  1041.  
  1042. xtemp:
  1043.  dd ?;-
  1044. ytemp:
  1045.  dd ?;-
  1046. xfrac:
  1047.  dd ?;-
  1048. yfrac:
  1049.  dd ?;-
  1050. h_old:
  1051.  dd ?;-
  1052. vbottom:
  1053.  dd ?;-
  1054. mouseya:
  1055.  dd ?;-
  1056. remeax:
  1057.  dd ?;-
  1058. remebx:
  1059.  dd ?;-
  1060. remecx:
  1061.  dd ?;-
  1062. remedx:
  1063.  dd ?;-
  1064. remedi:
  1065.  dd ?;-
  1066. remesi:
  1067.  dd ?;-
  1068. red:
  1069.  dd ?;-
  1070. green:
  1071.  dd ?;-
  1072. blue:
  1073.  dd ?;-
  1074. pseudo:
  1075.  dd ?;-
  1076. step1:
  1077.  dd ?;-
  1078. step64:
  1079.  dd ?;-
  1080. lasty:
  1081.  dd ?;-
  1082.  
  1083. I_END:
  1084. IncludeUGlobals
  1085. sinus rd 360*10
  1086. eosinus:
  1087.