*
*               dbdir.cmd
*
*               This command module is used to display the directory
*               of a disk while in dBASE.  This is accomplished by
*               calling an assembler routine that has been loaded
*               into memory, prior to executing dBASE, at hex  
*               location A500.  This routine uses variables which
*               reside at hex location A400.  They are 1)search string
*               (11-bytes used to do directory search, initially set
*               to "???????????", which will return the whole directory)
*               2) user number (1-byte, initially set to zero, which 
*               indicates the user number to do the directory search
*               for; can be from 0-F).
*						- Mike Kelly
*
*			         
*              08-19-82 v1.0    written  
*              08-19-82 v1.0    updated
*              09-19-82 v1.1    Added routine to implement a function
*                               byte to be passed to the assembler
*                               routine.  Function 00h will alter
*                               the user number, function 01h will
*                               show the directory.
*
*
set echo off
set talk off
set colon off
*
erase
store 57344+1024         to e400
store 40960+1024         to a400
store 40960+1280         to a500
store a500               to addrdir
store a400               to addrfunc
store addrfunc+1         to addrsearch
store addrfunc+12        to addrusr
store addrfunc+13        to addrdrv
store '3,68,73,82,0'     to dir
store 59162              to e71a
store '0123456789ABCDEF' to hextbl
store 'B'                to drive1
store 0                  to userno
store '????????.???'     to findme
store ' !"#$%&' +;
      chr(39) +;
      '()' +;
      '*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`' +;
      'abcdefghijklmnopqrstuvwxyz{|}~' to asciitbl
*
erase
store t to badrv  
store t to badusr
store t to badstr
do while badusr .or. badstr .or. badrv
    @  1,0  say 'dBASEII Directory display'
    @  3,0  say 'Enter User number to use (0-15)    ===>';
            get userno;
            picture '99'
    @  5,0  say 'Enter the Disk Drive to search'
    @  6,0  say '       A: or B:                    ===>';
            get drive1;
            picture '!'
    @  8,0  say 'Enter type of search to do'
    @  9,0  say '  ie. ????????.??? will display entire directory'
    @ 10,0  say '      ????????.CMD will display all files with'
    @ 11,0  say '                    CMD as a file type'
    @ 13,0  say '  Enter search string              ===>';
            get findme;
            picture '!!!!!!!!!!!!'
*
    read
*
    if  userno < 0 .or.;
        userno > 15
        store t to badusr
        @ 22,0  say 'ERROR - the user number must be from 0 to 15'
    else
        store f to badusr
        @ 22,0
    endif  userno
*
*
    if  drive1 = 'A' .or.;
        drive1 = 'B'
        store f to badrv
        @ 21,0 say '                                           '
    else
        store t to badrv
        @ 21,0 say 'ERROR - the selected drive must be A: or B:'
    endif  drive1
*
*
    store @('.',findme) to dotpos
*
    if  dotpos = 0
        store t to badstr
        @ 23,0  say 'ERROR - search string not appropriate '
    else
        store f to badstr
        @ 23,0  say '                                      '
    endif  findme
*
enddo  badusr/badstr
*
*                 take the '.' out of the search string
*
store $(findme,1,dotpos-1)+$(findme,dotpos+1,len(findme)-dotpos);
      to stringin
*
*        convert ascii to decimal (value returned in "stringout")
*
do asciidec
*
*        poke the function (01h = show dir)
*
poke addrfunc,1
*
*        poke in search string to memory
*
poke addrsearch,&stringout
*
*        convert the user number 0-15 to 0-F
*
store $(hextbl,userno+1,1) to stringin
*
*        convert ascii to decimal
*
do asciidec
*
*            now make the user number hex 0-F binary
*
store val(stringout)-48 to num1
store str(num1,2)       to stringout
*
*            poke in the user number
*
*
poke addrusr,&stringout
*
*            convert ascii to decimal
*
store drive1 to stringin
*
do asciidec
*
*            now make drive 0-F binary
*
store val(stringout)-64 to num1
store str(num1,2)       to stringout
*
*            poke the drive to memory
*
poke addrdrv,&stringout
*
*            set up the call address to the assembler routine that
*              has been pre-loaded into high memory at addrdir
*
set call to addrdir
store 'dummy' to adress
*
*        do the call
*
erase
    call
return
