passport/src/ramdisk.a

107 lines
3.1 KiB
Plaintext

;-------------------------------
; MaybeCreateFileOnRAMDisk
; create 140KB file on RAM disk (filename is hardcoded)
;
; in: ProDOS is not in memory
; out: if creation succeeded, gRAMDiskRef contains file refnum
; all flags clobbered
; all registers clobbered
; ProDOS is not in memory
;-------------------------------
!macro MaybeCreateFileOnRAMDisk {
lda RAMDiskImagePath
beq @doneRAMDisk ; no RAM disk available -> skip everything
jsr SwapProDOS ; ProDOS out -> in (preserves flags)
jsr DeleteFileOnRAMDisk ; always safe to call
lda #<RAMDiskImagePath
sta mliparam+1
lda #>RAMDiskImagePath
sta mliparam+2
jsr Create140KFile
bcc +
; We failed to create temporary file on RAM disk.
; This is not fatal, but we'll mark the RAM
; disk as unavailable so we don't bother with it
lda #0
sta RAMDiskImagePath
+ sta gRAMDiskRef
jsr SwapProDOS ; ProDOS in -> out (preserves flags)
@doneRAMDisk
}
;-------------------------------
; DeleteFileOnRAMDisk
; delete our temporary image file on RAM disk
;
; always safe to call
; gracefully returns if no RAM disk was detected
; gracefully closes file before deleting, if it was open
; does not return any error status because no one cares
;
; in: ProDOS is in memory
; out: all registers and flags clobbered
; gRAMDiskRef=0
; ProDOS is in memory
;-------------------------------
DeleteFileOnRAMDisk
lda RAMDiskImagePath
beq @exit ; no RAM disk available
lda gRAMDiskRef
beq +
jsr CloseFile ; close existing file
lda #0
sta gRAMDiskRef
+
lda #<RAMDiskImagePath
sta mliparam+1
lda #>RAMDiskImagePath
sta mliparam+2
jsr DeleteFile ; delete file, ignore error
@exit rts
;-------------------------------
; WriteRAMToDisk - write image file in RAM to physical disk
; if RAM disk is in use
; in: ProDOS is in memory
; out: if error, C set and A contains error code
; if success, C clear
; if a key is pressed, C clear and A contains keycode
; all other flags clobbered
; all registers clobbered
; ProDOS is in memory
;-------------------------------
WriteRAMToDisk
lda #0
sta mliparam+2
sta mliparam+3
sta mliparam+4
sta gTrack
lda gRAMDiskRef
jsr SetMark
jsr RestartProgress ; restart progress bar
@writeRAMToDiskLoop
lda #$00
sta mliparam+2
sta mliparam+4
lda #$10
sta mliparam+3
sta mliparam+5
lda gRAMDiskRef
jsr ReadFile
jsr IncProgress
jsr WriteTrackSecondPass
bcs @exit
lda KEY
bmi @exit
inc gTrack
lda gTrack
cmp #$23
bne @writeRAMToDiskLoop
jsr IncProgress
clc
@exit rts