home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / z3util / dev11a.lbr / DEV11A.ZZ0 / DEV11A.Z80
Encoding:
Text File  |  1993-06-07  |  11.9 KB  |  580 lines

  1. ;
  2. ;  PROGRAM:  DEV3
  3. ;  AUTHOR:  RICHARD CONN
  4. ;  VERSION:  1.0
  5. ;  DATE:  4 Apr 84
  6. ;  PREVIOUS VERSION:  None
  7. ;  DERIVATION:    DEVICE2 of ZCPR2
  8. ;
  9. VERS    EQU    11
  10. Z3ENV    DEFL    0FE00H
  11.  
  12. ; Version 1.1A strips high bits from EFCB characters in
  13. ; help screens.        Bruce Morgen    December 30, 1987
  14.  
  15. ; Version 1.1 modifications by Bruce Morgen, December 21, 1987:
  16. ; Made DEV respond to the WHEEL and QUIET bytes to make it a viable
  17. ; tool on an IOP-based RAS.  DEV now requires wheel powers to work
  18. ; at all.  With the quiet byte set, all display options are disabled
  19. ; while device assignment proceeds as per 1.0, but with no CON:
  20. ; output.  In combination with WHEEL 3.1 or later and T3RAS.IOP,
  21. ; this allows BYE.COM to be a VALIAS/SALIAS-style recursive alias.
  22. ; TERM3 supplies the other required tools, T3HANGUP and T3ANSWER.
  23. ; Implemented smarter help message using External FCB and QUIET byte,
  24. ; added Type 3 environment code.
  25. ;_______________________________________________________________
  26. ;
  27. ;    DEV is a program which enables the user to manipulate the
  28. ; extended ZCPR3 redirectable device drivers.  It allows the user to
  29. ; perform the following functions:
  30. ;
  31. ;        o Display the Names of the Current Devices
  32. ;        o Set One or More of the Current Devices
  33. ;        o Ask for Help
  34. ;
  35. ;    The format of the DEV command is:
  36. ;
  37. ;        DEV or DEV //            <-- Ask for Help
  38. ;        DEV command,command,command ... <-- Issue Commands
  39. ;
  40. ; where "command" may take the following forms:
  41. ;
  42. ;        DISPLAY ALL    <-- Display Names of All Devices
  43. ;        DISPLAY CON    <-- Display Names of Consoles
  44. ;        DISPLAY LST    <-- Display Names of Printers
  45. ;        DISPLAY RDR    <-- Display Names of Readers
  46. ;        DISPLAY PUN    <-- Display Names of Punches
  47. ;
  48. ;        CON:=name    <-- Select Console
  49. ;        LST:=name    <-- Select Printer
  50. ;        RDR:=name    <-- Select Reader
  51. ;        PUN:=name    <-- Select Punch
  52. ;
  53.  
  54. ;
  55. ;  Constants
  56. ;
  57. TBUFF    EQU    80H
  58. CR    EQU    0DH
  59. LF    EQU    0AH
  60.  
  61. ;
  62. ;  SYSLIB Routines
  63. ;
  64.     EXT Z3INIT,GETIOP
  65.     EXT CIN,COUT,PSTR,PRINT,CLINE,CRLF
  66.     EXT GETEFCB,GETWHL,GETQUIET,QPRINT
  67.  
  68. ;
  69. ; Environment Definition
  70. ;
  71.      IF    Z3ENV NE 0
  72. ;
  73. ; External ZCPR3 Environment Descriptor
  74. ;
  75.  
  76. ; TYPE 3 HEADER
  77.  
  78. ; Code modified as suggested by Charles Irvine to function correctly with
  79. ; interrupts enabled.  Program will abort with an error message when not
  80. ; loaded to the correct address (attempt to run it under CP/M or Z30).
  81.  
  82. ENTRY:
  83.     JR    STARTH            ; Must use relative jump
  84.     NOP                ; Filler
  85.     DB    'Z3ENV',3        ; Type-3 environment
  86. Z3EADR:
  87.     DW    Z3ENV            ; Filled in by Z33
  88.     DW    ENTRY            ; Intended load address
  89.  
  90. STARTH:
  91.     LD    HL,0            ; Point to warmboot entry
  92.     LD    A,(HL)            ; Save the byte there
  93.     DI                ; Protect against interrupts
  94.     LD    (HL),0C9H        ; Replace warmboot with a return opcode
  95.     RST    0            ; Call address 0, pushing RETADDR
  96.                     ; onto stack
  97. RETADDR:
  98.     LD    (HL),A            ; Restore byte at 0
  99.     DEC    SP            ; Get stack pointer to point
  100.     DEC    SP            ; To the value of RETADDR
  101.     POP    HL            ; Get it into HL and restore stack
  102.     EI                ; We can allow interrupts again
  103.     LD    DE,RETADDR        ; This is where we should be
  104.     XOR    A            ; Clear carry flag
  105.     PUSH    HL            ; Save address again
  106.     SBC    HL,DE            ; Subtract -- we should have 0 now
  107.     POP    HL            ; Restore value of RETADDR
  108.     JR    Z,START            ; If addresses matched, begin real code
  109.  
  110.     LD    DE,NOTZ33MSG-RETADDR    ; Offset to message
  111.     ADD    HL,DE
  112.     EX    DE,HL            ; Switch pointer to message into DE
  113.     LD    C,9
  114.     JP    0005H            ; Return via BDOS print string function
  115. NOTZ33MSG:
  116.     DB    'Not Z33+$'        ; Abort message if not Z33-compatible
  117.  
  118. START:
  119.     LD    HL,(Z3EADR)    ; Pt to ZCPR3 environment
  120. ;
  121.      ELSE
  122. ;
  123. ; Internal ZCPR3 Environment Descriptor
  124. ;
  125.     MACLIB Z3BASE.LIB
  126.     MACLIB SYSENV.LIB
  127. Z3EADR:
  128.     JP    START
  129.     SYSENV
  130. START:
  131.     LD    HL,Z3EADR    ; Pt to ZCPR3 environment
  132.      ENDIF
  133.  
  134. ;
  135. ; Start of Program -- Initialize ZCPR3 Environment
  136. ;
  137.     CALL    Z3INIT        ; Initialize the ZCPR3 Environment
  138.     CALL    GETWHL
  139.     JR    NZ,WHLOK
  140.     CALL    QPRINT
  141.     DB    'Wheel privileges required.',0
  142.     RET
  143. ;
  144. ;  Start of Program
  145. ;
  146.  
  147. WHLOK:    CALL    GETIOP        ; Check for initialization
  148.     LD    A,H
  149.     OR    L        ; Must NOT be zero
  150.     JR    NZ,START0
  151.     CALL    BANNER
  152.     CALL    PRINT
  153.     DB    CR,LF,'DEV NOT Initialized with I/O Base',0
  154. ABORT:
  155.     CALL    PRINT
  156.     DB    ' -- Aborting',0
  157.     RET
  158.  
  159. START0:
  160.     CALL    STATUS        ; Check for drivers
  161.     JR    NZ,START1
  162.     CALL    BANNER
  163.     CALL    PRINT
  164.     DB    CR,LF,'Redirection Not Supported',0
  165.     JR    ABORT
  166.  
  167. START1:
  168.     LD    HL,TBUFF    ; Pt to input buffer
  169.     CALL    CLINE        ; Extract and save command line
  170.     CALL    SBLANK        ; Skip to non-blank
  171.     OR    A        ; EOL?
  172.     JR    Z,HELP        ; Select help
  173.     CP    '/'        ; Help?
  174.     JP    NZ,DOCMD    ; Run command subroutine
  175.  
  176. ;
  177. ;  Print Help Message
  178. ;
  179. HELP:
  180.     CALL    BANNER
  181.     CALL    PRINT
  182.     DB    CR,LF,'DEV - Quick Redirectable I/O Device Selector'
  183.     DB    CR,LF,'Syntax:'
  184.     DB    CR,LF,'   ',0
  185.     CALL    COMNAM
  186.     CALL    PRINT
  187.     DB    ' or ',0
  188.     CALL    COMNAM
  189.     CALL    PRINT
  190.     DB    ' //             '
  191.     DB    '<-- Ask for Help'
  192.     DB    CR,LF,'   ',0
  193.     CALL    COMNAM
  194.     CALL    PRINT
  195.     DB    ' Command,Command, ...  '
  196.     DB    '<-- Issue Commands'
  197.     DB    CR,LF,'where "command" may take the following forms:'
  198.     DB    0
  199.     CALL    QPRINT        ; No display options if QUIET
  200.     DB    CR,LF,'  DISPLAY=ALL '
  201.     DB    '<-- Display All Devices'
  202.     DB    CR,LF,'  DISPLAY=CON '
  203.     DB    '<-- Display Consoles'
  204.     DB    CR,LF,'  DISPLAY=LST '
  205.     DB    '<-- Display Printers'
  206.     DB    CR,LF,'  DISPLAY=RDR '
  207.     DB    '<-- Display Readers'
  208.     DB    CR,LF,'  DISPLAY=PUN '
  209.     DB    '<-- Display Punches'
  210.     DB    CR,LF,0
  211.     CALL    PRINT
  212.     DB    CR,LF,'  CON:=name  <-- Select Console'
  213.     DB    CR,LF,'  LST:=name  <-- Select Printer'
  214.     DB    CR,LF,'  RDR:=name  <-- Select Reader'
  215.     DB    CR,LF,'  PUN:=name  <-- Select Punch'
  216.     DB    0
  217.     RET
  218. ;
  219. ; Print Banner
  220. ;
  221. BANNER:
  222.     CALL    PRINT
  223.     DB    'DEV, Version '
  224.     DB    [VERS/10]+'0','.',[VERS    MOD 10]+'0',0
  225.     RET
  226. ;
  227. ;  Skip to Non-Blank Routine
  228. ;
  229. SBLANK:
  230.     LD    A,(HL)        ; Get char
  231.     INC    HL        ; Pt to next
  232.     CP    ' '        ; Blank?
  233.     JR    Z,SBLANK    ; Continue if so
  234.     DEC    HL        ; Pt to non-blank
  235.     RET
  236.  
  237. ;
  238. ;  Skip until a delimiter encountered
  239. ;
  240. SDELM:
  241.     LD    A,(HL)        ; Get char
  242.     INC    HL        ; Pt to next
  243.     CP    ' '+1        ; <SP> or less?
  244.     RET    C
  245.     CP    '='
  246.     RET    Z
  247.     CP    ','
  248.     RET    Z
  249.     JR    SDELM
  250.  
  251. ;
  252. ;  DOCMD -- This subroutine processes the command line pted to by HL.
  253. ;    It is the Main Line if a DEVICE command line is given, it is just
  254. ;    a subroutine if the user is in interactive mode.
  255. ;
  256. DOCMD:
  257.     CALL    DOCMD1        ; Do first command
  258.     CALL    SDELM        ; Skip to delim
  259.     CP    ','        ; Another command?
  260.     JR    Z,DOCMD
  261.     RET
  262. DOCMD1:
  263.     LD    A,(HL)        ; Get command letter
  264.     CP    'D'        ; Display?
  265.     JR    NZ,NOTDIS
  266.     CALL    GETQUIET
  267.     JP    Z,DODISP
  268.     RET
  269. NOTDIS:    CP    'C'        ; Console assignment?
  270.     JR    Z,DOCON
  271.     CP    'L'        ; LST:?
  272.     JR    Z,DOLST
  273.     CP    'P'        ; PUN:?
  274.     JR    Z,DOPUN
  275.     CP    'R'        ; RDR:?
  276.     JR    Z,DORDR
  277. CERR:
  278.     CALL    PRINT
  279.     DB    CR,LF,'Error at -- ',0
  280.     CALL    PSTR        ; Print rest
  281.     RET
  282.  
  283. ;
  284. ;  Do LST: Assignment
  285. ;
  286. DOLST:
  287.     CALL    QPRINT
  288.     DB    ' LST:',0
  289.     LD    A,3        ; Select LST:
  290.     JR    ASSIGN
  291.  
  292. ;
  293. ;  Do PUN: Assignment
  294. ;
  295. DOPUN:
  296.     CALL    QPRINT
  297.     DB    ' PUN:',0
  298.     LD    A,2        ; Select PUN:
  299.     JR    ASSIGN
  300.  
  301. ;
  302. ;  Do RDR: Assignment
  303. ;
  304. DORDR:
  305.     CALL    QPRINT
  306.     DB    ' RDR:',0
  307.     LD    A,1        ; Select RDR:
  308.     JR    ASSIGN
  309.  
  310. ;
  311. ;  Do CON: Assignment
  312. ;
  313. DOCON:
  314.     CALL    QPRINT
  315.     DB    ' CON:',0
  316.     LD    A,0        ; Select console
  317. ;
  318. ;  Do Assignment in General
  319. ;
  320. ASSIGN:
  321.     LD    B,A        ; Save A in B
  322.     PUSH    BC        ; Save BC
  323.     CALL    SDELM        ; Skip to delimiter
  324.     POP    BC        ; Get BC
  325.     CP    ' '
  326.     JR    Z,ASGN0
  327.     CP    '='
  328.     JR    NZ,CERR
  329. ASGN0:
  330.     LD    A,B        ; Get A back
  331.     LD    (LOGICAL),A    ; Save logical device number
  332.     LD    (NAME),HL    ; Save ptr to mnemonic
  333.     LD    B,A        ; Number in B
  334.     INC    B        ; Add 1 for offset
  335.     CALL    STATUS        ; Get device status
  336.     DEC    HL        ; Pt to previous
  337.     DEC    HL
  338. ASGN1:
  339.     INC    HL        ; Pt to next
  340.     INC    HL
  341.     DJNZ    ASGN1        ; Count down
  342.     LD    C,(HL)        ; Get number of devices in C
  343.     LD    A,C        ; Check for value of zero
  344.     OR    A
  345.     JR    NZ,ASGN2
  346.     LD    HL,(NAME)    ; Pt to error name
  347.     JR    CERR
  348. ASGN2:
  349.     LD    A,(LOGICAL)    ; Get logical device number
  350.     LD    B,A        ; ... in B
  351.     PUSH    BC        ; Save device count
  352.     DEC    C        ; Pt to previous
  353.     CALL    NAMER        ; Get name
  354.     EX    DE,HL        ; Name pted to by DE
  355.     LD    HL,(NAME)    ; User's name pted to by HL
  356. ASGN3:
  357.     LD    A,(DE)        ; Get name of device
  358.     CP    ' '+1        ; Done?
  359.     JR    C,ASGN3A
  360.     CP    (HL)        ; Compare to user
  361.     JR    NZ,ASGN4
  362.     INC    HL        ; Pt to next
  363.     INC    DE
  364.     JR    ASGN3
  365. ASGN3A:
  366.     LD    A,(HL)        ; Get user
  367.     CP    ' '+1        ; Done?
  368.     JR    C,ASGN3B
  369.     CP    ','        ; Done?
  370.     JR    NZ,ASGN4
  371. ASGN3B:
  372.     POP    BC        ; Match -- C-1 is selected device
  373.     DEC    C        ; Decrement
  374.     CALL    SELECT        ; Select device
  375.     CALL    GETQUIET
  376.     LD    A,(LOGICAL)    ; Get logical device in A
  377.     CALL    Z,CURRENT    ; Print name of device selected
  378.     LD    HL,(NAME)    ; Pt to name for scan continuation
  379.     RET
  380. ASGN4:
  381.     POP    BC        ; Count down
  382.     DEC    C        ; Count down
  383.     JR    NZ,ASGN2    ; Continue
  384.     LD    HL,(NAME)    ; Pt to invalid name
  385.     CALL    PRINT
  386.     DB    CR,LF,' Invalid Name at -- ',0
  387.     CALL    PSTR
  388.     LD    HL,(NAME)    ; Pt to name for scan continuation
  389.     RET
  390.  
  391. ;
  392. ;  Display Devices and Assignments
  393. ;
  394. DODISP:
  395.     CALL    SDELM        ; Skip to delimiter
  396.     OR    A        ; None=all
  397.     JR    Z,DISPALL
  398.     LD    A,(HL)        ; Get char after delimiter
  399.     CP    'A'        ; All?
  400.     JR    Z,DISPALL
  401.     CP    'C'        ; CON:
  402.     JR    Z,DISPCON
  403.     CP    'L'        ; LST:
  404.     JR    Z,DISPLST
  405.     CP    'P'        ; PUN:
  406.     JR    Z,DISPPUN
  407.     CP    'R'        ; RDR:
  408.     JR    Z,DISPRDR
  409.     JP    CERR
  410. DISPALL:
  411.     CALL    DISPCON        ; Successive displays
  412.     CALL    DISPRDR
  413.     CALL    PRINT
  414.     DB    CR,LF,'Strike Any Key -- ',0
  415.     CALL    CIN
  416.     CALL    DISPPUN
  417.     JR    DISPLST
  418. DISPCON:
  419.     CALL    PRINT
  420.     DB    CR,LF,'CON:',0
  421.     LD    A,0        ; Select CON:
  422.     CALL    DISP
  423.     JR    CURR
  424. DISPLST:
  425.     CALL    PRINT
  426.     DB    CR,LF,'LST:',0
  427.     LD    A,3        ; Select LST:
  428.     CALL    DISP
  429.     JR    CURR
  430. DISPRDR:
  431.     CALL    PRINT
  432.     DB    CR,LF,'RDR:',0
  433.     LD    A,1        ; Select RDR:
  434.     CALL    DISP
  435.     JR    CURR
  436. DISPPUN:
  437.     CALL    PRINT
  438.     DB    CR,LF,'PUN:',0
  439.     LD    A,2        ; Select PUN:
  440.     CALL    DISP
  441. ;
  442. ;  Print Name of Current Device
  443. ;
  444. CURR:
  445.     CALL    CRLF        ; New line
  446. CURRENT:
  447.     PUSH    HL        ; Save ptr
  448.     LD    B,A        ; Save number in B
  449.     PUSH    BC        ; Save B
  450.     CALL    PRINT
  451.     DB    ' Assignment is ',0
  452.     PUSH    BC        ; Save B
  453.     CALL    STATUS        ; Get status
  454.     POP    BC        ; Get B
  455.     INC    B        ; Add 1 for offset
  456.     DEC    HL        ; Back up
  457. CURR1:
  458.     INC    HL        ; Pt to next
  459.     INC    HL
  460.     DJNZ    CURR1        ; Count down
  461.     POP    BC        ; Get logical number in B
  462.     LD    C,(HL)        ; Get physical number in C
  463.     CALL    PNAME0        ; Print first part of name only
  464.     POP    HL        ; Get ptr
  465.     RET
  466. ;
  467. ;  Print Names of All Physical Devices for a Logical Device
  468. ;
  469. DISP:
  470.     PUSH    HL        ; Save char ptr
  471.     PUSH    AF        ; Save device number
  472.     CALL    PRINT
  473.     DB    ' Devices --',0
  474.     LD    B,A        ; Logical device in B
  475.     PUSH    BC        ; Save for later
  476.     PUSH    BC        ; Save it
  477.     CALL    STATUS        ; Get status report
  478.     POP    BC        ; Get logical device number
  479.     INC    B        ; Add 1 for offset
  480.     DEC    HL        ; Back up
  481.     DEC    HL
  482. DISP1:
  483.     INC    HL        ; Pt to next
  484.     INC    HL
  485.     DJNZ    DISP1        ; Count down
  486.     POP    BC        ; Get B back
  487.     LD    C,(HL)        ; Get count of devices
  488.     LD    A,C        ; Check for none
  489.     OR    A
  490.     JR    Z,DISP3
  491. DISP2:
  492.     PUSH    BC        ; Save values
  493.     DEC    C        ; Pt to next name
  494.     CALL    PRINT
  495.     DB    CR,LF,'    ',0
  496.     CALL    PNAMER        ; Print name (B=logical, C=physical)
  497.     POP    BC        ; Get count
  498.     DEC    C        ; Count down
  499.     JR    NZ,DISP2
  500. DISP3:
  501.     POP    AF
  502.     POP    HL
  503.     RET
  504. ;
  505. ;  Routine to Print Name of Selected Device
  506. ;    B=logical number, C=physical number
  507. ;
  508. PNAMER:
  509.     PUSH    BC        ; Save BC
  510.     CALL    PNAME0        ; Print first part of name
  511.     CALL    PRINT        ; Print separator
  512.     DB    ' - ',0
  513.     CALL    PSTR        ; Print rest as string
  514.     POP    BC        ; Restore BC
  515.     RET
  516. ;
  517. ;  Print first part of selected device name
  518. ;
  519. PNAME0:
  520.     CALL    NAMER        ; Get ptr to string
  521.     LD    B,8        ; At most 8 chars
  522. PNAME1:
  523.     LD    A,(HL)        ; Get char
  524.     INC    HL        ; Pt to next char
  525.     CP    ' '        ; End of name?
  526.     JR    Z,PNAME2
  527.     CALL    COUT        ; Print char
  528.     DJNZ    PNAME1        ; Count down
  529.     RET
  530. PNAME2:
  531.     LD    A,' '        ; Print spaces
  532.     CALL    COUT
  533.     DJNZ    PNAME2        ; Count down
  534.     RET
  535.  
  536. ;
  537. ;  Basic Interface Routines
  538. ;
  539. STATUS:
  540.     LD    DE,0        ; Offset 0
  541. RUNIT:
  542.     CALL    GETIOP        ; Device driver base
  543.     ADD    HL,DE
  544.     JP    (HL)
  545. SELECT:
  546.     LD    DE,3        ; Offset 3
  547.     JR    RUNIT
  548. NAMER:
  549.     LD    DE,6        ; Offset 6
  550.     JR    RUNIT
  551. ;
  552. ; Print actual COMfile name if possible, otherwise print "DEV"
  553. ;
  554. COMNAM:
  555.     CALL    GETEFCB
  556.     JR    Z,NOEFCB
  557.     LD    B,8
  558. COMNLP:    INC    HL
  559.     LD    A,(HL)
  560.     AND    7FH
  561.     CP    ' '
  562.     CALL    NZ,COUT
  563.     DJNZ    COMNLP
  564.     RET
  565. NOEFCB:    CALL    PRINT
  566.     DB    'DEV',0
  567.     RET
  568.  
  569.  
  570.     DSEG
  571. ;
  572. ;  Buffers
  573. ;
  574. LOGICAL:
  575.     DS    1        ; Logical Device Number
  576. NAME:
  577.     DS    2        ; Pointer to User-Supplied Name
  578.  
  579.     END
  580.