home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
UTILITYS
/
BEERTC.ARC
/
SETCLOCK.MAC
< prev
next >
Wrap
Text File
|
1990-07-21
|
7KB
|
430 lines
;02/05/87 age
TITLE 'Set MicroBee RTC'
.Z80
ASEG
page 80 ;() sets compressed print, 8 lines/inch
org 100h
.phase 100h
addr_port equ 04h ;register selection port
data_out equ 06h ;data output port to rtc
data_in equ 07h ;data input port to read data from rtc
bdos equ 005h
coninf equ 001h
cnoutf equ 002h
printf equ 009h
constf equ 00bh
bell equ 000h
tab equ 009h
lf equ 00ah
cr equ 00dh
clr equ 01ah
; registers
hour equ 4
min equ 2
sec equ 0
day equ 7
month equ 8
year equ 9
;macros
rdport macro
out (addr_port),a
in a,(data_in)
endm
begin: ld de,signon
ld c,printf
call bdos
; set up register 10
ld a,00ah ; address register 10
out (addr_port),a
ld a,00101111B ; 32.768 KHz crystal, 500ms interrupt
out (data_out),a ; rate
; stop clock by disabling updates
di ; no interrupts
ld a,00bh ; address register 11
out (addr_port),a
ld a,10000010B ; no update, BCD data, no DSE
out (data_out),a
;now fill the rtc registers with correct values
; YEAR
qy: ld de,qyear ; find year
ld c,printf
call bdos
ld c,coninf
call bdos
cp 030h ; check between 0 and 9
jr c,qy
cp 03ah
jp p,qy
sub 030h ; change to BCD
sla a ; shift to top 4 bits
sla a
sla a
sla a
ld (temp),a ; save
ld c,coninf
call bdos
cp 030h ; check between 0 and 9
jr c,qy
cp 03ah
jp p,qy
sub 030h ; change to BCD
ld hl,temp
or (hl)
ld (hl),a ; save combined BCD values
ld a,009h ; year register
out (addr_port),a
ld a,(hl)
out (data_out),a
;MONTH
qm: ld de,qmonth
ld c,printf
call bdos
ld c,coninf ; get tens of month
call bdos
cp 030h
jr c,qm
cp 032h
jp p,qm
sub 030h ; change to BCD
sla a ; shift to top 4 bits
sla a
sla a
sla a
ld (temp),a ; save
ld c,coninf ; get units of month
call bdos
cp 030h
jr c,qm
cp 03ah
jp p,qm
sub 030h ; change to BCD
ld hl,temp
or (hl)
ld (hl),a ; save combined BCD values
ld a,008h ; month register
out (addr_port),a
ld a,(hl)
out (data_out),a
;DAY OF THE WEEK
qwd: ld de,qwday
ld c,printf
call bdos
ld c,coninf ; get day of the week
call bdos
cp 031h
jr c,qwd
cp 038h
jp p,qwd
sub 030h ; change to BCD
push af
ld a,006h ; day of week register
out (addr_port),a
pop af
out (data_out),a
;DAY
qd: ld de,qday
ld c,printf
call bdos
ld c,coninf ; get tens of day
call bdos
cp 030h
jr c,qd
cp 034h
jp p,qd
sub 030h ; change to BCD
sla a ; shift to top 4 bits
sla a
sla a
sla a
ld (temp),a ; save
ld c,coninf ; get units of day
call bdos
cp 030h
jr c,qd
cp 03ah
jp p,qd
sub 030h ; change to BCD
ld hl,temp
or (hl)
ld (hl),a ; save combined BCD values
ld a,007h ; day of month register
out (addr_port),a
ld a,(hl)
out (data_out),a
;HOUR
qh: ld de,qhour
ld c,printf
call bdos
ld c,coninf ; get tens of hour
call bdos
cp 030h
jr c,qh
cp 036h
jp p,qh
sub 030h ; change to BCD
sla a ; shift to top 4 bits
sla a
sla a
sla a
ld (temp),a ; save
ld c,coninf ; get units of hour
call bdos
cp 030h
jr c,qh
cp 03ah
jp p,qh
sub 030h ; change to BCD
ld hl,temp
or (hl)
ld (hl),a ; save combined BCD values
ld a,004h ; hour register
out (addr_port),a
ld a,(hl)
out (data_out),a
;MINUTES
qmn: ld de,qmin
ld c,printf
call bdos
ld c,coninf ; get tens of minutes
call bdos
cp 030h
jr c,qmn
cp 036h
jp p,qmn
sub 030h ; change to BCD
sla a ; shift to top 4 bits
sla a
sla a
sla a
ld (temp),a ; save
ld c,coninf ; get units of minute
call bdos
cp 030h
jr c,qmn
cp 03ah
jp p,qmn
sub 030h ; change to BCD
ld hl,temp
or (hl)
ld (hl),a ; save combined BCD values
ld a,002h ; mins register
out (addr_port),a
ld a,(hl)
out (data_out),a
;SECONDS
qsecs: ld de,qsec
ld c,printf
call bdos
ld c,coninf ; get tens of minutes
call bdos
cp 030h
jr c,qsecs
cp 036h
jp p,qsecs
sub 030h ; change to BCD
sla a ; shift to top 4 bits
sla a
sla a
sla a
ld (temp),a ; save
ld c,coninf ; get units of minute
call bdos
cp 030h
jr c,qsecs
cp 03ah
jp p,qsecs
sub 030h ; change to BCD
ld hl,temp
or (hl)
ld (hl),a ; save combined BCD values
ld a,000h ; secs register
out (addr_port),a
ld a,(hl)
out (data_out),a
; now set the clock ticking
ld a,00bh ; register 11
out (addr_port),a
in a,(data_in)
and 07fh
push af
ld a,00bh ; register 11
out (addr_port),a
pop af
out (data_out),a
; ask if time ok
ld de,ok
ld c,printf
call bdos
; hide the cursor
ld b,00fh
ld a,000h
ld hl,0fa00h
hide: ld (hl),a
inc hl
djnz hide
; show the time incrementing
;read the data from the rtc
read_rtc:
ld de,space
ld c,printf
call bdos
ld a,hour
rdport ;get value for hours
call split ;convert to msb and lsb in H, L
ld (hours),hl
ld a,min
rdport
call split
ld (mins),hl
ld a,sec
rdport
call split
ld (secs),hl
ld a,day
rdport
call split
ld (days),hl
ld a,month
rdport
call split
ld (months),hl
ld a,year
rdport
call split
ld (years),hl
pr_time:
ld hl,hours
ld b,15h
pr1: ld a,(hl)
call con
inc hl
djnz pr1
; wait for next 1 second
loop: ld a,00ch ; status register
rdport
and 010h ; update bit
jp nz,read_rtc
ld c,06h ; swallow key
ld e,0ffh
call bdos
and 01011111B ; make upper case
cp 'Y'
jp z,cpm
cp 'N'
jp z,begin
jr loop
; return to CP/M
cpm: ei ; enable interrupts
ld de,poscur
ld c,printf
call bdos
jp 0 ; warm boot
;subroutines
;subroutine to take the packed BCD number in A and split it into a tens and
;a units digit in L and H.
split: push af
and 0f0h ;mask out units
ld l,a ;L contains tens
pop af
sub l
add a,'0' ;convert to ascii
ld h,a ;get units into H
srl l ;divide by 16 to get true 0-9 value
srl l
srl l
srl l
ld a,l
add a,'0' ;convert to ascii
ld l,a
ret
;console print subroutine
con: push af
push bc
push hl
ld e,a
ld c,cnoutf
call bdos
pop hl
pop bc
pop af
ret
;messages
signon: db clr,lf,lf,tab,'Set MicroBee Real Time Clock'
db ' (add leading zeros if needed)','$'
qyear: db cr,lf,lf,tab,'Year (last two digits only)? ',bell,'$'
qmonth: db cr,lf,lf,tab,'Month? ',bell,'$'
qwday: db cr,lf,lf,tab,'Day of week (1 - 7)? ',bell,'$'
qday: db cr,lf,lf,tab,'Day of month? ',bell,'$'
qhour: db cr,lf,lf,tab,'Hour (24 hour format)? ',bell,'$'
qmin: db cr,lf,lf,tab,'Minutes? ',bell,'$'
qsec: db cr,lf,lf,tab,'Seconds? ',bell,'$'
ok: db cr,lf,lf,lf,lf,tab,'Is the time correct (y/n)? _',00bh,00bh,'$'
space: db cr,' ','$'
poscur: db cr,lf,lf,lf,'$'
;data storage
hours: db '00:'
mins: db '00:'
secs: db '00 '
days: db '00/'
months: db '00/19'
years: db '00'
temp: ds 1
end