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 / ZSYS / SIMTEL20 / ZCPR3 / ALIAS0.MAC < prev    next >
Text File  |  2000-06-30  |  8KB  |  432 lines

  1. ;
  2. ; Program: ALIAS0
  3. ; Author: Richard Conn
  4. ; Version: 1.1
  5. ; Date: 10 Jun 84
  6. ; Previous Versions:  1.0 (5 Mar 84)
  7. ;
  8. version    equ    11
  9.  
  10. ;
  11. ;    The purpose of ALIAS0 is to create aliases using the ALIAS1
  12. ; program.
  13. ;
  14.  
  15. ;
  16. ; Environment Definition
  17. ;
  18.     MACLIB    Z3BASE.LIB
  19.  
  20. ;
  21. ; Basic Equates
  22. ;
  23. buffer    equ    4000h    ;1K (approx) buffer
  24. tbuff    equ    80h
  25. fcb    equ    5ch
  26. cr    equ    0dh
  27. lf    equ    0ah
  28.  
  29. ;
  30. ; External References
  31. ;
  32.     ext    $memry
  33.     ext    z3init,qprint,getwhl
  34.     ext    print,sksp,bbline,capine,crlf,pfn1,retud,logud,padc
  35.     ext    hmovb,sfa,cout,ccout,pstr,zfname
  36.     ext    f$open,f$read,f$close,f$make,f$delete,f$write,f$exist,initfcb
  37.  
  38. ;
  39. ; Key Equates for Address Definition of Environment
  40. ;
  41. envdefn    equ    103H    ;Beginning of Environment Definition
  42. envclas    equ    108H    ;Address of Environment Descriptor Class
  43.  
  44. ;
  45. ; Environment Definition
  46. ;
  47.     if    z3env ne 0
  48. ;
  49. ; External ZCPR3 Environment Descriptor
  50. ;
  51.     jmp    start
  52.     db    'Z3ENV'    ;This is a ZCPR3 Utility
  53.     db    1    ;External Environment Descriptor
  54. z3eadr:
  55.     dw    z3env
  56. start:
  57.     lhld    z3eadr    ;pt to ZCPR3 environment
  58. ;
  59.     else
  60. ;
  61. ; Internal ZCPR3 Environment Descriptor
  62. ;
  63.     MACLIB    SYSENV.LIB
  64. z3eadr:
  65.     jmp    start
  66.     SYSENV
  67. start:
  68.     lxi    h,z3eadr    ;pt to ZCPR3 environment
  69.     endif
  70.  
  71. ;
  72. ; Start of Program -- Initialize ZCPR3 Environment
  73. ;
  74.     call    z3init    ;initialize the ZCPR3 Env and the VLIB Env
  75. ;
  76. ; Print Banner
  77. ;
  78.     call    qprint
  79.     db    'ALIAS, Version '
  80.     db    (version/10)+'0','.',(version mod 10)+'0',0
  81. ;
  82. ; Check for File
  83. ;
  84.     xra    a
  85.     sta    flflag    ;clear file loaded flag
  86.     lxi    h,fcb+1    ;pt to file name
  87.     mov    a,m    ;get first char
  88.     cpi    ' '    ;no name if space
  89.     jz    create    ;create an alias if no name
  90.     cpi    '/'    ;help?
  91.     jnz    start0
  92. ;
  93. ; Help Message
  94. ;
  95.     call    print
  96.     db    cr,lf,'ALIAS -- Create Alias Commands'
  97.     db    cr,lf,'Syntax:'
  98.     db    cr,lf,'    ALIAS            <-- Define New Command'
  99.     db    cr,lf,'or'
  100.     db    cr,lf,'    ALIAS dir:cmndname    <-- Redefine Old Command'
  101.     db    0
  102.     ret
  103.  
  104. ;
  105. ; Load ALIAS File
  106. ;
  107. start0:
  108.     call    setcom    ;set file type of file in FCB to COM if not already
  109.     call    retud    ;get current DU in BC
  110.     dcx    h    ;pt to disk
  111.     mov    a,m    ;get disk
  112.     ora    a    ;no current disk?
  113.     jz    start1    ;use current disk
  114.     dcr    a    ;set disk (A=0)
  115.     mov    b,a
  116. start1:
  117.     mvi    m,0    ;set current disk
  118.     lxi    d,13    ;pt to user number
  119.     push    h    ;save ptr to FCB
  120.     dad    d    ;pt to user
  121.     mov    c,m    ;get user
  122.     pop    d    ;pt to FCB
  123.     call    logud    ;log into dir in BC
  124.     lxi    h,buffer    ;pt to file storage buffer
  125.     call    f$open    ;open alias file for input
  126.     jz    load    ;load file
  127.     call    print
  128.     db    cr,lf,' Alias File ',0
  129.     inx    d    ;pt to file name
  130.     call    pfn1    ;print it
  131.     call    print
  132.     db    ' Not Found',0
  133.     ret
  134. ;
  135. ; Load Alias File
  136. ;
  137. load:
  138.     lxi    h,buffer    ;pt to load buffer
  139.     mvi    c,9    ;set block count
  140. load1:
  141.     lxi    d,fcb    ;pt to FCB
  142.     call    f$read    ;read next block
  143.     jnz    load2
  144.     lxi    d,tbuff    ;pt to buffer
  145.     xchg
  146.     mvi    b,128    ;128 bytes
  147.     call    hmovb
  148.     xchg        ;DE pts to next block
  149.     dcr    c    ;count down
  150.     jnz    load1
  151. ;
  152. ; Error - Not an Alias File
  153. ;
  154. noalias:
  155.     call    print
  156.     db    cr,lf,' File ',0
  157.     lxi    d,fcb+1
  158.     call    pfn1
  159.     call    print
  160.     db    ' is Not an Alias',0
  161.     ret
  162. ;
  163. ; Load Complete - Check for Alias File Structure
  164. ;
  165. load2:
  166.     call    f$close    ;close input file
  167.     lhld    buffer+1    ;get address of START
  168.     lxi    d,buffer-100H
  169.     dad    d    ;pt to actual address
  170.     lxi    d,9    ;skip to ALIAS ID
  171.     dad    d
  172.     lxi    d,aliasid    ;compare
  173.     mvi    b,8    ;8 chars
  174. acheck:
  175.     ldax    d    ;get char
  176.     cmp    m    ;compare
  177.     jnz    noalias
  178.     inx    h    ;pt to next
  179.     inx    d
  180.     dcr    b    ;count down
  181.     jnz    acheck
  182.     shld    oldaline    ;save ptr to old alias command line
  183.     mvi    a,0ffh    ;set file loaded flag
  184.     sta    flflag
  185. ;
  186. ; Create New Alias
  187. ;
  188. create:
  189.     lda    flflag    ;check for file loaded
  190.     ora    a    ;0 if not
  191.     jz    cr1
  192. ;
  193. ; Display Data on Old Alias
  194. ;
  195.     call    print
  196.     db    cr,lf,' Alias Name: ',0
  197.     lxi    h,fcb+1    ;pt to name
  198.     mvi    b,8    ;8 chars
  199. cr0:
  200.     mov    a,m    ;print name
  201.     call    cout
  202.     inx    h    ;pt to next char
  203.     dcr    b    ;count down
  204.     jnz    cr0
  205.     call    print
  206.     db    cr,lf,' Old Alias Command Line:',0
  207.     lhld    oldaline
  208.     mvi    b,1    ;set line count
  209. cr0a:
  210.     mov    a,m    ;check for done
  211.     ora    a
  212.     jz    cr1
  213.     call    crlf    ;new line
  214.     mov    a,b    ;print line number
  215.     call    padc
  216.     inr    b    ;increment count
  217.     call    print    ;print prompt
  218.     db    ' --> ',0
  219. cr0b:
  220.     mov    a,m    ;get char
  221.     ora    a
  222.     jz    cr1
  223.     call    ccout    ;print char with control char processing
  224.     inx    h    ;pt to next
  225.     cpi    ';'    ;next logical line?
  226.     jz    cr0a
  227.     jmp    cr0b
  228.  
  229. ;
  230. ; Input Alias Command from User
  231. ;
  232. cr1:
  233.     call    getwhl    ;get wheel byte
  234.     jnz    cr1a
  235.     call    print
  236.     db    cr,lf,' Modification of Alias Not Permitted',0
  237.     ret
  238. ;
  239. ; Input Alias from User
  240. ;
  241. cr1a:
  242.     call    print
  243.     db    cr,lf
  244.     db    cr,lf,' Input Alias (RETURN to Abort)',cr,lf,' --> ',0
  245.     mvi    a,0ffh    ;input line from user
  246.     call    bbline
  247.     call    sksp    ;skip to non-blank
  248.     mov    a,m    ;get char
  249.     ora    a    ;any input?
  250.     rz
  251.     push    h    ;save ptr
  252. ;
  253. ; Set Buffers in New Alias to Reflect the ALIAS0 Buffers
  254. ;
  255.     call    codend    ;pt to new alias
  256.     inx    h    ;pt to start of buffers
  257.     inx    h
  258.     inx    h
  259.     lxi    d,envdefn    ;pt to environment definition
  260.     mvi    b,8    ;prepare to copy 8 bytes for class 1
  261.             ; bytes are:    DB    'Z3ENV',1
  262.             ;        DW    envaddr
  263.     lda    envclas    ;get code for class of alias
  264.     cpi    1    ;class 1 is address of Env Desc only
  265.     jz    cr1b
  266.     mvi    b,100H-3    ;prepare to copy an entire env desc
  267. ;
  268. ; Copy the Buffers Over
  269. ;
  270. cr1b:
  271.     ldax    d    ;copy environment definition into new alias
  272.     mov    m,a
  273.     inx    h    ;advance
  274.     inx    d
  275.     dcr    b    ;count down
  276.     jnz    cr1b
  277. ;
  278. ; Prep to Copy New Command Into Alias
  279. ;
  280.     call    codend    ;pt to new alias command buffer
  281.     inx    h
  282.     mov    e,m    ;get address of START
  283.     inx    h
  284.     mov    d,m
  285.     lxi    h,17    ;pt to buffer at START+17
  286.     dad    d
  287.     lxi    d,-100H    ;compute offset
  288.     dad    d    ;HL contains offset
  289.     xchg
  290.     call    codend
  291.     dad    d    ;HL pts to absolute address
  292.     mvi    b,255    ;check for overflow (max number of chars)
  293.     pop    d    ;pt to new command
  294. ;
  295. ; Copy New Command into ALIAS File
  296. ;
  297. cr2:
  298.     ldax    d    ;get char
  299.     mov    m,a    ;put char
  300.     ora    a    ;done?
  301.     jz    cr3
  302.     inx    h    ;pt to next
  303.     inx    d
  304.     dcr    b    ;count down
  305.     jnz    cr2
  306.     call    print
  307.     db    cr,lf,' Command Too Long for Buffer - Reenter',0
  308.     jmp    create
  309. ;
  310. ; ALIAS Command Line Copied
  311. ;
  312. cr3:
  313.     lda    flflag    ;file loaded?
  314.     ora    a    ;0=no
  315.     jnz    write
  316.     call    print
  317.     db    cr,lf,' Name of ALIAS Command (RETURN to Abort)? ',0
  318.     mvi    a,0ffh    ;capitalize
  319.     call    bbline
  320.     call    sksp    ;skip to non-blank
  321.     mov    a,m
  322.     ora    a
  323.     jz    create
  324.     lxi    d,fcb    ;pt to FCB
  325.     call    zfname    ;convert and place in FCB
  326.     call    setcom    ;set file type to COM if not already
  327.     call    retud    ;get current DU
  328.     lda    fcb    ;get disk
  329.     ora    a    ;default?
  330.     jz    cr4
  331.     dcr    a    ;disk A = 0
  332.     mov    b,a
  333. cr4:
  334.     lda    fcb+13    ;get user
  335.     mov    c,a
  336.     call    logud
  337. ;
  338. ; Write File whose Name is in FCB
  339. ;
  340. write:
  341.     lxi    d,fcb    ;check for file
  342.     call    initfcb    ;clear FCB
  343.     call    f$exist    ;check for existence
  344.     jz    write1
  345.     call    print
  346.     db    cr,lf,' File ',0
  347.     lxi    d,fcb+1
  348.     call    pfn1
  349.     call    print
  350.     db    ' Exists - Overwrite (Y/N)? ',0
  351.     call    capine
  352.     call    crlf
  353.     cpi    'Y'
  354.     rnz        ;abort if not Y
  355.     lxi    d,fcb    ;clear file attributes
  356.     xra    a
  357.     call    sfa    ;set file attributes to R/W DIR
  358.     call    f$delete    ;delete file
  359. ;
  360. ; Create New File
  361. ;
  362. write1:
  363.     lxi    d,fcb    ;pt to FCB
  364.     call    initfcb    ;init it
  365.     call    f$make    ;create file
  366.     mvi    c,8    ;8 sectors
  367.     call    codend    ;pt to file
  368. write2:
  369.     lxi    d,tbuff    ;copy sector into buffer
  370.     mvi    b,128    ;128 bytes
  371.     call    hmovb
  372.     lxi    d,fcb    ;write block
  373.     call    f$write
  374.     jnz    werr
  375.     dcr    c    ;count down
  376.     jnz    write2
  377.     call    f$close    ;close file
  378.     call    print
  379.     db    cr,lf,' Alias Created',0
  380.     ret
  381. werr:
  382.     call    print
  383.     db    cr,lf,' Error in Creating File',0
  384.     ret
  385.  
  386. ;
  387. ; Determine End of Code to Nearest 128 bytes
  388. ;
  389. codend:
  390.     push    d
  391.     lhld    $memry    ;get next available byte
  392.     mov    a,l    ;get low
  393.     ani    80h    ;set MSB
  394.     mov    l,a
  395.     lxi    d,128    ;next 128 bytes
  396.     dad    d
  397.     pop    d
  398.     ret
  399.  
  400. ;
  401. ; Set File Type of File in FCB to COM if Not Already Set
  402. ;
  403. setcom:
  404.     lda    fcb+9    ;get first char of file type
  405.     cpi    ' '
  406.     rnz
  407.     push    h
  408.     push    d
  409.     push    b
  410.     lxi    h,comtyp    ;set COM type
  411.     lxi    d,fcb+9        ;copy into file type
  412.     mvi    b,3    ;3 bytes
  413.     call    hmovb
  414.     pop    b
  415.     pop    d
  416.     pop    h
  417.     ret
  418.  
  419. ;
  420. ; Buffers
  421. ;
  422. comtyp:
  423.     db    'COM'        ;COM File Type
  424. aliasid:
  425.     db    'Z3 ALIAS'    ;ALIAS File ID
  426. flflag:
  427.     ds    1    ;file loaded flag
  428. oldaline:
  429.     ds    2    ;ptr to old alias line
  430.  
  431.     end
  432.