Zy
"HHf> cPHugo220905
ve 20220220907
VE 20220220908
VE 20220zH$220912
VE 20220L@F7
#LP3
ve
B#VPLPM
ve
B#ZSELPMOD
#<OA
1F9E
1FERHP
4FE8
5OQP9PVC7
P
4#.@xPVC8
4#.oPVC9
P
4#8.PVCA
P
4#.PVCB
P
4#n.PVCC
P
4#.+PVCD
P
4#P/ZPVCe
P
4#/PVCF
P
4#/PVD0
P
4#/PVD1
4#f/PVD2
4#O0]PVD3
P
4#/PVD4
4#/PVD5
P
4#/PVD6
4#/zPVD7
P
4#y/!PVD8
P
4#i0N%PVD9
P
4#0&PVDA
4#0(PVDB
P
4#;11PVDC
000#A14PVDD
000#15PVDE
P
4#18TTIME
#TUTCF
4#y6METEST
0#K)$
$
$
$
$
$
$
$
$
$
$
PHugor7 September 2022
De detectie van de response
verbeterd en meer controle
ingebouwt om te kijken of we wel
een valide response hebben. Ook
begonnen met de retry als er geen
valide response is . De vars voor
month en day van de maand waren
iets te ver afgekort voor die van
dag wat D% was en dat is ook een
basic var. Daarom is daar DAY% van
gemaakt.
Ook begin gemaakt om de tijd te
gaan opslaan in de TIME variable
zodat de tijd automatisch wordt
bijgewerkt. Wat wel mocht van
Roland is het gebruik van directe
geheugen toegang ipv de API. Het
gebruik van copros op de electron
is hoogst onwaarschijnlijk op de
beeb en master zou dit wel kunnen.
Waar mogelijk is wel de API
gebruik gemaakt. Als API gebruik
zou moeten is het mogelijk
noodzakelijk om RAM geheugen te
claimen
Dingen te doen:
 Betere retry in het geval van
niet of verkeerde NTP data
ontvangen
 Update van de TIME variable
 UTC correctie
5 September 2022
Het ontwikkelen van de software
heeft hier en daar behoorlijke
vertraging opgelopen. Allereerst
door werk. In juli en augustus was
ik aan het werk dus geen
ontwikkeling voor de NTP stack.
Dit omdat ik nu wel een echte
WiFi kaart nodig heb.
Iets wat veel tijd heeft gekost is
het feit dat op een gegeven moment
het clearen van page 0 in address
bereik &FDxx niet meer werkte.
Met de logic analyser zou de latch
gewoon moeten werken. Er werd een
klein test programma geschreven
wat wel werkte. Uiteindelijk bleek
de oplossing te zijn om de code te
verwijderen en opnieuw te
schrijven.
CMD 30
O% 100
I = 0 3 3
P% = O%
( BEGIN% = O%
2
[OPT I
< .Test1
F JSR Test2
P RTS
Z .Test2
d JSR Start
n RTS
x
.Start
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
]
F $CMD = "SAVE ASMTST " + ~(O%) + " " + ~(P%) + " " + ~(Start)
X% = CMD 256
" Y% = CMD 256
, &FFF7
1 $CMD
6 "KLAAR"
BPL DDL17
H JSR Sub32
R LDX #3
\ .DDL18
f LDA NM1%,X:STA DOY%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
$ .DDL1A
. CMP #3
8 BPL DDL1B
B LDX #3
L .DDL1C
V! LDA FDBS% + YR%,X:STA NM1%,X
` LDA #0:STA NM2%,X
j DEX
t BPL DDL1C
~ LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
( LDA #2:STA NM2%
2 JSR Add32
< LDA #5:STA NM2%
F JSR Div32
P LDX #3
Z .DDL21
d LDA zNum%,X:STA NM2%,X
n LDA DOY%,X:STA NM1%,X
x DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
" .Mul32
, LDA #0
6 STA MLR%+4
@ STA MLR%+5
J STA MLR%+6
T STA MLR%+7
^ LDX #3
h
.Mul32L1
r LDA NM1%,X:STA MLR%,X
 DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
& ADC NM2%+3
0 STA MLR%+7
: .ROTATE_R
D
ROR A
N ROR MLR%+6
X ROR MLR%+5
b ROR MLR%+4
l .START_R
v ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
* CLD
4 SEC
>
.Sub32L1
H LDA NM1%,Y
R SBC NM2%,Y
\ STA NM1%,Y
f INY
p DEX
z BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
$ DEX
. BNE Add32L1
8 PLA:TAY
B PLA:TAX
L RTS
V .Div32
` TXA:PHA
j TYA:PHA
t LDX #3
~ .CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
( .Subtract
2 LDA zRem%
< SBC zDen%
F STA zTemp%
P LDA zRem% + 1
Z SBC zDen% + 1
d STA zTemp% + 1
n LDA zRem% + 2
x SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
" PLA:TAX
, RTS
6 .StoreToTIME
@ LDX #3
J .STTI1
T LDA #0:STA NM1%,X
^% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
h DEX
r BPL STTI1
 LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
& LDY #0
0 JSR &FFF4
: LDY #0
D
LDA #10
N STA NM2%
X .PrTiL1
b LDA FDBS% + HR%,Y
l
STA NM1%
v JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
*
STA NM1%
4 JSR Conv2d
> LDA #&2D
H JSR &FFEE
R# \ Year printing is different \
\
LDA #100
f
STA NM2%
p LDX #3
z
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STUDP
0.nl.pool.ntp.org
123 rP P hP aP V` .V \V` cQ R R` P P P P` `OLP2OO腖O0
LPe ` + I P DL*Q٩Ơ `` :LQi) `HH ;0H Qh Q T Q tU QLQH Qh QI T Q VU Q Qhh`HHhh`HHhh`HHvRhh`HHH hhh`rR UvR U< U`Q
::zR tU~R U T VUR U VUR U tUR U VUT UT T tUT TNnnn tUd U VU VU T tU U
iLfT # tU T tU U VU tU`m!1%mmmmjnnnnnnn`HH8hh(`HHyhh`HH .......8аhh`d TǠ ` V
V: ` V V d U V
V V ` Ui0 i0 ``
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
tA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
$
STA NM1%
. JSR Conv2d
8 JSR &FFE7
B RTS
L .Conv2d
V JSR Div32
` LDA zNum%
j CLC
t
ADC #&30
~ JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
( "SIZE : " +(P%PROG%)
2H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
< Y% = CMD 256
F X% = CMD 256
P &FFF7
Z $CMD
7Zdnx",6@JT^hr&0:DNXblv *4>HR\fpz$Time
V LDX #3
` .DTL1
j LDA STORE%,X:STA NM1%,X
t LDA DayS,X:STA NM2%,X
~ DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
( LDA zRem%,X:STA NM1%,X
2 LDA #0:STA NM2%,X
< DEX
F
BPL DTL3
P LDA #&3C:STA NM2%
Z JSR Div32
d! LDA zNum% : STA FDBS% + MIN%
n# LDA zRem% : STA FDBS% + SEC%
x RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
" .DDL1
, LDA DAYT%,X:STA NM1%,X
6 LDA YrCr,X:STA NM2%,X
@ DEX
J BPL DDL1
T JSR Add32
^ \ era = days / 146097 \
h LDX #3
r .DDL3
 LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
& DEX
0 BPL DDL6
: JSR Sub32
D LDX #3
N .DDL7
X LDA NM1%,X:STA DOE%,X
b LDA c1460,X:STA NM2%,X
l DEX
v
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
* LDX #3
4 .DDLA
> LDA zNum%,X:STA NM1%,X
H LDA STORE%,X:STA NM2%,X
R DEX
\ BPL DDLA
f JSR Add32
p LDX #3
z
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
$ LDA year,X:STA NM2%,X
. DEX
8 BPL DDLD
B JSR Div32
L \ Store result in YOE% \
V LDX #3
` .DDLE
j LDA zNum%,X:STA YOE%,X
t DEX
~
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
( LDX #3
2 .DDL11
0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA MLR%,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
$ .DTL1
. LDA STORE%,X:STA NM1%,X
8 LDA DayS,X:STA NM2%,X
B DEX
L
BPL DTL1
V JSR Div32
` \ hours = seconds / 3600 \
j LDX #3
t
.DTL2
~ LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
(! LDA zNum% : STA FDBS% + MIN%
2# LDA zRem% : STA FDBS% + SEC%
< RTS
F
.DayS
P EQUD &00015180
Z
.HrsS
d EQUD &00000E10
n
.YrCr
x EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
" \ era = days / 146097 \
, LDX #3
6 .DDL3
@ LDA NM1%,X:STA DYS%,X
J LDA Yr400,X:STA NM2%,X
T DEX
^ BPL DDL3
h JSR Div32
r LDX #3
 .DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
& LDA c1460,X:STA NM2%,X
0 DEX
:
BPL DDL7
D JSR Div32
N \ doe  doe / 1460 \
X LDX #3
b .DDL8
l LDA zNum%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
* JSR Add32
4 LDX #3
>
.DDLB
H LDA NM1%,X: STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c146096,X:STA NM2%,X
f DEX
p BPL DDLB
z JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
& LDA #0:STA NM2%,X
0 DEX
: BPL DDL18
D LDA #5:STA NM2%
N JSR Mul32
X LDA #2:STA NM2%
b JSR Add32
l LDA #153:STA NM2%
v JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
* BPL DDL1C
4 LDA #1:STA NM2%
> JSR Add32
H LDX #3
R .DDL1D
\ LDA NM1%,X:STA FDBS%+YR%,X
f DEX
p BPL DDL1D
z .DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
$ LDA DOY%,X:STA NM1%,X
. DEX
8 BPL DDL21
B JSR Sub32
L LDX #3
V LDA #0
` .DDL22
j STA NM2%,X
t DEX
~ BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
( LDA NM1%,X:STA MLR%,X
2 DEX
< BPL Mul32L1
F
LDX #&21
P BNE START_R
Z
.SHIFT_R
d BCC ROTATE_R
n LDA MLR%+4
x CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
" .START_R
, ROR MLR%+3
6 ROR MLR%+2
@ ROR MLR%+1
J
ROR MLR%
T DEX
^ BNE SHIFT_R
h LDX #3
r
.Mul32L2
 LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
& DEX
0 BNE Sub32L1
: PLA:TAY
D
PLA:TAX
N PLP
X RTS
b .Add32
l TXA:PHA
v TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
* LDX #3
4 .CND
> LDA NM1%,X:STA zNum%,X
H LDA NM2%,X:STA zDen%,X
R LDA #0:STA zRem%,X
\ DEX
f
BPL CND
p LDX #32
z
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
$ LDA zRem% + 2
. SBC zDen% + 2
8 STA zTemp% + 2
B LDA zRem% + 3
L SBC zDen% + 3
V STA zTemp% + 3
`
BCC Next
j INC zNum%
t LDY #3
~ .CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
( BPL STTI1
2 LDA #100:STA NM1%
< JSR Mul32
F LDX #3
P .STTI2
Z$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
d DEX
n BPL STTI2
x LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
"
STA NM1%
, JSR Conv2d
6 LDA #&3A
@ CPY #2
J BEQ PrTiL2
T JSR &FFEE
^ .PrTiL2
h INY
r CPY #3
 BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
& LDX #3
0
.PDL1
: LDA FDBS%+YR%,X
D STA NM1%,X
N DEX
X BPL PDL1
b JSR Div32
l$ \ STORE LOWER PART OF YEAR \
v LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2% DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
$ .DDLE
. LDA zNum%,X:STA YOE%,X
8 DEX
B
BPL DDLE
L \ era * 400 \
V LDX #3
`
.DDLF
j LDA ERA%,X:STA NM1%,X
t LDA c400,X:STA NM2%,X
~ DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
( .DDL12
2 LDA year,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL12
Z JSR Mul32
d LDX #3
n .DDL13
x LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
" BPL DDL15
, LDA #100:STA NM2%
6 JSR Div32
@ LDX #3
J
.DDL16
T LDA zNum%,X:STA NM2%,X
^ LDA STORE%,X:STA NM1%,X
h DEX
r BPL DDL16
 JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
& JSR Add32
0 LDA #153:STA NM2%
: JSR Div32
D LDA zNum%:STA MP%
N CMP #10
X BPL DDL19
b ADC #3
l STA FDBS%+MN%
v JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
* DEX
4 BPL DDL1D
> .DDL1B
H LDX #3
R LDA #0
\ .DDL20
f STA NM1%,X:STA NM2%,X
p DEX
z BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
$ .DDL22
. STA NM2%,X
8 DEX
B BPL DDL22
L LDA #1:STA NM2%
V JSR Add32
` LDA NM1% :STA FDBS%+DAY%
j RTS
t
.year
~ EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
( BCC ROTATE_R
2 LDA MLR%+4
< CLC
F ADC NM2%
P STA MLR%+4
Z LDA MLR%+5
d ADC NM2%+1
n STA MLR%+5
x LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
" BNE SHIFT_R
, LDX #3
6
.Mul32L2
@ LDA MLR%,X:STA NM1%,X
J DEX
T BPL Mul32L2
^ RTS
h
.Sub32
r PHP
 TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
& .Add32
0 TXA:PHA
: TYA:PHA
D LDY #0
N LDX #4
X CLD
b CLC
l
.Add32L1
v LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
*
BPL CND
4 LDX #32
>
.Divide
H ASL zNum%
R ROL zNum% + 1
\ ROL zNum% + 2
f ROL zNum% + 3
p ROL zRem%
z ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
$
BCC Next
. INC zNum%
8 LDY #3
B .CpTmpToRem
L LDA zTemp%, Y
V
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
*
ADC #&30
4 JSR &FFEE
> LDA zRem%
H CLC
R ADC #&30
\ JSR &FFEE
f RTS
p .ClearNums
z$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
(2<FPZdnx",6@JT^hr&0:DNXblv *4>HR\fp
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
STA zRem% , Y
` DEY
j BPL CpTmpToRem
t .Next
~ DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
( DEX
2 BPL STTI2
< LDA #&2
F LDX #(FDBS%+TIMEVAR%) 256
P LDY #(FDBS%+TIMEVAR%) 256
Z JSR &FFF1
d RTS
n .PrintTime
x JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
" .PrTiL2
, INY
6 CPY #3
@ BNE PrTiL1
J JSR &FFE7
T RTS
^ .PrintDate
h LDA FDBS%+DAY%
r STA NM1%
 JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
& JSR Div32
0$ \ STORE LOWER PART OF YEAR \
: LDA zRem%
D STA STORE%
N JSR ClearNums
X LDA #10
b STA NM2%
l LDA zNum%
v
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
* RTS
4 .ClearNums
>$ \ NM1 and NM2 are in one line \
H LDX #7
R LDA #0
\
.CNL1
f STA NM1%,X
p DEX
z
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
5UMD$SAVE NTP 4D37 53DA 4DA0
DDBS%VR%cLIN%LEC%uLAY%LN%LR%LYS%RA%LOE%VOE%MOY%LP%LNum%LDen%LTemp%Rem%LM1%FYM2%XLR%XTOR8 September 2022
Geimplementeerd:
 setten van de TIME variabele met
OSWORD &2 ( Set system clock )
Dit was reletief makkelijk omdat
bij het bereken van de tijd een
van de tussenresultaten al het
aantal seconden is zoals bij TIME
wordt gebruikt. Het enige wat
nodig was om dit getal met 100 te
vermenigvuldigen.
Ook moest geheugen beschikaar
worden gemaakt om de OSWORD call
te kunnen doen. Dit geheugen wordt
neergezet in het RAM van de WiFi
kaart. Dat dit geheugen langzamer
is is voor het aanroepen van deze
call niet echt relevant
Nog te implementeren:
 UTC correctie
 onderbrengen in sideway rom
*NTP
T=
S = (T 100) 60
M = (T 6000) 60
(H = (T 360000) 24
2 H;":";M;":";S;
i `dc
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 :12 September 2022
Geimplementeerd:
 UTC correctie. Omdat stukken
code hetzelfde zijn is een
gedeelte als utility subroutines
toegevoed. Voor negatieve,
positieve en geen UTC correctie
wordt door middel van jumps
geimplementeerd. Voor geen UTC
correctie wordt zo snel mogelijk
uit de subroutine gesprongen. Voor
positief wordt vermenigvuldigd en
opgeteld en voor negatief wordt de
UTC getal van teken veranderd door
eerst af te trekken en dan een XOR
te doen daarna vermenigvukdigen
maal het aantal seconden in een
uur ( al beschikbare constante )
en dan af te trekken van de
seconden die in NTP struct staan.
Nog te implementeren:
Retry in het geval geen data is
ontvangen of rubbish
Implement *HELP
" (c) Bruce Smith October 1984
The BBC Micro ROM Book
(:
2osnewl = &FFE7
< pass% = 4 7 3
FP% = &8000 : O% = &5000
P[
Z
OPT pass%
d
EQUB 0
n
EQUW 0
xJMP service_entry
EQUB &82
EQUB offset 256
EQUBv JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
\BMI UTCCNEG \
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA HrsS,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
$ .DTL1
. LDA STORE%,X:STA NM1%,X
8 LDA DayS,X:STA NM2%,X
B DEX
L
BPL DTL1
V JSR Div32
` \ hours = seconds / 3600 \
j LDX #3
t
.DTL2
~ LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
(! LDA zNum% : STA FDBS% + MIN%
2# LDA zRem% : STA FDBS% + SEC%
< RTS
F
.DayS
P EQUD &00015180
Z
.HrsS
d EQUD &00000E10
n
.YrCr
x EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
" \ era = days / 146097 \
, LDX #3
6 .DDL3
@ LDA NM1%,X:STA DYS%,X
J LDA Yr400,X:STA NM2%,X
T DEX
^ BPL DDL3
h JSR Div32
r LDX #3
 .DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
& LDA c1460,X:STA NM2%,X
0 DEX
:
BPL DDL7
D JSR Div32
N \ doe  doe / 1460 \
X LDX #3
b .DDL8
l LDA zNum%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
* JSR Add32
4 LDX #3
>
.DDLB
H LDA NM1%,X: STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c146096,X:STA NM2%,X
f DEX
p BPL DDLB
z JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
$ .DDLE
. LDA zNum%,X:STA YOE%,X
8 DEX
B
BPL DDLE
L \ era * 400 \
V LDX #3
`
.DDLF
j LDA ERA%,X:STA NM1%,X
t LDA c400,X:STA NM2%,X
~ DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
( .DDL12
2 LDA year,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL12
Z JSR Mul32
d LDX #3
n .DDL13
x LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
" BPL DDL15
, LDA #100:STA NM2%
6 JSR Div32
@ LDX #3
J
.DDL16
T LDA zNum%,X:STA NM2%,X
^ LDA STORE%,X:STA NM1%,X
h DEX
r BPL DDL16
 JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
L 1
.title
EQUS "BASIC Tools 1.00"
EQUB 0
.offset
EQUB 0
EQUS "(C) Love Bytes"
EQUB 0
.service_entry
PHA
CMP #9
BEQ help
PLA
RTS
" .help
,JSR osnewl
6LDX #&FF
@
.helploop
JINX
TLDA title,X
^
JSR &FFE3
hBNE helploop
rJSR osnewl
PLA
RTS
]
~O%
L+BASIC Tools 1.00(C) Love BytesH h` h`L*BASIC Tools 1.00(C) Love BytesH h` h`
store 512
Implement *HELP
" (c) Bruce Smith October 1984
( The BBC Micro ROM Book
2:
<osnewl = &FFE7
F pass% = 4 7 3
PP% = &8000 : O% = store
Z[
d
OPT pass%
n
EQUB 0
x
EQUW 0
JMP service_entry
EQUB &82
EQUB offset 256
EQUB 1
.title
EQUS "BASIC Tools 1.00"
EQUB 0
.offset
EQUB 0
EQUS "(C) Love Bytes"
EQUB 0
.service_entry
PHA
CMP #9
BEQ help
PLA
"RTS
, .help
6JSR osnewl
@LDX #&FF
J
.helploop
TINX
^LDA title,X
h
JSR &FFE3
rBNE helploop
JSR osnewl
PLA
RTS
]
~store
~O%
!tore{0L*BASIC Tools 1.00(C) Love BytesH h` h`
store 512
Implement *HELP
" (c) Bruce Smith October 1984
( The BBC Micro ROM Book
2:
<osnewl = &FFE7
F osasci = &FFE3
P pass% = 4 7 3
ZP% = &8000 : O% = store
d[
n
OPT pass%
x
EQUB 0
EQUW 0
JMP service_entry
EQUB &82
EQUB offset 256
EQUB 1
.title
EQUS "BASIC Tools"
EQUB 0
.version
EQUS " 1.00"
EQUB 0
.offset
EQUB 0
EQUS "(C) Love Bytes"
EQUB 0
.service_entry
"PHA
,
CMP #9
6BEQ help
@PLA
JRTS
T .help
^
TYA:PHA
h TXA:PHA
r LDA (&F2),Y
 CMP #13
BEQ over
LDX #&FF
DEY
.ntploop
INX
INY
LDA ntphlp,X
CMP (&F2),Y
BEQ ntploop
CMP #&FE
BEQ details
PLA:TAX
PLA:TAY
JMP return
.over
JSR printhelp
& PLA:TAX
0 PLA:TAY
: .return
D PLA
N RTS
X .printhelp
b JSR osnewl
l
LDX #&FF
v
.helploop
INX
LDA title,X
JSR osasci
BNE helploop
JSR osnewl
PLA
RTS
]
~store
~O%
~O%
~O%
dnxTA NM2%,X
DEX
BPL DTL2
JSR Div32
* LDA zNum%:STA FDBS% + HR%
4 LDX #3
>
.DTL3
H LDA zRem%,X:STA NM1%,X
R LDA #0:STA NM2%,X
\ DEX
f
BPL DTL3
p LDA #&3C:STA NM2%
z JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
$ EQUD &00023AB0
. .DecoDate
8 LDX #3
B .DDL1
L LDA DAYT%,X:STA NM1%,X
V LDA YrCr,X:STA NM2%,X
` DEX
j BPL DDL1
t JSR Add32
~ \ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
( .DDL6
2 LDA MLR%,X:STA NM2%,X
< LDA DYS%,X:STA NM1%,X
F DEX
P BPL DDL6
Z JSR Sub32
d LDX #3
n .DDL7
x LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
" LDA c36524,X:STA NM2%,X
, DEX
6
BPL DDL9
@ JSR Div32
J LDX #3
T .DDLA
^ LDA zNum%,X:STA NM1%,X
h LDA STORE%,X:STA NM2%,X
r DEX
 BPL DDLA
JSR Add32
LDX #DA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
& JSR Add32
0 LDA #153:STA NM2%
: JSR Div32
D LDA zNum%:STA MP%
N CMP #10
X BPL DDL19
b ADC #3
l STA FDBS%+MN%
v JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
* DEX
4 BPL DDL1D
> .DDL1B
H LDX #3
R LDA #0
\ .DDL20
f STA NM1%,X:STA NM2%,X
p DEX
z BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
$ .DDL22
. STA NM2%,X
8 DEX
B BPL DDL22
L LDA #1:STA NM2%
V JSR Add32
` LDA NM1% :STA FDBS%+DAY%
j RTS
t
.year
~ EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
( BCC ROTATE_R
2 LDA MLR%+4
< CLC
F ADC NM2%
P STA MLR%+4
Z LDA MLR%+5
d ADC NM2%+1
n STA MLR%+5
x LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
" BNE SHIFT_R
, LDX #3
6
.Mul32L2
@ LDA MLR%,X:STA NM1%,X
J DEX
T BPL Mul32L2
^ RTS
h
.Sub32
r PHP
 TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
& .Add32
0 TXA:PHA
: TYA:PHA
D LDY #0
N LDX #4
X CLD
b CLC
l
.Add32L1
v LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
*
BPL CND
4 LDX #32
>
.Divide
H ASL zNum%
R ROL zNum% + 1
\ ROL zNum% + 2
f ROL zNum% + 3
p ROL zRem%
z ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
$
BCC Next
. INC zNum%
8 LDY #3
B .CpTmpToRem
L LDA zTemp%, Y
V STA zRem% , Y
` DEY
j BPL CpTmpToRem
t .Next
~ DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
( DEX
2 BPL STTI2
< LDA #&2
F LDX #(FDBS%+TIMEVAR%) 256
P LDY #(FDBS%+TIMEVAR%) 256
Z JSR &FFF1
d RTS
n .PrintTime
x JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
" .PrTiL2
, INY
6 CPY #3
@ BNE PrTiL1
J JSR &FFE7
T RTS
^ .PrintDate
h LDA FDBS%+DAY%
r STA NM1%
 JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
& JSR Div32
0$ \ STORE LOWER PART OF YEAR \
: LDA zRem%
D STA STORE%
N JSR ClearNums
X LDA #10
b STA NM2%
l LDA zNum%
v
STA NM1%
\ Conv. upp. part of year \
JSR Conv3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
& JSR Sub32
0 LDX #3
: .DDLD
D LDA year,X:STA NM2%,X
N DEX
X BPL DDLD
b JSR Div32
l \ Store result in YOE% \
v LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
* DEX
4 BPL DDL10
> JSR Add32
H LDX #3
R .DDL11
\! LDA NM1%,X:STA FDBS% + YR%,X
f DEX
p BPL DDL11
z LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
$ DEX
. BPL DDL14
8 JSR Add32
B LDX #3
L .DDL15
V LDA NM1%,X:STA STORE%,X
` LDA #0:STA NM2%,X
j LDA YOE%,X:STA NM1%,X
t DEX
~ BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
( LDX #3
2 .DDL18
< LDA NM1%,X:STA DOY%,X
F LDA #0:STA NM2%,X
P DEX
Z BPL DDL18
d LDA #5:STA NM2%
n JSR Mul32
x LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
" .DDL1C
,! LDA FDBS% + YR%,X:STA NM1%,X
6 LDA #0:STA NM2%,X
@ DEX
J BPL DDL1C
T LDA #1:STA NM2%
^ JSR Add32
h LDX #3
r .DDL1D
 LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
& LDX #3
0 .DDL21
: LDA zNum%,X:STA NM2%,X
D LDA DOY%,X:STA NM1%,X
N DEX
X BPL DDL21
b JSR Sub32
l LDX #3
v LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
* STA MLR%+7
4 LDX #3
>
.Mul32L1
H LDA NM1%,X:STA MLR%,X
R DEX
\ BPL Mul32L1
f
LDX #&21
p BNE START_R
z
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
$ ROR MLR%+6
. ROR MLR%+5
8 ROR MLR%+4
B .START_R
L ROR MLR%+3
V ROR MLR%+2
` ROR MLR%+1
j
ROR MLR%
t DEX
~ BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
( SBC NM2%,Y
2 STA NM1%,Y
< INY
F DEX
P BNE Sub32L1
Z PLA:TAY
d
PLA:TAX
n PLP
x RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
" RTS
, .Div32
6 TXA:PHA
@ TYA:PHA
J LDX #3
T .CND
^ LDA NM1%,X:STA zNum%,X
h LDA NM2%,X:STA zDen%,X
r LDA #0:STA zRem%,X
 DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC 2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
* RTS
4 .ClearNums
>$ \ NM1 and NM2 are in one line \
H LDX #7
R LDA #0
\
.CNL1
f STA NM1%,X
p DEX
z
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
CUMD&SAVE NTP 4D38 53D9 4DA1
DDBS%VR%dLIN%LEC%vLAY%LN%LR%LYS%RA%LOE%VOE%MOY%LP%LNum%LDen%LTemp%Rem%LM1%GYM2%}XLR%XTO
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
zDen%
STA zTemp%
& LDA zRem% + 1
0 SBC zDen% + 1
: STA zTemp% + 1
D LDA zRem% + 2
N SBC zDen% + 2
X STA zTemp% + 2
b LDA zRem% + 3
l SBC zDen% + 3
v STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
* LDA #0:STA NM1%,X
4% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
> DEX
H BPL STTI1
R LDA #100:STA NM1%
\ JSR Mul32
f LDX #3
p .STTI2
z$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
$ STA NM2%
. .PrTiL1
8 LDA FDBS% + HR%,Y
B
STA NM1%
L JSR Conv2d
V LDA #&3A
` CPY #2
j BEQ PrTiL2
t JSR &FFEE
~ .PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
(# \ Year printing is different \
2
LDA #100
<
STA NM2%
F LDX #3
P
.PDL1
Z LDA FDBS%+YR%,X
d STA NM1%,X
n DEX
x BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
" .Conv2d
, JSR Div32
6 LDA zNum%
@ CLC
J
ADC #&30
T JSR &FFEE
^ LDA zRem%
h CLC
r ADC #&30
 JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
& &FFF7
0 $CMD
$CMD
(RMDNSAVE NTP 4A4C 5097 4AB5
DBS%DBS%SR%xIIN%JEC%IAY%IN%IR%IYS%RA%IOE%SOE%JOY%JP%INum%IDen%ITemp%Rem%IM1%VM2
" PROGRAM TO SET UTC EXP. FLAG
A% = &93
X% = &FF
(
Y% = 1
2 &FFF4
<A% = &95
F
X% = 0
P
Y% = 2
Z &FFF4
1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 Sv JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA HrsS,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
$ .DTL1
. LDA STORE%,X:STA NM1%,X
8 LDA DayS,X:STA NM2%,X
B DEX
L
BPL DTL1
V JSR Div32
` \ hours = seconds / 3600 \
j LDX #3
t
.DTL2
~ LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
(! LDA zNum% : STA FDBS% + MIN%
2# LDA zRem% : STA FDBS% + SEC%
< RTS
F
.DayS
P EQUD &00015180
Z
.HrsS
d EQUD &00000E10
n
.YrCr
x EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
" \ era = days / 146097 \
, LDX #3
6 .DDL3
@ LDA NM1%,X:STA DYS%,X
J LDA Yr400,X:STA NM2%,X
T DEX
^ BPL DDL3
h JSR Div32
r LDX #3
 .DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
& LDA c1460,X:STA NM2%,X
0 DEX
:
BPL DDL7
D JSR Div32
N \ doe  doe / 1460 \
X LDX #3
b .DDL8
l LDA zNum%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
* JSR Add32
4 LDX #3
>
.DDLB
H LDA NM1%,X: STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c146096,X:STA NM2%,X
f DEX
p BPL DDLB
z JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
$ .DDLE
. LDA zNum%,X:STA YOE%,X
8 DEX
B
BPL DDLE
L \ era * 400 \
V LDX #3
`
.DDLF
j LDA ERA%,X:STA NM1%,X
t LDA c400,X:STA NM2%,X
~ DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
( .DDL12
2 LDA year,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL12
Z JSR Mul32
d LDX #3
n .DDL13
x LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
" BPL DDL15
, LDA #100:STA NM2%
6 JSR Div32
@ LDX #3
J
.DDL16
T LDA zNum%,X:STA NM2%,X
^ LDA STORE%,X:STA NM1%,X
h DEX
r BPL DDL16
 JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA TA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
\TYA:PHA \
JSR SelPZ
\PLA:TAY \
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
\LDA #&93\
\LDX #&FF\
\LDY #0\
\JSR &FFF4 \
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.SelPZ
$ \ Select page 0
. \ Reg X,Y and A preserved
8 TXA:PHA
B TYA:PHA
L PHA
V
LDA #&93
`
LDX #&FF
j LDY #0
t JSR &FFF4
~ PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
(" \ To be used to set value
2% LDA zRem%,X:STA &FD00+TIMEVAR%,X
< LDA HrsS,X:STA NM2%,X
F DEX
P BPL DTL2
Z JSR Div32
d LDA zNum%:STA FDBS% + HR%
n LDX #3
x
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
" EQUD &00023AB1
, .c1460
6 EQUD &000005B4
@ .c36524
J EQUD &00008EAC
T
.c146096
^ EQUD &00023AB0
h .DecoDate
r LDX #3
 .DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
& LDA zNum%,X:STA NM1%,X
0 DEX
:
BPL DDL5
D JSR Mul32
N \ days  era * 146097 \
X LDX #3
b .DDL6
l LDA MLR%,X:STA NM2%,X
v LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
& JSR Add32
0 LDA #153:STA NM2%
: JSR Div32
D LDA zNum%:STA MP%
N CMP #10
X BPL DDL19
b ADC #3
l STA FDBS%+MN%
v JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
* DEX
4 BPL DDL1D
> .DDL1B
H LDX #3
R LDA #0
\ .DDL20
f STA NM1%,X:STA NM2%,X
p DEX
z BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
$ .DDL22
. STA NM2%,X
8 DEX
B BPL DDL22
L LDA #1:STA NM2%
V JSR Add32
` LDA NM1% :STA FDBS%+DAY%
j RTS
t
.year
~ EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
( BCC ROTATE_R
2 LDA MLR%+4
< CLC
F ADC NM2%
P STA MLR%+4
Z LDA MLR%+5
d ADC NM2%+1
n STA MLR%+5
x LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
" BNE SHIFT_R
, LDX #3
6
.Mul32L2
@ LDA MLR%,X:STA NM1%,X
J DEX
T BPL Mul32L2
^ RTS
h
.Sub32
r PHP
 TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
& .Add32
0 TXA:PHA
: TYA:PHA
D LDY #0
N LDX #4
X CLD
b CLC
l
.Add32L1
v LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
*
BPL CND
4 LDX #32
>
.Divide
H ASL zNum%
R ROL zNum% + 1
\ ROL zNum% + 2
f ROL zNum% + 3
p ROL zRem%
z ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
$
BCC Next
. INC zNum%
8 LDY #3
B .CpTmpToRem
L LDA zTemp%, Y
V STA zRem% , Y
` DEY
j BPL CpTmpToRem
t .Next
~ DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
( DEX
2 BPL STTI2
< LDA #&2
F LDX #(FDBS%+TIMEVAR%) 256
P LDY #(FDBS%+TIMEVAR%) 256
Z JSR &FFF1
d RTS
n .PrintTime
x JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
" .PrTiL2
, INY
6 CPY #3
@ BNE PrTiL1
J JSR &FFE7
T RTS
^ .PrintDate
h LDA FDBS%+DAY%
r STA NM1%
 JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
& JSR Div32
0$ \ STORE LOWER PART OF YEAR \
: LDA zRem%
D STA STORE%
N JSR ClearNums
X LDA #10
b STA NM2%
l LDA zNum%
v
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
* JSR Sub32
4 LDX #3
> .DDL9
H LDA NM1%,X:STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c36524,X:STA NM2%,X
f DEX
p
BPL DDL9
z JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
$ LDX #3
.
.DDLC
8 LDA STORE%,X:STA NM1%,X
B LDA zNum%,X:STA NM2%,X
L DEX
V
BPL DDLC
` JSR Sub32
j LDX #3
t .DDLD
~ LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
( JSR Mul32
2 \ yoe + era * 400 \
< LDX #3
F .DDL10
P LDA MLR%,X:STA NM1%,X
Z LDA YOE%,X:STA NM2%,X
d DEX
n BPL DDL10
x JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
" LDX #1
, .DDL14
6 LSR NM2%+3
@ ROR NM2%+2
J ROR NM2%+1
T ROR NM2%
^ DEX
h BPL DDL14
r JSR Add32
 LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
& .DDL17
0 LDA NM1%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL17
X JSR Sub32
b LDX #3
l .DDL18
v LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
* STA FDBS%+MN%
4 .DDL1A
> CMP #3
H BPL DDL1B
R LDX #3
\ .DDL1C
f! LDA FDBS% + YR%,X:STA NM1%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
$ LDA MP%: STA NM1%
. JSR Mul32
8 LDA #2:STA NM2%
B JSR Add32
L LDA #5:STA NM2%
V JSR Div32
` LDX #3
j .DDL21
t LDA zNum%,X:STA NM2%,X
~ LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
( EQUD &00000190
2 .Mul32
< LDA #0
F STA MLR%+4
P STA MLR%+5
Z STA MLR%+6
d STA MLR%+7
n LDX #3
x
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
" STA MLR%+6
, LDA MLR%+7
6 ADC NM2%+3
@ STA MLR%+7
J .ROTATE_R
T
ROR A
^ ROR MLR%+6
h ROR MLR%+5
r ROR MLR%+4
 .START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
& LDX #4
0 LDY #0
: CLD
D SEC
N
.Sub32L1
X LDA NM1%,Y
b SBC NM2%,Y
l STA NM1%,Y
v INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
* INY LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
* RTS
4 .ClearNums
>$ \ NM1 and NM2 are in one line \
H LDX #7
R LDA #0
\
.CNL1
f STA NM1%,X
p DEX
z
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
UMD$SAVE NTP 4D37 53DA 4DA0
DDBS%VR%cLIN%LEC%uLAY%LN%LR%LYS%RA%LOE%VOE%MOY%LP%LNum%LDen%LTemp%Rem%LM1%FYM2%XLR%XTOR
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
4 DEX
> BNE Add32L1
H PLA:TAY
R PLA:TAX
\ RTS
f .Div32
p TXA:PHA
z TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
$ ROL zRem% + 3
. SEC
8 .Subtract
B LDA zRem%
L SBC zDen%
V STA zTemp%
` LDA zRem% + 1
j SBC zDen% + 1
t STA zTemp% + 1
~ LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
( PLA:TAY
2 PLA:TAX
< RTS
F .StoreToTIME
P LDX #3
Z .STTI1
d LDA #0:STA NM1%,X
n% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
x DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
" LDA #&93
,
LDX #&FF
6 LDY #0
@ JSR &FFF4
J LDY #0
T
LDA #10
^ STA NM2%
h .PrTiL1
r LDA FDBS% + HR%,Y

STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
& JSR &FFEE
0 LDA FDBS%+MN%
:
STA NM1%
D JSR Conv2d
N LDA #&2D
X JSR &FFEE
b# \ Year printing is different \
l
LDA #100
v
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
* LDA STORE%
4
STA NM1%
> JSR Conv2d
H JSR &FFE7
R RTS
\ .Conv2d
f JSR Div32
p LDA zNum%
z CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
$ ]
. Pass%
8 "SIZE : " +(P%PROG%)
BH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
L Y% = CMD 256
V X% = CMD 256
` &FFF7
j $CMD
$CMD
F7
j $CMD
UMDSAVE NTP 4E03 54B7 4E6C
WR%D
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 Sv JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA MLR%,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
$ LDY #0
. JSR &FFF4
8 PLA:TAY
B PLA:TAX
L RTS
V .DecoTime
` LDX #3
j .DTL1
t LDA STORE%,X:STA NM1%,X
~ LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
(
.DTL3
2 LDA zRem%,X:STA NM1%,X
< LDA #0:STA NM2%,X
F DEX
P
BPL DTL3
Z LDA #&3C:STA NM2%
d JSR Div32
n! LDA zNum% : STA FDBS% + MIN%
x# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
" LDX #3
, .DDL1
6 LDA DAYT%,X:STA NM1%,X
@ LDA YrCr,X:STA NM2%,X
J DEX
T BPL DDL1
^ JSR Add32
h \ era = days / 146097 \
r LDX #3
 .DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
& LDA DYS%,X:STA NM1%,X
0 DEX
: BPL DDL6
D JSR Sub32
N LDX #3
X .DDL7
b LDA NM1%,X:STA DOE%,X
l LDA c1460,X:STA NM2%,X
v DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
* JSR Div32
4 LDX #3
> .DDLA
H LDA zNum%,X:STA NM1%,X
R LDA STORE%,X:STA NM2%,X
\ DEX
f BPL DDLA
p JSR Add32
z LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
$ .DDLD
. LDA year,X:STA NM2%,X
8 DEX
B BPL DDLD
L JSR Div32
V \ Store result in YOE% \
` LDX #3
j .DDLE
t LDA zNum%,X:STA YOE%,X
~ DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
( JSR Add32
2 LDX #3
< .DDL11
F! LDA NM1%,X:STA FDBS% + YR%,X
P DEX
Z BPL DDL11
d LDX #3
n .DDL12
x LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
" JSR Add32
, LDX #3
6 .DDL15
@ LDA NM1%,X:STA STORE%,X
J LDA #0:STA NM2%,X
T LDA YOE%,X:STA NM1%,X
^ DEX
h BPL DDL15
r LDA #100:STA NM2%
 JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,TA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
JSR StoMLR
JSR Add32
LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
* JMP UTCCEND
4
.UTCCNEG
> \ Select page 0
H TYA:PHA
R JSR SelPZ
\ PLA:TAY
f JSR StoZero
p
.UTCCEND
z JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.NMToSTR
\ Copies NM1% to STORE%
\ Reg. X and A preserved
TXA:PHA
PHA
PLA
PLA:TAX
RTS
.StoMLR
\ Copies STORE% to NM1%
\ Copies MLR% to NM2%
\ Preserves A and Z
TXA:PHA
$ PHA
. LDX #3
8 .STMLR1
B LDA STORE%,X:STA NM1%,X
L LDA MLR%,X:STA NM2%,X
V DEX
` BPL STMLR1
j PLA
t PLA:TAX
~ RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.STZE1
LDA HrsS,X : STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL STZE1
PLA
PLA:TAX
RTS
.SelPZ
( \ Select page 0
2 \ Reg X,Y and A preserved
< TXA:PHA
F TYA:PHA
P PHA
Z
LDA #&93
d
LDX #&FF
n LDY #0
x JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
" LDA zRem%,X:STA NM1%,X
," \ To be used to set value
6% LDA zRem%,X:STA &FD00+TIMEVAR%,X
@ LDA HrsS,X:STA NM2%,X
J DEX
T BPL DTL2
^ JSR Div32
h LDA zNum%:STA FDBS% + HR%
r LDX #3

.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
& EQUD &00023AB1
0 .c1460
: EQUD &000005B4
D .c36524
N EQUD &00008EAC
X
.c146096
b EQUD &00023AB0
l .DecoDate
v LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STAX
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
& LDA NM1%,X:STA DOY%,X
0 LDA #0:STA NM2%,X
: DEX
D BPL DDL18
N LDA #5:STA NM2%
X JSR Mul32
b LDA #2:STA NM2%
l JSR Add32
v LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
* DEX
4 BPL DDL1C
> LDA #1:STA NM2%
H JSR Add32
R LDX #3
\ .DDL1D
f LDA NM1%,X:STA FDBS%+YR%,X
p DEX
z BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
$ LDA zNum%,X:STA NM2%,X
. LDA DOY%,X:STA NM1%,X
8 DEX
B BPL DDL21
L JSR Sub32
V LDX #3
` LDA #0
j .DDL22
t STA NM2%,X
~ DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
(
.Mul32L1
2 LDA NM1%,X:STA MLR%,X
< DEX
F BPL Mul32L1
P
LDX #&21
Z BNE START_R
d
.SHIFT_R
n BCC ROTATE_R
x LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
" ROR MLR%+4
, .START_R
6 ROR MLR%+3
@ ROR MLR%+2
J ROR MLR%+1
T
ROR MLR%
^ DEX
h BNE SHIFT_R
r LDX #3

.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
& INY
0 DEX
: BNE Sub32L1
D PLA:TAY
N
PLA:TAX
X PLP
b RTS
l .Add32
v TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
* TYA:PHA
4 LDX #3
> .CND
H LDA NM1%,X:STA zNum%,X
R LDA NM2%,X:STA zDen%,X
\ LDA #0:STA zRem%,X
f DEX
p
BPL CND
z LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
$ STA zTemp% + 1
. LDA zRem% + 2
8 SBC zDen% + 2
B STA zTemp% + 2
L LDA zRem% + 3
V SBC zDen% + 3
` STA zTemp% + 3
j
BCC Next
t INC zNum%
~ LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
( DEX
2 BPL STTI1
< LDA #100:STA NM1%
F JSR Mul32
P LDX #3
Z .STTI2
d$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
n DEX
x BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
" LDA FDBS% + HR%,Y
,
STA NM1%
6 JSR Conv2d
@ LDA #&3A
J CPY #2
T BEQ PrTiL2
^ JSR &FFEE
h .PrTiL2
r INY
 CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
&
STA NM2%
0 LDX #3
:
.PDL1
D LDA FDBS%+YR%,X
N STA NM1%,X
X DEX
b BPL PDL1
l JSR Div32
v$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
* LDA zNum%,X:STA NM1%,X
4 DEX
>
BPL DDL5
H JSR Mul32
R \ days  era * 146097 \
\ LDX #3
f .DDL6
p LDA MLR%,X:STA NM2%,X
z LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
$ BPL DDL8
. JSR Sub32
8 LDX #3
B .DDL9
L LDA NM1%,X:STA STORE%,X
V LDA DOE%,X:STA NM1%,X
` LDA c36524,X:STA NM2%,X
j DEX
t
BPL DDL9
~ JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
( LDX #3
2
.DDLC
< LDA STORE%,X:STA NM1%,X
F LDA zNum%,X:STA NM2%,X
P DEX
Z
BPL DDLC
d JSR Sub32
n LDX #3
x .DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
"
BPL DDLF
, JSR Mul32
6 \ yoe + era * 400 \
@ LDX #3
J .DDL10
T LDA MLR%,X:STA NM1%,X
^ LDA YOE%,X:STA NM2%,X
h DEX
r BPL DDL10
 JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
& LDX #1
0 .DDL14
: LSR NM2%+3
D ROR NM2%+2
N ROR NM2%+1
X ROR NM2%
b DEX
l BPL DDL14
v JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
* .DDL17
4 LDA NM1%,X:STA NM2%,X
> LDA DOE%,X:STA NM1%,X
H DEX
R BPL DDL17
\ JSR Sub32
f LDX #3
p .DDL18
z LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
$ SBC #9
. STA FDBS%+MN%
8 .DDL1A
B CMP #3
L BPL DDL1B
V LDX #3
` .DDL1C
j! LDA FDBS% + YR%,X:STA NM1%,X
t LDA #0:STA NM2%,X
~ DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
( LDA MP%: STA NM1%
2 JSR Mul32
< LDA #2:STA NM2%
F JSR Add32
P LDA #5:STA NM2%
Z JSR Div32
d LDX #3
n .DDL21
x LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
"
.c400
, EQUD &00000190
6 .Mul32
@ LDA #0
J STA MLR%+4
T STA MLR%+5
^ STA MLR%+6
h STA MLR%+7
r LDX #3

.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
& STA MLR%+6
0 LDA MLR%+7
: ADC NM2%+3
D STA MLR%+7
N .ROTATE_R
X
ROR A
b ROR MLR%+6
l ROR MLR%+5
v ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
* CLC
4
ADC #&30
> JSR &FFEE
H LDA zRem%
R CLC
\ ADC #&30
f JSR &FFEE
p RTS
z .ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
(2<FPZdnx",6@JT^hr&0:DNXblv
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
* LDX #4
4 LDY #0
> CLD
H SEC
R
.Sub32L1
\ LDA NM1%,Y
f SBC NM2%,Y
p STA NM1%,Y
z INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
$ STA NM1%,Y
. INY
8 DEX
B BNE Add32L1
L PLA:TAY
V PLA:TAX
` RTS
j .Div32
t TXA:PHA
~ TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
( ROL zRem% + 3
2 SEC
< .Subtract
F LDA zRem%
P SBC zDen%
Z STA zTemp%
d LDA zRem% + 1
n SBC zDen% + 1
x STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
" BNE Divide
, PLA:TAY
6 PLA:TAX
@ RTS
J .StoreToTIME
T LDX #3
^ .STTI1
h LDA #0:STA NM1%,X
r% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
 DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
& LDA #&93
0
LDX #&FF
: LDY #0
D JSR &FFF4
N LDY #0
X
LDA #10
b STA NM2%
l .PrTiL1
v LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
* JSR &FFEE
4 LDA FDBS%+MN%
>
STA NM1%
H JSR Conv2d
R LDA #&2D
\ JSR &FFEE
f# \ Year printing is different \
p
LDA #100
z
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
$ JSR Conv2d
. LDA STORE%
8
STA NM1%
B JSR Conv2d
L JSR &FFE7
V RTS
` .Conv2d
j JSR Div32
t LDA zNum%
~ CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
( ]
2 Pass%
< "SIZE : " +(P%PROG%)
FH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
P Y% = CMD 256
Z X% = CMD 256
d &FFF7
n $CMD
(2<FPZdnx",6@JT^hr&0:DNXblv *4>HR\fpz
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
\LDA #&93 \
\LDX #&FF \
\LDY #0 \
\JSR &FFF4 \
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA MLR%,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
\LDA #&93 \
\LDX #&FF \
\LDY #0 \
\JSR &FFF4 \
JSR SelPZ
PLA:TAY
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
$ LDY #0
. JSR &FFF4
8 PLA:TAY
B PLA:TAX
L RTS
V .SelPZ
` \ Select page 0
j \ Reg X,Y and A preserved
t TXA:PHA
~ TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
( JSR Div32
2 \ hours = seconds / 3600 \
< LDX #3
F
.DTL2
P LDA zNum%,X:STA DAYT%,X
Z LDA zRem%,X:STA NM1%,X
d" \ To be used to set value
n% LDA zRem%,X:STA &FD00+TIMEVAR%,X
x LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
" EQUD &00015180
,
.HrsS
6 EQUD &00000E10
@
.YrCr
J EQUD &000A968D
T .Yr400
^ EQUD &00023AB1
h .c1460
r EQUD &000005B4
 .c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
& DEX
0 BPL DDL3
: JSR Div32
D LDX #3
N .DDL5
X LDA zNum%,X:STA ERA%,X
b LDA zNum%,X:STA NM1%,X
l DEX
v
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
* LDX #3
4 .DDL8
> LDA zNum%,X:STA NM2%,X
H LDA DOE%,X:STA NM1%,X
R DEX
\ BPL DDL8
f JSR Sub32
p LDX #3
z .DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
$ LDA DOE%,X:STA NM1%,X
. LDA c146096,X:STA NM2%,X
8 DEX
B BPL DDLB
L JSR Div32
V* \ doedoe/1460+doe/36524doe/146096 \
` LDX #3
j
.DDLC
t LDA STORE%,X:STA NM1%,X
~ LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
( LDX #3
2
.DDLF
< LDA ERA%,X:STA NM1%,X
F LDA c400,X:STA NM2%,X
P DEX
Z
BPL DDLF
d JSR Mul32
n \ yoe + era * 400 \
x LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
" BPL DDL12
, JSR Mul32
6 LDX #3
@ .DDL13
J LDA YOE%,X:STA NM2%,X:DEX
T BPL DDL13
^ LDX #1
h .DDL14
r LSR NM2%+3
 ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STAUTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
JSR StoMLR
JSR Add32
\LDX #3 \
.UTCL3
\LDA NM1%,X:STA STORE%,X \
\DEX \
\BPL UTCL3 \
% JSR NMToSTR
* JMP UTCCEND
4
.UTCCNEG
> \ Select page 0
H TYA:PHA
R JSR SelPZ
\ PLA:TAY
f JSR StoZero
p
.UTCCEND
z JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.NMToSTR
\ Copies NM1% to STORE%
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.NMTSTR1
LDA NM1%,X:STA STORE%,X
DEX
BPL NMTSTR1
PLA
PLA:TAX
RTS
$ .StoMLR
. \ Copies STORE% to NM1%
8 \ Copies MLR% to NM2%
B \ Preserves A and Z
L TXA:PHA
V PHA
` LDX #3
j .STMLR1
t LDA STORE%,X:STA NM1%,X
~ LDA MLR%,X:STA NM2%,X
DEX
BPL STMLR1
PLA
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.STZE1
LDA HrsS,X : STA NM1%,X
LDA #0: STA NM2%,X
DEX
( BPL STZE1
2 PLA
< PLA:TAX
F RTS
P .SelPZ
Z \ Select page 0
d \ Reg X,Y and A preserved
n TXA:PHA
x TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
" JSR Div32
, \ hours = seconds / 3600 \
6 LDX #3
@
.DTL2
J LDA zNum%,X:STA DAYT%,X
T LDA zRem%,X:STA NM1%,X
^" \ To be used to set value
h% LDA zRem%,X:STA &FD00+TIMEVAR%,X
r LDA HrsS,X:STA NM2%,X
 DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LD NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
& LDA zNum%,X:STA NM2%,X
0 LDA STORE%,X:STA NM1%,X
: DEX
D BPL DDL16
N JSR Sub32
X LDX #3
b .DDL17
l LDA NM1%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
* BPL DDL19
4 ADC #3
> STA FDBS%+MN%
H JMP DDL1A
R .DDL19
\ SBC #9
f STA FDBS%+MN%
p .DDL1A
z CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
$ LDA #0
. .DDL20
8 STA NM1%,X:STA NM2%,X
B DEX
L BPL DDL20
V LDA #153:STA NM2%
` LDA MP%: STA NM1%
j JSR Mul32
t LDA #2:STA NM2%
~ JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
( JSR Add32
2 LDA NM1% :STA FDBS%+DAY%
< RTS
F
.year
P EQUD &0000016D
Z
.c400
d EQUD &00000190
n .Mul32
x LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
" STA MLR%+4
, LDA MLR%+5
6 ADC NM2%+1
@ STA MLR%+5
J LDA MLR%+6
T ADC NM2%+2
^ STA MLR%+6
h LDA MLR%+7
r ADC NM2%+3
 STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
& BPL Mul32L2
0 RTS
:
.Sub32
D PHP
N TXA:PHA
X TYA:PHA
b LDX #4
l LDY #0
v CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
* CLD
4 CLC
>
.Add32L1
H LDA NM1%,Y
R ADC NM2%,Y
\ STA NM1%,Y
f INY
p DEX
z BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
$ ROL zNum% + 1
. ROL zNum% + 2
8 ROL zNum% + 3
B ROL zRem%
L ROL zRem% + 1
V ROL zRem% + 2
` ROL zRem% + 3
j SEC
t .Subtract
~ LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
( STA zRem% , Y
2 DEY
< BPL CpTmpToRem
F .Next
P DEX
Z BNE Divide
d PLA:TAY
n PLA:TAX
x RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
" LDY #(FDBS%+TIMEVAR%) 256
, JSR &FFF1
6 RTS
@ .PrintTime
J JSR ClearNums
T \ Select page 0 \
^ LDA #&93
h
LDX #&FF
r LDY #0
 JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
& RTS
0 .PrintDate
: LDA FDBS%+DAY%
D STA NM1%
N JSR Conv2d
X
LDA #&2D
b JSR &FFEE
l LDA FDBS%+MN%
v
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ YeA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
&
.HrsS
0 EQUD &00000E10
:
.YrCr
D EQUD &000A968D
N .Yr400
X EQUD &00023AB1
b .c1460
l EQUD &000005B4
v .c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
* BPL DDL3
4 JSR Div32
> LDX #3
H .DDL5
R LDA zNum%,X:STA ERA%,X
\ LDA zNum%,X:STA NM1%,X
f DEX
p
BPL DDL5
z JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
$ LDX #3
. .DDL8
8 LDA zNum%,X:STA NM2%,X
B LDA DOE%,X:STA NM1%,X
L DEX
V BPL DDL8
` JSR Sub32
j LDX #3
t .DDL9
~ LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
( LDA c146096,X:STA NM2%,X
2 DEX
< BPL DDLB
F JSR Div32
P* \ doedoe/1460+doe/36524doe/146096 \
Z LDX #3
d
.DDLC
n LDA STORE%,X:STA NM1%,X
x LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
" LDX #3
,
.DDLF
6 LDA ERA%,X:STA NM1%,X
@ LDA c400,X:STA NM2%,X
J DEX
T
BPL DDLF
^ JSR Mul32
h \ yoe + era * 400 \
r LDX #3
 .DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
& JSR Mul32
0 LDX #3
: .DDL13
D LDA YOE%,X:STA NM2%,X:DEX
N BPL DDL13
X LDX #1
b .DDL14
l LSR NM2%+3
v ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
* LDA STORE%,X:STA NM1%,X
4 DEX
> BPL DDL16
H JSR Sub32
R LDX #3
\ .DDL17
f LDA NM1%,X:STA NM2%,X
p LDA DOE%,X:STA NM1%,X
z DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
$ BPL DDL19
. ADC #3
8 STA FDBS%+MN%
B JMP DDL1A
L .DDL19
V SBC #9
` STA FDBS%+MN%
j .DDL1A
t CMP #3
~ BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
( .DDL20
2 STA NM1%,X:STA NM2%,X
< DEX
F BPL DDL20
P LDA #153:STA NM2%
Z LDA MP%: STA NM1%
d JSR Mul32
n LDA #2:STA NM2%
x JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
" JSR Add32
, LDA NM1% :STA FDBS%+DAY%
6 RTS
@
.year
J EQUD &0000016D
T
.c400
^ EQUD &00000190
h .Mul32
r LDar printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
* LDA #10
4 STA NM2%
> LDA zNum%
H
STA NM1%
R \ Conv. upp. part of year \
\ JSR Conv2d
f LDA STORE%
p
STA NM1%
z JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
$ LDA #0
.
.CNL1
8 STA NM1%,X
B DEX
L
BPL CNL1
V RTS
` ]
j Pass%
t "SIZE : " +(P%PROG%)
~H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
7",6@JT^hr&0:DNXblv *4>HR\fpz$.8BLV`
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time A #0
 STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
& LDA MLR%+5
0 ADC NM2%+1
: STA MLR%+5
D LDA MLR%+6
N ADC NM2%+2
X STA MLR%+6
b LDA MLR%+7
l ADC NM2%+3
v STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
* RTS
4
.Sub32
> PHP
H TXA:PHA
R TYA:PHA
\ LDX #4
f LDY #0
p CLD
z SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
$ CLD
. CLC
8
.Add32L1
B LDA NM1%,Y
L ADC NM2%,Y
V STA NM1%,Y
` INY
j DEX
t BNE Add32L1
~ PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
( ROL zNum% + 2
2 ROL zNum% + 3
< ROL zRem%
F ROL zRem% + 1
P ROL zRem% + 2
Z ROL zRem% + 3
d SEC
n .Subtract
x LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
" STA zRem% , Y
, DEY
6 BPL CpTmpToRem
@ .Next
J DEX
T BNE Divide
^ PLA:TAY
h PLA:TAX
r RTS
 .StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
& JSR &FFF1
0 RTS
: .PrintTime
D JSR ClearNums
N \ Select page 0 \
X LDA #&93
b
LDX #&FF
l LDY #0
v JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
* .PrintDate
4 LDA FDBS%+DAY%
> STA NM1%
H JSR Conv2d
R
LDA #&2D
\ JSR &FFEE
f LDA FDBS%+MN%
p
STA NM1%
z JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
$ LDA #10
. STA NM2%
8 LDA zNum%
B
STA NM1%
L \ Conv. upp. part of year \
V JSR Conv2d
` LDA STORE%
j
STA NM1%
t JSR Conv2d
~ JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
(
.CNL1
2 STA NM1%,X
< DEX
F
BPL CNL1
P RTS
Z ]
d Pass%
n "SIZE : " +(P%PROG%)
xH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
7",6@JT^hr&0:
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.SelPZ
$ \ Select page 0
. \ Reg X,Y and A preserved
8 TXA:PHA
B TYA:PHA
L PHA
V
LDA #&93
`
LDX #&FF
j LDY #0
t JSR &FFF4
~ PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
(" \ To be used to set value
2% LDA zRem%,X:STA &FD00+TIMEVAR%,X
< LDA HrsS,X:STA NM2%,X
F DEX
P BPL DTL2
Z JSR Div32
d LDA zNum%:STA FDBS% + HR%
n LDX #3
x
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
" EQUD &00023AB1
, .c1460
6 EQUD &000005B4
@ .c36524
J EQUD &00008EAC
T
.c146096
^ EQUD &00023AB0
h .DecoDate
r LDX #3
 .DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
& LDA zNum%,X:STA NM1%,X
0 DEX
:
BPL DDL5
D JSR Mul32
N \ days  era * 146097 \
X LDX #3
b .DDL6
l LDA MLR%,X:STA NM2%,X
v LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
* JSR Sub32
4 LDX #3
> .DDL9
H LDA NM1%,X:STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c36524,X:STA NM2%,X
f DEX
p
BPL DDL9
z JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
$ LDX #3
.
.DDLC
8 LDA STORE%,X:STA NM1%,X
B LDA zNum%,X:STA NM2%,X
L DEX
V
BPL DDLC
` JSR Sub32
j LDX #3
t .DDLD
~ LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
( JSR Mul32
2 \ yoe + era * 400 \
< LDX #3
F .DDL10
P LDA MLR%,X:STA NM1%,X
Z LDA YOE%,X:STA NM2%,X
d DEX
n BPL DDL10
x JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
" LDX #1
, .DDL14
6 LSR NM2%+3
@ ROR NM2%+2
J ROR NM2%+1
T ROR NM2%
^ : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
JSR StoMLR
JSR Add32
JSR NMToSTR
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
* JSR SelPZ
4 PLA:TAY
> JSR StoZero
H DEY
R TYA
\ #&FF
f
STA NM2%
p JSR Mul32
z JSR StoMLR
JSR Sub32
JSR NMToSTR
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.NMToSTR
\ Copies NM1% to STORE%
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.NMTSTR1
LDA NM1%,X:STA STORE%,X
DEX
$ BPL NMTSTR1
. PLA
8 PLA:TAX
B RTS
L .StoMLR
V \ Copies STORE% to NM1%
` \ Copies MLR% to NM2%
j \ Preserves A and Z
t TXA:PHA
~ PHA
LDX #3
.STMLR1
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
BPL STMLR1
PLA
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
( .STZE1
2 LDA HrsS,X : STA NM1%,X
< LDA #0: STA NM2%,X
F DEX
P BPL STZE1
Z PLA
d PLA:TAX
n RTS
x .SelPZ
\ Select page 0
\ Reg X,Y and A preserved
TXA:PHA
TYA:PHA
P DEX
h BPL DDL14
r JSR Add32
 LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
& .DDL17
0 LDA NM1%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL17
X JSR Sub32
b LDX #3
l .DDL18
v LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
* STA FDBS%+MN%
4 .DDL1A
> CMP #3
H BPL DDL1B
R LDX #3
\ .DDL1C
f! LDA FDBS% + YR%,X:STA NM1%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
$ LDA MP%: STA NM1%
. JSR Mul32
8 LDA #2:STA NM2%
B JSR Add32
L LDA #5:STA NM2%
V JSR Div32
` LDX #3
j .DDL21
t LDA zNum%,X:STA NM2%,X
~ LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
( EQUD &00000190
2 .Mul32
< LDA #0
F STA MLR%+4
P STA MLR%+5
Z STA MLR%+6
d STA MLR%+7
n LDX #3
x
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
" STA MLR%+6
, LDA MLR%+7
6 ADC NM2%+3
@ STA MLR%+7
J .ROTATE_R
T
ROR A
^ ROR MLR%+6
h ROR MLR%+5
r ROR MLR%+4
 .START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
& LDX #4
0 LDY #0
: CLD
D SEC
N
.Sub32L1
X LDA NM1%,Y
b SBC NM2%,Y
l STA NM1%,Y
v INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
* INY
4 DEX
> BNE Add32L1
H PLA:TAY
R PLA:TAX
\ RTS
f .Div32
p TXA:PHA
z TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
$ ROL zRem% + 3
. SEC
8 .Subtract
B LDA zRem%
L SBC zDen%
V STA zTemp%
` LDA zRem% + 1
j SBC zDen% + 1
t STA zTemp% + 1
~ LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
( PLA:TAY
2 PLA:TAX
< RTS
F .StoreToTIME
P LDX #3
Z .STTI1
d LDA #0:STA NM1%,X
n% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
x DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
" LDA #&93
,
LDX #&FF
6 LDY #0
@ JSR &FFF4
J LDY #0
T
LDA #10
^ STA NM2%
h .PrTiL1
r LDA FDBS% + HR%,Y

STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%HA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
" LDA STORE%,X:STA NM1%,X
, LDA DayS,X:STA NM2%,X
6 DEX
@
BPL DTL1
J JSR Div32
T \ hours = seconds / 3600 \
^ LDX #3
h
.DTL2
r LDA zNum%,X:STA DAYT%,X
 LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
&# LDA zRem% : STA FDBS% + SEC%
0 RTS
:
.DayS
D EQUD &00015180
N
.HrsS
X EQUD &00000E10
b
.YrCr
l EQUD &000A968D
v .Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
* .DDL3
4 LDA NM1%,X:STA DYS%,X
> LDA Yr400,X:STA NM2%,X
H DEX
R BPL DDL3
\ JSR Div32
f LDX #3
p .DDL5
z LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
$ DEX
.
BPL DDL7
8 JSR Div32
B \ doe  doe / 1460 \
L LDX #3
V .DDL8
` LDA zNum%,X:STA NM2%,X
j LDA DOE%,X:STA NM1%,X
t DEX
~ BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
( LDX #3
2
.DDLB
< LDA NM1%,X: STA STORE%,X
F LDA DOE%,X:STA NM1%,X
P LDA c146096,X:STA NM2%,X
Z DEX
d BPL DDLB
n JSR Div32
x* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
" LDA zNum%,X:STA YOE%,X
, DEX
6
BPL DDLE
@ \ era * 400 \
J LDX #3
T
.DDLF
^ LDA ERA%,X:STA NM1%,X
h LDA c400,X:STA NM2%,X
r DEX

BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
& LDA year,X:STA NM1%,X
0 LDA YOE%,X:STA NM2%,X
: DEX
D BPL DDL12
N JSR Mul32
X LDX #3
b .DDL13
l LDA YOE%,X:STA NM2%,X:DEX
v BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
* JSR Div32
4 LDX #3
>
.DDL16
H LDA zNum%,X:STA NM2%,X
R LDA STORE%,X:STA NM1%,X
\ DEX
f BPL DDL16
p JSR Sub32
z LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
$ LDA #153:STA NM2%
. JSR Div32
8 LDA zNum%:STA MP%
B CMP #10
L BPL DDL19
V ADC #3
` STA FDBS%+MN%
j JMP DDL1A
t .DDL19
~ SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
( BPL DDL1D
2 .DDL1B
< LDX #3
F LD
JSR Conv2d
LDA #&2D
& JSR &FFEE
0 LDA FDBS%+MN%
:
STA NM1%
D JSR Conv2d
N LDA #&2D
X JSR &FFEE
b# \ Year printing is different \
l
LDA #100
v
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
* LDA STORE%
4
STA NM1%
> JSR Conv2d
H JSR &FFE7
R RTS
\ .Conv2d
f JSR Div32
p LDA zNum%
z CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
$ ]
. Pass%
8 "SIZE : " +(P%PROG%)
BH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
L Y% = CMD 256
V X% = CMD 256
` &FFF7
j $CMD
(2<FPZdnx
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time A #0
P .DDL20
Z STA NM1%,X:STA NM2%,X
d DEX
n BPL DDL20
x LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
" STA NM2%,X
, DEX
6 BPL DDL22
@ LDA #1:STA NM2%
J JSR Add32
T LDA NM1% :STA FDBS%+DAY%
^ RTS
h
.year
r EQUD &0000016D

.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
& LDA MLR%+4
0 CLC
: ADC NM2%
D STA MLR%+4
N LDA MLR%+5
X ADC NM2%+1
b STA MLR%+5
l LDA MLR%+6
v ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
*
.Mul32L2
4 LDA MLR%,X:STA NM1%,X
> DEX
H BPL Mul32L2
R RTS
\
.Sub32
f PHP
p TXA:PHA
z TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
$ TXA:PHA
. TYA:PHA
8 LDY #0
B LDX #4
L CLD
V CLC
`
.Add32L1
j LDA NM1%,Y
t ADC NM2%,Y
~ STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
( LDX #32
2
.Divide
< ASL zNum%
F ROL zNum% + 1
P ROL zNum% + 2
Z ROL zNum% + 3
d ROL zRem%
n ROL zRem% + 1
x ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
" INC zNum%
, LDY #3
6 .CpTmpToRem
@ LDA zTemp%, Y
J STA zRem% , Y
T DEY
^ BPL CpTmpToRem
h .Next
r DEX
 BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
& BPL STTI2
0 LDA #&2
: LDX #(FDBS%+TIMEVAR%) 256
D LDY #(FDBS%+TIMEVAR%) 256
N JSR &FFF1
X RTS
b .PrintTime
l JSR ClearNums
v \ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
* CPY #3
4 BNE PrTiL1
> JSR &FFE7
H RTS
R .PrintDate
\ LDA FDBS%+DAY%
f STA NM1%
p JSR Conv2d
z
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$$ \ STORE LOWER PART OF YEAR \
. LDA zRem%
8 STA STORE%
B JSR ClearNums
L LDA #10
V STA NM2%
` LDA zNum%
j
STA NM1%
t \ Conv. upp. part of year \
~ JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
( .ClearNums
2$ \ NM1 and NM2 are in one line \
< LDX #7
F LDA #0
P
.CNL1
Z STA NM1%,X
d DEX
n
BPL CNL1
x RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
(2<FPZdnx",6@JT^data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
\LDA #&93\
\LDX #&FF\
\LDY #0\
\JSR &FFF4 \
PLA:TAY
PLA:TAX
RTS
.SelPZ
$ \ Select page 0
. \ Reg X,Y and A preserved
8 TXA:PHA
B TYA:PHA
L PHA
V
LDA #&93
`
LDX #&FF
j LDY #0
t JSR &FFF4
~ PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
(" \ To be used to set value
2% LDA zRem%,X:STA &FD00+TIMEVAR%,X
< LDA HrsS,X:STA NM2%,X
F DEX
P BPL DTL2
Z JSR Div32
d LDA zNum%:STA FDBS% + HR%
n LDX #3
x
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
" EQUD &00023AB1
, .c1460
6 EQUD &000005B4
@ .c36524
J EQUD &00008EAC
T
.c146096
^ EQUD &00023AB0
h .DecoDate
r LDX #3
 .DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
& LDA zNum%,X:STA NM1%,X
0 DEX
:
BPL DDL5
D JSR Mul32
N \ days  era * 146097 \
X LDX #3
b .DDL6
l LDA MLR%,X:STA NM2%,X
v LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
* JSR Sub32
4 LDX #3
> .DDL9
H LDA NM1%,X:STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c36524,X:STA NM2%,X
f DEX
p
BPL DDL9
z JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
$ LDX #3
.
.DDLC
8 LDA STORE%,X:STA NM1%,X
B LDA zNum%,X:STA NM2%,X
L DEX
V
BPL DDLC
` JSR Sub32
j LDX #3
t .DDLD
~ LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
( JSR Mul32
2 \ yoe + era * 400 \
< LDX #3
F .DDL10
P LDA MLR%,X:STA NM1%,X
Z LDA YOE%,X:STA NM2%,X
d DEX
n BPL DDL10
x JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
" LDX #1
, .DDL14
6 LSR NM2%+3
@ ROR NM2%+2
J ROR NM2%+1
T ROR NM2%
^ DEX
h BPL
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 \JSR UTCCorr\
JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Prepare multi
: LDX #3
D .UTCCL1
N LDA HrsS,X:STA NM1%,X
X LDA #0:STA NM2%,X
b DEX
l BPL UTCCL1
v \ Get UTC flag
LDA #&93
LDX #&FF
LDY #1
JSR &FFF4
LDA #&94
LDX #0
JSR &FFF4
CPY #0 \ UTC = 0 ?
BEQ UTCCEND \ =0 NO ACTION
BMI UTCCNEG
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
* BPL UTCL2
4 JSR Sub32
> LDX #3
H .UTCL3
R LDA NM1%,X:STA STORE%,X
\ DEX
f BPL UTCL3
p JMP UTCCEND
z
.UTCCNEG
SEC
LDA #0
SBC &FD00
STA NM2%
JSR Mul32
JMP UTCCEND
.UTCCEND
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
$
BPL DTL1
. JSR Div32
8 \ hours = seconds / 3600 \
B LDX #3
L
.DTL2
V LDA DDL14
r JSR Add32
 LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
& .DDL17
0 LDA NM1%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL17
X JSR Sub32
b LDX #3
l .DDL18
v LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
* STA FDBS%+MN%
4 .DDL1A
> CMP #3
H BPL DDL1B
R LDX #3
\ .DDL1C
f! LDA FDBS% + YR%,X:STA NM1%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
$ LDA MP%: STA NM1%
. JSR Mul32
8 LDA #2:STA NM2%
B JSR Add32
L LDA #5:STA NM2%
V JSR Div32
` LDX #3
j .DDL21
t LDA zNum%,X:STA NM2%,X
~ LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
( EQUD &00000190
2 .Mul32
< LDA #0
F STA MLR%+4
P STA MLR%+5
Z STA MLR%+6
d STA MLR%+7
n LDX #3
x
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
" STA MLR%+6
, LDA MLR%+7
6 ADC NM2%+3
@ STA MLR%+7
J .ROTATE_R
T
ROR A
^ ROR MLR%+6
h ROR MLR%+5
r ROR MLR%+4
 .START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
& LDX #4
0 LDY #0
: CLD
D SEC
N
.Sub32L1
X LDA NM1%,Y
b SBC NM2%,Y
l STA NM1%,Y
v INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
* INY
4 DEX
> BNE Add32L1
H PLA:TAY
R PLA:TAX
\ RTS
f .Div32
p TXA:PHA
z TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
$ ROL zRem% + 3
. SEC
8 .Subtract
B LDA zRem%
L SBC zDen%
V STA zTemp%
` LDA zRem% + 1
j SBC zDen% + 1
t STA zTemp% + 1
~ LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
( PLA:TAY
2 PLA:TAX
< RTS
F .StoreToTIME
P LDX #3
Z .STTI1
d LDA #0:STA NM1%,X
n% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
x DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
" LDA #&93
,
LDX #&FF
6 LDY #0
@ JSR &FFF4
J LDY #0
T
LDA #10
^ STA NM2%
h .PrTiL1
r LDA FDBS% + HR%,Y

STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR C zNum%,X:STA DAYT%,X
` LDA zRem%,X:STA NM1%,X
j" \ To be used to set value
t% LDA zRem%,X:STA &FD00+TIMEVAR%,X
~ LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
( EQUD &00015180
2
.HrsS
< EQUD &00000E10
F
.YrCr
P EQUD &000A968D
Z .Yr400
d EQUD &00023AB1
n .c1460
x EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
" LDA Yr400,X:STA NM2%,X
, DEX
6 BPL DDL3
@ JSR Div32
J LDX #3
T .DDL5
^ LDA zNum%,X:STA ERA%,X
h LDA zNum%,X:STA NM1%,X
r DEX

BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
& \ doe  doe / 1460 \
0 LDX #3
: .DDL8
D LDA zNum%,X:STA NM2%,X
N LDA DOE%,X:STA NM1%,X
X DEX
b BPL DDL8
l JSR Sub32
v LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
* LDA DOE%,X:STA NM1%,X
4 LDA c146096,X:STA NM2%,X
> DEX
H BPL DDLB
R JSR Div32
\* \ doedoe/1460+doe/36524doe/146096 \
f LDX #3
p
.DDLC
z LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
$ \ era * 400 \
. LDX #3
8
.DDLF
B LDA ERA%,X:STA NM1%,X
L LDA c400,X:STA NM2%,X
V DEX
`
BPL DDLF
j JSR Mul32
t \ yoe + era * 400 \
~ LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
( BPL DDL12
2 JSR Mul32
< LDX #3
F .DDL13
P LDA YOE%,X:STA NM2%,X:DEX
Z BPL DDL13
d LDX #1
n .DDL14
x LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
"
.DDL16
, LDA zNum%,X:STA NM2%,X
6 LDA STORE%,X:STA NM1%,X
@ DEX
J BPL DDL16
T JSR Sub32
^ LDX #3
h .DDL17
r LDA NM1%,X:STA NM2%,X
 LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
& CMP #10
0 BPL DDL19
: ADC #3
D STA FDBS%+MN%
N JMP DDL1A
X .DDL19
b SBC #9
l STA FDBS%+MN%
v .DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
* LDA #0
4 .DDL20
> STA NM1%,X:STA NM2%,X
H DEX
R BPL DDL20
\ LDA #153:STA NM2%
f LDA MP%: STA NM1%
p JSR Mul32
z LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
onv2d
LDA #&2D
& JSR &FFEE
0 LDA FDBS%+MN%
:
STA NM1%
D JSR Conv2d
N LDA #&2D
X JSR &FFEE
b# \ Year printing is different \
l
LDA #100
v
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
* LDA STORE%
4
STA NM1%
> JSR Conv2d
H JSR &FFE7
R RTS
\ .Conv2d
f JSR Div32
p LDA zNum%
z CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
$ ]
. Pass%
8 "SIZE : " +(P%PROG%)
BH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
L Y% = CMD 256
V X% = CMD 256
` &FFF7
j $CMD
7j $CMD
UMDSAVE NTP 4E00 54BA 4E69
DBS%
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
$ LDA #1:STA NM2%
. JSR Add32
8 LDA NM1% :STA FDBS%+DAY%
B RTS
L
.year
V EQUD &0000016D
`
.c400
j EQUD &00000190
t .Mul32
~ LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
( STA MLR%+4
2 LDA MLR%+5
< ADC NM2%+1
F STA MLR%+5
P LDA MLR%+6
Z ADC NM2%+2
d STA MLR%+6
n LDA MLR%+7
x ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
" DEX
, BPL Mul32L2
6 RTS
@
.Sub32
J PHP
T TXA:PHA
^ TYA:PHA
h LDX #4
r LDY #0
 CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
& LDX #4
0 CLD
: CLC
D
.Add32L1
N LDA NM1%,Y
X ADC NM2%,Y
b STA NM1%,Y
l INY
v DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
* ROL zNum% + 1
4 ROL zNum% + 2
> ROL zNum% + 3
H ROL zRem%
R ROL zRem% + 1
\ ROL zRem% + 2
f ROL zRem% + 3
p SEC
z .Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
$ LDA zTemp%, Y
. STA zRem% , Y
8 DEY
B BPL CpTmpToRem
L .Next
V DEX
` BNE Divide
j PLA:TAY
t PLA:TAX
~ RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
( LDY #(FDBS%+TIMEVAR%) 256
2 JSR &FFF1
< RTS
F .PrintTime
P JSR ClearNums
Z \ Select page 0 \
d LDA #&93
n
LDX #&FF
x LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
" JSR &FFE7
, RTS
6 .PrintDate
@ LDA FDBS%+DAY%
J STA NM1%
T JSR Conv2d
^
LDA #&2D
h JSR &FFEE
r LDA FDBS%+MN%

STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
& JSR ClearNums
0 LDA #10
: STA NM2%
D LDA zNum%
N
STA NM1%
X \ Conv. upp. part of year \
b JSR Conv2d
l LDA STORE%
v
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
* LDA #0
4
.CNL1
> STA NM1%,X
H DEX
R
BPL CNL1
\ RTS
f ]
p Pass%
z "SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
&FSAVE NTP 4CC8 5363 4D31
DBS%EVR%KIN%LEC%LAY%8LN%$LR
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FDdata \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
\LDA #&93\
\LDX #&FF\
\LDY #0\
\JSR &FFF4 \
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.SelPZ
$ \ Select page 0
. \ Reg X,Y and A preserved
8 TXA:PHA
B TYA:PHA
L PHA
V
LDA #&93
`
LDX #&FF
j LDY #0
t JSR &FFF4
~ PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
(" \ To be used to set value
2% LDA zRem%,X:STA &FD00+TIMEVAR%,X
< LDA HrsS,X:STA NM2%,X
F DEX
P BPL DTL2
Z JSR Div32
d LDA zNum%:STA FDBS% + HR%
n LDX #3
x
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
" EQUD &00023AB1
, .c1460
6 EQUD &000005B4
@ .c36524
J EQUD &00008EAC
T
.c146096
^ EQUD &00023AB0
h .DecoDate
r LDX #3
 .DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
& LDA zNum%,X:STA NM1%,X
0 DEX
:
BPL DDL5
D JSR Mul32
N \ days  era * 146097 \
X LDX #3
b .DDL6
l LDA MLR%,X:STA NM2%,X
v LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
* JSR Sub32
4 LDX #3
> .DDL9
H LDA NM1%,X:STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c36524,X:STA NM2%,X
f DEX
p
BPL DDL9
z JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
$ LDX #3
.
.DDLC
8 LDA STORE%,X:STA NM1%,X
B LDA zNum%,X:STA NM2%,X
L DEX
V
BPL DDLC
` JSR Sub32
j LDX #3
t .DDLD
~ LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
( JSR Mul32
2 \ yoe + era * 400 \
< LDX #3
F .DDL10
P LDA MLR%,X:STA NM1%,X
Z LDA YOE%,X:STA NM2%,X
d DEX
n BPL DDL10
x JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
" LDX #1
, .DDL14
6 LSR NM2%+3
@ ROR NM2%+2
J ROR NM2%+1
T ROR NM2%
91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
+ JMP UTCCEND
0 \ Prepare multi
: LDX #3
D .UTCCL1
N LDA HrsS,X:STA NM1%,X
X LDA #0:STA NM2%,X
b DEX
l BPL UTCCL1
v \ Get UTC flag
LDA #&93
LDX #&FF
LDY #1
JSR &FFF4
LDA #&94
LDX #0
JSR &FFF4
CPY #0 \ UTC = 0 ?
BEQ UTCCEND \ =0 NO ACTION
BMI UTCCNEG
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
* BPL UTCL2
4 JSR Sub32
> LDX #3
H .UTCL3
R LDA NM1%,X:STA STORE%,X
\ DEX
f BPL UTCL3
p JMP UTCCEND
z
.UTCCNEG
SEC
LDA #0
SBC &FD00
STA NM2%
JSR Mul32
JMP UTCCEND
.UTCCEND
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
$
BPL DTL1
. JSR Div32
8 \ hours = seconds / 3600 \
B LDX #3
L
.DTL2
V LDA zNum%,X:STA DAYT%,X
` LDA zRem%,X:STA NM1%,X
j" \ To be used to set value
t% LDA zRem%,X:STA &FD00+TIMEVAR%,X
~ LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
^ DEX
h BPL DDL14
r JSR Add32
 LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
& .DDL17
0 LDA NM1%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL17
X JSR Sub32
b LDX #3
l .DDL18
v LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
* STA FDBS%+MN%
4 .DDL1A
> CMP #3
H BPL DDL1B
R LDX #3
\ .DDL1C
f! LDA FDBS% + YR%,X:STA NM1%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
$ LDA MP%: STA NM1%
. JSR Mul32
8 LDA #2:STA NM2%
B JSR Add32
L LDA #5:STA NM2%
V JSR Div32
` LDX #3
j .DDL21
t LDA zNum%,X:STA NM2%,X
~ LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
( EQUD &00000190
2 .Mul32
< LDA #0
F STA MLR%+4
P STA MLR%+5
Z STA MLR%+6
d STA MLR%+7
n LDX #3
x
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
" STA MLR%+6
, LDA MLR%+7
6 ADC NM2%+3
@ STA MLR%+7
J .ROTATE_R
T
ROR A
^ ROR MLR%+6
h ROR MLR%+5
r ROR MLR%+4
 .START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
& LDX #4
0 LDY #0
: CLD
D SEC
N
.Sub32L1
X LDA NM1%,Y
b SBC NM2%,Y
l STA NM1%,Y
v INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
* INY
4 DEX
> BNE Add32L1
H PLA:TAY
R PLA:TAX
\ RTS
f .Div32
p TXA:PHA
z TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
$ ROL zRem% + 3
. SEC
8 .Subtract
B LDA zRem%
L SBC zDen%
V STA zTemp%
` LDA zRem% + 1
j SBC zDen% + 1
t STA zTemp% + 1
~ LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
( PLA:TAY
2 PLA:TAX
< RTS
F .StoreToTIME
P LDX #3
Z .STTI1
d LDA #0:STA NM1%,X
n% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
x DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
" LDA #&93
,
LDX #&FF
6 LDY #0
@ JSR &FFF4
J LDY #0
T
LDA #10
^ STA NM2%
h .PrTiL1
r LDA FDBS% + HR%,Y

STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NLDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
( EQUD &00015180
2
.HrsS
< EQUD &00000E10
F
.YrCr
P EQUD &000A968D
Z .Yr400
d EQUD &00023AB1
n .c1460
x EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
" LDA Yr400,X:STA NM2%,X
, DEX
6 BPL DDL3
@ JSR Div32
J LDX #3
T .DDL5
^ LDA zNum%,X:STA ERA%,X
h LDA zNum%,X:STA NM1%,X
r DEX

BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
& \ doe  doe / 1460 \
0 LDX #3
: .DDL8
D LDA zNum%,X:STA NM2%,X
N LDA DOE%,X:STA NM1%,X
X DEX
b BPL DDL8
l JSR Sub32
v LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
* LDA DOE%,X:STA NM1%,X
4 LDA c146096,X:STA NM2%,X
> DEX
H BPL DDLB
R JSR Div32
\* \ doedoe/1460+doe/36524doe/146096 \
f LDX #3
p
.DDLC
z LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
$ \ era * 400 \
. LDX #3
8
.DDLF
B LDA ERA%,X:STA NM1%,X
L LDA c400,X:STA NM2%,X
V DEX
`
BPL DDLF
j JSR Mul32
t \ yoe + era * 400 \
~ LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
( BPL DDL12
2 JSR Mul32
< LDX #3
F .DDL13
P LDA YOE%,X:STA NM2%,X:DEX
Z BPL DDL13
d LDX #1
n .DDL14
x LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
"
.DDL16
, LDA zNum%,X:STA NM2%,X
6 LDA STORE%,X:STA NM1%,X
@ DEX
J BPL DDL16
T JSR Sub32
^ LDX #3
h .DDL17
r LDA NM1%,X:STA NM2%,X
 LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
& CMP #10
0 BPL DDL19
: ADC #3
D STA FDBS%+MN%
N JMP DDL1A
X .DDL19
b SBC #9
l STA FDBS%+MN%
v .DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
* LDA #0
4 .DDL20
> STA NM1%,X:STA NM2%,X
H DEX
R BPL DDL20
\ LDA #153:STA NM2%
f LDA MP%: STA NM1%
p JSR Mul32
z LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
$ LDA #1:STA NM2%
. JSR Add32
8 LDA NM1% :STA FDBS%+DAY%
B RTS
L
.year
V EQUD &0000016D
`
.c400
j EQUD &00000190
t .Mul32
~ M1%
JSR Conv2d
LDA #&2D
& JSR &FFEE
0 LDA FDBS%+MN%
:
STA NM1%
D JSR Conv2d
N LDA #&2D
X JSR &FFEE
b# \ Year printing is different \
l
LDA #100
v
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
* LDA STORE%
4
STA NM1%
> JSR Conv2d
H JSR &FFE7
R RTS
\ .Conv2d
f JSR Div32
p LDA zNum%
z CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
$ ]
. Pass%
8 "SIZE : " +(P%PROG%)
BH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
L Y% = CMD 256
V X% = CMD 256
` &FFF7
j $CMD
TP 4DF4 54A5 4E5D
0 54BA 4DBS%WR%
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
( STA MLR%+4
2 LDA MLR%+5
< ADC NM2%+1
F STA MLR%+5
P LDA MLR%+6
Z ADC NM2%+2
d STA MLR%+6
n LDA MLR%+7
x ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
" DEX
, BPL Mul32L2
6 RTS
@
.Sub32
J PHP
T TXA:PHA
^ TYA:PHA
h LDX #4
r LDY #0
 CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
& LDX #4
0 CLD
: CLC
D
.Add32L1
N LDA NM1%,Y
X ADC NM2%,Y
b STA NM1%,Y
l INY
v DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
* ROL zNum% + 1
4 ROL zNum% + 2
> ROL zNum% + 3
H ROL zRem%
R ROL zRem% + 1
\ ROL zRem% + 2
f ROL zRem% + 3
p SEC
z .Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
$ LDA zTemp%, Y
. STA zRem% , Y
8 DEY
B BPL CpTmpToRem
L .Next
V DEX
` BNE Divide
j PLA:TAY
t PLA:TAX
~ RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
( LDY #(FDBS%+TIMEVAR%) 256
2 JSR &FFF1
< RTS
F .PrintTime
P JSR ClearNums
Z \ Select page 0 \
d LDA #&93
n
LDX #&FF
x LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
" JSR &FFE7
, RTS
6 .PrintDate
@ LDA FDBS%+DAY%
J STA NM1%
T JSR Conv2d
^
LDA #&2D
h JSR &FFEE
r LDA FDBS%+MN%

STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
& JSR ClearNums
0 LDA #10
: STA NM2%
D LDA zNum%
N
STA NM1%
X \ Conv. upp. part of year \
b JSR Conv2d
l LDA STORE%
v
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
* LDA #0
4
.CNL1
> STA NM1%,X
H DEX
R
BPL CNL1
\ RTS
f ]
p Pass%
z "SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
dnx",6@JT^hr
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
TXA:PHA
$ TYA:PHA
. PHA
8
LDA #&93
B
LDX #&FF
L LDY #0
V JSR &FFF4
` PLA
j
PLA:TAY
t PLA:TAX
~ RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
( DEX
2 BPL DTL2
< JSR Div32
F LDA zNum%:STA FDBS% + HR%
P LDX #3
Z
.DTL3
d LDA zRem%,X:STA NM1%,X
n LDA #0:STA NM2%,X
x DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
" .c36524
, EQUD &00008EAC
6
.c146096
@ EQUD &00023AB0
J .DecoDate
T LDX #3
^ .DDL1
h LDA DAYT%,X:STA NM1%,X
r LDA YrCr,X:STA NM2%,X
 DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
& JSR Mul32
0 \ days  era * 146097 \
: LDX #3
D .DDL6
N LDA MLR%,X:STA NM2%,X
X LDA DYS%,X:STA NM1%,X
b DEX
l BPL DDL6
v JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
* LDA NM1%,X:STA STORE%,X
4 LDA DOE%,X:STA NM1%,X
> LDA c36524,X:STA NM2%,X
H DEX
R
BPL DDL9
\ JSR Div32
f LDX #3
p .DDLA
z LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
$ LDA zNum%,X:STA NM2%,X
. DEX
8
BPL DDLC
B JSR Sub32
L LDX #3
V .DDLD
` LDA year,X:STA NM2%,X
j DEX
t BPL DDLD
~ JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
( .DDL10
2 LDA MLR%,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL10
Z JSR Add32
d LDX #3
n .DDL11
x! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
" ROR NM2%+2
, ROR NM2%+1
6 ROR NM2%
@ DEX
J BPL DDL14
T JSR Add32
^ LDX #3
h .DDL15
r LDA NM1%,X:STA STORE%,X
: 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
JMP UTCCEND
CPY #0 \ UTC = 0 ?
BEQ UTCCEND \ =0 NO ACTION
BMI UTCCNEG
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
BPL UTCL2
JSR Sub32
LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
* BPL UTCL3
4 JMP UTCCEND
>
.UTCCNEG
H SEC
R LDA #0
\ SBC &FD00
f
STA NM2%
p JSR Mul32
z JMP UTCCEND
.UTCCEND
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
$ LDA zRem%,X:STA NM1%,X
." \ To be used to set value
8% LDA zRem%,X:STA &FD00+TIMEVAR%,X
B LDA HrsS,X:STA NM2%,X
L DEX
V BPL DTL2
` JSR Div32
j LDA zNum%:STA FDBS% + HR%
t LDX #3
~
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
( EQUD &00023AB1
2 .c1460
< EQUD &000005B4
F .c36524
P EQUD &00008EAC
Z
.c146096 LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
& DEX
0 BPL DDL17
: JSR Sub32
D LDX #3
N .DDL18
X LDA NM1%,X:STA DOY%,X
b LDA #0:STA NM2%,X
l DEX
v BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
* BPL DDL1B
4 LDX #3
> .DDL1C
H! LDA FDBS% + YR%,X:STA NM1%,X
R LDA #0:STA NM2%,X
\ DEX
f BPL DDL1C
p LDA #1:STA NM2%
z JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
$ JSR Add32
. LDA #5:STA NM2%
8 JSR Div32
B LDX #3
L .DDL21
V LDA zNum%,X:STA NM2%,X
` LDA DOY%,X:STA NM1%,X
j DEX
t BPL DDL21
~ JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
( STA MLR%+4
2 STA MLR%+5
< STA MLR%+6
F STA MLR%+7
P LDX #3
Z
.Mul32L1
d LDA NM1%,X:STA MLR%,X
n DEX
x BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
" STA MLR%+7
, .ROTATE_R
6
ROR A
@ ROR MLR%+6
J ROR MLR%+5
T ROR MLR%+4
^ .START_R
h ROR MLR%+3
r ROR MLR%+2
 ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
& SEC
0
.Sub32L1
: LDA NM1%,Y
D SBC NM2%,Y
N STA NM1%,Y
X INY
b DEX
l BNE Sub32L1
v PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
* PLA:TAY
4 PLA:TAX
> RTS
H .Div32
R TXA:PHA
\ TYA:PHA
f LDX #3
p .CND
z LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
$ LDA zRem%
. SBC zDen%
8 STA zTemp%
B LDA zRem% + 1
L SBC zDen% + 1
V STA zTemp% + 1
` LDA zRem% + 2
j SBC zDen% + 2
t STA zTemp% + 2
~ LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
( .StoreToTIME
2 LDX #3
< .STTI1
F LDA #0:STA NM1%,X
P% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
Z DEX
d BPL STTI1
n LDA #100:STA NM1%
x JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
" JSR &FFF4
, LDY #0
6
LDA #10
@ STA NM2%
J .PrTiL1
T LDA FDBS% + HR%,Y
^
STA NM1%
h JSR Conv2d
r LDA #&3A
 CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
& JSR Conv
d EQUD &00023AB0
n .DecoDate
x LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
" LDA zNum%,X:STA ERA%,X
, LDA zNum%,X:STA NM1%,X
6 DEX
@
BPL DDL5
J JSR Mul32
T \ days  era * 146097 \
^ LDX #3
h .DDL6
r LDA MLR%,X:STA NM2%,X
 LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
& BPL DDL8
0 JSR Sub32
: LDX #3
D .DDL9
N LDA NM1%,X:STA STORE%,X
X LDA DOE%,X:STA NM1%,X
b LDA c36524,X:STA NM2%,X
l DEX
v
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
* LDX #3
4
.DDLC
> LDA STORE%,X:STA NM1%,X
H LDA zNum%,X:STA NM2%,X
R DEX
\
BPL DDLC
f JSR Sub32
p LDX #3
z .DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
$
BPL DDLF
. JSR Mul32
8 \ yoe + era * 400 \
B LDX #3
L .DDL10
V LDA MLR%,X:STA NM1%,X
` LDA YOE%,X:STA NM2%,X
j DEX
t BPL DDL10
~ JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
( LDX #1
2 .DDL14
< LSR NM2%+3
F ROR NM2%+2
P ROR NM2%+1
Z ROR NM2%
d DEX
n BPL DDL14
x JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
" LDX #3
, .DDL17
6 LDA NM1%,X:STA NM2%,X
@ LDA DOE%,X:STA NM1%,X
J DEX
T BPL DDL17
^ JSR Sub32
h LDX #3
r .DDL18
 LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
& SBC #9
0 STA FDBS%+MN%
: .DDL1A
D CMP #3
N BPL DDL1B
X LDX #3
b .DDL1C
l! LDA FDBS% + YR%,X:STA NM1%,X
v LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
* LDA MP%: STA NM1%
4 JSR Mul32
> LDA #2:STA NM2%
H JSR Add32
R LDA #5:STA NM2%
\ JSR Div32
f LDX #3
p .DDL21
z LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
$
.c400
. EQUD &00000190
8 .Mul32
B LDA #0
L STA MLR%+4
V STA MLR%+5
` STA MLR%+6
j STA MLR%+7
t LDX #3
~
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
( STA MLR%+6
2 LDA MLR%+7
<2d
0 LDA #&2D
: JSR &FFEE
D# \ Year printing is different \
N
LDA #100
X
STA NM2%
b LDX #3
l
.PDL1
v LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
* JSR &FFE7
4 RTS
> .Conv2d
H JSR Div32
R LDA zNum%
\ CLC
f
ADC #&30
p JSR &FFEE
z LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
$H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
. Y% = CMD 256
8 X% = CMD 256
B &FFF7
L $CMD
(2<FPZdnx",6@JT^hr&0:DNXblv
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time ADC NM2%+3
F STA MLR%+7
P .ROTATE_R
Z
ROR A
d ROR MLR%+6
n ROR MLR%+5
x ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
" TYA:PHA
, LDX #4
6 LDY #0
@ CLD
J SEC
T
.Sub32L1
^ LDA NM1%,Y
h SBC NM2%,Y
r STA NM1%,Y
 INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
& STA NM1%,Y
0 INY
: DEX
D BNE Add32L1
N PLA:TAY
X PLA:TAX
b RTS
l .Div32
v TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
* ROL zRem% + 3
4 SEC
> .Subtract
H LDA zRem%
R SBC zDen%
\ STA zTemp%
f LDA zRem% + 1
p SBC zDen% + 1
z STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
$ BNE Divide
. PLA:TAY
8 PLA:TAX
B RTS
L .StoreToTIME
V LDX #3
` .STTI1
j LDA #0:STA NM1%,X
t% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
~ DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
( LDA #&93
2
LDX #&FF
< LDY #0
F JSR &FFF4
P LDY #0
Z
LDA #10
d STA NM2%
n .PrTiL1
x LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
"
LDA #&2D
, JSR &FFEE
6 LDA FDBS%+MN%
@
STA NM1%
J JSR Conv2d
T LDA #&2D
^ JSR &FFEE
h# \ Year printing is different \
r
LDA #100

STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
& JSR Conv2d
0 LDA STORE%
:
STA NM1%
D JSR Conv2d
N JSR &FFE7
X RTS
b .Conv2d
l JSR Div32
v LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
* ]
4 Pass%
> "SIZE : " +(P%PROG%)
HH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
R Y% = CMD 256
\ X% = CMD 256
f &FFF7
p $CMD
(2<FPZdnx",6@JT^hr&0:DNXblv *4>HR\fpz
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
$ TXA:PHA
. PHA
8 LDX #3
B .STZE1
L LDA HrsS,X : STA NM1%,X
V LDA #0: STA NM2%,X
` DEX
j BPL STZE1
t PLA
~ PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
TXA:PHA
TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
( LDX #3
2 .DTL1
< LDA STORE%,X:STA NM1%,X
F LDA DayS,X:STA NM2%,X
P DEX
Z
BPL DTL1
d JSR Div32
n \ hours = seconds / 3600 \
x LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
" LDA #&3C:STA NM2%
, JSR Div32
6! LDA zNum% : STA FDBS% + MIN%
@# LDA zRem% : STA FDBS% + SEC%
J RTS
T
.DayS
^ EQUD &00015180
h
.HrsS
r EQUD &00000E10

.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
& JSR Add32
0 \ era = days / 146097 \
: LDX #3
D .DDL3
N LDA NM1%,X:STA DYS%,X
X LDA Yr400,X:STA NM2%,X
b DEX
l BPL DDL3
v JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
* LDA NM1%,X:STA DOE%,X
4 LDA c1460,X:STA NM2%,X
> DEX
H
BPL DDL7
R JSR Div32
\ \ doe  doe / 1460 \
f LDX #3
p .DDL8
z LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
$ DEX
. BPL DDLA
8 JSR Add32
B LDX #3
L
.DDLB
V LDA NM1%,X: STA STORE%,X
` LDA DOE%,X:STA NM1%,X
j LDA c146096,X:STA NM2%,X
t DEX
~ BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
( LDX #3
2 .DDLE
< LDA zNum%,X:STA YOE%,X
F DEX
P
BPL DDLE
Z \ era * 400 \
d LDX #3
n
.DDLF
x LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
" BPL DDL11
, LDX #3
6 .DDL12
@ LDA year,X:STA NM1%,X
J LDA YOE%,X:STA NM2%,X
T DEX
^ BPL DDL12
h JSR Mul32
r"0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
JMP UTCCEND
CPY #0 \ UTC = 0 ?
BEQ UTCCEND \ =0 NO ACTION
BMI UTCCNEG
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
BPL UTCL2
JSR Sub32
LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
* BPL UTCL3
4 JMP UTCCEND
>
.UTCCNEG
H SEC
R LDA #0
\ SBC &FD00
f
STA NM2%
p JSR Mul32
z JMP UTCCEND
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
$ \ hours = seconds / 3600 \
. LDX #3
8
.DTL2
B LDA zNum%,X:STA DAYT%,X
L LDA zRem%,X:STA NM1%,X
V" \ To be used to set value
`% LDA zRem%,X:STA &FD00+TIMEVAR%,X
j LDA HrsS,X:STA NM2%,X
t DEX
~ BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
( EQUD &00000E10
2
.YrCr
< EQUD &000A968D
F .Yr400
P EQUD &00023AB1
Z .c1460
d EQUD &000005B4
n .c36524
x EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX LDX #3
 .DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
& DEX
0 BPL DDL15
: LDA #100:STA NM2%
D JSR Div32
N LDX #3
X
.DDL16
b LDA zNum%,X:STA NM2%,X
l LDA STORE%,X:STA NM1%,X
v DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
* LDA #2:STA NM2%
4 JSR Add32
> LDA #153:STA NM2%
H JSR Div32
R LDA zNum%:STA MP%
\ CMP #10
f BPL DDL19
p ADC #3
z STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
$ .DDL1D
. LDA NM1%,X:STA FDBS%+YR%,X
8 DEX
B BPL DDL1D
L .DDL1B
V LDX #3
` LDA #0
j .DDL20
t STA NM1%,X:STA NM2%,X
~ DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
( LDA #0
2 .DDL22
< STA NM2%,X
F DEX
P BPL DDL22
Z LDA #1:STA NM2%
d JSR Add32
n LDA NM1% :STA FDBS%+DAY%
x RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
" BNE START_R
,
.SHIFT_R
6 BCC ROTATE_R
@ LDA MLR%+4
J CLC
T ADC NM2%
^ STA MLR%+4
h LDA MLR%+5
r ADC NM2%+1
 STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
& DEX
0 BNE SHIFT_R
: LDX #3
D
.Mul32L2
N LDA MLR%,X:STA NM1%,X
X DEX
b BPL Mul32L2
l RTS
v
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
* RTS
4 .Add32
> TXA:PHA
H TYA:PHA
R LDY #0
\ LDX #4
f CLD
p CLC
z
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
$ LDA #0:STA zRem%,X
. DEX
8
BPL CND
B LDX #32
L
.Divide
V ASL zNum%
` ROL zNum% + 1
j ROL zNum% + 2
t ROL zNum% + 3
~ ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
( STA zTemp% + 3
2
BCC Next
< INC zNum%
F LDY #3
P .CpTmpToRem
Z LDA zTemp%, Y
d STA zRem% , Y
n DEY
x BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
" .STTI2
,$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
6 DEX
@ BPL STTI2
J LDA #&2
T LDX #(FDBS%+TIMEVAR%) 256
^ LDY #(FDBS%+TIMEVAR%) 256
h JSR &FFF1
r RTS
 .PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
#3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
" BPL DDL3
, JSR Div32
6 LDX #3
@ .DDL5
J LDA zNum%,X:STA ERA%,X
T LDA zNum%,X:STA NM1%,X
^ DEX
h
BPL DDL5
r JSR Mul32
 \ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
& .DDL8
0 LDA zNum%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL8
X JSR Sub32
b LDX #3
l .DDL9
v LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
* DEX
4 BPL DDLB
> JSR Div32
H* \ doedoe/1460+doe/36524doe/146096 \
R LDX #3
\
.DDLC
f LDA STORE%,X:STA NM1%,X
p LDA zNum%,X:STA NM2%,X
z DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
$
.DDLF
. LDA ERA%,X:STA NM1%,X
8 LDA c400,X:STA NM2%,X
B DEX
L
BPL DDLF
V JSR Mul32
` \ yoe + era * 400 \
j LDX #3
t .DDL10
~ LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
( LDX #3
2 .DDL13
< LDA YOE%,X:STA NM2%,X:DEX
F BPL DDL13
P LDX #1
Z .DDL14
d LSR NM2%+3
n ROR NM2%+2
x ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
" LDA STORE%,X:STA NM1%,X
, DEX
6 BPL DDL16
@ JSR Sub32
J LDX #3
T .DDL17
^ LDA NM1%,X:STA NM2%,X
h LDA DOE%,X:STA NM1%,X
r DEX
 BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
& ADC #3
0 STA FDBS%+MN%
: JMP DDL1A
D .DDL19
N SBC #9
X STA FDBS%+MN%
b .DDL1A
l CMP #3
v BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
* STA NM1%,X:STA NM2%,X
4 DEX
> BPL DDL20
H LDA #153:STA NM2%
R LDA MP%: STA NM1%
\ JSR Mul32
f LDA #2:STA NM2%
p JSR Add32
z LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
$ LDA NM1% :STA FDBS%+DAY%
. RTS
8
.year
B EQUD &0000016D
L
.c400
V EQUD &00000190
` .Mul32
j LDA #0
t STA MLR%+4
~ STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
( ADC NM2%+1
2 STA MLR%+5
< LDA MLR%+6
F ADC NM2%+2
P STA MLR%+6
Z LDA MLR%+7
d ADC NM2%+3
n STA MLR%+7
x .ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BN CPY #2
BEQ PrTiL2
& JSR &FFEE
0 .PrTiL2
: INY
D CPY #3
N BNE PrTiL1
X JSR &FFE7
b RTS
l .PrintDate
v LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
* BPL PDL1
4 JSR Div32
>$ \ STORE LOWER PART OF YEAR \
H LDA zRem%
R STA STORE%
\ JSR ClearNums
f LDA #10
p STA NM2%
z LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
$ ADC #&30
. JSR &FFEE
8 RTS
B .ClearNums
L$ \ NM1 and NM2 are in one line \
V LDX #7
` LDA #0
j
.CNL1
t STA NM1%,X
~ DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
tVMDSAVE NTP 4E98 5563 4F01
DBS%:XR%MIN%\NEC%MAY%NN%MR%MYS%RA%MOE%EXOE%hN
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
E SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
" RTS
,
.Sub32
6 PHP
@ TXA:PHA
J TYA:PHA
T LDX #4
^ LDY #0
h CLD
r SEC

.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
& CLC
0
.Add32L1
: LDA NM1%,Y
D ADC NM2%,Y
N STA NM1%,Y
X INY
b DEX
l BNE Add32L1
v PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
* ROL zNum% + 3
4 ROL zRem%
> ROL zRem% + 1
H ROL zRem% + 2
R ROL zRem% + 3
\ SEC
f .Subtract
p LDA zRem%
z SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
$ DEY
. BPL CpTmpToRem
8 .Next
B DEX
L BNE Divide
V PLA:TAY
` PLA:TAX
j RTS
t .StoreToTIME
~ LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
( RTS
2 .PrintTime
< JSR ClearNums
F \ Select page 0 \
P LDA #&93
Z
LDX #&FF
d LDY #0
n JSR &FFF4
x LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
" .PrintDate
, LDA FDBS%+DAY%
6 STA NM1%
@ JSR Conv2d
J
LDA #&2D
T JSR &FFEE
^ LDA FDBS%+MN%
h
STA NM1%
r JSR Conv2d
 LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
& STA NM2%
0 LDA zNum%
:
STA NM1%
D \ Conv. upp. part of year \
N JSR Conv2d
X LDA STORE%
b
STA NM1%
l JSR Conv2d
v JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
* STA NM1%,X
4 DEX
>
BPL CNL1
H RTS
R ]
\ Pass%
f "SIZE : " +(P%PROG%)
pH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
z Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
x",6@JT^hr&0:DNXblv
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR .GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
\LDX #3 \
.UTCL1
\LDA HrsS,X:STA NM1%,X \
\LDA #0: STA NM2%,X \
\DEX \
\BPL UTCL1
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
$ TXA:PHA
. PHA
8 LDX #3
B .STZE1
L LDA HrsS,X : STA NM1%,X
V LDA #0: STA NM2%,X
` DEX
j BPL STZE1
t PLA
~ PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
TXA:PHA
TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
( LDX #3
2 .DTL1
< LDA STORE%,X:STA NM1%,X
F LDA DayS,X:STA NM2%,X
P DEX
Z
BPL DTL1
d JSR Div32
n \ hours = seconds / 3600 \
x LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
" LDA #&3C:STA NM2%
, JSR Div32
6! LDA zNum% : STA FDBS% + MIN%
@# LDA zRem% : STA FDBS% + SEC%
J RTS
T
.DayS
^ EQUD &00015180
h
.HrsS
r EQUD &00000E10

.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
& JSR Add32
0 \ era = days / 146097 \
: LDX #3
D .DDL3
N LDA NM1%,X:STA DYS%,X
X LDA Yr400,X:STA NM2%,X
b DEX
l BPL DDL3
v JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
* LDA NM1%,X:STA DOE%,X
4 LDA c1460,X:STA NM2%,X
> DEX
H
BPL DDL7
R JSR Div32
\ \ doe  doe / 1460 \
f LDX #3
p .DDL8
z LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
$ DEX
. BPL DDLA
8 JSR Add32
B LDX #3
L
.DDLB
V LDA NM1%,X: STA STORE%,X
` LDA DOE%,X:STA NM1%,X
j LDA c146096,X:STA NM2%,X
t DEX
~ BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
( LDX #3
2 .DDLE
< LDA zNum%,X:STA YOE%,X
F DEX
P
BPL DDLE
Z \ era * 400 \
d LDX #3
n
.DDLF
x LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL1UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
BEQ UTCCEND \ =0 NO ACTION
BMI UTCCNEG
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
BPL UTCL2
JSR Sub32
LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
* BPL UTCL3
4 JMP UTCCEND
>
.UTCCNEG
H SEC
R LDA #0
\ SBC &FD00
f
STA NM2%
p JSR Mul32
z JMP UTCCEND
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
$ \ hours = seconds / 3600 \
. LDX #3
8
.DTL2
B LDA zNum%,X:STA DAYT%,X
L LDA zRem%,X:STA NM1%,X
V" \ To be used to set value
`% LDA zRem%,X:STA &FD00+TIMEVAR%,X
j LDA HrsS,X:STA NM2%,X
t DEX
~ BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
( EQUD &00000E10
2
.YrCr
< EQUD &000A968D
F .Yr400
P EQUD &00023AB1
Z .c1460
d EQUD &000005B4
n .c36524
x EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
" BPL DDL3
, JSR Div32
6 LDX #3
@ .DDL5
J LDA zNum%,X:STA ERA%,X
T LDA zNum%,X:STA NM1%,X
^ DEX
h
BPL DDL5
r JSR Mul32
 \ days  era * 146097 \
LDX #3
.DDL6
0
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
" BPL DDL11
, LDX #3
6 .DDL12
@ LDA year,X:STA NM1%,X
J LDA YOE%,X:STA NM2%,X
T DEX
^ BPL DDL12
h JSR Mul32
r LDX #3
 .DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
& DEX
0 BPL DDL15
: LDA #100:STA NM2%
D JSR Div32
N LDX #3
X
.DDL16
b LDA zNum%,X:STA NM2%,X
l LDA STORE%,X:STA NM1%,X
v DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
* LDA #2:STA NM2%
4 JSR Add32
> LDA #153:STA NM2%
H JSR Div32
R LDA zNum%:STA MP%
\ CMP #10
f BPL DDL19
p ADC #3
z STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
$ .DDL1D
. LDA NM1%,X:STA FDBS%+YR%,X
8 DEX
B BPL DDL1D
L .DDL1B
V LDX #3
` LDA #0
j .DDL20
t STA NM1%,X:STA NM2%,X
~ DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
( LDA #0
2 .DDL22
< STA NM2%,X
F DEX
P BPL DDL22
Z LDA #1:STA NM2%
d JSR Add32
n LDA NM1% :STA FDBS%+DAY%
x RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
" BNE START_R
,
.SHIFT_R
6 BCC ROTATE_R
@ LDA MLR%+4
J CLC
T ADC NM2%
^ STA MLR%+4
h LDA MLR%+5
r ADC NM2%+1
 STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
& DEX
0 BNE SHIFT_R
: LDX #3
D
.Mul32L2
N LDA MLR%,X:STA NM1%,X
X DEX
b BPL Mul32L2
l RTS
v
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
* RTS
4 .Add32
> TXA:PHA
H TYA:PHA
R LDY #0
\ LDX #4
f CLD
p CLC
z
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
$ LDA #0:STA zRem%,X
. DEX
8
BPL CND
B LDX #32
L
.Divide
V ASL zNum%
` ROL zNum% + 1
j ROL zNum% + 2
t ROL zNum% + 3
~ ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
( STA zTemp% + 3
2
BCC Next
< INC zNum%
F LDY #3
P .CpTmpToRem
Z LDA zTemp%, Y
d STA zRem% , Y
n DEY
x BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
" .STTI2
,$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
6 DEX
@ BPL STTI2
J LDA #&2
T LDX #(FDBS%+TIMEVAR%) LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
& .DDL8
0 LDA zNum%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL8
X JSR Sub32
b LDX #3
l .DDL9
v LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
* DEX
4 BPL DDLB
> JSR Div32
H* \ doedoe/1460+doe/36524doe/146096 \
R LDX #3
\
.DDLC
f LDA STORE%,X:STA NM1%,X
p LDA zNum%,X:STA NM2%,X
z DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
$
.DDLF
. LDA ERA%,X:STA NM1%,X
8 LDA c400,X:STA NM2%,X
B DEX
L
BPL DDLF
V JSR Mul32
` \ yoe + era * 400 \
j LDX #3
t .DDL10
~ LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
( LDX #3
2 .DDL13
< LDA YOE%,X:STA NM2%,X:DEX
F BPL DDL13
P LDX #1
Z .DDL14
d LSR NM2%+3
n ROR NM2%+2
x ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
" LDA STORE%,X:STA NM1%,X
, DEX
6 BPL DDL16
@ JSR Sub32
J LDX #3
T .DDL17
^ LDA NM1%,X:STA NM2%,X
h LDA DOE%,X:STA NM1%,X
r DEX
 BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
& ADC #3
0 STA FDBS%+MN%
: JMP DDL1A
D .DDL19
N SBC #9
X STA FDBS%+MN%
b .DDL1A
l CMP #3
v BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
* STA NM1%,X:STA NM2%,X
4 DEX
> BPL DDL20
H LDA #153:STA NM2%
R LDA MP%: STA NM1%
\ JSR Mul32
f LDA #2:STA NM2%
p JSR Add32
z LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
$ LDA NM1% :STA FDBS%+DAY%
. RTS
8
.year
B EQUD &0000016D
L
.c400
V EQUD &00000190
` .Mul32
j LDA #0
t STA MLR%+4
~ STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
( ADC NM2%+1
2 STA MLR%+5
< LDA MLR%+6
F ADC NM2%+2
P STA MLR%+6
Z LDA MLR%+7
d ADC NM2%+3
n STA MLR%+7
x .ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
" RTS
,
.Sub32
6 PHP
@ TXA:PHA
J TYA:PHA
T LDX #4
^ LDY #0
h CLD
r SEC

.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
256
^ LDY #(FDBS%+TIMEVAR%) 256
h JSR &FFF1
r RTS
 .PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
& JSR &FFEE
0 .PrTiL2
: INY
D CPY #3
N BNE PrTiL1
X JSR &FFE7
b RTS
l .PrintDate
v LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
* BPL PDL1
4 JSR Div32
>$ \ STORE LOWER PART OF YEAR \
H LDA zRem%
R STA STORE%
\ JSR ClearNums
f LDA #10
p STA NM2%
z LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
$ ADC #&30
. JSR &FFEE
8 RTS
B .ClearNums
L$ \ NM1 and NM2 are in one line \
V LDX #7
` LDA #0
j
.CNL1
t STA NM1%,X
~ DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
F01
DBS%:XR%MIN%\NEC%MAY%NN%MR%MYS%RA%MOE%EXOE%hN
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&9 PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
& CLC
0
.Add32L1
: LDA NM1%,Y
D ADC NM2%,Y
N STA NM1%,Y
X INY
b DEX
l BNE Add32L1
v PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
* ROL zNum% + 3
4 ROL zRem%
> ROL zRem% + 1
H ROL zRem% + 2
R ROL zRem% + 3
\ SEC
f .Subtract
p LDA zRem%
z SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
$ DEY
. BPL CpTmpToRem
8 .Next
B DEX
L BNE Divide
V PLA:TAY
` PLA:TAX
j RTS
t .StoreToTIME
~ LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
( RTS
2 .PrintTime
< JSR ClearNums
F \ Select page 0 \
P LDA #&93
Z
LDX #&FF
d LDY #0
n JSR &FFF4
x LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
" .PrintDate
, LDA FDBS%+DAY%
6 STA NM1%
@ JSR Conv2d
J
LDA #&2D
T JSR &FFEE
^ LDA FDBS%+MN%
h
STA NM1%
r JSR Conv2d
 LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
& STA NM2%
0 LDA zNum%
:
STA NM1%
D \ Conv. upp. part of year \
N JSR Conv2d
X LDA STORE%
b
STA NM1%
l JSR Conv2d
v JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
* STA NM1%,X
4 DEX
>
BPL CNL1
H RTS
R ]
\ Pass%
f "SIZE : " +(P%PROG%)
pH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
z Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
FF7
$CMD
TMDSAVE NTP 4CAD 5347 4D16
DBS%VR%KIN%qLEC%KAY%LN% LR%KYS%XRA%
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
5
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
BPL UTCL2
JSR Add32
* LDX #3
4 .UTCL3
> LDA NM1%,X:STA STORE%,X
H DEX
R BPL UTCL3
\ JMP UTCCEND
f
.UTCCNEG
p \ Select page 0
z TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.STZE1
LDA HrsS,X : STA NM1%,X
$ LDA #0: STA NM2%,X
. DEX
8 BPL STZE1
B PLA
L PLA:TAX
V RTS
` .SelPZ
j \ Select page 0
t \ Reg X,Y and A preserved
~ TXA:PHA
TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
(
BPL DTL1
2 JSR Div32
< \ hours = seconds / 3600 \
F LDX #3
P
.DTL2
Z LDA zNum%,X:STA DAYT%,X
d LDA zRem%,X:STA NM1%,X
n" \ To be used to set value
x% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
"
.DayS
, EQUD &00015180
6
.HrsS
@ EQUD &00000E10
J
.YrCr
T EQUD &000A968D
^ .Yr400
h EQUD &00023AB1
r .c1460
 EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
& LDA Yr400,X:STA NM2%,X
0 DEX
: BPL DDL3
D JSR Div32
N LDX #3
X .DDL5
b LDA zNum%,X:STA ERA%,X
l LDA zNum%,X:STA NM1%,X
v DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
* \ doe  doe / 1460 \
4 LDX #3
> .DDL8
H LDA zNum%,X:STA NM2%,X
R LDA DOE%,X:STA NM1%,X
\ DEX
f BPL DDL8
p JSR Sub32
z LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
$ LDA NM1%,X: STA STORE%,X
. LDA DOE%,X:STA NM1%,X
8 LDA c146096,X:STA NM2%,X
B DEX
L BPL DDLB
V JSR Div32
`* \ doedoe/1460+doe/36524doe/146096 \
j LDX #3
t
.DDLC
~ LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
( \ era * 400 \
2 LD
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
BEQ UTCCEND \ =0 NO ACTION
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
* BPL UTCL2
4 JSR Sub32
> LDX #3
H .UTCL3
R LDA NM1%,X:STA STORE%,X
\ DEX
f BPL UTCL3
p JMP UTCCEND
z
.UTCCNEG
SEC
LDA #0
SBC &FD00
STA NM2%
JSR Mul32
JMP UTCCEND
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
$ .DTL1
. LDA STORE%,X:STA NM1%,X
8 LDA DayS,X:STA NM2%,X
B DEX
L
BPL DTL1
V JSR Div32
` \ hours = seconds / 3600 \
j LDX #3
t
.DTL2
~ LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
(! LDA zNum% : STA FDBS% + MIN%
2# LDA zRem% : STA FDBS% + SEC%
< RTS
F
.DayS
P EQUD &00015180
Z
.HrsS
d EQUD &00000E10
n
.YrCr
x EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
" \ era = days / 146097 \
, LDX #3
6 .DDL3
@ LDA NM1%,X:STA DYS%,X
J LDA Yr400,X:STA NM2%,X
T DEX
^ BPL DDL3
h JSR Div32
r LDX #3
 .DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,XX #3
<
.DDLF
F LDA ERA%,X:STA NM1%,X
P LDA c400,X:STA NM2%,X
Z DEX
d
BPL DDLF
n JSR Mul32
x \ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
" DEX
, BPL DDL12
6 JSR Mul32
@ LDX #3
J .DDL13
T LDA YOE%,X:STA NM2%,X:DEX
^ BPL DDL13
h LDX #1
r .DDL14
 LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
&
.DDL16
0 LDA zNum%,X:STA NM2%,X
: LDA STORE%,X:STA NM1%,X
D DEX
N BPL DDL16
X JSR Sub32
b LDX #3
l .DDL17
v LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
* CMP #10
4 BPL DDL19
> ADC #3
H STA FDBS%+MN%
R JMP DDL1A
\ .DDL19
f SBC #9
p STA FDBS%+MN%
z .DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
$ LDX #3
. LDA #0
8 .DDL20
B STA NM1%,X:STA NM2%,X
L DEX
V BPL DDL20
` LDA #153:STA NM2%
j LDA MP%: STA NM1%
t JSR Mul32
~ LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
( LDA #1:STA NM2%
2 JSR Add32
< LDA NM1% :STA FDBS%+DAY%
F RTS
P
.year
Z EQUD &0000016D
d
.c400
n EQUD &00000190
x .Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
" ADC NM2%
, STA MLR%+4
6 LDA MLR%+5
@ ADC NM2%+1
J STA MLR%+5
T LDA MLR%+6
^ ADC NM2%+2
h STA MLR%+6
r LDA MLR%+7
 ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
& DEX
0 BPL Mul32L2
: RTS
D
.Sub32
N PHP
X TXA:PHA
b TYA:PHA
l LDX #4
v LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
* LDX #4
4 CLD
> CLC
H
.Add32L1
R LDA NM1%,Y
\ ADC NM2%,Y
f STA NM1%,Y
p INY
z DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
$ ASL zNum%
. ROL zNum% + 1
8 ROL zNum% + 2
B ROL zNum% + 3
L ROL zRem%
V ROL zRem% + 1
` ROL zRem% + 2
j ROL zRem% + 3
t SEC
~ .Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
( LDA zTemp%, Y
2 STA zRem% , Y
< DEY
F BPL CpTmpToRem
P .Next
Z DEX
d BNE Divide
n PLA:TAY
x PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
L:STA DOE%,X
& LDA c1460,X:STA NM2%,X
0 DEX
:
BPL DDL7
D JSR Div32
N \ doe  doe / 1460 \
X LDX #3
b .DDL8
l LDA zNum%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
* JSR Add32
4 LDX #3
>
.DDLB
H LDA NM1%,X: STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c146096,X:STA NM2%,X
f DEX
p BPL DDLB
z JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
$ .DDLE
. LDA zNum%,X:STA YOE%,X
8 DEX
B
BPL DDLE
L \ era * 400 \
V LDX #3
`
.DDLF
j LDA ERA%,X:STA NM1%,X
t LDA c400,X:STA NM2%,X
~ DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
( .DDL12
2 LDA year,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL12
Z JSR Mul32
d LDX #3
n .DDL13
x LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
" BPL DDL15
, LDA #100:STA NM2%
6 JSR Div32
@ LDX #3
J
.DDL16
T LDA zNum%,X:STA NM2%,X
^ LDA STORE%,X:STA NM1%,X
h DEX
r BPL DDL16
 JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
& JSR Add32
0 LDA #153:STA NM2%
: JSR Div32
D LDA zNum%:STA MP%
N CMP #10
X BPL DDL19
b ADC #3
l STA FDBS%+MN%
v JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
* DEX
4 BPL DDL1D
> .DDL1B
H LDX #3
R LDA #0
\ .DDL20
f STA NM1%,X:STA NM2%,X
p DEX
z BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
$ .DDL22
. STA NM2%,X
8 DEX
B BPL DDL22
L LDA #1:STA NM2%
V JSR Add32
` LDA NM1% :STA FDBS%+DAY%
j RTS
t
.year
~ EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
( BCC ROTATE_R
2 LDA MLR%+4
< CLC
F ADC NM2%
P STA MLR%+4
Z LDA MLR%+5
d ADC NM2%+1
n STA MLR%+5
x LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
" BNE SHIFT_R
, LDX #3
6
.Mul32L2
@ LDA MLR%,X:STA NM1%,X
J DEX
T BPL Mul32L2
^ RTS
h
.Sub32
r PHP
 TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
& .Add32
0 TXA:PHA
: TYA:PHA
D LDY #0
N LDX #4
X CLD
b CLC
l
.Add32DA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
" LDX #(FDBS%+TIMEVAR%) 256
, LDY #(FDBS%+TIMEVAR%) 256
6 JSR &FFF1
@ RTS
J .PrintTime
T JSR ClearNums
^ \ Select page 0 \
h LDA #&93
r
LDX #&FF
 LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
& JSR &FFE7
0 RTS
: .PrintDate
D LDA FDBS%+DAY%
N STA NM1%
X JSR Conv2d
b
LDA #&2D
l JSR &FFEE
v LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
* JSR ClearNums
4 LDA #10
> STA NM2%
H LDA zNum%
R
STA NM1%
\ \ Conv. upp. part of year \
f JSR Conv2d
p LDA STORE%
z
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
$ LDX #7
. LDA #0
8
.CNL1
B STA NM1%,X
L DEX
V
BPL CNL1
` RTS
j ]
t Pass%
~ "SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
(2<FPZdnx",6@JT^hr&0:DNXblv *4>HR\fpz$.8BLV`jt
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INXL1
v LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
*
BPL CND
4 LDX #32
>
.Divide
H ASL zNum%
R ROL zNum% + 1
\ ROL zNum% + 2
f ROL zNum% + 3
p ROL zRem%
z ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
$
BCC Next
. INC zNum%
8 LDY #3
B .CpTmpToRem
L LDA zTemp%, Y
V STA zRem% , Y
` DEY
j BPL CpTmpToRem
t .Next
~ DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
( DEX
2 BPL STTI2
< LDA #&2
F LDX #(FDBS%+TIMEVAR%) 256
P LDY #(FDBS%+TIMEVAR%) 256
Z JSR &FFF1
d RTS
n .PrintTime
x JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
" .PrTiL2
, INY
6 CPY #3
@ BNE PrTiL1
J JSR &FFE7
T RTS
^ .PrintDate
h LDA FDBS%+DAY%
r STA NM1%
 JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
& JSR Div32
0$ \ STORE LOWER PART OF YEAR \
: LDA zRem%
D STA STORE%
N JSR ClearNums
X LDA #10
b STA NM2%
l LDA zNum%
v
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
* RTS
4 .ClearNums
>$ \ NM1 and NM2 are in one line \
H LDX #7
R LDA #0
\
.CNL1
f STA NM1%,X
p DEX
z
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
(2<F
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 S
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
\LDX #3 \
.UTCL2
\LDA STORE%,X:STA NM1%,X \
\LDA MLR%,X:STA NM2%,X
\DEX \
\BPL UTCL2 \
JSR StoMLR
* JSR Add32
4 LDX #3
> .UTCL3
H LDA NM1%,X:STA STORE%,X
R DEX
\ BPL UTCL3
f JMP UTCCEND
p
.UTCCNEG
z \ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoMLR
\ Copies STORE% to NM1%
\ Copies MLR% to NM2%
\ Preserves A and Z
TXA:PHA
PHA
LDX #3
$ .STMLR1
. LDA STORE%,X:STA NM1%,X
8 LDA MLR%,X:STA NM2%,X
B DEX
L BPL STMLR1
V PLA
` PLA:TAX
j RTS
t
.StoZero
~ \ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.STZE1
LDA HrsS,X : STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL STZE1
PLA
PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
( TXA:PHA
2 TYA:PHA
< PHA
F
LDA #&93
P
LDX #&FF
Z LDY #0
d JSR &FFF4
n PLA
x
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
"% LDA zRem%,X:STA &FD00+TIMEVAR%,X
, LDA HrsS,X:STA NM2%,X
6 DEX
@ BPL DTL2
J JSR Div32
T LDA zNum%:STA FDBS% + HR%
^ LDX #3
h
.DTL3
r LDA zRem%,X:STA NM1%,X
 LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
& EQUD &000005B4
0 .c36524
: EQUD &00008EAC
D
.c146096
N EQUD &00023AB0
X .DecoDate
b LDX #3
l .DDL1
v LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
*
BPL DDL5
4 JSR Mul32
> \ days  era * 146097 \
H LDX #3
R .DDL6
\ LDA MLR%,X:STA NM2%,X
f LDA DYS%,X:STA NM1%,X
p DEX
z BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
$ LDX #3
. .DDL9
8 LDA NM1%,X:STA STORE%,X
B LDA DOE%,X:STA NM1%,X
L LDA c36524,X:STA NM2%,X
V DEX
`
BPL DDL9
j JSR Div32
t LDX #3
~ .DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DETA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
BEQ UTCCEND \ =0 NO ACTION
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA MLR%,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Sub32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
SEC
LDA #0
SBC &FD00
STA NM2%
JSR Mul32
JMP UTCCEND
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
$ JSR &FFF4
. PLA:TAY
8 PLA:TAX
B RTS
L .DecoTime
V LDX #3
` .DTL1
j LDA STORE%,X:STA NM1%,X
t LDA DayS,X:STA NM2%,X
~ DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
( LDA zRem%,X:STA NM1%,X
2 LDA #0:STA NM2%,X
< DEX
F
BPL DTL3
P LDA #&3C:STA NM2%
Z JSR Div32
d! LDA zNum% : STA FDBS% + MIN%
n# LDA zRem% : STA FDBS% + SEC%
x RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
" .DDL1
, LDA DAYT%,X:STA NM1%,X
6 LDA YrCr,X:STA NM2%,X
@ DEX
J BPL DDL1
T JSR Add32
^ \ era = days / 146097 \
h LDX #3
r .DDL3
 LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
& DEX
0 BPL DDL6
: JSR Sub32
D LDX #3
N .DDL7
X LDA NM1%,X:STA DOE%,X
b LDA c1460,X:STA NM2%,X
l DEX
v
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,XX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
( LDA STORE%,X:STA NM1%,X
2 LDA zNum%,X:STA NM2%,X
< DEX
F
BPL DDLC
P JSR Sub32
Z LDX #3
d .DDLD
n LDA year,X:STA NM2%,X
x DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
" \ yoe + era * 400 \
, LDX #3
6 .DDL10
@ LDA MLR%,X:STA NM1%,X
J LDA YOE%,X:STA NM2%,X
T DEX
^ BPL DDL10
h JSR Add32
r LDX #3
 .DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
& LSR NM2%+3
0 ROR NM2%+2
: ROR NM2%+1
D ROR NM2%
N DEX
X BPL DDL14
b JSR Add32
l LDX #3
v .DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
* LDA DOE%,X:STA NM1%,X
4 DEX
> BPL DDL17
H JSR Sub32
R LDX #3
\ .DDL18
f LDA NM1%,X:STA DOY%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
$ .DDL1A
. CMP #3
8 BPL DDL1B
B LDX #3
L .DDL1C
V! LDA FDBS% + YR%,X:STA NM1%,X
` LDA #0:STA NM2%,X
j DEX
t BPL DDL1C
~ LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
( LDA #2:STA NM2%
2 JSR Add32
< LDA #5:STA NM2%
F JSR Div32
P LDX #3
Z .DDL21
d LDA zNum%,X:STA NM2%,X
n LDA DOY%,X:STA NM1%,X
x DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
" .Mul32
, LDA #0
6 STA MLR%+4
@ STA MLR%+5
J STA MLR%+6
T STA MLR%+7
^ LDX #3
h
.Mul32L1
r LDA NM1%,X:STA MLR%,X
 DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
& ADC NM2%+3
0 STA MLR%+7
: .ROTATE_R
D
ROR A
N ROR MLR%+6
X ROR MLR%+5
b ROR MLR%+4
l .START_R
v ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
* CLD
4 SEC
>
.Sub32L1
H LDA NM1%,Y
R SBC NM2%,Y
\ STA NM1%,Y
f INY
p DEX
z BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
$ DEX
. BNE Add32L1
8 PLA:TAY
B PLA:TAX
L RTS
V .Div32
` TXA:PHA
j TYA:PHA
t LDX #3
~ .CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
* LDX #3
4 .DDLA
> LDA zNum%,X:STA NM1%,X
H LDA STORE%,X:STA NM2%,X
R DEX
\ BPL DDLA
f JSR Add32
p LDX #3
z
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
$ LDA year,X:STA NM2%,X
. DEX
8 BPL DDLD
B JSR Div32
L \ Store result in YOE% \
V LDX #3
` .DDLE
j LDA zNum%,X:STA YOE%,X
t DEX
~
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
( LDX #3
2 .DDL11
JSR Add32
H LDX #3
R .DDL1D
\ LDA NM1%,X:STA FDBS%+YR%,X
f DEX
p BPL DDL1D
z .DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
$ LDA DOY%,X:STA NM1%,X
. DEX
8 BPL DDL21
B JSR Sub32
L LDX #3
V LDA #0
` .DDL22
j STA NM2%,X
t DEX
~ BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
( LDA NM1%,X:STA MLR%,X
2 DEX
< BPL Mul32L1
F
LDX #&21
P BNE START_R
Z
.SHIFT_R
d BCC ROTATE_R
n LDA MLR%+4
x CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
" .START_R
, ROR MLR%+3
6 ROR MLR%+2
@ ROR MLR%+1
J
ROR MLR%
T DEX
^ BNE SHIFT_R
h LDX #3
r
.Mul32L2
 LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
& DEX
0 BNE Sub32L1
: PLA:TAY
D
PLA:TAX
N PLP
X RTS
b .Add32
l TXA:PHA
v TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
* LDX #3
4
( .Subtract
2 LDA zRem%
< SBC zDen%
F STA zTemp%
P LDA zRem% + 1
Z SBC zDen% + 1
d STA zTemp% + 1
n LDA zRem% + 2
x SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
" PLA:TAX
, RTS
6 .StoreToTIME
@ LDX #3
J .STTI1
T LDA #0:STA NM1%,X
^% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
h DEX
r BPL STTI1
 LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
& LDY #0
0 JSR &FFF4
: LDY #0
D
LDA #10
N STA NM2%
X .PrTiL1
b LDA FDBS% + HR%,Y
l
STA NM1%
v JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
*
STA NM1%
4 JSR Conv2d
> LDA #&2D
H JSR &FFEE
R# \ Year printing is different \
\
LDA #100
f
STA NM2%
p LDX #3
z
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
$
STA NM1%
. JSR Conv2d
8 JSR &FFE7
B RTS
L .Conv2d
V JSR Div32
` LDA zNum%
j CLC
t
ADC #&30
~ JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
( "SIZE : " +(P%PROG%)
2H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
< Y% = CMD 256
F X% = CMD 256
P &FFF7
Z $CMD
7Zdnx",6@JT^hr&0:DNXblv *4>HR\fpz$llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll .CND
> LDA NM1%,X:STA zNum%,X
H LDA NM2%,X:STA zDen%,X
R LDA #0:STA zRem%,X
\ DEX
f
BPL CND
p LDX #32
z
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
$ LDA zRem% + 2
. SBC zDen% + 2
8 STA zTemp% + 2
B LDA zRem% + 3
L SBC zDen% + 3
V STA zTemp% + 3
`
BCC Next
j INC zNum%
t LDY #3
~ .CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
( BPL STTI1
2 LDA #100:STA NM1%
< JSR Mul32
F LDX #3
P .STTI2
Z$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
d DEX
n BPL STTI2
x LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
"
STA NM1%
, JSR Conv2d
6 LDA #&3A
@ CPY #2
J BEQ PrTiL2
T JSR &FFEE
^ .PrTiL2
h INY
r CPY #3
 BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
& LDX #3
0
.PDL1
: LDA FDBS%+YR%,X
D STA NM1%,X
N DEX
X BPL PDL1
b JSR Div32
l$ \ STORE LOWER PART OF YEAR \
v LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
*
ADC #&30
4 JSR &FFEE
> LDA zRem%
H CLC
R ADC #&30
\ JSR &FFEE
f RTS
p .ClearNums
z$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
(2<FPZdnx",6@JT^hr&0:DNXblv *4>HR\fp
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 SllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllTA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
\BMI UTCCNEG \
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA HrsS,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
$ .DTL1
. LDA STORE%,X:STA NM1%,X
8 LDA DayS,X:STA NM2%,X
B DEX
L
BPL DTL1
V JSR Div32
` \ hours = seconds / 3600 \
j LDX #3
t
.DTL2
~ LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
(! LDA zNum% : STA FDBS% + MIN%
2# LDA zRem% : STA FDBS% + SEC%
< RTS
F
.DayS
P EQUD &00015180
Z
.HrsS
d EQUD &00000E10
n
.YrCr
x EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
" \ era = days / 146097 \
, LDX #3
6 .DDL3
@ LDA NM1%,X:STA DYS%,X
J LDA Yr400,X:STA NM2%,X
T DEX
^ BPL DDL3
h JSR Div32
r LDX #3
 .DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
& LDA c1460,X:STA NM2%,X
0 DEX
:
BPL DDL7
D JSR Div32
N \ doe  doe / 1460 \
X LDX #3
b .DDL8
l LDA zNum%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
* JSR Add32
4 LDX #3
>
.DDLB
H LDA NM1%,X: STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c146096,X:STA NM2%,X
f DEX
p BPL DDLB
z JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
$ .DDLE
. LDA zNum%,X:STA YOE%,X
8 DEX
B
BPL DDLE
L \ era * 400 \
V LDX #3
`
.DDLF
j LDA ERA%,X:STA NM1%,X
t LDA c400,X:STA NM2%,X
~ DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
( .DDL12
2 LDA year,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL12
Z JSR Mul32
d LDX #3
n .DDL13
x LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
" BPL DDL15
, LDA #100:STA NM2%
6 JSR Div32
@ LDX #3
J
.DDL16
T LDA zNum%,X:STA NM2%,X
^ LDA STORE%,X:STA NM1%,X
h DEX
r BPL DDL16
 JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
& JSR Add32
0 LDA #153:STA NM2%
: JSR Div32
D LDA zNum%:STA MP%
N CMP #10
X BPL DDL19
b ADC #3
l STA FDBS%+MN%
v JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
* DEX
4 BPL DDL1D
> .DDL1B
H LDX #3
R LDA #0
\ .DDL20
f STA NM1%,X:STA NM2%,X
p DEX
z BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
$ .DDL22
. STA NM2%,X
8 DEX
B BPL DDL22
L LDA #1:STA NM2%
V JSR Add32
` LDA NM1% :STA FDBS%+DAY%
j RTS
t
.year
~ EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
( BCC ROTATE_R
2 LDA MLR%+4
< CLC
F ADC NM2%
P STA MLR%+4
Z LDA MLR%+5
d ADC NM2%+1
n STA MLR%+5
x LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
" BNE SHIFT_R
, LDX #3
6
.Mul32L2
@ LDA MLR%,X:STA NM1%,X
J DEX
T BPL Mul32L2
^ RTS
h
.Sub32
r PHP
 TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
& .Add32
0 TXA:PHA
: TYA:PHA
D LDY #0
N LDX #4
X CLD
b CLC
l
.Add32L1
v LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll#0:STA zRem%,X
DEX
*
BPL CND
4 LDX #32
>
.Divide
H ASL zNum%
R ROL zNum% + 1
\ ROL zNum% + 2
f ROL zNum% + 3
p ROL zRem%
z ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
$
BCC Next
. INC zNum%
8 LDY #3
B .CpTmpToRem
L LDA zTemp%, Y
V STA zRem% , Y
` DEY
j BPL CpTmpToRem
t .Next
~ DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
( DEX
2 BPL STTI2
< LDA #&2
F LDX #(FDBS%+TIMEVAR%) 256
P LDY #(FDBS%+TIMEVAR%) 256
Z JSR &FFF1
d RTS
n .PrintTime
x JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
" .PrTiL2
, INY
6 CPY #3
@ BNE PrTiL1
J JSR &FFE7
T RTS
^ .PrintDate
h LDA FDBS%+DAY%
r STA NM1%
 JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
& JSR Div32
0$ \ STORE LOWER PART OF YEAR \
: LDA zRem%
D STA STORE%
N JSR ClearNums
X LDA #10
b STA NM2%
l LDA zNum%
v
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
* RTS
4 .ClearNums
>$ \ NM1 and NM2 are in one line \
H LDX #7
R LDA #0
\
.CNL1
f STA NM1%,X
p DEX
z
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
CUMD&SAVE NTP 4D38 53D9 4DA1
DDBS%VR%dLIN%LEC%vLAY%LN%LR%LYS%RA%LOE%VOE%MOY%LP%LNum%LDen%LTemp%Rem%LM1%GYM2%}XLR%XTO
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 SllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllTA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA HrsS,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
$ .DTL1
. LDA STORE%,X:STA NM1%,X
8 LDA DayS,X:STA NM2%,X
B DEX
L
BPL DTL1
V JSR Div32
` \ hours = seconds / 3600 \
j LDX #3
t
.DTL2
~ LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
(! LDA zNum% : STA FDBS% + MIN%
2# LDA zRem% : STA FDBS% + SEC%
< RTS
F
.DayS
P EQUD &00015180
Z
.HrsS
d EQUD &00000E10
n
.YrCr
x EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
" \ era = days / 146097 \
, LDX #3
6 .DDL3
@ LDA NM1%,X:STA DYS%,X
J LDA Yr400,X:STA NM2%,X
T DEX
^ BPL DDL3
h JSR Div32
r LDX #3
 .DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
& LDA c1460,X:STA NM2%,X
0 DEX
:
BPL DDL7
D JSR Div32
N \ doe  doe / 1460 \
X LDX #3
b .DDL8
l LDA zNum%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
* JSR Add32
4 LDX #3
>
.DDLB
H LDA NM1%,X: STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c146096,X:STA NM2%,X
f DEX
p BPL DDLB
z JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
$ .DDLE
. LDA zNum%,X:STA YOE%,X
8 DEX
B
BPL DDLE
L \ era * 400 \
V LDX #3
`
.DDLF
j LDA ERA%,X:STA NM1%,X
t LDA c400,X:STA NM2%,X
~ DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
( .DDL12
2 LDA year,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL12
Z JSR Mul32
d LDX #3
n .DDL13
x LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
" BPL DDL15
, LDA #100:STA NM2%
6 JSR Div32
@ LDX #3
J
.DDL16
T LDA zNum%,X:STA NM2%,X
^ LDA STORE%,X:STA NM1%,X
h DEX
r BPL DDL16
 JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
& JSR Add32
0 LDA #153:STA NM2%
: JSR Div32
D LDA zNum%:STA MP%
N CMP #10
X BPL DDL19
b ADC #3
l STA FDBS%+MN%
v JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
* DEX
4 BPL DDL1D
> .DDL1B
H LDX #3
R LDA #0
\ .DDL20
f STA NM1%,X:STA NM2%,X
p DEX
z BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
$ .DDL22
. STA NM2%,X
8 DEX
B BPL DDL22
L LDA #1:STA NM2%
V JSR Add32
` LDA NM1% :STA FDBS%+DAY%
j RTS
t
.year
~ EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
( BCC ROTATE_R
2 LDA MLR%+4
< CLC
F ADC NM2%
P STA MLR%+4
Z LDA MLR%+5
d ADC NM2%+1
n STA MLR%+5
x LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
" BNE SHIFT_R
, LDX #3
6
.Mul32L2
@ LDA MLR%,X:STA NM1%,X
J DEX
T BPL Mul32L2
^ RTS
h
.Sub32
r PHP
 TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
& .Add32
0 TXA:PHA
: TYA:PHA
D LDY #0
N LDX #4
X CLD
b CLC
l
.Add32L1
v LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllSTA zRem%,X
DEX
*
BPL CND
4 LDX #32
>
.Divide
H ASL zNum%
R ROL zNum% + 1
\ ROL zNum% + 2
f ROL zNum% + 3
p ROL zRem%
z ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
$
BCC Next
. INC zNum%
8 LDY #3
B .CpTmpToRem
L LDA zTemp%, Y
V STA zRem% , Y
` DEY
j BPL CpTmpToRem
t .Next
~ DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
( DEX
2 BPL STTI2
< LDA #&2
F LDX #(FDBS%+TIMEVAR%) 256
P LDY #(FDBS%+TIMEVAR%) 256
Z JSR &FFF1
d RTS
n .PrintTime
x JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
" .PrTiL2
, INY
6 CPY #3
@ BNE PrTiL1
J JSR &FFE7
T RTS
^ .PrintDate
h LDA FDBS%+DAY%
r STA NM1%
 JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
& JSR Div32
0$ \ STORE LOWER PART OF YEAR \
: LDA zRem%
D STA STORE%
N JSR ClearNums
X LDA #10
b STA NM2%
l LDA zNum%
v
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
* RTS
4 .ClearNums
>$ \ NM1 and NM2 are in one line \
H LDX #7
R LDA #0
\
.CNL1
f STA NM1%,X
p DEX
z
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
UMD$SAVE NTP 4D37 53DA 4DA0
DDBS%VR%cLIN%LEC%uLAY%LN%LR%LYS%RA%LOE%VOE%MOY%LP%LNum%LDen%LTemp%Rem%LM1%FYM2%XLR%XTOR
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
"
.DDL16
, LDA zNum%,X:STA NM2%,X
6 LDA STORE%,X:STA NM1%,X
@ DEX
J BPL DDL16
T JSR Sub32
^ LDX #3
h .DDL17
r LDA NM1%,X:STA NM2%,X
 LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
& CMP #10
0 BPL DDL19
: ADC #3
D STA FDBS%+MN%
N JMP DDL1A
X .DDL19
b SBC #9
l STA FDBS%+MN%
v .DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
* LDA #0
4 .DDL20
> STA NM1%,X:STA NM2%,X
H DEX
R BPL DDL20
\ LDA #153:STA NM2%
f LDA MP%: STA NM1%
p JSR Mul32
z LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
$ LDA #1:STA NM2%
. JSR Add32
8 LDA NM1% :STA FDBS%+DAY%
B RTS
L
.year
V EQUD &0000016D
`
.c400
j EQUD &00000190
t .Mul32
~ LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
( STA MLR%+4
2 LDA MLR%+5
< ADC NM2%+1
F STA MLR%+5
P LDA MLR%+6
Z ADC NM2%+2
d STA MLR%+6
n LDA MLR%+7
x ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
" DEX
, BPL Mul32L2
6 RTS
@
.Sub32
J PHP
T TXA:PHA
^ TYA:PHA
h LDX #4
r LDY #0
 CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
& LDX #4
0 CLD
: CLC
D
.Add32L1
N LDA NM1%,Y
X ADC NM2%,Y
b STA NM1%,Y
l INY
v DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
* ROL zNum% + 1
4 ROL zNum% + 2
> ROL zNum% + 3
H ROL zRem%
R ROL zRem% + 1
\ ROL zRem% + 2
f ROL zRem% + 3
p SEC
z .Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
$ LDA zTemp%, Y
. STA zRem% , Y
8 DEY
B BPL CpTmpToRem
L .Next
V DEX
` BNE Divide
j PLA:TAY
t PLA:TAX
~ RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
( LDY #(FDBS%+TIMEVAR%) 256
2 JSR &FFF1
< RTS
F .PrintTime
P JSR ClearNums
Z \ Select page 0 \
d LDA #&93
n
LDX #&FF
x LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
" JSR &FFE7
, RTS
6 .PrintDate
@ LDA FDBS%+DAY%
J STA NM1%
T JSR Conv2d
^
LDA #&2D
h JSR &FFEE
r LDA FDBS%+MN%

STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
& JSR ClearNums
0 LDA #10
: STA NM2%
D LDA zNum%
N
STA NM1%
X \ Conv. upp. part of year \
b JSR Conv2d
l LDA STORE%
v
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
* LDA #0
4
.CNL1
> STA NM1%,X
H DEX
R
BPL CNL1
\ RTS
f ]
p Pass%
z "SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
FSAVE NTP 4C8F 5324 4CF8
DBDBS%VR%KIN%SLEC%KAY%KN%KR%KYS%ARA%KOE%VOE%_LOY%I
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h LDY #0
r JSR GetData
 JSR GetResData
LDA #&94
LDX RSTAT%
JSR &FFF4
CPY #0
BNE ProcLogic
JSR DecodeData
JSR PrintResult
JSR UTCCorr
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR DecoTime
& JSR DecoDate
0 RTS
:
.GetData
D JSR ClearBuff
N JSR UDPConn
X JSR UDPReq
b JSR CloseConn
l RTS
v .ClearBuff
! \ Set page 0 of &FDxx to 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
* STA STORE%+1
4 LDA #CONN 256
> STA STORE%+2
H JMP ConnExec
R .UDPReq
\ LDX #50
f LDA #0
p STA &99
z
.UDPRL1
STA CONN,X
DEX
BPL UDPRL1
LDA #&1B
STA CONN
' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
$ LDA #0
. STA STORE%+2
8 JMP ConnExec
B .CloseConn
L LDA #0:LDX #3
V
.CCL1
` STA STORE%,X
j DEX
t BPL CCL1
~ LDA #14
STA STORE%
\ exec. WiFi command \
.ConnExec
LDX #STORE% 256
LDY #STORE% 256
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
( INX
2 JSR &FFF4
< CPY #("I")
F BNE GRDNRSP
P INX
Z JSR &FFF4
d CPY #("P")
n BNE GRDNRSP
x INX
JSR &FFF4
CPY #("D")
BNE GRDNRSP
JMP GRDL2
.GRDNRSP \ No +IPD string
INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
"$ .GRDL2 \ Now start hunt for :
, JSR &FFF4
6 CPY #(":")
@ BEQ GRDSD
J INX
T& CPX #&80 \ Have we reached vars ?
^ BCC GRDL2
h JMP GRDND
r
.GRDSD
$ \Offset to time in NTP struct \
TXA:CLC:ADC #41:TAX
LDA #&94
JSR &FFF4
STY STORE%+3
INX
JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
& BEQ GRDND
0 RTS
:
.UTCCorr
D& \ UTC Correction must be executed
N \ before any other action
X TXA:PHA
b TYA:PHA
l \ Prepare multi
v LDX #3
.UTCCL1
LDA HrsS,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL UTCCL1
\ Get UTC flag
LDA #&93
LDX #&FF
LDY #1
JSR &FFF4
LDA #&94
LDX #0
JSR &FFF4
CPY #0
BEQ UTCCNULL
BMI UTCCNEG
LDA #&95
* LDX #1
4
LDY #&10
> JSR &FFF4
H JMP UTCCEND
R
.UTCCNEG
\ LDA #&95
f LDX #1
p
LDY #&20
z JSR &FFF4
JMP UTCCEND
.UTCCNULL
LDA #&95
LDX #1
LDY #&40
JSR &FFF4
.UTCCEND
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
$
BPL DTL1
. JSR Div32
8 \ hours = seconds / 3600 \
B LDX #3
L
.DTL2
V LDA zNum%,X:STA DAYT%,X
` LDA zRem%,X:STA NM1%,X
j" \ To be used to set value
t% LDA zRem%,X:STA &FD00+TIMEVAR%,X
~ LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
( EQUD &00015180
2
.HrsS
< EQUD &00000E10
F
.YrCr
P EQUD &000A968D
Z .Yr400
d EQUD &00023AB1
n .c1460
x EQUD &000005B4
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll .c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
" LDA Yr400,X:STA NM2%,X
, DEX
6 BPL DDL3
@ JSR Div32
J LDX #3
T .DDL5
^ LDA zNum%,X:STA ERA%,X
h LDA zNum%,X:STA NM1%,X
r DEX

BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
& \ doe  doe / 1460 \
0 LDX #3
: .DDL8
D LDA zNum%,X:STA NM2%,X
N LDA DOE%,X:STA NM1%,X
X DEX
b BPL DDL8
l JSR Sub32
v LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
* LDA DOE%,X:STA NM1%,X
4 LDA c146096,X:STA NM2%,X
> DEX
H BPL DDLB
R JSR Div32
\* \ doedoe/1460+doe/36524doe/146096 \
f LDX #3
p
.DDLC
z LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
$ \ era * 400 \
. LDX #3
8
.DDLF
B LDA ERA%,X:STA NM1%,X
L LDA c400,X:STA NM2%,X
V DEX
`
BPL DDLF
j JSR Mul32
t \ yoe + era * 400 \
~ LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
( BPL DDL12
2 JSR Mul32
< LDX #3
F .DDL13
P LDA YOE%,X:STA NM2%,X:DEX
Z BPL DDL13
d LDX #1
n .DDL14
x LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
"
.DDL16
, LDA zNum%,X:STA NM2%,X
6 LDA STORE%,X:STA NM1%,X
@ DEX
J BPL DDL16
T JSR Sub32
^ LDX #3
h .DDL17
r LDA NM1%,X:STA NM2%,X
 LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
& CMP #10
0 BPL DDL19
: ADC #3
D STA FDBS%+MN%
N JMP DDL1A
X .DDL19
b SBC #9
l STA FDBS%+MN%
v .DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
* LDA #0
4 .DDL20
> STA NM1%,X:STA NM2%,X
H DEX
R BPL DDL20
\ LDA #153:STA NM2%
f LDA MP%: STA NM1%
p JSR Mul32
z LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
$ LDA #1:STA NM2%
. JSR Add32
8 LDA NM1% :STA FDBS%+DAY%
B RTS
L
.year
V EQUD &0000016D
`
.c400
j EQUD &00000190
t .Mul32
~ LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
( STA MLR%+4
2 LDA MLR%+5
< ADC NM2%+1
F STA MLR%+5
P LDA MLR%+6
Z ADC NMllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll2%+2
d STA MLR%+6
n LDA MLR%+7
x ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
" DEX
, BPL Mul32L2
6 RTS
@
.Sub32
J PHP
T TXA:PHA
^ TYA:PHA
h LDX #4
r LDY #0
 CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
& LDX #4
0 CLD
: CLC
D
.Add32L1
N LDA NM1%,Y
X ADC NM2%,Y
b STA NM1%,Y
l INY
v DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
* ROL zNum% + 1
4 ROL zNum% + 2
> ROL zNum% + 3
H ROL zRem%
R ROL zRem% + 1
\ ROL zRem% + 2
f ROL zRem% + 3
p SEC
z .Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
$ LDA zTemp%, Y
. STA zRem% , Y
8 DEY
B BPL CpTmpToRem
L .Next
V DEX
` BNE Divide
j PLA:TAY
t PLA:TAX
~ RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
( LDY #(FDBS%+TIMEVAR%) 256
2 JSR &FFF1
< RTS
F .PrintTime
P JSR ClearNums
Z \ Select page 0 \
d LDA #&93
n
LDX #&FF
x LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
" JSR &FFE7
, RTS
6 .PrintDate
@ LDA FDBS%+DAY%
J STA NM1%
T JSR Conv2d
^
LDA #&2D
h JSR &FFEE
r LDA FDBS%+MN%

STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
& JSR ClearNums
0 LDA #10
: STA NM2%
D LDA zNum%
N
STA NM1%
X \ Conv. upp. part of year \
b JSR Conv2d
l LDA STORE%
v
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
* LDA #0
4
.CNL1
> STA NM1%,X
H DEX
R
BPL CNL1
\ RTS
f ]
p Pass%
z "SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
lTMDSAVE NTP 4C90 5325 4CF9
B
DBDBS%VR%KIN%TLEC%KAY%LN%KR%KYS%RA%KOE%VOE%`LOY%
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll"0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA MLR%,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
$ LDY #0
. JSR &FFF4
8 PLA:TAY
B PLA:TAX
L RTS
V .DecoTime
` LDX #3
j .DTL1
t LDA STORE%,X:STA NM1%,X
~ LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
(
.DTL3
2 LDA zRem%,X:STA NM1%,X
< LDA #0:STA NM2%,X
F DEX
P
BPL DTL3
Z LDA #&3C:STA NM2%
d JSR Div32
n! LDA zNum% : STA FDBS% + MIN%
x# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllB4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
" LDX #3
, .DDL1
6 LDA DAYT%,X:STA NM1%,X
@ LDA YrCr,X:STA NM2%,X
J DEX
T BPL DDL1
^ JSR Add32
h \ era = days / 146097 \
r LDX #3
 .DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
& LDA DYS%,X:STA NM1%,X
0 DEX
: BPL DDL6
D JSR Sub32
N LDX #3
X .DDL7
b LDA NM1%,X:STA DOE%,X
l LDA c1460,X:STA NM2%,X
v DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
* JSR Div32
4 LDX #3
> .DDLA
H LDA zNum%,X:STA NM1%,X
R LDA STORE%,X:STA NM2%,X
\ DEX
f BPL DDLA
p JSR Add32
z LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
$ .DDLD
. LDA year,X:STA NM2%,X
8 DEX
B BPL DDLD
L JSR Div32
V \ Store result in YOE% \
` LDX #3
j .DDLE
t LDA zNum%,X:STA YOE%,X
~ DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
( JSR Add32
2 LDX #3
< .DDL11
F! LDA NM1%,X:STA FDBS% + YR%,X
P DEX
Z BPL DDL11
d LDX #3
n .DDL12
x LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
" JSR Add32
, LDX #3
6 .DDL15
@ LDA NM1%,X:STA STORE%,X
J LDA #0:STA NM2%,X
T LDA YOE%,X:STA NM1%,X
^ DEX
h BPL DDL15
r LDA #100:STA NM2%
 JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
& LDA NM1%,X:STA DOY%,X
0 LDA #0:STA NM2%,X
: DEX
D BPL DDL18
N LDA #5:STA NM2%
X JSR Mul32
b LDA #2:STA NM2%
l JSR Add32
v LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
* DEX
4 BPL DDL1C
> LDA #1:STA NM2%
H JSR Add32
R LDX #3
\ .DDL1D
f LDA NM1%,X:STA FDBS%+YR%,X
p DEX
z BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
$ LDA zNum%,X:STA NM2%,X
. LDA DOY%,X:STA NM1%,X
8 DEX
B BPL DDL21
L JSR Sub32
V LDX #3
` LDA #0
j .DDL22
t STA NM2%,X
~ DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
(
.Mul32L1
2 LDA NM1%,X:STA MLR%,X
< DEX
F BPL Mul32L1
P
LDX #&21
Z BNE START_R
d
.SHIFT_R
n BCC ROTATE_R
x LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
AllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllDC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
" ROR MLR%+4
, .START_R
6 ROR MLR%+3
@ ROR MLR%+2
J ROR MLR%+1
T
ROR MLR%
^ DEX
h BNE SHIFT_R
r LDX #3

.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
& INY
0 DEX
: BNE Sub32L1
D PLA:TAY
N
PLA:TAX
X PLP
b RTS
l .Add32
v TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
* TYA:PHA
4 LDX #3
> .CND
H LDA NM1%,X:STA zNum%,X
R LDA NM2%,X:STA zDen%,X
\ LDA #0:STA zRem%,X
f DEX
p
BPL CND
z LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
$ STA zTemp% + 1
. LDA zRem% + 2
8 SBC zDen% + 2
B STA zTemp% + 2
L LDA zRem% + 3
V SBC zDen% + 3
` STA zTemp% + 3
j
BCC Next
t INC zNum%
~ LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
( DEX
2 BPL STTI1
< LDA #100:STA NM1%
F JSR Mul32
P LDX #3
Z .STTI2
d$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
n DEX
x BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
" LDA FDBS% + HR%,Y
,
STA NM1%
6 JSR Conv2d
@ LDA #&3A
J CPY #2
T BEQ PrTiL2
^ JSR &FFEE
h .PrTiL2
r INY
 CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
&
STA NM2%
0 LDX #3
:
.PDL1
D LDA FDBS%+YR%,X
N STA NM1%,X
X DEX
b BPL PDL1
l JSR Div32
v$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
* CLC
4
ADC #&30
> JSR &FFEE
H LDA zRem%
R CLC
\ ADC #&30
f JSR &FFEE
p RTS
z .ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
(2<FPZdnx",6@JT^hr&0:DNXblv
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll"0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
\LDA #&93 \
\LDX #&FF \
\LDY #0 \
\JSR &FFF4 \
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
* JSR Mul32
4 LDX #3
> .UTCL2
H LDA STORE%,X:STA NM1%,X
R LDA MLR%,X:STA NM2%,X
\ DEX
f BPL UTCL2
p JSR Add32
z LDX #3
.UTCL3
LDA NM1%,X:STA STORE%,X
DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
\LDA #&93 \
\LDX #&FF \
\LDY #0 \
\JSR &FFF4 \
JSR SelPZ
PLA:TAY
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
$ LDY #0
. JSR &FFF4
8 PLA:TAY
B PLA:TAX
L RTS
V .SelPZ
` \ Select page 0
j \ Reg X,Y and A preserved
t TXA:PHA
~ TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
( JSR Div32
2 \ hours = seconds / 3600 \
< LDX #3
F
.DTL2
P LDA zNum%,X:STA DAYT%,X
Z LDA zRem%,X:STA NM1%,X
d" \ To be used to set value
n% LDA zRem%,X:STA &FD00+TIMEVAR%,X
x LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
" EQUD &00015180
,
.HrsS
6 EQUD &00000E10
@
.YrCr
J EQUD &000A968D
T .Yr400
^ EQUD &00023AB1
h .c1460
r EQUD &000005B4
 .c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
& DEX
0 BPL DDL3
: JSR Div32
D LDX #3
N .DDL5
X LDA zNum%,X:STA ERA%,X
b LDA zNum%,X:STA NM1%,X
l DEX
v
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
* LDX #3
4 .DDL8
> LDA zNum%,X:STA NM2%,X
H LDA DOE%,X:STA NM1%,X
R DEX
\ BPL DDL8
f JSR Sub32
p LDX #3
z .DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
$ LDA DOE%,X:STA NM1%,X
. LDA c146096,X:STA NM2%,X
8 DEX
B BPL DDLB
L JSR Div32
V* \ doedoe/1460+doe/36524doe/146096 \
` LDX #3
j
.DDLC
t LDA STORE%,X:STA NM1%,X
~ LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
( LDX #3
2
.DDLF
< LDA ERA%,X:STA NM1%,X
F LDA c400,X:STA NM2%,X
P DEX
Z
BPL DDLF
d JSR Mul32
n \ yoe + era * 400 \
x LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
" BPL DDL12
, JSR Mul32
6 LDX #3
@ .DDL13
J LDA YOE%,X:STA NM2%,X:DEX
T BPL DDL13
^ LDX #1
h .DDL14
r LSR NM2%+3
 ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
& LDA zNum%,X:STA NM2%,X
0 LDA STORE%,X:STA NM1%,X
: DEX
D BPL DDL16
N JSR Sub32
X LDX #3
b .DDL17
l LDA NM1%,X:STA NM2%,X
v LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
* BPL DDL19
4 ADC #3
> STA FDBS%+MN%
H JMP DDL1A
R .DDL19
\ SBC #9
f STA FDBS%+MN%
p .DDL1A
z CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
$ LDA #0
. .DDL20
8 STA NM1%,X:STA NM2%,X
B DEX
L BPL DDL20
V LDA #153:STA NM2%
` LDA MP%: STA NM1%
j JSR Mul32
t LDA #2:STA NM2%
~ JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
( JSR Add32
2 LDA NM1% :STA FDBS%+DAY%
< RTS
F
.year
P EQUD &0000016D
Z
.c400
d EQUD &00000190
n .Mul32
x LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
" STA MLR%+4
, LDA MLR%+5
6 ADC NM2%+1
@ STA MLR%+5
J LDA MLR%+6
T ADC NM2%+2
^ STA MLR%+6
h LDA MLR%+7
r ADC NM2%+3
 STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
& BPL Mul32L2
0 RTS
:
.Sub32
D PHP
N TXA:PHA
X TYA:PHA
b LDX #4
l LDY #0
v CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
* CLD
4 CLC
>
.Add32L1
H LDA NM1%,Y
R ADC NM2%,Y
\ STA NM1%,Y
f INY
p DEX
z BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
$ ROL zNum% + 1
. ROL zNum% + 2
8 ROL zNum% + 3
B ROL zRem%
L ROL zRem% + 1
V ROL zRem% + 2
` ROL zRem% + 3
j SEC
t .Subtract
~ LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
( STA zRem% , Y
2 DEY
< BPL CpTmpToRem
F .Next
P DEX
Z BNE Divide
d PLA:TAY
n PLA:TAX
x RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
" LDY #(FDBS%+TIMEVAR%) 256
, JSR &FFF1
6 RTS
@ .PrintTime
J JSR ClearNums
T \ Select page 0 \
^ LDA #&93
h
LDX #&FF
r LDY #0
 JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
& RTS
0 .PrintDate
: LDA FDBS%+DAY%
D STA NM1%
N JSR Conv2d
X
LDA #&2D
b JSR &FFEE
l LDA FDBS%+MN%
v
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
* LDA #10
4 STA NM2%
> LDA zNum%
H
STA NM1%
R \ Conv. upp. part of year \
\ JSR Conv2d
f LDA STORE%
p
STA NM1%
z JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
$ LDA #0
.
.CNL1
8 STA NM1%,X
B DEX
L
BPL CNL1
V RTS
` ]
j Pass%
t "SIZE : " +(P%PROG%)
~H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
7",6@JT^hr&0:DNXblv *4>HR\fpz$.8BLV`
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
" LDA #&93 \ Set back to page 0
LDX #&FF
LDY #0
JSR &FFF4
PLA:TAY
PLA:TAX
RTS
.SelPZ
$ \ Select page 0
. \ Reg X,Y and A preserved
8 TXA:PHA
B TYA:PHA
L PHA
V
LDA #&93
`
LDX #&FF
j LDY #0
t JSR &FFF4
~ PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
(" \ To be used to set value
2% LDA zRem%,X:STA &FD00+TIMEVAR%,X
< LDA HrsS,X:STA NM2%,X
F DEX
P BPL DTL2
Z JSR Div32
d LDA zNum%:STA FllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllDBS% + HR%
n LDX #3
x
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
" EQUD &00023AB1
, .c1460
6 EQUD &000005B4
@ .c36524
J EQUD &00008EAC
T
.c146096
^ EQUD &00023AB0
h .DecoDate
r LDX #3
 .DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
& LDA zNum%,X:STA NM1%,X
0 DEX
:
BPL DDL5
D JSR Mul32
N \ days  era * 146097 \
X LDX #3
b .DDL6
l LDA MLR%,X:STA NM2%,X
v LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
* JSR Sub32
4 LDX #3
> .DDL9
H LDA NM1%,X:STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c36524,X:STA NM2%,X
f DEX
p
BPL DDL9
z JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
$ LDX #3
.
.DDLC
8 LDA STORE%,X:STA NM1%,X
B LDA zNum%,X:STA NM2%,X
L DEX
V
BPL DDLC
` JSR Sub32
j LDX #3
t .DDLD
~ LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
( JSR Mul32
2 \ yoe + era * 400 \
< LDX #3
F .DDL10
P LDA MLR%,X:STA NM1%,X
Z LDA YOE%,X:STA NM2%,X
d DEX
n BPL DDL10
x JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
" LDX #1
, .DDL14
6 LSR NM2%+3
@ ROR NM2%+2
J ROR NM2%+1
T ROR NM2%
^ DEX
h BPL DDL14
r JSR Add32
 LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
& .DDL17
0 LDA NM1%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL17
X JSR Sub32
b LDX #3
l .DDL18
v LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
* STA FDBS%+MN%
4 .DDL1A
> CMP #3
H BPL DDL1B
R LDX #3
\ .DDL1C
f! LDA FDBS% + YR%,X:STA NM1%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
$ LDA MP%: STA NM1%
. JSR Mul32
8 LDA #2:STA NM2%
B JSR Add32
L LDA #5:STA NM2%
V JSR Div32
` LDX #3
j .DDL21
t LDA zNum%,X:STA NM2%,X
~ LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c40llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll0
( EQUD &00000190
2 .Mul32
< LDA #0
F STA MLR%+4
P STA MLR%+5
Z STA MLR%+6
d STA MLR%+7
n LDX #3
x
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
" STA MLR%+6
, LDA MLR%+7
6 ADC NM2%+3
@ STA MLR%+7
J .ROTATE_R
T
ROR A
^ ROR MLR%+6
h ROR MLR%+5
r ROR MLR%+4
 .START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
& LDX #4
0 LDY #0
: CLD
D SEC
N
.Sub32L1
X LDA NM1%,Y
b SBC NM2%,Y
l STA NM1%,Y
v INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
* INY
4 DEX
> BNE Add32L1
H PLA:TAY
R PLA:TAX
\ RTS
f .Div32
p TXA:PHA
z TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
$ ROL zRem% + 3
. SEC
8 .Subtract
B LDA zRem%
L SBC zDen%
V STA zTemp%
` LDA zRem% + 1
j SBC zDen% + 1
t STA zTemp% + 1
~ LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
( PLA:TAY
2 PLA:TAX
< RTS
F .StoreToTIME
P LDX #3
Z .STTI1
d LDA #0:STA NM1%,X
n% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
x DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
" LDA #&93
,
LDX #&FF
6 LDY #0
@ JSR &FFF4
J LDY #0
T
LDA #10
^ STA NM2%
h .PrTiL1
r LDA FDBS% + HR%,Y

STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
& JSR &FFEE
0 LDA FDBS%+MN%
:
STA NM1%
D JSR Conv2d
N LDA #&2D
X JSR &FFEE
b# \ Year printing is different \
l
LDA #100
v
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
* LDA STORE%
4
STA NM1%
> JSR Conv2d
H JSR &FFE7
R RTS
\ .Conv2d
f JSR Div32
p LDA zNum%
z CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
$ ]
. Pass%
8 "SIZE : " +(P%PROG%)
BH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
L Y% = CMD 256
V X% = CMD 256
` &FFF7
j $CMD
(2<FPZdnx
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
\LDA #&93\
\LDX #&FF\
\LDY #0\
\JSR &FFF4 \
PLA:TAY
PLA:TAX
RTS
.SelPZ
$ \ Select page 0
. \ Reg X,Y and A preserved
8 TXA:PHA
B TYA:PHA
L PHA
V
LDA #&93
`
LDX #&FF
j LDY #0
t JSR &FFF4
~ PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
(" \ To be used to set value
2% LDA zRem%,X:STA &FD00+TIMEVAR%,X
< LDA HrsS,X:STA NM2%,X
F DEX
P BPL DTL2
Z JSR Div32
d LDA zNum%:STA FDBS% + HR%
lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllln LDX #3
x
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
" EQUD &00023AB1
, .c1460
6 EQUD &000005B4
@ .c36524
J EQUD &00008EAC
T
.c146096
^ EQUD &00023AB0
h .DecoDate
r LDX #3
 .DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
& LDA zNum%,X:STA NM1%,X
0 DEX
:
BPL DDL5
D JSR Mul32
N \ days  era * 146097 \
X LDX #3
b .DDL6
l LDA MLR%,X:STA NM2%,X
v LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
* JSR Sub32
4 LDX #3
> .DDL9
H LDA NM1%,X:STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c36524,X:STA NM2%,X
f DEX
p
BPL DDL9
z JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
$ LDX #3
.
.DDLC
8 LDA STORE%,X:STA NM1%,X
B LDA zNum%,X:STA NM2%,X
L DEX
V
BPL DDLC
` JSR Sub32
j LDX #3
t .DDLD
~ LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
( JSR Mul32
2 \ yoe + era * 400 \
< LDX #3
F .DDL10
P LDA MLR%,X:STA NM1%,X
Z LDA YOE%,X:STA NM2%,X
d DEX
n BPL DDL10
x JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
" LDX #1
, .DDL14
6 LSR NM2%+3
@ ROR NM2%+2
J ROR NM2%+1
T ROR NM2%
^ DEX
h BPL DDL14
r JSR Add32
 LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
& .DDL17
0 LDA NM1%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL17
X JSR Sub32
b LDX #3
l .DDL18
v LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
* STA FDBS%+MN%
4 .DDL1A
> CMP #3
H BPL DDL1B
R LDX #3
\ .DDL1C
f! LDA FDBS% + YR%,X:STA NM1%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
$ LDA MP%: STA NM1%
. JSR Mul32
8 LDA #2:STA NM2%
B JSR Add32
L LDA #5:STA NM2%
V JSR Div32
` LDX #3
j .DDL21
t LDA zNum%,X:STA NM2%,X
~ LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
( EQUD &llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll00000190
2 .Mul32
< LDA #0
F STA MLR%+4
P STA MLR%+5
Z STA MLR%+6
d STA MLR%+7
n LDX #3
x
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
" STA MLR%+6
, LDA MLR%+7
6 ADC NM2%+3
@ STA MLR%+7
J .ROTATE_R
T
ROR A
^ ROR MLR%+6
h ROR MLR%+5
r ROR MLR%+4
 .START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
& LDX #4
0 LDY #0
: CLD
D SEC
N
.Sub32L1
X LDA NM1%,Y
b SBC NM2%,Y
l STA NM1%,Y
v INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
* INY
4 DEX
> BNE Add32L1
H PLA:TAY
R PLA:TAX
\ RTS
f .Div32
p TXA:PHA
z TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
$ ROL zRem% + 3
. SEC
8 .Subtract
B LDA zRem%
L SBC zDen%
V STA zTemp%
` LDA zRem% + 1
j SBC zDen% + 1
t STA zTemp% + 1
~ LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
( PLA:TAY
2 PLA:TAX
< RTS
F .StoreToTIME
P LDX #3
Z .STTI1
d LDA #0:STA NM1%,X
n% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
x DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
" LDA #&93
,
LDX #&FF
6 LDY #0
@ JSR &FFF4
J LDY #0
T
LDA #10
^ STA NM2%
h .PrTiL1
r LDA FDBS% + HR%,Y

STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
& JSR &FFEE
0 LDA FDBS%+MN%
:
STA NM1%
D JSR Conv2d
N LDA #&2D
X JSR &FFEE
b# \ Year printing is different \
l
LDA #100
v
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
* LDA STORE%
4
STA NM1%
> JSR Conv2d
H JSR &FFE7
R RTS
\ .Conv2d
f JSR Div32
p LDA zNum%
z CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
$ ]
. Pass%
8 "SIZE : " +(P%PROG%)
BH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
L Y% = CMD 256
V X% = CMD 256
` &FFF7
j $CMD
7j $CMD
UMDSAVE NTP 4E00 54BA 4E69
DBS%
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA \ Store Y on stack
JSR SelPZ
PLA:TAY \ Restore Y
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
\LDA #&93\
\LDX #&FF\
\LDY #0\
\JSR &FFF4 \
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.SelPZ
$ \ Select page 0
. \ Reg X,Y and A preserved
8 TXA:PHA
B TYA:PHA
L PHA
V
LDA #&93
`
LDX #&FF
j LDY #0
t JSR &FFF4
~ PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
(" \ To be used to set value
2% LDA zRem%,X:STA &FD00+TIMEVAR%,X
< LDA HrsS,X:STA NM2%,X
F DEX
P BPL DTL2
Z JSR Div32
d LDA zNum%:STllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllA FDBS% + HR%
n LDX #3
x
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
" EQUD &00023AB1
, .c1460
6 EQUD &000005B4
@ .c36524
J EQUD &00008EAC
T
.c146096
^ EQUD &00023AB0
h .DecoDate
r LDX #3
 .DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
& LDA zNum%,X:STA NM1%,X
0 DEX
:
BPL DDL5
D JSR Mul32
N \ days  era * 146097 \
X LDX #3
b .DDL6
l LDA MLR%,X:STA NM2%,X
v LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
* JSR Sub32
4 LDX #3
> .DDL9
H LDA NM1%,X:STA STORE%,X
R LDA DOE%,X:STA NM1%,X
\ LDA c36524,X:STA NM2%,X
f DEX
p
BPL DDL9
z JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
$ LDX #3
.
.DDLC
8 LDA STORE%,X:STA NM1%,X
B LDA zNum%,X:STA NM2%,X
L DEX
V
BPL DDLC
` JSR Sub32
j LDX #3
t .DDLD
~ LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
( JSR Mul32
2 \ yoe + era * 400 \
< LDX #3
F .DDL10
P LDA MLR%,X:STA NM1%,X
Z LDA YOE%,X:STA NM2%,X
d DEX
n BPL DDL10
x JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
" LDX #1
, .DDL14
6 LSR NM2%+3
@ ROR NM2%+2
J ROR NM2%+1
T ROR NM2%
^ DEX
h BPL DDL14
r JSR Add32
 LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
& .DDL17
0 LDA NM1%,X:STA NM2%,X
: LDA DOE%,X:STA NM1%,X
D DEX
N BPL DDL17
X JSR Sub32
b LDX #3
l .DDL18
v LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
* STA FDBS%+MN%
4 .DDL1A
> CMP #3
H BPL DDL1B
R LDX #3
\ .DDL1C
f! LDA FDBS% + YR%,X:STA NM1%,X
p LDA #0:STA NM2%,X
z DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
$ LDA MP%: STA NM1%
. JSR Mul32
8 LDA #2:STA NM2%
B JSR Add32
L LDA #5:STA NM2%
V JSR Div32
` LDX #3
j .DDL21
t LDA zNum%,X:STA NM2%,X
~ LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllc400
( EQUD &00000190
2 .Mul32
< LDA #0
F STA MLR%+4
P STA MLR%+5
Z STA MLR%+6
d STA MLR%+7
n LDX #3
x
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
" STA MLR%+6
, LDA MLR%+7
6 ADC NM2%+3
@ STA MLR%+7
J .ROTATE_R
T
ROR A
^ ROR MLR%+6
h ROR MLR%+5
r ROR MLR%+4
 .START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
& LDX #4
0 LDY #0
: CLD
D SEC
N
.Sub32L1
X LDA NM1%,Y
b SBC NM2%,Y
l STA NM1%,Y
v INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
* INY
4 DEX
> BNE Add32L1
H PLA:TAY
R PLA:TAX
\ RTS
f .Div32
p TXA:PHA
z TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
$ ROL zRem% + 3
. SEC
8 .Subtract
B LDA zRem%
L SBC zDen%
V STA zTemp%
` LDA zRem% + 1
j SBC zDen% + 1
t STA zTemp% + 1
~ LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
( PLA:TAY
2 PLA:TAX
< RTS
F .StoreToTIME
P LDX #3
Z .STTI1
d LDA #0:STA NM1%,X
n% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
x DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
" LDA #&93
,
LDX #&FF
6 LDY #0
@ JSR &FFF4
J LDY #0
T
LDA #10
^ STA NM2%
h .PrTiL1
r LDA FDBS% + HR%,Y

STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
& JSR &FFEE
0 LDA FDBS%+MN%
:
STA NM1%
D JSR Conv2d
N LDA #&2D
X JSR &FFEE
b# \ Year printing is different \
l
LDA #100
v
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
* LDA STORE%
4
STA NM1%
> JSR Conv2d
H JSR &FFE7
R RTS
\ .Conv2d
f JSR Div32
p LDA zNum%
z CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
$ ]
. Pass%
8 "SIZE : " +(P%PROG%)
BH $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
L Y% = CMD 256
V X% = CMD 256
` &FFF7
j $CMD
TP 4DF4 54A5 4E5D
0 54BA 4DBS%WR%
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
TXA:PHA
$ TYA:PHA
. PHA
8
LDA #&93
B
LDX #&FF
L LDY #0
V JSR &FFF4
` PLA
j
PLA:TAY
t PLA:TAX
~ RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
( DEX
2 BPL DTL2
< JSR Div32
F LDA zNum%:STA FDBS% + HR%
P LDX #3
Z
.DTL3
d LDA zRem%,X:STA NM1%,X
n LDA #0:STA NM2%,X
x llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllDEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
" .c36524
, EQUD &00008EAC
6
.c146096
@ EQUD &00023AB0
J .DecoDate
T LDX #3
^ .DDL1
h LDA DAYT%,X:STA NM1%,X
r LDA YrCr,X:STA NM2%,X
 DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
& JSR Mul32
0 \ days  era * 146097 \
: LDX #3
D .DDL6
N LDA MLR%,X:STA NM2%,X
X LDA DYS%,X:STA NM1%,X
b DEX
l BPL DDL6
v JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
* LDA NM1%,X:STA STORE%,X
4 LDA DOE%,X:STA NM1%,X
> LDA c36524,X:STA NM2%,X
H DEX
R
BPL DDL9
\ JSR Div32
f LDX #3
p .DDLA
z LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
$ LDA zNum%,X:STA NM2%,X
. DEX
8
BPL DDLC
B JSR Sub32
L LDX #3
V .DDLD
` LDA year,X:STA NM2%,X
j DEX
t BPL DDLD
~ JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
( .DDL10
2 LDA MLR%,X:STA NM1%,X
< LDA YOE%,X:STA NM2%,X
F DEX
P BPL DDL10
Z JSR Add32
d LDX #3
n .DDL11
x! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
" ROR NM2%+2
, ROR NM2%+1
6 ROR NM2%
@ DEX
J BPL DDL14
T JSR Add32
^ LDX #3
h .DDL15
r LDA NM1%,X:STA STORE%,X
 LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
& DEX
0 BPL DDL17
: JSR Sub32
D LDX #3
N .DDL18
X LDA NM1%,X:STA DOY%,X
b LDA #0:STA NM2%,X
l DEX
v BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
CMP #10
BPL DDL19
ADC #3
STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
* BPL DDL1B
4 LDX #3
> .DDL1C
H! LDA FDBS% + YR%,X:STA NM1%,X
R LDA #0:STA NM2%,X
\ DEX
f BPL DDL1C
p LDA #1:STA NM2%
z JSR Add32
LDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
LDX #3
LDA #0
.DDL20
STA NM1%,X:STA NM2%,X
DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
$ JSR Add32
. LDA #5:STA NM2%
8 JSR Div32
B LDX #3
L .DDL21
V LDA zNum%,X:STA NM2%,X
` LDA DOY%,X:STA NM1%,X
j DEX
t BPL DDL21
~ JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
LDA #1:STA NM2%
JSR Add32
LDA NM1% :STA FDBS%+DAY%
RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
( STA MLR%+4
2 STA MLR%+5
< STA MLR%+6llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
F STA MLR%+7
P LDX #3
Z
.Mul32L1
d LDA NM1%,X:STA MLR%,X
n DEX
x BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
ADC NM2%
STA MLR%+4
LDA MLR%+5
ADC NM2%+1
STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
" STA MLR%+7
, .ROTATE_R
6
ROR A
@ ROR MLR%+6
J ROR MLR%+5
T ROR MLR%+4
^ .START_R
h ROR MLR%+3
r ROR MLR%+2
 ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
DEX
BPL Mul32L2
RTS
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
& SEC
0
.Sub32L1
: LDA NM1%,Y
D SBC NM2%,Y
N STA NM1%,Y
X INY
b DEX
l BNE Sub32L1
v PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
LDX #4
CLD
CLC
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
* PLA:TAY
4 PLA:TAX
> RTS
H .Div32
R TXA:PHA
\ TYA:PHA
f LDX #3
p .CND
z LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
ASL zNum%
ROL zNum% + 1
ROL zNum% + 2
ROL zNum% + 3
ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
$ LDA zRem%
. SBC zDen%
8 STA zTemp%
B LDA zRem% + 1
L SBC zDen% + 1
V STA zTemp% + 1
` LDA zRem% + 2
j SBC zDen% + 2
t STA zTemp% + 2
~ LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
LDA zTemp%, Y
STA zRem% , Y
DEY
BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
( .StoreToTIME
2 LDX #3
< .STTI1
F LDA #0:STA NM1%,X
P% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
Z DEX
d BPL STTI1
n LDA #100:STA NM1%
x JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
LDX #(FDBS%+TIMEVAR%) 256
LDY #(FDBS%+TIMEVAR%) 256
JSR &FFF1
RTS
.PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
" JSR &FFF4
, LDY #0
6
LDA #10
@ STA NM2%
J .PrTiL1
T LDA FDBS% + HR%,Y
^
STA NM1%
h JSR Conv2d
r LDA #&3A
 CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
JSR &FFE7
RTS
.PrintDate
LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
& JSR Conv2d
0 LDA #&2D
: JSR &FFEE
D# \ Year printing is different \
N
LDA #100
X
STA NM2%
b LDX #3
l
.PDL1
v LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
JSR ClearNums
LDA #10
STA NM2%
LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
* JSR &FFE7
4 RTS
> .Conv2d
H JSR Div32
R LDA zNum%
\ CLC
f
ADC #&30
p JSR &FFEE
z LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
LDX #7
LDA #0
.CNL1
STA NM1%,X
DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
$H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
. Y% = CMD 256
8 X% = CMD 256
B &FFF7
L $CMD
(2<FPZdnx",6@JT^hr&0:DNXblv
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
LDX #3
.UTCL1
LDA HrsS,X:STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL UTCL1
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
$ TXA:PHA
. PHA
8 LDX #3
B .STZE1
L LDA HrsS,X : STA NM1%,X
V LDA #0: STA NM2%,X
` DEX
j BPL STZE1
t PLA
~ PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
TXA:PHA
TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
( LDX #3
2 .DTL1
< LDA STORE%,X:STA NM1%,X
F LDA DayS,X:STA NM2%,X
P DEX
Z
BPL DTL1
d JSR Div32
n \ hours = seconds / 3600 \
x LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
" LDA #&3C:STA NM2%
, JSR Div32
6! LDA zNum% : STA FDBS% + MIN%
@# LDA zRem% : STA FDBS% + SEC%
J RTS
T
.DayS
^ EQUD &00015180
h
.HrsS
r EQUD &00000E10

.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
& JSR Add32
0 \ era = days / 146097 \
: LDX #3
D .DDL3
N LDA NM1%,X:STA DYS%,X
X LDA Yr400,X:STA NM2%,X
b DEX
l BPL DDL3
v JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
* LDA NM1%,X:STA DOE%,X
4 LDA c1460,X:STA NM2%,X
> DEX
H
BPL DDL7
R JSR Div32
\ \ doe  doe / 1460 \
f LDX #3
p .DDL8
z LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
$ DEX
. BPL DDLA
8 JSR Add32
B LDX #3
L
.DDLB
V LDA NM1%,X: STA STORE%,X
` LDA DOE%,X:STA NM1%,X
j LDA c146096,X:STA NM2%,X
t DEX
~ BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
( LDX #3
2 .DDLE
< LDA zNum%,X:STA YOE%,X
F DEX
P
BPL DDLE
Z \ era * 400 \
d LDX #3
n
.DDLF
x LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
" BPL DDL11
, LDX #3
6 .DDL12
@ LDA year,X:STA NM1%,X
J LDA YOE%,X:STA NM2%,X
T DEX
^ BPL DDL12
h JSR Mul32
r LDX #3
 .DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
& DEX
0 BPL DDL15
: LDA #100:STA NM2%
D JSR Div32
N LDX #3
X
.DDL16
b LDA zNum%,X:STA NM2%,X
l LDA STORE%,X:STA NM1%,X
v DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
* LDA #2:STA NM2%
4 JSR Add32
> LDA #153:STA NM2%
H JSR Div32
R LDA zNum%:STA MP%
\ CMP #10
f BPL DDL19
p ADC #3
z STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
$ .DDL1D
. LDA NM1%,X:STA FDBS%+YR%,X
8 DEX
B BPL DDL1D
L .DDL1B
V LDX #3
` LDA #0
j .DDL20
t STA NM1%,X:STA NM2%,X
~ DEX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
( LDA #0
2 llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll.DDL22
< STA NM2%,X
F DEX
P BPL DDL22
Z LDA #1:STA NM2%
d JSR Add32
n LDA NM1% :STA FDBS%+DAY%
x RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
" BNE START_R
,
.SHIFT_R
6 BCC ROTATE_R
@ LDA MLR%+4
J CLC
T ADC NM2%
^ STA MLR%+4
h LDA MLR%+5
r ADC NM2%+1
 STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
& DEX
0 BNE SHIFT_R
: LDX #3
D
.Mul32L2
N LDA MLR%,X:STA NM1%,X
X DEX
b BPL Mul32L2
l RTS
v
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
* RTS
4 .Add32
> TXA:PHA
H TYA:PHA
R LDY #0
\ LDX #4
f CLD
p CLC
z
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
$ LDA #0:STA zRem%,X
. DEX
8
BPL CND
B LDX #32
L
.Divide
V ASL zNum%
` ROL zNum% + 1
j ROL zNum% + 2
t ROL zNum% + 3
~ ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
( STA zTemp% + 3
2
BCC Next
< INC zNum%
F LDY #3
P .CpTmpToRem
Z LDA zTemp%, Y
d STA zRem% , Y
n DEY
x BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
" .STTI2
,$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
6 DEX
@ BPL STTI2
J LDA #&2
T LDX #(FDBS%+TIMEVAR%) 256
^ LDY #(FDBS%+TIMEVAR%) 256
h JSR &FFF1
r RTS
 .PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
& JSR &FFEE
0 .PrTiL2
: INY
D CPY #3
N BNE PrTiL1
X JSR &FFE7
b RTS
l .PrintDate
v LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
* BPL PDL1
4 JSR Div32
>$ \ STORE LOWER PART OF YEAR \
H LDA zRem%
R STA STORE%
\ JSR ClearNums
f LDA #10
p STA NM2%
z LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
$ ADC #&30
. JSR &FFEE
8 RTS
B .ClearNums
L$ \ NM1 and NM2 are in one line \
V LDX #7
` LDA #0
j
.CNL1
t STA NM1%,X
~ DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
tVMDSAVE NTP 4E98 5563 4F01
DBS%:XR%MIN%\NEC%MAY%NN%MR%MYS%RA%MOE%EXOE%hN
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FDllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
\LDX #3 \
.UTCL1
\LDA HrsS,X:STA NM1%,X \
\LDA #0: STA NM2%,X \
\DEX \
\BPL UTCL1
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
* LDA STORE%,X:STA NM1%,X
4 LDA MLR%,X:STA NM2%,X
> DEX
H BPL UTCL2
R JSR Add32
\ LDX #3
f .UTCL3
p LDA NM1%,X:STA STORE%,X
z DEX
BPL UTCL3
JMP UTCCEND
.UTCCNEG
\ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
$ TXA:PHA
. PHA
8 LDX #3
B .STZE1
L LDA HrsS,X : STA NM1%,X
V LDA #0: STA NM2%,X
` DEX
j BPL STZE1
t PLA
~ PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
TXA:PHA
TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
( LDX #3
2 .DTL1
< LDA STORE%,X:STA NM1%,X
F LDA DayS,X:STA NM2%,X
P DEX
Z
BPL DTL1
d JSR Div32
n \ hours = seconds / 3600 \
x LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
" LDA #&3C:STA NM2%
, JSR Div32
6! LDA zNum% : STA FDBS% + MIN%
@# LDA zRem% : STA FDBS% + SEC%
J RTS
T
.DayS
^ EQUD &00015180
h
.HrsS
r EQUD &00000E10

.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
& JSR Add32
0 \ era = days / 146097 \
: LDX #3
D .DDL3
N LDA NM1%,X:STA DYS%,X
X LDA Yr400,X:STA NM2%,X
b DEX
l BPL DDL3
v JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
* LDA NM1%,X:STA DOE%,X
4 LDA c1460,X:STA NM2%,X
> DEX
H
BPL DDL7
R JSR Div32
\ \ doe  doe / 1460 \
f LDX #3
p .DDL8
z LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
$ DEX
. BPL DDLA
8 JSR Add32
B LDX #3
L
.DDLB
V LDA NM1%,X: STA STORE%,X
` LDA DOE%,X:STA NM1%,X
j LDA c146096,X:STA NM2%,X
t DEX
~ BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
( LDX #3
2 .DDLE
< LDA zNum%,X:STA YOE%,X
F DEX
P
BPL DDLE
Z \ era * 400 \
d LDX #3
n
.DDLF
x LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
\ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
" BPL DDL11
, LDX #3
6 .DDL12
@ LDA year,X:STA NM1%,X
J LDA YOE%,X:STA NM2%,X
T DEX
^ BPL DDL12
h JSR Mul32
r LDX #3
 .DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
& DEX
0 BPL DDL15
: LDA #100:STA NM2%
D JSR Div32
N LDX #3
X
.DDL16
b LDA zNum%,X:STA NM2%,X
l LDA STORE%,X:STA NM1%,X
v DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
* LDA #2:STA NM2%
4 JSR Add32
> LDA #153:STA NM2%
H JSR Div32
R LDA zNum%:STA MP%
\ CMP #10
f BPL DDL19
p ADC #3
z STA FDBS%+MN%
JMP DDL1A
.DDL19
SBC #9
STA FDBS%+MN%
.DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LDX #3
$ .DDL1D
. LDA NM1%,X:STA FDBS%+YR%,X
8 DEX
B BPL DDL1D
L .DDL1B
V LDX #3
` LDA #0
j .DDL20
t STA NM1%,X:STA NM2%,X
~ DEllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllX
BPL DDL20
LDA #153:STA NM2%
LDA MP%: STA NM1%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
( LDA #0
2 .DDL22
< STA NM2%,X
F DEX
P BPL DDL22
Z LDA #1:STA NM2%
d JSR Add32
n LDA NM1% :STA FDBS%+DAY%
x RTS
.year
EQUD &0000016D
.c400
EQUD &00000190
.Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
" BNE START_R
,
.SHIFT_R
6 BCC ROTATE_R
@ LDA MLR%+4
J CLC
T ADC NM2%
^ STA MLR%+4
h LDA MLR%+5
r ADC NM2%+1
 STA MLR%+5
LDA MLR%+6
ADC NM2%+2
STA MLR%+6
LDA MLR%+7
ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
& DEX
0 BNE SHIFT_R
: LDX #3
D
.Mul32L2
N LDA MLR%,X:STA NM1%,X
X DEX
b BPL Mul32L2
l RTS
v
.Sub32
PHP
TXA:PHA
TYA:PHA
LDX #4
LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
* RTS
4 .Add32
> TXA:PHA
H TYA:PHA
R LDY #0
\ LDX #4
f CLD
p CLC
z
.Add32L1
LDA NM1%,Y
ADC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
$ LDA #0:STA zRem%,X
. DEX
8
BPL CND
B LDX #32
L
.Divide
V ASL zNum%
` ROL zNum% + 1
j ROL zNum% + 2
t ROL zNum% + 3
~ ROL zRem%
ROL zRem% + 1
ROL zRem% + 2
ROL zRem% + 3
SEC
.Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
( STA zTemp% + 3
2
BCC Next
< INC zNum%
F LDY #3
P .CpTmpToRem
Z LDA zTemp%, Y
d STA zRem% , Y
n DEY
x BPL CpTmpToRem
.Next
DEX
BNE Divide
PLA:TAY
PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
" .STTI2
,$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
6 DEX
@ BPL STTI2
J LDA #&2
T LDX #(FDBS%+TIMEVAR%) 256
^ LDY #(FDBS%+TIMEVAR%) 256
h JSR &FFF1
r RTS
 .PrintTime
JSR ClearNums
\ Select page 0 \
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
& JSR &FFEE
0 .PrTiL2
: INY
D CPY #3
N BNE PrTiL1
X JSR &FFE7
b RTS
l .PrintDate
v LDA FDBS%+DAY%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
* BPL PDL1
4 JSR Div32
>$ \ STORE LOWER PART OF YEAR \
H LDA zRem%
R STA STORE%
\ JSR ClearNums
f LDA #10
p STA NM2%
z LDA zNum%
STA NM1%
\ Conv. upp. part of year \
JSR Conv2d
LDA STORE%
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
$ ADC #&30
. JSR &FFEE
8 RTS
B .ClearNums
L$ \ NM1 and NM2 are in one line \
V LDX #7
` LDA #0
j
.CNL1
t STA NM1%,X
~ DEX
BPL CNL1
RTS
]
Pass%
"SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 256
&FFF7
$CMD
F01
DBS%:XR%MIN%\NEC%MAY%NN%MR%MYS%RA%MOE%EXOE%hNllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
LDX #3
.UTCL2
LDA STORE%,X:STA NM1%,X
LDA MLR%,X:STA NM2%,X
DEX
BPL UTCL2
JSR Add32
* LDX #3
4 .UTCL3
> LDA NM1%,X:STA STORE%,X
H DEX
R BPL UTCL3
\ JMP UTCCEND
f
.UTCCNEG
p \ Select page 0
z TYA:PHA
JSR SelPZ
PLA:TAY
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoZero
\ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.STZE1
LDA HrsS,X : STA NM1%,X
$ LDA #0: STA NM2%,X
. DEX
8 BPL STZE1
B PLA
L PLA:TAX
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll V RTS
` .SelPZ
j \ Select page 0
t \ Reg X,Y and A preserved
~ TXA:PHA
TYA:PHA
PHA
LDA #&93
LDX #&FF
LDY #0
JSR &FFF4
PLA
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
(
BPL DTL1
2 JSR Div32
< \ hours = seconds / 3600 \
F LDX #3
P
.DTL2
Z LDA zNum%,X:STA DAYT%,X
d LDA zRem%,X:STA NM1%,X
n" \ To be used to set value
x% LDA zRem%,X:STA &FD00+TIMEVAR%,X
LDA HrsS,X:STA NM2%,X
DEX
BPL DTL2
JSR Div32
LDA zNum%:STA FDBS% + HR%
LDX #3
.DTL3
LDA zRem%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
"
.DayS
, EQUD &00015180
6
.HrsS
@ EQUD &00000E10
J
.YrCr
T EQUD &000A968D
^ .Yr400
h EQUD &00023AB1
r .c1460
 EQUD &000005B4
.c36524
EQUD &00008EAC
.c146096
EQUD &00023AB0
.DecoDate
LDX #3
.DDL1
LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
& LDA Yr400,X:STA NM2%,X
0 DEX
: BPL DDL3
D JSR Div32
N LDX #3
X .DDL5
b LDA zNum%,X:STA ERA%,X
l LDA zNum%,X:STA NM1%,X
v DEX
BPL DDL5
JSR Mul32
\ days  era * 146097 \
LDX #3
.DDL6
LDA MLR%,X:STA NM2%,X
LDA DYS%,X:STA NM1%,X
DEX
BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
* \ doe  doe / 1460 \
4 LDX #3
> .DDL8
H LDA zNum%,X:STA NM2%,X
R LDA DOE%,X:STA NM1%,X
\ DEX
f BPL DDL8
p JSR Sub32
z LDX #3
.DDL9
LDA NM1%,X:STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c36524,X:STA NM2%,X
DEX
BPL DDL9
JSR Div32
LDX #3
.DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
$ LDA NM1%,X: STA STORE%,X
. LDA DOE%,X:STA NM1%,X
8 LDA c146096,X:STA NM2%,X
B DEX
L BPL DDLB
V JSR Div32
`* \ doedoe/1460+doe/36524doe/146096 \
j LDX #3
t
.DDLC
~ LDA STORE%,X:STA NM1%,X
LDA zNum%,X:STA NM2%,X
DEX
BPL DDLC
JSR Sub32
LDX #3
.DDLD
LDA year,X:STA NM2%,X
DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
( \ era * 400 \
2 LDX #3
<
.DDLF
F LDA ERA%,X:STA NM1%,X
P LDA c400,X:STA NM2%,X
Z DEX
d
BPL DDLF
n JSR Mul32
x \ yoe + era * 400 \
LDX #3
.DDL10
LDA MLR%,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL10
JSR Add32
LDX #3
.DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
" DEX
, BPL DDL12
6 JSR Mul32
@ LDX #3
J .DDL13
T LDA YOE%,X:STA NM2%,X:DEX
^ BPL DDL13
h LDX #1
r .DDL14
 LSR NM2%+3
ROR NM2%+2
ROR NM2%+1
ROR NM2%
DEX
BPL DDL14
JSR Add32
LDX #3
.DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
&
.DDL16
0 LDA zNum%,X:STA NM2%,X
: LDA STORE%,X:STA NM1%,X
D DEX
N BPL DDL16
X JSR Sub32
b LDX #3
l .DDL17
v LDA NM1%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL17
JSR Sub32
LDX #3
.DDL18
LDA NM1%,X:STA DOY%,X
LDA #0:STA NM2%,X
DEX
BPL DDL18
LDA #5:STA NM2%
JSR Mul32
LDA #2:STA NM2%
JSR Add32
LDA #153:STA NM2%
JSR Div32
LDA zNum%:STA MP%
* CMP #10
4 BPL DDL19
> ADC #3
H STA FDBS%+MN%
R JMP DDL1A
\ .DDL19
f SBC #9
p STA FDBS%+MN%
z .DDL1A
CMP #3
BPL DDL1B
LDX #3
.DDL1C
! LDA FDBS% + YR%,X:STA NM1%,X
LDA #0:STA NM2%,X
DEX
BPL DDL1C
LDA #1:STA NM2%
JSR Add32
LllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllDX #3
.DDL1D
LDA NM1%,X:STA FDBS%+YR%,X
DEX
BPL DDL1D
.DDL1B
$ LDX #3
. LDA #0
8 .DDL20
B STA NM1%,X:STA NM2%,X
L DEX
V BPL DDL20
` LDA #153:STA NM2%
j LDA MP%: STA NM1%
t JSR Mul32
~ LDA #2:STA NM2%
JSR Add32
LDA #5:STA NM2%
JSR Div32
LDX #3
.DDL21
LDA zNum%,X:STA NM2%,X
LDA DOY%,X:STA NM1%,X
DEX
BPL DDL21
JSR Sub32
LDX #3
LDA #0
.DDL22
STA NM2%,X
DEX
BPL DDL22
( LDA #1:STA NM2%
2 JSR Add32
< LDA NM1% :STA FDBS%+DAY%
F RTS
P
.year
Z EQUD &0000016D
d
.c400
n EQUD &00000190
x .Mul32
LDA #0
STA MLR%+4
STA MLR%+5
STA MLR%+6
STA MLR%+7
LDX #3
.Mul32L1
LDA NM1%,X:STA MLR%,X
DEX
BPL Mul32L1
LDX #&21
BNE START_R
.SHIFT_R
BCC ROTATE_R
LDA MLR%+4
CLC
" ADC NM2%
, STA MLR%+4
6 LDA MLR%+5
@ ADC NM2%+1
J STA MLR%+5
T LDA MLR%+6
^ ADC NM2%+2
h STA MLR%+6
r LDA MLR%+7
 ADC NM2%+3
STA MLR%+7
.ROTATE_R
ROR A
ROR MLR%+6
ROR MLR%+5
ROR MLR%+4
.START_R
ROR MLR%+3
ROR MLR%+2
ROR MLR%+1
ROR MLR%
DEX
BNE SHIFT_R
LDX #3
.Mul32L2
LDA MLR%,X:STA NM1%,X
& DEX
0 BPL Mul32L2
: RTS
D
.Sub32
N PHP
X TXA:PHA
b TYA:PHA
l LDX #4
v LDY #0
CLD
SEC
.Sub32L1
LDA NM1%,Y
SBC NM2%,Y
STA NM1%,Y
INY
DEX
BNE Sub32L1
PLA:TAY
PLA:TAX
PLP
RTS
.Add32
TXA:PHA
TYA:PHA
LDY #0
* LDX #4
4 CLD
> CLC
H
.Add32L1
R LDA NM1%,Y
\ ADC NM2%,Y
f STA NM1%,Y
p INY
z DEX
BNE Add32L1
PLA:TAY
PLA:TAX
RTS
.Div32
TXA:PHA
TYA:PHA
LDX #3
.CND
LDA NM1%,X:STA zNum%,X
LDA NM2%,X:STA zDen%,X
LDA #0:STA zRem%,X
DEX
BPL CND
LDX #32
.Divide
$ ASL zNum%
. ROL zNum% + 1
8 ROL zNum% + 2
B ROL zNum% + 3
L ROL zRem%
V ROL zRem% + 1
` ROL zRem% + 2
j ROL zRem% + 3
t SEC
~ .Subtract
LDA zRem%
SBC zDen%
STA zTemp%
LDA zRem% + 1
SBC zDen% + 1
STA zTemp% + 1
LDA zRem% + 2
SBC zDen% + 2
STA zTemp% + 2
LDA zRem% + 3
SBC zDen% + 3
STA zTemp% + 3
BCC Next
INC zNum%
LDY #3
.CpTmpToRem
( LDA zTemp%, Y
2 STA zRem% , Y
< DEY
F BPL CpTmpToRem
P .Next
Z DEX
d BNE Divide
n PLA:TAY
x PLA:TAX
RTS
.StoreToTIME
LDX #3
.STTI1
LDA #0:STA NM1%,X
% LDA FDBS%+TIMEVAR%,X: STA NM2%,X
DEX
BPL STTI1
LDA #100:STA NM1%
JSR Mul32
LDX #3
.STTI2
$ LDA MLR%,X:STA FDBS%+TIMEVAR%,X
DEX
BPL STTI2
LDA #&2
" LDX #(FDBS%+TIMEVAR%) 256
, LDY #(FDBS%+TIMEVAR%) 256
6 JSR &FFF1
@ RTS
J .PrintTime
T JSR ClearNums
^ \ Select page 0 \
h LDA #&93
r
LDX #&FF
 LDY #0
JSR &FFF4
LDY #0
LDA #10
STA NM2%
.PrTiL1
LDA FDBS% + HR%,Y
STA NM1%
JSR Conv2d
LDA #&3A
CPY #2
BEQ PrTiL2
JSR &FFEE
.PrTiL2
INY
CPY #3
BNE PrTiL1
& JSR &FFE7
0 RTS
: .PrintDate
D LDA FDBS%+DAY%
N STA NM1%
X JSR Conv2d
b
LDA #&2D
l JSR &FFEE
v LDA FDBS%+MN%
STA NM1%
JSR Conv2d
LDA #&2D
JSR &FFEE
# \ Year printing is different \
LDA #100
STA NM2%
LDX #3
.PDL1
LDA FDBS%+YR%,X
STA NM1%,X
DEX
BPL PDL1
JSR Div32
$ \ STORE LOWER PART OF YEAR \
LDA zRem%
STA STORE%
* JSR ClearNums
4 LDA #10
> STA NM2%
H LDA zNum%
R
STA NM1%
\ \ Conv. upp. part of year \
f JSR Conv2d
p LDA STORE%
z
STA NM1%
JSR Conv2d
JSR &FFE7
RTS
.Conv2d
JSR Div32
LDA zNum%
CLC
ADC #&30
JSR &FFEE
LDA zRem%
CLC
ADC #&30
JSR &FFEE
RTS
.ClearNums
$ \ NM1 and NM2 are in one line \
$ LDX #7
. LDA #0
8
.CNL1
B STA NM1%,X
L DEX
V
BPL CNL1
` RTS
j ]
t Pass%
~ "SIZE : " +(P%PROG%)
H $CMD = "SAVE NTP " + ~(PROG%) + " " + ~(P%) + " " + ~(ProcLogic)
Y% = CMD 256
X% = CMD 2llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll56
&FFF7
$CMD
(2<FPZdnx",6@JT^hr&0:DNXblv *4>HR\fpz$.8BLV`jt
CMD 30
FDBS% = &FD00
Area time.All one byte
(! HR%=&80:MIN%=&81:SEC%=&82
2" Area date.Yr 4 bytes rest 1
< DAY%=&83:MN%=&84:YR%=&85
F Area date calculation
P DYS% = &FD89 : 4 BYTES
Z ERA% = &FD8D : 4
d DOE% = &FD91 : 4
n YOE% = &FD95 : 4
x DOY% = &FD99 : 4
MP% = &FD9D : 1
Div32 variables
zNum% = &FD9E : 4
zDen% = &FDA2 : 4
zTemp% = &FDA6 : 4
zRem% = &FDAA : 4
Mul32
NM1% = &FDAE : 4
NM2% = &FDB2 : 4
MLR% = &FDB6 : 8
Misc
STORE% = &FDBE : 4
DAYT% = &FDC2 : 4
RSTAT% = &C6
TIMEVAR% = &C7 : 5
PROG% 2000
" Pass% = 0 2 2
, P% = PROG%
6 [OPT Pass%
@ \Misc \
J
.CONN
TG EQUS "UDP"+(&0D)+ "0.nl.pool.ntp.org"+(&0D)+"123" + 80,(0))
^ .ProcLogic
h JSR GetData
r JSR GetResData
 JSR DecodeData
JSR PrintResult
JSR StoreToTIME
RTS
.PrintResult
JSR PrintTime
JSR PrintDate
RTS
.DecodeData
JSR UTCCorr
JSR DecoTime
JSR DecoDate
RTS
.GetData
JSR ClearBuff
JSR UDPConn
JSR UDPReq
& JSR CloseConn
0 RTS
: .ClearBuff
D! \ Set page 0 of &FDxx to 0 \
N
LDA #&93
X
LDX #&FF
b LDY #0
l JSR &FFF4
v
LDA #&95
LDX #&FF
.CLBL1
LDY #0
JSR &FFF4
DEX
BNE CLBL1
RTS
.UDPConn
LDA #8
STA STORE%
LDA #CONN 256
STA STORE%+1
LDA #CONN 256
STA STORE%+2
JMP ConnExec
.UDPReq
LDX #50
* LDA #0
4 STA &99
>
.UDPRL1
H STA CONN,X
R DEX
\ BPL UDPRL1
f LDA #&1B
p STA CONN
z' \ Seen in the driver source code \
LDA #CONN 256
STA &96
LDA #CONN 256
STA &97
LDA #48
STA &98
LDA #13
STA STORE%
LDA #&96
STA STORE%+1
LDA #0
STA STORE%+2
JMP ConnExec
.CloseConn
LDA #0:LDX #3
.CCL1
$ STA STORE%,X
. DEX
8 BPL CCL1
B LDA #14
L STA STORE%
V \ exec. WiFi command \
` .ConnExec
j LDX #STORE% 256
t LDY #STORE% 256
~
LDA #&65
JSR &FFF1
RTS
.GetResData
LDA #0 : STA &FCFF
LDX #0
LDA #&94
.GRDL1
JSR &FFF4
! CPY #("+") \ Corr. Response
BNE GRDNRSP
INX
JSR &FFF4
CPY #("I")
BNE GRDNRSP
INX
JSR &FFF4
( CPY #("P")
2 BNE GRDNRSP
< INX
F JSR &FFF4
P CPY #("D")
Z BNE GRDNRSP
d JMP GRDL2
n .GRDNRSP \ No +IPD string
x INX
& CPX #&80 \ Have we reached vars ?
& BCC GRDL1 \ Cont. search for +IPD
.GRDND
LDA #&95
LDX #RSTAT%
LDY #1
JSR &FFF4
" RTS \ No response data found
.GRDDVAL
RTS
$ .GRDL2 \ Now start hunt for :
JSR &FFF4
CPY #(":")
BEQ GRDSD
INX
& CPX #&80 \ Have we reached vars ?
" BCC GRDL2
, JMP GRDND
6
.GRDSD
@$ \Offset to time in NTP struct \
J TXA:CLC:ADC #41:TAX
T
LDA #&94
^ JSR &FFF4
h STY STORE%+3
r INX
 JSR &FFF4
STY STORE%+2
INX
JSR &FFF4
STY STORE%+1
INX
JSR &FFF4
STY STORE%
\ quick test on time data \
LDA STORE%+3
CMP #0
BEQ GRDND
RTS
.UTCCorr
& \ UTC Correction must be executed
\ before any other action
TXA:PHA
& TYA:PHA
0 \ Get UTC flag
:
LDA #&93
D
LDX #&FF
N LDY #1
X JSR &FFF4
b
LDA #&94
l LDX #0
v JSR &FFF4
CPY #0 \ UTC = 0 ?
! BEQ UTCCEND \ =0 NO ACTION \
BMI UTCCNEG
\ = 1 MUST BE 0
TYA:PHA
JSR SelPZ
PLA:TAY
JSR StoZero
STY NM2% \ UTC > 0
JSR Mul32
\LDX #3 \
.UTCL2
\LDA STORE%,X:STA NM1%,X \
\LDA MLR%,X:STA NM2%,X
\DEX \
\BPL UTCL2 \
JSR StoMLR
* JSR Add32
4 LDX #3
> .UTCL3
H LDA NM1%,X:STA STORE%,X
R DEX
\ BPL UTCL3
f JMP UTCCEND
p
.UTCCNEG
z \ Select page 0
TYA:PHA
JSR SelPZ
PLA:TAY
JllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllSR StoZero
.UTCCEND
JSR SelPZ
PLA:TAY
PLA:TAX
RTS
.StoMLR
\ Copies STORE% to NM1%
\ Copies MLR% to NM2%
\ Preserves A and Z
TXA:PHA
PHA
LDX #3
$ .STMLR1
. LDA STORE%,X:STA NM1%,X
8 LDA MLR%,X:STA NM2%,X
B DEX
L BPL STMLR1
V PLA
` PLA:TAX
j RTS
t
.StoZero
~ \ Copy STORE % in NM1%
\ Fill NM2% with 0
\ Reg. X and A preserved
TXA:PHA
PHA
LDX #3
.STZE1
LDA HrsS,X : STA NM1%,X
LDA #0: STA NM2%,X
DEX
BPL STZE1
PLA
PLA:TAX
RTS
.SelPZ
\ Select page 0
\ Reg X,Y and A preserved
( TXA:PHA
2 TYA:PHA
< PHA
F
LDA #&93
P
LDX #&FF
Z LDY #0
d JSR &FFF4
n PLA
x
PLA:TAY
PLA:TAX
RTS
.DecoTime
LDX #3
.DTL1
LDA STORE%,X:STA NM1%,X
LDA DayS,X:STA NM2%,X
DEX
BPL DTL1
JSR Div32
\ hours = seconds / 3600 \
LDX #3
.DTL2
LDA zNum%,X:STA DAYT%,X
LDA zRem%,X:STA NM1%,X
" \ To be used to set value
"% LDA zRem%,X:STA &FD00+TIMEVAR%,X
, LDA HrsS,X:STA NM2%,X
6 DEX
@ BPL DTL2
J JSR Div32
T LDA zNum%:STA FDBS% + HR%
^ LDX #3
h
.DTL3
r LDA zRem%,X:STA NM1%,X
 LDA #0:STA NM2%,X
DEX
BPL DTL3
LDA #&3C:STA NM2%
JSR Div32
! LDA zNum% : STA FDBS% + MIN%
# LDA zRem% : STA FDBS% + SEC%
RTS
.DayS
EQUD &00015180
.HrsS
EQUD &00000E10
.YrCr
EQUD &000A968D
.Yr400
EQUD &00023AB1
.c1460
& EQUD &000005B4
0 .c36524
: EQUD &00008EAC
D
.c146096
N EQUD &00023AB0
X .DecoDate
b LDX #3
l .DDL1
v LDA DAYT%,X:STA NM1%,X
LDA YrCr,X:STA NM2%,X
DEX
BPL DDL1
JSR Add32
\ era = days / 146097 \
LDX #3
.DDL3
LDA NM1%,X:STA DYS%,X
LDA Yr400,X:STA NM2%,X
DEX
BPL DDL3
JSR Div32
LDX #3
.DDL5
LDA zNum%,X:STA ERA%,X
LDA zNum%,X:STA NM1%,X
DEX
*
BPL DDL5
4 JSR Mul32
> \ days  era * 146097 \
H LDX #3
R .DDL6
\ LDA MLR%,X:STA NM2%,X
f LDA DYS%,X:STA NM1%,X
p DEX
z BPL DDL6
JSR Sub32
LDX #3
.DDL7
LDA NM1%,X:STA DOE%,X
LDA c1460,X:STA NM2%,X
DEX
BPL DDL7
JSR Div32
\ doe  doe / 1460 \
LDX #3
.DDL8
LDA zNum%,X:STA NM2%,X
LDA DOE%,X:STA NM1%,X
DEX
BPL DDL8
JSR Sub32
$ LDX #3
. .DDL9
8 LDA NM1%,X:STA STORE%,X
B LDA DOE%,X:STA NM1%,X
L LDA c36524,X:STA NM2%,X
V DEX
`
BPL DDL9
j JSR Div32
t LDX #3
~ .DDLA
LDA zNum%,X:STA NM1%,X
LDA STORE%,X:STA NM2%,X
DEX
BPL DDLA
JSR Add32
LDX #3
.DDLB
LDA NM1%,X: STA STORE%,X
LDA DOE%,X:STA NM1%,X
LDA c146096,X:STA NM2%,X
DEX
BPL DDLB
JSR Div32
* \ doedoe/1460+doe/36524doe/146096 \
LDX #3
.DDLC
( LDA STORE%,X:STA NM1%,X
2 LDA zNum%,X:STA NM2%,X
< DEX
F
BPL DDLC
P JSR Sub32
Z LDX #3
d .DDLD
n LDA year,X:STA NM2%,X
x DEX
BPL DDLD
JSR Div32
\ Store result in YOE% \
LDX #3
.DDLE
LDA zNum%,X:STA YOE%,X
DEX
BPL DDLE
\ era * 400 \
LDX #3
.DDLF
LDA ERA%,X:STA NM1%,X
LDA c400,X:STA NM2%,X
DEX
BPL DDLF
JSR Mul32
" \ yoe + era * 400 \
, LDX #3
6 .DDL10
@ LDA MLR%,X:STA NM1%,X
J LDA YOE%,X:STA NM2%,X
T DEX
^ BPL DDL10
h JSR Add32
r LDX #3
 .DDL11
! LDA NM1%,X:STA FDBS% + YR%,X
DEX
BPL DDL11
LDX #3
.DDL12
LDA year,X:STA NM1%,X
LDA YOE%,X:STA NM2%,X
DEX
BPL DDL12
JSR Mul32
LDX #3
.DDL13
LDA YOE%,X:STA NM2%,X:DEX
BPL DDL13
LDX #1
.DDL14
& LSR NM2%+3
0 ROR NM2%+2
: ROR NM2%+1
D ROR NM2%
N DEX
X BPL DDL14
b JSR Add32
l LDX #3
v .DDL15
LDA NM1%,X:STA STORE%,X
LDA #0:STA NM2%,X
LDA YOE%,X:STA NM1%,X
DEX
BPL DDL15
LDA #100:STA NM2%
JSR Div32
LDX #3
.DDL16
LDA zNum%,X:STA NM2%,X
LDA STORE%,X:STA NM1%,X
DEX
BPL DDL16
JSR Sub32
LDX #3
.DDL17
LDA NM1%,X:STA NM2%,X
* LDA DOE%,X:STA NM1%,X
4 DEX
> llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll