title 'SS1 clock read routine' name 'CLOCK' ; CompuPro System Support One clock driver for bios3 ; This will not set the clock, this is best handled by ; a transient. ; by dick lieber 3/20/83 maclib z80 version equ 03 ;version restore regs desg ver$ck: db 'clck ', version / 10 + '0', version mod 10 + '0', 0 cseg no equ 0 yes equ not no testing equ yes ; ; ss1 clock ports ; base equ 50h clkcmd equ base+10 clkdata equ base+11 read equ 10h write equ 20h hold equ 40h public ?time, ver$ck if testing public dtable endif extrn @date, @hour, @min, @sec ?time: push h push d call read$clock ;fill buffer with data from clock ; ; determine days since jan 1 1978 ; lda t$year mov b,a xra a rept 10 ;add in nine more times add b endm mov b,a lda u$year add b ;add tens of years to units of years sui 78 ;base year for cpm3 lxi h,0 lxi b,365 tloop: dad b ;add one years worth of days dcr a jrnz tloop ; ; hl is number of days till the start of this year ; lxi d,months lda t$mon rrc mvi a,0 jnc no$tens mvi a,10 ;make ten if t$mn was a one no$tens: mov b,a lda u$mon add b ;months so far this year mov b,a mloop: dcr b jrz mloop$dn ldax d ;get days for that month add l ;add with l mov l,a ;put back into l jnc ml1 ;did it carry inr h ;yes? ml1: inx d ;point to next month jr mloop mloop$dn: lda t$days mov b,a xra a rept 10 ;add in nine more times add b endm mov b,a lda u$days add b ;add tens of days to units of days inr a ;fudge in 1980 leap year mov c,a mvi b,0 dad b ; ; days since jan 1 1978 ; shld @date ; ; process the time ; lxi d,t$hr ; ; hours ; ldax d rlc! rlc! rlc! rlc ani 0f0h mov h,a inx d ldax d ani 0fh ora h sta @hour ; ; minutes ; inx d ldax d rlc! rlc! rlc! rlc ani 0f0h mov h,a inx d ldax d ani 0fh ora h sta @min ; ; seconds ; inx d ldax d rlc! rlc! rlc! rlc ani 0f0h mov h,a inx d ldax d ani 0fh ora h sta @sec pop d pop h ret ; ; get time/date and put in dtable buffer ; readclock: lxi d,dtable ;buffer to receive time/date lxi h,atable ;command table mvi b,13 ;bytes to read rdclkloop: mov a,m ;get command call nhrddgt ;read clock stax d ;stuff into buffer dcr b rz ;done inx h inx d jmp rdclkloop ;keep on ; ; get a digit from 5832 ; a = command (high order bit set if bits 2 &3 to be masked ; don't apply hold ; nhrddgt: adi read out clkcmd cpi 80h jmp nhentry ; ; same as above but apply hold ; rddgt: adi read + hold out clkcmd cpi 80h nhentry: in clkdata rc ;no need to mask ani 3h ret ; ; this is a table of 5832 commands ; those flagged with 80h require masking of bit 2 & 3 ; atable: db 5 + 80h ;hours tens db 4 ;hours units db 3 ;minutes tens db 2 ;minutes units db 1 ;seconds tens db 0 ;seconds units db 6 ;day of week db 0ah ;months tens db 9 ;months units db 8 + 80h ;days tens db 7 ;days units db 0ch ;years tens db 0bh ;years units ; ; table to calculate days in year ; months: db 31 ;jan db 28 ;feb db 31 ;mar db 30 ;apr db 31 ;may db 30 ;jun db 31 ;jul db 31 ;aug db 30 ;sep db 31 ;oct db 30 ;nov db 31 ;dec dtable: t$hr ds 1 ;hours tens u$hr ds 1 ;hours units t$mn ds 1 ;minutes tens u$mn ds 1 ;minutes units t$sc ds 1 ;seconds tens u$sc ds 1 ;seconds units ds 1 ;day of week t$mon: ds 1 ;months tens u$mon: ds 1 ;months units t$days: ds 1 ;days tens u$days: ds 1 ;days units t$year: ds 1 ;years tens u$year: ds 1 ;years units end