Subversion Repositories Kolibri OS

Rev

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