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 / CATLOG / LABEL.AQM / LABEL.ASM
Assembly Source File  |  2000-06-30  |  14KB  |  621 lines

  1. ;**************** BYPASS CUSTOMIZING SECTION ************************
  2.     ORG    100H
  3.     JMP    START
  4. ;********************************************************************
  5. ;
  6. ; TITLE: DLABEL.ASM        Author: R.Bascom
  7. ;
  8. P$LOGON    DB    'DLABEL 1.0   24/11/85',0Dh,0Ah,0Ah,'$'
  9. ;
  10. ; PURPOSE: To print an alphabetically sorted disk directory on a 
  11. ;       label in small (condensed) font.
  12. ;
  13. ; FEATURE: (1)    The condensed font is used for the main directory.
  14. ;       (2)    The program can be repeated, using the same drive
  15. ;        and optional filenames.  Allowing for labeling 
  16. ;        numerous disks at one time.
  17. ;
  18. ; USAGE:   DLABELER [D][FILENAME.TYP]
  19. ;
  20. ;                  D = disk (i.e. A:, B:, ect)
  21. ;        filename.typ = filename using conventional wildcards
  22. ;
  23. TRUE    EQU    0FFh
  24. FALSE    EQU    00h
  25. ;
  26. ;*********************** PROGRAM EQUATES ****************************
  27. ;
  28. MAXFILS        EQU    255    ;maximum number of directory entries
  29. BDOS        EQU    5
  30. FCB        EQU    5Ch     ;first file control block
  31. ;
  32. CR        EQU    0Dh    ;carriage return
  33. LF        EQU    0Ah    ;line feed
  34. ESC        EQU    1Bh    ;escape
  35. BELL        EQU    7    ;bell
  36. CTL$C        EQU    3    ;end of text
  37. ;
  38. ;
  39. ;*********************** BDOS EQUATES *******************************
  40. ;
  41. B$CONIN        EQU    1    ;read CON byte
  42. B$CONOUT    EQU    2    ;write CON byte
  43. B$LISTOUT    EQU    5    ;write PRN byte
  44. B$DIRCONIO    EQU    6    ;direct CON input and output
  45. B$PRINTS    EQU    9    ;write a $ terminated string to CON
  46. B$CONST        EQU    11    ;read CON status
  47. B$RESETDSK    EQU    13    ;reset disk system
  48. B$SEARCHF    EQU    17    ;search for first name match
  49. B$SEARCHN    EQU    18    ;search for next name match
  50. ;
  51. ;******************** CUSTOMIZING SECTION ***************************
  52. ;
  53. V$COLUMNS    DB    60    ;number of label columns (maximum of 
  54.                 ;250 columns) based on char per inch
  55.                 ;of condensed fontè;
  56. V$ROWS        DB    8     ;number of label rows based on the
  57.                 ;line spacing
  58. ;
  59. V$SPACES    DB    1       ;lines btwn labels (based on line spacing)
  60. ;
  61. ;This string is the divider fence that is printed between filenames and can 
  62. ;be changed as desired.  The divider is not printed before the first or after
  63. ;the last filename on a line.  String can have a maximum of of 5 chars and
  64. ;must end with $.   NOTE the first byte is the char count.
  65. ;
  66. V$FENCE    DB    3            ;char count (# of divider chars)
  67.     DB    ' | '            ;the divider chars
  68.     DB    '$'            ;end of string
  69.     DB    0,0            ;spares
  70. ;
  71. ;******************** PRINTER CONTROL STRINGS ***********************
  72. ;
  73. ;This string is used to set line spacing (usually to 9 LPI) and small print
  74. ;font (usually condensed).  It may include any printer characteristics you
  75. ;desire.  String can have a maximum of 15 chars and must end with $.
  76. ;
  77. V$CONDENST:
  78.     DB    ESC,'B',3        ;set pitch to condensed (17 CPI)
  79.     DB    ESC,'A',8        ;set line spacing to 8/72
  80.     DB    '$'            ;end of string 
  81.     DB    0,0,0,0,0,0,0,0,0,0,0    ;spares
  82. ;
  83. ;This string is used to return printer to its normal line spacing (usually
  84. ;6 LPI) and normal print font (usually 10 CPI).  It may also include any 
  85. ;printer characteristics you desire.  String can have a maximum of 15 chars
  86. ;and must end with $.
  87. ;
  88. V$RESETST:
  89.     DB    ESC,'@'            ;reset the printer
  90.     DB    '$'            ;end of string 
  91.     DB    0,0,0,0,0,0,0,0,0,0,0,0    ;spares
  92. ;
  93. ;****************** END OF CUSTOMIZING SECTION *************************
  94.  
  95. ;***********************************************************************
  96. ;***********************************************************************
  97. ;                M A I N   P R O G R A M
  98. ;***********************************************************************
  99. ;
  100. START:
  101.     LXI    SP,STACK    ;get new stack
  102. ;
  103. ;save disk for restarting later
  104. ;
  105.     LXI    H,FCB
  106.     MOV    A,M
  107.     STA    SAVEFCB
  108. ;
  109. ;type logonè;
  110.     LXI    D,P$LOGON
  111.     MVI    C,B$PRINTS
  112.     CALL    BDOS
  113. ;----------------
  114. ;
  115. ;calculate label width (in number of filenames/fences across the label)
  116. ;
  117.     LDA    V$FENCE        ;number of fence chars
  118.     MVI    H,12        ;plus number chars for filename
  119.     ADD    H
  120.     MOV    B,A        ;B = number of chars per filename/fence
  121. ;
  122.     XRA    A        ;clear flags
  123.     LDA    V$COLUMNS    ;number of columns
  124.     CPI    251        ;maximum number of columns is 250 (FAh)
  125.     JNC    COLERR        ;err if max num of colums is exceeded
  126.     MOV    H,A    
  127.     LDA    V$FENCE        ;plus length of one fence
  128.     ADD    H        ;A = line length and one fence length
  129. ;
  130.     MVI    C,0        ;C is the dividend
  131.     ANA    A        ;prepare for divide - clear carry
  132. ;    
  133. ;mod divide A by B
  134. ;
  135. LWID:
  136.     SUB    B        ;repeated subtraction
  137.     JC    LWID1
  138.     INR    C        ;count the number of subtractions
  139.     JMP    LWID
  140. LWID1:
  141.     MOV    A,C        ;
  142.     CPI    0        ;check for zero filename width
  143.     JZ    LWIDERR        ;  then error
  144.     STA    LBLWID        ;  else save the width
  145. ;----------------
  146. ;
  147. ;check number of rows 
  148. ;
  149. CKROWS:
  150.     LDA    V$ROWS
  151.     CPI    0
  152.     JZ    ROWERR        ;err if zero rows calculated
  153. ;----------------
  154. ;
  155. ;set maximum number of files
  156. ;
  157. SETMFIL:
  158.     LDA    V$ROWS        ;get the number of filenames wide
  159.     MOV    B,A
  160.     LDA    LBLWID        ;get the number of rows
  161.     MOV    C,A
  162.     XRA    A        ;zero A and clear carry
  163. SETMFIL1:è    ADD    C
  164.     JC    MFILERR        ;error if count exceeds 255 (FFh)
  165.     DCR    B
  166.     JNZ    SETMFIL1
  167.     STA    MAXFIL        ;maximum possible filenames on a label
  168. ;----------------
  169. ;
  170. ;got something - set up the printer
  171. ;
  172.     LXI    H,V$CONDENST    ;set condensed print
  173.     CALL    WRPRNT        ;send initialization string to printer 
  174. ;----------------
  175. ;
  176. ;able to restart the program here using the same command tail
  177. ;
  178. REINIT:
  179.     MVI    A,0    
  180.     STA    COUNT        ;clear counters
  181.     STA    SCOUNT
  182.     STA    WCOUNT
  183.     STA    LCOUNT
  184.     STA    SWITCH
  185. ;----------------
  186. ;
  187. ;does the command tail exist?
  188. ;
  189.     LDA    SAVEFCB        ;restore disk
  190.     STA    FCB
  191.     LXI    H,FCB+1        ;set pointer first char of FCB
  192.     MOV    A,M
  193.     CPI    ' '
  194.     JNZ    GOTFCB        ;yes, comand tail exists
  195. ;
  196. ;command tail does not exist
  197. ;
  198.     MVI    B,11        ;initial filename and filetype count
  199. QLOOP:
  200.     MVI    M,'?'        ;store '?' in FCB
  201.     INX    H
  202.     DCR      B
  203.     JNZ    QLOOP
  204. ;
  205. ;look up the FCB in the directory
  206. ;
  207. GOTFCB:
  208.     LDA    V$ROWS        ;initialize # of lines remaining on
  209.     STA    LCOUNT        ;   label to full count
  210.     MVI    C,B$SEARCHF     ;search for first name match
  211.     LXI    D,FCB
  212.     CALL    BDOS        ;read first
  213.     INR    A        ;were there any?
  214.     STA    TEMP        ;save extent
  215.     JZ    FNFERR        ;didn't get any
  216.     LDA    TEMP        ;reload extent
  217. ;----------------è;
  218. ;point to directory entry 
  219. ;
  220. SOME:
  221.     DCR    A        ;undo previous INR A
  222.     ANI    3        ;make modulus 4
  223.     ADD    A        ;multiply
  224.     ADD    A        ;  by 32 because
  225.     ADD    A        ;  each directory
  226.     ADD    A        ;  entry is 32
  227.     ADD    A        ;  bytes long
  228.     LXI    H,81H        ;point to buffer (skip to FN/FT)
  229.     ADD    L        ;point to entry
  230.     MOV    L,A        ;save (can't carry to H)
  231.     LDA    MAXFIL        ;is there room in table for entry ?
  232.     MOV    B,A
  233.     LDA    COUNT
  234.     CMP    B
  235.     JZ    TMFERR        ;err - too many files for the label
  236. ;
  237. ;move entry to table
  238. ;
  239.     XCHG            ;entry to DE
  240.     LHLD    NEXTT        ;next table entry to HL
  241.     MVI    B,31        ;entry length
  242. TMOVE:
  243.     LDAX    D        ;get entry char
  244.     MOV    M,A        ;store in table
  245.     INX    D
  246.     INX    H
  247.     DCR    B        ;more?
  248.     JNZ    TMOVE
  249.     SHLD    NEXTT        ;save updated table adx
  250.     LDA    COUNT        ;get previous count
  251.     INR    A
  252.     STA    COUNT
  253. ;
  254. ;read more directory entries        
  255. ;
  256.     MVI    C,B$SEARCHN     ;search for next name match
  257.     LXI    D,FCB
  258.     CALL    BDOS        ;read dir entry
  259.     INR    A        ;check for end (0FFh)
  260.     JNZ    SOME        ;more 
  261. ;----------------
  262. ;
  263. ;sort filenames
  264. ;
  265.     LDA    COUNT        ;init the order table
  266.     STA    SCOUNT        ;save as # to sort
  267.     LXI    H,ORDER
  268.     LXI    D,TABLE
  269.     LXI    B,31        ;entry length
  270. BLDORD:    
  271.     MOV    M,E        ;save LO order adxè    INX    H
  272.     MOV    M,D        ;save HI order adx
  273.     INX    H
  274.     XCHG            ;table adx to HL
  275.     DAD    B        ;point to next entry
  276.     XCHG
  277.     DCR    A        ;more?
  278.     JNZ    BLDORD        ;  yes
  279. SORT    XRA    A        ;get a zero
  280.     STA    SWITCH        ;show none switched
  281.     LDA    SCOUNT        ;get count
  282.     DCR    A        ;use 1 less
  283.     STA    TEMP        ;save # to compare
  284.     STA    SCOUNT        ;save highest entry
  285.     JZ    DONE        ;exit if no more
  286.     LXI    H,ORDER     ;point to order table
  287. SORTLP    CALL    COMPR        ;compare 2 entries
  288.     CM    SWAP        ;swap if not in order
  289.     INX    H        ;bump order
  290.     INX    H        ;  table pointer
  291.     LDA    TEMP        ;get count
  292.     DCR    A
  293.     STA    TEMP
  294.     JNZ    SORTLP        ;continue
  295. ;
  296. ;one pass of sort done
  297. ;
  298.     LDA    SWITCH        ;any swaps done?
  299.     ORA    A
  300.     JNZ    SORT
  301. ;
  302. ;sort is all done - print entries
  303. ;
  304. DONE    LXI    D,ORDER        ;DE point to 1st entry in ORDER
  305.     PUSH    D        ;Save DE
  306.     LDA    LBLWID        ;get initial count of filenames per line
  307.     STA    WCOUNT        ;   and save it for a counter
  308. ;----------------
  309. ;
  310. ;print the label
  311. ;
  312. PRINT:
  313.     MVI    C,B$CONST    ;check status of keyboard
  314.     CALL    BDOS        ;are any keys pressed?
  315.     DCR    A
  316.     JZ    0        ;yes, abort
  317.     POP    D        ;restore DE
  318.     LDAX    D        ;no - get memory byte addressed by DE
  319.     MOV    L,A        ;   and put in L
  320.     INX    D        ;move to next location in ORDER
  321.     LDAX    D        ;get memory byte addressed by DE
  322.     MOV    H,A        ;   and put in L
  323.     INX    D        ;move to next location in ORDER
  324.     PUSH    D        ;   and save DE
  325.     MVI    B,8        ;file name lengthè    CALL    TYPEIT        ;type filename
  326.     MVI    E,'.'
  327.     CALL    TYPE  
  328.     MVI    B,3        ;get the filetype
  329.     CALL    TYPEIT
  330. ;
  331. ;check for last directory entry
  332. ;
  333.     LDA     COUNT        ;decrement count of file names to print
  334.     DCR    A
  335.     STA    COUNT
  336.     JZ    TOP        ;exit if count is zero
  337. ;
  338. ;check for maximum directory entries on current row
  339. ;
  340. WFENCE    LDA    WCOUNT        ;decrement # of entries left on this
  341.     DCR    A        ;  line for filenames
  342.     STA    WCOUNT
  343.     JZ    NXTLIN        ;no more room on line so skip divider fence
  344. ;
  345. ;divider fence goes to the printer
  346. ;
  347.     LXI    H,V$FENCE+1    ;since there is room for another filename 
  348.       CALL    WRPRNT        ;   put divider fence btwn filenames
  349.     JMP    PRINT
  350. ;
  351. ;end of current line
  352. ;
  353. NXTLIN:
  354.     CALL    CRLF        ;output CR/LF 
  355.     JMP    PRINT        ;go to print next line and file name
  356. ;----------------
  357. ;
  358. ;completed printing the directory entries, now set up for next label
  359. ;
  360. TOP:
  361.     LDA    LCOUNT        ;number of remaining lines in the label
  362.     CPI    0        ;done?
  363.     JZ    TOP2        ;yes, then space out btwn labels
  364.     CALL    CRLF        ;no, send out CR/LF 
  365.     JMP    TOP        ;try again
  366. ;
  367. TOP2:
  368.     LDA    V$SPACES    ;get number of lines btween labels
  369. TOP3:
  370.     CPI    0        ;done
  371.     JZ    AGAIN        ;yes, then ask if another label desired
  372.     PUSH    A        ;no, spaceing line count
  373.     CALL    CRLF        ;send out CR/LF
  374.     POP     A        ;restore spacing line count
  375.     DCR    A        ;decrement count
  376.     JMP    TOP3        ;try again
  377. ;----------------
  378. ;
  379. ;do another label or exit?è;
  380. AGAIN:    
  381.     LDA    SAVEFCB
  382.     CPI    0
  383.     JNZ    AGAIN1        ;zero means use current disk
  384.     LDA    4        ;get curent disk and user
  385.     ANI    0Fh        ;bits 0-3 are the current disk
  386.     INR    A
  387. AGAIN1:
  388.     ADI    '@'        ;change to alfa 1->A, 2->B,...ect.
  389.     STA    CDR1        ;set drive in prompt
  390.     CALL    ILPRT
  391.     DB    'Mount another DISK TO BE LABELED in Drive '
  392. CDR1:
  393.     DB    'A:'        ;hot-patched to show correct drive
  394.     DB    ' Ready? (Y/N): ',0
  395. AGAIN2:
  396.     MVI    C,B$DIRCONIO    ;direct input from keyboard
  397.     MVI    E,TRUE        ;  true = read keyboard char 
  398.     CALL    BDOS
  399.     CPI    'N'        ;N exits
  400.     JZ    EXIT
  401.     CPI    'n'        ;and little n too
  402.     JZ    EXIT
  403.     CPI    ' '        ;accept space as yes
  404.     JZ    AGAIN3
  405.     CPI    CR        ;accept CR as yes
  406.     JZ    AGAIN3
  407.     CPI    'Y'        ;accept Y
  408.     JZ    AGAIN3
  409.     CPI    'y'        ;and little y
  410.     JNZ    AGAIN2        ;anything else is not accepted
  411. ;
  412. AGAIN3:
  413.     CALL    ILPRT
  414.     DB    CR,'                                          '
  415.     DB    '                    ',CR,0
  416.     MVI    C,B$RESETDSK    ;reset the disks
  417.     CALL    BDOS        
  418.     JMP    REINIT    
  419. ;----------------
  420. ;
  421. ;reset the printer and return to CP/M 
  422. ;
  423. EXIT:
  424.     MVI    A,CR        ;CR
  425.     CALL    CRTOUT
  426.     MVI    A,LF        ;LF
  427.     CALL    CRTOUT
  428.     LXI    H,V$RESETST    ;reset printer to Normal mode
  429.     CALL    WRPRNT
  430.     JMP    0
  431. ;--------------------------------------------------------------------
  432. ;
  433. ;            S U B R O U T I N E Sè;
  434. ; Inline print subroutine
  435. ;
  436. ILPRT:    XTHL            ;get starting address of string to 'HL'
  437. ;
  438. ILPLP:    MOV    A,M
  439.     PUSH    H
  440.     CALL    CRTOUT        ;show the character on the CRT
  441.     POP    H
  442.     INX    H
  443.     MOV    A,M
  444.     ORA    A
  445.     JNZ    ILPLP
  446.     INX    H
  447.     XTHL            ;return address to top of stack
  448.     RET
  449. ;----------------
  450. ;
  451. ; Displays one character on the CRT
  452. ;
  453. CRTOUT:    PUSH    PSW        ;save the character
  454.     MVI    C,B$CONOUT
  455.     MOV    E,A        ;get the character into 'E' reg.
  456.     CALL    BDOS        ;show the character on the crt
  457.     POP    PSW        ;get the character back
  458.     RET
  459. ;----------------
  460. ;
  461. ;char in E goes to the printer
  462. ;
  463. TYPE    PUSH    B
  464.     PUSH    D
  465.     PUSH    H
  466.     MVI    C,B$LISTOUT
  467.     CALL    BDOS
  468.     POP    H
  469.     POP     D
  470.     POP    B
  471.     RET
  472. ;----------------
  473. ;
  474. ;string specified by HL goes to the printer
  475. ;
  476. WRPRNT    MVI    A,'$'
  477.     CMP    M
  478.     RZ 
  479.     MOV    E,M
  480.     CALL    TYPE
  481.     INX    H
  482.     JMP    WRPRNT
  483. ;----------------
  484. ;
  485. ;string specified by HL and length in B goes to the printer
  486. ;with any tag bits stripped off
  487. ;èTYPEIT:
  488.     MOV    A,M        ;get rid of any tag bits in name
  489.     ANI    07Fh        ; for print out
  490.     MOV    E,A
  491.     CALL    TYPE
  492.     INX    H
  493.     DCR    B
  494.     JNZ    TYPEIT
  495.     RET
  496. ;----------------
  497. ;
  498. ;CR/LF go to the printer and
  499. ;reset label width counter and decrement line counter
  500. ;
  501. CRLF:
  502.     MVI    E,CR        ;get CR character in E
  503.     CALL    TYPE        ; and output it
  504.     MVI    E,LF        ;get LF character in E
  505.     CALL    TYPE        ; and output it
  506. ;
  507.     LDA    LBLWID        ;reset number of filenames across label
  508.     STA    WCOUNT
  509. ;
  510.     LDA    LCOUNT        ;decrement line count
  511.     DCR    A 
  512.     STA    LCOUNT 
  513. ;
  514.     RET
  515. ;---------------- 
  516. ;
  517. ;compare routine for sort
  518. ;
  519. COMPR:
  520.     PUSH    H        ;save table adx
  521.     MOV    E,M        ;load LO
  522.     INX    H
  523.     MOV    D,M        ;load HI
  524.     INX    H
  525.     MOV    C,M
  526.     INX    H
  527.     MOV    B,M
  528. ;
  529. ;BC and DE now point to entries to be compared
  530. ;
  531.     XCHG
  532. CMPLP:
  533.     MOV    A,M        ;get rid of any tag bit in name
  534.     ANI    07FH        ; before comparing names for sort
  535.     MOV    M,A
  536.     LDAX    B
  537.     ANI    07FH
  538.     CMP    M
  539.     INX    H
  540.     INX    B
  541.     JZ    CMPLPè    POP    H
  542.     RET            ;cond code tells all
  543. ;----------------
  544. ;
  545. ;swap entries in the order table
  546. ;
  547. SWAP:
  548.     MVI    A,1
  549.     STA    SWITCH        ;show a swap was made
  550.     MOV    C,M
  551.     INX    H
  552.     PUSH    H        ;save table adx+1
  553.     MOV    B,M
  554.     INX    H
  555.     MOV    E,M
  556.     MOV    M,C
  557.     INX    H
  558.     MOV    D,M
  559.     MOV    M,B
  560.     POP    H
  561.     MOV    M,D
  562.     DCX    H        ;back pointer to correct location
  563.     MOV    M,E
  564.     RET
  565. ;----------------
  566. ;
  567. ;        E R R O R   R O U T I N E S
  568. ;
  569. COLERR:
  570.     CALL    ILPRT
  571.     DB    CR,LF,'++ YOUR SETTINGS ALLOW MORE THAN 250 COLUMNS ++'
  572.     DB    BELL,0
  573.     JMP    0
  574. ;
  575. LWIDERR:
  576.     CALL    ILPRT
  577.     DB    CR,LF,'++ YOUR SETTINGS DO NOT ALLOW AT LEAST 12 COLUMNS ++'
  578.     DB    BELL,0
  579.     JMP    0
  580. ;
  581. ROWERR:
  582.     CALL    ILPRT
  583.     DB    CR,LF,'++ YOUR SETTINGS DO NOT ALLOW ANY ROWS ON A LABEL ++'
  584.     DB    BELL,0
  585.     JMP    0
  586. ;
  587. MFILERR:
  588.     CALL    ILPRT
  589.     DB    CR,LF,'++ YOUR SETTINGS ALLOW MORE THAN 255 FILENAMES ++'
  590.     DB    BELL,0
  591.     JMP    0
  592. ;
  593. FNFERR:
  594.     CALL    ILPRT    
  595.         DB    CR,LF,'++ FILE(S) NOT FOUND ++',CR,LF,0è    JMP    AGAIN        ;try another disk or exit
  596. ;
  597. TMFERR:
  598.     CALL    ILPRT
  599.     DB    CR,LF,'++ TOO MANY FILENAMES ++',CR,LF,0
  600.     JMP    AGAIN        ;try another disk or exit 
  601. ;
  602. ;
  603. ;
  604. ;    
  605. ;
  606. NEXTT    DW    TABLE        ;next table entry
  607. LBLWID    DB    0        ;label width = (V$COLUMNS+V$FENCE)/(12+V$FENCE)
  608. MAXFIL    DB    0        ;max number of disk filenames on one label
  609. COUNT    DB    0        ;entry count
  610. SCOUNT    DB    0        ;# to sort
  611. WCOUNT    DB    0        ;# of filename sapces left across line
  612. LCOUNT    DB    0        ;# of lines remaining on this Label
  613. SWITCH    DB    0        ;swap switch for sort
  614. SAVEFCB DB    0        ;save disk FCB
  615. TEMP    DS    1
  616. ORDER    DS    2*MAXFILS    ;order table
  617.     DS    50        ;stack area
  618. STACK
  619. TABLE    DB    0        ;read entries from here to top of BDOS
  620.     END    100H
  621.