A2osX/BIN/NSCUTIL.S.txt
2016-09-21 17:20:37 +02:00

380 lines
6.4 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/BIN/NSCUTIL
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBSTR.I
.INB INC/LIBTCPIP.I
*--------------------------------------
ZPPtr1 .EQ ZPBIN
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START
.DA 0
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.READ.KO .DA MSG.READ.KO
L.MSG.READ.OK1 .DA MSG.READ.OK1
L.MSG.READ.OK2.12 .DA MSG.READ.OK2.12
L.MSG.READ.OK2.24 .DA MSG.READ.OK2.24
L.MSG.READ.OK3 .DA MSG.READ.OK3
L.MSG.READ.OK4 .DA MSG.READ.OK4
L.MSG.USAGE .DA MSG.USAGE
.DA 0
*--------------------------------------
CS.INIT ldy #S.PS.hARGS
lda (pPs),y
bne CS.INIT.SET
CS.INIT.READ jsr NSC.Init
jsr NSC.Read
ldx #7
.1 lda DS1216E.DETECT,x
eor DS1216E.DATA,x
bne .8
dex
bpl .1
>LDYA L.MSG.READ.KO
>SYSCALL SYS.PStrOutYA
lda #DEVMGR.ERRNOHW
sec
rts
.8 jsr NSC.Dump
>LDYA L.MSG.USAGE
>SYSCALL SYS.PStrOutYA
lda #0 tell TSKMGR that all done ok, but
sec we do not want to stay in memory
rts
CS.INIT.SET >SYSCALL SYS.GetMemPtrA
>STYA ZPPtr1
lda (ZPPtr1)
cmp #17
bne .9
ldy #1
stz DS1216E.DATA+7
jsr GetBCD
bcs .9
sta DS1216E.DATA+2
lda (ZPPtr1),y
cmp #'/'
bne .9
iny
jsr GetBCD
bcs .9
sta DS1216E.DATA+1
lda (ZPPtr1),y
cmp #'/'
bne .9
iny
jsr GetBCD
bcs .9
sta DS1216E.DATA
lda (ZPPtr1),y
cmp #' '
bne .9
iny
jsr GetBCD
bcs .9
sta DS1216E.DATA+4
lda (ZPPtr1),y
cmp #':'
bne .9
iny
jsr GetBCD
bcs .9
sta DS1216E.DATA+5
lda (ZPPtr1),y
cmp #':'
bne .9
iny
jsr GetBCD
bcs .9
sta DS1216E.DATA+6
stz DS1216E.DATA+7
jsr NSC.Write
lda #0 tell TSKMGR that all done ok, but
sec we do not want to stay in memory
rts
.9 lda #SYSMGR.ERRSYN
sec
rts
*--------------------------------------
CS.RUN
CS.DOEVENT
CS.QUIT clc
rts
*--------------------------------------
NSC.Init php
sei
lda $CFFF
pha
ldx #7
.1 ldy #8
.2 lda $C304
lsr
ror DS1216E.DETECT,x
dey
bne .2
dex
bpl .1
pla
bmi .99
sta $CFFF
.99 plp
rts
*--------------------------------------
NSC.Select sta $C300
lda $C304 Reset DS1216E comparison register with READ A2=1
ldx #7 Read 8 bytes...
.3 lda DS1216E.PATTERN,x
phx
ldx #8 ....of 8 bits
.4 ldy #0
lsr
bcc .5
iny
.5 pha
lda $C300,y Write Pattern bit in A0, with A2=0
pla
dex
bne .4
plx
dex
bpl .3
rts
*--------------------------------------
NSC.Read php
sei
lda $CFFF
pha
jsr NSC.Select
ldx #7
.1 ldy #8
.2 lda $C304
lsr
ror DS1216E.DATA,x
dey
bne .2
dex
bpl .1
pla
bmi .99
sta $CFFF
.99 plp
rts
*--------------------------------------
NSC.Write php
sei
lda $CFFF
pha
jsr NSC.Select
ldx #7
.3 lda DS1216E.DATA,x
phx
ldx #8 ....of 8 bits
.4 ldy #0
lsr
bcc .5
iny
.5 pha
lda $C300,y Write Pattern bit in A0, with A2=0
pla
dex
bne .4
plx
dex
bpl .3
pla
bmi .99
sta $CFFF
.99 plp
rts
*--------------------------------------
NSC.Dump ldx #1
ldy #1
lda DS1216E.DATA+3
bit #%00010000
beq .1
dex
.1 bit #%00100000
beq .2
dey
.2 txa
>PUSHA
tya
>PUSHA
>LDYA L.MSG.READ.OK1
>SYSCALL SYS.PStrOutYA
>LDYA L.MSG.READ.OK2.24
bit DS1216E.DATA+4
bpl .3
>LDYA L.MSG.READ.OK2.12
.3 >SYSCALL SYS.PStrOutYA
>LDYA L.MSG.READ.OK3
>SYSCALL SYS.PStrOutYA
lda DS1216E.DATA+2
jsr PrintBCD
lda #'/'
>SYSCALL SYS.COutA
lda DS1216E.DATA+1
jsr PrintBCD
lda #'/'
>SYSCALL SYS.COutA
lda DS1216E.DATA
jsr PrintBCD
>LDYA L.MSG.READ.OK4
>SYSCALL SYS.PStrOutYA
lda DS1216E.DATA+4
bpl .4
and #$1F
.4 and #$3F
jsr PrintBCD
lda #':'
>SYSCALL SYS.COutA
lda DS1216E.DATA+5
jsr PrintBCD
lda #':'
>SYSCALL SYS.COutA
lda DS1216E.DATA+6
jsr PrintBCD
lda #'.'
>SYSCALL SYS.COutA
lda DS1216E.DATA+7
jsr PrintBCD
rts
*--------------------------------------
PrintBCD pha
lsr
lsr
lsr
lsr
ora #$30
>SYSCALL SYS.COutA
bcs .9
pla
and #$0f
ora #$30
>SYSCALL SYS.COutA
.9 rts
*--------------------------------------
GetBCD lda (ZPPtr1),y
iny
jsr IsDigit
bcs .9
asl
asl
asl
asl
sta TmpByte
lda (ZPPtr1),y
iny
jsr IsDigit
bcs .9
and #$0f
ora TmpByte
.9 rts
*--------------------------------------
IsDigit cmp #'0'
bcc .9
cmp #'9'+1
and #$0f
rts cc if ok, cs if not
.9 sec
rts
*--------------------------------------
CS.END
MSG.READ.KO >PSTRING "DS1216E Not Detected.\n"
MSG.READ.OK1 >PSTRING "DS1216E Detected:/OSC=%d,/RST=%d,mode="
MSG.READ.OK2.12 >PSTRING "am/pm"
MSG.READ.OK2.24 >PSTRING "24h"
MSG.READ.OK3 >PSTRING "\nDate:"
MSG.READ.OK4 >PSTRING "\nTime:"
MSG.USAGE >PSTRING "\n\nTo Reset the chip and set clock, type:\nNSCUTIL DD/MM/YY hh:mm:ss\n"
TmpByte .BS 1
DS1216E.PATTERN .HS 5CA33AC55CA33AC5 Reverted 7->0
DS1216E.DETECT .BS 8
DS1216E.DATA .BS 8 Reverted YY MM DD Day HH mm SS CS
*--------------------------------------
DS.START
DS.END
*--------------------------------------
MAN
SAVE BIN/NSCUTIL.S
ASM