2,863 bytes added,
15:08, 28 August 2006 These are the [[SYMBiFACE II]] realtime clock routines of [[SymbOS]], written by [[Prodatron]]. They show how to read and set the date and time of the RTC.
<pre>
timrtcadr equ #fd15
rtc_sec equ #00 ;actual second (0-59)
rtc_sec_alarm equ #01 ;alarm second (0-59)
rtc_min equ #02 ;actual minute (0-59)
rtc_min_alarm equ #03 ;alarm minute (0-59)
rtc_hour equ #04 ;actual hour (0-23)
rtc_hour_alarm equ #05 ;alarm hour (0-23)
rtc_day_week equ #06 ;day of the week
rtc_day equ #07 ;day of the month (1-31)
rtc_month equ #08 ;month (1-12)
rtc_year equ #09 ;year (0-99)
rtc_status_a equ #0a ;Status A
rtc_status_b equ #0b ;Status B
rtc_status_c equ #0c ;Status C
rtc_memtest equ #0f ;ram test
rtc_mil equ #32 ;millenium (19-20)
timadr db rtc_status_b,rtc_sec,rtc_hour,rtc_min,rtc_month,rtc_day,rtc_year,rtc_mil,rtc_status_b
db #87
timreg ds 7
db #07
;### TIMSET -> Updates SYMBiFACE II RTC
;### Input A=seconds, B=minutes, C=hours, D=day (1-31), E=month (1-12), HL=year (1900-2099)
;### Destroyed AF,BC,DE,HL,IY
timset ld (timreg+0),a ;*** realtime clock (CPC version)
ld (timreg+1),bc
ld (timreg+3),de
call timset0
ld bc,2000
or a
sbc hl,bc
ld a,20
jr nc,timset2
ld bc,100
add hl,bc
ld a,19
timset2 ld h,a ;L=year, H=millenium
ld (timreg+5),hl
ld bc,timrtcadr
ld iy,timadr
ld e,9
timset3 ld a,(iy+0)
out (c),a
dec c
ld a,(iy+9)
out (c),a
inc c
inc iy
dec e
jr nz,timset3
ret
;### TIMGET -> Read SYMBiFACE II RTC
;### Output CF=0 -> A=seconds, B=minutes, C=hours, D=day (1-31), E=month (1-12), HL=year (1900-2099)
;### CF=1 -> time is currently been updated; please try again later
;### Destroyed F,IY
timget ld bc,timrtcadr ;*** realtime clock (CPC version)
ld a,rtc_status_a
out (c),a
dec c
in a,(c)
inc c
rla
ret c ;time is currently been updated -> abort
ld iy,timadr+1
ld e,7 ;read 7 registers
timget3 ld a,(iy+0)
out (c),a
dec c
in a,(c)
inc c
ld (iy+9),a
inc iy
dec e
jr nz,timget3
ld hl,(timreg+5) ;calculate year
ld a,h
ld h,0
ld bc,1900
cp 19
jr z,timget2
ld bc,2000
timget2 add hl,bc
ld a,(timreg+0) ;get registers
ld bc,(timreg+1)
ld de,(timreg+3)
or a
ret
</pre>
== See also ==
* [[Programming:SYMBiFACE_II|SYMBiFACE II documentations]]
[[Category:Programming]]