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 / CPM3 / CCP105P.ARK / SETDIR.MAC < prev    next >
Text File  |  1986-10-17  |  5KB  |  342 lines

  1.     .z80
  2.  
  3. ;Utility to load directory names into the DIR RSX for use by the CCP
  4. ;
  5. ;Copyright (c) 1984 - Jim Lopushinsky
  6. ;
  7.  
  8. bdos    equ    5
  9. fcb    equ    5ch
  10.  
  11. setdir:
  12.     ld    sp,stack        ;set up local stack
  13.     ld    de,scbpb
  14.     ld    c,49
  15.     call    bdos            ;return SCB address
  16.     ld    (scbase),hl        ;save SCB address
  17.     ld    a,(fcb+1)
  18.     cp    ' '            ;any command line options?
  19.     jp    nz,noroot        ;jump if file spec
  20.     ld    hl,rootdir        ;point to default name (ROOT.DIR)
  21.     ld    de,fcb+1
  22.     ld    c,8
  23.     call    move            ;move it into place
  24. noroot:
  25.     ld    hl,fcb+1
  26.     ld    de,off            ;point to "OFF"
  27.     ld    c,8
  28.     call    comp            ;does he want to remove dir table?
  29.     jp    nz,notoff        ;jump if he doesn't
  30.     ld    hl,(bdos+1)
  31.     call    delrsx            ;remove the RSX just loaded
  32.     ld    de,rsx66
  33.     ld    c,60
  34.     call    bdos            ;see if DIR RSX exists
  35.     or    a
  36.     jp    z,isdir            ;jump if ok.
  37.     call    ilprt            ;tell him the bad news
  38.     db    'Directory names are not loaded',13,10,0
  39.     rst    0
  40. isdir:
  41.     call    delrsx            ;remove dir table
  42.     call    ilprt
  43.     db    'Directory names removed',13,10,0
  44.     rst    0
  45.  
  46. ;..............
  47. ;
  48. ;Here for normal load of directory table
  49. ;
  50. notoff:
  51.     ld    de,fcb+9
  52.     ld    a,(de)
  53.     ld    hl,dir
  54.     ld    c,3
  55.     cp    ' '            ;is file type specified?
  56.     call    z,move            ;if not, move DIR into place
  57.     ld    de,fcb
  58.     ld    c,15
  59.     call    bdos            ;open the file
  60.     inc    a
  61.     jp    nz,isfile        ;jump if open ok
  62.     ld    hl,(bdos+1)
  63.     call    delrsx            ;delete RSX just loaded
  64.     call    ilprt
  65.     db    'File not found.',13,10,0
  66.     rst    0
  67. isfile:
  68.     ld    de,rsx66
  69.     ld    c,60
  70.     call    bdos            ;see if old DIR RSX exists
  71.     or    a
  72.     jp    nz,nodir        ;jump if no old DIR RSX exists
  73.     ld    (diradr),hl
  74.     ld    hl,(bdos+1)
  75.     call    delrsx            ;remove RSX just loaded
  76.     jp    onward
  77. nodir:
  78.     ld    hl,(bdos+1)
  79.     ld    l,1bh            ;point to init flag in RSX
  80.     ld    (hl),0ffh        ;set DIR RSX as initialized
  81.     ld    de,rsx66
  82.     ld    c,60
  83.     call    bdos            ;get table load address
  84.     ld    (diradr),hl
  85. onward:
  86.     ld    hl,(diradr)        ;get table load address
  87.     ld    l,1bh            ;point to init flag
  88.     ld    (hl),0            ;reset it in case of errors
  89.     ld    l,0eh            ;point to remove flag
  90.     ld    (hl),0ffh        ;set remove flag in case of errors
  91.     ld    l,0ffh
  92.     inc    h            ;calculate highest usable table address
  93.     ld    (dirend),hl
  94.     ld    hl,(diradr)        ;get directory load address
  95.     ex    de,hl
  96.     ld    hl,rootbuf        ;point to file buffer
  97.     call    rootfill        ;fill the buffer
  98.     ld    (rootloc),a        ;reset offset into buffer
  99.     jp    nz,rootparse        ;jump if not at end of file
  100. eof:
  101.     call    ilprt
  102.     db    'Abnormal EOF reading directory file',13,10,0
  103. errxit:
  104.     ld    hl,(bdos+1)
  105.     call    delrsx
  106.     rst    0
  107. findlf:
  108.     call    rootbyte
  109.     jp    z,done
  110.     cp    10
  111.     jp    nz,findlf
  112. rootparse:
  113.     push    de
  114.     ld    b,9
  115. rootnmove:
  116.     call    rootbyte
  117.     jp    z,done1
  118.     call    chkdir
  119.     ld    (de),a
  120.     inc    de
  121.     cp    ';'
  122.     jp    z,rootpass
  123.     dec    b
  124.     jp    nz,rootnmove
  125.     jp    golf
  126. rootpass:
  127.     ld    b,9
  128. rootpmove:
  129.     call    rootbyte
  130.     jp    z,eof
  131.     call    chkdir
  132.     cp    ' '
  133.     jp    z,rootdu
  134.     ld    (de),a
  135.     inc    de
  136.     dec    b
  137.     jp    nz,rootpmove
  138. golf:
  139.     pop    de
  140.     jp    findlf
  141. rootdu:
  142.     xor    a
  143.     ld    (de),a
  144.     inc    de
  145.     call    chkdir
  146. rootblk:
  147.     call    rootbyte
  148.     jp    z,eof
  149.     cp    ' '
  150.     jp    z,rootblk
  151.     sub    'A'
  152.     jp    m,golf
  153.     cp    16
  154.     jp    nc,golf
  155.     ld    (rootdrv),a
  156.     ld    b,0
  157. rootu:
  158.     call    rootbyte
  159.     jp    z,eof
  160.     cp    ' '
  161.     jp    z,rootudone
  162.     sub    '0'
  163.     jp    m,golf
  164.     cp    10
  165.     jp    nc,golf
  166.     push    af
  167.     ld    a,b
  168.     add    a,a
  169.     add    a,a
  170.     add    a,b
  171.     add    a,a
  172.     ld    b,a
  173.     pop    af
  174.     add    a,b
  175.     ld    b,a
  176.     cp    16
  177.     jp    nc,golf
  178.     jp    rootu
  179. rootudone:
  180.     ld    a,b
  181.     rept    4
  182.     add    a,a
  183.     endm
  184.     ld    b,a
  185.     ld    a,(rootdrv)
  186.     or    b
  187.     ld    (de),a
  188.     inc    de
  189.     pop    bc
  190.     jp    findlf
  191. done1:
  192.     pop    de
  193. done:
  194.     call    chkdir
  195.     xor    a
  196.     ld    (de),a
  197.     ld    hl,(diradr)
  198.     ld    l,1bh
  199.     ld    (hl),0ffh
  200.     ld    l,0eh
  201.     ld    (hl),0
  202.     call    ilprt
  203.     db    'Directory table initialized',13,10,0
  204.     rst    0
  205.  
  206. rootbyte:
  207.     push    hl
  208.     push    de
  209.     push    bc
  210.     ld    a,(rootloc)
  211.     or    a
  212.     jp    p,norootf
  213.     call    rootfill
  214.     jp    z,rootnon
  215. norootf:
  216.     inc    a
  217.     ld    (rootloc),a
  218.     dec    a
  219.     call    addhla
  220.     ld    a,(hl)
  221.     and    7fh
  222.     cp    26
  223. rootnon:
  224.     pop    bc
  225.     pop    de
  226.     pop    hl
  227.     ret
  228.  
  229. rootfill:
  230.     push    hl
  231.     push    de
  232.     ex    de,hl
  233.     ld    c,26
  234.     call    bdos
  235.     ld    de,fcb
  236.     ld    c,20
  237.     call    bdos
  238.     pop    de
  239.     pop    hl
  240.     or    a
  241.     jp    z,goodr
  242.     xor    a
  243.     ret
  244. goodr:
  245.     inc    a
  246.     ld    a,0
  247.     ret
  248.  
  249. addhla:
  250.     add    a,l
  251.     ld    l,a
  252.     ret    nc
  253.     inc    h
  254.     ret
  255.  
  256. chkdir:
  257.     push    af
  258.     push    hl
  259.     ld    hl,(dirend)
  260.     call    cphlde
  261.     pop    hl
  262.     jp    nc,dirok
  263.     call    ilprt
  264.     db    'Too many directory table entries',13,10,0
  265.     jp    errxit
  266. dirok:
  267.     pop    af
  268.     ret
  269.  
  270. cphlde:
  271.     ld    a,h
  272.     cp    d
  273.     ret    nz
  274.     ld    a,l
  275.     cp    e
  276.     ret
  277.  
  278. delrsx:
  279.     ld    de,dir
  280.     ld    l,10h
  281.     ld    c,8
  282.     call    comp
  283.     ret    nz
  284.     ld    l,0eh
  285.     ld    (hl),0ffh
  286.     ld    de,0
  287.     ld    c,59
  288.     jp    bdos
  289.  
  290. ilprt:
  291.     pop    hl
  292.     ld    a,(hl)
  293.     inc    hl
  294.     push    hl
  295.     or    a
  296.     ret    z
  297.     ld    e,a
  298.     ld    c,2
  299.     call    bdos
  300.     jp    ilprt
  301.  
  302. move:
  303.     ld    a,(hl)
  304.     ld    (de),a
  305.     inc    hl
  306.     inc    de
  307.     dec    c
  308.     jp    nz,move
  309.     ret
  310.  
  311. comp:
  312.     ld    a,(de)
  313.     cp    (hl)
  314.     ret    nz
  315.     inc    de
  316.     inc    hl
  317.     dec    c
  318.     jp    nz,comp
  319.     ret
  320.  
  321.     dseg
  322.  
  323. stack    equ    100h
  324. scbpb:    db    3ah,0
  325. rootdir:
  326.     db    'ROOT    '
  327. off:    db    'OFF     '
  328. rsx66:    db    66
  329. dir:    db    'DIR     '
  330. diradr:    ds    2
  331. dirend:    ds    2
  332. rootbuf:
  333.     ds    128
  334. rootdrv:
  335.     ds    1
  336. rootloc:
  337.     ds    1
  338. scbase:    ds    2
  339.  
  340.  
  341.     end    setdir
  342.