home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / zkuste / SVET_GEO / GEORAY / GEORAY.ZIP / SOURCE.ZIP / ASMREND / MANAGER.ASM
Assembly Source File  |  1996-02-17  |  10KB  |  270 lines

  1. include geos.def        ; standard macros
  2. include resource.def    ; idata/udata, ProcCallFixedOrMovable etc.
  3.  
  4.  
  5. XAUF = 240                              ; screen bitmap size
  6. YAUF = 200
  7.  
  8. TEX_SIZE = 128                          ; texture size
  9.  
  10. OFF_LINES = XAUF/8                      ; bytes/line in offscreen bitmap
  11. TEX_LINES = TEX_SIZE/8                  ; bytes/line if texture bitmap
  12.  
  13.  
  14. global CLEAR_LINE_LOW:far
  15. global GREY_LINE_LOW:far
  16. global SCALE_LINE_LOW:far
  17.  
  18.  
  19.                 SetGeosConvention               ; set calling convention
  20.  
  21. ASM_TEXT        segment resource
  22.  
  23. ;void clear_line_low(char *p,char mask,word hoehe)
  24. ;{
  25. ;    for(; hoehe; hoehe--,p+=sizeof(Offscreen.data[0]))
  26. ;      *p&=~mask;
  27. ;}
  28. CLEAR_LINE_LOW  proc far _p:fptr, _mask:word, _hoehe:word
  29.         uses    di
  30.         .enter
  31.                 les di,_p               ; pointer into destination buffer
  32.                 mov ah,{byte}_mask      ; mask marking bits to clear
  33.                 not ah                  ; make it a "clear" mask
  34.                 mov cx,_hoehe           ; number of points to clear
  35. clearloop:      and {byte}es:[di],ah    ; apply mask
  36.                 add di,OFF_LINES        ; advance one line
  37.                 loop clearloop          ; do until done
  38.         .leave
  39.         ret
  40. CLEAR_LINE_LOW  endp
  41.  
  42. ;void grey_line_low(char *p,char mask,word hoehe,word evenodd)
  43. ;{
  44. ;    for(; hoehe; hoehe--,p+=sizeof(Offscreen.data[0]),evenodd^=1)
  45. ;      if(evenodd)
  46. ;        *p&=~mask;
  47. ;      else
  48. ;        *p|=mask;
  49. ;}
  50. GREY_LINE_LOW  proc far _p:fptr, _mask:word, _hoehe:word, _evenodd:word
  51.         uses    di
  52.         .enter
  53.                 les di,_p               ; pointer into destination buffer
  54.                 mov ah,{byte}_mask      ; mask marking bits to clear
  55.                 mov al,ah               ; we need a "set" and a "clear" mask
  56.                 not al                  ; make it a "clear" mask
  57.                 mov cx,_hoehe           ; number of points to clear
  58.                 mov bx,_evenodd         ; even/odd toggle
  59. greyloop:       test bx,1
  60.                 je grey_set
  61.                 and {byte}es:[di],al    ; apply mask
  62.                 jmp short grey_cont
  63. grey_set:       or  {byte}es:[di],ah    ; apply mask
  64. grey_cont:      add di,OFF_LINES        ; advance one line
  65.                 xor bx,1                ; toggle black/white
  66.                 loop greyloop           ; do until done
  67.         .leave
  68.         ret
  69. GREY_LINE_LOW  endp
  70.  
  71. ;void scale_line_low(char *p,char mask,char *tp,char tmask,int ypos,word hoehe)
  72. ;{
  73. ;    int ylimit;
  74. ;    int error,c1,c2;                    ; Konstanten für Bresenham
  75. ;
  76. ;     ; Bresenham scaling of wall texture: x <=> source, y <=> destination
  77. ;
  78. ;    ylimit = MIN(ypos+hoehe,YAUF)-MAX(ypos,0);
  79. ;
  80. SCALE_LINE_LOW  proc far _p:fptr, _mask:word, _tp:fptr, _tmask:word, _ypos:sword, _hoehe:word
  81.         uses    si,di
  82.         .enter
  83.                 push    bp
  84.                 push    ds
  85.                 push    es
  86.  
  87.                 ; compute ylimit (number of pixels in offscreen target bitmap)
  88.                 mov     dx,_ypos        ; MIN(ypos+hoehe,YAUF)
  89.                 add     dx,_hoehe
  90.                 cmp     dx,YAUF
  91.                 jl      sll_1
  92.                   mov     dx,YAUF
  93. sll_1:          mov     bx,_ypos        ; MAX(ypos,0)
  94.                 cmp     bx,0
  95.                 jge     sll_2
  96.                   mov     bx,0
  97. sll_2:          sub     dx,bx           ; MIN()-MAX()
  98.                 push    dx              ; (store ylimit for later use)
  99.  
  100.                 mov     ah,{byte}_mask
  101.                 mov     al,{byte}_tmask
  102.                 lds     si,_tp
  103.                 les     di,_p
  104.  
  105.                 cmp     _hoehe,TEX_SIZE
  106.                 ja      sll_enlarge
  107.  
  108. ;    if(TEX_SIZE>=hoehe)                 ; reducing texture
  109. ;    {
  110. ;      c1 = 2 * hoehe;
  111. ;      error = c1 - (TEX_SIZE-1);
  112. ;      c2 = error - (TEX_SIZE-1);
  113.  
  114.                 mov     cx,_hoehe       ; c1=2*hoehe
  115.                 add     cx,_hoehe
  116.                 mov     bx,cx           ; error=c1-(TEX_SIZE-1)
  117.                 sub     bx,(TEX_SIZE-1)
  118.                 mov     dx,bx           ; c2=error-(TEX_SIZE-1)
  119.                 sub     dx,(TEX_SIZE-1)
  120.  
  121. ;      if(ypos<0)
  122. ;        while(ypos)
  123. ;        {
  124. ;          tp+=sizeof(texture[0]);
  125. ;          if(error < 0)                 ; Error ggf. erhöhen
  126. ;            error += c1;
  127. ;          else
  128. ;          {
  129. ;            ypos++;                     ; Auch Schritt nach "oben" (=Schirm)
  130. ;            error += c2;                ; Fehler vermerken.
  131. ;          }
  132. ;        }
  133.  
  134.                 mov     bp,_ypos        ; no access to local vars from here on
  135. sll_red_skip:   cmp     bp,0            ; no longer "above" screentop?
  136.                 jge     sll_red_endskip
  137.                   add     si,TEX_LINES  ; tp+=sizeof()
  138.                   cmp     bx,0          ; error<0 ?
  139.                   jge     sll_red_1
  140.                     add     bx,cx       ; yes: error+=c1
  141.                     jmp     sll_red_skip
  142. sll_red_1:        inc     bp            ; no: ypos++
  143.                   add     bx,dx         ; error+=c2
  144.                   jmp     sll_red_skip
  145. sll_red_endskip:
  146.  
  147. ;      while(ylimit)
  148. ;      {
  149. ;        tp+=sizeof(texture[0]);
  150. ;        if(error < 0)                   ; Error ggf. erhöhen
  151. ;          error += c1;
  152. ;        else
  153. ;        {
  154. ;          if( *tp & tmask )
  155. ;            *p|=mask;
  156. ;          else
  157. ;            *p&=~mask;
  158. ;          p+=sizeof(Offscreen.data[0]);
  159. ;          ylimit--;                     ; Auch Schritt nach "oben" (=Schirm)
  160. ;          error += c2;                  ; Fehler vermerken.
  161. ;        }
  162. ;      }
  163. ;    }
  164.  
  165.                 pop     bp              ; get ylimit
  166. sll_red_scale:  cmp     bp,0            ; copied all pixels
  167.                 je      sll_end
  168.                   add     si,TEX_LINES  ; tp+=sizeof()
  169.                   cmp     bx,0          ; error<0 ?
  170.                   jge     sll_red_2
  171.                     add     bx,cx       ; yes: error+=c1
  172.                     jmp     sll_red_scale
  173. sll_red_2:        test    ds:[si],al
  174.                   je      sll_red_clear
  175.                     or      es:[di],ah  ; set bit
  176.                     jmp     short sll_red_cont
  177. sll_red_clear:      not     ah
  178.                     and     es:[di],ah  ; clear bit
  179.                     not     ah
  180. sll_red_cont:     add     di,OFF_LINES  ; p+=sizeof()
  181.                   dec     bp            ; no: ylimit--
  182.                   add     bx,dx         ; error+=c2
  183.                   jmp     sll_red_scale
  184.  
  185. ;    else                                ; enlarging texture
  186. ;    {
  187. ;      c1 = 2 * (TEX_SIZE-1);
  188. ;      error = c1 - hoehe;
  189. ;      c2 = error - hoehe;
  190.  
  191. sll_enlarge:    mov     cx,TEX_SIZE-1   ; c1=2*(TEX_SIZE-1)
  192.                 add     cx,TEX_SIZE-1
  193.                 mov     bx,cx           ; error=c1-hoehe
  194.                 sub     bx,_hoehe
  195.                 mov     dx,bx           ; c2=error-hoehe
  196.                 sub     dx,_hoehe
  197.  
  198. ;      if(ypos<0)
  199. ;        while(ypos)
  200. ;        {
  201. ;          ypos++;                       ; Schritt nach "oben" (=auf Schirm)
  202. ;          if(error < 0)                 ; Error ggf. erhöhen
  203. ;            error += c1;
  204. ;          else
  205. ;          {
  206. ;            tp+=sizeof(texture[0]);
  207. ;            error += c2;                ; Fehler vermerken.
  208. ;          }
  209. ;        }
  210.  
  211.                 mov     bp,_ypos        ; no access to local vars from here on
  212. sll_enl_skip:   cmp     bp,0            ; no longer "above" screentop?
  213.                 jge     sll_enl_endskip
  214.                   inc     bp            ; ypos++
  215.                   cmp     bx,0          ; error<0 ?
  216.                   jge     sll_enl_1
  217.                     add     bx,cx       ; yes: error+=c1
  218.                     jmp     sll_enl_skip
  219. sll_enl_1:        add     si,TEX_LINES  ; no: tp+=sizeof()
  220.                   add     bx,dx         ; error+=c2
  221.                   jmp     sll_enl_skip
  222. sll_enl_endskip:
  223.  
  224. ;      while(ylimit)
  225. ;      {
  226. ;        if( *tp & tmask )
  227. ;          *p|=mask;
  228. ;        else
  229. ;          *p&=~mask;
  230. ;        p+=sizeof(Offscreen.data[0]);
  231. ;        ylimit--;                       ; Schritt nach "oben" (=auf Schirm)
  232. ;        if(error < 0)                   ; Error ggf. erhöhen
  233. ;          error += c1;
  234. ;        else
  235. ;        {
  236. ;          tp+=sizeof(texture[0]);
  237. ;          error += c2;                  ; Fehler vermerken.
  238. ;        }
  239. ;      }
  240. ;    }
  241.  
  242.                 pop     bp              ; get ylimit
  243. sll_enl_scale:  cmp     bp,0            ; copied all pixels
  244.                 je      sll_end
  245.                   test    ds:[si],al
  246.                   je      sll_enl_clear
  247.                     or      es:[di],ah  ; set bit
  248.                     jmp     short sll_enl_cont
  249. sll_enl_clear:      not     ah
  250.                     and     es:[di],ah  ; clear bit
  251.                     not     ah
  252. sll_enl_cont:     add     di,OFF_LINES  ; p+=sizeof()
  253.                   dec     bp            ; no: ylimit--
  254.                   cmp     bx,0          ; error<0 ?
  255.                   jge     sll_enl_2
  256.                     add     bx,cx       ; yes: error+=c1
  257.                     jmp     sll_enl_scale
  258. sll_enl_2:        add     si,TEX_LINES  ; tp+=sizeof()
  259.                   add     bx,dx         ; error+=c2
  260.                   jmp     sll_enl_scale
  261. ;}
  262. sll_end:        pop     es
  263.                 pop     ds
  264.                 pop     bp
  265.         .leave
  266.         ret
  267. SCALE_LINE_LOW  endp
  268.  
  269. ASM_TEXT        ends
  270.