Subversion Repositories Kolibri OS

Rev

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