home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / m80date.lbr / DATIME.IZC / DATIME.INC
Encoding:
Text File  |  1987-07-18  |  6.8 KB  |  315 lines

  1. ;************************************************************************
  2. ;  File DATIME.INC                ver 28 Oct 84        *
  3. ;************************************************************************
  4. ;                                    *
  5. ;  DATE1:  Routine to insert date in format mm/dd/yy into buffer at HL    *
  6. ;                                    *
  7. ;************************************************************************
  8.  
  9. DATE1:    
  10.     CALL    GET_CLOCK
  11.     PUSH    HL
  12.     LD    HL,(DATEPB)    ;get days since 1/1/78
  13.     CALL    CNVDAY        ;convert to month,day, year
  14.     POP    HL
  15.     LD    A,(MONTHS)
  16.     CALL    PUTBCD
  17.  
  18.     LD    (HL),'/'
  19.     INC    HL
  20.  
  21.     LD    A,(DAYS)
  22.     CALL    PUTBCD
  23.  
  24.     LD    (HL),'/'
  25.     INC    HL
  26.  
  27.     LD    A,(YEARS)
  28.     CALL    PUTBCD
  29.     RET    
  30.  
  31. ;************************************************************************
  32. ;                                    *
  33. ;  DATE2:  Routine to insert date in format dd mmm yy into buffer at HL    *
  34. ;                                    *
  35. ;************************************************************************
  36.  
  37. DATE2:    
  38.     CALL    GET_CLOCK
  39.     PUSH    HL
  40.     LD    HL,(DATEPB)    ;get days since 1/1/78
  41.     CALL    CNVDAY        ;convert to month,day, year
  42.     POP    HL
  43.     LD    A,(DAYS)
  44.     CALL    PUTBCD
  45.  
  46.     LD    (HL),' '
  47.     INC    HL
  48.  
  49.     PUSH    HL
  50.     LD    A,(MONTHS)
  51.     AND    10H        ;see if greater than 9
  52.     LD    A,(MONTHS)
  53.     JR    Z,DAT_J1
  54.     AND    0FH        ;get lower tens digit
  55.     ADD    A,10        ;and add ten to it 
  56. DAT_J1:
  57.     DEC    A        ;make it an offset
  58.     LD    B,A        ;multiply by three
  59.     SLA    A        ;and do a table lookup
  60.     ADD    A,B        ;into the month string 
  61.     LD    D,0        ;table
  62.     LD    E,A
  63.     LD    HL,MONTAB
  64.     ADD    HL,DE
  65.     POP    DE        ;output buffer address
  66.     LD    BC,3
  67.     LDIR
  68.     EX    DE,HL        ;get output buffer addr in HL
  69.     LD    (HL),' '
  70.     INC    HL
  71.  
  72.     LD    A,(YEARS)
  73.     CALL    PUTBCD
  74.     RET    
  75.  
  76. MONTAB:    DB    'JanFebMarAprMayJunJulAugSepOctNovDec'
  77.  
  78. ;************************************************************************
  79. ;                                    *
  80. ;  HHMMSS:  Routine to insert time in format hh:mm:ss into buffer at HL    *
  81. ;                                    *
  82. ;************************************************************************
  83.  
  84. HHMMSS:
  85.     CALL    GET_CLOCK
  86.     LD    DE,DATEPB+2    ;point to hours byte
  87.     LD    (DATEPB+4),A    ;put seconds in date parm block
  88.     LD    B,2
  89. TIME1:    LD    A,(DE)
  90.     INC    DE
  91.     CALL    PUTBCD        ;insert hh:mm:
  92.     LD    (HL),':'
  93.     INC    HL
  94.     DJNZ    TIME1
  95.     LD    A,(DE)
  96.     CALL    PUTBCD        ;insert seconds
  97.     RET    
  98.     PAGE
  99. ;************************************************************************
  100. ;                                    *
  101. ;  HHMM:  Routine to insert time in format hh:mm into buffer at HL    *
  102. ;                                    *
  103. ;************************************************************************
  104.  
  105. HHMM:
  106.     CALL    GET_CLOCK
  107.     LD    DE,DATEPB+2    ;point to hours byte
  108.     LD    A,(DE)
  109.     INC    DE
  110.     CALL    PUTBCD        ;insert hours
  111.     LD    (HL),':'
  112.     INC    HL
  113.     LD    A,(DE)
  114.     CALL    PUTBCD        ;insert minutes
  115.     RET    
  116.  
  117. ;************************************************************************
  118. ;  Routine to convert a BCD byte into two ascii characters at HL    *
  119. ;************************************************************************
  120.  
  121. PUTBCD:    
  122.     PUSH    AF
  123.     RRCA            
  124.     RRCA            
  125.     RRCA            
  126.     RRCA            ;get high nibble
  127.     CALL    PUTNIB
  128.     POP    AF        ;now low nibble
  129.     CALL    PUTNIB
  130.     RET    
  131. ;       make ascii & put into buffer
  132.  
  133. PUTNIB:                ;make ascii & put into buffer
  134.     AND    0FH
  135.     OR    '0'
  136.     LD    (HL),A
  137.     INC    HL        ;next buffer location
  138.     RET    
  139.     PAGE
  140. ;************************************************************************
  141. ;                                    *
  142. ;  Routine to get date and time from cp/m+ in bdos format        *
  143. ;                                    *
  144. ;************************************************************************
  145.  
  146. GET_CLOCK:    
  147.     PUSH    HL
  148. ;
  149. ;       this bios call is needed because the bdos rdtime
  150. ;       function doesn't call bios to update the clock data
  151. ;       in the scb
  152. ;
  153.     LD    C,DRBIOS    ;direct bios call
  154.     LD    DE,BIOSPB    ;read time function
  155.     CALL    BDOS
  156.     LD    C,RDTIME    ;get date/time
  157.     LD    DE,DATEPB    ;where to put date
  158.     CALL    BDOS
  159.     POP    HL
  160.     RET    
  161.  
  162. BIOSPB:    DB    26        ;time function
  163.     DB    0        ;value for A 
  164.  
  165. DATEPB:    DS    5        ;date parameter block
  166.  
  167.  
  168. ;************************************************************************
  169. ;                                    *
  170. ;  CNVDAY  -  Routine to convert cp/m or mp/m date from days since    *
  171. ;          1/1/78 to month, day, and year in 3 BCD bytes.        *
  172. ;                                    *        
  173. ;************************************************************************
  174.  
  175. YEAR    EQU    365        ;leap year gets adjusted for
  176. ;
  177. ;       count up until goal days exceeded
  178. ;
  179. CNVDAY:    
  180.     LD    (GOALDAYS),HL    ;save as goal to reach
  181.     LD    A,1        ;initial values
  182.     LD    (DAYS),A
  183.     LD    (MONTHS),A    ;month counter (jan is one)
  184.  
  185.     LD    HL,0
  186.     LD    (DAYSCNT),HL    ;start at zero
  187.     LD    DE,YEAR        ;one year of days
  188.         
  189.     LD    A,78H        ;the first year (bcd)
  190.     LD    (YEARS),A    ;save year value
  191. ;
  192. ;       it's much eaiser to detect leap years in binary
  193. ;
  194.     LD    A,78        ;1st year (binary)
  195.     LD    (YEARS_BIN),A    ;for leap year determination
  196. YEARLOOP:    
  197.     LD    HL,(DAYSCNT)
  198.     ADD    HL,DE        ;trial add one year of days
  199.     CALL    CKLEAP
  200.     JR    NZ,NO_LEAP
  201.     INC    HL        ;was a leap year
  202. NO_LEAP:    
  203.     CALL    CKGOAL
  204.     JP    NC,YEARDONE    ;year over flowed
  205.     LD    A,(YEARS)
  206.     CCF            ;daa screws up if carry is set
  207.     INC    A        ;add one to the year count
  208.     DAA            ;make bcd
  209.     LD    (YEARS),A    ;save years
  210.     JP    Z,DONE        ;exact match
  211.     LD    (DAYSCNT),HL    ;year was ok to add
  212.     LD    HL,YEARS_BIN
  213.     INC    (HL)
  214.     JR    YEARLOOP
  215. ;       
  216. YEARDONE:    
  217. ;
  218. ;       see if this is a leap year and adjust Feb if required
  219. ;
  220.     CALL    CKLEAP
  221.     LD    HL,FEB        ;point to feburary
  222.     LD    (HL),28
  223.     JR    NZ,NOT_LEAP    ;no, don't adjust feb
  224.     INC    (HL)        ;make 29
  225. NOT_LEAP:    
  226.     LD    DE,MONTBL    ;point to month table
  227. MONTHLOOP:    
  228.     LD    HL,(DAYSCNT)
  229.     LD    A,(DE)        ;get month
  230.     LD    C,A
  231.     LD    B,0
  232.     ADD    HL,BC
  233.     CALL    CKGOAL
  234.     JP    NC,MONTHDONE
  235.     PUSH    AF
  236.     CCF    
  237.     LD    A,(MONTHS)
  238.     INC    A        ;count to next month
  239.     DAA    
  240.     LD    (MONTHS),A
  241.     POP    AF
  242.     JR    Z,DONE        ;exact (on the first of the month)
  243.     LD    (DAYSCNT),HL
  244.     INC    DE        ;point to next month
  245.     JR    MONTHLOOP
  246. MONTHDONE:    
  247. ;
  248. ;       continue counting until day of month attained
  249. ;
  250.     LD    HL,(DAYSCNT)
  251. DAYSLOOP:    
  252.     INC    HL        ;add one day
  253.     CALL    CKGOAL
  254.     JP    NC,DONE
  255.     CCF            ;zero carry bit so daa is screwed up
  256.     LD    A,(DAYS)
  257.     INC    A
  258.     DAA    
  259.     LD    (DAYS),A
  260.     JR    DAYSLOOP
  261. DONE:    RET            ;leave module
  262.  
  263.         
  264. ;
  265. ;       compare count (in hl) with goal
  266. ;       C if count < goal
  267. ;       Z if count = goal
  268. ;
  269. CKGOAL:    PUSH    DE
  270.     LD    DE,(GOALDAYS)
  271.     LD    A,H
  272.     CP    D
  273.     JR    NZ,CKEND
  274.     LD    A,L
  275.     CP    E
  276. CKEND:    POP    DE
  277.     RET    
  278. ;
  279. ;       check for leap year
  280. ;       return z if leap year
  281. ;
  282. CKLEAP:    
  283.     LD    A,(YEARS_BIN)    ;get years
  284.     AND    03H
  285.     RET    
  286.  
  287. MONTBL:    
  288.     DB    31        ;jan
  289. FEB:    DB    28        ;feb
  290.     DB    31        ;mar
  291.     DB    30        ;apr
  292.     DB    31        ;may
  293.     DB    30        ;jun
  294.     DB    31        ;jul
  295.     DB    31        ;aug
  296.     DB    30        ;sep
  297.     DB    31        ;oct
  298.     DB    30        ;nov
  299.     DB    31        ;dec
  300. ;
  301. ;       these values are the output of this module
  302. ;
  303. DAYS:    DS    1        ;counts days in month (bcd)
  304. MONTHS:    DS    1        ;counts months in year (bcd)
  305. YEARS:    DS    1        ;counts years (starts at 78) (bcd)
  306. ;
  307. ;       cnvdays ram area
  308. ;
  309. YEARS_BIN:    DS    1        ;years in binary (for leap year calc)
  310. DAYSCNT:    DS    2        ;counts days
  311. GOALDAYS:    DS    2        ;days since 1/1/78
  312. ;
  313. ;  End of file DATIME.INC                        *
  314. ;************************************************************************
  315.