Subversion Repositories Kolibri OS

Rev

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