ProDOS Y2K date handling for 'View By Date'. Fixes #15

This commit is contained in:
Joshua Bell 2018-12-05 08:36:04 -08:00
parent b22210eee6
commit 257d0165d2

View File

@ -7186,16 +7186,10 @@ iloop: jsr ptr_calc
bmi inext bmi inext
;; Compare dates ;; Compare dates
;; TODO: Proper ProDOS Y2K date handling ldy #FileRecord::modification_date
ldy #FileRecord::modification_date+1 copy16in (ptr),y, date_a
lda (ptr),y copy16 date, date_b
cmp date+1 ; hi byte jsr compare_dates
beq :+
bcs place
jmp inext
: dey
lda (ptr),y
cmp date ; lo byte
beq inext beq inext
bcc inext bcc inext
@ -7466,6 +7460,47 @@ L809E: inc index
rts rts
.endproc .endproc
;;; --------------------------------------------------
date_a: .word 0
date_b: .word 0
.proc compare_dates
ptr := $0A
copy16 #parsed_a, ptr
ldax date_a
jsr parse_date
copy16 #parsed_b, ptr
ldax date_b
jsr parse_date
lda year_a+1
cmp year_b+1
bne done
lda year_a
cmp year_b
bne done
lda month_a
cmp month_b
bne done
lda day_a
cmp day_b
done: rts
parsed_a:
year_a: .word 0
month_a:.byte 0
day_a: .byte 0
parsed_b:
year_b: .word 0
month_b:.byte 0
day_b: .byte 0
.endproc
;;; -------------------------------------------------- ;;; --------------------------------------------------
;;; ??? ;;; ???
@ -7710,40 +7745,9 @@ value: .word 0
jmp append_month_string jmp append_month_string
append_date_strings: append_date_strings:
;; TODO: Handle ProDOS 2.5 extended dates copy16 #parsed_date, $0A
ldax date
;; Year jsr parse_date
lda #0
sta year+1
lda date+1
and #%11111110
lsr a
sta year
;; Per ProDOS Tech Note #28, 40-99 is 1940-1999, 0-39 is 2000-2039
;; http://www.1000bit.it/support/manuali/apple/technotes/pdos/tn.pdos.28.html
cmp #40 ; 40-99 (and also 100-127, though non-conforming)
bcs y1900
y2000: add16 #2000, year, year
jmp :+
y1900: add16 #1900, year, year
;; Month
: lda date+1
ror a
lda date
ror a
lsr a
lsr a
lsr a
lsr a
sta month
;; Day
lda date
and #%00011111
sta day
jsr append_month_string jsr append_month_string
addr_call concatenate_date_part, str_space addr_call concatenate_date_part, str_space
@ -7776,6 +7780,7 @@ y1900: add16 #1900, year, year
addr_jump concatenate_date_part, str_from_int addr_jump concatenate_date_part, str_from_int
.endproc .endproc
parsed_date:
year: .word 0 year: .word 0
month: .byte 0 month: .byte 0
day: .byte 0 day: .byte 0
@ -7833,6 +7838,72 @@ concat_len:
.endproc .endproc
;;; ============================================================
;;; Parse date
;;; Input: A,X = Date lo/hi
;;; $0A points at {year:.word, month:.byte, day:.byte} to be filled
.proc parse_date
ptr := $0A
;; TODO: Handle ProDOS 2.5 extended dates
;; (additional year bits packed into time bytes)
stax date
;; Null date? Leave as all zeros.
ora date+1 ; null date?
bne year
ldy #3
: sta (ptr),y
dey
bpl :-
rts
;; Year
year: ldy #1
copy #0, (ptr),y
lda date+1
and #%11111110
lsr a
ldy #0
sta (ptr),y
;; Per ProDOS Tech Note #28, 40-99 is 1940-1999, 0-39 is 2000-2039
;; http://www.1000bit.it/support/manuali/apple/technotes/pdos/tn.pdos.28.html
cmp #40 ; 40-99 (and also 100-127, though non-conforming)
bcs y1900
y2000: add16in (ptr),y, #2000, (ptr),y
jmp month
y1900: add16in (ptr),y, #1900, (ptr),y
;; Month
month: lda date+1
ror a
lda date
ror a
lsr a
lsr a
lsr a
lsr a
ldy #2
sta (ptr),y
;; Day
day: lda date
and #%00011111
ldy #3
sta (ptr),y
rts
date: .word 0
.endproc
;;; ============================================================
PAD_TO $84D1 ; Maintain previous addresses PAD_TO $84D1 ; Maintain previous addresses
;;; ============================================================ ;;; ============================================================