IsCalculator = defined(statVars) .module RTC ;------------------------------------------------------------------------------- ;@doc:routine ; ; === RTC.Read === ; ; Reads the time and date from the hardware real-time-clock into memory. ; ; OUTPUTS: ; MEMORY ; * Time and Date - All components of the time and date are repopulated. ; ;@doc:end ;------------------------------------------------------------------------------- Read push af ld a,(OS.Version.Major) cp 2 jr z,ReadHardwareClock push bc di ld bc,(Interrupt.RTCSeconds) push bc ld bc,0 ld (Interrupt.RTCSeconds),bc pop bc ei ld a,b or c jr z,+ - call Tick dec bc ld a,b or c jr nz,- + pop bc pop af ret ReadHardwareClock push iy push hl push de push bc push ix ld iy,(TIOS.IY) ; Grab the date from the TI-84+ RTC. .bcall $514F ; getDate ; Pop the result off the FPS and convert to BCD. ld ix,Date.DayOfMonth ld b,3 - push bc push ix .bcall _PopOP1 .bcall _ConvOP1 .oscall "Utility.EncodeBCD" pop ix pop bc ld (ix+0),a inc ix djnz - ; de = Year. ld h,d ld l,e push de .bcall _DivHLBy10 .bcall _DivHLBy10 ld a,l .oscall "Utility.EncodeBCD" ld (ix+0),a ; Century. ld h,100 .bcall _HTimesL pop de ex de,hl or a sbc hl,de ld a,l .oscall "Utility.EncodeBCD" ld (ix-1),a ; Year. ; Grab the time from the TI-84+ RTC. .bcall $515B ; getTime ; Pop the result off the FPS and convert to BCD. ld ix,Time.Second ld b,3 - push bc push ix .bcall _PopOP1 .bcall _ConvOP1 .oscall "Utility.EncodeBCD" pop ix pop bc ld (ix+0),a inc ix djnz - pop ix pop bc pop de pop hl pop iy pop af ret ;------------------------------------------------------------------------------- ;@doc:routine ; ; === RTC.Write === ; ; Writes the time and date from memory into the hardware real-time-clock. ; ; INPUTS: ; MEMORY ; * Time and Date - All components of the time and date are copied. ; ; DESTROYED: ; REGISTERS ; * AF ; ;@doc:end ;------------------------------------------------------------------------------- Write push af ld a,(OS.Version.Major) cp 2 jr z,+ pop af ret + push iy push hl push de push bc ld iy,(TIOS.IY) di ld hl,WriteDateErrorHandler call APP_PUSH_ERRORH ld a,(Date.Century) .oscall "Utility.DecodeBCD" ld l,a ld h,100 .bcall _HTimesL ld a,(Date.Year) .oscall "Utility.DecodeBCD" ld e,a ld d,0 add hl,de .bcall _SetXXXXOP2 .bcall _OP2ToOP1 .bcall _PushOP1 ld a,(Date.Month) .oscall "Utility.DecodeBCD" .bcall _SetXXOP1 .bcall _PushOP1 ld a,(Date.DayOfMonth) .oscall "Utility.DecodeBCD" .bcall _SetXXOP1 .bcall $516A ; setDate call APP_POP_ERRORH WriteDateErrorHandler ld hl,WriteTimeErrorHandler call APP_PUSH_ERRORH ld a,(Time.Hour) .oscall "Utility.DecodeBCD" .bcall _SetXXOP1 .bcall _PushOP1 ld a,(Time.Minute) .oscall "Utility.DecodeBCD" .bcall _SetXXOP1 .bcall _PushOP1 ld a,(Time.Second) .oscall "Utility.DecodeBCD" .bcall _SetXXOP1 .bcall $5170 ; setTime call APP_POP_ERRORH WriteTimeErrorHandler im 2 ei pop bc pop de pop hl pop iy pop af ret ;------------------------------------------------------------------------------- ;@doc:routine ; ; === RTC.Tick === ; ; Ticks the software clock for one second. ; ; INPUTS: ; MEMORY ; * Time and Date - All components of the time and date are updated. ; ; DESTROYED: ; REGISTERS ; * AF ; ;@doc:end ;------------------------------------------------------------------------------- Tick xor a ld a,(Time.Second) inc a daa ld (Time.Second),a cp $60 ret nz xor a ld (Time.Second),a ld a,(Time.Minute) inc a daa ld (Time.Minute),a cp $60 ret nz xor a ld (Time.Minute),a ld a,(Time.Hour) inc a daa ld (Time.Hour),a cp $24 ret nz xor a ld (Time.Hour),a push hl push de ld a,(Date.Century) .oscall "Utility.DecodeBCD" ld l,a ld h,0 ; 100 = *4 + *32 + *64 add hl,hl ; 2 add hl,hl ; 4 push hl add hl,hl ; 8 add hl,hl ; 16 add hl,hl ; 32 push hl add hl,hl pop de add hl,de pop de add hl,de ld a,(Date.Year) .oscall "Utility.DecodeBCD" ld e,a ld d,0 add hl,de ld a,(Date.Month) .oscall "Utility.DecodeBCD" .oscall "DateTime.GetDaysInMonth" inc a .oscall "Utility.EncodeBCD" ld l,a pop de xor a ld a,(Date.DayOfMonth) inc a daa ld (Date.DayOfMonth),a cp l pop hl ret nz ld a,$01 ld (Date.DayOfMonth),a ld a,(Date.Month) inc a daa ld (Date.Month),a cp $13 ret nz ld a,$01 ld (Date.Month),a ld a,(Date.Year) inc a daa ld (Date.Year),a ret nz ld a,(Date.Century) inc a daa ld (Date.Century),a ret .endmodule