Re: A86: Re: Calendar Formulas


[Prev][Next][Index][Thread]

Re: A86: Re: Calendar Formulas





your routine seemed overly complicated so i wrote one off of my
suggestion
(beats doing calculus homework ;)
not as easy as i had expected...

this routine must base off of a leap year, so 1970 doesn't work.
if you really want to base off of 1970, subtract 2*365 from hl before
calling
then base off of 1972 (add 2 to the year after return)

also, this will be off by one day after feb 28, 2100
inc hl before calling if >46810 to fix that (using 1972 as base year)
or >42427 (using 1984 as base year)

---------

#include "ti86asm.inc"

_homeup                 = $4a95
_dispAHL                = $4A33
_hldiv10                = $4044

.org $d748

call _clrLCD
call _homeup
; 1972, 1976, 1980
;        yrs leap j  f  m  a  m  j  j  a  s  o
ld hl,365* 8+  2 +31+29+31+30+31+30+31+31+30+9
call printdate  ; Oct 10, 1980
ld hl,0
call printdate  ; Jan 01, 1972
ld hl,365*3+1+31+28
call printdate  ; Mar 01, 1975
ld hl,365*4+1+31+28
call printdate  ; Feb 29, 1976
ld hl,365*5+2+31+28
call printdate  ; Mar 01, 1977
ld hl,365*6+2+31+28
; call printdate ; Mar 01, 1978


; in: days from jan 1, 1972 in hl 
; (remember it's 0 based)
printdate:
call Date
ld (Day),hl
ld (Year),bc

ld de,s_months
ld hl,(Month)
ld h,0
add hl,hl
add hl,hl
add hl,de
call _puts

ld a,' '
call _putc

ld hl,(Day)
inc l          ; make day 1-whatever
ld h,0
call _hldiv10
ld h,a
ld a,'0'
add a,l
call _putc
ld a,'0'
add a,h
call _putc

  ld a,','
call _putc

ld a,(Year)
ld l,a
ld h,0
ld a,h
ld de,1972     ; can't base from 1970
add hl,de      ; 1970 was not a leap year
call _dispAHL

call _newline

ret

Day: .db 0
Year: .db 0
Month: .db 0

s_months:
    .db "Jan",0,"Feb",0,"May",0,"Apr",0
    .db "May",0,"Jun",0,"Jul",0,"Aug",0
    .db "Sep",0,"Oct",0,"Nov",0,"Dec",0




; in:
;    hl=day
;    (year 0 MUST be a leap year)
; out:
;    c = year - "year 0"
;    b = month (0 to 11)
;    l = day of month (0 to whatever)
;   ix,de,af,h destroyed
Date:
   ld bc,$0000      ; c = year / b = month
   ld ix,month_table
   call skip_month  ; skip january
   call skip_month  ; skip february
   dec c
year_loop:
   ex de,hl         ; days left -> de
   inc c            ; add a year
   ld a,c
   and %00000011
   jr nz,not_leap_year
   
   ld a,e           ; make sure feb 29th
   or d             ; does not wrap
   jr z,feb_29
   
   dec de           ; skip february 29
not_leap_year:
   ld hl,-365       ; subtract a year
   add hl,de        ; negative now?
   jr c,year_loop

   ex de,hl         ; days left -> hl
      
month_loop:
   call skip_month
   jr month_loop
   
feb_29:
   dec b
   ld l,28
   ret

; hl = days
; c = year
; b = month
; ix -> month_table
skip_month:
   ld a,b
   ld (patch1),a
   ld e,(ix+$00)    ; get days in current month to e
patch1 = $-1

   ld a,h       ; more than 255 days?
   or a         ; don't bother checking (no month has >255 days)
   jr nz,month_ok

   ld a,l       ; days is < 256
   cp e         ; compare to days in current month
   jr nc,month_ok

   pop de       ; trash return address
   ret          ; finished

month_ok:
   inc b        ; next month #
   ld a,b
   sub 12       ; passed december?
   jr c,same_year
   ld b,a       ; subtract a year
   inc c        ; add a year
same_year:
   ld d,0
   or a
   sbc hl,de    ; subtract the month
   ret          ; back to the loop

month_table:
   .db 31,28,31,30,31,30,31,31,30,31,30,31


---------

-josh



On Fri, 2 Feb 2001 19:18:17 -0500 malcolmj1@juno.com writes:
i think i've got it done.  would someone be willing to help test it. 
i've attached it at the end.

i tried to use php 4's date() function to test it but there seems to be a
difference between the function of the two calls (php's date() and my
ti86 routine).  i can't find a way to test it out now.

========================
that should be all the source you need.  if anyone wants me to email them
the *.asm source, let me know.  i hope this routine really works.  i
really appreciate this you guys!

> Date: Fri, 2 Feb 2001 12:10:42 -0800
> From: rabidcow@juno.com
> Subject: Re: A86: Calender Formulas

thanks. i wrote the above routine and then checked my mail and found what
you said.  it's been a while since i've talked to you.

jimi malcolm
mailto:malcolmj1@juno.com
http://guide.ticalc.org
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/tagj.