home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 223_02 / fputc.mac < prev    next >
Text File  |  1989-02-23  |  4KB  |  217 lines

  1.  
  2. ;
  3. ;    putc(c,unit)
  4. ;
  5. ;
  6. CBDOS    EQU    5    ;/* bdos entry point */
  7. CPMARG    EQU    128    ;/* CP/M command line */
  8. MAXARG    EQU    32    ;/* Maximum number of input args */
  9. STDIN    EQU    0
  10. STDOUT    EQU    1
  11. STDERR    EQU    2
  12. STDLST    EQU    4
  13. CTRLZ    EQU    26    ;control z
  14. NULL    EQU    0    ;pointer to nothing
  15. FCBSIZE    EQU    36    ;size, in bytes, of an FCB
  16. NEXTP    EQU    0    ;offset    to next-character pointer in I/O structure
  17. UNUSED    EQU    2    ;offset    to unused-positions-count in I/O structure
  18. BUFFER    EQU    6    ;offset    to disk    sector buffer in I/O structure
  19. UNGOT    EQU    5    ;offset to char ungotten by ungetc()
  20. FLAG    EQU    33    ;file-type flag    byte (in unused    part of    FCB)
  21. FREEFLG    EQU    128    ;This I/O structure is available for the taking
  22. EOFFLG    EQU    2    ;The end of this file has been hit
  23. WRTFLG    EQU    1    ;This file open    for writing
  24. BUFSIZ    EQU    1024    ;how long the sector buffer is
  25. NBUFS    EQU    8    ;number    of I/O buffers
  26. TBUFF    EQU    128    ;default cpm buffer
  27. LF    EQU    10
  28. EOL    EQU    13
  29. ;
  30. ; CP/M BDOS CALLS 
  31. ;
  32. CLOSE    EQU    16    ;close a file
  33. CPMSTR    EQU    9    ;print '$' delimited string on console
  34. CREATE    EQU    22    ;make a    file
  35. DMA    EQU    26    ;set DMA (I/O address)
  36. DELETE    EQU    19    ;delete    a file
  37. GETCH    EQU    1    ;read character    from console
  38. GETSTR    EQU    10    ;read string from console
  39. LSTOUT    EQU    5    ;write character to list device
  40. OPEN    EQU    15    ;open a    file
  41. PUTCH    EQU    2    ;write character to console
  42. QUERY    EQU    25    ;get logged-in drive id
  43. READ    EQU    20    ;read a    sector
  44. SELECT    EQU    14    ;log-in    a drive
  45. WRITE    EQU    21    ;write a sector
  46. ;
  47. ;    File i/o storage varibles found in ulink()
  48. ;
  49. EXTRN    ZZUNIT
  50. EXTRN    ZZIP
  51. EXTRN    ZZCHP
  52. EXTRN    ZZDP
  53. EXTRN    ZZFILE
  54. EXTRN    ZZMODE
  55. EXTRN    ZZCH
  56. EXTRN    ZZT
  57. EXTRN    ZZFN
  58. EXTRN    ZZNUBU
  59. EXTRN    ZZMXSC
  60. ;
  61. ;    Characteristics variable storage found in ulink()    
  62. ;
  63. EXTRN    ZZSVCH
  64. EXTRN    ZZDFLT
  65. EXTRN    ZZSTAK
  66. EXTRN    ZZMEM
  67. ;
  68. EXTRN    PUTCHAR
  69. EXTRN    PUTLIST
  70. EXTRN    CPMIO
  71. ;
  72. FPUTC::
  73. PUTC::
  74.     POP    B    ;rtn addr
  75.     POP    D    ;unit
  76.     POP    H    ;c
  77.     PUSH    H
  78.     PUSH    D
  79.     PUSH    B
  80.     MOV    A,D
  81.     ORA    A        ; if(unit < 256) {
  82.     JNZ    PUTC4        ;    /* assume stdout, stderr */
  83.     MOV    A,E        ;    /* or stdlist. */
  84.     CPI    STDOUT        ;    if(unit    == stdout) {
  85.     JNZ    PUTC1
  86.     PUSH    H
  87.     CALL    PUTCHAR        ;        putchar(c);
  88.     POP    H
  89.     RET            ;        return;}
  90. PUTC1:    CPI    STDERR        ;    elseif(unit == stderr) {
  91.     JNZ    PUTC2
  92.     PUSH     H
  93.     CALL    PUTCHAR        ;        putchar(c);
  94.     POP    H
  95.     RET            ;        return;}
  96. PUTC2:    CPI    STDLST        ;    elseif(unit == stdlist)    {
  97.     JNZ    PUTC3
  98.     PUSH    H
  99.     CALL    PUTLIST        ;        putlist(c);
  100.     POP    H
  101.     RET            ;        return;}
  102. PUTC3:    JMP    PTCER1        ;    else goto putcerr; }
  103.  
  104. PUTC4:    PUSH    H            ; if(cput(c,unit)<0)
  105.     PUSH    D            ;    goto putcerr;
  106.     CALL    CPUT
  107.     POP    D
  108.     MOV    A,H
  109.     ORA    A
  110.     JM    PUTCERR
  111.     MOV    A,L            ; if(c=='\r')
  112.     CPI    EOL
  113.     JNZ    PUTCRET
  114.     LXI    H,LF            ;    cput('\n',unit);
  115.     PUSH    H
  116.     PUSH    D
  117.     CALL    CPUT
  118.     POP    D
  119.     POP    D
  120.     MOV    A,H
  121.     ORA    A
  122.     JM    PUTCERR
  123. PUTCRET:
  124.     POP    H            ; return(c);
  125.     RET
  126. PUTCERR:                ;putcerr:
  127.     POP    B            ; return(-1);
  128. PTCER1:
  129.     LXI    H,-1
  130.     RET
  131.  
  132. ;
  133. ;    cput(c,unit)
  134. ;
  135. CPUT::
  136.     POP    B
  137.     POP    D
  138.     POP    H
  139.     PUSH    H
  140.     PUSH    D
  141.     PUSH    B
  142.     SHLD    ZZCH
  143.     XCHG
  144.     SHLD    ZZUNIT
  145.     LXI    D,FCBSIZE        ; ip = unit + FCBSIZE;
  146.     DAD    D
  147.     SHLD    ZZIP
  148.     LXI    D,NEXTP            ; cp = ip[NEXTP];
  149.     DAD    D
  150.     MOV    E,M
  151.     INX    H
  152.     MOV    D,M
  153.     XCHG
  154.     SHLD    ZZCHP
  155.     LHLD    ZZIP            ; if(ip[UNUSED]==0){
  156.     LXI    D,UNUSED
  157.     DAD    D
  158.     MOV    A,M
  159.     INX    H
  160.     ORA    M
  161.     JNZ    PTCIF1
  162.     LXI    H,WRITE            ;    if(cpmio(WRITE,unit)~=0)    
  163.     PUSH    H
  164.     LHLD    ZZUNIT
  165.     PUSH    H
  166.     CALL    CPMIO
  167.     POP    D
  168.     POP    D
  169.     MOV    A,H
  170.     ORA    L
  171.     JZ    PTCIF2
  172.     LXI    H,-1            ;        return(-1);
  173.     RET
  174. PTCIF2:
  175.     LHLD    ZZIP            ;    else {    ip[UNUSED] = BUFSIZ;
  176.     LXI    D,UNUSED
  177.     DAD    D
  178.     LXI    D,BUFSIZ
  179.     MOV    M,E
  180.     INX    H
  181.     MOV    M,D
  182.     LHLD    ZZIP            ;        cp = &ip[BUFFER];
  183.     LXI    D,BUFFER
  184.     DAD    D
  185.     SHLD    ZZCHP
  186.                     ;        }
  187.                     ;    }
  188. PTCIF1:
  189.     LHLD    ZZIP
  190.     LXI    D,UNUSED        ; ip[UNUSED]--;
  191.     DAD    D
  192.     MOV    E,M
  193.     INX    H
  194.     MOV    D,M
  195.     DCX    D
  196.     MOV    M,D
  197.     DCX    H
  198.     MOV    M,E
  199.     LHLD    ZZCHP            ; ip[NEXTP] = cp+1;
  200.     INX    H
  201.     XCHG
  202.     LHLD    ZZIP
  203.     LXI    B,NEXTP
  204.     DAD    B
  205.     MOV    M,E
  206.     INX    H
  207.     MOV    M,D
  208.     LDA    ZZCH            ; return((*cp =    c) & 0377);
  209.     LHLD    ZZCHP
  210.     MOV    M,A
  211.     MVI    H,0
  212.     MOV    L,A
  213.     RET
  214.  
  215.     END    
  216.  
  217.