home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / FONTASM.AS$ / FONTASM.bin
Encoding:
Text File  |  1990-06-24  |  15.2 KB  |  511 lines

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