; Set Turbo Chameleon 64 RTC ; ; Written by Paul Foerster ; (paul.foerster@gmail.com), based on ; Yahoo Chameleon 64 group, article #349 ; by Peter Wendrich (pwsoft@syntiac.com) ; ; Chameleon 64 clock chip: PFC2123 ; ; Input for RTC: ; CC YY MM WD DD HH MM SS (8 bytes) ; value input format is BCD ; ;------------------------------------------------------------------------------- *=$0801 !word bend !word 10 !byte $9e !text "2304", 0 bend: !word 0 ;------------------------------------------------------------------------------- *= $0900 - 8 !byte 00,16,01,02,03,01,02,03 *= $0900 clkdat = *-$08 ; clock input buffer cfgreg = $d0fe ; config enable reg cfgspi = $d0f1 ; SPI config reg mmcena = 42 ; bring MMC to life mmcdis = $ff ; kill MMC mmcsel1 = $13 ; spictl init code mmcsel2 = $12 ; spidat init code mmcrtc = $03 ; cfgspi init code spidat = $df10 ; SPI data transfer reg spictl = $df11 ; SPI control reg spistat = $df12 ; SPI status reg spirdy = $01 ; busy wait status code ; The PFC2123 does not know a century, ; so assume century to be 20: century = $20 ; Enable config mode lda #mmcena sta cfgreg ; Save old config lda cfgspi pha lda spictl pha ; MMC emulation and RTC enable lda #mmcrtc sta cfgspi ; MMC active, 250 kHz, RTC selected lda #mmcsel1 sta spictl ; Set SPI transfer control for writing lda #mmcsel2 sta spidat wait1 lda spistat and #spirdy bne wait1 ; Correct the century byte to 20 lda #century sta clkdat ; Write 7 date/time bytes sequentially ldx #$07 setval lda clkdat,x sta spidat wait2 lda spistat and #spirdy bne wait2 dex bne setval ; Need one more dummy byte to commit lda #$00 sta spidat ; Restore old Chameleon 64 config pla sta spictl pla sta cfgspi ; Disable Chameleon 64 config mode lda #mmcdis sta cfgreg rts