; Read 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 ; ; Output of RTC: ; CC YY MM WD DD HH MM SS (8 bytes) ; value output format is BCD ; ;------------------------------------------------------------------------------- *=$0801 !word bend !word 10 !byte $9e !text "2304", 0 bend: !word 0 ;------------------------------------------------------------------------------- *= $0900 - 8 !byte 0,0,0,0,0,0,0,0 *= $0900 clkdat = *-$08 ; clock output 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 = $92 ; spidat init code mmcrtc = $03 ; cfgspi init code spidat = $df10 ; SPI data transfer reg spictl = $df11 ; SPI control reg spistat = $df12 ; SPI status reg spiread = $00 ; SPI read init code 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 sta spictl ; MMC active, 250 kHz, RTC selected lda #mmcsel1 sta spictl ; Set SPI transfer control for reading lda #mmcsel2 sta spidat wait1 lda spistat and #spirdy bne wait1 ; Read 7 date/time bytes sequentially ldx #$07 getval lda #spiread sta spidat wait2 lda spistat and #spirdy bne wait2 lda spidat sta clkdat,x sta $0400,x dex bne getval ; Set assumed century here lda #century sta clkdat ; Restore old Chameleon 64 config pla sta spictl pla sta cfgspi ; Disable Chameleon 64 config mode lda #mmcdis sta cfgreg rts