prodos-drivers/clocks/ns.clock/ns.clock.system.s

294 lines
7.1 KiB
ArmAsm
Raw Normal View History

2017-11-27 03:51:35 +00:00
;;; NS.CLOCK.SYSTEM
;;; Original by "CAP" 04/21/91
;;; http://www.apple2.org.za/gswv/a2zine/GS.WorldView/v1999/Oct/MISC/NSC.Disk.TXT
;;; Modification history available at:
;;; https://github.com/a2stuff/prodos-drivers
2017-11-27 03:51:35 +00:00
2017-11-27 00:52:28 +00:00
.setcpu "6502"
2017-11-26 20:57:47 +00:00
.linecont +
2019-09-29 03:54:23 +00:00
.feature string_escapes
2017-11-27 00:52:28 +00:00
.include "apple2.inc"
2019-09-29 03:54:23 +00:00
.include "apple2.mac"
2017-11-27 00:52:28 +00:00
.include "opcodes.inc"
.include "../../inc/apple2.inc"
.include "../../inc/macros.inc"
.include "../../inc/prodos.inc"
;;; ************************************************************
.include "../../inc/driver_preamble.inc"
;;; ************************************************************
;;; ============================================================
;;;
;;; Driver Installer
;;;
;;; ============================================================
.define PRODUCT "No-Slot Clock"
;;; ============================================================
2019-09-29 19:52:51 +00:00
;;; Ensure there is not a previous clock driver installed.
.proc maybe_install_driver
lda MACHID
2017-11-26 01:35:48 +00:00
and #$01 ; existing clock card?
beq detect_nsc ; nope, check for NSC
rts ; yes, done!
2017-11-26 01:35:48 +00:00
.endproc
2017-11-27 00:52:28 +00:00
;;; ------------------------------------------------------------
2017-11-26 20:57:47 +00:00
;;; Detect NSC. Scan slot ROMs and main ROMs. Try reading
;;; each location several times, and validate results before
;;; installing driver.
2017-11-26 00:15:42 +00:00
2017-11-26 08:03:11 +00:00
.proc detect_nsc
2017-11-26 01:35:48 +00:00
;; Preserve date/time
ldy #3 ; copy 4 bytes
: lda DATELO,y
2017-11-26 20:57:47 +00:00
sta saved,y
dey
2017-11-26 01:35:48 +00:00
bpl :-
2017-11-26 08:03:11 +00:00
;; Check slot ROMs
2017-11-26 20:57:47 +00:00
lda #>$CFFF
ldy #<$CFFF
sta ld4+2
sty ld4+1
sta st4+2
sty st4+1
2017-11-26 20:57:47 +00:00
lda #0
2017-11-26 08:03:11 +00:00
sta slot
2017-11-26 20:57:47 +00:00
lda #3 ; treat slot 0 as slot 3
sloop: ora #$C0 ; A=$Cs
sta st1+2
2017-11-26 20:57:47 +00:00
rloop: sta ld1+2
sta ld2+2
sta st2+2
2017-11-26 20:57:47 +00:00
lda #3 ; 3 tries - need valid results each time
2017-11-26 08:03:11 +00:00
sta tries
2017-11-26 20:57:47 +00:00
try: jsr driver ; try reading date/time
lda DATELO+1 ; check result
ror a
lda DATELO
rol a
rol a
rol a
rol a
and #$0F
2017-11-26 08:03:11 +00:00
beq next
2017-11-26 20:57:47 +00:00
cmp #13 ; month
2017-11-26 08:03:11 +00:00
bcs next
lda DATELO
2017-11-26 08:03:11 +00:00
and #$1F
beq next
2017-11-26 20:57:47 +00:00
cmp #32 ; day
2017-11-26 08:03:11 +00:00
bcs next
2017-11-26 20:57:47 +00:00
lda TIMELO+1
cmp #24 ; hours
2017-11-26 08:03:11 +00:00
bcs next
lda TIMELO
2017-11-26 20:57:47 +00:00
cmp #60 ; minutes
2017-11-26 08:03:11 +00:00
bcs next
dec tries
bne try
2017-11-26 20:57:47 +00:00
beq install_driver ; all tries look valid
2017-11-26 08:03:11 +00:00
next: inc slot
lda slot
cmp #8
2017-11-26 20:57:47 +00:00
bcc sloop ; next slot
2017-11-26 08:03:11 +00:00
bne not_found
2017-11-26 20:57:47 +00:00
;; Not found in slot ROM, try main ROMs ???
lda #>$C015
ldy #<$C015
sta ld4+2
sty ld4+1
ldy #$07
sta st1+2
sty st1+1
dey
sta st4+2
sty st4+1
2017-11-26 20:57:47 +00:00
lda #>$C800
bne rloop
2017-11-26 01:35:48 +00:00
;; Restore date/time
2017-11-26 08:03:11 +00:00
not_found:
ldy #3
2017-11-26 20:57:47 +00:00
: lda saved,y
sta DATELO,y
dey
2017-11-26 01:35:48 +00:00
bpl :-
;; Show failure message
jsr log_message
scrcode PRODUCT, " - Not Found."
2019-09-29 03:54:23 +00:00
.byte 0
rts
2017-11-26 20:57:47 +00:00
saved: .byte 0, 0, 0, 0
2017-11-26 08:03:11 +00:00
tries: .byte 3
slot: .byte 0
.endproc
2017-11-27 00:52:28 +00:00
;;; ------------------------------------------------------------
2017-11-26 20:57:47 +00:00
;;; Install NSC Driver. Copy into address at DATETIME vector,
;;; update the vector and update MACHID bits to signal a clock
;;; is present.
.proc install_driver
2017-11-26 01:35:48 +00:00
ptr := $A5
;; Update absolute addresses within driver
lda DATETIME+1
2017-11-26 01:35:48 +00:00
sta ptr
clc
2017-11-27 00:52:28 +00:00
adc #(unlock - driver - 1)
sta unlock_addr
lda DATETIME+2
2017-11-26 01:35:48 +00:00
sta ptr+1
adc #0
sta unlock_addr+1
;; Copy driver into appropriate bank
lda RWRAM1
lda RWRAM1
2017-11-26 01:35:48 +00:00
ldy #sizeof_driver-1
2017-11-26 01:35:48 +00:00
loop: lda driver,y
sta (ptr),y
dey
bpl loop
2017-11-26 00:15:42 +00:00
;; Set the "Recognizable Clock Card" bit
lda MACHID
ora #$01
sta MACHID
2017-11-26 00:15:42 +00:00
2017-11-27 00:52:28 +00:00
lda #OPC_JMP_abs
sta DATETIME
;; Invoke the driver to init the time
jsr DATETIME
lda ROMIN2
;; Display success message
jsr log_message
scrcode PRODUCT, " - "
2019-09-29 03:54:23 +00:00
.byte 0
;; Display the current date
jsr cout_date
rts ; done!
.endproc
;;; ============================================================
2017-11-27 00:52:28 +00:00
;;; NSC driver - modified as needed and copied into ProDOS
;;; ============================================================
2017-11-26 01:35:48 +00:00
driver:
php
sei
2017-11-26 08:27:03 +00:00
ld4: lda $CFFF ; self-modified
pha
st1: sta $C300 ; self-modified
ld1: lda $C304 ; self-modified
ldx #8
2017-11-27 00:52:28 +00:00
;; Unlock the NSC by bit-banging.
uloop:
unlock_addr := *+1
lda unlock-1,x ; self-modified
sec
2017-11-27 00:52:28 +00:00
ror a ; a bit at a time
: pha
lda #0
rol a
tay
ld2: lda $C300,y ; self-modified
pla
lsr a
2017-11-27 00:52:28 +00:00
bne :-
dex
2017-11-27 00:52:28 +00:00
bne uloop
;; Read 8 bytes * 8 bits of clock data into $200...$207
ldx #8
2017-11-27 00:52:28 +00:00
bloop: ldy #8
st2:
2017-11-26 08:27:03 +00:00
: lda $C304 ; self-modified
ror a
ror $01FF,x
dey
2017-11-26 08:27:03 +00:00
bne :-
2017-11-27 00:52:28 +00:00
lda $01FF,x ; got 8 bits
lsr a ; BCD to binary
lsr a ; shift out tens
lsr a
lsr a
tay
2017-11-27 00:52:28 +00:00
beq donebcd
lda $01FF,x
2017-11-27 00:52:28 +00:00
and #$0F ; mask out units
clc
2017-11-27 00:52:28 +00:00
: adc #10 ; and add tens as needed
dey
2017-11-26 08:27:03 +00:00
bne :-
sta $01FF,x
2017-11-27 00:52:28 +00:00
donebcd:
dex
bne bloop
;; Now $200...$207 is y/m/d/w/H/M/S/f
;; Update ProDOS date/time.
lda $0204 ; hour
sta TIMELO+1
2017-11-27 00:52:28 +00:00
lda $0205 ; minute
sta TIMELO
2017-11-27 00:52:28 +00:00
lda $0201 ; month
asl a
asl a
asl a
asl a
asl a
2017-11-27 00:52:28 +00:00
ora $0202 ; day
sta DATELO
2017-11-27 00:52:28 +00:00
lda $0200 ; year
rol a
sta DATELO+1
2017-11-27 00:52:28 +00:00
pla
2017-11-26 08:27:03 +00:00
bmi done
st4: sta $CFFF ; self-modified
2017-11-26 08:27:03 +00:00
done: plp
rts
2017-11-26 01:35:48 +00:00
unlock:
;; NSC unlock sequence
.byte $5C, $A3, $3A, $C5
.byte $5C, $A3, $3A, $C5
.byte $00
sizeof_driver := * - driver
2017-12-03 05:35:50 +00:00
.assert sizeof_driver <= 125, error, "Clock code must be <= 125 bytes"
2017-11-26 20:57:47 +00:00
;;; ************************************************************
.include "../../inc/driver_postamble.inc"
;;; ************************************************************