mirror of
https://github.com/A2osX/A2osX.git
synced 2024-09-10 22:54:59 +00:00
625 lines
12 KiB
Plaintext
625 lines
12 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
* https://www.cise.ufl.edu/~cop4600/cgi-bin/lxr/http/source.cgi/lib/ansi/gmtime.c
|
||
*--------------------------------------
|
||
SECSDAY .EQ 86400 60*60*24
|
||
CENTURY0 .EQ 19
|
||
YEAR0 .EQ 70
|
||
DAY0 .EQ 4 day 0 was a thursday
|
||
*--------------------------------------
|
||
* K.TimeYA get System Time
|
||
* In :
|
||
* Y,A = PTR to K.Time
|
||
* Out :
|
||
* K.Time filled with ProDOS MLI date/time
|
||
*--------------------------------------
|
||
K.TimeYA >STYA ZPQuickPtr2
|
||
>MLICALL MLIGETTIME
|
||
>LDYAI DATELO
|
||
>STYA ZPQuickPtr1
|
||
bra K.PTime2Time.1
|
||
*--------------------------------------
|
||
* In :
|
||
* PULLW = Src PDATE/TIME (DWORD)
|
||
* PULLW = Dst PTR To K.Time
|
||
*--------------------------------------
|
||
K.PTime2Time >PULLW ZPQuickPtr1
|
||
>PULLW ZPQuickPtr2
|
||
|
||
K.PTime2Time.1 ldy #1
|
||
lda (ZPQuickPtr1),y Get Year
|
||
lsr C is high bit of month
|
||
ldy #S.Time.YEAR
|
||
sta (ZPQuickPtr2),y set year
|
||
sta K.CTime.Year for conputing Century/WDAY later
|
||
|
||
lda (ZPQuickPtr1) Get Month/day
|
||
pha save Day
|
||
ror
|
||
lsr
|
||
lsr
|
||
lsr
|
||
lsr
|
||
ldy #S.Time.MONTH
|
||
sta (ZPQuickPtr2),y set month
|
||
|
||
pla get back day
|
||
and #$1F
|
||
iny
|
||
sta (ZPQuickPtr2),y set day
|
||
|
||
lda K.CTime.Year get back year
|
||
|
||
cmp #69 if before 70 CC,if > 70, CS
|
||
lda #0
|
||
rol get back C in bit 0
|
||
eor #1 toggle C
|
||
adc #19 set date before 1970 -> 20xx
|
||
sta (ZPQuickPtr2) set Century
|
||
sta K.CTime.Century for conputing WDAY later
|
||
|
||
ldy #2
|
||
lda (ZPQuickPtr1),y Get Min
|
||
tax
|
||
iny
|
||
lda (ZPQuickPtr1),y Get Hour
|
||
|
||
ldy #S.Time.HOUR
|
||
sta (ZPQuickPtr2),y set hour
|
||
iny
|
||
txa
|
||
sta (ZPQuickPtr2),y set min
|
||
iny
|
||
lda #0
|
||
sta (ZPQuickPtr2),y set seconds (ProDOS does not provide it)
|
||
|
||
* 1/1/1970 was Thursday...if not leap, add one, if leap add 2
|
||
|
||
K.ComputeWDAY lda #3 Thursday : 4 (-1 for mod 7)
|
||
pha
|
||
lda #19
|
||
sta K.CTime.DWORD
|
||
lda #70
|
||
sta K.CTime.DWORD+1
|
||
|
||
.1 ldy K.CTime.DWORD
|
||
lda K.CTime.DWORD+1
|
||
|
||
cpy K.CTime.Century
|
||
bne .2
|
||
cmp K.CTime.Year
|
||
beq .4
|
||
|
||
.2 jsr K.IsLeapYearYA CC = Leap
|
||
lda #0
|
||
rol
|
||
eor #1
|
||
lsr
|
||
|
||
pla
|
||
adc #1
|
||
cmp #7
|
||
bcc .3
|
||
sbc #7 MOD 7
|
||
|
||
.3 pha
|
||
inc K.CTime.DWORD+1
|
||
lda K.CTime.DWORD+1
|
||
cmp #100
|
||
bne .1
|
||
lda #0
|
||
sta K.CTime.DWORD+1
|
||
inc K.CTime.DWORD
|
||
bra .1
|
||
|
||
.4 ldy #S.Time.MONTH
|
||
lda (ZPQuickPtr2),y get month
|
||
tax
|
||
|
||
.5 lda K.StrFTime.MDAY-1,x get day count in this month
|
||
bne .6 february ?
|
||
|
||
ldy K.CTime.Century
|
||
lda K.CTime.Year
|
||
jsr K.IsLeapYearYA CC = Leap
|
||
lda #0
|
||
rol
|
||
eor #1
|
||
lsr
|
||
|
||
.6 pla
|
||
adc K.StrFTime.MDAY-1,x
|
||
cmp #7
|
||
bcc .7
|
||
sbc #7
|
||
|
||
.7 pha
|
||
dex
|
||
bne .5
|
||
|
||
pla
|
||
|
||
ldy #S.Time.DAY
|
||
adc (ZPQuickPtr2),y get month (1..31)
|
||
dec adjust range 0.31 for MOD 7
|
||
|
||
.8 cmp #7 MOD 7
|
||
bcc .80
|
||
sbc #7
|
||
bra .8
|
||
|
||
.80 inc adjust range 1..7
|
||
ldy #S.Time.WDAY
|
||
sta (ZPQuickPtr2),y
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* K.CTime2Time
|
||
* In :
|
||
* PULLW = Src CTIME DWORD
|
||
* PULLW = Dst PTR To K.Time
|
||
*--------------------------------------
|
||
K.CTime2Time >PULLW ZPQuickPtr1
|
||
>PULLW ZPQuickPtr2
|
||
|
||
ldy #3
|
||
|
||
.1 lda (ZPQuickPtr1),y
|
||
sta K.CTime.DWORD,y
|
||
dey
|
||
bpl .1
|
||
|
||
stz K.CTime.DivDay
|
||
stz K.CTime.DivDay+1
|
||
|
||
.2 lda K.CTime.DWORD
|
||
sta K.CTime.ModDay
|
||
sec
|
||
sbc #SECSDAY
|
||
pha
|
||
|
||
lda K.CTime.DWORD+1
|
||
sta K.CTime.ModDay+1
|
||
sbc /SECSDAY
|
||
pha
|
||
|
||
lda K.CTime.DWORD+2
|
||
sta K.CTime.ModDay+2
|
||
sbc #0
|
||
pha
|
||
|
||
lda K.CTime.DWORD+3
|
||
sbc #0
|
||
bcc .3 end of DIV/MOD ?
|
||
|
||
sta K.CTime.DWORD+3
|
||
pla
|
||
sta K.CTime.DWORD+2
|
||
pla
|
||
sta K.CTime.DWORD+1
|
||
pla
|
||
sta K.CTime.DWORD
|
||
|
||
inc K.CTime.DivDay
|
||
bne .2
|
||
inc K.CTime.DivDay+1
|
||
bne .2
|
||
|
||
.3 pla
|
||
pla
|
||
pla
|
||
stz K.CTime.Div60
|
||
stz K.CTime.Div60+1
|
||
|
||
.4 lda K.CTime.ModDay
|
||
sta K.CTime.Mod
|
||
sec
|
||
sbc #60
|
||
pha
|
||
|
||
lda K.CTime.ModDay+1
|
||
sbc #0
|
||
pha
|
||
|
||
lda K.CTime.ModDay+2
|
||
sbc #0
|
||
|
||
bcc .5
|
||
|
||
sta K.CTime.ModDay+2
|
||
pla
|
||
sta K.CTime.ModDay+1
|
||
pla
|
||
sta K.CTime.ModDay
|
||
|
||
inc K.CTime.Div60
|
||
bne .4
|
||
inc K.CTime.Div60+1
|
||
bne .4
|
||
|
||
.5 pla
|
||
pla
|
||
lda K.CTime.Mod
|
||
ldy #S.Time.SECOND
|
||
sta (ZPQuickPtr2),y
|
||
|
||
stz K.CTime.Div3600
|
||
|
||
.6 lda K.CTime.Div60
|
||
sta K.CTime.Mod
|
||
sec
|
||
sbc #60
|
||
pha
|
||
|
||
lda K.CTime.Div60+1
|
||
sbc #0
|
||
pha
|
||
|
||
bcc .7
|
||
|
||
sta K.CTime.Div60+1
|
||
pla
|
||
sta K.CTime.Div60
|
||
|
||
inc K.CTime.Div3600
|
||
bne .6
|
||
|
||
.7 pla
|
||
|
||
lda K.CTime.Mod
|
||
dey ldy #S.Time.MINUTE
|
||
sta (ZPQuickPtr2),y
|
||
|
||
lda K.CTime.Div3600
|
||
dey ldy #S.Time.HOUR
|
||
sta (ZPQuickPtr2),y
|
||
|
||
lda K.CTime.DivDay WDAY computation : (DivDay + DAY0) mod 7
|
||
clc
|
||
adc #DAY0
|
||
pha
|
||
lda K.CTime.DivDay+1
|
||
adc /DAY0
|
||
eor #$ff
|
||
tax
|
||
pla
|
||
|
||
.8 sta K.CTime.Mod
|
||
sec
|
||
sbc #7
|
||
bcs .8
|
||
inx
|
||
bne .8
|
||
|
||
lda K.CTime.Mod
|
||
ldy #S.Time.WDAY
|
||
sta (ZPQuickPtr2),y
|
||
|
||
lda #CENTURY0
|
||
sta K.CTime.Century
|
||
lda #YEAR0
|
||
sta K.CTime.Year
|
||
|
||
K.CTime2Time.Year
|
||
.1 ldy K.CTime.Century
|
||
lda K.CTime.Year
|
||
jsr K.IsLeapYearYA if Leap year CC
|
||
lda K.CTime.DivDay
|
||
sbc #365
|
||
pha
|
||
lda K.CTime.DivDay+1
|
||
sbc /365
|
||
bcc .2
|
||
|
||
sta K.CTime.DivDay+1
|
||
pla
|
||
sta K.CTime.DivDay
|
||
|
||
inc K.CTime.Year
|
||
lda K.CTime.Year
|
||
cmp #100
|
||
bne .1
|
||
stz K.CTime.Year
|
||
inc K.CTime.Century
|
||
bne .1
|
||
|
||
.2 pla
|
||
lda K.CTime.Century
|
||
* ldy #S.Time.CENTURY
|
||
sta (ZPQuickPtr2)
|
||
ldy #S.Time.YEAR
|
||
lda K.CTime.Year
|
||
sta (ZPQuickPtr2),y
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* K.StrFTime
|
||
* In :
|
||
* PULLW = Src PTR To K.Time
|
||
* PULLW = Src PTR To Format String
|
||
* PULLW = Dst PTR To PSTR Buf
|
||
* %a Abbreviated weekday name : Thu
|
||
* %A Full weekday name : Thursday
|
||
* %b Abbreviated month name : Aug
|
||
* %B Full month name : August
|
||
* %d Day of the month, zero-padded (01-31)
|
||
* %H Hour in 24h format (00-23) 14
|
||
* %I Hour in 12h format (01-12) 02
|
||
* %m Month as a decimal number (01-12) 08
|
||
* %M Minute (00-59) 55
|
||
* %p AM or PM designation PM
|
||
* %S Second (00-61) 02
|
||
* %w Weekday as a decimal number with Sunday as 0 (0-6)
|
||
* %y Year, last two digits (00-99)
|
||
* %Y Year four digits 2001
|
||
* PULLW = Dst PSTR Buffer
|
||
*--------------------------------------
|
||
K.StrFTime >PULLW ZPQuickPtr1
|
||
>PULLW ZPQuickPtr2
|
||
>PULLW ZPQuickPtr3
|
||
|
||
lda #0
|
||
sta (ZPQuickPtr3) Reset target PSTR length
|
||
|
||
tay
|
||
|
||
.1 iny
|
||
lda (ZPQuickPtr2),y
|
||
cmp #'%'
|
||
beq .2
|
||
|
||
phy
|
||
jsr K.StrFTime.addChar
|
||
ply
|
||
.10 tya
|
||
cmp (ZPQuickPtr2)
|
||
bne .1
|
||
rts
|
||
|
||
.2 tya
|
||
cmp (ZPQuickPtr2)
|
||
beq .8
|
||
|
||
iny
|
||
ldx #K.StrFTime.JMPL-K.StrFTime.Tbl-1
|
||
|
||
.3 lda (ZPQuickPtr2),y
|
||
cmp K.StrFTime.Tbl,x
|
||
beq .4
|
||
dex
|
||
bpl .3
|
||
beq .10
|
||
|
||
.4 lda K.StrFTime.JMPL,x
|
||
sta .5+1
|
||
lda K.StrFTime.JMPH,x
|
||
sta .5+2
|
||
phy
|
||
.5 jsr $ffff
|
||
ply
|
||
bra .10
|
||
|
||
.8 rts
|
||
*--------------------------------------
|
||
K.StrFTime.A ldx #3 Max Len
|
||
.HS 2C Bit abs
|
||
|
||
K.StrFTime.AA ldx #15
|
||
>LDYAI K.StrFTime.DAY
|
||
>STYA ZPQuickPtr4
|
||
ldy #S.Time.WDAY
|
||
bra K.StrFTime.STR
|
||
|
||
K.StrFTime.B ldx #3
|
||
.HS 2C Bit abs
|
||
|
||
K.StrFTime.BB ldx #15
|
||
>LDYAI K.StrFTime.MON
|
||
>STYA ZPQuickPtr4
|
||
ldy #S.Time.MONTH
|
||
|
||
K.StrFTime.STR lda (ZPQuickPtr1),y get required S.Time field value
|
||
tay
|
||
beq .8 Illegal value
|
||
|
||
.1 dey range 0..x
|
||
beq .2
|
||
lda (ZPQuickPtr4)
|
||
sec
|
||
adc ZPQuickPtr4
|
||
sta ZPQuickPtr4
|
||
bcc .1
|
||
inc ZPQuickPtr4+1
|
||
bra .1
|
||
|
||
.2 ldy #0
|
||
|
||
.3 iny
|
||
lda (ZPQuickPtr4),y
|
||
phy
|
||
jsr K.StrFTime.addChar
|
||
pla
|
||
cmp (ZPQuickPtr4)
|
||
beq .8
|
||
|
||
tay
|
||
dex
|
||
bne .3
|
||
|
||
.8 rts
|
||
|
||
K.StrFTime.D ldy #S.Time.DAY
|
||
bra K.StrFTime.addDecPtr1Y
|
||
K.StrFTime.HH ldy #S.Time.HOUR
|
||
bra K.StrFTime.addDecPtr1Y
|
||
K.StrFTime.II ldy #S.Time.HOUR
|
||
lda (ZPQuickPtr1),y
|
||
cmp #12
|
||
bcc .1
|
||
sbc #12
|
||
.1 bra K.StrFTime.addDecA
|
||
K.StrFTime.M ldy #S.Time.MONTH
|
||
bra K.StrFTime.addDecPtr1Y
|
||
K.StrFTime.MM ldy #S.Time.MINUTE
|
||
bra K.StrFTime.addDecPtr1Y
|
||
K.StrFTime.P ldy #S.Time.HOUR
|
||
lda (ZPQuickPtr1),y
|
||
cmp #12
|
||
bcc .1
|
||
lda #'p'
|
||
.HS 2C bit abs
|
||
.1 lda #'a'
|
||
jsr K.StrFTime.addChar
|
||
lda #'m'
|
||
bra K.StrFTime.addChar
|
||
K.StrFTime.SS ldy #S.Time.SECOND
|
||
bra K.StrFTime.addDecPtr1Y
|
||
K.StrFTime.W ldy #S.Time.WDAY
|
||
bra K.StrFTime.addDecPtr1Y
|
||
K.StrFTime.YY ldy #S.Time.CENTURY
|
||
jsr K.StrFTime.addDecPtr1Y
|
||
K.StrFTime.Y ldy #S.Time.YEAR
|
||
*--------------------------------------
|
||
K.StrFTime.addDecPtr1Y
|
||
lda (ZPQuickPtr1),y
|
||
K.StrFTime.addDecA
|
||
sta K.StrFTime.BIN
|
||
stz K.StrFTime.DEC
|
||
sed
|
||
ldx #8
|
||
|
||
.1 asl K.StrFTime.BIN
|
||
|
||
lda K.StrFTime.DEC
|
||
adc K.StrFTime.DEC
|
||
sta K.StrFTime.DEC
|
||
|
||
dex
|
||
bne .1
|
||
cld
|
||
|
||
* lda K.StrFTime.DEC already in A
|
||
|
||
lsr
|
||
lsr
|
||
lsr
|
||
lsr
|
||
ora #$30
|
||
jsr K.StrFTime.addChar
|
||
lda K.StrFTime.DEC
|
||
and #$0f
|
||
ora #$30
|
||
*--------------------------------------
|
||
K.StrFTime.addChar
|
||
pha
|
||
lda (ZPQuickPtr3)
|
||
inc
|
||
sta (ZPQuickPtr3)
|
||
tay
|
||
pla
|
||
sta (ZPQuickPtr3),y
|
||
rts
|
||
*--------------------------------------
|
||
K.StrFTime.TBL .AS "aAbBdHImMpSwyY"
|
||
K.StrFTime.JMPL .DA #K.StrFTime.A
|
||
.DA #K.StrFTime.AA
|
||
.DA #K.StrFTime.B
|
||
.DA #K.StrFTime.BB
|
||
.DA #K.StrFTime.D
|
||
.DA #K.StrFTime.HH
|
||
.DA #K.StrFTime.II
|
||
.DA #K.StrFTime.M
|
||
.DA #K.StrFTime.MM
|
||
.DA #K.StrFTime.P
|
||
.DA #K.StrFTime.SS
|
||
.DA #K.StrFTime.W
|
||
.DA #K.StrFTime.Y
|
||
.DA #K.StrFTime.YY
|
||
*--------------------------------------
|
||
K.StrFTime.JMPH .DA /K.StrFTime.A
|
||
.DA /K.StrFTime.AA
|
||
.DA /K.StrFTime.B
|
||
.DA /K.StrFTime.BB
|
||
.DA /K.StrFTime.D
|
||
.DA /K.StrFTime.HH
|
||
.DA /K.StrFTime.II
|
||
.DA /K.StrFTime.M
|
||
.DA /K.StrFTime.MM
|
||
.DA /K.StrFTime.P
|
||
.DA /K.StrFTime.SS
|
||
.DA /K.StrFTime.W
|
||
.DA /K.StrFTime.Y
|
||
.DA /K.StrFTime.YY
|
||
*--------------------------------------
|
||
K.StrFTime.DAY >PSTRING "Monday"
|
||
>PSTRING "Tuesday"
|
||
>PSTRING "Wednesday"
|
||
>PSTRING "Thursday"
|
||
>PSTRING "Friday"
|
||
>PSTRING "Saturday"
|
||
>PSTRING "Sunday"
|
||
*--------------------------------------
|
||
K.StrFTime.MON >PSTRING "January"
|
||
>PSTRING "February"
|
||
>PSTRING "March"
|
||
>PSTRING "April"
|
||
>PSTRING "May"
|
||
>PSTRING "June"
|
||
>PSTRING "July"
|
||
>PSTRING "August"
|
||
>PSTRING "September"
|
||
>PSTRING "October"
|
||
>PSTRING "November"
|
||
>PSTRING "December"
|
||
*--------------------------------------
|
||
* In :
|
||
* Y = Century
|
||
* A = Year (0..99)
|
||
* if (year mod 400 = 0)
|
||
* or
|
||
* if not (year mod 100 = 0) and (year mod 4 = 0)
|
||
* Out :
|
||
* CC = Leap
|
||
* CS = Not Leap
|
||
*--------------------------------------
|
||
K.IsLeapYearYA cmp #0 Year = 00 ?
|
||
bne .1 no
|
||
|
||
tya year = 00, get century in a
|
||
and #$3 mod 4 = 0 ?
|
||
beq .9 leap year
|
||
|
||
.8 sec not leap
|
||
rts
|
||
|
||
.1 and #$3 mod 4 = 0 ?
|
||
bne .8
|
||
|
||
.9 clc Leap
|
||
rts
|
||
*--------------------------------------
|
||
K.CTime.DWORD .BS 4
|
||
K.CTime.DivDay .BS 2
|
||
K.CTime.ModDay .BS 3
|
||
K.CTime.Div60 .BS 2
|
||
K.CTime.Div3600 .BS 1
|
||
K.CTime.Mod .BS 1
|
||
K.CTime.Century .BS 1
|
||
K.CTime.Year .BS 1
|
||
*--------------------------------------
|
||
K.StrFTime.BIN .BS 1
|
||
K.StrFTime.DEC .BS 1 always < 100
|
||
*--------------------------------------
|
||
K.StrFTime.MDAY .DA #3,#0,#3,#2,#3,#2,#3,#3,#2,#3,#2,#3
|
||
MAN
|
||
SAVE SYS/KERNEL.S.Time
|
||
LOAD SYS/KERNEL.S
|
||
ASM
|