home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / zcat / timestmp.lbr / TIMESTMP.MQC / TIMESTMP.MAC
Text File  |  1991-01-31  |  8KB  |  375 lines

  1. Title Time stamp   VERS:- 00.02  DATE:- 08/01/82  TIME:- 01:35:45
  2.  
  3. ;************************************************************
  4. ;*
  5. ;*    File Tracking Program
  6. ;*    by Eric Forbes
  7. ;*    c/o Mississauga, Ont. Canada RCP/M System
  8. ;*     (416) 826-5394
  9. ;*
  10. ;************************************************************
  11. ;Copyright (c) 1982, E. Forbes; permission granted to use,
  12. ;copy and distribute for non-commercial purposes.
  13.  
  14.  
  15. ;QUICK VIEW:  Increment version and insert date and time each
  16. ;          time a file is assembled / edited. See top line
  17.  
  18.  
  19. ;To use the 'DATE:- ' and 'TIME:- ' functions, this program
  20. ;expects to find three consecutive bytes at MONTH and HOUR,
  21. ;in BCD format. E.G. to print the date 07/31/82, the bytes
  22. ;07H 31H 82H should be available at HOUR, HOUR+1 and HOUR+2
  23.  
  24. ;If you do not have a clock ignore the 'month' and 'hour'
  25. ;equates. They are both read only and will only be read if
  26. ;'DATE:- ' or 'TIME:- ' is found in the 1st record of the file
  27.  
  28. ;See TIMESTMP.DOC for further deatails
  29.  
  30. false    equ    0
  31. true    equ    not false
  32.  
  33. stdaln    equ    true    ;True means this will stand alone.
  34.             ;False means the program will be
  35. ;patched to the end of an assembler or editor. Then, after
  36. ;updating the version, date and time, the assembler or
  37. ;editor will act upon the updated file.
  38.  
  39.  
  40. month    equ    0feadh        ;month byte in bios
  41. hour    equ    month+3        ;hour byte in bios
  42. base    equ    0        ;standard CP/M
  43. recsiz    equ    128        ;record length
  44. cr    equ    0dh
  45. lf    equ    0ah
  46. bell    equ    7
  47. bdos    equ    base+5
  48. tail    equ    base+80h    ;command line
  49.  
  50. if not stdaln    ;if not stand alone
  51.  
  52. endasm    equ    4580h    ;address to jump to at the end of
  53.             ;assembler, also org of this program
  54.  
  55. oldjmp    equ    3EFDh    ;used to restore the jump at the
  56.             ;start of the assembler
  57.  
  58. jmpadd    equ    0103h    ;address of the JP (C3h) used to get
  59.             ;to this program
  60.  
  61. assemb    equ    0100h    ;address to return to when finished
  62.             ;updating the file
  63.  
  64. endif    ;if not stand alone
  65.  
  66. if stdaln    ;if stand alone
  67.  
  68. endasm    equ    base+100h    ;org if stand alone
  69. fcb    equ    base+5ch    ;use default fcb
  70.  
  71. endif    ;if stand alone
  72.  
  73.  
  74.         .z80
  75.         aseg
  76.  
  77.     org    endasm        ;end of assembler
  78.  
  79. ;BC = Count of characters in command line tail.
  80. ;DE = File control block.
  81. ;Hl = Command line tail.
  82.  
  83. start:    ld    de,crlf
  84.     ld    c,9        ;new line
  85.     call    bdos
  86.  
  87. if not stdaln        ;if not stand alone
  88.  
  89. ;All these contortions are needed to keep the input command
  90. ;line exactly as the assembler expects to find it
  91.  
  92.     ld    hl,tail        ;move & format source file
  93.     ld    b,0        ;name to fcb
  94.     ld    c,(hl)        ;count of characters
  95.     inc    hl        ;HL --> 1st character in tail
  96.     ld    a,'='        ;look for the '=' in front
  97.     cpir            ;of the source file
  98. cmder:    ld    de,cmderr    ;no '=' is a command error
  99.     jp    po,error
  100.  
  101.     ld    de,fcb        ;DE --> 1st position of FCB
  102.     inc    hl        ;HL --> 2nd char after '='
  103.     ld    a,':'        ;see if 'd:' given
  104.     cp    (hl)        ;Z set if found
  105.     dec    hl        ;HL --> 1st char after '='
  106.     jr    nz,start1    ;jump - no drive given
  107.  
  108.     ld    a,(hl)        ;get drive A, B, C, D, etc
  109.     and    0fh        ;convert A to 01 etc
  110.     ld    (de),a        ;put in fcb
  111.     cpi            ;inc hl dec bc
  112.     jp    po,cmder    ;command line too short
  113.     cpi            ;HL --> past drive & ':'
  114.     jp    po,cmder    ;command line too short
  115.  
  116. start1:    inc    de        ;DE --> file name
  117. st1a:    ld    a,(hl)
  118.     cp    ' '        ;transfer file name til ' '
  119.     jr    z,start2
  120.     cp    '.'        ;ignore '.' if ext given
  121.     jr    z,stext        ;don't put '.' in fcb
  122.     ldi            ;ld in fcb inc hl & de dec bc
  123.     jp    po,start3    ;jump if end of tail
  124.     jr    st1a
  125.  
  126. stext:    ld    de,ext        ;DE --> file extention
  127.     cpi            ;inc hl dec bc
  128.     jp    po,start3    ;jump if end of tail
  129.     jr    st1a
  130.  
  131. start2:    ld    a,' '        ;look for the space
  132.     cpir            ;before option
  133.     jp    po,start3    ;no ' '= no option
  134.     ld    a,(hl)
  135.     ld    (major),a    ;save the option
  136.     ld    hl,tail        ;dec the char count if
  137.     dec    (hl)        ;option used, in case the
  138.     dec    (hl)        ;assembler needs it.
  139.  
  140. endif    ;if not stand alone
  141.  
  142. if stdaln    ;if stand alone
  143.  
  144.     ld    a,(base+6dh)    ;get option ' ' or 'M'
  145.     ld    (major),a    ;save it
  146.     ld    bc,3
  147.     ld    de,fcb+9    ;set up to
  148.     ld    hl,ext        ;make default ext 'MAC'
  149.     ld    a,(de)
  150.     cp    ' '        ;jump if ext not ' '
  151.     jr    nz,start3
  152.     ldir            ;ext = 'MAC'
  153.  
  154. endif    ;if stand alone
  155.  
  156. start3:    ld    de,fcb        ;open input file
  157.     ld    c,15
  158.     call    bdos
  159.  
  160.     ld    de,nofile    ;report if can't open and
  161.     inc    a        ;exit to CP/M
  162.     jp    z,error
  163.  
  164.     ld    de,buff
  165.     ld    c,26        ;setdma
  166.     call    bdos
  167.  
  168.     ld    de,fcb
  169.     ld    c,20        ;read record 1
  170.     call    bdos
  171.  
  172.     ld    de,verstx
  173.     call    find        ;update version
  174.     ld    de,novers
  175.     call    nz,print
  176.     call    z,versn
  177.  
  178.     ld    de,datetx
  179.     call    find        ;update date
  180.     ld    de,nodate
  181.     call    nz,print
  182.     call    z,date
  183.  
  184.     ld    de,timetx
  185.     call    find        ;update time
  186.     ld    de,notime
  187.     call    nz,print
  188.     call    z,time
  189.  
  190. ;write record back into file and exit to assembler or CP/M
  191. ;The file is not closed, 'cos that would reduce it to a
  192. ;single record.
  193.  
  194.     xor    a
  195.     ld    (fcb+32),a    ;zero the record count
  196.     ld    de,fcb
  197.     ld    c,21
  198.     call    bdos
  199.     ld    de,donmsg
  200.  
  201. error:    call    print        ;print error message and exit.
  202.                 ;also normal exit
  203.  
  204. if not stdaln    ;if not stand alone
  205.  
  206. ;Restore the assembler to original condition and jump to it
  207.  
  208.     ld    hl,oldjmp    ;restore value in hl
  209.     ld    (jmpadd+1),hl    ;restore old jump address
  210.     jp    assemb        ;jump to the assembler
  211.  
  212. endif        ;if not stand alone
  213.  
  214. if stdaln    ;if stand alone
  215.  
  216.     ret    ;back to CP/M
  217.  
  218. endif    ;if stand alone
  219.  
  220. print:    push    af
  221.     ld    c,9
  222.     call    bdos
  223.     ld    hl,fcb+1
  224.     ld    de,prtnam
  225.     ld    bc,11
  226.     ldir
  227.     ld    de,prtfil
  228.     ld    c,9
  229.     call    bdos        ;print file name
  230.     pop    af
  231.     ret
  232.  
  233. ;Increment the version number
  234.  
  235. versn:    inc    hl        ;hl --> units of major change
  236.     ld    a,(major)    ;is a major change requested
  237.     cp    'M'
  238.     call    z,twoinc    ;inc major change number
  239.     jr    z,zeromn    ;zero minor change number
  240.     cp    'N'        ;do not change version if
  241.     ret    z        ;'n' option given
  242.     inc    hl
  243.     inc    hl
  244.     inc    hl        ;hl --> units of vers no.
  245.  
  246. twoinc:    push    af        ;increment a 2 digit field
  247.     push    hl
  248.     ld    b,2
  249.     ld    a,'9'+1        ;hl --> units position
  250. two1:    inc    (hl)
  251.     cp    (hl)
  252.     jr    nz,twox        ;exit if not > 9 ascii
  253.     ld    (hl),'0'    ;else zero the units
  254.     dec    hl        ;and inc the tens
  255.     djnz    two1
  256. twox:    pop    hl
  257.     pop    af
  258.     ret
  259.  
  260. zeromn:    inc    hl        ;zero minor version
  261.     inc    hl
  262.     ld    (hl),'0'    ;used when major changes
  263.     inc    hl
  264.     ld    (hl),'0'
  265.     ret
  266.  
  267. date:    ld    de,month    ;insert m/d/y
  268.     ld    b,2
  269. date1:    call    unpack
  270.     ld    (hl),'/'
  271.     inc    hl
  272.     djnz    date1
  273.     call    unpack
  274.     ret
  275.  
  276. time:    ld    de,hour
  277.     ld    b,2
  278. time1:    call    unpack        ;insert h:m:s
  279.     ld    (hl),':'
  280.     inc    hl
  281.     djnz    time1
  282.     call    unpack
  283.     ret
  284.  
  285.  
  286. ;find the first character of string in de (V, D or T)
  287.  
  288. find:    ld    hl,buff        ;de = compare string
  289.     ld    bc,recsiz    ;limit search to 1 rec
  290. trynxt:    ld    a,(de)        ;get 1st char to find
  291.     cpir
  292.     ret    po        ;ret nz set = not found
  293.  
  294. ;see if the rest of the string compares equal. Retry til we
  295. ;get to the end of the buffer
  296.  
  297.     push    bc
  298.     push    de
  299.     ld    b,6        ;compare next 6 chars
  300. find2:    inc    de
  301.     ld    a,(de)
  302.     cp    (hl)
  303.     jr    nz,tryagn    ;try for another string
  304.     inc    hl
  305.     djnz    find2        ;keep comparing til b = 0
  306.     pop    de
  307.     pop    bc
  308.     ret            ;ret with z set
  309.  
  310. tryagn:    pop    de        ;Found the 1st character, but
  311.     pop    bc        ;there was a bad compare in
  312.     jr    trynxt        ;the next 6 characters.
  313.  
  314. unpack:    ld    a,(de)        ;unpack the BCD time & date
  315.     inc    de        ;and put the ASCII characters
  316.     push    af        ;in the buffer.
  317.     rrca
  318.     rrca
  319.     rrca            ;move high nibble to low
  320.     rrca
  321.     call    unpak1
  322.     pop    af        ;do the low nibble
  323. unpak1:    and    0fh
  324.     add    a,'0'        ;make it an ASCII number
  325.     ld    (hl),a
  326.     inc    hl
  327.     ret
  328.  
  329. if not stdaln    ;if not stand alone
  330.  
  331. cmderr:    db    bell,'++ Command error ++',cr,lf,lf
  332.     db    'e.g. datstamp d:obj.ext,d:lst.ext=d:xxx.mac m',cr,lf,lf
  333.     db    '"datstamp =xxx" is mandatory, the rest are optional',cr,lf,lf
  334.     db    'M increments the major and zeros the minor version numbers',cr,lf,lf
  335.     db    'N leaves the version numbers unchanged',cr,lf,lf
  336.     db    'File was$'
  337.  
  338. endif    ;if not stand alone
  339.  
  340. donmsg:    db    '++ Date stamped$'
  341.  
  342. nofile:    db    '++ No source$'
  343.  
  344. novers:    db    '++ No '
  345. verstx:    db    'VERS:- '
  346.     db    'in$'
  347.  
  348. nodate:    db    '++ No '
  349. datetx:    db    'DATE:- '    
  350.     db    'in$'
  351.  
  352. notime:    db    '++ No ' 
  353. timetx:    db    'TIME:- '    
  354.     db    'in$'
  355.  
  356. crlf:    db    cr,lf,'$'
  357.  
  358. major:    db    0
  359.  
  360. if not stdaln    ;if not stand alone
  361. fcb:    db    0,'        '    ;file cotrol block
  362. endif    ;if not stand alone
  363.  
  364. ext:    db    'MAC'
  365.  
  366. if not stdaln    ;if not stand alone
  367.     db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  368. endif    ;if not stand alone
  369.  
  370. buff:    ds    recsiz
  371. prtfil:    db    ' File:- '
  372. prtnam:    db    '           ',cr,lf,lf,'$'
  373.     end
  374.  
  375.