#include "ti86asm.inc"
.org _asm_exec_ram
call _clrLCD
call
_homeup
ld hl,365*4+1
call Date
ld a,(Month)
call
PrintNum
ld a,(Day)
call
PrintNum
ld hl,_curRow
inc
(hl)
inc hl
ld (hl),$00
ld a,(Year)
ld l,a
ld
h,0
ld a,h
ld de,1970
add hl,de
call
_dispAHL
ret
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
ret
PrintNum:
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 _dispAHL
CheckLeapYear: ; 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
ret
Month: .db 0
Day: .db
0
Year: .db 0
MonthDays:
.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
========================