Subversion Repositories Kolibri OS

Rev

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