After some brief testing, my routine seems to work OK. Here is the relevant code I've added to startup.i.
Code:
move.l $4.w,a6
move.l a6,a5 ; execbase in a5
lea battresname(pc),a1 ; battclock.resource
jsr -498(a6) ; OpenResource()
movea.l d0,a4 ; battclockbase in a4
move.l a4,d0 ; hmm...
bne.b .battok
bra .fail
.battok moveq #$28,d0 ; want 40 bytes allocated
move.l #$10001,d1 ; MEMF_ANY, MEMF_CLEAR?
jsr -198(a6) ; AllocMem()
move.l d0,a3 ; allocated mem in a3
tst.l d0
beq .fail
move.l d0,a1
lea timerdevname(pc),a0
moveq #0,d0
move.l d0,d1
jsr -444(a6) ; OpenDevice()
move.l d0,d6
ext.w d6 ; byte to word
ext.l d6 ; word to long, d6 equals 0?
bne.b .fail
moveq #0,d0
move.b d0,8(a3) ; start building IORequest
move.b d0,9(a3)
suba.l a1,a1
move.l a1,$a(a3)
move.l a1,$e(a3)
clr.l $24(a3)
movea.l a4,a6 ; battclockbase in a4
jsr -12(a6) ; ReadBattClock()
move.l d0,$20(a3) ; unix time in d0
move.w #$b,$1c(a3) ; io_Command = TR_SETSYSTIME
movea.l a3,a1
movea.l a5,a6 ; execbase in a5
jsr -456(a6) ; DoIO()
movea.l a3,a1
jsr -450(a6) ; CloseDevice()
movea.l a3,a1
moveq #$28,d0 ; free the 40 bytes
jsr -210(a6) ; FreeMem()
.fail
; snip
rts
battresname dc.b 'battclock.resource',0
timerdevname dc.b 'timer.device',0
I have also attached the whole test intro with source code, just run 'intro' in the 'bin' folder to check it. The included source startup_rtc.i is StingRay's code with my added RTC restore routine.
NOTE: The source code is converted to compile with Devpac (had to add some directives, change a few instructions, etc.).