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 / CPM / ZCPR33 / A-R / LDR16.LBR / LDR16.ZZ0 / LDR16.Z80
Text File  |  2000-06-30  |  17KB  |  783 lines

  1. ;  PROGRAM:  LDR
  2. ;  AUTHOR:  RICHARD CONN
  3. ;  VERSION:  1.0
  4. ;  DATE:  27 FEB 84
  5. ;  PREVIOUS VERSIONS:  0.1 (3 Feb 84), 0.2 (22 Feb 84), 1.1 (28 Sep 84)
  6. ;
  7. ;    8080 code for z80asm
  8. ;
  9. VERSION        EQU    16    ; Use LBR files
  10.                 ; Idea -- Jay Sage
  11.                 ; Implementation -- Paul Pomerleau -- 3/6/87
  12.  
  13. ;VERSION    EQU    15    ; Search the path for file to load.
  14.                 ; Joe Wright  2 June 86
  15. ;
  16. ;VERSION    EQU    14    ; V1.4 by steve a. kitahata -- 17-mar-86
  17.  
  18.                 ; This version modified to correct problem in
  19.                 ; The 'load:' routine when loading a package
  20.                 ; That is too large, specifically the tcap.
  21.                 ; Previous versions cleared the first 128 bytes
  22.                 ; Of the memory buffer, and appended a 3-byte
  23.                 ; Error code routine, resulting in whatever
  24.                 ; Resided after the tcap buffer to be zapped.
  25.  
  26. ;version    equ    13    ; This version responds to the quiet flag.
  27.                 ; 11 march 85  joe wright
  28.  
  29. ;VERSION    EQU    12    ; Version 1.2 by Dave Lucky  31 Dec 84
  30.  
  31.                 ; This version modified to correct exit regs from
  32.                 ; Sdload subroutine.  the source and destination
  33.                 ; Registers on entry were hl and de, respectively.
  34.                 ; On exit, they were de and hl.  the calling routine
  35.                 ; (setdata) went amuck when calculating number of ndr
  36.                 ; Records using bogus de.  also, corrected the setdata
  37.                 ; Routine from using the incorrect address of the ndr
  38.                 ; Entry size field as well as its contents acquired
  39.                 ; From the getndr routine.
  40.  
  41. ;VERSION    EQU    11    ; Version 1.1 by Joe Wright  28 Sept 84
  42.  
  43.                 ; This version modified to allow loading the .env
  44.                 ; File the first time, when there is no environment
  45.                 ; Descriptor in memory.  the program now takes
  46.                 ; The environment address from the .env file so
  47.                 ; That subsequent files are also loaded correctly.
  48.                 ; Ie. ldr sys.env,sys.rcp,etc.    note that .env must
  49.                 ; Be the first declared file until ldr is installed
  50.                 ; To your environment.    jww
  51.  
  52. ;VERSION    EQU    10    ; Release version
  53.  
  54. EXTENV    EQU    1        ; 1 for external environ, 0 for internal environ
  55.  
  56. ;
  57. ;    LDR is a general-purpose package loader for ZCPR3.  It is
  58. ; invoked by the following form:
  59. ;
  60. ;        LDR <list of packages>
  61. ;
  62. ; For example:
  63. ;        LDR DEFAULT.RCP,SYSIO.IOP
  64. ;
  65. ;    No default file types are assumed on the list of packages, and
  66. ; each package specified must be unambigous and have a type of RCP or IOP
  67. ; (for Resident Command Package or Input/Output Package).  LDR
  68. ; checks to make sure that the files are valid packages and then loads
  69. ; them into memory at the correct locations, checking for package boundary
  70. ; overflow.
  71. ;
  72. ;
  73.  
  74. ;
  75. ;  ZCPR3 Header
  76. ;
  77.     MACLIB    Z3BASE.LIB
  78.  
  79. ;
  80. ;  System Equates
  81. ;
  82. BDOS    EQU    5
  83. FCB    EQU    5CH
  84. TBUFF    EQU    80H
  85. RCPFLG    EQU    1        ; Package type is rcp
  86. IOPFLG    EQU    2        ; Package type is iop
  87. FCPFLG    EQU    3        ; Package type is fcp
  88. NDRFLG    EQU    4        ; Package type is ndr
  89. ENVFLG    EQU    5        ; Package type is env
  90. TCAPFLG    EQU    6        ; Package type is z3t
  91. CR    EQU    0DH
  92. LF    EQU    0AH
  93.  
  94.     EXT    Z3INIT,ENVPTR,GETQUIET
  95.     EXT    PFIND,RETUD,GETUD,PUTUD,LOGUD
  96.     EXT    GETRCP,GETFCP,GETIOP,GETNDR
  97.     EXT    F$OPEN,F$CLOSE,F$READ
  98.     EXT    PRINT,PFN2
  99.     EXT    HMOVB,MOVEB,FILLB
  100.     EXT    CLINE,SKSP,ZFNAME,z3log,luopen,luread,luinit
  101.  
  102. ;
  103. ;  Environments
  104. ;
  105. ORIGIN:
  106. ;
  107.      IF    EXTENV        ; If external environment ...
  108. ;
  109. ;  External Environment Definition
  110. ;
  111.     JP    Z3LDR
  112.     DB    'Z3ENV'        ; This is an environment
  113.     DB    1        ; Class 1 environment (external)
  114. ENVLOC:
  115.     DW    Z3ENV        ; Ptr to environment
  116. Z3LDR:
  117.     LD    HL,(ENVLOC)    ; Hl pts to environment
  118.  
  119.      ELSE            ; If internal environment ...
  120. ;
  121. ;  Internal Environment Definition
  122. ;
  123.     MACLIB    SYSENV.LIB
  124. ENVLOC:
  125.     JP    Z3LDR
  126.     SYSENV            ; Define environment
  127. Z3LDR:
  128.     LD    HL,ENVLOC    ; Hl pts to environment
  129.  
  130.      ENDIF
  131.  
  132. ;
  133. ;  Beginning of LDR
  134. ;
  135.     CALL    Z3INIT        ; Initialize environment pointer
  136.     CALL    PUTUD
  137.     CALL    BANNER        ; Print banner
  138.     LD    HL,TBUFF    ; Pt to command line
  139.     CALL    CLINE        ; Save command line as string
  140.     CALL    SKSP        ; Skip over spaces
  141.     XOR    A
  142.     ld    (LBRFLG),a    ; Not a library, yet.
  143.     LD    A,(HL)        ; Get offending char
  144.     CP    '/'        ; Help?
  145.     JP    Z,HELP
  146.     OR    A        ; Help?
  147.     JP    Z,HELP
  148. ;
  149. ;  Main Loop - HL pts to next file name in list
  150. ;
  151.     PUSH    HL
  152.     LD    DE,FCB+9
  153.     LD    HL,LBRTYP
  154.     LD    A,(DE)
  155.     CP    ' '
  156.     JP    NZ,NOMOV    ; If it has no type, it must be a LBR.
  157.     LD    BC,3
  158.     LDIR
  159.     JP    NOCMP
  160. NOMOV:    CALL    COMPTYP        ; Is it .LBR?
  161.     POP    HL
  162.     JP    NZ,Z3LDR1    ; No, loop.
  163.     PUSH    HL
  164. NOCMP:
  165.     CALL    GETQUIET
  166.     JP    NZ,PQ0
  167.     CALL    PRINT
  168.     DB    cr,lf,' Reading from ',0
  169.     LD    DE,FCB+1
  170.     CALL    PFN2
  171. PQ0:    LD    DE,LUFCB1
  172.     POP    HL
  173.     CALL    ZFNAME        ; Skip over the name.
  174.     CALL    LBRSETUP
  175.     JP    LQ1        ; Skip over comma.
  176. Z3LDR1:
  177.     LD    DE,FCB        ; Pt to fcb
  178.     CALL    ZFNAME        ; Extract file name and data
  179.  
  180. NOTLBR:    INC    DE        ; Pt to file name
  181. ;
  182.     CALL    GETQUIET
  183.     JP    NZ,Q0
  184.     CALL    PRINT
  185.     DB    CR,LF,' Loading ',0
  186.     CALL    PFN2        ; Print file name
  187.  
  188. Q0:    PUSH    HL        ; Save ptr
  189.     CALL    PKLOAD        ; Load file
  190.     POP    HL        ; Get ptr
  191. LQ1:    LD    A,(HL)        ; Get char
  192.     INC    HL        ; Pt to next char
  193.     CP    ','        ; Another file in list?
  194.     JP    Z,Z3LDR1
  195.     LD    A,(LBRFLG)
  196.     OR    A
  197.     RET    Z
  198.     DEC    A
  199.     LD    (LBRFLG),A
  200.     LD    DE,LUFCB1
  201.     JP    F$CLOSE
  202.  
  203. ;
  204. ;  Print Help Message
  205. ;
  206. HELP:
  207.     CALL    GETQUIET
  208.     RET    NZ
  209.     CALL    PRINT
  210.     DB    CR,LF,' LDR Syntax:'
  211.     DB    CR,LF,'   LDR [Library,]<list of packages/data files>'
  212.     DB    CR,LF,' where entries in the list may be any of these types:'
  213.     DB    CR,LF
  214.     DB    CR,LF,'   FCP - Flow Cmnd Package         ENV - Z3 Environ'
  215.     DB    CR,LF,'   IOP - Input/Output Package      NDR - Z3 Named Dir'
  216.     DB    CR,LF,'   RCP - Resident Cmnd Package     Z3T - Z3TCAP Entry'
  217.     DB    CR,LF,LF,' The package list may have DU: or DIR: references.'
  218.     DB    CR,LF,' If they do not, the path is searched for the package.'
  219.     DB    CR,LF,LF,' The ENV file must be first if LDR is not installed.'
  220.     DB    CR,LF,0
  221.     RET
  222. ;
  223. ;  Load package named in FCB
  224. ;
  225. PKLOAD:
  226.     CALL    SETDATA        ; Load data buffers from environment in case of change
  227.     CALL    CKTYPE        ; Check for valid file type
  228.     JP    Z,TYPERR    ; Abort if error
  229.     CALL    OPEN        ; Open file, read in first block, check for valid
  230.     JP    Z,LGETUD    ; Abort if error
  231.  
  232. ; Check if ENV.  If so, get Z3ENV and call z3init
  233.  
  234.     PUSH    HL        ; Save package pointer from cktype
  235.     LD    DE,FCB+9    ; Fcb type
  236.     LD    HL,ENVTYP    ; Env?
  237.     CALL    COMPTYP        ; Compare types
  238.     POP    HL        ; Get package pointer
  239.     JP    NZ,PKLD        ; Not env, proceed normally
  240. ;
  241. ; File type is ENV.  Get Z3ENV address from file and re-initialize
  242. ;
  243.     LD    HL,TBUFF    ; First sector in tbuff
  244.     LD    DE,1BH        ; Offset to z3env
  245.     ADD    HL,DE        ; Point hl to it
  246.     LD    E,(HL)        ; Get z3env
  247.     INC    HL
  248.     LD    D,(HL)        ; Got it
  249.     EX    DE,HL        ; In hl
  250.     CALL    Z3INIT        ; Set new environment
  251.  
  252. PKLD:    CALL    LOAD        ; Load package into memory at correct location
  253.     CALL    CLOSE        ; Close up process
  254.     CALL    LGETUD        ; Return home
  255. ;
  256. ;  Check for IOP and return if not
  257. ;
  258.     LD    A,(PKTYPE)    ; Init package if iop
  259.     CP    IOPFLG
  260.     RET    NZ
  261. ;
  262. ;  Init IOP
  263. ;
  264.     LD    HL,(PACKADR)    ; Get address
  265.     LD    DE,9        ; 4th jmp into it
  266.     ADD    HL,DE
  267.     PUSH    HL        ; Address on stack
  268.     RET            ; "call" routine and return to OS
  269. ;
  270. ;  Load Data Buffers from Environment
  271. ;
  272. SETDATA:
  273.     LD    HL,(ENVPTR)    ; Get environment descriptor address
  274.     LD    (ENVADR),HL
  275.     LD    DE,80H        ; Pt to z3tcap
  276.     ADD    HL,DE
  277.     LD    (TCAPADR),HL
  278.     CALL    GETRCP        ; Get rcp data
  279.     LD    DE,RCPDATA    ; Load
  280.     CALL    SDLOAD
  281.     CALL    GETIOP        ; Get iop data
  282.     LD    DE,IOPDATA    ; Load
  283.     CALL    SDLOAD
  284.     CALL    GETFCP        ; Get fcp data
  285.     LD    DE,FCPDATA    ; Load
  286.     CALL    SDLOAD
  287.     LD    HL,NDRIDAT    ; Init ndr data in case no entry
  288.     LD    DE,NDRDATA
  289.     LD    B,9        ; 9 bytes (1-jmp, 5-id, 2-adr, 1-size)
  290.     CALL    MOVEB
  291.     CALL    GETNDR        ; Get ndr data
  292.     LD    B,A        ; Save entry count                ;1284dl
  293.     LD    A,H        ; No ndr data?
  294.     OR    L
  295.     RET    Z
  296.     LD    A,B        ; Restore entry count                ;1284dl
  297.     CALL    SDLOAD        ; With de -> ndrdata                ;1284dl
  298.     PUSH    DE        ; Save ptr to entry count            ;1284dl
  299.     LD    H,0        ; Hl = value
  300.     LD    L,A        ; A  = entry count
  301.     ADD    HL,HL        ; *2
  302.     LD    D,H        ; De = value * 2
  303.     LD    E,L
  304.     ADD    HL,HL        ; *4
  305.     ADD    HL,HL        ; *8
  306.     ADD    HL,HL        ; *16
  307.     ADD    HL,DE        ; *18
  308.     LD    A,H        ; /128
  309.     RLCA
  310.     AND    0FEH
  311.     LD    H,A
  312.     LD    A,L
  313.     RLCA
  314.     AND    1
  315.     OR    H        ; A = value * 18 / 128
  316.     INC    A        ; +1
  317.     POP    DE        ; Get ptr
  318.     LD    (DE),A        ; Save value
  319.     RET
  320. ;
  321. ;  Load 3 bytes pted to by HL into memory pted to by DE+6
  322. ;
  323. ;    Input Regs:                            ;1284DL
  324. ;        HL = Source                        ;1284DL
  325. ;        DE = Destination                    ;1284DL
  326. ;                                    ;1284DL
  327. ;    Output Regs:                            ;1284DL
  328. ;        HL = Source                        ;1284DL
  329. ;        DE = Destination+8                    ;1284DL
  330. ;                                    ;1284DL
  331. SDLOAD:
  332.     PUSH    HL        ; Save ptr to data
  333.     LD    HL,6        ; Add 6 to de to pt to proper buffer
  334.     ADD    HL,DE        ; Hl pts to buffer
  335.     POP    DE        ; De contains address
  336.     LD    (HL),E        ; Store address
  337.     INC    HL
  338.     LD    (HL),D
  339.     INC    HL
  340.     LD    (HL),A        ; Store size data
  341.     EX    DE,HL        ; Swap source / destination regs        ;1284dl
  342.     RET
  343. ;
  344. ;  Print Banner
  345. ;
  346. BANNER:
  347.     CALL    GETQUIET
  348.     RET    NZ
  349.     CALL    PRINT
  350.     DB    CR,LF,'ZCPR3 LDR, Version '
  351.     DB    (VERSION/10)+'0','.',(VERSION MOD 10)+'0',0
  352.     RET
  353. ;
  354. ;  Check for Valid Package File Type
  355. ;    Return with Zero Flag Set if error
  356. ;    If validated, PKTYPE contains package type and HL pts to data
  357. ;
  358. CKTYPE:
  359.     LD    DE,FCB+9    ; Pt to file type
  360.     LD    HL,RCPTYP    ; See if rcp
  361.     LD    B,RCPFLG    ; Rcp code
  362.     CALL    COMPTYP        ; Compare
  363.     JP    Z,CKTOK        ; Ok if match
  364.     LD    HL,IOPTYP    ; See if iop
  365.     LD    B,IOPFLG    ; Iop code
  366.     CALL    COMPTYP        ; Compare
  367.     JP    Z,CKTOK        ; Ok if match
  368.     LD    HL,FCPTYP    ; See if fcp
  369.     LD    B,FCPFLG    ; Fcp code
  370.     CALL    COMPTYP        ; Compare
  371.     JP    Z,CKTOK        ; Ok if match
  372.     LD    HL,NDRTYP    ; See if ndr
  373.     LD    B,NDRFLG    ; Ndr code
  374.     CALL    COMPTYP        ; Compare
  375.     JP    Z,CKTOK        ; Ok if match
  376.     LD    HL,ENVTYP    ; See if env
  377.     LD    B,ENVFLG    ; Env code
  378.     CALL    COMPTYP        ; Compare
  379.     JP    Z,CKTOK        ; Ok if match
  380.     LD    HL,TCAPTYP    ; See if z3tcap
  381.     LD    B,TCAPFLG    ; Z3t code
  382.     CALL    COMPTYP        ; Compare
  383.     JP    Z,CKTOK
  384.     LD    B,0        ; Invalid type
  385. CKTOK:
  386.     LD    A,B        ; Set package type
  387.     LD    (PKTYPE),A
  388.     OR    A        ; Set nz if no error
  389.     RET
  390. COMPTYP:
  391.     PUSH    DE        ; Save regs
  392.     PUSH    BC
  393.     LD    B,3        ; 3 bytes
  394. COMPT1:
  395.     LD    A,(DE)        ; Get fcb char
  396.     AND    7FH        ; Mask
  397.     CP    (HL)        ; Compare
  398.     JP    NZ,COMPT2
  399.     INC    HL        ; Pt to next
  400.     INC    DE
  401.     DEC    B        ; Count down
  402.     JP    NZ,COMPT1
  403. COMPT2:
  404.     POP    BC        ; Restore regs
  405.     POP    DE
  406.     RET
  407. TYPERR:
  408.     CALL    GETQUIET
  409.     RET    NZ
  410.     CALL    PRF        ; Print file name and string
  411.     DB    ' is not a Valid Type',0
  412.     RET
  413. ;
  414. ;    If DU reference is explicit, log into it.  If not, search path.
  415. ;    Open File and Load First Block into TBUFF
  416. ;    Validate Package Structure and Return with Zero Flag Set if Error
  417. ;    On input, HL pts to data buffer
  418. ;    If no error, HL points to load address and B is number of 128-byte
  419. ;        pages allowed in buffer
  420. ;
  421. OPEN:
  422.     LD    A,(LBRFLG)
  423.     OR    A
  424.     JP    NZ,AMC
  425.     CALL    PUTUD        ; Save current DU
  426.     CALL    RETUD        ; Get current DU in BC
  427.     LD    A,(FCB)        ; Get disk
  428.     OR    A        ; Default?
  429.     JP    NZ,EXPLICIT    ; Explicit reference, do it.
  430.     LD    DE,FCB
  431.     DEC    A        ; A non-zero
  432.     CALL    PFIND        ; Search current DU, then along path
  433.     JP    Z,FNFERR    ; Can't find it
  434.     JP    LOGIT
  435. EXPLICIT:
  436.     LD    B,A        ; Disk in b (a=1)
  437.     DEC    B        ; Adjust to a=0
  438. OPEN0:
  439.     LD    A,(FCB+13)    ; Get user
  440.     LD    C,A        ; User in c
  441. LOGIT:
  442.     CALL    LOGUD        ; Log into ud
  443.     XOR    A        ; Clear disk
  444.     LD    (FCB),A
  445.  
  446. ;
  447. ;  Disallow Ambiguous File Name
  448. ;
  449. AMC:    CALL    AMBCHK        ; Check for ambiguous file name
  450.     JP    Z,AMBERR    ; Abort if any ambiguity
  451. ;
  452. ;  Open File
  453. ;
  454.     LD    DE,FCB        ; Pt to fcb
  455.     LD    A,(LBRFLG)
  456.     OR    A
  457.     JP    Z,O1
  458.     PUSH    HL
  459.     PUSH    DE
  460.     INC    DE
  461.     EX    DE,HL
  462.     LD    DE,LUFCB
  463.     CALL    LUOPEN        ; Get file from within LBR.
  464.     POP    DE
  465.     POP    HL
  466.     JP    O2
  467. O1:    CALL    F$OPEN        ; Open file
  468. O2:    JP    NZ,FNFERR    ; Abort if file not found
  469. ;
  470. ;  Read First 128-byte Block
  471. ;
  472.     PUSH    HL
  473.     CALL    LREAD        ; Read in first block
  474.     POP    HL
  475.     JP    NZ,FEMPTY    ; Abort if file empty
  476. ;
  477. ;  Validate Package
  478. ;    Package Data Area is structured as follows:
  479. ;        DB    numjmps ; number of jumps at beginning of package
  480. ;        DB    'Z3xxx' ; package ID (always 5 chars)
  481. ;        DW    address ; address of memory buffer
  482. ;        DB    size    ; number of 128-byte blocks in memory buffer
  483. ;
  484.     EX    DE,HL        ; De pts to package data
  485.     LD    A,(DE)        ; Get number of jumps
  486.     INC    DE        ; Pt to package id
  487.     LD    B,A        ; Jump count in b
  488. ;
  489. ;  Validate Package - MUST have proper number of JMPs
  490. ;
  491.     LD    HL,TBUFF    ; Check jumps
  492. OPEN1:
  493.     LD    A,B        ; At limit of jumps?
  494.     OR    A
  495.     JP    Z,OPEN2
  496.     DEC    B        ; Count down
  497.     LD    A,(HL)        ; Check for jmp
  498.     CP    0C3H        ; Jmp?
  499.     JP    NZ,STRERR    ; Structure error
  500.     INC    HL        ; Pt to next
  501.     INC    HL
  502.     INC    HL
  503.     JP    OPEN1
  504. ;
  505. ;  Check Package ID - must match
  506. ;
  507. OPEN2:
  508.     LD    B,5        ; Check package id
  509. OPEN3:
  510.     LD    A,(DE)        ; Get byte
  511.     CP    ' '        ; No id if space
  512.     JP    Z,OPEN4
  513.     CP    (HL)        ; Check
  514.     JP    NZ,STRERR    ; Structure error
  515. OPEN4:
  516.     INC    DE        ; Pt to next
  517.     INC    HL
  518.     DEC    B        ; Count down
  519.     JP    NZ,OPEN3
  520. ;
  521. ;  Extract Package Address
  522. ;
  523.     LD    A,(DE)        ; Get low-order address
  524.     LD    L,A        ; Put in hl
  525.     INC    DE
  526.     LD    A,(DE)        ; Get high-order address
  527.     LD    H,A
  528.     INC    DE
  529. ;
  530. ;  Check for Valid Package Address
  531. ;
  532.     LD    A,H        ; Must not be zero
  533.     OR    L
  534.     JP    Z,ADRERR
  535. ;
  536. ;  Extract 128-byte Block Count
  537. ;
  538.     LD    A,(DE)        ; Get block count
  539.     LD    B,A        ; Put in b
  540.     XOR    A        ; Set flags
  541.     DEC    A        ; Nz
  542.     RET
  543. ;
  544. ;  Ambiguous File Name Check
  545. ;    Returns with Z Set if Ambiguous
  546. ;
  547. AMBCHK:
  548.     LD    DE,FCB+1    ; Check for ambiguous file name
  549.     LD    B,11        ; 11 chars
  550. AMBCHK1:
  551.     LD    A,(DE)        ; Get char
  552.     AND    7FH        ; Mask
  553.     CP    '?'
  554.     RET    Z
  555.     INC    DE        ; Pt to next
  556.     DEC    B        ; Count down
  557.     JP    NZ,AMBCHK1
  558.     DEC    B        ; Set nz flag
  559.     RET
  560.  
  561. ;
  562. ;  Error Messages
  563. ;
  564. AMBERR:
  565.     CALL    GETQUIET
  566.     JP    NZ,ERRET
  567.     CALL    PRF        ; Print file name and message
  568.     DB    ' is Ambiguous',0
  569. ERRET:
  570.     XOR    A        ; Set error code
  571.     RET
  572. ADRERR:
  573.     CALL    GETQUIET
  574.     JP    NZ,ERRET
  575.     CALL    PRF        ; Print file name and message
  576.     DB    ' Not Known to Environ',0
  577.     JP    ERRET
  578. FNFERR:
  579.     CALL    GETQUIET
  580.     JP    NZ,ERRET
  581.     CALL    PRF        ; Print file name and message
  582.     DB    ' Not Found',0
  583.     JP    ERRET
  584. FEMPTY:
  585.     CALL    GETQUIET
  586.     JP    NZ,ERRET
  587.     CALL    PRF        ; Print file name and message
  588.     DB    ' Empty',0
  589.     JP    ERRET
  590. STRERR:
  591.     CALL    GETQUIET
  592.     JP    NZ,ERRET
  593.     CALL    PRF        ; Print file name and message
  594.     DB    ' Contains a Format Flaw',0
  595.     JP    ERRET
  596. PRF:
  597.     CALL    PRINT
  598.     DB    CR,LF,' File ',0
  599.     LD    DE,FCB+1
  600.     CALL    PFN2
  601.     JP    PRINT
  602.  
  603. ;
  604. ; Open a LBR for reading
  605. ;
  606. LBRSETUP:
  607.     PUSH    HL
  608.     XOR    A
  609.     DEC    A
  610.     LD    (LBRFLG),A    ; Yes we are running from a LBR.
  611.     LD    DE,FCB
  612.     CALL    Z3LOG        ; Log onto LBR's DU:
  613.     LD    DE,LUFCB1
  614.     LD    HL,FCB
  615.     LD    BC,14
  616.     LDIR            ; Move the LBR to LU's FCB.
  617.     LD    DE,LUFCB
  618.     CALL    LUINIT        ; Do the Conn routine.
  619.     JP    Z,FOUND1
  620.     LD    DE,LUFCB1
  621.     XOR    A
  622.     LD    (DE),a
  623.     DEC    A        ; A non-zero
  624.     CALL    PFIND        ; Search current DU, then along path
  625.     JP    Z,FOUND2
  626.     CALL    LOGUD        ; Log into ud
  627.     XOR    A        ; Clear disk
  628.     LD    (LUFCB),A
  629. FOUND2:    LD    DE,LUFCB
  630.     CALL    LUINIT
  631. FOUND1:    POP    HL
  632.     RET    Z
  633.     POP    HL        ; Swallow the CALL's return.
  634.     DEC    A
  635.     JP    Z,FNFERR    ; Not found.
  636.     DEC    A
  637.     JP    Z,FEMPTY    ; Empty.
  638.     JP    STRERR        ; Bad form.
  639.  
  640. ;
  641. ;  Close File
  642. ;
  643. CLOSE:
  644.     LD    A,(LBRFLG)
  645.     OR    A
  646.     RET    NZ        ; No close necessary
  647.     LD    DE,FCB        ; Pt to fcb
  648.     JP    F$CLOSE        ; Close file
  649.  
  650. ;
  651. ; Don't restore if we're using a library.
  652. ;
  653. LGETUD:    ld    a,(LBRFLG)
  654.     or    a
  655.     ret    nz
  656.     jp    GETUD
  657.  
  658. ;
  659. ; LBR or file read
  660. ;
  661. LREAD:    LD    A,(LBRFLG)
  662.     OR    A
  663.     JP    Z,LREAD2    ; Normal read unless a LBR.
  664.     PUSH    DE
  665.     LD    DE,LUFCB
  666.     CALL    LUREAD        ; Conn's routine.
  667.     POP    DE
  668.     RET
  669. LREAD2:
  670.     JP    F$READ
  671.  
  672. ;
  673. ;  Load File Into Buffer
  674. ;
  675. LOAD:
  676.     LD    (PACKADR),HL    ; Save package address in case of error
  677.     EX    DE,HL        ; De pts to buffer, b = max blocks
  678. LOAD1:
  679.     PUSH    BC        ; Save count
  680.     LD    HL,TBUFF    ; Pt to buffer
  681.     LD    B,128
  682.     CALL    HMOVB        ; Copy tbuff into buffer
  683.     PUSH    DE        ; Save ptr to next block in buffer
  684.     LD    DE,FCB        ; Pt to fcb
  685.     CALL    LREAD        ; Read next block
  686.     POP    DE        ; Get ptr
  687.     POP    BC        ; Get count
  688.     RET    NZ        ; Done if nz
  689.     DEC    B        ; Count down
  690.     JP    NZ,LOAD1
  691. ;
  692. ;  Buffer Full
  693. ;
  694.     CALL    GETQUIET
  695.     JP    NZ,Q1
  696.     CALL    PRF
  697.     DB    ' is too Large',0
  698. Q1:    LD    HL,(PACKADR)    ; Clear package
  699.     LD    B,128        ; Nops
  700.     XOR    A
  701.     CALL    FILLB
  702. ;    lxi    b,128    ; pt to after last NOP        [sak]
  703.     LD    BC,128-ERCSIZ    ; [sak]
  704.     ADD    HL,BC
  705.     LD    B,3        ; Copy 3 bytes
  706.     EX    DE,HL        ; De pts to empty space
  707.     LD    HL,ERCODE    ; Store error code
  708.     JP    MOVEB
  709. ;
  710. ;  Error Code to be Stored if Package Load Fails
  711. ;
  712. ERCODE:
  713.     XOR    A        ; 3 bytes
  714.     DEC    A        ; A=0ffh and nz flag set
  715.     RET
  716.  
  717. ERCSIZ    EQU    $-ERCODE    ; [sak]
  718. ;
  719. ;  Buffers
  720. ;
  721. LUFCB:    db    0,0,0,0,0,0    ; For Conn's Library utilities.
  722.     db    'filenametyp'
  723. LUFCB1:    db    0,'filenametyp'
  724.     ds    26,0
  725. LBRTYP:    db    'LBR'        ; Filename.LBR
  726. LBRFLG:    db    0        ; Was first file a LBR?
  727.  
  728. NDRIDAT:
  729.     DB    0        ; No jmps
  730.     DB    '     '        ; No id stored
  731.     DW    0        ; Address
  732.     DB    0        ; (z3ndirs*18)/128+1 size
  733. RCPTYP:
  734.     DB    'RCP'        ; File type of rcp file
  735. RCPDATA:
  736.     DB    0        ; 0 jmps
  737.     DB    'Z3RCP'        ; Id
  738.     DW    0        ; Address
  739.     DB    0        ; Size
  740. IOPTYP:
  741.     DB    'IOP'        ; File type of iop file
  742. IOPDATA:
  743.     DB    16        ; 16 jmps
  744.     DB    'Z3IOP'        ; Id
  745.     DW    0        ; Address
  746.     DB    0        ; Size
  747. FCPTYP:
  748.     DB    'FCP'        ; File type of fcp file
  749. FCPDATA:
  750.     DB    0        ; 0 jmps
  751.     DB    'Z3FCP'        ; Id
  752.     DW    0        ; Address
  753.     DB    0        ; Size
  754. NDRTYP:
  755.     DB    'NDR'        ; File type of ndr file
  756. NDRDATA:
  757.     DB    0        ; No jmps
  758.     DB    '     '        ; No id stored
  759.     DW    0        ; Address
  760.     DB    0        ; (z3ndirs*18)/128+1 size
  761. ENVTYP:
  762.     DB    'ENV'        ; File type of env file
  763. ENVDATA:
  764.     DB    1        ; 1 jmp
  765.     DB    'Z3ENV'        ; Id
  766. ENVADR:
  767.     DW    0        ; Address
  768.     DB    2        ; 2 128-byte blocks max
  769. TCAPTYP:
  770.     DB    'Z3T'        ; File type of z3tcap file
  771. TCAPDATA:
  772.     DB    0        ; No jmps
  773.     DB    '     '        ; No id stored
  774. TCAPADR:
  775.     DW    0        ; Address
  776.     DB    1        ; 1 128-byte block max
  777. PKTYPE:
  778.     DS    1        ; Package type (0=error)
  779. PACKADR:
  780.     DS    2        ; Package address
  781.  
  782.     END
  783.  Address