From b0e75e809bae423d774ecbe0843a4f96c20e3189 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 30 Oct 2024 22:07:12 +0100 Subject: [PATCH 1/5] Ensure that the current drive is selected when exiting a system call. This avoids issues where the current drive according to the BDOS doesn't match the current drive according to the BIOS, which can make odd things happen. --- src/bdos/filesystem.S | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bdos/filesystem.S b/src/bdos/filesystem.S index 758f438e..bd29e5c8 100644 --- a/src/bdos/filesystem.S +++ b/src/bdos/filesystem.S @@ -55,6 +55,8 @@ zproc internal_ENDSYS pha tya pha + txa + pha lda old_fcb_drive zif_pl @@ -62,6 +64,11 @@ zproc internal_ENDSYS sta (param), y ; restore user FCB zendif + lda current_drive ; reselect the current drive + jsr bios_SELDSK + + pla + tax pla tay pla @@ -1818,7 +1825,7 @@ NOINIT filesystem_state_start: find_first_count: .byte 0 active_drive: .byte 0 ; drive currently being worked on -old_drive: .byte 0 ; if the drive has been overridden by the FCB +old_active_drive: .byte 0 ; if the drive has been overridden by the FCB old_fcb_drive: .byte 0 ; drive in user FCB on entry write_protect_vector: .word 0 login_vector: .word 0 From 1b1c2b616d35d289e063ed056d198d90fdc2e4c8 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 30 Oct 2024 22:26:27 +0100 Subject: [PATCH 2/5] Fail with a hard error when trying to write to a full disk. --- src/bdos/filesystem.S | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bdos/filesystem.S b/src/bdos/filesystem.S index bd29e5c8..aa50d457 100644 --- a/src/bdos/filesystem.S +++ b/src/bdos/filesystem.S @@ -1605,9 +1605,15 @@ zproc allocate_unused_block zloop lda temp+2 + cmp blocks_on_disk+0 ; bounds check + bcs disk_full_error sta temp+0 + lda temp+3 + cmp blocks_on_disk+1 ; bounds check + bcs disk_full_error sta temp+1 + jsr get_bitmap_status and #$01 zbreakif_eq @@ -1630,6 +1636,15 @@ zproc allocate_unused_block rts zendproc +zproc disk_full_error + lda #<1f + ldx #>1f + jmp harderror +1: + .ascii "BDOS: disk full" + .byte 13, 10, 0 +zendproc + ; Sets a drive as being readonly. zproc bdos_SETDRIVEREADONLY From b38e4ea77b3356108d315cc042b1d8e6104fb16b Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 30 Oct 2024 22:37:29 +0100 Subject: [PATCH 3/5] Bounds check the block number _correctly_. --- src/bdos/filesystem.S | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bdos/filesystem.S b/src/bdos/filesystem.S index aa50d457..40ec45ab 100644 --- a/src/bdos/filesystem.S +++ b/src/bdos/filesystem.S @@ -1604,14 +1604,20 @@ zproc allocate_unused_block sta temp+3 zloop + ; Bounds check. + lda temp+2 - cmp blocks_on_disk+0 ; bounds check - bcs disk_full_error - sta temp+0 + cmp blocks_on_disk+0 + bcc not_out_of_bounds lda temp+3 - cmp blocks_on_disk+1 ; bounds check + cmp blocks_on_disk+1 bcs disk_full_error + + not_out_of_bounds: + lda temp+2 + sta temp+0 + lda temp+3 sta temp+1 jsr get_bitmap_status From 93ed08e8186cd573ecd3ad69443669fc6fa4e121 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 30 Oct 2024 23:16:43 +0100 Subject: [PATCH 4/5] Discover that the drive problem isn't that the old drive isn't being selected, it's that the user programs are changing drive when they shouldn't be --- specifically, the CPP was changing drive to the argument of DIR. Fix this. --- src/bdos/filesystem.S | 4 ---- src/ccp.S | 11 +---------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/bdos/filesystem.S b/src/bdos/filesystem.S index 40ec45ab..00c6d9b0 100644 --- a/src/bdos/filesystem.S +++ b/src/bdos/filesystem.S @@ -64,9 +64,6 @@ zproc internal_ENDSYS sta (param), y ; restore user FCB zendif - lda current_drive ; reselect the current drive - jsr bios_SELDSK - pla tax pla @@ -1846,7 +1843,6 @@ NOINIT filesystem_state_start: find_first_count: .byte 0 active_drive: .byte 0 ; drive currently being worked on -old_active_drive: .byte 0 ; if the drive has been overridden by the FCB old_fcb_drive: .byte 0 ; drive in user FCB on entry write_protect_vector: .word 0 login_vector: .word 0 diff --git a/src/ccp.S b/src/ccp.S index afc60463..00749063 100644 --- a/src/ccp.S +++ b/src/ccp.S @@ -386,17 +386,8 @@ zproc entry_DIR zuntil_mi zendif - ; Set the drive. - - ldx userfcb+FCB_DR - dex - zif_mi - ldx drive - zendif - txa - jsr bdos_SELECTDISK - ; Find number of files to print per line + jsr set_dirlen ; Start iterating. From f11a3244d5a40d25f75cb96d482edf93220672f1 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 30 Oct 2024 23:19:28 +0100 Subject: [PATCH 5/5] Prevent ls from selecting the drive being listed. --- apps/ls.asm | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/apps/ls.asm b/apps/ls.asm index d50375a4..878d6927 100644 --- a/apps/ls.asm +++ b/apps/ls.asm @@ -36,35 +36,10 @@ endcondx=tmp+3 .zp pfile, 2 .zp pfile2, 2 +.label print_string + start: .expand 1 - - ldy #BDOS_GET_CURRENT_DRIVE - jsr BDOS - sta tmp - - lda cpm_fcb - beq keepcur - - sta tmp - dec tmp \ fcb.dr - 1 - -keepcur: - lda tmp - ldy #BDOS_SELECT_DRIVE - jsr BDOS - - ldy #BDOS_GET_CURRENT_DRIVE - jsr BDOS - - cmp tmp - beq success - - lda #error - jmp print_string \ exits - -success: lda cpm_fcb+1 cmp #' ' bne no_fill_wildcards