;+ ; ; Program to read and write TOY clock. ; ; Equivalent to the /SYNCHRONIZE and /SETTOY features of TIM, but doesn't ; depend on RSX's opinion of whether this is a KDJ11E CPU board (so the user ; can use an outboard TOY-compatible hardware clock, or E11 with SET CPU ASR ; combined with any CPU emulation). ; ; By John Wilson, . ; ; 11/26/99 JMBW Created (based on RDTOY.MAC). ; ;- .mcall dir$,exit$s,gmcr$,gtim$s,stim$s,qiow$ ; asr$= 177526 ;add'l status reg ; start: ; start here dir$ #corcmn ;get command line mov $dsw,r1 ;get length ble 20$ ;error, assume /SYNC cmp r1,#7 ;long enough for "TOY /SE"? blo 20$ cmp r1,#toysel ;too long? bhi 20$ mov #corcmn+2,r0 ;point at string mov #toyset,r2 ;string to match 10$: cmpb (r0)+,(r2)+ ;check for match bne 20$ ;no match, assume /SYNC sob r1,10$ ;loop through all jmp settoy 20$: ; TOY [/SYNCHRONIZE] ; set the system time from the TOY clock call toyatn ;get TOY clock's attention, R5=ASR MSB, R3=1 ; presumably we're in, read 64 bits of clock data mov #toybuf+6,r4 ;pt at last word clr (r4) ;nuke out buf clr -(r4) clr -(r4) clr -(r4) ;(now R4=TOYBUF, R3=1 from above) 30$: bitb #1,(r5) ;read a bit beq 40$ bis r3,(r4) ;1, set it 40$: asl r3 ;shift the bit left bcc 30$ ;didn't wrap inc r3 ;start over at bit 0 tst (r4)+ ;skip to next word cmp r4,#toybuf+8. ;done all 64 data bits? blo 30$ ;loop if not ; unpack BCD data and write to time buffer call gttime ;get existing values, including clock Hz call bcdbin ;get hundredths from +0 mul rsxtim+s.ticp,r0 ;convert to 50ths/60ths div #100.,r0 mov r0,rsxtim+s.tict ;save call bcdbin ;get seconds from +1 mov r0,rsxtim+s.tisc call bcdbin ;get minutes from +2 mov r0,rsxtim+s.timi call bcdbin ;get hours from +3 mov r0,rsxtim+s.tihr inc r5 ;skip day of week at +4 call bcdbin ;get day from +5 mov r0,rsxtim+s.tida call bcdbin ;get month from +6 mov r0,rsxtim+s.timo call bcdbin ;get year (since 1900.) from +7 ; DS1215 only stores 2-digit years, so we use a window to infer the ; first two digits -- 99 is 1999, 00-98 are 2000-2098 cmp r0,#99. ;1999? beq 50$ add #100.,r0 ;no, 2000-2098 50$: mov r0,rsxtim+s.tiyr mov #-1,rsxtim+s.ticp ;we don't mess with Hz stim$s #rsxtim ;set the system time bcc 60$ ;success mov #seterr,r0 ;error message mov #seterl,r1 call print ;print it 60$: exit$s ; settoy: ; TOY /SETTOY call gttime ;get time, or die trying mov rsxtim+g.tict,r0 ;get ticks mul #100.,r0 ;convert to hundredths div rsxtim+g.ticp,r0 call binbcd ;save at +0 mov rsxtim+g.tisc,r0 ;seconds call binbcd ;save at +1 mov rsxtim+g.timi,r0 ;minutes call binbcd ;save at +2 mov rsxtim+g.tihr,r0 ;hours call binbcd ;save at +3 clrb (r5)+ ;don't care about day of week (at +4) mov rsxtim+g.tida,r0 ;day call binbcd ;save at +5 mov rsxtim+g.timo,r0 ;month call binbcd ;save at +6 mov rsxtim+g.tiyr,r1 ;get year clr r0 ;zero-extend div #100.,r0 ;find year within century mov r1,r0 ;copy (DS1215 chip only handles 2-digit year) call binbcd ;save at +7 ; 64-bit buffer is loaded, feed it to the TOY clock call toyatn ;get TOY clock's attention, R5=ASR MSB, R3=1 ; presumably we're in, write 64 bits of clock data mov #toybuf,r4 ;pt at buf 10$: bic #1,r0 ;clear bit 8 of CSR value bit r3,(r4) ;should we set it? beq 20$ inc r0 ;yes 20$: movb r0,(r5) ;write a bit asl r3 ;shift the bit left bcc 10$ ;didn't wrap inc r3 ;start over at bit 0 tst (r4)+ ;skip to next word cmp r4,#toybuf+8. ;done all 64 bits of data? blo 10$ ;loop if not exit$s ;finished ;+ ; ; Get Dallas DS1215 time-of-year clock's attention. ; ; r5 returns pointer to high byte of additional status reg ; r3 returns 1 ; r0 returns high byte of ASR ; ;- toyatn: mov #asr$+1,r5 ;point at MSB of additional status reg ; write 64-bit signature to DS1215 mov #toysig,r4 ;point at signature mov #1,r3 ;bit 0 movb (r5),r0 ;get value (don't know if other bits are R/W) ;(this should also clear the DS1215 ptr) 10$: bic #1,r0 ;clear bit 8 bit r3,(r4) ;should we set it? beq 20$ inc r0 ;yes 20$: movb r0,(r5) ;write a bit asl r3 ;shift the bit left bcc 10$ ;didn't wrap inc r3 ;start over at bit 0 tst (r4)+ ;skip to next word cmp r4,#toysig+8. ;done all 64 bits of signature? blo 10$ ;loop if not rts pc ;+ ; ; Convert number from (R5)+ from 2-digit BCD to binary in R0. ; ;- bcdbin: clr r0 ;zero-extend bisb (r5)+,r0 ;fetch value mov r0,r1 ;copy bic #^C17,r0 ;isolate low digit bic r0,r1 ;and high digit asr r1 ;high dig *8 add r1,r0 ;add that in asr r1 ;right 2 more bits asr r1 add r1,r0 ;+ dig *2 = dig *10 rts pc ;+ ; ; Convert number in R0 from binary to 2-digit BCD and store at (R5)+. ; ;- binbcd: mov r0,r1 ;copy clr r0 ;zero-extend div #10.,r0 ;split digits ash #4,r0 ;high digit left 4 bits bis r1,r0 ;combine movb r0,(r5)+ ;save rts pc ;+ ; ; Print a message on the terminal. ; ; r0 address ; r1 length ; ;- print: mov r0,ttyout+q.iopl ;set addr mov r1,ttyout+q.iopl+2 ;and length dir$ #ttyout ;print it rts pc ;+ ; ; Get system time into RSXTIM. ; ; R5 returns poniter to TOYBUF. ; ;- gttime: gtim$s #rsxtim ;get system time bcc 10$ ;success mov #geterr,r0 ;error message mov #geterl,r1 call print ;print it exit$s 10$: mov #toybuf,r5 ;point at buffer rts pc ; ; Signature pattern to get into Dallas Semiconductor DS1215 time of year chip toysig: .word 35305 ;C5 3A .word 56243 ;A3 5C .word 35305 ;C5 3A .word 56243 ;A3 5C ; toyset: .ascii "TOY /SETTOY" ;set TOY clock if command line looks like this toysel= .-toyset ;otherwise read TOY clock ; seterr: .ascii /?Error setting time/ seterl= .-seterr ; geterr: .ascii /?Error reading time/ geterl= .-geterr ; .even ; ttyout: qiow$ io.wvb,5,,,,,<,,40> ;QIOW to terminal ; corcmn: gmcr$ ;get MCR command line ; rsxtim: .blkw 8. ;time in RSX format toybuf: .blkw 4 ;TOY read buf ; .end start