{ program in TurboPASCAL to read real-time-clock loacted at ports 30h through 33h in Morrow MD 2/3 rev.2 main board Mike Allen 7/13/86 } program time; const {array of days of the week} day: array[0..6] of string[9] = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); {array of time tags} tag: array[0..2] of string[4] = ('HRS.','AM','PM'); CLS= ^Z; {Clear Screen} HOME = ^^; {Home cursor [MDT 60/70]} CUROFF = ^['"6'; {Turn off cursor (ESC"6) [MDT60/70]} CURON = ^['"0'; {Turn on cursor (ESC"0) [MDT60/70]} PA = $30; {8255 A register} PB = $31; {8255 B register} PC = $32; {8255 C register} CNTRL = $33; {8255 control register} var rtc: array[0..12] of byte; {MSM8532 registers} i,civil_time: byte; {i=general loop variable, civil_time=24hr, AM or PM indicator} begin write(CUROFF); {turn off the cursor} write(CLS); {clear the screen} port[CNTRL]:=$90; {set up the 8522} port[PC]:=$20; {put MSM5832 in 'read' mode} while not KeyPressed do {loop until a key is pressed} begin for i:=0 to 12 do {read all 12 MSM5832 registers} begin port[PB]:=i; {output the register address} rtc[i]:=port[PA] and $0f {read the register and strip the top 4 bits} end; rtc[8]:=rtc[8] and $03; {strip off the leap year flag} if rtc[5]>7 then {check for 24hr time} civil_time:=0 else if rtc[5]>3 then {not 24 hr, check for PM} civil_time:=2 else civil_time:=1; {not 24 hr or PM, must be AM} rtc[5]:=rtc[5] and $03; {strip off 24hr and PM flags} writeln(HOME,'DATE: ',day[rtc[6]],', ',10*rtc[10]+rtc[9],'/',10*rtc[8]+rtc[7],'/',rtc[12]:1,rtc[11]:1); {home the cursor and print the day and date} if civil_time=0 then write('TIME: ',rtc[5]:1,rtc[4]:1) {if 24hr time, print leading 0 in hrs} else write('TIME: ',10*rtc[5]+rtc[4]); {otherwise suppress it.} write(':',rtc[3]:1,rtc[2]:1,':',rtc[1]:1,rtc[0]:1,' ',tag[civil_time]) {print minutes, seconds and tag} end; port[PC]:=$00; {take the MSM5832 out of read mode} write(CURON) {turn the cursor back on} end. { and retire!}