home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / zsys / simtel20 / install / z3ins.mac < prev    next >
Encoding:
Text File  |  1994-07-13  |  10.5 KB  |  528 lines

  1. ;
  2. ; Program:  Z3INS
  3. ; Author:  Richard Conn
  4. ; Version:  1.2
  5. ; Date:  9 January 1985
  6. ; Previous Versions:  1.0 11 June 84, 1.1 1 Dec 84
  7. ;
  8. VERS    EQU    12        ; Four times faster.. jww
  9. Z3ENV    SET    0F400H
  10.  
  11. ;
  12. ;    The purpose of Z3INS is to install a group of ZCPR3 System Utilities.
  13. ; Z3INS reads in an Environment Descriptor and then reads in a file containing
  14. ; the names of the utilities to be installed.  It then reads in each file named
  15. ; and installs the proper values into it.
  16. ;
  17. ;    Syntax:
  18. ;        Z3INS Envfile.typ Install.typ
  19. ;    Default File Types:
  20. ;        Envfile - ENV
  21. ;        Install - INS
  22. ;
  23. ;    Added the ability to install one program if the "Install" type
  24. ;    is "COM".
  25. ;
  26. ;  Customization
  27. ;    Number of Blocks to Read/Write Per File Access
  28. ;
  29. NBLKS    EQU    16        ; Must be even (8=1K, 16=2K, etc)
  30.  
  31. ;
  32. ;  Library Utilities
  33. ;
  34.     EXT    Z3INIT
  35.     EXT    FNAME
  36.     EXT    F$OPEN,F$CLOSE,F$READ,F$WRITE,INITFCB
  37.     EXT    EPRINT,PFN1,CRLF,COUT
  38.     EXT    MOVEB,SKSP
  39.     EXT    CODEND
  40.  
  41. ;
  42. ;  System Equates
  43. ;
  44. BASE    EQU    0        ; Base address of system
  45. BDOS    EQU    BASE+05H
  46. FCB    EQU    BASE+5CH
  47. FCB2    EQU    BASE+6CH
  48. TBUFF    EQU    BASE+80H
  49. TAB    EQU    09H
  50. CR    EQU    0DH
  51. LF    EQU    0AH
  52. CTRLZ    EQU    'Z'-'@'        ; EOF mark
  53.  
  54. ;
  55. ; Environment Definition
  56. ;
  57.      IF    Z3ENV NE 0
  58. ;
  59. ; External ZCPR3 Environment Descriptor
  60. ;
  61.     JMP    START
  62.     DB    'Z3ENV'        ; This is a ZCPR3 Utility
  63.     DB    1        ; External Environment Descriptor
  64. Z3EADR:
  65.     DW    Z3ENV
  66. START:
  67.     LHLD    Z3EADR        ; Pt to ZCPR3 environment
  68. ;
  69.      ELSE
  70. ;
  71. ; Internal ZCPR3 Environment Descriptor
  72. ;
  73.     MACLIB    Z3BASE.LIB
  74.     MACLIB    SYSENV.LIB
  75. Z3EADR:
  76.     JMP    START
  77.     SYSENV
  78. START:
  79.     LXI    H,Z3EADR    ; Pt to ZCPR3 environment
  80.      ENDIF
  81.  
  82. ;
  83. ; Start of Program -- Initialize ZCPR3 Environment
  84. ;
  85.     CALL    Z3INIT        ; Initialize the ZCPR3 Env and the VLIB Env
  86. ;
  87. ; Print Name
  88. ;
  89.     CALL    EPRINT
  90.     DB    'Z3INS  Version '
  91.     DB    (VERS/10)+'0','.',(VERS    MOD 10)+'0',0
  92. ;
  93. ; Check for file names
  94. ;
  95.     LDA    FCB+1        ; Get first char
  96.     CPI    '/'        ; Print help
  97.     JZ    HELP
  98.     CPI    ' '
  99.     JNZ    FN2
  100. ;
  101. ; Print Help Message
  102. ;
  103. HELP:
  104.     CALL    EPRINT
  105.     DB    CR,LF,'Syntax:'
  106.     DB    CR,LF,'  Z3INS envfile.ENV insfile.INS or'
  107.     DB    CR,LF,'  Z3INS envfile.ENV program.com'
  108.     DB    0
  109.     RET
  110. ;
  111. ; Continue file name check
  112. ;
  113. FN2:
  114.     LDA    FCB2+1
  115.     CPI    ' '        ; Print help if none
  116.     JZ    HELP
  117. ;
  118. ; Set Default File Types
  119. ;
  120.     LXI    D,FCB+9        ; Pt to file type
  121.     LXI    H,DEFENV    ; Pt to default
  122.     CALL    SETTYP
  123.     LXI    D,FCB2+9    ; Pt to file type
  124.     LXI    H,DEFINS    ; Pt to default
  125.     CALL    SETTYP
  126.     LXI    H,FCB2        ; Save 2nd FCB
  127.     LXI    D,INFILE
  128.     MVI    B,16        ; 16 bytes
  129.     CALL    MOVEB
  130. ;
  131. ; Load Environment Descriptor
  132. ;
  133.     LXI    D,FCB        ; Pt to FCB
  134.     CALL    INITFCB
  135.     CALL    F$OPEN        ; Open file
  136.     JZ    LOADENV
  137. ;
  138. ; Print File Not Found Message
  139. ;    DE pts to FCB
  140. ;
  141. PRFNF:
  142.     CALL    EPRINT
  143.     DB    CR,LF,'** File ',0
  144.     LXI    D,FCB+1        ; Pt to file name
  145.     CALL    PFN1
  146.     CALL    EPRINT
  147.     DB    ' NOT Found',0
  148.     RET
  149. ;
  150. ; Load Environment Descriptor
  151. ;
  152. LOADENV:
  153.     CALL    CODEND        ; Pt to free space
  154.     CALL    LOAD        ; Load in file
  155.     SHLD    FLIST        ; Save ptr to file list
  156.     XCHG            ; In DE also
  157.     CALL    CODEND        ; Check for proper amount
  158.     MOV    A,D
  159.     SUB    H
  160.     CPI    1        ; Must be 1 page
  161.     JZ    LOADE1
  162. ENVERR:
  163.     CALL    EPRINT
  164.     DB    CR,LF,'** Invalid Environment Descriptor',0
  165.     RET
  166. LOADE1:
  167.     MOV    A,L        ; Low must be same
  168.     SUB    E
  169.     JNZ    ENVERR
  170.     LXI    D,FCB        ; Close environment descriptor
  171.     CALL    F$CLOSE
  172. ;
  173. ;  Load File List
  174. ;
  175.     LXI    H,INFILE    ; Copy into FCB
  176.     LXI    D,FCB
  177.     MVI    B,16
  178.     CALL    MOVEB
  179.  
  180. ; start changes here (Vers 1.1)
  181.  
  182.     LXI    H,FCB+9        ; Point to install file type
  183.     LXI    D,COMNAME    ; File type for single Install
  184.     MVI    B,3        ; Character loop count
  185. COMLP:
  186.     LDAX    D        ; Next character for file type
  187.     CMP    M        ; Next install file type char
  188.     JNZ    MULT        ; Match failed - install multiple
  189.     INX    H
  190.     INX    D
  191.     DCR    B
  192.     JNZ    COMLP        ; Loop for all chars
  193.  
  194.     LXI    H,ZZ        ; Point to EOF character
  195.     SHLD    NXTCHR        ; To stop install procedure
  196.     LHLD    FLIST        ; Get next avail free storage loc
  197.     SHLD    FREE        ; Place to load installed program
  198.     JMP    SINGLE        ; Process just a single program
  199.  
  200. ; stop changes here (Vers 1.1)
  201.  
  202. MULT:    LXI    D,FCB        ; Init FCB
  203.     CALL    INITFCB
  204.     CALL    F$OPEN        ; Open file
  205.     JNZ    PRFNF        ; File not found
  206.     LHLD    FLIST        ; Pt to buffer
  207.     CALL    LOAD        ; Load file
  208.     MVI    M,CTRLZ        ; Ensure EOF mark
  209. ZZ    EQU    $-1        ; Point to a convenient CTRL-Z (Vers 1.1)
  210.     SHLD    FREE        ; Set ptr to free space
  211.     XCHG            ; Ptr in DE
  212.     LHLD    BDOS+1        ; Get address of top of TPA
  213.     MOV    A,H        ; Adjust for CPR
  214.     SUI    10
  215.     SUB    D        ; See how many pages left
  216.     CPI    NBLKS/2        ; Must be at least N/2 pages
  217.     JNC    FUNCTION    ; Perform function if OK
  218.     CALL    EPRINT
  219.     DB    CR,LF,'** Not Enough Free Memory for Installation'
  220.     DB    CR,LF,'   Make Installation File Shorter',0
  221.     RET
  222. ;
  223. ; Perform Installation Function
  224. ;
  225. FUNCTION:
  226.     LHLD    FLIST        ; Pt to file list
  227.     PUSH    H        ; Save ptr
  228. ;
  229. ; Set all MSBs to Zero
  230. ;
  231. CLEAN:
  232.     MOV    A,M        ; Clear MSB
  233.     ANI    7FH
  234.     MOV    M,A
  235.     INX    H        ; Pt to next
  236.     CPI    CTRLZ        ; Done?
  237.     JNZ    CLEAN
  238.     POP    H        ; Pt to first line
  239. ;
  240. ; Process Next Line
  241. ;
  242. FCTNXT:
  243.     CALL    SKSP        ; Skip over leading spaces
  244.     SHLD    NXTCHR        ; Set ptr to next char
  245.     MOV    A,M        ; Get char
  246.     CPI    ';'        ; Comment?
  247.     JZ    FCTCMT        ; Process comment line
  248.     CPI    CTRLZ        ; Done?
  249.     JZ    DONE
  250.     LXI    D,FCB        ; Pt to FCB
  251.     CALL    FNAME        ; Process file name
  252. ;
  253. ; Check for Non-Ambiguous File Name
  254. ;
  255. SINGLE:                ; Entry point to install a single program
  256.     LXI    H,FCB+1        ; Pt to file name
  257.     MVI    B,11        ; 11 chars
  258. FCTAMB:
  259.     MOV    A,M        ; Check it
  260.     CPI    '?'
  261.     JZ    AMBERR
  262.     INX    H        ; Pt to next
  263.     DCR    B        ; Count down
  264.     JNZ    FCTAMB
  265.     LXI    D,FCB        ; Init FCB and open file
  266.     CALL    INITFCB
  267.     CALL    F$OPEN
  268.     JZ    FCTPRE        ; If ok, process preamble
  269.     CALL    PRFNF        ; Print file not found
  270. ;
  271. ; Continue with Next Line
  272. ;
  273. FCTCONT:
  274.     LHLD    NXTCHR        ; Pt to next char
  275. FCTC1:
  276.     MOV    A,M        ; Skip to after LF or EOF
  277.     INX    H
  278.     CPI    LF
  279.     JZ    FCTNXT        ; Continue
  280.     CPI    CTRLZ        ; Done?
  281.     JNZ    FCTC1
  282.     RET
  283. ;
  284. ; Print Ambiguous File Name Error
  285. ;
  286. AMBERR:
  287.     CALL    EPRINT
  288.     DB    CR,LF,'** Ambiguous File Name Not Allowed: ',0
  289.     LXI    D,FCB+1        ; Pt to file name
  290.     CALL    PFN1
  291.     JMP    FCTCONT        ; Continue
  292. ;
  293. ; Process Comment Line
  294. ;
  295. FCTCMT:
  296.     CALL    CRLF        ; New line
  297.     MVI    C,1        ; Set tab count
  298. FCTCMT1:
  299.     MOV    A,M        ; Get char
  300.     INX    H        ; Pt to next
  301.     CPI    TAB        ; Tabulate?
  302.     JZ    FCTCMT2
  303.     CPI    CR        ; Done?
  304.     JZ    FCTCONT
  305.     CPI    LF        ; Done?
  306.     JZ    FCTCONT
  307.     CPI    CTRLZ        ; Done?
  308.     JZ    FCTCONT
  309.     CPI    ' '        ; Don't advance if less than space
  310.     JC    FCTCMT1
  311.     INR    C        ; Add 1 to col pos
  312.     CALL    COUT        ; Print
  313.     JMP    FCTCMT1        ; Resume
  314. FCTCMT2:
  315.     MVI    A,' '        ; Space over
  316.     CALL    COUT
  317.     INR    C        ; Increment location
  318.     MOV    A,C
  319.     ANI    7        ; Check for every 8
  320.     JNZ    FCTCMT2
  321.     JMP    FCTCMT1        ; Resume
  322. ;
  323. ; Process Preamble
  324. ;
  325. FCTPRE:
  326.     CALL    EPRINT
  327.     DB    CR,LF,'** Installing File ',0
  328.     LXI    D,FCB+1        ; Pt to file name
  329.     CALL    PFN1
  330.     LHLD    FREE        ; Pt to free area
  331.     MVI    B,2        ; Number of blocks to load
  332.     CALL    LOADN        ; Load them
  333.     MOV    A,C        ; How many blocks loaded?
  334.     CPI    2        ; Must be 2
  335.     JZ    FCTPRE1
  336. ;
  337. ; Not a ZCPR3 Utility
  338. ;
  339. NOTZ3:
  340.     CALL    EPRINT
  341.     DB    ' -- NOT a ZCPR3 Utility',0
  342.     JMP    FCTCONT
  343. ;
  344. ; Ensure we have a Z3 utility
  345. ;
  346. FCTPRE1:
  347.     LHLD    FREE        ; Pt to first byte
  348.     MOV    A,M        ; Get it
  349.     CPI    0C3H        ; Must be a JMP
  350.     JNZ    NOTZ3
  351.     INX    H        ; Pt to next key area
  352.     INX    H
  353.     INX    H
  354.     LXI    D,ENVNAM    ; Pt to environment name
  355.     MVI    B,5        ; 5 chars
  356. FCTPRE2:
  357.     LDAX    D        ; Get name char
  358.     CMP    M        ; Check
  359.     JNZ    NOTZ3
  360.     INX    H        ; Pt to next
  361.     INX    D
  362.     DCR    B        ; Count down
  363.     JNZ    FCTPRE2
  364.     MOV    A,M        ; Get class
  365.     PUSH    PSW
  366.     INX    H        ; Pt to first byte
  367.     XCHG            ; DE pts to next byte
  368.     CALL    CODEND        ; Pt to environment descriptor
  369.     POP    PSW
  370.     CPI    1        ; Class 1 (external) or 2 (internal)?
  371.     JZ    CLASS1
  372. ;
  373. ; Environment Descriptor is Internal
  374. ;    HL pts to Environment Descriptor and DE pts to next byte
  375. ;
  376.     LXI    B,3+5+1        ; Skip to first valid byte
  377.     DAD    B
  378.     MVI    A,0        ; Compute number of bytes to copy
  379.     SUB    C
  380.     MOV    B,A        ; Result in B
  381.     CALL    MOVEB        ; Copy into buffer
  382.     JMP    FCTPRE3        ; Complete preamble processing
  383. ;
  384. ; Environment Descriptor is External
  385. ;    HL pts to Environment Descriptor and DE pts to next byte
  386. ;
  387. CLASS1:
  388.     LXI    B,1BH        ; Offset to environment descriptor address
  389.     DAD    B
  390.     MOV    A,M        ; Get address
  391.     STAX    D        ; Store it
  392.     INX    H        ; Pt to next
  393.     INX    D
  394.     MOV    A,M        ; Get high
  395.     STAX    D        ; Store it
  396. ;
  397. ; Complete Preamble Processing
  398. ;  Write the new preamble directly to the target file (Vers 1.2)
  399. ;
  400. FCTPRE3:
  401.     XRA    A
  402.     STA    FCB+32        ; Set current record to zero
  403.     LXI    B,2        ; Record count
  404.     LHLD    FREE        ; Start at the beginning
  405.     CALL    WRITEN        ; Write 2 records
  406.     MOV    A,C
  407.     ORA    A        ; Check that 2 records were written
  408.     JNZ    PRFWE        ; Report error and exit, if not.
  409.     LXI    D,FCB        ; Point to current FCB
  410.     CALL    F$CLOSE        ; Close the file
  411.     JMP    FCTCONT        ; Get the next one
  412. ;
  413. ; File Write Error
  414. ;
  415. PRFWE:
  416.     CALL    EPRINT
  417.     DB    CR,LF,'** File Write Error',0
  418.     RET
  419. ;
  420. ; Set File Type Pted to by HL into DE if (DE)=' '
  421. ;
  422. SETTYP:
  423.     LDAX    D        ; Get dest byte
  424.     CPI    ' '
  425.     RNZ            ; Already has type
  426.     MVI    B,3        ; Copy
  427.     JMP    MOVEB
  428. ;
  429. ; Load File Specified in FCB into Memory Starting at HL
  430. ;    Check for Overflow
  431. ;
  432. LOAD:
  433.     PUSH    H        ; Save address of next block
  434.     LHLD    BDOS+1        ; Check for overflow
  435.     XCHG
  436.     POP    H        ; Get address of next block
  437.     MOV    A,D
  438.     SUI    10        ; Adjust for CPR
  439.     SUB    H
  440.     JNZ    LOAD1
  441.     CALL    EPRINT
  442.     DB    CR,LF,'** Memory Overflow',0
  443.     POP    PSW        ; Clear stack
  444.     RET
  445. ;
  446. ; Load next block - HL pts to location
  447. ;
  448. LOAD1:
  449.     LXI    D,FCB        ; Pt to FCB
  450.     CALL    F$READ        ; Read next block
  451.     RNZ            ; Done if EOF
  452.     LXI    D,TBUFF        ; Pt to buffer area
  453.     XCHG            ; Flip source and dest
  454.     MVI    B,128        ; 128 bytes
  455.     CALL    MOVEB
  456.     LXI    H,128        ; Pt to next
  457.     DAD    D
  458.     JMP    LOAD        ; Continue
  459. ;
  460. ; Load B blocks into Memory Pted to by HL
  461. ;  Return count in C
  462. ;
  463. LOADN:
  464.     MVI    C,0        ; Set count
  465. LOADN1:
  466.     LXI    D,FCB        ; Pt to fcb
  467.     CALL    F$READ        ; Read next block
  468.     RNZ            ; Done if EOF
  469.     INR    C        ; Increment count
  470.     PUSH    B        ; Save BC
  471.     LXI    D,TBUFF        ; Pt to buffer area
  472.     XCHG            ; Flip source and dest
  473.     MVI    B,128        ; 128 bytes
  474.     CALL    MOVEB
  475.     LXI    H,128        ; Pt to next
  476.     DAD    D
  477.     POP    B        ; Restore BC
  478.     DCR    B        ; Count down
  479.     JNZ    LOADN1
  480.     RET
  481. ;
  482. ; Store C blocks from Memory Pted to by HL
  483. ;
  484. WRITEN:
  485.     PUSH    B        ; Save count
  486.     LXI    D,TBUFF        ; Copy into TBUFF
  487.     MVI    B,128        ; 128 bytes
  488.     CALL    MOVEB
  489.     LXI    B,128        ; Pt to next
  490.     DAD    B
  491.     POP    B        ; Get count
  492.     LXI    D,FCB        ; Pt to fcb
  493.     CALL    F$WRITE        ; Write next block
  494.     RNZ            ; Done if EOF
  495.     DCR    C        ; Decrement count
  496.     JNZ    WRITEN
  497.     RET
  498.  
  499. ;
  500. ; Write Completion Message
  501. ;
  502. DONE:
  503.     CALL    EPRINT
  504.     DB    CR,LF,'** Installation Complete **',0
  505.     RET
  506.  
  507. ;
  508. ; Buffers
  509. ;
  510. COMNAME:
  511.     DB    'COM'        ; File type for COM file
  512. DEFENV:
  513.     DB    'ENV'        ; Default file type for Environment Descriptor
  514. DEFINS:
  515.     DB    'INS'        ; Default file type for Installation File
  516. INFILE:
  517.     DS    16        ; FCB save area
  518. FLIST:
  519.     DS    2        ; Address of file list
  520. FREE:
  521.     DS    2        ; Address of scratch area to read into
  522. NXTCHR:
  523.     DS    2        ; Ptr to next char to process
  524. ENVNAM:
  525.     DB    'Z3ENV'        ; Environment Descriptor ID
  526.  
  527.     END
  528.