home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / texmap / tmap_aa.asm < prev    next >
Assembly Source File  |  1998-06-08  |  14KB  |  690 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. ; $Source: f:/miner/source/texmap/rcs/tmap_per.asm $
  13. ; $Revision: 1.8 $
  14. ; $Author: mike $
  15. ; $Date: 1993/12/16 18:37:52 $
  16. ;
  17. ; Perspective texture mapper inner loop.
  18. ;
  19. ; $Log: tmap_per.asm $
  20. ; Revision 1.8  1993/12/16  18:37:52  mike
  21. ; Align some stuff on 4 byte boundaries.
  22. ; Revision 1.7  1993/11/30  08:44:18  john
  23. ; Made selector set check for < 64*64 bitmaps.
  24. ; Revision 1.6  1993/11/23  17:25:26  john
  25. ; Added safety "and eax, 0fffh" in lighting lookup.
  26. ; Revision 1.5  1993/11/23  15:08:52  mike
  27. ; Fixed lighting bug. 
  28. ; Revision 1.4  1993/11/23  14:38:50  john
  29. ; optimized NORMAL code by switching EBX and ESI, so BH can be used in
  30. ; the lighting process.
  31. ; Revision 1.3  1993/11/23  14:30:53  john
  32. ; Made the perspective tmapper do 1/8 divides; added lighting.
  33. ; Revision 1.2  1993/11/22  10:24:59  mike
  34. ; *** empty log message ***
  35. ; Revision 1.1  1993/09/08  17:29:53  mike
  36. ; Initial revision
  37. ;
  38. ;
  39.  
  40.     .386
  41.  
  42.     public    _fx_u,_fx_v,_fx_z,_fx_du_dx,_fx_dv_dx,_fx_dz_dx,_fx_y,_fx_xleft,_fx_xright
  43.     public    _pixptr
  44.     public    asm_tmap_scanline_per_
  45. ;**    public    copy_canvas_to_a000_,clear_canvas_
  46.  
  47.     include    tmap_inc.asm
  48.  
  49. ;**    public    _v_window_left,_v_window_right,_v_window_top,_v_window_bottom
  50.  
  51.  public _max_ecx,_min_ecx
  52.  
  53.     extern    _fx_l:dword
  54.     extern     _fx_dl_dx:dword
  55.     extern    _dither_intensity_lighting:dword
  56.     extern _Lighting_on:dword
  57.  
  58. _DATA    SEGMENT DWORD PUBLIC USE32 'DATA'
  59.     align    4
  60. ;**_v_window_left    dd    _window_left
  61. ;**_v_window_right    dd    _window_right
  62. ;**_v_window_top    dd    _window_top
  63. ;**_v_window_bottom    dd    _window_bottom
  64.  
  65. ; ---------- These are passed in by the C caller ----------
  66. _fx_u    dd    ?    
  67. _fx_v    dd    ?
  68. _fx_z    dd    ?
  69. _fx_du_dx    dd    ?
  70. _fx_dv_dx    dd    ?
  71. _fx_dz_dx    dd    ?
  72.  
  73. _fx_y    dd    ?
  74. _fx_xleft    dd    ?
  75. _fx_xright    dd    ?
  76.  
  77. _pixptr    dd    ?
  78. ; ----------^^ These are passed in by the C caller ^^----------
  79.  
  80.     public    _x,_loop_count
  81.     align    4
  82. _x    dd    ?
  83. _loop_count    dd    ?
  84. ;**temp    dd    ?
  85.  
  86. _max_ecx    dd    0
  87. _min_ecx    dd    55555555h
  88.  
  89.     public    _per2_flag
  90. _per2_flag    dd    1
  91.  
  92.     public    _tmap_aliasing
  93.  
  94. _tmap_aliasing    dd 0
  95.  
  96. ;---------- local variables
  97.     align    4
  98. req_base    dd ?
  99. req_size    dd ?
  100. U0        dd ?
  101. U1        dd ?
  102. V0        dd ?
  103. V1        dd ?
  104. temp        dd ?
  105. num_left_over    dd ?
  106. DU1        dd ?
  107. DV1        dd ?
  108. DZ1        dd ?
  109. _fx_dl_dx1    dd ?
  110. _fx_dl_dx2    dd ?
  111.  
  112. initialized    db 10 dup (?)
  113. selector    dw 10 dup (?)
  114.  
  115. _DATA    ENDS
  116.  
  117. DGROUP    GROUP    _DATA
  118.  
  119.  
  120. _TEXT   SEGMENT DWORD PUBLIC USE32 'CODE'
  121.     ASSUME    DS:_DATA
  122.     ASSUME    CS:_TEXT
  123.  
  124. ; --------------------------------------------------------------------------------------------------
  125. ; Enter:
  126. ;    _xleft    fixed point left x coordinate
  127. ;    _xright    fixed point right x coordinate
  128. ;    _y    fixed point y coordinate
  129. ;    _pixptr    address of source pixel map
  130. ;    _u    fixed point initial u coordinate
  131. ;    _v    fixed point initial v coordinate
  132. ;    _z    fixed point initial z coordinate
  133. ;    _du_dx    fixed point du/dx
  134. ;    _dv_dx    fixed point dv/dx
  135. ;    _dz_dx    fixed point dz/dx
  136.  
  137. ;   for (x = (int) xleft; x <= (int) xright; x++) {
  138. ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  139. ;      _setpixel(x,y);
  140. ;
  141. ;      u += du_dx;
  142. ;      v += dv_dx;
  143. ;      z += dz_dx;
  144. ;   }
  145.  
  146.  
  147. TMAP_NORMAL MACRO
  148.     LOCAL NoLight1
  149.  
  150.     xchg    ebx, esi
  151.  
  152.     ; compute v coordinate
  153.     mov    eax,ebp    ; get v
  154.     cdq
  155.     idiv    ecx    ; eax = (v/z)
  156.  
  157.     and    eax,3fh    ; mask with height-1
  158.     mov    ebx,eax
  159.  
  160.     ; compute u coordinate
  161.     mov    eax,esi    ; get u
  162.     cdq
  163.     idiv    ecx    ; eax = (u/z)
  164.  
  165.     shl     eax,26
  166.     shld     ebx,eax,6        ; esi = v*64+u
  167.  
  168.     ; read 1  pixel
  169.     mov    al,es:[ebx]    ; get pixel from source bitmap
  170.  
  171.     cmp    _Lighting_on, 0
  172.     je    NoLight1
  173.     ;LIGHTING CODE
  174.     mov    ebx, _fx_l    ; get temp copy of lighting value
  175.     mov    ah, bh        ; get lighting level
  176.     add    ebx, _fx_dl_dx1    ; update lighting value
  177.     and    eax, 0fffh    ; make sure no garbage in EAX
  178.     mov    al, fs:[eax]    ; xlat pixel thru lighting tables
  179.     mov    _fx_l, ebx    ; save temp copy of lighting value
  180.                     
  181.     ;DITHERING CODE
  182.     mov     ebx, _fx_dl_dx1
  183.     xchg    ebx, _fx_dl_dx2
  184.     mov    _fx_dl_dx1, ebx
  185. NoLight1:
  186.     
  187.     cmp    _tmap_aliasing, 0
  188.     je    @f
  189.     ;ANTI-ALIASING CODE
  190.     mov    bl, [edi-320]     ; pixel above
  191.     mov    bh, [edi-1]    ; pixel to left
  192.     and    ebx, 0ffffh
  193.     mov    ah, gs:[ebx]    ; average those two
  194.     and    eax, 0ffffh
  195.     mov    al, gs:[eax]    ; average with current
  196. @@:    
  197.     ; write 1 pixel
  198.     mov    [edi],al
  199.     inc    edi
  200.     
  201.     ; update deltas
  202.     add    ebp,_fx_dv_dx
  203.     add    esi,_fx_du_dx
  204.     add    ecx,_fx_dz_dx
  205.  
  206.     xchg    esi, ebx
  207. ENDM
  208.  
  209. asm_tmap_scanline_per_:
  210.     push    es
  211.     push    fs
  212.     push    gs
  213.     pusha
  214.     
  215. ;---------------------------- setup for loop ---------------------------------
  216. ; Setup for loop:    _loop_count  iterations = (int) xright - (int) xleft
  217. ;    esi    source pixel pointer = pixptr
  218. ;    edi    initial row pointer = y*320+x
  219.  
  220. ; set esi = pointer to start of texture map data
  221. ;**    mov    esi,_pixptr
  222.     mov    es,selector[0*2]
  223.     mov    fs,selector[1*2]    ; fs = bmd_fade_table
  224.     mov    gs,selector[2*2]      ; gs = bmd_blend_table
  225.     cmp    _tmap_aliasing, 0
  226.     jne    @f
  227.     mov    gs,selector[1*2]      ; gs = bmd_fade_table
  228.     @@:    
  229.  
  230.  
  231. ; set edi = address of first pixel to modify
  232.     mov    edi,_fx_y
  233.     cmp    edi,_window_bottom
  234.     jae    _none_to_do
  235.  
  236.     imul    edi,_bytes_per_row
  237.     mov    eax,_fx_xleft
  238.     sar    eax,16
  239.     jns    eax_ok
  240.     sub    eax,eax
  241. eax_ok:
  242.     add    edi,eax
  243.     add    edi,write_buffer
  244.  
  245. ; set _loop_count = # of iterations
  246.     mov    eax,_fx_xright
  247.     sar    eax,16
  248.     cmp    eax,_window_right
  249.     jb    eax_ok1
  250.     mov    eax,_window_right
  251. eax_ok1:    cmp    eax,_window_left
  252.     ja    eax_ok2
  253.     mov    eax,_window_left
  254. eax_ok2:
  255.  
  256.     mov    ebx,_fx_xleft
  257.     sar    ebx,16
  258.     sub    eax,ebx
  259.     js    _none_to_do
  260.     cmp    eax,_window_width
  261.     jbe    _ok_to_do
  262.     mov    eax,_window_width
  263. _ok_to_do:
  264.     mov    _loop_count,eax
  265.  
  266. ;-------------------------- setup for dithering -----------------------------
  267. ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
  268. ; get the integer by reading %bh
  269.     sar    _fx_l, 8
  270.     sar    _fx_dl_dx,8
  271.     jns    dl_dx_ok
  272.     inc    _fx_dl_dx    ; round towards 0 for negative deltas
  273. dl_dx_ok:
  274.  
  275. ; do dithering, use lighting values which are .5 less than and .5 more than actual value
  276.     mov    ebx,80h    ; assume dithering on
  277.     test    _dither_intensity_lighting,-1
  278.     jne    do_dither
  279.     sub    ebx,ebx    ; no dithering
  280. do_dither:
  281.     mov    eax,_fx_dl_dx
  282.     add    eax,ebx    ; add 1/2
  283.     mov    _fx_dl_dx1,eax
  284.     sub    eax,ebx
  285.     sub    eax,ebx
  286.     mov    _fx_dl_dx2,eax
  287.     mov    ebx,_fx_xleft
  288.     shr    ebx,16
  289.     xor    ebx,_fx_y
  290.     and    ebx,1
  291.     jne    dith_1
  292.     xchg    eax,_fx_dl_dx1
  293. dith_1:    mov    _fx_dl_dx2,eax
  294.  
  295.  
  296. ; set initial values
  297.     mov    ebx,_fx_u
  298.     mov    ebp,_fx_v
  299.     mov    ecx,_fx_z
  300.  
  301.     test _per2_flag,-1
  302.     je   tmap_loop
  303.  
  304.     jmp    tmap_loop_fast
  305.  
  306. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  307. ;
  308. ; Usage in loop:    eax    division, pixel value
  309. ;    ebx    u
  310. ;    ecx    z
  311. ;    edx    division
  312. ;    ebp    v
  313. ;    esi    source pixel pointer
  314. ;    edi    destination pixel pointer
  315.  
  316. ;-------------------- NORMAL PERSPECTIVE TEXTURE MAP LOOP -----------------
  317.     align    4
  318. tmap_loop:
  319.     TMAP_NORMAL
  320.     dec    _loop_count
  321.     jns    tmap_loop
  322.  
  323. _none_to_do:    
  324.     popa
  325.     pop    gs
  326.     pop    fs
  327.     pop    es
  328.     ret
  329.  
  330. ;-------------------------- PER/4 TMAPPER ----------------
  331. ;    x = x1
  332. ;    U0 = u/w; V0 = v/w;
  333. ;    while ( 1 )
  334. ;        u += du_dx*4; v+= dv_dx*4
  335. ;        U1 = u/w; V1 = v/w;
  336. ;        DUDX = (U1-U0)/4; DVDX = (V1-V0)/4;
  337. ;
  338. ;        ; Pixel 0
  339. ;        pixels = texmap[V0*64+U0];
  340. ;        U0 += DUDX; V0 += DVDX
  341. ;        ; Pixel 1
  342. ;        pixels = (pixels<<8)+texmap[V0*64+U0];
  343. ;        U0 += DUDX; V0 += DVDX
  344. ;        ; Pixel 2
  345. ;        pixels = (pixels<<8)+texmap[V0*64+U0];
  346. ;        U0 += DUDX; V0 += DVDX
  347. ;        ; Pixel 3
  348. ;        pixels = (pixels<<8)+texmap[V0*64+U0];
  349. ;
  350. ;        screen[x] = pixel
  351. ;        x += 4;
  352. ;        U0 = U1; V0 = V1 
  353.  
  354. NBITS = 3
  355. ZSHIFT = 3
  356.  
  357.  
  358. PDIV MACRO
  359.     ; Returns EAX/ECX in 16.16 format in EAX. Trashes EDX
  360.     ;          sig bits   6.3
  361.     cdq
  362.     shld    edx,eax, ZSHIFT
  363.     shl    eax, ZSHIFT
  364.     idiv    ecx    ; eax = (v/z)
  365.     shl    eax, 16-ZSHIFT
  366. ENDM
  367.  
  368. public tmap_loop_fast
  369. tmap_loop_fast:
  370.  
  371. NotDwordAligned1:
  372.     test    edi, 11b
  373.     jz    DwordAligned1
  374.     TMAP_NORMAL
  375.     dec    _loop_count
  376.     jns    NotDwordAligned1
  377.     jmp    _none_to_do
  378.  
  379. DwordAligned1:
  380.     mov    eax, _loop_count
  381.     inc    eax
  382.     mov    num_left_over, eax
  383.     shr    eax, NBITS
  384.  
  385.     cmp    eax, 0        
  386.     je    tmap_loop
  387.     
  388.     mov     _loop_count, eax    ; _loop_count = pixels / NPIXS
  389.     shl    eax, NBITS
  390.     sub    num_left_over, eax    ; num_left_over = obvious
  391.         
  392.     ; compute initial v coordinate
  393.     mov    eax,ebp    ; get v
  394.     PDIV
  395.     mov    V0, eax
  396.  
  397.     ; compute initial u coordinate
  398.     mov    eax,ebx    ; get u
  399.     PDIV    
  400.     mov    U0, eax
  401.  
  402.     ; Set deltas to NPIXS pixel increments
  403.     mov    eax, _fx_du_dx
  404.     shl    eax, NBITS
  405.     mov    DU1, eax
  406.     mov    eax, _fx_dv_dx
  407.     shl    eax, NBITS
  408.     mov    DV1, eax
  409.     mov    eax, _fx_dz_dx
  410.     shl    eax, NBITS
  411.     mov    DZ1, eax
  412.     
  413. TopOfLoop4:
  414.         add    ebx, DU1
  415.         add    ebp, DV1
  416.         add    ecx, DZ1
  417.  
  418.         ; Done with ebx, ebp, ecx until next iteration
  419.         push    ebx
  420.         push    ecx
  421.         push    ebp
  422.         push    edi
  423.     
  424.         ; Find fixed U1        
  425.         mov    eax, ebx
  426.         PDIV
  427.         mov    ebx, eax    ; ebx = U1 until pop's
  428.  
  429.         ; Find fixed V1        
  430.         mov    eax, ebp
  431.         PDIV
  432.         mov    ebp, eax    ; ebp = V1 until pop's
  433.  
  434.         mov    ecx, U0        ; ecx = U0 until pop's
  435.         mov    edi, V0        ; edi = V0 until pop's
  436.  
  437.         ; Make ESI =  V0:U0 in 6:10,6:10 format
  438.         mov    eax, ecx
  439.         shr    eax, 6
  440.         mov    esi, edi
  441.         shl    esi, 10
  442.         mov    si, ax
  443.         
  444.         ; Make EDX = DV:DU in 6:10,6:10 format
  445.         mov    eax, ebx
  446.         sub    eax, ecx
  447.         ;**sar    eax, NBITS      ; EAX = U1-U0 / 2^NBITS
  448.         ;**shr    eax, 6        ; put 6:10 int:frac into low word
  449.         sar    eax, NBITS+6
  450.         mov    edx, ebp
  451.         sub    edx, edi
  452.         ;**sar    edx, NBITS        ; EDX = V1-V0 / 4
  453.         ;**shl    edx, 10        ; put 6:10 int:frac into low word
  454.         shl    edx, 10-NBITS
  455.         mov    dx, ax        ; put delta u in low word
  456.  
  457.         ; Save the U1 and V1 so we don't have to divide on the
  458.         ; next iteration
  459.         mov    U0, ebx
  460.         mov    V0, ebp
  461.  
  462.         pop    edi        ; Restore EDI before using it
  463.         
  464.         cmp    _Lighting_on, 0
  465.         je    NoLight
  466.                 
  467.         ;LIGHTING CODE
  468.         mov    ebx, _fx_l
  469.         mov    ebp, _fx_dl_dx1
  470.  
  471.         mov    cl, [edi-1]
  472.                         
  473.         REPT (1 SHL (NBITS-2))
  474.             ITERATION = 0
  475.             REPT 2
  476.                 ; Do even pixel
  477.                 mov    eax, esi    ; get u,v
  478.                 shr    eax, 26        ; shift out all but int(v)
  479.                 shld    ax,si,6        ; shift in u, shifting up v
  480.                 add    esi, edx    ; inc u,v
  481.  
  482.                 ;LIGHTING CODE
  483.                 mov     al, es:[eax]    ; get pixel
  484.                 mov    ah, bh        ; get lighting table
  485.                 ;SAFETY CHECK
  486.                 and    eax, 0fffh
  487.                 add    ebx, ebp    ; update lighting value
  488.  
  489.                 ;ANTI-ALIASING CODE
  490.                 cmp    _tmap_aliasing, 0
  491.                 je    @f
  492.                 mov    ch, fs:[eax]
  493.                 mov    al, [edi-(320+ITERATION)]     ; pixel above
  494.                 mov    ah, cl         ; pixel to left
  495.                 ;**and    eax, 0ffffh
  496.                 mov    al, gs:[eax]    ; average those two
  497.                 mov    ah, ch
  498.                 @@:                
  499.                 
  500.                 ror    ecx, 8
  501.                 mov    cl, gs:[eax]    ; average with current
  502.  
  503.                 ITERATION = ITERATION + 1
  504.                 ; Do odd pixel
  505.                 mov    eax, esi    ; get u,v
  506.                 shr    eax, 26        ; shift out all but int(v)
  507.                 shld    ax,si,6        ; shift in u, shifting up v
  508.                 add    esi, edx    ; inc u,v
  509.  
  510.                 ;LIGHTING CODE
  511.                 mov     al, es:[eax]    ; get pixel
  512.                 mov    ah, bh        ; get lighting table
  513.                 ;SAFETY CHECK
  514.                 and    eax, 0fffh
  515.                 add    ebx, _fx_dl_dx2    ; update lighting value
  516.  
  517.                 ;ANTI-ALIASING CODE
  518.                 cmp    _tmap_aliasing, 0
  519.                 je    @f
  520.                 mov    ch, fs:[eax]
  521.                 mov    al, [edi-(320+ITERATION)]     ; pixel above
  522.                 mov    ah, cl         ; pixel to left
  523.                 ;**and    eax, 0ffffh
  524.                 mov    al, gs:[eax]    ; average those two
  525.                 mov    ah, ch
  526.                 @@:                
  527.                 
  528.                 ror    ecx, 8
  529.                 mov    cl, gs:[eax]    ; average with current
  530.  
  531.                 ITERATION = ITERATION + 1
  532.  
  533.  
  534.             ENDM
  535.                     
  536.             ror ecx, 8
  537.             mov [edi],ecx        ; Draw 4 pixels to display
  538.             rol ecx, 8    ; for aliasing
  539.             add edi,4
  540.         ENDM
  541.  
  542.         ;LIGHTING CODE
  543.         mov    _fx_l, ebx
  544.         pop    ebp
  545.         pop    ecx
  546.         pop    ebx
  547.         dec    _loop_count
  548.         jnz    TopOfLoop4
  549.         jmp    EndOfLoop4
  550.  
  551. NoLight:    
  552.         mov    cl, [edi-1]
  553.  
  554.         REPT (1 SHL (NBITS-2))
  555.             ITERATION = 0
  556.             REPT 4    
  557.                 LOCAL NoAA    
  558.                 LOCAL AA
  559.                 ; Do 1 pixel 
  560.                 mov    eax, esi    ; get u,v
  561.                 shr    eax, 26        ; shift out all but int(v)
  562.                 shld    ax,si,6        ; shift in u, shifting up v
  563.                 add    esi, edx    ; inc u,v
  564.  
  565.                 ;ANTI-ALIASING CODE
  566.                 cmp    _tmap_aliasing, 0
  567.                 je    NoAA
  568.                 mov    ch, es:[eax]
  569.                 mov    al, [edi-(320+ITERATION)]     ; pixel above
  570.                 mov    ah, cl         ; pixel to left
  571.                 mov    al, gs:[eax]    ; average those two
  572.                 mov    ah, ch
  573.                 ror    ecx, 8
  574.                 mov    cl, gs:[eax]    ; average with current
  575.                 jmp    AA        
  576.  
  577. NoAA:                ror    ecx, 8
  578.                 mov    cl, es:[eax]    ; average with current
  579.  
  580. AA:                    
  581.                 ITERATION = ITERATION + 1
  582.             ENDM
  583.                     
  584.             ror    ecx, 8
  585.             mov     [edi],ecx        ; Draw 4 pixels to display
  586.             rol    ecx, 8
  587.             add     edi,4
  588.         ENDM
  589.  
  590.         pop    ebp
  591.         pop    ecx
  592.         pop    ebx
  593.         dec    _loop_count
  594.         jnz    TopOfLoop4
  595. EndOfLoop4:
  596.  
  597.     cmp    num_left_over, 0
  598.     je    _none_to_do
  599.  
  600. DoEndPixels:
  601.     TMAP_NORMAL
  602.     dec    num_left_over
  603.     jnz    DoEndPixels
  604.     jmp    _none_to_do
  605.     
  606.  
  607. PUBLIC     tmap_set_selector_
  608.  
  609.     ; EAX = Selector number    
  610.     ; EDX = 32-bit base address #1
  611.     ; EBX = Size in bytes #1
  612.  
  613.     ; Returns:  EAX = 0 if ok, otherwise, EAX = non-zero (1)
  614.  
  615.     ; Uses variables: initialized    db 10 dup (?)
  616.     ;                 selector    dw 10 dup (?) 
  617.     ;          req_base    dd ?
  618.     ;          req_size    dd ?
  619.         
  620. tmap_set_selector_:
  621.  
  622.     pusha
  623.     
  624.     mov    esi, eax
  625.     
  626.     mov    req_base, edx
  627.     mov    req_size, ebx
  628.  
  629.     cmp    req_size, 64*64
  630.     jge    @f
  631.  
  632.     ;Too small of a texture map!!! (Not 64x64)
  633.     int    3
  634.  
  635. @@:    cmp     initialized[esi], 1
  636.     je    already_initialized
  637.     mov    initialized[esi], 1
  638.  
  639.     ; Allocate a selector using DPMI
  640.     mov    eax, 0
  641.     mov    ecx, 1
  642.     int    31h
  643.     jc    failed
  644.     mov    selector[esi*2], ax
  645.  
  646.  
  647. already_initialized:    
  648.  
  649.     ; Set the selector's base address using DPMI
  650.     mov    eax, 7
  651.     mov    bx, selector[esi*2]
  652.     mov    ecx, req_base
  653.     mov    edx, ecx
  654.     shr    ecx, 16
  655.     int    31h
  656.     jc     failed
  657.  
  658.     ; Set the selector's size using DPMI
  659.     mov    ax, 08h
  660.     mov    bx, selector[esi*2]
  661.     mov    ecx, req_size
  662.     mov    edx, ecx
  663.     shr    ecx, 16
  664.     int    31h
  665.     jc    failed
  666.  
  667.     popa
  668.     mov    eax, 0
  669.     ret
  670. failed:
  671.     popa
  672.     mov    eax, 1
  673.     ret
  674.  
  675.  
  676.  
  677. _TEXT    ends
  678.  
  679.     end
  680.  
  681.