home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / zsys / simtel20 / z3lib / zlib2.lbr / Z3PCL.Z80 < prev    next >
Encoding:
Text File  |  1986-02-07  |  2.4 KB  |  132 lines

  1. ;
  2. ; Z3LIB Module Name:  Z3PCL
  3. ; Author:  Richard Conn
  4. ; Z3LIB  Version Number:  1.3
  5. ; Module Version Number:  1.1
  6. ;
  7.     public    putcl
  8.  
  9.     ext    getcl1,getcl2
  10.  
  11. ;
  12. ; Macros
  13. ;
  14. putrg    macro
  15.     push    bc
  16.     push    de
  17.     push    hl
  18.     endm
  19.  
  20. getrg    macro
  21.     pop    hl
  22.     pop    de
  23.     pop    bc
  24.     endm
  25.  
  26. ;
  27. ;    Z3PCL stores a command line in the ZCPR3 command line buffer.
  28. ; This command line is pted to by HL.  On return, A=0 and Zero Flag Set
  29. ; if command line overflow is possible (no change to command line).
  30. ;
  31. putcl:
  32.     putrg            ;save registers
  33.     ex    de,hl        ;DE pts to new line
  34.     call    getcl1        ;is command line available?
  35.     jp    nz,pcl1
  36. ;
  37. ; Error Return
  38. ;
  39. nocl:
  40.     getrg            ;restore registers
  41.     xor    a        ;ret Z
  42.     ret
  43. ;
  44. ; Process Command Line
  45. ;
  46. pcl1:
  47.     ld    b,a        ;char count in B
  48.     ex    de,hl        ;HL pts to new line
  49.     push    hl        ;save ptr to new line
  50. pcl2:
  51.     ld    a,(hl)        ;go to end of line
  52.     or    a        ;at end?
  53.     jp    z,pcl3
  54.     inc    hl        ;pt to next
  55.     dec    b        ;count down
  56.     jp    nz,pcl2
  57.     pop    hl        ;clear stack
  58.     jp    nocl        ;command line too long
  59. ;
  60. ; At End of New Command Line (ptr on stack)
  61. ;    Ptr to first char of new command line on stack
  62. ;    HL pts to ending 0 of new command line
  63. ;    B = number of chars remaining before overflow of Z3 command line
  64. ;
  65. pcl3:
  66.     ex    de,hl        ;DE pts to last byte
  67.     push    de        ;save ptr to last byte in case of error
  68.     call    getcl2        ;pt to tail of command line buffer
  69.     ld    a,(hl)        ;get first char of tail
  70.     cp    ';'        ;continuation?
  71.     jp    z,pcl4
  72.     or    a        ;done?
  73.     jp    z,pcl4
  74.     ld    a,';'        ;set continuation char
  75.     ld    (de),a
  76.     inc    de
  77.     dec    b        ;count down
  78.     jp    z,pcl5        ;overflow
  79. ;
  80. ; Copy tail onto end of new command line
  81. ;
  82. pcl4:
  83.     ld    a,(hl)        ;get next char
  84.     ld    (de),a        ;store it
  85.     inc    hl        ;pt to next
  86.     inc    de
  87.     or    a        ;done?
  88.     jp    z,pcl6
  89.     dec    b        ;count down
  90.     jp    nz,pcl4
  91. ;
  92. ; Command Line too Long
  93. ;
  94. pcl5:
  95.     pop    hl        ;get ptr to end of old line
  96.     ld    (hl),0        ;store ending 0
  97.     pop    af        ;clear stack
  98.     jp    nocl
  99. ;
  100. ; New Command Line OK
  101. ;
  102. pcl6:
  103.     pop    af        ;clear stack
  104.     call    getcl1        ;get ptr to buffer
  105.     ld    de,4        ;pt to first char in buffer
  106.     ex    de,hl
  107.     add    hl,de
  108.     ex    de,hl
  109.     ld    (hl),e        ;store address
  110.     inc    hl
  111.     ld    (hl),d        ;DE pts to first char of buffer
  112.     pop    hl        ;HL pts to first char of new line
  113. ;
  114. ; Copy New Command Line into Buffer
  115. ;
  116. pcl7:
  117.     ld    a,(hl)        ;copy
  118.     ld    (de),a
  119.     inc    hl
  120.     inc    de
  121.     or    a        ;EOL?
  122.     jp    nz,pcl7
  123. ;
  124. ; Exit with OK Code
  125. ;
  126.     getrg            ;restore regs
  127.     xor    a        ;set NZ
  128.     dec    a
  129.     ret
  130.  
  131.     end
  132.