TITLE IMPLEMENTATION MODULE PCPITIME .COMMENT $ a .REL module for reading the PCPI/DS1216E (no-slot) clock from Turbo Modula-2. Requires DSCLK.DVR (see PCPINSC1.LBR) revision 1.0 Jim Lill 8/29/87 PROCEDURE CLOCK(): BOOLEAN; PROCEDURE YEAR() : CARDINAL; PROCEDURE MONTH() : CARDINAL; PROCEDURE DAY() : CARDINAL; PROCEDURE HOUR() : CARDINAL; PROCEDURE MIN() : CARDINAL; PROCEDURE SEC() : CARDINAL; PROCEDURE HSEC() : CARDINAL; $ TRUE EQU NOT 0 BDOS EQU 5 DVR3 EQU 0FFE3H ; these two locations are in the DVR0 EQU 0FFE0H ; 6502 I/O area for talking to .DVR CLOCK:: LD C,251 ; put command in C for call CALL DVR3 ; send the command LD C,16 ; get time command in C CALL DVR3 ; send it LD HL,CLKTBL ; point at table READ: CALL DVR0 ; receive a character CP 0AAH ; Check to see if last character JP Z,CKCHG ; if it is exit loop LD (HL),A ; store data in table INC HL ; bump table pointer JP READ ; go get new data CKCHG: ; check to see if time has changed XOR A ; preset 'A' to FALSE & clear 'CY' LD HL,(LAST) ; put last min/sec in 'HL' (16 bits) LD DE,(MI) ; get new min/sec SBC HL,DE ; 'Z' if there was no change JP Z,LEAVE ; so leave with FALSE in 'A' LD (LAST),DE ; \_ if not, save the new min/sec LD A,TRUE ; / leave with TRUE in A JP LEAVE ; go use common code for RET to TM2 ; CLKTBL: ; YY: DS 1 ; \ MM: DS 1 ; \ DD: DS 1 ; \ DOW: DS 1 ; \_ current read HH: DS 1 ; / MI: DS 1 ; / SS: DS 1 ; / HS: DS 1 ; / LAST: DS 2 ; last min/sec ; ; YEAR:: ; TM2 address is handled in LEAVE LD A,(YY) ; get year JP BCD2BIN ; convert bcd to bin and go back to TM2 ; ; MONTH:: LD A,(MM) JP BCD2BIN ; ; DAY:: LD A,(DD) JP BCD2BIN ; ; HOUR:: LD A,(HH) JP BCD2BIN ; ; MIN:: LD A,(MI) JP BCD2BIN ; ; SEC:: LD A,(SS) JP BCD2BIN ; ; HSEC:: LD A,(HS) ; fall into next routine ; ; BCD2BIN: LD E,A ; save it for use in units stuff later AND 11110000B ; mask off lower-nybble, do tens stuff RRA ; * 8 LD B,A ; save it RRA ; \_ * 2 RRA ; / ADD A,B ; * 10 LD B,A ; save the tens result LD A,E ; get the byte again AND 00001111B ; mask off upper-nybble for units ADD A,B ; combine the nybbles, 'A' is binary ; ; LEAVE: POP HL ; get the TM2 address LD BC,0 ; \_ CARDINALS have two bytes, LD C,A ; / we have just one PUSH BC ; set it up for TM2 to get PUSH HL ; put the return address back on stack RET ; return to TM2 ; END ; DStime.Z80