home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / RTGRAF.ZIP / SOURCE.ZIP / ETEXT.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-30  |  9.1 KB  |  277 lines

  1. ;====================================================================
  2. ;  display a null terminated string with the baseline at x,y in color
  3. ;  using supplied font
  4. ;  struct font  {
  5. ;      uchar   cell_width      // in bytes
  6. ;      uchar   cell_depth      // in scan lines
  7. ;      uchar   baseline        // in scan lines from top 0-rel
  8. ;      uchar   first_char      // ASCII value of 1st cell in font
  9. ;      uchar   last_char       // ASCII value of last cell in font
  10. ;      struct  cell  {
  11. ;              uchar   width   // pixel width of this character
  12. ;              uchar   points[cell_depth][cell_width]
  13. ;              } cells[last_char-first_char +1]
  14. ;      }
  15. ;--------------------------------------------------------------------
  16. ;  etext (int x, int y, char* string, int color, char* font);
  17. ;
  18.  
  19. ;  Large parms
  20. pX0        equ [bp+6]
  21. pY0        equ [bp+8]
  22. pSoffs     equ [bp+10]
  23. pSseg      equ [bp+12]
  24. pColor     equ [bp+14]
  25. pFoffs     equ [bp+16]
  26. pFseg      equ [bp+18]
  27.  
  28. ;  Local storage
  29. lBytesWide equ WORD PTR [bp-2]
  30. lHigh      equ BYTE PTR [bp-4]
  31. lHwrk      equ BYTE PTR [bp-6]
  32. lWwrk      equ WORD PTR [bp-8]
  33. lCellsize  equ WORD PTR [bp-12]
  34. lStrPos    equ WORD PTR [bp-14]
  35. lBytesChar equ WORD PTR [bp-16]
  36. lBwide     equ WORD PTR [bp-18]
  37. lCurrVidSeg equ WORD PTR [bp-20]
  38.  
  39. ;  Font header control structure
  40. fonthdr    struc
  41.    cell_wide   db  ?
  42.    cell_high   db  ?
  43.    baseline    db  ?
  44.    char_wide   db  ?
  45.    first_ch    db  ?
  46.    last_ch     db  ?
  47.    cell_base   db  ?
  48. fonthdr    ends
  49.  
  50.  
  51.    public  _etext
  52.  
  53. _etext proc far
  54.        push    bp              ;<1>
  55.        mov     bp,sp
  56.        sub     sp,22
  57.        pushf
  58.        push    si              ;<2>
  59.        push    di              ;<3>
  60.        push    ds              ;<4>
  61.        push    es              ;<5>
  62.  
  63.        cld
  64.  
  65.        mov     si,pFoffs       ;font offset
  66.        mov     ax,pSoffs
  67.        mov     lStrPos,ax      ;save string offset--we will adjust this
  68.  
  69.        ;   Make the size of a scan line and video addressable for the stack
  70.        mov     ax,_bytes_per_line
  71.        mov     lBwide,ax
  72.        mov     ax,_curr_vid_seg
  73.        mov     lCurrVidSeg,ax
  74.  
  75.        ;   Adjust the video image back up to the top of the box
  76.        ;   based upon the baseline offset from the top
  77.  
  78.        mov     ds,pFseg        ;addressability on the font
  79.        xor     cx,cx
  80.        mov     cl,[si].baseline ;how many to back up
  81.        cmp     cl,0            ;no adjustmet needed ?
  82.  
  83.        ;   Decrement the pixel base by 80 (640 pixels) for each
  84.        ;   scanline that the cell top is above the baseline.
  85.  
  86.        jz      PcharBaseSet
  87. PcharBloop:
  88.        dec     WORD PTR pY0    ;up one scan line in bytes
  89.        loop    PcharBloop
  90. PcharBaseSet:
  91.  
  92.        ;   Compute the size of the individual cells in the font
  93.        ;   character description array  (wide(bytes)*deep(scans)) +1
  94.  
  95.        mov     al,[si].cell_wide   ;DS:SI => font structure
  96.        mul     [si].cell_high
  97.        inc     ax
  98.        mov     lCellsize,ax
  99.  
  100.        ;   Set lBytesWide to the number of bits in one scan line
  101.  
  102.        mov     al,[si].cell_wide   ;byte width
  103.        xor     ah,ah               ;clear top of 16bit reg
  104.        mov     lBytesWide,ax       ;save it
  105.  
  106.        ;   get a working copy of the depth
  107.  
  108.        mov     al,[si].cell_high
  109.        mov     lHigh,al
  110.  
  111.        ;   Set mode to SET/RESET
  112.  
  113.        mov     dx,GRAPHIC12
  114.        mov     al,SETRESET
  115.        out     dx,al
  116.  
  117.        inc     dx
  118.        mov     al,pColor
  119.        out     dx,al
  120.  
  121.        dec     dx
  122.        mov     al,ENABLERESET
  123.        out     dx,al
  124.        inc     dx
  125.        mov     al,0fh              ; all 4 planes
  126.        out     dx,al
  127.  
  128. ;====================================================================
  129.        ;   This loop is done for each char in the string
  130.  
  131. PcharNextByte:
  132.        mov     cx,pX0          ;pick up user coordinates
  133.        mov     bx,pY0
  134.        call    emapxy          ;compute byte & bit offset
  135.  
  136.        ;       fetch a character, test that it is in range
  137.  
  138.        push    di              ;<6>points to video byte
  139.        mov     si,pFoffs       ;address font structure
  140.        mov     es,pSseg        ;addressability on the string to print
  141.        mov     di,lStrPos      ;offset to next character in the string
  142.        mov     al,es:[di]      ;fetch it
  143.        cmp     al,0
  144.        jnz     PcharNotEOS     ;NULL=end of string  1 extra push on stack!!
  145.        jmp     PcharStrEnd
  146. PcharNotEOS:
  147.        inc     di              ;prepare for next char
  148.        mov     lStrPos,di      ;save offset away
  149.        pop     di              ;<5>points to video again
  150.  
  151.        ;   Test that it is within range
  152.  
  153.        cmp     al,[si].first_ch ;is it lower that the 1st character
  154.        jb      PcharNextByte   ;too low - ignore
  155.        cmp     al,[si].last_ch ;is it too big?
  156.        jnbe    PcharNextByte
  157.  
  158.        ;   In range, now determine the offset within the font
  159.  
  160.        sub     al,[si].first_ch ;ordinal position
  161.        xor     ah,ah           ;clear top of ax
  162.        mul     lCellSize       ;position x cellsize = offset within font
  163.  
  164.        ;   Now make an indexed address out of it
  165.  
  166.        lea     bx,[si].cell_base ;where the char definitions start
  167.        add     bx,ax           ;bx = pointer to start of definition
  168.        inc     bx              ;ignore 1st byte which is a proportional width
  169.  
  170.        ;   we are now ready to print ???
  171.  
  172.        mov     ax,lCurrVidSeg  ;page #1
  173.        mov     es,ax           ;ES=video  DS=font
  174.        mov     si,bx           ;font char definition
  175.  
  176.        call    Pchar           ; display this character
  177.  
  178.        ;   Now adjust for the next character
  179.  
  180.        mov     si,pFoffs       ;address the font header
  181.  
  182.        ;   Compute next char base from last char and fixed width
  183.        ;   of font characters
  184.  
  185.        mov     dl,[si].char_wide ;width in pixels
  186.        xor     dh,dh           ;DL=actual width of character set
  187.        add     pX0,dx          ;DI=start of next character
  188.  
  189.        jmp     PcharNextByte
  190.  
  191.        ;   All done
  192.  
  193. PcharStrEnd:
  194.        pop     di              ;pop off that Di that was pushed just
  195.                                ; b4 fetching the NULL but never poped
  196.        ;   reset write mode
  197.        mov     dx,GRAPHIC12
  198.        mov     al,ENABLERESET
  199.        out     dx,al
  200.  
  201.        inc     dx
  202.        mov     al,00h          ;Enable all planes for set
  203.        out     dx,al
  204.  
  205.        ;   set bitmask to FF
  206.  
  207.        GR12_BITMASK 0ffh       ;reset all pixel masks just incase
  208.  
  209.        mov     ax,pX0          ; next character position
  210.        pop     es              ;<4>
  211.        pop     ds              ;<3>
  212.        pop     di              ;<2>
  213.        pop     si              ;<1>
  214.        popf
  215.        mov     sp,bp
  216.        pop     bp              ;<0>
  217.        ret
  218.  
  219. Pchar proc  NEAR
  220. ;====================================================================
  221. ;====================================================================
  222. ;  put an individual character on the screen
  223. ;      DS:SI = beginning of char definition in font
  224. ;      ES:DI = top of character cell invideo memory
  225. ;      ah    = bit to be used next after shifting
  226. ;      al    = 1) bits from font  2) by macro for video controler
  227. ;      bx    = count of bits processed
  228. ;      cx    = shifting count to align with video memory
  229. ;      dx    = 1) video controller  2) temp stuff
  230. ;
  231. ;----------------------------------------------------------------------
  232.        mov     al,lHigh
  233.        mov     lHwrk,al        ;count of scan lines
  234.  
  235.        ;   compute alignment amount to video memory
  236.  
  237.        mov     cx,pX0          ;video position
  238.        and     cx,7            ;alignment amount
  239.  
  240. PcharScanLine:
  241.        push    di              ;<6>save start of scan line pixel
  242.        mov     bx,lBytesWide    ;cell width in bytes
  243.        xor     ax,ax           ;all zeros
  244.  
  245. PcharScanByte:
  246.        lodsb                   ;get a byte of of the font   0000000011111111
  247.        dec     bx              ;bytes -= 1
  248.        ror     ax,cl           ;rotate unused up into AH    1100000000111111
  249.        push    ax              ;<7>save current bits
  250.        mov     ah,al           ;move wanted to ah           0011111100111111
  251.        GR12_BITMASK ah         ;mask pixels to be updated   ^^^^^^^^
  252.        mov     ax,pColor       ;retreive the color
  253.        mov     ah,es:[di]      ;store thru bits set
  254.        stosb                   ;store color thru bit mask
  255.        pop     ax              ;<6>get back the scan image  1100000000111111
  256.        rol     ah,cl           ;leftover bits to end of AH  00000011xxxxxxxx
  257.  
  258.        ;   adjust bits/scan line
  259.  
  260.        cmp     bx,0            ; is this the 1st or later times through?
  261.        jg      PcharScanByte   ; more bytes to process
  262.  
  263. PcharRiteEnd:
  264.        ror     ah,cl           ;move remaining bits into top of AH
  265.        GR12_BITMASK ah
  266.        mov     al,es:[di]
  267.        stosb                   ;store color thru bit mask
  268.  
  269. PcharScanDone:
  270.        pop     di              ;<5>get back start of scan line
  271.        add     di,lBwide       ;move to next scanline
  272.        dec     lHwrk           ;
  273.        jnz     PcharScanLine   ;nope- do another
  274.        ret
  275. Pchar  endp
  276. _etext endp
  277.