properly close/delete RAM disk file, refactor Save/SwapProDOS to preserve registers and flags

This commit is contained in:
4am 2021-04-15 12:33:41 -04:00
parent 8bcc24c3f5
commit 9aef30b9b1
3 changed files with 88 additions and 116 deletions

View File

@ -22,16 +22,38 @@
; saves memory pages used by ProDOS
; pages $BF
; in: none
; out: all flags and registers clobbered
; out: all flags and registers preserved
;-------------------------------
!zone {
SaveProDOS
SaveGlobal
php
pha
lda #$BF
ldx #$0F
ldy #$01
;;jsr CopyMemory ; fall through
}
jsr CopyMemory
pla
plp
rts
;-------------------------------
; SwapProDOS
; saves/restores memory pages used by ProDOS
; pages $BF
; in: none
; out: all flags and registers preserved
;-------------------------------
SwapProDOS
php
pha
lda #$BF
ldx #$0F
ldy #$01
sec
jsr SwapMemory
pla
plp
rts
;-------------------------------
; CopyMemory
@ -40,21 +62,19 @@ SaveGlobal
; Y = number of pages to copy
; out: all flags and registers clobbered
;-------------------------------
!zone {
CopyMemory
sta .source+2
stx .dest+2
sta @source+2
stx @dest+2
ldx #$00
.source lda $FF00,x
.dest sta $FF00,x
@source lda $FF00,x
@dest sta $FF00,x
inx
bne .source
inc .source+2
inc .dest+2
bne @source
inc @source+2
inc @dest+2
dey
bne .source
bne @source
rts
}
;-------------------------------
; ClearTSBuffer
@ -67,7 +87,7 @@ ClearTSBuffer
lda #BASEPAGE
ldx #$00
ldy #$10
;; jmp ClearMemory ; fall through
; /!\ execution falls through here
;-------------------------------
; ClearMemory
@ -76,17 +96,15 @@ ClearTSBuffer
; Y = number of pages
; out: all flags and registers clobbered
;-------------------------------
!zone {
ClearMemory
sta .dest+2
.dest stx $FF00
inc .dest+1
bne .dest
inc .dest+2
sta @dest+2
@dest stx $FF00
inc @dest+1
bne @dest
inc @dest+2
dey
bne .dest
bne @dest
rts
}
;-------------------------------
; ReorderBuffer - convert data
@ -98,28 +116,11 @@ ClearMemory
; out: all flags clobbered
; all registers clobbered
;-------------------------------
!zone {
ReorderBuffer
lda #BASEPAGE+1
ldx #BASEPAGE+$0E
ldy #$07
clc
bcc SwapMemory ; branch always
}
;-------------------------------
; SwapProDOS
; saves/restores memory pages used by ProDOS
; pages $BF
; in: none
; out: all flags and registers clobbered
;-------------------------------
SwapProDOS
lda #$BF
ldx #$0F
ldy #$01
sec
;;jsr SwapMemory ; fall through
; /!\ execution falls through here
;-------------------------------
; SwapMemory
@ -129,37 +130,35 @@ SwapProDOS
; C = dest direction (set: +, clear: -)
; out: all flags and registers clobbered
;-------------------------------
!zone {
SwapMemory
sta .source1+2
sta .source2+2
stx .dest1+2
stx .dest2+2
sta @source1+2
sta @source2+2
stx @dest1+2
stx @dest2+2
lda #$FF
adc #0
ora #1
sta .destadjust+1
sta @destadjust+1
ldx #$00
.source1 lda $FF00,x
@source1 lda $FF00,x
pha
.dest1 lda $FF00,x
.source2 sta $FF00,x
@dest1 lda $FF00,x
@source2 sta $FF00,x
pla
.dest2 sta $FF00,x
@dest2 sta $FF00,x
inx
bne .source1
inc .source1+2
inc .source2+2
lda .dest1+2
bne @source1
inc @source1+2
inc @source2+2
lda @dest1+2
clc
.destadjust
@destadjust
adc #$D1
sta .dest1+2
sta .dest2+2
sta @dest1+2
sta @dest2+2
dey
bne .source1
bne @source1
rts
}
;-------------------------------
; ReorderLogicalToPhysical - reorder pages in
@ -186,7 +185,6 @@ SwapMemory
; in: track buffer has data in logical sector order
; out: A,X,Y clobbered
;-------------------------------
!zone {
ReorderLogicalToPhysical
ldy #$00
- ldx $1800,y

View File

@ -28,14 +28,14 @@ PC_SETEOF = $02
PRODOSMLI = $BF00 ; [callable] MLI entry point
!ct "lcase.ct"
RAMFileName !text "PASSPORTTMP.DSK"
;!ct "lcase.ct"
RAMFileName !raw "PASSPORTTMP.DSK"
RAMFileName_e
HardDirName !text "PASSPORT"
HardDirName !raw "PASSPORT"
HardDirName_e
HardDiskName !text "/IMG0000.DSK"
HardDiskName !raw "/IMG0000.DSK"
HardDiskName_e
; MLI error codes
@ -443,7 +443,11 @@ CreateRAMOrHardFile
dex
dey
bne -
jsr CreateHardDir
lda #<DiskImgPath
sta mliparam+1
lda #>DiskImgPath
sta mliparam+2
jsr CreateDir
clc
lda DiskImgPath
@ -525,11 +529,7 @@ CreateRAMOrHardFile
;update file buffer array
plp
pha
php
jsr SaveGlobal
plp
pla
jsr SaveProDOS
beq .restore
php
@ -560,14 +560,7 @@ CreateRAMOrHardFile
stx gUsingRAMDisk
.restore
php
pha
jsr SwapProDOS
pla
plp
.done
rts
jmp SwapProDOS
DiskImgPath
!byte $d1
@ -625,12 +618,10 @@ WriteToFile
+ jsr WriteFile
.done
pha
lda .tmpparm4
sta mliparam+4
lda .tmpparm5
sta mliparam+5
pla
ldx .tmpparm4
stx mliparam+4
ldx .tmpparm5
stx mliparam+5
rts
.tmpparm4 !byte 0
@ -691,8 +682,7 @@ WriteRAMToDisk
rts
.cancel
lda #TRUE
sta gUsingRAMDisk
jsr .exit
jmp Cancel
}
@ -708,7 +698,12 @@ WriteRAMToDisk
;-------------------------------
!zone {
CloseDeleteRAMFile
bit $c010
- bit $c000
bpl -
bit $c010
lda gRAMDiskRef
beq +
jsr CloseFile
lda #0
sta gRAMDiskRef
@ -717,29 +712,10 @@ DeleteRAMFile
sta mliparam+1
lda #>DiskImgPath
sta mliparam+2
jmp DeleteFile
jsr DeleteFile
+ rts
}
;-------------------------------
; CreateHardDir - create images directory on hard disk
; if hard disk is in use
; in: nothing
; out: if error, C set and A contains error code
; if success, C clear
; all other flags clobbered
; all registers clobbered
;-------------------------------
!zone {
CreateHardDir
lda #<DiskImgPath
sta mliparam+1
lda #>DiskImgPath
sta mliparam+2
jmp CreateDir
}
;-------------------------------
; get volume name of disk in specific slot+drive
; in: A = unit number (DSSS0000)

View File

@ -639,10 +639,11 @@ FatalError
TheEnd
lda $C0E8
lda gHardDiskRef
ora gRAMDiskRef
beq +
pha
jsr SwapProDOS
pla
jsr CloseDeleteRAMFile ; does nothing if RAM disk was not used
lda gHardDiskRef
jsr CloseFile
jsr SwapProDOS
+ lda #s_done
@ -676,13 +677,10 @@ HandleRedo
CleanExit
jsr SwapProDOS
lda gChangedPrefs
bne .checkRAM
bne +
jsr SavePrefs
.checkRAM
lda gRAMDiskRef
jsr CloseFile ; leave it behind in case it's wanted
.doquit
jsr MLI
+ jsr CloseDeleteRAMFile
jsr MLI ; does not return
!byte $65
!word .quitparm
.quitparm