home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / ZCNFG21.LBR / CFGSUBS.ZZ0 / CFGSUBS.Z8°
Text File  |  1991-10-27  |  13KB  |  612 lines

  1. ;Program name: CFGSUBS.Z80
  2. ;Author: Al Hawley
  3. ;Date 10/26/91
  4. ;Previous Date 09/17/91
  5.  
  6. ;Program function: Subroutines used with ZCNFG
  7.  
  8. ;standard definitions
  9.     .XLIST        ;don't bother listing in PRN
  10.     INCLUDE SYSDEF
  11.     .LIST
  12.  
  13. ;symbols from other modules
  14. ;from ZCNFG
  15.     EXT    Z3ENV,DEFDU,QUIT
  16.     EXT    COLCNT,ROWCNT,UCFLAG
  17.  
  18. ;from CFGLIB
  19.     EXT    SDELM
  20.  
  21. ;from SYSLIB
  22.     EXT    SETDMA,MA2HC,GUA,SUA,@BDOSA,ISPRINT
  23.  
  24. ;from VLIB
  25.     EXT    VPSTR,STNDOUT,STNDEND
  26.  
  27. ;symbols availale to other modules
  28.     PUBLIC    B2BCD,CLSFIL,CIN,COUT,CST,DEF_FT
  29.     PUBLIC    DEF_DU,DEF_FN,GUA,OPNFIL,RANGE,ISTXTF
  30.     PUBLIC    RDFILE,RDREC,STORDT,STRCPY,ISFNC
  31.     PUBLIC    TYPLIN,VCOUT,WRREC,MOVE2Z,SKIP2Z
  32.  
  33. ;=======================================================
  34.  
  35. DEF_DU:
  36. ;provides defaults for undefined D and/or U
  37. ;entry-    HL = DU with possible undefined values
  38. ;    BC = default DU
  39. ;exit-    HL = DU with no ambiguity
  40. ;    BC preserved
  41.  
  42.     LD    A,31        ;max user
  43.     CP    L        ;usr > max?
  44.     JR    NC,FIXA1    ;no if NC, don't adjust
  45.     LD    L,C        ;install default user
  46. FIXA1::    LD    A,16        ;max drive (1...16)
  47.     CP    H        ;drive > max?
  48.     RET    NC        ;done if not, else
  49.     CCF            ;reset carry, and
  50.     LD    H,B        ;install default drive
  51.     RET
  52.  
  53. ;=======================================================
  54.  
  55. DEF_FN:
  56. ;install the default FileName in the
  57. ;target FN field if it is empty.
  58.  
  59. ;entry-    DE -> target FCB
  60. ;    HL -> default FN
  61. ;exit-    flags NZ = no replacement
  62. ;           Z = FN field filled
  63. ;    DE preserved
  64. ;     B = 0
  65.  
  66.     PUSH    DE
  67.     INC    DE        ;->FN
  68.     LD    BC,8        ;(length of fn field)
  69.     LD    A,(DE)
  70.     CP    SPC        ;if the fn field is still empty,
  71.     JR    NZ,DEFFNX    ;(it isn't if nz)
  72.     LDIR            ;use target fn for overlay name
  73. DEFFNX:    POP    DE
  74.     RET
  75.     
  76. ;=========================================================
  77.  
  78. DEF_FT:
  79. ;install the default filetype in the fcb filetype
  80. ; field if it is currently filled with spaces.
  81. ;on entry, DE -> initialized FCB
  82. ;       HL -> default file type
  83. ;exit-    flags NZ = no replacement
  84. ;           Z = FN field filled
  85. ;    DE is preserved.
  86. ;     B = O
  87.  
  88.     PUSH    DE
  89.     EX    DE,HL
  90.     LD    BC,9
  91.     ADD    HL,BC
  92.     LD    A,' '
  93.     CP    A,(HL)        ;first char of type blank?
  94.     JR    NZ,FCBTYX    ;return if not. User has supplied type
  95.     EX    DE,HL        ;de -> fcb+9, hl -> def type
  96.     LD    BC,3        ;3 char to move
  97.     LDIR            ;move 'em
  98. FCBTYX:    POP    DE        ;fcb address
  99.     RET
  100.  
  101. ;=======================================================
  102. ;    TEST FOR DE WITHIN RANGE
  103.  
  104. RANGE:
  105. ;Returns NC if DE is within the range. The range
  106. ;of values includes the endpoints. Returns CY set
  107. ;if DE > Max or DE < Min
  108. ;entry-    DE = value to test
  109. ;    HL = high end of range
  110. ;    BC = low end of range
  111. ;exit-    DE and BC preserved
  112. ;    HL destroyed
  113. ;    Cy set = out of range, NC within
  114.  
  115.     OR    A
  116.     SBC    HL,DE        ;test high limit
  117.     RET    C        ;de higher than max
  118.     PUSH    DE        ;save test value
  119.     EX    DE,HL
  120.     SBC    HL,BC        ;test lower limit
  121.     POP    DE
  122.     RET            ;cy set = lower than min
  123.  
  124. ;=======================================================
  125.  
  126. ;    B2BCD - Convert Binary Byte to BCD
  127.  
  128. B2BCD:
  129. ;entry- A = binary value to convert
  130. ;exit-    A = bcd tens,ones
  131. ;    B = tens in high nibl
  132. ;    C = hundreds
  133. ;    flags, Z = number <100, NZ = number >99
  134.  
  135.     LD    BC,0FFFFH    ;b,c =-1, rdy for first increment
  136. B2BCD1:    INC    C        ;accumulate hundreds
  137.     SUB    100
  138.     JR    NC,B2BCD1
  139.     ADD    100        ;too much - back up!
  140. B2BCD0:    INC    B        ;accumulate 10s
  141.     SUB    10
  142.     JR    NC,B2BCD0
  143.     ADD    10        ;too much - back up!
  144.     RLC    B        ;shift into high nibl
  145.     RLC    B
  146.     RLC    B
  147.     RLC    B
  148.     OR    B        ;..and put into high nibl of A
  149.     INC    C
  150.     DEC    C        ;return nz if 100s present
  151.     RET            ;..and Z if not
  152.  
  153. ;=======================================================
  154.  
  155. ;    CONVERT BINARY TO DATE STRING
  156.  
  157. STORDT:
  158. ; BYTE -> 2 ASCII CHAR, 1 POSITION SKIPPED.
  159. ; Typically used to fill in '__/__/__'
  160.  
  161. ;entry-    HL -> Source (bytes)
  162. ;    DE -> Destination for ASCII
  163. ;    B  = number of bytes to convert
  164. ;exit-    HL -> next dest. & source
  165. ;    DE is preserved
  166.  
  167.     PUSH    DE
  168. STRDT0:    PUSH    BC        ;counter
  169.     LD    A,(HL)
  170.     CALL    MA2HC        ;send Hex ASCII to dest.
  171.     INC    DE        ;skip a dest. position
  172.     INC    HL        ;-> next source byte
  173.     POP    BC        ;recover counter
  174.     DJNZ    STRDT0
  175.     POP    DE
  176.     RET
  177.  
  178. ;===========================================================
  179.  
  180. ;CST, CIN, and COUT are replacements for the
  181. ;SYSLIB routines of the same name. Whereas SYSLIB
  182. ;uses BIOS calls for these functions, the replacements
  183. ;here use DOS function 6 calls for console status,
  184. ;input, and output. These routines take the place of
  185. ;SYSLIB routines with the same name if this module is
  186. ;linked ahead of SYSLIB.
  187.  
  188. ;--------------------------
  189. CST:
  190. ;console status using DOS function6 with
  191. ;Z flag inverted to agree with SYSLIB CST.
  192.  
  193.     CALL    CST6        ; get FN 6 console stat
  194.     JR    Z,CSTX        ; invert the Z flag
  195.     LD    A,1
  196. CSTX:    DEC    A        ; a->0ff if z, a->0 if nz
  197.     RET            ; and flags are readjusted to match
  198.  
  199. ;console status using DOS function 6
  200. ;exit-     Z = no character waiting
  201. ;    NZ = Character waiting
  202.  
  203. CST6:    PUSH    DE
  204.     PUSH    BC
  205.     PUSH    HL
  206.     LD    E,0FEH        ; console status call
  207.     LD    C,6        ; bdos function number
  208.     CALL    BDOS
  209.     AND    A        ; anything there?
  210.     POP    HL
  211.     POP    BC
  212.     POP    DE
  213.     RET
  214.  
  215. ;--------------------------
  216.  
  217. CIN:
  218. ;console input using DOS function 6
  219. ;exit-    A contains the character, and NZ
  220. ;    if A=0 then there was no character
  221. ;    and Z
  222.  
  223.     PUSH    DE
  224.     PUSH    BC
  225.     PUSH    HL
  226.     LD    E,0FFH        ; get console input
  227.     LD    C,6
  228.     CALL    BDOS
  229.     AND    A        ; will be nz if present
  230.     POP    HL
  231.     POP    BC
  232.     POP    DE
  233.     RET
  234.  
  235. ;--------------------------
  236.  
  237. VCOUT:
  238. ;console output with highlighting
  239.     CP    3        ;0,1, or 2?
  240.     JR    NC,COUT        ;use cout if not
  241.     OR    A        ;00?
  242.     RET    Z        ;don't even bother sending!
  243.     DEC    A        ;1? (^A) ?
  244.     JP    Z,STNDOUT    ;yep, start standout mode & ret
  245.     JP    STNDEND        ;else must be end of standout
  246.  
  247. ;--------------------------
  248.  
  249. COUT:
  250. ; COUT - console output using DOS function 6
  251. ;entry-    A = char to be output, 0-FCH
  252. ;exit-    char sent to console
  253. ;    AF and 8080 registers preserved
  254.  
  255.     OR    A
  256.     RET    Z    ;don't send nulls to console
  257.     PUSH    DE
  258.     PUSH    BC
  259.     PUSH    HL
  260.     PUSH    AF
  261.     res    7,a    ;don't send graphics!
  262.     CALL    TABS
  263.     LD    E,A
  264.     LD    C,6
  265.     CALL    NC,BDOS
  266.     POP    AF
  267.     POP    HL
  268.     POP    BC
  269.     POP    DE
  270.     RET
  271.  
  272. ;===========================================================
  273.  
  274. TABS:
  275. ;tabs routine to be called from cout
  276. ; NOTE: this routine does not account for
  277. ; BS and 7fh characters
  278.  
  279.     LD    HL,COLCNT    ;column counter (in ZCNFG)
  280.     LD    C,(HL)
  281.     CP    TAB
  282.     JR    Z,TABIFY
  283.     CP    CR
  284.     JR    NZ,TABS01
  285.     LD    C,0        ;CR resets column counter
  286.     JR    TABSX
  287.  
  288. TABS01:    CP    LF
  289.     JR    NZ,TABS02
  290.     INC    HL
  291.     INC    (HL)        ;increment line counter
  292.     DEC    HL
  293. TABS02:    CP    SPC        ;ret cy set for cntl chars
  294.     CCF            ;NC = current char is <spc
  295.     RET    NC        ;don't advance counter for cntl char
  296.     CCF            ;return NC so character will be output
  297.     INC    C        ;count the printing char
  298. TABSX:    LD    (HL),C        ;advance column counter
  299.     RET
  300.  
  301. TABIFY:
  302.     LD    A,C
  303.     CPL
  304.     AND    7
  305.     INC    A
  306.     LD    B,A
  307.  
  308. TABSL:    LD    E,SPC
  309.     LD    A,6
  310.     CALL    @BDOSA
  311.     INC    C
  312.     DJNZ    TABSL
  313.  
  314.     SCF            ;show tabs expanded
  315.     JR    TABSX
  316.  
  317. ;===========================================================
  318.  
  319. ;    COPY DELIMITED STRING (HL) TO (DE)
  320.  
  321. STRCPY:
  322. ; string is delimited by null, '$', or high bit set
  323. ; or by a char count in excess of the number passed
  324. ; in reg B. The special terminator in C is most
  325. ; likely a space that terminates a FN in an FCB.
  326. ;entry-    HL->string to copy
  327. ;    DE->destination
  328. ;    B = Max length of string
  329. ;    C = 0 or special terminator
  330. ;exit-    A = delimiter
  331. ;    B = unused locations in dest.
  332. ;    HL->delimiter
  333. ;    DE->next unwritten loc in dest.
  334. ; the delimiter is not copied.
  335.  
  336.     LD    A,(HL)
  337.     CP    '$'    ;delimiter?
  338.     RET    Z
  339.     OR    A,A    ;delimiter?
  340.     RET    Z
  341.     CP    C    ;named terminator?
  342.     RET    Z
  343.     BIT    7,A
  344.     JR    NZ,STRHBS
  345.     LD    (DE),A    ;transfer a byte
  346.     INC    HL
  347.     INC    DE
  348.     DJNZ    STRCPY
  349.     RET
  350.  
  351. STRHBS:    RES    7,A    ;reset high bit
  352.     LD    (DE),A    ;transfer last char
  353.     INC    DE    ;next dest
  354.     DEC    B    ;count the char
  355.     RET        ;ret hl->delimiting char
  356.  
  357. ;=================================================
  358.  
  359. ;    PRINT NULL TERMINATED STRING
  360.  
  361. TYPLIN:
  362.     EX    DE,HL
  363.     CALL    VPSTR
  364.     EX    DE,HL
  365.     RET
  366.  
  367. ;=========================================================
  368.  
  369. MOVE2Z:
  370. ;copy a null terminated string from (HL)
  371. ;to (DE). Don't copy the null. Ret HL->null
  372. ;entry-    HL -> source
  373. ;    DE -> destination
  374. ;exit-    AF = 0,Z,NC
  375. ;    BC,DE,HL used
  376.  
  377.     LD    A,(HL)
  378.     OR    A
  379.     RET    Z
  380.     LDI
  381.     JR    MOVE2Z
  382.  
  383. ;=========================================================
  384.  
  385. SKIP2Z:
  386. ;scan until binary zero.
  387. ;entry-    HL-> null or null terminated string
  388. ;exit-    AF = 0,Z,NC
  389. ;    HL-> byte following the 0.
  390.  
  391.     LD    A,(HL)
  392.     INC    HL
  393.     OR    A
  394.     JR    NZ,SKIP2Z
  395.     RET
  396.  
  397. ;=================================================
  398.  
  399. ISTXTF:
  400. ;scan a block of bytes for non-printable
  401. ;characters. The block is terminated by
  402. ;the byte in A or by the end-of-field.
  403. ;If A=-1, then only field length is used.
  404. ;entry-    HL->start of block
  405. ;     B = string field length
  406. ;     A = String terminator byte
  407. ;UCFLAG is bitmapped, 
  408. ;    B0 set = UC only
  409. ;    B7 set = ignore high bit
  410. ;exit-
  411. ;    HL preserved
  412. ; flags- Z,NC = all are printable
  413. ;     B = trailing unused bytes in field
  414. ;     C = bytes used by string, incl leading sp
  415. ;     D = leading spaces
  416. ;     E = String terminator byte
  417. ; flags- NZ,C = non printing char found
  418. ;    BC,DE undefined
  419.  
  420.     PUSH    HL
  421.     LD    E,A        ;save terminator
  422.     LD    C,0        ;string length counter
  423.     LD    D,C
  424. ISTXT1:    LD    A,(HL)
  425.     CP    SPC
  426.     JR    NZ,ISTXT2
  427.     INC    D        ;count leading spaces
  428.     INC    C        ; and total spc + str
  429.     INC    HL
  430.     DJNZ    ISTXT1
  431.     POP    HL
  432.     RET            ;string is all spaces
  433.  
  434. ISTXT2:    PUSH    DE        ;save leading space count
  435.     LD    A,(UCFLAG)
  436.     LD    D,A        ;UC only if -1
  437.  
  438. ISTXT3:
  439. ;    LD    A,(HL)
  440.     LD    A,D
  441.     AND    80H        ;isolate bit 7
  442.     CPL            ;make high bit mask
  443.     AND    (HL)        ;ignore high bit if D7 was 1,
  444.                 ;allowing HBS chars in string.
  445.  
  446.     CP    E        ;end of string?
  447.     JR    Z,ISTXTX
  448.     INC    HL
  449.  
  450.     CALL    ISPRINT        ;printable?
  451.     SCF            ;..in case not
  452.     JR    NZ,ISTXTX
  453. ;test for LC if bit 0 of UCFLAG = 1
  454.     BIT    0,D        ;NZ = CAPS ONLY
  455.     JR    Z,ISTXT4    ;Z = LC is OK
  456.     CP    61H        ;CAP?
  457.     JR    C,ISTXT4    ;Cy=yes, pass it
  458.     CP    '{'        ;also pass specials
  459.     JR    C,ISTXTX    ;LC is an error    
  460.  
  461. ISTXT4:    INC    C        ;count string bytes
  462.     DJNZ    ISTXT3
  463.     XOR    A        ;all printable
  464.  
  465. ISTXTX:    POP    DE        ;leading spaces in D
  466.     POP    HL
  467.     RET
  468.  
  469. ;=================================================
  470.  
  471. ISFNC:
  472. ;determines if a character is part of
  473. ;the set which defines a filename.
  474. ;This is all characters from "!" to "Z"
  475. ;except those listed in the table below.
  476. ;entry-    A = byte to test
  477. ;exit-    all regs preserved except F
  478. ;    NC = character may be part of FN
  479. ;     C = char is outside the set.
  480.  
  481.     cp    5bh
  482.     ccf
  483.     ret    c    ;C = >'Z'
  484.     cp    '!'
  485.     ret    c    ;C = < '!'
  486.     push    hl
  487.     push    bc
  488.     ld    hl,nfndat
  489.     ld    bc,nfndend-nfndat
  490.     cpir        ;CY unaffected, still reset
  491.     pop    bc
  492.     pop    hl
  493.     ret    nz    ;NZ = not in list
  494.     scf        ;show reject if found
  495.     ret
  496.  
  497. nfndat:    db    '%()*,./;:<>=?'
  498. nfndend:
  499.  
  500. ;=================================================
  501.  
  502. ;    OPEN FILE
  503.  
  504. OPNFIL:
  505. ;entry-    DE -> file FCB
  506. ;    user number at (DE-1)
  507. ;exit-    Z = file not found
  508.     DEC    DE
  509.     LD    A,(DE)
  510.     INC    DE
  511.     call    setusr
  512.     LD    A,15
  513.     CALL    @BDOSA
  514.     CP    255
  515.     JR    RESUSR
  516.  
  517. ;=================================================
  518.  
  519. ;    CLOSE FILE
  520. ;entry-    DE -> file FCB
  521. ;    user number at (DE-1)
  522.  
  523. CLSFIL:
  524.     LD    A,16
  525.     CALL    @BDOSA
  526.     INC    A
  527.     RET    NZ
  528.     LD    DE,CLOSER
  529.     JR    ERRORX
  530.  
  531. ;=================================================
  532.  
  533. SETUSR:
  534. ;set the user number to that passed in A
  535. ;if it is a number <255
  536.  
  537.     CP    0FFH    ;is default requested?
  538.     JP    NZ,SUA    ;jmp if user specified
  539. ;else fall through and set default user
  540.  
  541. ;=================================================
  542.  
  543. ;RESTORE THE DEFAULT USER NUMBER
  544.  
  545. RESUSR:    PUSH    AF
  546.     LD    A,(DEFDU)
  547.     CALL    SUA
  548.     POP    AF
  549.     RET
  550.  
  551. ;=================================================
  552. ;    READ ENTIRE FILE INTO DMA ADDRESS
  553.  
  554. ;entry-    DE -> FCB
  555. ;    HL =  DMA address
  556.  
  557. RDFILE:    LD    BC,128        ;sector size
  558. RDF_LP:    CALL    SETDMA
  559.     CALL    RDREC
  560.     RET    C        ;end of file
  561.     ADD    HL,BC
  562.     JR    RDF_LP
  563.  
  564. ;=================================================
  565.  
  566. ;    READ NEXT RECORD
  567.  
  568. RDREC:    LD    A,20
  569.     CALL    @BDOSA
  570.     RET    Z
  571.     CP    2        ;check for eof
  572.     RET    C
  573.  
  574.     OR    30H        ;make ascii
  575.     LD    (RDERRN),A
  576.     LD    DE,READER
  577.     JR    ERRORX
  578.  
  579. ;=================================================
  580.  
  581. ;    WRITE NEXT RECORD
  582.  
  583. WRREC:    LD    A,21
  584.     CALL    @BDOSA
  585.     RET    Z
  586.  
  587.     CP    1
  588.     JP    Z,DIRFUL
  589.     OR    30H        ;make ascii
  590.     LD    (WRERRN),A
  591.     LD    DE,WRITER
  592.     JR    ERRORX
  593.  
  594. ;=================================================
  595.  
  596. ;    DIRECTORY FULL ERROR ENTRY POINT
  597.  
  598. DIRFUL:    LD    DE,DIRER
  599. ERRORX:    CALL    TYPLIN
  600.     JP    QUIT
  601.  
  602. DIRER:    DB    'DIRECTORY FULL',0
  603. CLOSER:    DB    'CLOSE ERROR',0
  604. READER:    DB    CR,LF,'READ ERROR ='
  605. RDERRN:    DB    ' ',0
  606. WRITER:    DB    CR,LF,'WRITE ERROR ='
  607. WRERRN:    DB    ' ',0
  608.  
  609. ;=================================================
  610.  
  611.     END
  612.