home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / texmap / john.asm next >
Assembly Source File  |  1998-06-08  |  12KB  |  440 lines

  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  11.  
  12.     align    4
  13. TopOfLoop4:
  14.     add    ebx, DU1
  15.     add    ebp, DV1
  16.     add    ecx, DZ1
  17.  
  18. ; Done with ebx, ebp, ecx until next iteration
  19.     push    ebx
  20.     push    ecx
  21.     push    ebp
  22.     push    edi
  23.     
  24. ; Find fixed U1        
  25.     mov    eax, ebx
  26.     PDIV
  27.     mov    ebx, eax    ; ebx = U1 until pop's
  28.  
  29. ; Find fixed V1        
  30.     mov    eax, ebp
  31.     PDIV
  32.     mov    ebp, eax    ; ebp = V1 until pop's
  33.  
  34.     mov    ecx, U0    ; ecx = U0 until pop's
  35.     mov    edi, V0    ; edi = V0 until pop's
  36.  
  37. ; Make ESI =  V0:U0 in 6:10,6:10 format
  38.     mov    eax, ecx
  39.     shr    eax, 6
  40.     mov    esi, edi
  41.     shl    esi, 10
  42.     mov    si, ax
  43.         
  44. ; Make EDX = DV:DU in 6:10,6:10 format
  45.     mov    eax, ebx
  46.     sub    eax, ecx
  47.     sar    eax, NBITS+6
  48.     mov    edx, ebp
  49.     sub    edx, edi
  50.     shl    edx, 10-NBITS    ; EDX = V1-V0/ 4 in 6:10 int:frac
  51.     mov    dx, ax    ; put delta u in low word
  52.  
  53. ; Save the U1 and V1 so we don't have to divide on the next iteration
  54.     mov    U0, ebx
  55.     mov    V0, ebp
  56.  
  57.     pop    edi    ; Restore EDI before using it
  58.         
  59. ; LIGHTING CODE
  60.     mov    ebx, _fx_l
  61.     mov    ebp, _fx_dl_dx1
  62.  
  63.     REPT (1 SHL (NBITS-2))
  64.         REPT 2
  65.             mov    eax, esi    ; get u,v
  66.             shr    eax, 26        ; shift out all but int(v)
  67.             shld    ax,si,6        ; shift in u, shifting up v
  68.             add    esi, edx    ; inc u,v
  69.             mov     al, es:[eax]    ; get pixel from source bitmap
  70.             mov    ah, bh        ; form lighting table lookup value
  71.             add    ebx, ebp    ; update lighting value
  72.             mov    cl, fs:[eax]    ; xlat thru lighting table into dest buffer
  73.  
  74.             ; eax = 0
  75.             ; ebx = l in fixed 24.8 (really 8.8)
  76.             ; ecx = (dv << 16) | du   (in fixed 8.8)
  77.             ; edx = free
  78.             ; esi = ptr to source bitmap
  79.             ; edi = destination ptr
  80.             ; ebp = dldx   (in fixed 24.8) (really 8.8)
  81.             ; MEM [0..3] = (u<<16) | v  (in fixed 8.8)
  82.                         
  83.         ; Code for 8-bit destination, lighting
  84.             mov    al, [0]            ; get u
  85.             mov    ah, [2]            ; get v
  86.             add    [0], ecx        ; inc u,v
  87.             mov    al, [esi+eax]        ; get source pixel
  88.             mov    ah, bh            ; form lighting lookup value
  89.             mov    al, FadeTable[eax]    ; get lit pixel
  90.             mov    ah, [edi]        ; get prev pixel
  91.             mov    al, Transparent[eax]    ; get transluscent pixel value
  92.             mov    [edi], al        ; write pixel to frame buffer
  93.             inc    edi            ; inc dest
  94.             add    ebx, ebp        ; inc lighting value
  95.  
  96.         ; Code for 8-bit destination, no lighting
  97.             mov    al, [0]        ; get u
  98.             mov    ah, [2]        ; get v
  99.             add    [0], ecx    ; inc u,v
  100.             mov    al, [esi+eax]    ; get source pixel
  101.             mov    [edi], al    ; write pixel to frame buffer
  102.             inc    edi        ; inc dest
  103.             add    ebx, ebp    ; inc dl
  104.  
  105.  
  106.             ; old way
  107.             mov    eax,ebp    ; clear for 
  108.             add    ebp,edx    ; update v coordinate
  109.             shr    eax,26    ; shift in v coordinate
  110.             shld    eax,ebx,6    ; shift in u coordinate while shifting up v coordinate
  111.             add    ebx,ecx    ; update u coordinate
  112.             mov    al,[esi+eax]    ; get pixel from source bitmap
  113.             mov    [edi],al
  114.             inc    edi
  115.  
  116.  
  117.  
  118.         ; Code for 15-bit destination, with fade table in hardware
  119.             mov    al, ch        ; get u,v
  120.             mov    ah, dh        ;
  121.             mov    al, es:[eax]
  122.             mov    ah, bh
  123.             mov    [edi], ax    ; write pixel to frame buffer
  124.             add    edi, 2
  125.             add    ecx, esi
  126.             bswap    esi
  127.             add    edx, esi
  128.             bswap     esi
  129.             add    ebx, ebp
  130.  
  131.         ; Code for 15-bit destination, with RGB 15 bit in hardware...
  132.             mov    al, ch        ; get u,v
  133.             mov    ah, dh        ;
  134.             mov    al, es:[eax]    
  135.             mov    ah, bh
  136.             mov    ax, gs:[eax*2]    
  137.             mov    [edi], ax    ; write pixel to frame buffer
  138.             add    edi, 2
  139.             add    ecx, esi
  140.             bswap    esi
  141.             add    edx, esi
  142.             bswap     esi
  143.             add    ebx, ebp
  144.  
  145.  
  146.             
  147.  
  148.             mov    eax, esi    ; get u,v
  149.             shr    eax, 26        ; shift out all but int(v)
  150.             shld    ax,si,6        ; shift in u, shifting up v
  151.             add    esi, edx    ; inc u,v
  152.             mov     al, es:[eax]    ; get pixel from source bitmap
  153.             mov    ah, bh        ; form lighting table lookup value
  154.  
  155.  
  156.         esi, ebp
  157.  
  158.             
  159.     
  160.             esi, ebp, 
  161.             
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.         
  169.             ; Do odd pixel
  170.             mov    eax, esi    ; get u,v
  171.             shr    eax, 26        ; shift out all but int(v)
  172.             shld    ax,si,6        ; shift in u, shifting up v
  173.             add    esi, edx    ; inc u,v
  174.             mov     al, es:[eax]    ; get pixel from source bitmap
  175.             mov    ah, bh        ; form lighting table lookup value
  176.             add    ebx, ebp    ; update lighting value
  177.             mov    ch, fs:[eax]    ; xlat thru lighting table into dest buffer
  178.         
  179.             ror    ecx, 16        ; move to next double dest pixel position
  180.         ENDM
  181.                     
  182.         mov     [edi],ecx    ; Draw 4 pixels to display
  183.         add     edi,4
  184.     ENDM
  185.  
  186. ; LIGHTING CODE
  187.     mov    _fx_l, ebx
  188.     pop    ebp
  189.     pop    ecx
  190.     pop    ebx
  191.     dec    _loop_count
  192.     jnz    TopOfLoop4
  193.  
  194.  
  195.  
  196.     mov    eax, esi    ; get u,v
  197.     shr    eax, 26    ; shift out all but int(v)
  198.     shld    ax,si,6    ; shift in u, shifting up v
  199.     add    esi, edx    ; inc u,v
  200.     mov     al, es:[eax]    ; get pixel from source bitmap
  201.     cmp    al,255
  202.     je    skipa1
  203.     mov    ah, bh    ; form lighting table lookup value
  204.     add    ebx, ebp    ; update lighting value
  205.     mov    al, fs:[eax]    ; xlat thru lighting table into dest buffer
  206.     mov    [edi],al
  207.  
  208.  
  209.     mov    eax, esi    ; get u,v
  210.     shr    eax, 26        ; shift out all but int(v)
  211.     shld    ax,si,6        ; shift in u, shifting up v
  212.     add    esi, edx    ; inc u,v
  213.     mov     al, es:[eax]    ; get pixel from source bitmap
  214.     mov    ah, bh        ; form lighting table lookup value
  215.     add    ebx, ebp    ; update lighting value
  216.     mov    al, fs:[eax]    ; xlat thru lighting table into dest buffer
  217.     mov    ah, [edi]    ; get pixel already drawn here
  218.     mov    al, gs:[eax]    ; lookup in translation table
  219.     mov    [edi],al    ; write pixel
  220.  
  221.  
  222.     ; Code for 8-bit destination, lighting, transluscency
  223.     mov    dx, [edi]
  224.     mov    al, [0]            ; get u
  225.     mov    ah, [2]            ; get v
  226.     add    [0], ecx        ; inc u,v
  227.     mov    al, [esi+eax]        ; get source pixel
  228.     mov    ah, bh            ; form lighting lookup value
  229.     mov    al, FadeTable[eax]    ; get lit pixel
  230.     mov    ah, dl            ; get prev pixel
  231.     add    ebx, ebp        ; inc lighting value
  232.     mov    dl, TransTable[eax]    ; get transluscent pixel value
  233.  
  234.     mov    al, [0]            ; get u
  235.     mov    ah, [2]            ; get v
  236.     add    [0], ecx        ; inc u,v
  237.     mov    al, [esi+eax]        ; get source pixel
  238.     mov    ah, bh            ; form lighting lookup value
  239.     mov    al, FadeTable[eax]    ; get lit pixel
  240.     mov    ah, dh            ; get prev pixel
  241.     add    ebx, ebp        ; inc lighting value
  242.     mov    dh, TransTable[eax]    ; get transluscent pixel value
  243.  
  244.     mov    [edi], dx        ; write 2 pixels to frame buffer
  245.     inc    edi            ; move to next pixel
  246.     inc    edi            ; move to next pixel
  247.  
  248.  
  249.     ; compute v coordinate
  250.     mov    eax,ebp    ; get v
  251.     cdq
  252.     idiv    ecx    ; eax = (v/z)
  253.     and    eax,3fh    ; mask with height-1
  254.     mov    ebx,eax
  255.  
  256.     ; compute u coordinate
  257.     mov    eax,esi    ; get u
  258.     cdq
  259.     idiv    ecx        ; eax = (u/z)
  260.     shl     eax,26        
  261.     shld     ebx,eax,6    ; ebx = v*64+u
  262.  
  263.     ; read 1  pixel
  264.     movzx    eax,byte ptr es:[ebx]    ; get pixel from source bitmap
  265.  
  266. ; LIGHTING CODE
  267.     mov    ebx, _fx_l    ; get temp copy of lighting value
  268.     mov    ah, bh        ; get lighting level
  269.     add    ebx, _fx_dl_dx    ; update lighting value
  270.     mov    al, fs:[eax]    ; xlat pixel thru lighting tables
  271.     mov    _fx_l, ebx    ; save temp copy of lighting value
  272.  
  273.     mov    [edi],al
  274.     inc    edi
  275.     
  276. ; update deltas
  277.     add    ebp,_fx_dv_dx
  278.     add    esi,_fx_du_dx
  279.     add    ecx,_fx_dz_dx
  280.  
  281.     xchg    esi, ebx
  282.  
  283.     dec    _loop_count
  284.     jns    tmap_loop
  285.  
  286.  
  287.  
  288. fix fixdiv(fix a,fix b);
  289. #pragma aux fixdiv parm [eax] [ebx] modify exact [eax edx] = \
  290.     "cdq    "    \
  291.     "idiv    ebx"    \
  292.     
  293.  
  294.  
  295.     fix u = u0;
  296.     fix v = v0;
  297.     fix z = z0;
  298.     fix l = l0;
  299.  
  300.     for ( x=x1; x<=x2; x++ )    {
  301.         if ( z < zbuffer[x] )    {
  302.             zbuffer[x] = z;
  303.             color = bitmap[(u/z)&63][(v/z)&63];
  304.             if ( color != xparent )    {
  305.                 color = LightingTable[color][f2i(l)&31];
  306.                 pixel[x] = color;
  307.             }
  308.         }
  309.         u += du;
  310.         v += dv;
  311.         z += dz;
  312.         l += dl;
  313.     }
  314.  
  315. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  316. ;
  317. ; Usage in loop:
  318. ;    eax    division, pixel value
  319. ;    ebx    source pixel pointer
  320. ;    ecx    z
  321. ;    edx    division
  322. ;    ebp    v
  323. ;    esi    u
  324. ;    edi    destination pixel pointer
  325.  
  326.  
  327. rept niters
  328.     mov    eax, [_fx_z]            ; get z-value
  329.     cmp    zbuffer[edi], eax        ; check if closer
  330.     jge    skip1                ; don't do if z farther away
  331.     mov    zbuffer[edi], eax        ; update z-buffer
  332.     mov    eax,[_fx_v]            ; get v        
  333.     cdq                    ; sign extend into edx:eax
  334.     idiv    [_fx_z]                ; eax = (v/z)
  335.     and    eax,63                ; mask with height-1
  336.     mov    ebx,eax                ; start build bitmap address
  337.     mov    eax,[_fx_u]            ; get u
  338.     cdq                    ; sign extend into edx:eax
  339.     idiv    [_fx_z]                ; eax = (u/z)
  340.     shl     eax,26                ; continue building bitmap address
  341.     shld     ebx,eax,6            ; ebx = v*64+u
  342.     mov    al,byte ptr es:[ebx]        ; get pixel from source bitmap
  343.     cmp    al,255                ; check if it's transparent
  344.     je    skip1                ; don't write if transparent
  345.     mov    bx, [_fx_l]            ; get lighting value
  346.     mov    bl, al                ; build lighting table lookup index
  347.     mov    al, lighting[ebx]        ; lookup lighting value
  348.     mov    video[edi],al            ; write the pixel
  349. skip1:    inc    edi                ; go to next pixel address
  350.     add    [_fx_l],[_fx_dl_dx]        ; increment lighting
  351.     add    [_fx_u],[_fx_du_dx]        ; increment u
  352.     add    [_fx_v],[_fx_dv_dx]        ; incrememt v
  353.     add    [_fx_z],[_fx_dz_dx]        ; increment z
  354.     je    _div_0_abort            ; would be dividing by 0, so abort
  355. endm
  356.  
  357.  
  358.     mov    eax, F1_0
  359.     mov    ebx, [z]
  360.     mov    edx,eax
  361.     sar    edx,16
  362.     shl    eax,16
  363.     idiv    ebx
  364.  
  365.     "imul    edx"                \
  366.     "shrd    eax,edx,16";
  367.  
  368.     // assume 8.12 fixed point
  369.  
  370. rept niters
  371.     mov    eax, [_fx_z]            ; get z-value
  372.     cmp    zbuffer[edi], eax        ; check if closer
  373.     jge    skip1                ; don't do if z farther away
  374.     mov    zbuffer[edi], eax        ; update z-buffer
  375.     mov    eax,[_fx_v]            ; get v        
  376.     cdq        
  377.     idiv    eax, [z]
  378.     mov    ebx,eax                ; start build bitmap address
  379.     mov    eax,[_fx_u]            ; get u
  380.     imul    eax, [z]
  381.     shl     eax,26                ; continue building bitmap address
  382.     shld     ebx,eax,6            ; ebx = v*64+u
  383.     mov    al,byte ptr es:[ebx]        ; get pixel from source bitmap
  384.     cmp    al,255                ; check if it's transparent
  385.     je    skip1                ; don't write if transparent
  386.     mov    bx, [_fx_l]            ; get lighting value
  387.     mov    bl, al                ; build lighting table lookup index
  388.     mov    al, lighting[ebx]        ; lookup lighting value
  389.     mov    video[edi],al            ; write the pixel
  390. skip1:    inc    edi                ; go to next pixel address
  391.     add    [_fx_l],[_fx_dl_dx]        ; increment lighting
  392.     add    [_fx_u],[_fx_du_dx]        ; increment u
  393.     add    [_fx_v],[_fx_dv_dx]        ; incrememt v
  394.     add    [_fx_z],[_fx_dz_dx]        ; increment z
  395.     je    _div_0_abort            ; would be dividing by 0, so abort
  396. endm
  397.  
  398.  
  399. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  400. ;
  401. ; Usage in loop:
  402. ;    eax    division, pixel value
  403. ;    ebx    source pixel pointer
  404. ;    ecx    z
  405. ;    edx    division
  406. ;    ebp    v
  407. ;    esi    u
  408. ;    edi    destination pixel pointer
  409.  
  410.  
  411. rept niters
  412.     cmp    zbuffer[edi], ecx        ; check if closer
  413.     jge    skip1                ; don't do if z farther away
  414.     mov    zbuffer[edi], ecx        ; update z-buffer
  415.     mov    eax,[_fx_v]            ; get v        
  416.     mov    edx,[_fx_u]            ; get u
  417.     idiv    ecx                ; eax = (v/z)
  418.     and    eax,63                ; mask with height-1
  419.     mov    ebx,eax                ; start build bitmap address
  420.     mov    eax,[_fx_u]            ; get u
  421.     cdq                    ; sign extend into edx:eax
  422.     idiv    ecx                ; eax = (u/z)
  423.     shl     eax,26                ; continue building bitmap address
  424.     shld     ebx,eax,6            ; ebx = v*64+u
  425.     mov    al,byte ptr es:[ebx]        ; get pixel from source bitmap
  426.     cmp    al,255                ; check if it's transparent
  427.     je    skip1                ; don't write if transparent
  428.     mov    bx, [_fx_l]            ; get lighting value
  429.     mov    bl, al                ; build lighting table lookup index
  430.     mov    al, lighting[ebx]        ; lookup lighting value
  431.     mov    video[edi],al            ; write the pixel
  432. skip1:    inc    edi                ; go to next pixel address
  433.     add    [_fx_l],[_fx_dl_dx]        ; increment lighting
  434.     add    [_fx_u],[_fx_du_dx]        ; increment u
  435.     add    [_fx_v],[_fx_dv_dx]        ; incrememt v
  436.     add    ecx,[_fx_dz_dx]            ; increment z
  437.     je    _div_0_abort            ; would be dividing by 0, so abort
  438. endm
  439. 
  440.