home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER2.ISO / prog / djgpp / cbgrx102.a01 / CONTRIB / LIBGRX / SRC / WORDDRAW.H < prev   
Encoding:
C/C++ Source or Header  |  1992-08-12  |  9.4 KB  |  263 lines

  1. /**
  2.  ** WORDDRAW.H
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef _WORDDRAW_H_
  25. #define _WORDDRAW_H_
  26.  
  27. #ifndef __GNUC__
  28. #error  This file is for the DJGPP version only !!!
  29. #endif
  30.  
  31. /*
  32.  * utilities -- other files may define them too
  33.  */
  34. #ifndef _SaveDS
  35.  
  36. #define _ASV        asm volatile
  37. #define _ClrDir()    _ASV("cld")
  38. #define _SetDir()    _ASV("std")
  39. #define _SaveDS()
  40. #define _RestoreDS()
  41.  
  42. #endif  /* _SaveDS */
  43.  
  44. /*
  45.  * display a bit mapped font character (both FGC and BGC)
  46.  */
  47. #define __WRTFONT__(dst,offs,bits,wdt,hgt,fg,bg,putword) do {        \
  48.     int _HGT_ = (hgt);                            \
  49.     _ASV("                                                            \n\
  50.     movl    %1,%%edi                          \n\
  51.     movl    %3,%%esi                          \n\
  52.     movl    %5,%%edx                          \n\
  53.     xorl    %6,%%edx                          \n\
  54. L_Font"#putword"NextRow:                          \n\
  55.     movl    %4,%%ecx                          \n\
  56. L_Font"#putword"ReadBits:                          \n\
  57.     lodsb                                  \n\
  58.     movb    %%al,%%bl                          \n\
  59.     stc                                  \n\
  60.     adcb    %%bl,%%bl                          \n\
  61. L_Font"#putword"Loop:                              \n\
  62.     sbbl    %%eax,%%eax                          \n\
  63.     andl    %%edx,%%eax                          \n\
  64.     xorl    %6,%%eax                          \n\
  65.     "putword"                              \n\
  66.     addb    %%bl,%%bl                          \n\
  67.     loopnz  L_Font"#putword"Loop                      \n\
  68.     orl    %%ecx,%%ecx                          \n\
  69.     jnz    L_Font"#putword"ReadBits                  \n\
  70.     addl    %2,%%edi                          \n\
  71.     decl    %0                              \n\
  72.     jnz    L_Font"#putword"NextRow                       "\
  73.     : "=g" (_HGT_)                            \
  74.     : "g" (dst), "g" (offs),   "g" (bits),                \
  75.       "g" (wdt), "g" (fg),       "g" (bg)                \
  76.     : "di", "si", "dx", "cx", "bx", "ax"                \
  77.     );                                    \
  78. } while(0)
  79.  
  80. /*
  81.  * display a bit mapped font character (FGC or BGC only)
  82.  */
  83. #define __WR1CFNT__(dst,offs,bits,wdt,hgt,color,jump,opr)     _ASV("  \n\
  84.     movl    %0,%%edi                          \n\
  85.     movl    %2,%%esi                          \n\
  86.     movl    %4,%%ebx                          \n\
  87.     movl    %5,%%edx                          \n\
  88. L_Font"jump opr"NextRow:                          \n\
  89.     movl    %3,%%ecx                          \n\
  90. L_Font"jump opr"ReadBits:                          \n\
  91.     lodsb                                  \n\
  92.     stc                                  \n\
  93.     adcb    %%al,%%al                          \n\
  94. L_Font"jump opr"Loop:                              \n\
  95.     "jump"  L_Font"jump opr"NoSet                      \n\
  96.     "opr"w  %%dx,(%%edi)                          \n\
  97. L_Font"jump opr"NoSet:                              \n\
  98.     leal    2(%%edi),%%edi                          \n\
  99.     addb    %%al,%%al                          \n\
  100.     loopnz  L_Font"jump opr"Loop                      \n\
  101.     orl    %%ecx,%%ecx                          \n\
  102.     jnz    L_Font"jump opr"ReadBits                  \n\
  103.     addl    %1,%%edi                          \n\
  104.     decl    %%ebx                              \n\
  105.     jnz    L_Font"jump opr"NextRow                       "\
  106.     : /* NOTHING */                            \
  107.     : "g" (dst), "g" (offs), "g" (bits),                \
  108.       "g" (wdt), "g" (hgt),  "g" (color)                \
  109.     : "di", "si", "dx", "cx", "bx", "ax"                \
  110. )
  111.  
  112. #define __WFSET__    "stosw"
  113. #define __WFXOR__    "xorw   %%ax,(%%edi); leal  2(%%edi),%%edi"
  114. #define __WFOR__    "orw    %%ax,(%%edi); leal  2(%%edi),%%edi"
  115. #define __WFAND__    "andw   %%ax,(%%edi); leal  2(%%edi),%%edi"
  116.  
  117. #define _WriteFont(dp,o,bp,w,h,f,b)    __WRTFONT__(dp,o,bp,w,h,f,b,__WFSET__)
  118. #define _WriteFontXor(dp,o,bp,w,h,f,b)  __WRTFONT__(dp,o,bp,w,h,f,b,__WFXOR__)
  119. #define _WriteFontOr(dp,o,bp,w,h,f,b)    __WRTFONT__(dp,o,bp,w,h,f,b,__WFOR__)
  120. #define _WriteFontAnd(dp,o,bp,w,h,f,b)  __WRTFONT__(dp,o,bp,w,h,f,b,__WFAND__)
  121.  
  122. #define _WrFGCFont(dp,o,bp,w,h,fg)    __WR1CFNT__(dp,o,bp,w,h,fg,"jnc","mov")
  123. #define _WrFGCFontXor(dp,o,bp,w,h,fg)    __WR1CFNT__(dp,o,bp,w,h,fg,"jnc","xor")
  124. #define _WrFGCFontOr(dp,o,bp,w,h,fg)    __WR1CFNT__(dp,o,bp,w,h,fg,"jnc","or")
  125. #define _WrFGCFontAnd(dp,o,bp,w,h,fg)    __WR1CFNT__(dp,o,bp,w,h,fg,"jnc","and")
  126.  
  127. #define _WrBGCFont(dp,o,bp,w,h,bg)    __WR1CFNT__(dp,o,bp,w,h,bg,"jc","mov")
  128. #define _WrBGCFontXor(dp,o,bp,w,h,bg)    __WR1CFNT__(dp,o,bp,w,h,bg,"jc","xor")
  129. #define _WrBGCFontOr(dp,o,bp,w,h,bg)    __WR1CFNT__(dp,o,bp,w,h,bg,"jc","or")
  130. #define _WrBGCFontAnd(dp,o,bp,w,h,bg)    __WR1CFNT__(dp,o,bp,w,h,bg,"jc","and")
  131.  
  132. /*
  133.  * set a bitmap patterned row
  134.  */
  135. #define __PTNROW__(dst,maskpatt,width,fgc,bgc,putword) _ASV("         \n\
  136.     movl    %0,%%edi                          \n\
  137.     movl    %1,%%edx                          \n\
  138.     movl    %2,%%ecx                          \n\
  139.     movl    %3,%%ebx                          \n\
  140.     movl    %4,%%esi                          \n\
  141.     xorl    %%esi,%%ebx                          \n\
  142. L_Patt"#putword"Loop:                              \n\
  143.     rolb    $1,%%dl                              \n\
  144.     sbbl    %%eax,%%eax                          \n\
  145.     andl    %%ebx,%%eax                          \n\
  146.     xorl    %%esi,%%eax                          \n\
  147.     "putword"                              \n\
  148.     loop    L_Patt"#putword"Loop                       "\
  149.     : /* NOTHING */                            \
  150.     : "g" (dst), "g" (maskpatt), "g" (width), "g" (fgc), "g" (bgc)  \
  151.     : "di", "si", "dx", "cx", "bx", "ax"                \
  152. )
  153.  
  154. /*
  155.  * set a bitmap patterned row, foreground or background only
  156.  */
  157. #define __P1CROW__(dst,maskpatt,width,color,jump,opr) _ASV("          \n\
  158.     movl    %0,%%edi                          \n\
  159.     movl    %1,%%edx                          \n\
  160.     movl    %2,%%ecx                          \n\
  161.     movl    %3,%%eax                          \n\
  162. L_Patt"jump opr"Loop:                              \n\
  163.     rolb    $1,%%dl                              \n\
  164.     "jump"  L_Patt"jump opr"NoSet                      \n\
  165.     "opr"w  %%ax,(%%edi)                          \n\
  166. L_Patt"jump opr"NoSet:                              \n\
  167.     leal    2(%%edi),%%edi                          \n\
  168.     loop    L_Patt"jump opr"Loop                      \n\
  169. L_Patt"jump opr"End:                               "\
  170.     : /* NOTHING */                            \
  171.     : "g" (dst), "g" (maskpatt), "g" (width), "g" (color)        \
  172.     : "di", "dx", "cx", "ax"                    \
  173. )
  174.  
  175. #define _PatternSet(dst,msk,wdt,f,b)    __PTNROW__(dst,msk,wdt,f,b,__WFSET__)
  176. #define _PatternXor(dst,msk,wdt,f,b)    __PTNROW__(dst,msk,wdt,f,b,__WFXOR__)
  177. #define _PatternOr(dst,msk,wdt,f,b)    __PTNROW__(dst,msk,wdt,f,b,__WFOR__)
  178. #define _PatternAnd(dst,msk,wdt,f,b)    __PTNROW__(dst,msk,wdt,f,b,__WFAND__)
  179.  
  180. #define _PattFGCSet(dst,msk,wdt,fg)    __P1CROW__(dst,msk,wdt,fg,"jnc","mov")
  181. #define _PattFGCXor(dst,msk,wdt,fg)    __P1CROW__(dst,msk,wdt,fg,"jnc","xor")
  182. #define _PattFGCOr(dst,msk,wdt,fg)    __P1CROW__(dst,msk,wdt,fg,"jnc","or")
  183. #define _PattFGCAnd(dst,msk,wdt,fg)    __P1CROW__(dst,msk,wdt,fg,"jnc","and")
  184.  
  185. #define _PattBGCSet(dst,msk,wdt,bg)    __P1CROW__(dst,msk,wdt,bg,"jc","mov")
  186. #define _PattBGCXor(dst,msk,wdt,bg)    __P1CROW__(dst,msk,wdt,bg,"jc","xor")
  187. #define _PattBGCOr(dst,msk,wdt,bg)    __P1CROW__(dst,msk,wdt,bg,"jc","or")
  188. #define _PattBGCAnd(dst,msk,wdt,bg)    __P1CROW__(dst,msk,wdt,bg,"jc","and")
  189.  
  190. /*
  191.  * X major line drawing
  192.  */
  193. #define __XLINE__(dst,offs,deltx,delty,color,putword) _ASV("          \n\
  194.     movl    %0,%%edi                          \n\
  195.     movl    %1,%%esi                          \n\
  196.     movl    %2,%%ecx                          \n\
  197.     movl    %3,%%ebx                          \n\
  198.     movl    %4,%%eax                          \n\
  199.     movl    %%ecx,%%edx                          \n\
  200.     shrl    $1,%%edx                          \n\
  201.     incl    %%ecx                              \n\
  202. L_LineX"#putword"Loop:                              \n\
  203.     "putword"                              \n\
  204.     subl    %%ebx,%%edx                          \n\
  205.     jnc    L_LineX"#putword"NoAdjust                  \n\
  206.     addl    %2,%%edx                          \n\
  207.     addl    %%esi,%%edi                          \n\
  208. L_LineX"#putword"NoAdjust:                          \n\
  209.     loop    L_LineX"#putword"Loop                       "\
  210.     : /* NOTHING */                            \
  211.     : "g" (dst), "g" (offs), "g" (deltx), "g" (delty), "g" (color)  \
  212.     : "di", "si", "dx", "cx", "bx", "ax"                \
  213. )
  214.  
  215. #define __XLSET__    "stosw"
  216. #define __XLXOR__    "xorw   %%ax,(%%edi); leal  2(%%edi),%%edi"
  217. #define __XLOR__    "orw    %%ax,(%%edi); leal  2(%%edi),%%edi"
  218. #define __XLAND__    "andw   %%ax,(%%edi); leal  2(%%edi),%%edi"
  219.  
  220. #define _DrawXLine(dp,do,dx,dy,c)    __XLINE__(dp,do,dx,dy,c,__XLSET__)
  221. #define _DrawXLineXor(dp,do,dx,dy,c)    __XLINE__(dp,do,dx,dy,c,__XLXOR__)
  222. #define _DrawXLineOr(dp,do,dx,dy,c)    __XLINE__(dp,do,dx,dy,c,__XLOR__)
  223. #define _DrawXLineAnd(dp,do,dx,dy,c)    __XLINE__(dp,do,dx,dy,c,__XLAND__)
  224.  
  225. /*
  226.  * Y major line drawing
  227.  */
  228. #define __YLINE__(dst,offs,deltx,delty,color,putword) _ASV("          \n\
  229.     movl    %0,%%edi                          \n\
  230.     movl    %1,%%esi                          \n\
  231.     movl    %3,%%ecx                          \n\
  232.     movl    %2,%%ebx                          \n\
  233.     movl    %4,%%eax                          \n\
  234.     movl    %%ecx,%%edx                          \n\
  235.     shrl    $1,%%edx                          \n\
  236.     incl    %%ecx                              \n\
  237. L_LineY"#putword"Loop:                              \n\
  238.     "putword"                              \n\
  239.     addl    %%esi,%%edi                          \n\
  240.     subl    %%ebx,%%edx                          \n\
  241.     jnc    L_LineY"#putword"NoAdjust                  \n\
  242.     addl    %3,%%edx                          \n\
  243.     leal    2(%%edi),%%edi                          \n\
  244. L_LineY"#putword"NoAdjust:                          \n\
  245.     loop    L_LineY"#putword"Loop                       "\
  246.     : /* NOTHING */                            \
  247.     : "g" (dst), "g" (offs), "g" (deltx), "g" (delty), "g" (color)  \
  248.     : "di", "si", "dx", "cx", "bx", "ax"                \
  249. )
  250.  
  251. #define __YLSET__    "movw   %%ax,(%%edi)"
  252. #define __YLXOR__    "xorw   %%ax,(%%edi)"
  253. #define __YLOR__    "orw    %%ax,(%%edi)"
  254. #define __YLAND__    "andw   %%ax,(%%edi)"
  255.  
  256. #define _DrawYLine(dp,do,dx,dy,c)    __YLINE__(dp,do,dx,dy,c,__YLSET__)
  257. #define _DrawYLineXor(dp,do,dx,dy,c)    __YLINE__(dp,do,dx,dy,c,__YLXOR__)
  258. #define _DrawYLineOr(dp,do,dx,dy,c)    __YLINE__(dp,do,dx,dy,c,__YLOR__)
  259. #define _DrawYLineAnd(dp,do,dx,dy,c)    __YLINE__(dp,do,dx,dy,c,__YLAND__)
  260.  
  261. #endif  /* whole file */
  262.  
  263.