home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_22_1988_Transactor_Publishing.d64
/
clock-cal.bud
< prev
next >
Wrap
Text File
|
2023-02-26
|
15KB
|
705 lines
;put"@0:clock-cal.bud
; ** rewritten in Buddy 128 Format
;
*=$1300 ; 4864
.obj "@0:clk4864"
;
;* * * * * * * * * * * * * * * * *
;* *
;* clock & calendar display... *
;* with audible alarm function *
;* *
;* c-128 mode, 40 or 80 columns *
;* *
;* written 11-16-85 w.j. brier *
;* *
;* revised 6-05-87 *
;* *
;* copyright 1986 *
;* *
;* this program is not to be... *
;* sold. it is permissible... *
;* to copy it but credit must... *
;* be given in the documentation *
;* *
;* see the documentation for... *
;* instructions on using this... *
;* program with your software... *
;* as well as distribution... *
;* limitations. *
;* *
;* * * * * * * * * * * * * * * * *
;
;
;* * * * * * * * * * * * * * * * *
;* *
;* <<< program assignments >>> *
;* *
;* * * * * * * * * * * * * * * * *
;
;
;system vectors & pointers...
;
dflto =$9a ;output device
;
mode =$d7 ;display mode flag
;
cinv =$0314 ;normal irq vector
ibsout =$0326 ;normal chrout vector
;
system =$0a00 ;basic reset vector
;
rptflg =$0a22 ;keyb'd repeat flag
;
basrst =$4003 ;basic warm reset
;
tod2 =$dd08 ;time of day clock #2
;
;
;screen editor functions...
;
wvdcm =$cdca ;write to 8563 ram
wvdcr =$cdcc ;write to 8563 register
;
;
;kernal functions...
;
chrout =$ef79 ;output a byte
irq =$fa65 ;normal irq
crti =$ff33 ;irq handler exit
;
;
;40 col vic screen ram...
;
vcram =$0400 ;start of display ram
vlram =$d800 ;start of color ram
;
;
;sid chip registers (voice 3)...
;
frelo3 =$d40e ;frequency ctrl (lo)
frehi3 =$d40f ;frequency ctrl (hi)
;
vcreg3 =$d412 ;control register
;
surel3 =$d414 ;sustain/release
;
sigvol =$d418 ;sid volume
;
;
;80 col 8563 vdc assignments...
;
scram1 =72 ;screen ram (time)
scram2 =152 ;screen ram (date)
;
atram1 =2120 ;attribute ram (time)
atram2 =2200 ;attribute ram (date)
;
upreg =18 ;update register
;
;
;=================================
;
;
;user-accessible memory...
;
tdta .asc " - - "
.byte 0 ; ascii date
toda .asc " : : "
.byte 0 ; ascii time
tdtc .byte 255, 255, 255 ;bcd date
;
dflg .byte 0 ;1 = no display
cflg .byte 7 ;display color
rflg .byte 0 ;1 = reverse video
;
key .byte 0, 0, 0, 0
;
;
;exit vector...
;
irqa .word irq
;
;
;alarm registers...
;
altc .byte 255, 255 ;time (h:m)
;
aflg .byte 255 ;enable flag
;
;---------------------------------
;
;entry point to start display
;
clkon jmp start ;start display
;
;---------------------------------
;
;entry point to stop display
;
clkof jmp stop ;stop display
;
;---------------------------------
;
;bcd time storage
;
todc .byte 0, 0, 0 ;hrs min sec
;
;=================================
;
;stop clock-calendar display
;
stop ldx cinv ;irq vector
ldy cinv+1
cpx #<dcc ;display vector
bne clkof2 ;not running
;
cpy #>dcc
bne clkof2 ;not running
;
sei ;interrupts off
;
ldx irqa ;original irq vector
ldy irqa+1
stx cinv
sty cinv+1
;
ldx bsouta
ldy bsouta+1
stx ibsout ;restore chrout vector
sty ibsout+1
;
ldx alrst1
ldy alrst1+1
stx system ;restore system vector
sty system+1
;
cli ;interrupts on
;
ldy #3 ;offset
lda #0
;
clkof1 sta key,y ;wipe out id key
dey
bpl clkof1 ;loop
;
clkof2 rts
;
;---------------------------------
;
;start clock-calendar display
;
start ldx cinv ;irq vector
ldy cinv+1
cpx #<dcc
bne start1 ;change vector
;
cpy #>dcc
beq start3 ;display is runnning
;
start1 stx irqa ;save existing...
sty irqa+1 ;irq vector
;
sei
;
ldx #<dcc ;change...
ldy #>dcc ;irq vector so that...
stx cinv ;clock-calendar runs
sty cinv+1
;
ldx ibsout ;save current...
ldy ibsout+1 ;chrout vector
stx bsouta
sty bsouta+1
;
ldx #<crdy ;change...
ldy #>crdy ;chrout vector so...
stx ibsout ;delay routine...
sty ibsout+1 ;intercepts it
;
ldx system ;basic reset
ldy system+1
stx alrst1 ;store
sty alrst1+1
;
ldx #<alrst ;alternate reset
ldy #>alrst
stx system ;new reset vector
sty system+1
;
lda tod2 ;give clock a kick...
sta tod2 ;to get it started
;
cli
;
ldy #3 ;offset
;
start2 lda keystr,y ;key
sta key,y ;enable key
dey
bpl start2 ;loop
;
iny
sty dflg ;clear display flag
sty lflg ;clear lockout flag
;
start3 rts
;
;=================================
;
;update & display time & date
;
dcc cld ;binary mode
;
lda tod2 ;tenths of seconds
beq dcc02 ;tenths are zero
;
lda #0
sta lflg ;clear lockout flag
;
dcc01 jmp (irqa) ;normal irq
;
dcc02 bit lflg
bmi dcc01 ;update locked out
;
dec lflg ;set lockout flag
;
;
;read clock registers...
;
ldx #3 ;tod2 offset
ldy #0 ;storage offset
;
dcc03 lda tod2,x ;fetch time value
dex
bmi dcc04 ;finished
;
sta todc,y ;save in buffer
;
iny
bne dcc03 ;loop
;
;
;test am/pm flag & adjust hours
;
dcc04 lda todc ;bcd hours
bmi dcc05 ;it's pm
;
cmp #$12
bne dcc06 ;not midnite
;
lda #0
beq dcc06 ;set hours to midnite
;
dcc05 and #%01111111 ;mask am/pm bit
cmp #$12
bcs dcc06 ;it's noon straight up
;
sed ;decimal mode
adc #$12 ;change to 24 hours
cld ;binary mode
;
dcc06 sta todc ;converted hours
;
;
;test for alarm time...
;
bit aflg ;check flag
bmi dcc09 ;alarm not enabled
;
ldy #1 ;offset
;
dcc07 lda altc,y ;alarm time
cmp todc,y ;check against tod
bne dcc09 ;not time
;
dey
bpl dcc07 ;loop
;
;
;sound alarm...
;
lda #15
sta sigvol ;max volume
sta frelo3 ;set frequency
sta frehi3
;
ldx #250 ;duration
ldy #33 ;sawtooth waveform
stx surel3 ;sustain/release
sty vcreg3 ;attack/decay
;
dey
sty vcreg3 ;gate voice
;
;
;test for stroke of midnite...
;
dcc09 ldy #2 ;todc offset
;
dcc10 lda todc,y ;fetch time value
bne dcc16 ;not midnite
;
dey
bpl dcc10 ;loop
;
;
;test for leap year...
;
lda tdtc+2 ;current year
jsr bcdof ;change to binary
;
ldx #$28
;
lsr ;divide by 2
bcs dcc11 ;odd year
;
lsr ;divide again
bcs dcc11 ;non-leap year
;
inx ;leap year
;
dcc11 stx clut+1 ;last day in feb.
;
;
;adjust date for end of month...
;
lda tdtc ;fetch month
jsr bcdof ;change to binary
;
tax
dex ;calendar lookup offset
;
lda tdtc+1 ;current day
cmp clut,x ;last day of month
bne dcc14 ;not end of month
;
cpx #11
bne dcc12 ;not december
;
lda tdtc+2 ;current year
jsr idv ;bump year
sta tdtc+2 ;save new year
;
lda #1
bne dcc13 ;set month to january
;
dcc12 lda tdtc ;current month
jsr idv ;bump
;
dcc13 sta tdtc ;new month
;
lda #1
bne dcc15 ;set day to 1st of month
;
dcc14 jsr idv ;bump day
;
dcc15 sta tdtc+1 ;new day
;
;
;decode date for display...
;
dcc16 lda tdtc ;current month
jsr bcdasc ;decode to ascii
cmp #"0"
bne dcc17
;
lda #32 ;blank leading zero
;
dcc17 sta tdta ;save tens
stx tdta+1 ;save units
;
lda tdtc+1 ;current day
jsr bcdasc
sta tdta+3
stx tdta+4
;
lda tdtc+2 ;current year
jsr bcdasc
sta tdta+6
stx tdta+7
;
;
;decode time for display...
;
lda todc ;hours
jsr bcdasc
sta toda
stx toda+1
;
lda todc+1 ;minutes
jsr bcdasc
sta toda+3
stx toda+4
;
lda todc+2 ;seconds
jsr bcdasc
sta toda+6
stx toda+7
;
;
;display time & date...
;
lda dflg
bne dcc23 ;display inhibited
;
;
;display on 40 column screen...
;
dcc18 lda cflg ;display color
ldy #7 ;offset
;
dcc19 sta vlram+32,y ;color
sta vlram+72,y
dey
bpl dcc19 ;loop
;
ldx rflg ;normal/reverse flag
ldy #7 ;offset
;
dcc20 lda toda,y ;fetch time
;
cpx #0 ;test reverse flag
beq dcc21 ;not reversed
;
ora #128 ;reverse
;
dcc21 sta vcram+32,y
;
lda tdta,y ;fetch date
cpx #0
beq dcc22
;
ora #128
;
dcc22 sta vcram+72,y
;
dey
bpl dcc20
;
;
;display on 80 column screen...
;
lda #>scram1 ;address for...
ldy #<scram1 ;time display
jsr setram ;set up vdc ram
;
ldx #<toda ;petascii time
ldy #>toda
jsr dtod ;display
;
lda #>scram2 ;address for...
ldy #<scram2 ;date display
jsr setram
;
ldx #<tdta ;petascii date
ldy #>tdta
jsr dtod ;display
;
;
;set 80 column attributes...
;
lda #>atram1 ;address for...
ldy #<atram1 ;time attribute
jsr setram
;
jsr atrst ;set up attributes
;
lda #>atram2 ;address for...
ldy #<atram2 ;date attribute
jsr setram
;
jsr atrst ;set up attributes
;
bit mode
bpl dcc23 ;40 column mode
;
jmp crti ;bypass rest of irq
;
dcc23 jmp (irqa) ;continue irq
;
;=================================
;
;display time or date
;
dtod stx dtod02 ;source address
sty dtod02+1
;
ldy #0 ;offset
;
dtod01 .byte $b9 ;lda llhh,y op-code
;
dtod02 *=*+2 ;source address
;
beq atrst3 ;end of string
;
jsr wvdcm ;output to 8563
iny
bne dtod01 ;loop
;
;---------------------------------
;
;set up display attributes
;
atrst ldy #8 ;counter
;
atrst1 lda cflg ;get color
ldx rflg
beq atrst2 ;no reverse display
;
ora #%01000000 ;reverse
;
atrst2 jsr wvdcm ;output to 8563
dey
bne atrst1 ;loop
;
atrst3 rts
;
;---------------------------------
;
;set up vdc ram address
;
setram ldx #upreg ;update register
jsr wvdcr ;write
inx
tya ;swap hi byte
jmp wvdcr
;
;---------------------------------
;
;chrout intercept & trap
;
crdy pha ;save printing char.
;
bit mode
bpl crdy01 ;in 40 columns
;
lda dflto ;output device
cmp #3
bne crdy01 ;not screen
;
lda dflg ;test display flag
bne crdy01 ;display inhibited
;
dec dflg ;block display
;
crdy01 pla ;recover character
;
.byte 32 ;jsr op-code
;
bsouta .word chrout ;normal chrout
;
bit dflg
bpl crdy02 ;no reset needed
;
inc dflg ;clear for display
;
crdy02 rts
;
;---------------------------------
;
;convert bcd to petascii
;
bcdasc jsr bcdbin ;bcd to binary
;
pha ;save tens value
;
txa ;units value
ora #48 ;change to petascii
tax ;hold
;
pla ;fetch tens
ora #48
;
rts
;
;---------------------------------
;
;bcd digit to 2 binary digits
;
bcdbin pha ;save bcd value
;
and #15 ;mask tens nybble
tax ;units in .x register
;
pla ;fetch bcd value
;
lsr ;shift tens nybble
lsr
lsr
lsr
;
rts
;
;---------------------------------
;
;bcd digit to 1 binary digit
;
bcdof jsr bcdbin ;bcd to binary
;
tay ;tens value
txa ;units
;
clc
;
bcdof1 dey ;counter
bmi idv01 ;finished
;
adc #10
bne bcdof1
;
;---------------------------------
;
;increment date value
;
idv sed ;decimal mode
;
clc
adc #1
;
cld ;binary mode
;
idv01 rts
;
;---------------------------------
;
;alternate basic reset
;
alrst jsr start ;restart clock
;
lda #0
sta rptflg ;repeat off
;
.byte $4c ;jmp llhh op-code
;
alrst1 *=*+2 ;reset jump
;
;---------------------------------
;
;calendar lookup table
;
clut .byte $31 ;jan
.byte $28 ;feb
.byte $31 ;mar
.byte $30 ;apr
.byte $31 ;may
.byte $30 ;jun
.byte $31 ;jul
.byte $31 ;aug
.byte $30 ;sep
.byte $31 ;oct
.byte $30 ;nov
.byte $31 ;dec
;
;---------------------------------
;
;program storage
;
keystr .asc "clk"
.byte 0
;
lflg *=*+1 ;display lockout
;
;=================================
.end