The time is returned as the number of seconds since Jan 1, 1900, so a little math is needed to convert it to a date/time format. Also, this 32bit value will roll-over in 2036 and start over at $00000000 (Current value is ~ $D2180352).
I'm a bit surprised you didn't use the UNIX epoch as the time base, since algorithms are plentiful for that. However, 1900-2036 is good—it covers my lifetime, and then some.
I'm working on a variant of this which uses a 48 bit time_t and is capable of working from 1800 onward. With the 65C816, a larger time_t value is not cumbersome to manage. As my POC unit has real time clock hardware, the initial date and time can be gotten from it and used to set the time_t value. Once that is done, jiffy IRQs will drive the time_t clock, with a resolution of 0.01 seconds.
I have a basic form of that running right now in a 40 bit uptime counter (current value $001F478B0A, or approximately 23 days, 18 hours). The least significant byte increments with each jiffy IRQ, which is generated by the watchdog timer in the real time clock hardware. I have the watchdog set to interrupt at 10 millisecond intervals. The code progression to do this is very simple with the '816:
Code: Select all
; ———————————————
; process RTC IRQ
; ———————————————
;
longa ;16 bit .A & memory
;
;
; decrement time delay counter...
;
lda tdsecct ;time delay seconds
beq .iirq002 ;timed out, so ignore
;
ldx tdirqct ;msecs timer
dex ;msecs=msecs-10
bne .iirq001 ;not time to update seconds
;
dec tdsecct ;secs=secs-1
ldx #hz ;reset msecs to 1000
;
.iirq001 stx tdirqct ;new IRQ timer value
;
;
; process uptime counter...
;
.iirq002 ldx utirqct ;msecs*10 counter
inx
cpx #hz ;reach 1000 msecs?
bcc .iirq004 ;no
;
inc utsecct ;bump uptime LSW
bne .iirq003 ;done
;
inc utsecct+s_word ;bump uptime MSW
;
.iirq003 ldx #0 ;reset msecs*10 counter
;
.iirq004 stx utirqct ;new msec counter value
In the above, s_word is the size in bytes of a 16 bit word (I don't bury magic numbers in code), hz is the jiffy interrupt rate per second (100), and longa is a macro that sets up the MPU for 16 bit accumulator operation. Note how being able to decrement or increment 16 bits at a time is real convenient—less code, less branching and fewer clock cycles. The time delay counter is callable from the BIOS jump table and can be set to as much as 18 hours.