home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TURBO.ZIP / FASTPRNT.ASM < prev    next >
Encoding:
Assembly Source File  |  1984-04-27  |  7.0 KB  |  226 lines

  1. ;--------------------------------------------------------------------
  2. ;           Program    FAST_PRINT.ASM
  3. ;====================================================================
  4. ; PROGRAM: FAST_PRINT
  5. ;
  6. ;       This program is a high speed screen printing routine for
  7. ;       use with TurboPascal.  It overcomes the problem of the
  8. ;       painfully slow printing facilities commonly supported by
  9. ;       MS-DOS.  This routine is capable of filling the screen
  10. ;       twenty times in one second.
  11. ;
  12. ;       The routine requires that TurboPascal pass a string and
  13. ;       an integer.    The string is printed with the Attribute
  14. ;       type specified by the integer.  The calling format is:
  15. ;
  16. ;           Procedure FastPrint(s:StringType, Attribute:Interger);
  17. ;             External;
  18. ;           FastPrint(strng,Attribute);
  19. ;
  20. ; AUTHOR : Jeff Firestone
  21. ;       April 27, 1984
  22. ;--------------------------------------------------------------------
  23.  
  24. MPOP    MACRO    DEST            ;Move the stack addr. into DEST
  25.     POP    AX
  26.     MOV    DEST, AX
  27.     ENDM
  28.  
  29. MPUSH    MACRO    SOURCE             ;Push the SOURCE onto the Stack
  30.     MOV    AX, SOURCE
  31.     PUSH    AX
  32.     ENDM
  33.  
  34.  
  35. BIOSseg      EQU     0040h        ;Segment Address of BIOS
  36. MonoSeg      EQU     0B000h        ;Segment Address of Monocrome Card
  37. ColorSeg     EQU     0B800h        ;Segment Address of Color Card
  38.  
  39. bEquipFlag   EQU     0010h        ;Address of Equipment flag in BIOS
  40. bCrtCols     EQU     004Ah        ;Address of number of columns on screen
  41. bCrtLen      EQU     004Ch        ;Address of length of regen in bytes
  42. bCursorPos   EQU     0050h        ;Address of Cursor Pos in BIOS
  43. bPageNumber  EQU     0062h        ;Address of Video Page number in BIOS
  44. bAddr_6845   EQU     0063h        ;Base address for active display card
  45.  
  46.  
  47. CODE         SEGMENT PARA PUBLIC 'CODE'
  48.          ASSUME  CS:CODE
  49.          PUBLIC  FASTPRINT
  50.  
  51. FASTPRINT    PROC    NEAR
  52.  
  53.          CALL    BEGIN
  54.  
  55. BasePage      DW     ?            ;Storage for BP reg
  56. RETURN          DW     ?            ;Storage for return address
  57. Attribute     DB     ?            ;Storage for Attribute byte
  58.  
  59. CrtCols      DB      ?            ;Address of number of columns on screen
  60. CrtLen         DW      ?            ;Address of length of regen in bytes
  61. Addr_6845    DW      ?            ;Base address for active display card
  62. CrtBoundary  DW      ?            ;Bottom of current CRT page
  63.  
  64.  
  65. BEGIN    PROC     NEAR
  66.     pop     ax               ;Get the segment for our data
  67.     sub     ax, 3               ;Adjust it
  68.     mov     si, ax            ;Move to SI temporarily
  69.     mov     BasePage[si], bp      ;Save old BP for exit
  70.     mov     bp, ax            ;BP now points to our data
  71.     cld                   ;Set direction forward
  72.  
  73.     MPOP     RETURN[bp]           ;Save the RETURN Addr.
  74.     pop     ax               ;Get the attribute into AX
  75.     mov     Attribute[bp], al     ;Save Attribute byte
  76.     pop     si               ;Get the string address in SI
  77.     pop     ax               ;A dummy pop to clear the stack
  78.     call     strdisp
  79.  
  80.     MPUSH    RETURN[bp]           ;Replace the Return Addr.
  81.     mov    bp, BasePage[bp]       ;Restore the BasePage
  82.     RET
  83. begin    endp
  84.  
  85.  
  86. strdisp proc near
  87.     mov      ax, BIOSseg            ;Segment 0040h
  88.     mov      es, ax            ;  loaded into ES
  89.  
  90.     mov      bx, 00            ;Zero BX
  91.     mov      al, ES:bCrtCols[bx]
  92.     mov      CrtCols[bp], al        ;Init CrtCols
  93.     mov      ax, ES:bCrtLen[bx]
  94.     mov      CrtLen[bp], ax        ;Init CrtLen
  95.     mov      ax, ES:bAddr_6845
  96.     mov      Addr_6845[bp], ax        ;Init Addr_6845
  97.  
  98.     mov      ax, ES:bCursorPos[bx]     ;Get Cursor POS in AX
  99.     mov      cl, ES:bPageNumber[bx]    ;Get Screen Page Number
  100.     xor      ch, ch            ;Zero screen page # garbage
  101.  
  102.     mov      dx, MonoSeg            ;Get Mono Screen Segment
  103.     mov      di, ES:bEquipFlag[bx]     ;Equipment setting to DI
  104.     and      di, 30h            ;Mask the flag
  105.     cmp      di, 30h            ;Is it B&W Card
  106.     jz      B_W                ;Yep, seg OK
  107.     mov      dx, ColorSeg            ;Nope, use Color Seg
  108. B_W:    mov      es, dx            ;Assign the video seg to ES
  109.  
  110.     jcxz      PageZero            ;Skip if Screen # is zero
  111.  
  112. PageLoop:
  113.     add      bx, CrtLen[bp]        ;Adjust for Screen Page #
  114.     loop      PageLoop
  115.  
  116. PageZero:
  117.     mov      di, bx            ;Save Screen Addr for later
  118.     mov      cx, bx            ;Get Screen Addr
  119.     add      cx, CrtLen[bp]        ;Add a page length
  120.     mov      CrtBoundary[bp], cx        ;Set up CrtBoundary
  121.  
  122.     mov      bl, al            ;Move COL to BL
  123.     xor      bh, bh            ;COL = BX
  124.     mov      al, ah            ;Move ROW to AL
  125.     xor      ah, ah            ;ROW = AX
  126.     mul      CrtCols[bp]            ;# of bytes per row
  127.     add      ax, bx            ;Add ROW & COL
  128.     sal      ax, 1             ;Times 2 for attribute bytes
  129.     add      di, ax            ;Add Screen Addr to Scrn POS
  130.  
  131.     mov      cl, byte ptr DS:[si]        ;Get string length
  132.     xor      ch, ch            ;Zero MSD
  133.     inc      si                ;Point at first char
  134.     mov      ah, Attribute[bp]        ;Put Video Attribute in AL
  135.  
  136. ScreenPrint:
  137.     mov      al, byte ptr DS:[si]        ;Get string character
  138.     cmp      al, 13            ;Is it a CR?
  139.     jz     short  NextLine            ;Nope, goto next line
  140.     mov      ES:[di], ax            ;Place on screen
  141.     inc      si                ;Point @ next char
  142.     inc      di                ;Point @ next screen pos
  143.     inc      di
  144.     loop  short  ScreenPrint
  145.  
  146.  
  147. ReplacePOS:
  148.     mov      ax, BIOSseg
  149.     mov      es, ax
  150.     mov      ax, di            ;Get screen pos
  151.     mov      cl, ES:bPageNumber[bx]    ;Get Screen Page Number
  152.     xor      ch, ch            ;Zero MSD
  153.     jcxz      ZeroPage            ;Dont bother if page zero
  154. DecLoop:
  155.     sub      ax, CrtLen[bp]        ;Adjust for Screen Page #
  156.     loop      DecLoop
  157.  
  158. ZeroPage:
  159.     sar      ax, 1             ;Divide by 2 for attribute byte
  160.     mov      bx, ax            ;Save for later
  161.     div      CrtCols[bp]            ;Divide by # of columns
  162.     xor      ah, ah            ;Zero remainder
  163.     mov      dh, al            ;Place ROWs into DH
  164.     mul      CrtCols[bp]            ;Translate back into screenpos
  165.     sub      bx, ax            ;Get remaining Columns
  166.     mov      dl, bl            ;Place COLs into DL
  167.  
  168.     mov      si, bCursorPos        ;Get Cursor Pos in BIOS
  169.     mov      es:[si], dx            ;Update it
  170.  
  171.     ret
  172.  
  173. NextLine:
  174.     mov      ax, di            ;Get screen pos
  175.     sar      ax, 1             ;Divide by 2 for attribute byte
  176.     div      CrtCols[bp]            ;Divide by # of columns
  177.     xor      ah, ah            ;Zero remainder
  178.     mul      CrtCols[bp]            ;Get beginning of line
  179.     mov      bl, CrtCols[bp]        ;Get line length
  180.     xor      bh, bh            ;Zero high BH
  181.     add      ax, bx            ;Move to next line
  182.     sal      ax, 1             ;Adjust for Attribute bytes
  183.     mov      di, ax            ;Screen pos back to DI
  184.     cmp      di, CrtBoundary[bp]        ;Is the Curp Pointer to far?
  185.     jl      Next1             ;Nope, no need to scrole
  186.     call      ScroleScreen            ;Scrole the screen
  187. Next1:    inc      si                ;Move to next string char
  188.     mov      ah, Attribute[bp]        ;Put Video Attribute in AL
  189.     dec      cx                ;Dec count
  190.     jnz      ScreenPrint            ;Print next char if any
  191.     jmp      ReplacePos            ;Put in Cursor Pos
  192.  
  193.  
  194. ScroleScreen:
  195.     push      si                ;Save the string pointer
  196.     push      cx                ;Save the count register
  197.     mov      di, CrtBoundary[bp]        ;DI = CrtBoundary
  198.     mov      cx, CrtLen[bp]        ;CX = CrtLen
  199.     sub      di, cx            ;DI = Top of current page
  200.     mov      si, di            ;SI = Top of current page
  201.     mov      al, CrtCols[bp]        ;Get CrtCols
  202.     xor      ah, ah            ;Clear MSD
  203.     sal      ax, 1             ;AX = CrtCols * 2
  204.     add      si, ax            ;SI = Second line is source
  205.     sar      ax, 1             ;AX = CrtCols
  206.     sub      cx, ax            ;CX = # of chars to scrole
  207.     push      ds                ;Save DS
  208.     mov      ax, es            ;Get ES
  209.     mov      ds, ax            ;Put is DS
  210. rep    movsw                    ;Scrole the screen
  211.     pop      ds                ;Restore DS
  212.     push      di                ;Save bottom line addr
  213.     mov      cx, ax            ;Save CrtCols number of zeros
  214.     mov      ax, 00            ;Store zeros
  215. rep    stosw                    ;Clear bottom line
  216.     pop      di                ;Screen pointer set to new line
  217.     pop      cx                ;Recall the count register
  218.     pop      si                ;Recall the string pointer
  219.     ret
  220.  
  221. strdisp endp
  222.  
  223. fastprint endp
  224. code      ends
  225.       end
  226.