home *** CD-ROM | disk | FTP | other *** search
- TITLE CLOCKMNT
- ; Version 1.1
- ; by Steve Dresser
- ; 01/30/92
- ;
- ; For use with Kenmore real-time clock and ZS/ZdDOS
- ;
- ; Gets current date directly from the clock registers.
- ; Compares current month to month of the previous run, and
- ; increments the year register if current month is less.
- ; Saves month in unused latch (base address of chip + 00FH)
- ; for future reference.
- ; Computes day-of-week for current date and
- ; sets the Kenmore's day-of-week register.
- ;
- ;===============================================================
- EXTRN WDAY0 ; Convert BCD date to weekday (0-6)
- .REQUEST ZSLIB,SYSLIB
- ;
- CLOCK EQU 0E0H ; Base address of Kenmore RTC
- WEEK EQU CLOCK+5 ; Day-of-week stored here
- DAY EQU CLOCK+6 ; Day-of-month stored here
- MONTH EQU CLOCK+7 ; Month stored here
- YEAR EQU CLOCK+9 ; Year stored here
- PRVMON EQU CLOCK+0FH ; Month on last clock access
-
- CLOCKMNT:
- LD (STACK),SP ; Save stack pointer
- LD SP,STACK ; SP points to new stack
- IN A,(PRVMON) ; Month saved at last run
- LD B,A ; Save it in B
- IN A,(MONTH) ; <A> = Current Month
- OUT (PRVMON),A ; Update previous month latch
- CP B ; Is Current < Previous?
- JR NC,SETWKDAY ; If not, don't change the year
- IN A,(YEAR) ; <A> = Year.
- ADD A,1 ; Bump it up
- DAA ; Adjust for packed BCD.
- OUT (YEAR),A ; Store Year in chip.
- SETWKDAY:
- LD HL,DATTIM ; ADDR DATE/TIME STRING
- PUSH HL ; Save on stack
- LD C,YEAR ; Point to port addr of year
- INI ; Read port and bump HL
- LD BC,256*2+MONTH ; B=2, C to address of month
- RDLOOP:
- INI ; Read data and increment HL
- DEC BC ; Decrement C, flags unchanged
- JR NZ,RDLOOP ; Do until B = 0
- POP HL ; Point to start of DATTIM
- CALL WDAY0 ; Put number of weekday in A
- OR A ; Set Z-flag if 0
- JR NZ,SET ; Don't change it if not 0
- ADD A,7 ; Change Saturday to 7
- SET:
- OUT (WEEK),A ; Set weekday
- LD SP,(STACK) ; Get old stack
- RET
- DSEG
- DATTIM: DS 6 ; Date/time storage
- DS 48 ; Stack area
- STACK: DS 2 ; Value of stack ptr saved here
- END