home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 186_01 / txtplot.csm < prev    next >
Text File  |  1985-08-21  |  3KB  |  113 lines

  1. ;   TXTPLOT.CSM
  2. ;   New txtplot function for BDS C library.:
  3. ;    James Pritchett,  3/11/85
  4. ;   Version 1.1, 6/14/85
  5.  
  6. ;    Format:
  7. ;   int txtplot(string,x,y,tabsiz)
  8. ;   char *string;
  9. ;   int  x, y, tabsiz;
  10.  
  11. ;   "string" is a pointer to the line to be plotted, "x" and "y" are
  12. ;   the screen coordinates to plot at, and "tabsiz" is the
  13. ;   factor for tab expansion.
  14.  
  15. ;   Strings may be either null-terminated or CR-terminated.
  16. ;   All control characters are ignored, except for tabs.
  17. ;   Tabs are expanded to every "tabsiz" space.
  18. ;   Parity is stripped.
  19. ;   Lines extending beyond column 80 are truncated.
  20. ;   Function returns the last column mapped.
  21.  
  22. ;   This function uses the values of "pbase" and "ysize" that are
  23. ;   stored in C.CCC.  See TXTPLOT.DOC for details of how to
  24. ;   set these parameters.
  25.  
  26.     INCLUDE    "BDS.LIB"
  27.  
  28. MAXCOL    EQU    80        ; Screen width
  29.  
  30.     FUNCTION TXTPLOT
  31.     CALL    ARGHAK        ; Gets the args passed
  32.     PUSH    B        ; 'cause Leor sez so
  33.     LHLD    ARG2        ; = row number (x)
  34.     XCHG            ; Row in DE
  35.     LHLD    YSIZE        ; = number of columns (120)
  36.     CALL    USMUL        ; X * 120 = beginning of row in memory
  37.     XCHG            ; Store this in HL
  38.     LHLD    ARG3        ; = column number (y)
  39.     MOV    C,L        ; Store in C for now
  40.     DAD    D        ; Y + (x * 120) = offset for location (x,y)
  41.     XCHG            ; Put in DE
  42.     LHLD    PBASE        ; Base of video ram
  43.     DAD    D        ; Base + offset = location to begin mapping
  44.     XCHG            ; Mapping address in HL
  45.     LHLD    ARG1        ; = string address
  46.  
  47. ;at this point, C = colcount, DE = target, HL = source
  48.  
  49. TXT0:
  50.     MOV    A,M        ; Fetch the char
  51.     ANI    7FH        ; Strip parity
  52.     CPI    ' '        ; Is it a control?
  53.     JC    TXT2        ; If so, check it out
  54.     
  55.     STAX    D        ; Else, map it
  56.     CALL    CHKCOL        ; Check for end of screen
  57.     JZ    TXTEXIT        ; Truncate if so
  58. TXT1:
  59.     INX    H        ; Else, increment pointers
  60.     INX    D
  61.     JMP    TXT0        ; And loop
  62.  
  63. TXT2:
  64.     ORA    A        ; Null is end of string
  65.     JZ    TXTEXIT
  66.     CPI    CR        ; As is a CR
  67.     JZ    TXTEXIT
  68.     CPI    TAB        ; Tabs are ok
  69.     JNZ    TXT1        ; Skip all others
  70.  
  71. TXTTAB:
  72.     PUSH    B        ; We need these registers
  73.     LDA    ARG4        ; Get the tabsiz
  74.     MOV    B,A        ; And put into B
  75.     MOV    A,C        ; A = current column
  76. TAB1:
  77.     CMP    B        ; This is a modulus function
  78.     JC    TAB2
  79.     SUB    B
  80.     JMP    TAB1
  81. TAB2:
  82.     MOV    C,A        ; C = column mod tabsiz
  83.     MOV    A,B        ; A = tabsiz
  84.     SUB    C        ; Tabsiz - (column mod tabsiz) = counter
  85.     POP    B        ; All clear now
  86.     XCHG            ; HL => video ram
  87.     MOV    B,A        ; B = count, C = column
  88. TAB3:
  89.     MVI    M,' '        ; Send a space
  90.     CALL    CHKCOL        ; Don't go too far
  91.     JZ    TXTEXIT
  92.     INX    H        ; Next map address
  93.     DCR    B        ; Countdown
  94.     JNZ    TAB3        ; Loop till count = 0
  95.     XCHG            ; Return string pointer to HL
  96.     INX    H        ; And increment it
  97.     JMP    TXT0        ; All done with this tab
  98.  
  99. TXTEXIT:
  100.     MOV    L,C        ; Set HL to last column
  101.     MVI    H,0
  102.     POP    B        ; Don't forget this
  103.     RET            ; All done
  104.  
  105. CHKCOL:
  106.     INR    C        ; Bump column count
  107.     MVI    A,MAXCOL    ; 80 cols in screen
  108.     CMP    C        ; Check it out
  109.     RET            ; Returns zero set on end of screen
  110.     ENDFUNC
  111.  
  112. 
  113.