passport/src/slots.a

103 lines
3.4 KiB
Plaintext
Executable File

;-------------------------------
; NextSlot/ThisSlot
; cycle through available output targets
;
; This is more complicated than it used to be,
; because we now support writing to files on suitable
; hard disks. But the purpose of this routine is to
; encapsulate all that messiness and set the relevant
; globals (SLOT, DRIVE, gTargetType) to values the
; caller can rely on without any additional checks.
;
; ThisSlot is an alternate entry point that is called
; once during program startup, to set the initial slot
; and drive and target type. The initial values may
; have been read from a preferences file, which may not
; accurately reflect the current environment (e.g. the
; previous target drive may have disappeared since the
; preferences file was written). In this case, calling
; ThisSlot ends up being equivalent to calling NextSlot,
; but the caller doesn't need to care about it one way
; or the other. (If ThisSlot ends up having to change
; the slot or drive, it does NOT set gChangedPrefs to
; TRUE. This is an intentional design decision, on which
; you are welcome to have an opinion as long as you keep
; it to yourself. Just kidding, nobody has ever even
; thought about this except me.)
;
; in: DiskIIArray populated by calling ScanForDiskII
; HardDiskArray populated by calling ScanForRAMAndHardDisks
; out: @SLOT, @DRIVE set to ASCII values of next available slot/drive
; @gTargetType set based on type of target (see apidefs.a for values)
;-------------------------------
NextSlot
ldy #$31
cpy DRIVE
bne NextSlotLoop
inc DRIVE ; cycle from drive 1 to drive 2 of the same slot
bne ThisSlot ; always branches
NextSlotLoop
sty DRIVE ; cycle to drive 1 of the next slot
inc SLOT
ThisSlot
lda SLOT
cmp #$38
bne +
sty SLOT ; cycle from slot 7 back to slot 1
tya
+ tax
lda DiskIIArray-$31, x
beq @maybeHardDisk
lda SLOT
and #$0F
ora #$C0
ldx #$28
ldy #$06
jsr CompareMemory ; check for signature of CFFA3000 virtual drive in slot ROM
!byte $20,$33,$CD
!byte $18
!byte $90,$2E
bcc @foundCFFA
lda SLOT
cmp #$36
bne @foundDiskII
lda #$32 ; never return S6,D1
sta DRIVE
bne @foundDiskII ; always branches
@maybeHardDisk
jsr LookupUnitNumberOfSelectedHardDisk ; see if we found a hard disk
beq NextSlotLoop ; no hard disk at this location, keep cycling
lda #ID_FILE_ON_HARD_DISK
!byte $2C
@foundCFFA
lda #ID_CFFA_VIRTUAL_DISK
!byte $2C
@foundDiskII
lda #ID_DISK_II
sta gTargetType
rts
LookupUnitNumberOfSelectedHardDisk
; in: HardDiskArray populated
; out: if selected slot and drive contain a suitable hard disk
; then A=ProDOS unit number, Z=0
; otherwise A=0, Z=1
; X clobbered
; Y preserved
lda SLOT
sec
sbc #$30
tax
lda DRIVE
lsr
bcs +
txa
ora #8
tax
+ lda HardDiskArray-1, x
rts