:-)
malcolmj1@juno.com wrote:
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. =========start dispdate.asm================#include "ti86asm.inc".org _asm_exec_ram
call _clrLCD
call _homeup
ld hl,365*4+1
call Dateld a,(Month)
call PrintNumld a,(Day)
call PrintNumld hl,_curRow
inc (hl)
inc hl
ld (hl),$00ld a,(Year)
ld l,a
ld h,0
ld a,h
ld de,1970
add hl,de
call _dispAHLret
Date:
ld de,365 ; Days in a year
ld b,0 ; Starts with zero being the year offset. The offset
; is based on 1984 being year 0. Year 1 would be 1985, etc.
YearLoop:
sub a ; Reset carry flag anticipating 'sbc hl,de' (Subtraction)
sbc hl,de
jr c,YearFound ; It went under zero
jr z,YearFound ; It was zero
inc b ; Increase year offset
call CheckLeapYear ; We want to check if it's a leap year. If so, subtract
; one from the total amount of days left to account for those
; infamous Feb 29ths!
jr YearLoop
YearFound:
ld a,b ; - Store away the year we found
ld (Year),a ; /
add hl,de ; Fix it because it just went under 0...put it back.
ld ix,MonthDays ; Start of array of bytes holding number of days per month. It's '-1'
; because we will be increasing it before we're using it.
call LeapYearArray ; Run another check for it being a leap year. This checks
; to see if the current year is a leap year. If so, it will
; add 12 to hl to move to the start of another array holding
; the number of days per months in a leap year (Feb has 29 days).
ld b,00 ; Start with the month being 00. The first line in the loop increases
; it so that it's on January (01).
MonthTallyLoop:
inc b ; Increase month counter
ld d,00 ; Zero Most Significant Byte (MSB) of 'de'
ld e,(ix) ; Get that month's number of days. Now 'de = (ix)'
inc ix ; Get it ready for the next time around
xor a ; Clear flags (For the upcoming 'sbc hl,de')
sbc hl,de ; See how it measures up to our cumulative sum
jr z,MonthFound ; - Went under so we must be inside the right month now!
jr c,MonthFound ; /
jr MonthTallyLoop
MonthFound:
.db 0 ; So I can use the Break feature of VTI
add hl,de
ld a,l
or a
jr nz,DayCont ; If the day is zero, move it to one (If a=0 Then a=1)
inc a
DayCont:
ld (Day),a
ld a,b
ld (Month),a ; Save away the month found
ret
LeapYearArray: ; Check to see if current year is a leap year
ld a,(Year) ; Get the year found
and %00000011 ; If either bit 0 or 1 are set then it's not divisible by four
ret nz
ld bc,MonthDaysLeapYear
retPrintNum:
ld hl,_curRow
inc (hl) ; Increase the row
inc hl
ld (hl),$00 ; Zero the column
ld l,a
ld h,$00
ld a,h ; Zero out 'a' also
jp _dispAHLCheckLeapYear: ; We need to check if it's a leap year. If divisible by
; 4 then it probably is. To divide by 4 we're going to
; copy it to 'a' and shift it right twice ( a /2 /2 = 4 ). A
; binary number is only divisible by 4 if its bits 0 and 1 are
; reset (i.e. %XXXXXX00 is divisible by 4 whereas %XXXXXX01 is not).
ld a,b ; Get it into 'a' so we can mess with it
and %00000011
ret nz ; If there was a bit in either bit 0 or 1 then it wasn't divisible by four
dec hl ; Decrease total number of days left
retMonth: .db 0
Day: .db 0
Year: .db 0MonthDays:
.db 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
MonthDaysLeapYear:
.db 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
.end========================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