fxdoc/asm/rtc-functions.txt

229 lines
7.4 KiB
Plaintext

RTC functions from Graph 35+E II OS 3.10
<%03b RTC_GetTicks>
Returns the number of 128-Hz ticks elapsed since midnight.
r0: Number of ticks (between 0 and 11059200)
80013c80: 2f86 mov.l r8, @-r15
80013c82: 2f96 mov.l r9, @-r15
80013c84: 2fa6 mov.l r10, @-r15
80013c86: 2fb6 mov.l r11, @-r15
80013c88: 2fc6 mov.l r12, @-r15
80013c8a: 2fd6 mov.l r13, @-r15
80013c8c: 4f12 sts.l macl, @-r15
# r9 is 128*60*60, ie. the number of ticks per hour
80013c8e: db79 mov.l 0xa413fedc RTC.RCR1, r11
80013c90: ecfc mov #-4, r12
80013c92: e807 mov #7, r8
80013c94: d978 mov.l 0x00070800, r9
80013c96: 6db3 mov r11, r13
80013c98: 7de4 add #-28, r13
# Clear the carry flag and carry interrupt in RCR1
80013c9a: 67b0 mov.b @r11, r7
80013c9c: 6073 mov r7, r0
80013c9e: c909 and #9, r0
80013ca0: 6a03 mov r0, r10
80013ca2: 2ba0 mov.b r10, @r11
# r5 = RSECCNT (binary) * 128 + R64CNT
80013ca4: 61d0 mov.b @r13, r1
80013ca6: 84d2 mov.b @(2,r13), r0
80013ca8: 631c extu.b r1, r3
80013caa: 6403 mov r0, r4
80013cac: c970 and #112, r0
80013cae: 40cc shad r12, r0
80013cb0: 6503 mov r0, r5
80013cb2: 4508 shll2 r5
80013cb4: 350c add r0, r5
80013cb6: 6043 mov r4, r0
80013cb8: 4500 shll r5
80013cba: c90f and #15, r0
80013cbc: 350c add r0, r5
80013cbe: 84d4 mov.b @(4,r13), r0
80013cc0: 458d shld r8, r5
80013cc2: 353c add r3, r5
# r6 = RMINCNT (binary)
80013cc4: 6603 mov r0, r6
80013cc6: 6203 mov r0, r2
80013cc8: 84d6 mov.b @(6,r13), r0
80013cca: 6103 mov r0, r1
80013ccc: 6063 mov r6, r0
80013cce: c970 and #112, r0
80013cd0: 40cc shad r12, r0
80013cd2: 6603 mov r0, r6
80013cd4: 4608 shll2 r6
80013cd6: 360c add r0, r6
80013cd8: 6023 mov r2, r0
80013cda: 4600 shll r6
80013cdc: c90f and #15, r0
80013cde: 360c add r0, r6
# r2 = RHRCNT (binary), r4 = r6 * (60*128)
80013ce0: 6013 mov r1, r0
80013ce2: c930 and #48, r0
80013ce4: 6463 mov r6, r4
80013ce6: 40cc shad r12, r0
80013ce8: 4408 shll2 r4
80013cea: 4408 shll2 r4
80013cec: 6203 mov r0, r2
80013cee: 3468 sub r6, r4
80013cf0: 4208 shll2 r2
80013cf2: 4418 shll8 r4
80013cf4: 320c add r0, r2
80013cf6: 6013 mov r1, r0
80013cf8: 4400 shll r4
80013cfa: 4200 shll r2
80013cfc: c90f and #15, r0
80013cfe: 320c add r0, r2
# Combine these together to form the number of ticks elapsed since midnight:
# r4 = 60*60*128*RHRCNT + 60*128*RMINCNT + 128*RSECCNT + R64CNT (binary)
# Restart if the carry is set.
80013d00: 60b0 mov.b @r11, r0
80013d02: 0927 mul.l r2, r9
80013d04: c880 tst #-128, r0
80013d06: 345c add r5, r4
80013d08: 051a sts macl, r5
80013d0a: 8fca bf.s <80013ca2>
80013d0c: 345c add r5, r4
80013d0e: 2b70 mov.b r7, @r11
80013d10: 6043 mov r4, r0
80013d12: 4f16 lds.l @r15+, macl
80013d14: 6df6 mov.l @r15+, r13
80013d16: 6cf6 mov.l @r15+, r12
80013d18: 6bf6 mov.l @r15+, r11
80013d1a: 6af6 mov.l @r15+, r10
80013d1c: 69f6 mov.l @r15+, r9
80013d1e: 000b rts
80013d20: 68f6 mov.l @r15+, r8
...
<80054456 RTC_GetRawTime>
Gets the time into a structure of the following form, where all objects are
written in BCD notation.
struct RTC_RawTime {
uint16_t YEAR;
uint8_t MONTH;
uint8_t DAY;
uint8_t HOURS;
uint8_t MINUTES;
uint8_t SECONDS;
uint8_t zero;
}; /* 8 bytes */
r4: Pointer to [struct RTC_RawTime]
80054456: d510 mov.l 0xa413fec2 RTC.RSECCNT, r5
80054458: e1f8 mov #-8, r1
8005445a: 8556 mov.w @(12,r5), r0
8005445c: 620d extu.w r0, r2
8005445e: 421c shad r1, r2
80054460: 2420 mov.b r2, @r4
80054462: 8041 mov.b r0, @(1,r4)
80054464: 845a mov.b @(10,r5), r0
80054466: 8042 mov.b r0, @(2,r4)
80054468: 8458 mov.b @(8,r5), r0
8005446a: 8043 mov.b r0, @(3,r4)
8005446c: 8454 mov.b @(4,r5), r0
8005446e: 8044 mov.b r0, @(4,r4)
80054470: 8452 mov.b @(2,r5), r0
80054472: 8045 mov.b r0, @(5,r4)
80054474: 6050 mov.b @r5, r0
80054476: 8046 mov.b r0, @(6,r4)
80054478: e000 mov #0, r0
8005447a: 000b rts
8005447c: 8047 mov.b r0, @(7,r4)
...
<8005788c RTC_IsInitialized>
Checks whether the RTC is initialized by comparing the current date with the
(probably default) date of 2019-01-01. (Note: this OS 3.10 was compiled in
2019 so this choice makes sense, even if the default has long been 2012.)
r0: 1 if the RTC is initialized, 0 otherwise.
# Get current time in BCD format
8005788c: 4f22 sts.l pr, @-r15
8005788e: 7ff8 add #-8, r15
80057890: d271 mov.l 0x80054456 RTC_GetRawTime, r2
80057892: 420b jsr @r2
80057894: 64f3 mov r15, r4
# Return 1 if the current date is not 2019-01-01
80057896: 60f0 mov.b @r15, r0
80057898: 8820 cmp/eq #32, r0
8005789a: 8b09 bf <800578b0>
8005789c: 84f1 mov.b @(1,r15), r0
8005789e: 8819 cmp/eq #25, r0
800578a0: 8b06 bf <800578b0>
800578a2: 84f2 mov.b @(2,r15), r0
800578a4: 8801 cmp/eq #1, r0
800578a6: 8b03 bf <800578b0>
800578a8: 84f3 mov.b @(3,r15), r0
800578aa: 8801 cmp/eq #1, r0
# Return 0 otherwise
800578ac: 8d01 bt.s <800578b2>
800578ae: e000 mov #0, r0
800578b0: e001 mov #1, r0
800578b2: 7f08 add #8, r15
800578b4: 4f26 lds.l @r15+, pr
800578b6: 000b rts
800578b8: 0009 nop
<800578ba RTC_TimeCategorySinceReset>
Returns a broad categorization of the time spent since last RTC reset. The
category is computed by comparing the current time to the default time of
RTC_IsInitialized (2019-01-01). The categories are defined by the following
ranges of time spent since last RTC reset:
3: More than 12 hours
2: Between 15 minutes and 12 hours
1: Between 10 minutes and 15 minutes
0: Less than 10 minutes
# Get tick-based time, divide by 128 to get second-based time and round to 0
# (adding 127 to a negative tick-time rounds near 0, but is useless here).
800578ba: 2fe6 mov.l r14, @-r15
800578bc: 4f22 sts.l pr, @-r15
800578be: d267 mov.l %03b RTC_GetTicks, r2
800578c0: 420b jsr @r2
800578c2: 0009 nop
800578c4: 4011 cmp/pz r0
800578c6: 8d01 bt.s <800578cc>
800578c8: 6e03 mov r0, r14
800578ca: 7e7f add #127, r14
800578cc: e2f9 mov #-7, r2
# Return:
# -> 3 if current date is after 2019-01-01 12:00
# -> 2 if it's before that but still after 00:15
# -> 1 if it's before that but still after 00:10
# -> 0 if it's before 00:10
800578ce: bfdd bsr <8005788c RTC_IsInitialized>
800578d0: 4e2c shad r2, r14
800578d2: 8801 cmp/eq #1, r0
800578d4: 890a bt <800578ec>
800578d6: d262 mov.l 0x0000a8c0, r2
800578d8: 3e23 cmp/ge r2, r14
800578da: 8907 bt <800578ec>
800578dc: 9293 mov.w 0x00000384, r2
800578de: 3e23 cmp/ge r2, r14
800578e0: 8d05 bt.s <800578ee>
800578e2: e002 mov #2, r0
800578e4: 9290 mov.w 0x00000258, r2
800578e6: 3e23 cmp/ge r2, r14
800578e8: a001 bra <800578ee>
800578ea: 0029 movt r0
800578ec: e003 mov #3, r0
800578ee: 4f26 lds.l @r15+, pr
800578f0: 000b rts
800578f2: 6ef6 mov.l @r15+, r14