No Slot Clock: Shave bytes and better comments

* Replace BCD->Binary with smaller routine
* Replace most absolute use of $200-7 with stack
* Remove unneeded sentinel byte at end of unlock sequence

Leaves 9 bytes free in driver.
This commit is contained in:
Joshua Bell 2023-01-27 18:29:09 -08:00
parent d9e72d3c1e
commit 1ddae4fab7
1 changed files with 56 additions and 46 deletions

View File

@ -116,14 +116,14 @@ next: inc slot
bne not_found bne not_found
;; Not found in slot ROM, try main ROMs ??? ;; Not found in slot ROM, try main ROMs ???
lda #>$C015 lda #>$C015 ; $C015 = RDCXROM (internal or slot ROM?)
ldy #<$C015 ldy #<$C015
sta ld4+2 sta ld4+2
sty ld4+1 sty ld4+1
ldy #$07 ldy #$07 ; $C007 = INTCXROM (read internal ROM)
sta st1+2 sta st1+2
sty st1+1 sty st1+1
dey dey ; $C006 = SLOTCXROM (read slot ROM)
sta st4+2 sta st4+2
sty st4+1 sty st4+1
lda #>$C800 lda #>$C800
@ -277,83 +277,95 @@ loop: lda driver,y
driver: driver:
php php
sei sei
ld4: lda $CFFF ; self-modified ld4: lda $CFFF ; self-modified ($CFFF or RDCXROM)
pha pha
st1: sta $C300 ; self-modified st1: sta $C300 ; self-modified ($Cn00 or INTCXROM)
ld1: lda $C304 ; self-modified ld1: lda $C304 ; self-modified ($Cn04)
ldx #8 ldx #8
;; --------------------------------------------------
;; Unlock the NSC by bit-banging. ;; Unlock the NSC by bit-banging.
uloop: uloop:
unlock_addr := *+1 unlock_addr := *+1
lda unlock-1,x ; self-modified lda unlock-1,x ; self-modified (during relocation)
sec sec
ror a ; a bit at a time ror a ; a bit at a time
: pha : pha
lda #0 lda #0
rol a rol a
tay tay
ld2: lda $C300,y ; self-modified ld2: lda $C300,y ; self-modified ($Cn00)
pla pla
lsr a lsr a
bne :- bne :-
dex dex
bne uloop bne uloop
;; Read 8 bytes * 8 bits of clock data into $200...$207 ;; --------------------------------------------------
;; Read 8 bytes * 8 bits of clock data, push onto stack
tmp := $200
ldx #8 ldx #8
bloop: ldy #8 bloop: ldy #8
st2: st2:
: lda $C304 ; self-modified : lda $C304 ; self-modified ($Cn04)
ror a ror a
ror $01FF,x ror tmp
dey dey
bne :- bne :-
lda $01FF,x ; got 8 bits
lsr a ; BCD to binary ;; BCD to Binary - slow but tiny
lsr a ; shift out tens lda tmp ; A = value
lsr a ldy #$FF ; result = -1
lsr a sec
tay sed
beq donebcd : iny ; result += 1
lda $01FF,x sbc #1 ; value -= 1
and #$0F ; mask out units bcs :-
clc cld
: adc #10 ; and add tens as needed tya ; A = result
dey
bne :- ;; Push to stack
sta $01FF,x pha
donebcd:
dex dex
bne bloop bne bloop
;; Now $200...$207 is y/m/d/w/H/M/S/f ;; --------------------------------------------------
;; Now stack has y/m/d/w/H/M/S/F
;; Update ProDOS date/time. pla ; year
lda $0204 ; hour sta DATELO+1
sta TIMELO+1
lda $0205 ; minute pla ; month
sta TIMELO asl
asl
asl
asl
asl
sta DATELO
rol DATELO+1
lda $0201 ; month pla ; day
asl a ora DATELO
asl a
asl a
asl a
asl a
ora $0202 ; day
sta DATELO sta DATELO
lda $0200 ; year pla ; skip week
rol a
sta DATELO+1 pla ; hour
sta TIMELO+1
pla ; minute
sta TIMELO
pla ; skip seconds
pla ; skip fraction
;; --------------------------------------------------
;; Finish up
pla pla
bmi done bmi done
st4: sta $CFFF ; self-modified st4: sta $CFFF ; self-modified ($CFFF or SLOTCXROM)
done: plp done: plp
rts rts
@ -361,12 +373,10 @@ unlock:
;; NSC unlock sequence ;; NSC unlock sequence
.byte $5C, $A3, $3A, $C5 .byte $5C, $A3, $3A, $C5
.byte $5C, $A3, $3A, $C5 .byte $5C, $A3, $3A, $C5
.byte $00
sizeof_driver := * - driver sizeof_driver := * - driver
.assert sizeof_driver <= 125, error, "Clock code must be <= 125 bytes" .assert sizeof_driver <= 125, error, "Clock code must be <= 125 bytes"
;;; ************************************************************ ;;; ************************************************************
.ifndef JUMBO_CLOCK_DRIVER .ifndef JUMBO_CLOCK_DRIVER
.include "../../inc/driver_postamble.inc" .include "../../inc/driver_postamble.inc"