home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / texture.inc < prev    next >
Text File  |  1995-07-28  |  10KB  |  323 lines

  1. ;this include file contains all the necessary macros for displaying
  2. ;textures.
  3.  
  4. txt_makevarl macro              ;reloads the 3d variables of the left side
  5. .386
  6.   movsx ebx,dyl                 ;number steps
  7.   inc ebx
  8.   push ecx
  9.   push edx
  10.  
  11.   movsx eax,poly3d[bp]          ;get 3d-x
  12.   shl eax,8                     ;lower 8 bits are "fractional" part
  13.   mov xl_3d,eax                 ;and write
  14.   movsx ecx,poly3d[bp+8]        ;obtain difference
  15.   shl ecx,8
  16.   sub eax,ecx
  17.   neg eax
  18.   cdq
  19.   idiv ebx                      ;define step
  20.   mov inc_xl,eax
  21.  
  22.   movsx eax,poly3d[bp+2]        ;get 3d-y
  23.   shl eax,8
  24.   mov yl_3d,eax
  25.   movsx ecx,poly3d[bp+10d]      ;obtain difference
  26.   shl ecx,8
  27.   sub eax,ecx
  28.   neg eax
  29.   cdq
  30.   idiv ebx                      ;define step
  31.   mov inc_yl,eax
  32.  
  33.   movsx eax,poly3d[bp+4]        ;get 3d-z
  34.   shl eax,8
  35.   mov zl_3d,eax
  36.   movsx ecx,poly3d[bp+12d]      ;obtain difference
  37.   shl ecx,8
  38.   sub eax,ecx
  39.   neg eax
  40.   cdq
  41.   idiv ebx                      ;define step
  42.   mov inc_zl,eax
  43.   pop edx
  44.   pop ecx
  45. endm
  46.  
  47. txt_makevarr macro              ;reloads the 3d variables of the right side
  48. .386
  49.   push eax
  50.   push ebx
  51.   movsx ebx,dyr                 ;number steps
  52.   inc ebx
  53.  
  54.   movsx eax,poly3d[bp+8]        ;get 3d-x
  55.   shl eax,8                     ;lower 8 bits are "fractional" part
  56.   mov xr_3d,eax                 ;and write
  57.   movsx ecx,poly3d[bp]          ;obtain difference
  58.   shl ecx,8
  59.   sub eax,ecx
  60.   neg eax
  61.   cdq
  62.   idiv ebx                      ;define step
  63.   mov inc_xr,eax
  64.  
  65.   movsx eax,poly3d[bp+10d]      ;get 3d-y
  66.   shl eax,8
  67.   mov yr_3d,eax
  68.   movsx ecx,poly3d[bp+2]        ;obtain difference
  69.   shl ecx,8
  70.   sub eax,ecx
  71.   neg eax
  72.   cdq
  73.   idiv ebx                      ;define step
  74.   mov inc_yr,eax
  75.  
  76.   movsx eax,poly3d[bp+12d]      ;get 3d-z
  77.   shl eax,8
  78.   mov zr_3d,eax
  79.   movsx ecx,poly3d[bp+4]        ;obtain difference
  80.   shl ecx,8
  81.   sub eax,ecx
  82.   neg eax
  83.   cdq
  84.   idiv ebx                      ;define step
  85.   mov inc_zr,eax
  86.   pop ebx
  87.   pop eax
  88. endm
  89.  
  90. txt_hline macro
  91. hline_texture proc near         ;replaces "hline" procedure with textures
  92. .386
  93.   push es
  94.   pusha
  95.   mov x0,ax                     ;save coordinates for later
  96.   mov y0,bx
  97.   mov x1,cx
  98.   sub cx,ax                     ;calculate number of pixels to be drawn
  99.   jne zzok2
  100.   inc cx
  101. zzok2:
  102.   mov zz,cx
  103.  
  104.   mov bp,upper_row
  105.   mov bx,lower_row
  106.   mov eax,xr_3d[bx]             ;determine relative x-coordinate
  107.   movsx ecx,poly3d[2]
  108.   shl ecx,8                     ;put in "fixed point" format
  109.   sub eax,ecx
  110.   mov d_y,eax
  111.   movsx ecx,w column2[0]
  112.   imul ecx                      ;multiply by Delta2 x
  113.   mov esi,eax                   ;place result in temporary storage
  114.  
  115.   mov eax,xr_3d[bp]             ;determine relative y-coordinate
  116.   movsx ecx,poly3d[0]
  117.   shl ecx,8                     ;put in "fixed point" format
  118.   sub eax,ecx
  119.   mov d_x,eax
  120.   movsx ecx,w column2[4]
  121.   imul ecx                      ;multiply by Delta2 y
  122.   sub eax,esi                   ;obtain difference (D1)
  123.   cdq                           ;prepare division
  124.   idiv dword ptr D              ;divide by main determinant
  125.   shl eax,8
  126.   neg eax
  127.   mov inc_lambda1,eax           ;store for subtraction
  128.  
  129.   mov eax,d_x                   ;get relative x-coordinate
  130.   movsx ecx,w column1[4]
  131.   imul ecx                      ;multiply by Delta1 y
  132.   mov esi,eax                   ;place result in temporary storage
  133.  
  134.   mov eax,d_y                   ;get relative y-coordinate
  135.   movsx ecx,w Column1[0]
  136.   imul ecx                      ;multiply by Delta1 x
  137.   sub eax,esi                   ;obtain difference (D2)
  138.   cdq                           ;prepare division
  139.   idiv dword ptr D              ;divide by main determinant
  140.   shl eax,8
  141.   neg eax
  142.   mov inc_lambda2,eax           ;store for subtraction
  143.  
  144.   mov eax,xl_3d[bx]             ;determine relative x-coordinate
  145.   movsx ecx,poly3d[2]
  146.   shl ecx,8                     ;put in "fixed point" format
  147.   sub eax,ecx
  148.   mov d_y,eax
  149.   movsx ecx,w column2[0]
  150.   imul ecx                      ;multiply by Delta2 x
  151.   mov esi,eax                   ;place result in temporary storage
  152.  
  153.   mov eax,xl_3d[bp]             ;determine relative y-coordinate
  154.   movsx ecx,poly3d[0]
  155.   shl ecx,8                     ;put in "fixed point" format
  156.   sub eax,ecx
  157.   mov d_x,eax
  158.   movsx ecx,w column2[4]
  159.   imul ecx                      ;multiply by Delta2 y
  160.   sub eax,esi                   ;obtain difference (D1)
  161.   cdq                           ;prepare division
  162.   idiv dword ptr D              ;divide by main determinant
  163.   shl eax,8
  164.   neg eax
  165.   mov lambda1,eax               ;Lambda1 determined
  166.   sub inc_lambda1,eax
  167.  
  168.   mov eax,d_x                   ;get relative x-coordinate
  169.   movsx ecx,w column1[4]
  170.   imul ecx                      ;multiply by Delta1 y
  171.   mov esi,eax                   ;place result in temporary storage
  172.  
  173.   mov eax,d_y                   ;get relative y-coordinate
  174.   movsx ecx,w column1[0]
  175.   imul ecx                      ;multiply by Delta1 x
  176.   sub eax,esi                   ;obtain difference (D2)
  177.   cdq                           ;prepare division
  178.   idiv dword ptr D              ;divide by main determinant
  179.   neg eax
  180.   shl eax,8
  181.   mov lambda2,eax               ;Lambda2 determined
  182.   sub inc_lambda2,eax
  183.  
  184.   mov ax,80d                    ;determine offset
  185.   mov bx,y0
  186.   mul bx
  187.   mov bx,x0                     ;(x div 4) + y*80
  188.   shr bx,2
  189.   add ax,bx
  190.   add ax,vpage
  191.   mov di,ax
  192.   mov ax,0a000h                 ;load VGA segment
  193.   mov es,ax
  194.  
  195.   mov cx,x0                     ;mask start plane
  196.   and cx,3
  197.   mov ax,1
  198.   shl ax,cl                     ;set corresponding bit
  199.   mov b plane+1,al
  200.   shl al,4                      ;and extend to high nibble
  201.   or b plane+1,al
  202.  
  203.   movsx ecx,zz                  ;calculate Lambda-Schrittweiten
  204.   mov eax,inc_lambda1           ;get total length
  205.   cdq
  206.   idiv ecx                      ;and divide by number steps
  207.   mov inc_lambda1,eax
  208.   mov eax,inc_lambda2           ;get total length
  209.   cdq
  210.   idiv ecx                      ;and divide by number steps
  211.   mov inc_lambda2,eax
  212.  
  213.   mov bp,txt_no                 ;get number of current texture
  214.   shl bp,1                      ;two bytes per entry
  215.   mov bx,txt_size[bp]           ;get current size specification
  216.   mov b cs:size_patch+3,bl      ;and patch in code
  217.   mov b cs:size_patch+7,bh
  218.  
  219.   mov ax,word ptr txt_offs[bp]  ;get offset of this texture
  220.  
  221.   push ds
  222.   shl bp,1                      ;4 byte entries
  223.   lds si,dword ptr txt_data[bp];get pointer to actual data
  224.   add si,ax
  225.   mov w cs:ofs_patch+2,si       ;and patch in code
  226.  
  227.   mov dx,3c4h                   ;timing sequencer
  228.   mov ebp,lambda1               ;register instead of variables
  229.   mov esi,lambda2
  230.  
  231. lp:                             ;runs for each pixel
  232.   add ebp,inc_lambda1           ;continue Lambda1 and 2
  233.   add esi,inc_lambda2
  234.  
  235.   mov ax,plane                  ;get plane
  236.   out dx,ax                     ;and select
  237.  
  238.   mov eax,ebp                   ;determine offset within the texture graphic
  239.   mov ebx,esi
  240. size_patch:
  241.   sar eax,11d                   ;set size, being modified
  242.   sar ebx,11d
  243.    imul eax,320d
  244.   add ebx,eax
  245.  
  246. ofs_patch:
  247.   mov al,ds:[bx+1111h]          ;get color from texture, being modified
  248.   mov es:[di],al                ;enter color
  249.   dec cx                        ;decrement number pixels
  250.   je hlt_finished               ;all pixels finished ?
  251.   rol b plane+1,1               ;next plane
  252.   cmp b plane+1,11h             ;plane overflow from 3 to 0 ?
  253.   jne lp                        ;no, then continue
  254.   inc di                        ;otherwise increment offset
  255.   jmp lp                        ;and continue
  256. hlt_finished:
  257.   pop ds
  258.   popa
  259.   pop es
  260.   ret
  261. hline_texture endp
  262.  
  263. endm
  264.  
  265. txt_maindet macro               ;calculate main determinant
  266.   xor si,si                     ;first attempt: rows 0 and 1
  267.   mov di,2
  268.  
  269. next:
  270.   mov ax,w delta1[si]           ;calculate main determinant
  271.   imul w delta2[di]
  272.   mov bx,ax                     ;store intermediate result
  273.   mov cx,dx
  274.   mov ax,w delta2[si]
  275.   imul w delta1[di]
  276.   sub bx,ax                     ;store difference
  277.   sbb cx,dx
  278.   mov w D,bx
  279.   mov w D+2,cx
  280.   or bx,cx                      ;main determinant = 0 ?
  281.   jne D_finished
  282.   add si,2                      ;then new components
  283.   add di,2
  284.   cmp di,4                      ;still within existing rows ?
  285.   jbe next
  286.   xor di,di                     ;no, then start again from above
  287.   jmp next
  288. D_finished:
  289.   movsx eax,delta1[si]          ;store used columnn values
  290.   mov column1[0],eax
  291.   movsx eax,delta1[di]
  292.   mov column1[4],eax
  293.   movsx eax,delta2[si]
  294.   mov column2[0],eax
  295.   movsx eax,delta2[di]
  296.   mov column2[4],eax
  297.   shl si,1                      ;note used columns
  298.   shl di,1
  299.   mov upper_row,si
  300.   mov lower_row,di
  301. endm
  302.  
  303. txt_incl macro                  ;increment left
  304.   push eax
  305.   mov eax,inc_xl                ;add 3d x-coordinate
  306.   add xl_3d,eax
  307.   mov eax,inc_yl                ;add 3d y-coordinate
  308.   add yl_3d,eax
  309.   mov eax,inc_zl                ;add 3d z-coordinate
  310.   add zl_3d,eax
  311.   pop eax
  312. endm
  313. txt_incr macro                  ;increment right
  314.   push eax
  315.   mov eax,inc_xr                ;add 3d x-coordinate
  316.   add xr_3d,eax
  317.   mov eax,inc_yr                ;add 3d y-coordinate
  318.   add yr_3d,eax
  319.   mov eax,inc_zr                ;add 3d z-coordinate
  320.   add zr_3d,eax
  321.   pop eax
  322. endm
  323.