home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / a / dbdir.lbr / DBDIR.AZM / DBDIR.ASM
Encoding:
Assembly Source File  |  1993-10-26  |  7.0 KB  |  355 lines

  1.      page    58
  2. ;    dbdir.asm      
  3. ;
  4. ;
  5. ;        THIS PROGRAM WILL ...
  6. ;            produce a directory list on the
  7. ;            console and will be called from dBASEII.
  8. ;                        - Mike Kelly
  9. ;
  10. ;    08-20-82  v1.0    written
  11. ;
  12. ;    08-22-82  v1.0     updated
  13. ;    08-30-82  v1.1    Add routine to load the program to upper memory
  14. ;            when it has been assembled in lower memory. To
  15. ;            do this requires adding a base number (offset)
  16. ;            to all labels and variables so that after the
  17. ;            move to upper memory, all addresses will have
  18. ;            been adjusted properly.
  19. ;    09-20-82  v1.2    Changed routine to add function byte to 
  20. ;            select which function of this routine.
  21. ;            Expanded routine to add set user function.
  22. ;
  23. ;                Function:
  24. ;                   00h = alter user number
  25. ;                   01h = show directory
  26. ;    01-20-83   v1.3    Added seperator between filenames in display.
  27. ;
  28. ;
  29.     global    tcmd,tfcb,bldfcb,loop1,prtit
  30.     global    srchnxt,end
  31.     global    linecnt,diroffset,prtfn
  32.     global    srchfrst,prtspace,prtdot,prtcrlf
  33.     global    nohit,findme,notfound,count
  34.     global    function,setusr,showdir,badfunc
  35.     global    badbyte,user,usrmsg
  36. ;
  37. ;SYSTEM EQUATES
  38. ;
  39. cr    equ    0dh        ;carriage return
  40. lf    equ    0ah        ;line feed
  41. esc    equ    1bh        ;escape
  42. exitcpm    equ    0        ;warmboot exit point
  43. base    equ    0        ;find wboot jmp address at rst0
  44. dumyadr    equ    0
  45. tfcb    equ    5ch        ;default fcb
  46. tcmd     equ    80h        ;default command line and DBA addr       
  47. tbuf    equ    80h        ;default buffer
  48. bdos    equ    5        ;CP/M function calls entry point
  49. entsize equ    13        ;bytes per sorted directory entry
  50. ;                ; includes: 1-2   for user number
  51. ;                ;           3-13  for fn,ft (no period)
  52. pagesize equ    20        ;# of lines to print on a page
  53. dirsect  equ    26        ;# of sectors in directory track
  54. tpa     equ    100h
  55. dbasetop equ    00400h        ;free memory above dBASEII (a400h-a000h)
  56. dbload     equ    00500h        ;load asm. routine here
  57. x     equ    0a000h        ;offset to add to all labels and     
  58.                 ; variables
  59. ;
  60. ;
  61.     aseg
  62.      org    tpa 
  63. ;
  64. ;                ;this routine will move the code at
  65. ;                ; 400h to a400h
  66. ;
  67.     ld    hl,st1        ;from address
  68.     ld    de,x+dbasetop    ;to address
  69.     ld    bc,fini1-st1    ;length
  70.     ldir            ;move it
  71. ;
  72. ;                ;this routine will move the code at
  73. ;                ; 500h to a500h
  74. ;
  75.     ld    hl,start    ;from address
  76.     ld    de,x+dbload    ;to address
  77.     ld    bc,fini-start    ;length
  78.     ldir            ;do the move
  79. ;
  80.      jp    x+start        ;then jump to the newly moved code
  81. ;    jp    exitcpm
  82. ;
  83.      org    dbasetop        ;put variables here
  84. ;
  85. st1:                    ;start of variables
  86. ;
  87. function:
  88.     db    01h            ;function byte
  89. ;                    ; 0 = set user
  90. ;                    ; 1 = show directory
  91. findme:  
  92.     db    '???????????'        ;directory entry to look for
  93. userno:
  94.     db    00h            ;user number
  95. drive:
  96.     db    00h            ;drive to search
  97. junk:
  98.     db    'end of storage used by dbdir'
  99. ;
  100. fini1:                         ;end of variables
  101. ;
  102. ;
  103.      org    dbload
  104. ;
  105. ;
  106. start:
  107.     ld    (x+oldstack),sp        ;save current stack pointer
  108.     ld     sp,x+stack            ;set stack pointer to my stack
  109. ;
  110.     push    psw            ;save the world
  111.     push    bc
  112.     push    de
  113.     push    hl
  114. ;
  115.     ld    a,(x+function)        ;get function
  116.     cp    00h            ;=00h then set user
  117.     jp    z,x+setusr
  118.     cp    01h            ;=01h then show directory
  119.     jp    z,x+showdir
  120.     jp    x+badfunc        ;bad function passed 
  121. ;
  122. setusr:
  123.     call    x+user
  124.     ld     de,x+usrmsg
  125.     call    x+sout
  126.     call    bdos
  127.     jp    x+end
  128. ;
  129. showdir:
  130.     ld    de,x+dirmsg        ;print signon msg
  131.     call    x+sout
  132.     ld    bc,0000h        ;init count
  133.     ld    (x+count),bc
  134. ;
  135.     call    x+setdma        ;set dma to addr of tbuf(80h)
  136.     call    x+bldfcb
  137.     call    x+srchfrst        ;get 1st entry
  138.     jp    z,x+nohit          ;=z,no entry found
  139.           call    x+prtit 
  140. loop1:
  141.     call    x+srchnxt        ;get n+1 entry
  142.     jp    z,x+end          ;=z,all done
  143.     call    x+prtit            ;print the entry
  144.     jp    x+loop1            ;loop til done
  145. ;
  146. bldfcb:
  147.     ld    a,(x+drive)        ;get drive byte
  148.     ld    (tfcb),a             ;put in fcb
  149. ;
  150.     ld    hl,x+findme        ;sending addr (search string)
  151.     ld    de,tfcb+1            ;receiving addr
  152.     ld    bc,000bh        ;count of 11
  153.     ldir                ;do move
  154.     ret
  155. ;
  156. prtit:
  157.     ld    a,(x+count)        ;check how many entries have
  158.     cp      05h            ; printed-only 5 per line
  159.     call    z,x+prtcrlf
  160.     inc    a            ;up count
  161.     ld    (x+count),a
  162. ;
  163.     ld    hl,tbuf+1             ;addr of buffer
  164.     ld    bc,(x+diroffset)    ;offset into directory entry
  165.     ld    b,00h
  166.     add    hl,bc
  167.     ld    bc,000bh        ;count of 11
  168. ;
  169.     call    x+prtspace            ;format print of each entry
  170.     ld    bc,0008h
  171.     call    x+prtfn
  172.     call    x+prtdot
  173.     ld    bc,0003h
  174.     call    x+prtfn
  175.     call    x+prtgate
  176.     ret
  177. ;
  178. prtspace:
  179.     ld    e,' '
  180.     call    x+conout
  181.     ret
  182. ;
  183. prtgate:
  184.     ld    e,'|'
  185.     call    x+conout
  186.     ret
  187. ;
  188. prtdot:
  189.     ld    e,'.'
  190.     call    x+conout
  191.     ret
  192. ;
  193. prtcrlf: 
  194.     ld    de,x+crlf
  195.     call    x+sout
  196.      xor    a            ;put zero in A
  197.      ld    (x+count),a        ;zero out count
  198.     ret
  199. ;
  200. prtfn:  
  201.     ld    e,(hl)            ;get a char
  202.     call    x+conout        ;print it
  203.     inc    hl            ;point to next char
  204.     dec    c            ;dec count
  205.     ret    z            ;return if done
  206.     jp    x+prtfn          ;loop til done
  207. ;
  208. nohit:    
  209.     ld    de,x+notfound
  210.     call    x+sout
  211.     jp    x+end
  212. ;
  213. badfunc:
  214.     ld    de,x+badbyte
  215.     call    x+sout
  216.     jp    x+end
  217. ;
  218. end:
  219.     pop    hl            ;put the world back as you 
  220.     pop    de            ; found it
  221.     pop    bc
  222.     pop    psw
  223.     ld    sp,(x+oldstack)        ;dont forget the stack
  224.      ret                ;ret, not jp to 0
  225. ;
  226. ;
  227. ;
  228. ;
  229. conin:
  230.           ld      c,1     
  231.     call    bdos
  232.     ret
  233. conout:
  234.     push    psw
  235.     push    bc
  236.     push    de
  237.     push    hl
  238.            ld     c,2      
  239.     call    bdos
  240.     pop    hl
  241.     pop    de
  242.     pop    bc
  243.     pop    psw
  244.     ret
  245. dirin:
  246.     ld    c,6
  247.     ld    e,0ffh
  248.     call    bdos
  249.     cp    00h             ;=00h, then char not ready
  250.     jp    z,x+dirin        ; will want to wait for it
  251.     ret
  252. sout:
  253.            ld     c,9                     ;write string to console
  254.     call    bdos
  255.     ret
  256. ;
  257. setdma:
  258.     ld    c,1ah            ;set dma addr to 80h
  259.     ld    de,tbuf
  260.     call    bdos
  261.     ret
  262. user:    
  263.     ld    a,(x+userno)        ;set user number
  264.     ld    e,a
  265.     ld    c,20h
  266.     call    bdos
  267.     ret
  268. ;
  269. srchfrst:                ;do search first
  270.     call    x+user            ;alter user #
  271. ;
  272.     ld    c,11h            ;bdos search 1st
  273.     ld    de,tfcb            ;de with addr of fcb
  274.     call    bdos
  275.     push    psw            ;save A register and z flag
  276.     add    a,a            ;adjust A to get offset to
  277.     add    a,a            ; the found entry
  278.     add    a,a
  279.     add    a,a
  280.     add    a,a
  281.     ld    (x+diroffset),a        ;save the offset
  282.     pop    psw            ;get the original value of A
  283.     inc    a            ;to detect 0ffh
  284.     ret
  285. ;
  286. srchnxt:                ;do search next
  287. ;                    ;  will only set srcheof flag
  288. ;                    ;   when have checked all users
  289.     ld    c,12h
  290.     call    bdos
  291.     push    psw            ;save A register and z flag
  292.     add    a,a            ;adjust A to get offset to
  293.     add    a,a            ; the found entry
  294.     add    a,a
  295.     add    a,a
  296.     add    a,a
  297.     ld    (x+diroffset),a        ;save the offset
  298.     pop    psw            ;get the original value of A
  299.     inc    a            ;to detect 0ffh
  300.     ret    
  301. ;
  302. ;
  303. ;
  304. ;        Variables
  305. ;
  306. count:
  307.     db    00h,00h
  308. linecnt:
  309.     db    00h            ;count of # of lines printed
  310.                     ; init at 2 for heading
  311. diroffset:
  312.     db    00h            ;offset into directory entry
  313. ;                    ; returned by bdos search,
  314. ;                    ; incremented by 32, max.
  315. ;                    ; should be 255
  316. ;
  317. dirmsg:
  318.     db    cr,lf
  319.     db    'dBASEII directory routine'
  320.     db    cr,lf
  321.     db    'Version 1.3     '
  322.     db    '01-20-83'
  323.     db    cr,lf
  324.     db    '$'
  325. notfound:
  326.            db    '++ Entry not found ++'
  327.     db    '$'
  328. usrmsg:
  329.     db    cr,lf
  330.     db    'User number has been altered'
  331.     db    cr,lf
  332.     db    '$'
  333. badbyte:
  334.     db    '++ Invalid function passed ++'
  335.     db    cr,lf
  336.     db    '$'
  337. anykey:
  338.     db    '                         '
  339.     db    'Press any key to continue'
  340.     db    cr
  341.     db    '$'
  342. crlf:  
  343.     db    cr,lf
  344.     db    '$'
  345. stktop: ds    64                    ;top of stack
  346. stack:    ds    1                    ;stack          
  347. oldstack:                ;saves old stack pointer
  348.     dw    0000h
  349. junk2:
  350.     db    'after old stack'
  351. ;
  352. fini:
  353.      end
  354.