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 / PROGRAMS / CLOCKK / LB-TSTP1.LBR / TMSTP-LB.ZZ0 / TMSTP-LB.Z80
Text File  |  2000-06-30  |  11KB  |  450 lines

  1. Title Time stamp   VERS:- 01.01  DATE:- 01/07/88  TIME:- 18:54:34
  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. ;          of this listing.
  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 MONTH, MONTH+1 and MONTH+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. ;
  31.       page
  32. ;********************************************************************
  33. ;
  34. ;     DAYDATE code:
  35. ;       Gets date and time from BIOS software real-time clock,
  36. ;       converts to BCD and places it in a 6-byte string
  37. ;       in format mmddyyhhmmss at location 'month'.
  38. ;
  39. ;       This version is customized for the AMPRO Little Board Z-80
  40. ;       by Larry Sonderling
  41. ;
  42. ;********************************************************************
  43. ;
  44. daydate:    call    getbios       ; get BIOS jump tables into local storage
  45.         call    j2md          ; convert Julian date to month/day
  46. ;
  47.         ld    a,(tmonth)    ; convert each value to BCD
  48.         call    binbcd        ; and store in output string
  49.         ld    (month),a     ; for TIMESTMP to use.
  50. ;    
  51.         ld    a,(tday)
  52.         call    binbcd
  53.         ld    (month+1),a
  54. ;
  55.         ld    a,(year)
  56.         call    binbcd
  57.         ld    (month+2),a
  58. ;
  59.         ld    a,(bhour)
  60.         call    binbcd
  61.         ld    (month+3),a
  62. ;
  63.         ld    a,(bmin)
  64.         call    binbcd
  65.         ld    (month+4),a
  66. ;
  67.         ld    a,(bsec)
  68.         call    binbcd
  69.         ld    (month+5),a
  70. ;
  71.         jp      timestmp      ; jump to main code
  72. ;
  73. ;
  74. month        ds    6     ; output string for TIMESTMP main code
  75. ;
  76. ;********************************************************************
  77. ;
  78. ;    Error exits for uninstalled clock or wrong BIOS version.
  79. ;
  80. ;********************************************************************
  81. ;
  82. ; Time of day TOD jmp was not in bios
  83. ;
  84. NOCLK:    CALL    PRINT0
  85.     DEFB    'Clock not installed',CR,LF,0
  86.     JP    0
  87. ;
  88. ; wrong BIOS version
  89. ;
  90. BADVER:    CALL    PRINT0
  91.     DEFB    'Requires Bios 3.6 or higher.',CR,LF,0
  92.     JP    0     
  93. ;
  94. ;********************************************************************;
  95. ;
  96. GETBIOS:LD      DE,WBOOT    ; build bios entry table
  97.     LD    HL,(1)        ; get bios start
  98.     LD    BC,51        ; bytes to move
  99.     LDIR
  100.     CALL    GETTBL        ; get address of next jmp tbl
  101.     CP    36        ; must be bios ver 3.6 or higher
  102.     JR    C,BADVER    ; give message and exit
  103.     LD    DE,NXTTBL    ; 'hl' has bios nxttbl address
  104.     LD    BC,15        ; 
  105.     LDIR                ; move the table
  106.     LD    HL,0        ; make sure that clock is enabled
  107.     CALL    TOD        ; get clock base address
  108.     LD    A,L        ; see if address of tick was returned
  109.     OR    H
  110.     JR    Z,NOCLK        ; exit if clock not enabled
  111. ;
  112. ; 'HL' has address of clock
  113. ;
  114.     LD    DE,BSEC        ; move time and date to work area
  115.     LD    BC,6
  116.     LDIR
  117.         RET
  118. ;
  119. ;****************************************************************
  120. ;                 convert julian to month/day
  121. ;****************************************************************
  122. ;
  123. J2MD:    LD    DE,MTHS        ; int month pointer
  124.     LD    HL,(JDAY)    ; julian day in 'hl'
  125.     INC    HL        ; adjust for ordinal 0
  126.     XOR    A
  127.     LD    B,A        ; init high byte of sub with 0
  128.     INC    A
  129.     LD    (TMONTH),A    ; init month to 1
  130.  
  131. J2MD1:    LD    A,(DE)
  132.     OR    A        ; clear carry
  133.     LD    C,A
  134.     LD    A,L        ; may be day
  135.     SBC     HL,BC
  136.     JR    C,J2MD2
  137.     JR    Z,J2MD2
  138.     LD    A,(TMONTH)
  139.     INC    A        ; update month
  140.     LD    (TMONTH),A
  141.     INC    DE
  142.     JR    J2MD1
  143.  
  144. J2MD2:    LD    (TDAY),A    ; set day
  145.     RET
  146. ;
  147. ;***************************************************************
  148. ;        convert binary to BCD
  149. ; in:    a  - binary value
  150. ; out:    a  - BCD equivalent
  151. ;***************************************************************
  152. ;
  153. BINBCD:    LD    C,0        ; init count for MSD
  154.     LD    B,10            ; divisor
  155.  
  156. BIN1:    SUB    B               ; divide by 10
  157.     JR    C,BINEXT        ; finished if underflow
  158.     INC    C               ; else incr MSD and
  159.     JR    BIN1            ; loop back for another one
  160.  
  161. BINEXT:    ADD    A,B        ; A = ones digit  C = tens digit
  162.     AND    0FH             ; zero high nibble
  163.     SLA     C               ; shift MSD to high nibble
  164.     SLA     C
  165.     SLA    C
  166.     SLA     C
  167.         OR      C               ; insert MSD
  168.     RET                     ; done
  169. ;
  170. ;     Print a null-terminated string on the console
  171. ;
  172. print0:       pop     hl              ; get address of string
  173.               ld      a,(hl)          ; load the character
  174.               and     a               ; test for null
  175.               jr      z,prnend        ; quit if null
  176.               push    hl              ; else save the pointer
  177.               ld      c,a             ; and print to console
  178.               call    conout
  179.           pop     hl              ; restore pointer
  180.               inc     hl              ; bump to next address
  181.               jr      print0+1        ; go back again
  182.  
  183. prnend:       push    hl              ; at end HL is return address
  184.               ret
  185. ;
  186. ;**************************************************************************
  187. ;
  188. ;     Table of lengths of months
  189. ;
  190. MTHS:    DEFB    31,29,31,30,31,30,31,31,30,31,30,31
  191. ;
  192. ; bios entry table
  193. ;
  194. WBOOT:    DEFS    3        ; Warm start
  195. CONST:    DEFS    3        ; Console status
  196. CONIN:    DEFS    3        ; Console character in
  197. CONOUT:    DEFS    3        ; Console character out
  198. LIST:    DEFS    3        ; List character out
  199. PUNCH:    DEFS    3        ; Punch character out
  200. READER:    DEFS    3        ; Reader character in
  201. HOME:    DEFS    3        ; Seek to home position
  202. SELDSK:    DEFS    3        ; Select disk
  203. SETTRK:    DEFS    3        ; Set track number
  204. SETSEC:    DEFS    3        ; Set sector number
  205. SETDMA:    DEFS    3        ; Set DMA address
  206. READ:    DEFS    3        ; Read disk
  207. WRITE:    DEFS    3        ; Write disk
  208. LISTST:    DEFS    3        ; Return list status
  209. SECTRAN:DEFS    3        ; Sector translate
  210. GETTBL:    DEFS    3        ; Point to more jumps, returns bioss
  211.                 ; version in 'a'.
  212. ;
  213. ;     Extended BIOS jump table - AMPRO LB specific
  214. ;
  215. NXTTBL:    
  216. SWAP:    DEFS    3        ; jmp swap
  217. HD$INF:    DEFS    3        ; get hd table info
  218. PHTBAC:    DEFS    3        ; get/set phytab acces
  219. PAGET:    DEFS    3        ; get phytab entry address
  220. TOD:    DEFS    3        ; get base address of clock tick
  221.  
  222. BSEC:    DEFS    1             ; binary seconds
  223. BMIN:    DEFS    1             ; binary minutes
  224. BHOUR:    DEFS    1             ; binary hours
  225. JDAY:    DEFS    2             ; Julian day
  226. YEAR:    DEFS    1             ; binary year
  227.  
  228. TMONTH:    DEFS    1             ; binary month
  229. TDAY:    DEFS    1             ; binary day
  230. TYEAR:    DEFS    1             ; not used
  231. ;
  232. ;********************************************************************
  233. ;********************************************************************
  234.       page
  235. ;********************************************************************
  236. ;     some equates
  237. ;********************************************************************
  238. ;
  239. false    equ    0
  240. true    equ    not false
  241. hour    equ    month+3        ; hour byte in bios
  242. base    equ    0        ; standard CP/M
  243. recsiz    equ    128        ; record length
  244. bell    equ    7
  245. bdos    equ    base+5
  246. tail    equ    base+80h    ; command line
  247. endasm    equ    base+100h    ; org if stand alone
  248. fcb    equ    base+5ch    ; use default fcb
  249. cr    equ    0dh        ; carriage return
  250. lf    equ    0ah        ; line feed
  251. ;
  252. ;********************************************************************
  253. ;
  254. ;     BC = Count of characters in command line tail.
  255. ;     DE = File control block.
  256. ;     HL = Command line tail.
  257. ;
  258. ;********************************************************************
  259. ;    Main TIMESTMP code begins here
  260. ;********************************************************************
  261. ;
  262. timestmp:
  263.     ld    de,crlf
  264.     ld    c,9        ;new line
  265.     call    bdos
  266.     ld    a,(base+6dh)    ;get option ' ' or 'M'
  267.     ld    (major),a    ;save it
  268.     ld    bc,3
  269.     ld    de,fcb+9    ;set up to
  270.     ld    hl,ext        ;make default ext 'Z80'
  271.     ld    a,(de)
  272.     cp    ' '        ;jump if ext not ' '
  273.     jr    nz,start3
  274.     ldir            ;ext = 'Z80'
  275. ;
  276. start3:    ld    de,fcb        ;open input file
  277.     ld    c,15
  278.     call    bdos
  279.     ld    de,nofile    ;report if can't open and
  280.     inc    a        ;exit to CP/M
  281.     jp    z,error
  282.     ld    de,buff
  283.     ld    c,26        ;setdma
  284.     call    bdos
  285. ;
  286.     ld    de,fcb
  287.     ld    c,20        ;read record 1
  288.     call    bdos
  289. ;
  290.     ld    de,verstx
  291.     call    find        ;update version
  292.     ld    de,novers
  293.     call    nz,print
  294.     call    z,versn
  295. ;
  296.     ld    de,datetx
  297.     call    find        ;update date
  298.     ld    de,nodate
  299.     call    nz,print
  300.     call    z,date
  301. ;
  302.     ld    de,timetx
  303.     call    find        ;update time
  304.     ld    de,notime
  305.     call    nz,print
  306.     call    z,time
  307. ;
  308. ;write record back into file and exit to assembler or CP/M
  309. ;The file is not closed, 'cos that would reduce it to a
  310. ;single record.
  311. ;
  312.     xor    a
  313.     ld    (fcb+32),a    ;zero the record count
  314.     ld    de,fcb
  315.     ld    c,21
  316.     call    bdos
  317.     ld    de,donmsg
  318. error:    call    print        ;print error message and exit.
  319.                 ;also normal exit
  320.     ret            ;back to CP/M
  321. ;
  322. print:    push    af
  323.     ld    c,9
  324.     call    bdos
  325.     ld    hl,fcb+1
  326.     ld    de,prtnam
  327.     ld    bc,11
  328.     ldir
  329.     ld    de,prtfil
  330.     ld    c,9
  331.     call    bdos        ;print file name
  332.     pop    af
  333.     ret
  334. ;
  335. ;Increment the version number
  336. ;
  337. versn:    inc    hl        ;hl --> units of major change
  338.     ld    a,(major)    ;is a major change requested
  339.     cp    'M'
  340.     call    z,twoinc    ;inc major change number
  341.     jr    z,zeromn    ;zero minor change number
  342.     cp    'N'        ;do not change version if
  343.     ret    z        ;'n' option given
  344.     inc    hl
  345.     inc    hl
  346.     inc    hl        ;hl --> units of vers no.
  347. ;
  348. twoinc:    push    af        ;increment a 2 digit field
  349.     push    hl
  350.     ld    b,2
  351.     ld    a,'9'+1        ;hl --> units position
  352. two1:    inc    (hl)
  353.     cp    (hl)
  354.     jr    nz,twox        ;exit if not > 9 ascii
  355.     ld    (hl),'0'    ;else zero the units
  356.     dec    hl        ;and inc the tens
  357.     djnz    two1
  358. twox:    pop    hl
  359.     pop    af
  360.     ret
  361. ;
  362. zeromn:    inc    hl        ;zero minor version
  363.     inc    hl
  364.     ld    (hl),'0'    ;used when major changes
  365.     inc    hl
  366.     ld    (hl),'0'
  367.     ret
  368. ;
  369. date:    ld    de,month    ;insert m/d/y
  370.     ld    b,2
  371. date1:    call    unpack
  372.     ld    (hl),'/'
  373.     inc    hl
  374.     djnz    date1
  375.     call    unpack
  376.     ret
  377. ;
  378. time:    ld    de,hour
  379.     ld    b,2
  380. time1:    call    unpack        ;insert h:m:s
  381.     ld    (hl),':'
  382.     inc    hl
  383.     djnz    time1
  384.     call    unpack
  385.     ret
  386. ;
  387. ;find the first character of string in de (V, D or T)
  388. ;
  389. find:    ld    hl,buff        ;de = compare string
  390.     ld    bc,recsiz    ;limit search to 1 rec
  391. trynxt:    ld    a,(de)        ;get 1st char to find
  392.     cpir
  393.     ret    po        ;ret nz set = not found
  394. ;
  395. ;see if the rest of the string compares equal. Retry til we
  396. ;get to the end of the buffer
  397. ;
  398.     push    bc
  399.     push    de
  400.     ld    b,6        ;compare next 6 chars
  401. find2:    inc    de
  402.     ld    a,(de)
  403.     cp    (hl)
  404.     jr    nz,tryagn    ;try for another string
  405.     inc    hl
  406.     djnz    find2        ;keep comparing til b = 0
  407.     pop    de
  408.     pop    bc
  409.     ret            ;ret with z set
  410. ;
  411. tryagn:    pop    de        ;Found the 1st character, but
  412.     pop    bc        ;there was a bad compare in
  413.     jr    trynxt        ;the next 6 characters.
  414. ;
  415. unpack:    ld    a,(de)        ;unpack the BCD time & date
  416.     inc    de        ;and put the ASCII characters
  417.     push    af        ;in the buffer.
  418.     rrca
  419.     rrca
  420.     rrca            ;move high nibble to low
  421.     rrca
  422.     call    unpak1
  423.     pop    af        ;do the low nibble
  424. unpak1:    and    0fh
  425.     add    a,'0'        ;make it an ASCII number
  426.     ld    (hl),a
  427.     inc    hl
  428.     ret
  429. ;
  430. donmsg:    db    '++ Date stamped$'
  431. nofile:    db    '++ No source$'
  432. novers:    db    '++ No '
  433. verstx:    db    'VERS:- '
  434.     db    'in$'
  435. nodate:    db    '++ No '
  436. datetx:    db    'DATE:- '    
  437.     db    'in$'
  438. notime:    db    '++ No ' 
  439. timetx:    db    'TIME:- '    
  440.     db    'in$'
  441. crlf:    db    cr,lf,'$'
  442. major:    db    0
  443. ext:    db    'Z80'
  444. buff:    ds    recsiz
  445. prtfil:    db    ' File:- '
  446. prtnam:    db    '           ',cr,lf,lf,'$'
  447.     end
  448.  
  449.