home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l391 / 2.ddi / FONTASM.AS$ / FONTASM.bin
Encoding:
Text File  |  1992-08-19  |  14.7 KB  |  520 lines

  1. ; ------------------------------------------------------------------------
  2. ; Assembly language routines for the Visual Basic for MS-DOS
  3. ; Presentation Graphics ToolKit.
  4. ;
  5. ;   fl_SetBltDir    - Sets bltchar direction increments
  6. ;   fl_SetBltColor  - Sets color parameter for bltchar
  7. ;   fl_SetBltParams - Sets font related parameters for bltchar
  8. ;   fl_BltChar      - Character output routine
  9. ;
  10. ;   fl_MovMem       - Moves memory
  11. ;   fl_ansi         - Maps IBM chars to Windows ANSI;
  12. ;
  13. ; Copyright (C) 1982-1992 Microsoft Corporation
  14. ;
  15. ; You have a royalty-free right to use, modify, reproduce
  16. ; and distribute the sample applications and toolkits provided with
  17. ; Visual Basic for MS-DOS (and/or any modified version)
  18. ; in any way you find useful, provided that you agree that
  19. ; Microsoft has no warranty, obligations or liability for
  20. ; any of the sample applications or toolkits.
  21. ; ------------------------------------------------------------------------
  22.  
  23. .MODEL  MEDIUM
  24.  
  25. ; BASIC Procedures
  26. EXTRN       B$N1I2:far, B$PSTC:far
  27.  
  28. ; BltChar data block
  29. .DATA
  30.  
  31. ; These are set by fl_SetBltParams
  32. HdrLen      dw      0       ;length of windows font file header
  33. CharHeight  dw      0       ;character height
  34. FirstChar   dw      0       ;first character defined in font
  35. LastChar    dw      0       ;last character defined in font
  36. DefaultChar dw      0       ;default character to use
  37.  
  38. ; This is set by fl_SetBltColor
  39. CharColor   dw      0       ;current character color
  40.  
  41. ; These are set by fl_SetBltDir
  42. XPixInc     dw      1       ;x inc for each pixel in character bitmap
  43. YPixInc     dw      0       ;y inc for each pixel in character bitmap
  44. XRowInc     dw      0       ;x inc for each row in character bitmap
  45. YRowInc     dw      1       ;y inc for each row in character bitmap
  46. XColInc     dw      8       ;x inc for each column (8 bits) in char bitmap
  47. YColInc     dw      0       ;y inc for each column (8 bits) in char bitmap
  48.  
  49. .CODE
  50. ;********************************************************************
  51. ; fl_SetBltDir - Sets pixel, row, and column step values for bltchar
  52. ;
  53. ;   BASIC CALL:
  54. ;       fl.SetBltDir XPixInc%, YPixInc%, XRowInc%, YRowInc%
  55. ;
  56. ;   Comments:
  57. ;       When bltchar is blt-ing a bitmap to allow the different
  58. ;       directions to be output it uses preset counter increments
  59. ;       for moving a pixel, to the next row, and to the next column
  60. ;       of the bitmap. The pixel and row increments are input to this
  61. ;       routine. The column increments are calculates as 8 times the
  62. ;       pixel increment.
  63. ;
  64. ;********************************************************************
  65.  
  66. ; Parameters
  67. pXPixInc    equ     WORD PTR [bp+12]
  68. pYPixInc    equ     WORD PTR [bp+10]
  69. pXRowInc    equ     WORD PTR [bp+8]
  70. pYRowInc    equ     WORD PTR [bp+6]
  71.  
  72.         PUBLIC  FL_SETBLTDIR
  73. fl_SetBltDir PROC
  74.  
  75.         push    bp          ;Entry
  76.         mov     bp,sp
  77.  
  78.         mov     ax,pXRowInc ;Save input parameters
  79.         mov     XRowInc,ax
  80.         mov     ax,pYRowInc
  81.         mov     YRowInc,ax
  82.  
  83.         mov     ax,pXPixInc
  84.         mov     XPixInc,ax
  85.         mov     cl,3
  86.         shl     ax,cl
  87.         mov     XColInc,ax  ;Column increment = Pix Inc * 8
  88.  
  89.         mov     ax,pYPixInc
  90.         mov     YPixInc,ax
  91.         mov     cl,3
  92.         shl     ax,cl
  93.         mov     YColInc,ax  ;Column increment = Pix Inc * 8
  94.  
  95.         pop     bp          ;Exit
  96.         ret     8
  97. fl_SetBltDir ENDP
  98.  
  99. ;********************************************************************
  100. ; fl_SetBltColor - Sets the color of blt-ed characters
  101. ;
  102. ;   BASIC CALL:
  103. ;       fl.SetBltColor color
  104. ;
  105. ;********************************************************************
  106.  
  107. ; Parameters
  108. pColor      EQU     WORD PTR [bp+6]
  109.  
  110.         PUBLIC  FL_SETBLTCOLOR
  111. fl_SetBltColor PROC
  112.  
  113.         push    bp              ;Entry
  114.         mov     bp,sp
  115.  
  116.         mov     ax,pColor       ;Save color in data block
  117.         mov     CharColor,ax
  118.  
  119.         pop     bp              ;Exit
  120.         ret     2
  121.  
  122. fl_SetBltColor  ENDP
  123.  
  124. ;********************************************************************
  125. ; fl_SetBltParams - Sets font-related params for bltchar
  126. ;
  127. ;   BASIC CALL:
  128. ;       fl.SetBltParams HdrLen%, CharHgt%, FirstChar%, LastChar%, DefChar%
  129. ;
  130. ;********************************************************************
  131.  
  132. ; Parameters
  133. pHdrLen     equ     WORD PTR [bp+14]
  134. pCharHgt    equ     WORD PTR [bp+12]
  135. pFirstChar  equ     WORD PTR [bp+10]
  136. pLastChar   equ     WORD PTR [bp+8]
  137. pDefChar    equ     WORD PTR [bp+6]
  138.  
  139.         PUBLIC  FL_SETBLTPARAMS
  140. fl_SetBltParams PROC
  141.  
  142.         push    bp              ;Entry
  143.         mov     bp,sp
  144.  
  145.         mov     ax,pHdrLen
  146.         mov     HdrLen,ax
  147.  
  148.         mov     ax,pCharHgt
  149.         mov     CharHeight,ax
  150.  
  151.         mov     ax,pFirstChar
  152.         mov     FirstChar,ax
  153.  
  154.         mov     ax,pLastChar
  155.         mov     LastChar,ax
  156.  
  157.         mov     ax,pDefChar
  158.         mov     DefaultChar,ax
  159.  
  160.         pop     bp              ;Exit
  161.         ret     10
  162.  
  163. fl_SetBltParams ENDP
  164.  
  165. ;********************************************************************
  166. ; fl_BltChar - Outputs a character's bitmap to the screen
  167. ;
  168. ;   BASIC CALL:
  169. ;       fl.BltChar FontAddr(far), Char%, X%, Y%
  170. ;
  171. ;********************************************************************
  172.  
  173. ; Parameters
  174. pFASeg      equ     WORD PTR [bp+14]
  175. pFAOffset   equ     WORD PTR [bp+12]
  176. pChar       equ     WORD PTR [bp+10]
  177. pX          equ     WORD PTR [bp+8]
  178. pY          equ     WORD PTR [bp+6]
  179.  
  180. ; Local Variables
  181. RowX       equ     WORD PTR [bp-2]
  182. RowY       equ     WORD PTR [bp-4]
  183. CharWid    equ     WORD PTR [bp-6]
  184. ColWid     equ     WORD PTR [bp-8]
  185.  
  186.         PUBLIC  FL_BLTCHAR
  187. fl_BltChar  PROC
  188.  
  189.         push    bp              ;Entry
  190.         mov     bp,sp
  191.         sub     sp,8            ;Make room for local variables
  192.         push    di
  193.         push    si
  194.  
  195.         ;Normalize font address (make offset as small as possible)
  196.         mov     ax,pFAOffset
  197.         mov     bx,pFASeg
  198.         push    ax
  199.         mov     cl,4
  200.         shr     ax,cl           ;offset = offset div 16
  201.         add     bx,ax           ;seg = seg + offset
  202.         pop     ax
  203.         and     ax,0Fh          ;offset = original offset mod 16
  204.         mov     si,ax
  205.         mov     es,bx
  206.  
  207.         ;Calculate character number
  208.         mov     bx,pChar
  209.         cmp     bx,LastChar
  210.         ja      usedefchar      ;Char is > last char, use default
  211.         sub     bx,FirstChar
  212.         jnc     getsize         ;Char is > first char, is OK
  213. usedefchar: mov     bx,DefaultChar
  214.  
  215.         ;Get character width from character table in font
  216. getsize:    shl     bx,1
  217.         shl     bx,1            ;char = char * 4
  218.         add     bx,si           ;offset into char table
  219.         mov     cx,es:[bx]      ;cx = character width
  220.         mov     CharWid,cx
  221.  
  222.         ;Calculate character bitmap address
  223.         inc     bx              ;move to next two bytes in char table
  224.         inc     bx
  225.         mov     cx,es:[bx]
  226.         add     si,cx           ;add bitmap offset into font index
  227.         sub     si,HdrLen       ;subtract length of header
  228.         dec     si              ;decrement for use in output algorithm
  229.  
  230.         ;Blt character
  231.         mov     cx,pX           ;cx = x coord
  232.         mov     dx,pY           ;dx = y coord
  233.  
  234.         mov     bx,CharWid
  235.  
  236. colloop:    mov     RowX,cx        ;save coordinates of this row
  237.         mov     RowY,dx
  238.         push    bx              ;save remaining bits in character
  239.         cmp     bx,8            ;limit to 8 for this column
  240.         jle     colloop2
  241.         mov     bx,8
  242.  
  243. colloop2:   mov     ColWid,bx      ;save width of this column for other rows
  244.         mov     ax,CharHeight   ;counter for number of rows
  245.  
  246. rowloop:    push    ax
  247.         inc     si              ;increment bitmap pointer
  248.         mov     al,es:[si]      ;get byte from bitmap
  249.  
  250. pixloop:    shl     al,1            ;check next bit (from left to right)
  251.         jnc     nextpixel       ;skip this pixel
  252.  
  253.         push    ax              ;save registers
  254.         push    bx
  255.         push    cx
  256.         push    dx
  257.         push    es
  258.         push    si
  259.  
  260.         mov     ax,CharColor    ;set up params for pset call
  261.         push    ax              ;color
  262.         push    cx              ;x-coordinate
  263.         push    dx              ;y-coordinate
  264.         call    B$N1I2          ;set graphics cursor location
  265.         call    B$PSTC          ;call PSET
  266.  
  267.         pop     si              ;restore registers
  268.         pop     es
  269.         pop     dx
  270.         pop     cx
  271.         pop     bx
  272.         pop     ax
  273.  
  274. nextpixel:  jz      nextrow         ;skip remaining zero bits
  275.         add     cx,XPixInc      ;increment x and y coordinates
  276.         add     dx,YPixInc
  277.         dec     bx              ;check for end of byte
  278.         jnz     pixloop         ;go for another pixel
  279.  
  280. nextrow:    mov     cx,RowX        ;retrieve the start coord of this row
  281.         mov     dx,RowY
  282.         add     cx,XRowInc      ;increment counters for next row
  283.         add     dx,YRowInc
  284.         mov     RowX,cx        ;save 'em back again
  285.         mov     RowY,dx
  286.         mov     bx,ColWid      ;reset the column width
  287.         pop     ax              ;check for the end of this column
  288.         dec     ax
  289.         jnz     rowloop         ;repeat for another row
  290.  
  291. nextcol:    mov     cx,pX           ;retrieve the start coord of this column
  292.         mov     dx,pY
  293.         add     cx,XColInc      ;increment coordinates for next column
  294.         add     dx,YColInc
  295.         mov     pX,cx           ;save coordinates to use after next column
  296.         mov     pY,dx
  297.         pop     bx              ;check for end of the bitmap
  298.         sub     bx,8
  299.         ja      colloop         ;repeat for another column
  300.  
  301.         ;Done
  302.         mov     ax,CharWid     ;return value
  303.  
  304.         pop     si              ;Exit
  305.         pop     di
  306.         mov     sp,bp
  307.         pop     bp
  308.         ret     10
  309. fl_BltChar  ENDP
  310.  
  311. ;********************************************************************
  312. ; fl_MovMem - Moves memory bytes
  313. ;
  314. ;   BASIC CALL:
  315. ;       fl.MovMem source, dest, nbytes
  316. ;
  317. ;********************************************************************
  318.         PUBLIC  FL_MOVMEM
  319. fl_MovMem   PROC
  320.         push    bp
  321.         mov     bp,sp
  322.         push    si
  323.         push    ds
  324.         push    di
  325.  
  326.         les     di,[bp+12]
  327.         lds     si,[bp+8]
  328.         mov     cx,[bp+6]
  329.         rep     movsb
  330.  
  331.         pop     di
  332.         pop     ds
  333.         pop     si
  334.         pop     bp
  335.         ret     10
  336. fl_MovMem   ENDP
  337.  
  338. ;********************************************************************
  339. ; fl_ansi - Converts IBM char to Windows ANSI mapping
  340. ;
  341. ;   BASIC CALL:
  342. ;       ansi_byte = fl_ansi (ibm_char%)
  343. ;
  344. ;********************************************************************
  345. .CODE
  346.         PUBLIC  FL_ANSI
  347. fl_ansi     PROC
  348.         push    bp
  349.         mov     bp,sp
  350.  
  351.         xor     ax,ax           ; zero ax
  352.         mov     al,[bp+6]       ; move input byte to ax
  353.         mov     bx,ax           ; copy byte to bx
  354.         and     al,7FH          ; mask off high bit
  355.         test    bl,80H          ; test bx to see it high bit set
  356.         jz      fl_a_2          ; if so then byte < 128, no translation
  357.  
  358.         mov     bx,OFFSET _OemToAnsiTable
  359.         xlat
  360.  
  361. fl_a_2:     pop     bp
  362.         ret     2
  363. fl_ansi     ENDP
  364.  
  365.  
  366. ;***************************************************************************
  367. ;   USA OEM/ANSI translation tables.                                       *
  368. ;***************************************************************************
  369. ;
  370.  
  371. ; This translation table is used by U.S.A. and some European countries.
  372. ; The original IBM extended character set is now addressed as Code Page 437.
  373. ; With DOS 3.3 or later, IBM introduced Code Page 850 as the preeminent
  374. ; multilingual character set.
  375.  
  376. ; this translates Oem codes >= 128 to ANSI.
  377. ; there are 128 entries.
  378.  
  379. .DATA
  380. _OemToAnsiTable  label   byte
  381.  
  382.     db   0C7H     ; 80h  C cedilla
  383.     db   0FCh     ; 81h  u umlaut
  384.     db   0E9h     ; 82h  e acute
  385.     db   0E2h     ; 83h  a circumflex
  386.     db   0E4h     ; 84h  a umlaut
  387.     db   0E0h     ; 85h  a grave
  388.     db   0E5h     ; 86h  a ring
  389.     db   0E7h     ; 87h  c cedilla
  390.     db   0EAh     ; 88h  e circumflex
  391.     db   0EBh     ; 89h  e umlaut
  392.     db   0E8h     ; 8Ah  e grave
  393.     db   0EFh     ; 8Bh  i umlaut
  394.     db   0EEh     ; 8Ch  i circumflex
  395.     db   0ECh     ; 8Dh  i grave
  396.     db   0C4h     ; 8Eh  A umlaut
  397.     db   0C5h     ; 8Fh  A ring
  398.  
  399.     db   0C9h     ; 90h  E acute
  400.     db   0E6h     ; 91h  ae
  401.     db   0C6h     ; 92h  AE
  402.     db   0F4h     ; 93h  o circumflex
  403.     db   0F6h     ; 94h  o umlaut
  404.     db   0F2h     ; 95h  o grave
  405.     db   0FBh     ; 96h  u circumflex
  406.     db   0F9h     ; 97h  u grave
  407.     db   0FFh     ; 98h  y umlaut
  408.     db   0D6h     ; 99h  O umlaut
  409.     db   0DCh     ; 9Ah  U umlaut
  410.     db   0A2h     ; 9Bh  cent
  411.     db   0A3h     ; 9Ch  british pound
  412.     db   0A5h     ; 9Dh  yen
  413.     db   070h     ; 9Eh  Pesetas
  414.     db   066h     ; 9Fh  florin (dutch)
  415.  
  416.     db   0E1h     ; A0h  a acute
  417.     db   0EDh     ; A1h  i acute
  418.     db   0F3h     ; A2h  o acute
  419.     db   0FAh     ; A3h  u acute
  420.     db   0F1h     ; A4h  n tilde
  421.     db   0D1h     ; A5h  N tilde
  422.     db   0AAh     ; A6h  a underlined superscript
  423.     db   0BAh     ; A7h  o underlined superscript
  424.     db   0BFh     ; A8h  inverted question mark
  425.     db   05Fh     ; A9h  left top corner
  426.     db   0ACh     ; AAh  right top corner
  427.     db   0BDh     ; ABh  1/2
  428.     db   0BCh     ; ACh  1/4
  429.     db   0A1h     ; ADh  inverted point
  430.     db   0ABh     ; AEh  <<
  431.     db   0BBh     ; AFh  >>
  432.  
  433.     db   05Fh     ; B0h  here begins semigraphic characters
  434.     db   05Fh     ; B1h
  435.     db   05Fh     ; B2h
  436.     db   0A6h     ; B3h  Vertical bar
  437.     db   05Fh     ; B4h
  438.     db   05Fh     ; B5h
  439.     db   05Fh     ; B6h
  440.     db   05Fh     ; B7h
  441.     db   05Fh     ; B8h
  442.     db   05Fh     ; B9h
  443.     db   05Fh     ; BAh
  444.     db   05Fh     ; BBh
  445.     db   05Fh     ; BCh
  446.     db   05Fh     ; BDh
  447.     db   05Fh     ; BEh
  448.     db   05Fh     ; BFh
  449.  
  450.     db   05Fh     ; C0h
  451.     db   05Fh     ; C1h
  452.     db   05Fh     ; C2h
  453.     db   05Fh     ; C3h
  454.     db   05Fh     ; C4h
  455.     db   05Fh     ; C5h
  456.     db   05Fh     ; C6h
  457.     db   05Fh     ; C7h
  458.     db   05Fh     ; C8h
  459.     db   05Fh     ; C9h
  460.     db   05Fh     ; CAh
  461.     db   05Fh     ; CBh
  462.     db   05Fh     ; CCh
  463.     db   05Fh     ; CDh
  464.     db   05Fh     ; CEh
  465.     db   05Fh     ; CFh
  466.  
  467.     db   05Fh     ; D0h
  468.     db   05Fh     ; D1h
  469.     db   05Fh     ; D2h
  470.     db   05Fh     ; D3h
  471.     db   05Fh     ; D4h
  472.     db   05Fh     ; D5h
  473.     db   05Fh     ; D6h
  474.     db   05Fh     ; D7h
  475.     db   05Fh     ; D8h
  476.     db   05Fh     ; D9h
  477.     db   05Fh     ; DAh
  478.     db   05Fh     ; DBh
  479.     db   05Fh     ; DCh
  480.     db   05Fh     ; DDh
  481.     db   05Fh     ; DEh
  482.     db   05Fh     ; DFh  end of semigraphic characters
  483.  
  484.     db   05Fh     ; E0h  alpha
  485.     db   0DFh     ; E1h  german sharp S or greek beta
  486.     db   05Fh     ; E2h  lambda
  487.     db   0B6h     ; E3h  pi
  488.     db   05Fh     ; E4h  sigma uc
  489.     db   05Fh     ; E5h  sigma lc
  490.     db   0B5h     ; E6h  mu
  491.     db   05Fh     ; E7h  tau
  492.     db   05Fh     ; E8h  phi uc
  493.     db   05Fh     ; E9h  theta
  494.     db   05Fh     ; EAh  omega
  495.     db   05Fh     ; EBh  delta
  496.     db   05Fh     ; ECh  infinite
  497.     db   0D8h     ; EDh  math empty set or phi lc
  498.     db   05Fh     ; EEh  math own sign
  499.     db   05Fh     ; EFh  math include sign
  500.  
  501.     db   05Fh     ; F0h  math equivalence sign
  502.     db   0B1h     ; F1h  + underlined
  503.     db   05Fh     ; F2h  greater equal
  504.     db   05Fh     ; F3h  less equal
  505.     db   05Fh     ; F4h  math integral upper part
  506.     db   05Fh     ; F5h  math integral lower part
  507.     db   05Fh     ; F6h  math divide
  508.     db   05Fh     ; F7h  math approximately (~)
  509.     db   0B0h     ; F8h  degree
  510.     db   0B7h     ; F9h  period accent (bold)
  511.     db   0B7h     ; FAh  period accent
  512.     db   05Fh     ; FBh  math root
  513.     db   06Eh     ; FCh  n superscript
  514.     db   0B2h     ; FDh  2 superscript
  515.     db   05Fh     ; FEh
  516.     db   05Fh     ; FFh  blank
  517.  
  518.     END
  519.  
  520.