diff --git a/lib/xfcb.S b/lib/xfcb.S index 63d82a19..bc91cb2b 100644 --- a/lib/xfcb.S +++ b/lib/xfcb.S @@ -3,6 +3,7 @@ ZEROPAGE __fcb: .fill 2 +__olduser: .fill 1 ; Preserves XA. zproc xfcb_clear @@ -26,45 +27,67 @@ zendproc zproc xfcb_prepare sta __fcb+0 stx __fcb+1 + lda #0xff + jsr xfcb_getsetuser + sta __olduser ldy #XFCB_US lda (__fcb), y - ldy #BDOS_GET_SET_USER_NUMBER - jsr BDOS + jsr xfcb_getsetuser lda __fcb+0 ldx __fcb+1 rts zendproc +zproc xfcb_execute + jsr BDOS + php + pha + txa + pha + lda __olduser + jsr xfcb_getsetuser + pla + tax + pla + plp + rts +zendproc + +zproc xfcb_getsetuser + ldy #BDOS_GET_SET_USER_NUMBER + jmp BDOS +zendproc + zproc xfcb_open jsr xfcb_prepare jsr xfcb_clear ldy #BDOS_OPEN_FILE - jmp BDOS + jmp xfcb_execute zendproc zproc xfcb_close jsr xfcb_prepare ldy #BDOS_CLOSE_FILE - jmp BDOS + jmp xfcb_execute zendproc zproc xfcb_erase jsr xfcb_prepare jsr xfcb_clear ldy #BDOS_DELETE_FILE - jmp BDOS + jmp xfcb_execute zendproc zproc xfcb_readsequential jsr xfcb_prepare ldy #BDOS_READ_SEQUENTIAL - jmp BDOS + jmp xfcb_execute zendproc zproc xfcb_writesequential jsr xfcb_prepare ldy #BDOS_WRITE_SEQUENTIAL - jmp BDOS + jmp xfcb_execute zendproc ; vim: sw=4 ts=4 et ft=asm diff --git a/src/bdos/exit.S b/src/bdos/exit.S index c0d96d50..f5da5726 100644 --- a/src/bdos/exit.S +++ b/src/bdos/exit.S @@ -20,6 +20,13 @@ zproc bdos_EXIT jsr bios_NEWLINE jsr bdos_RESET + ; The CCP.SYS is always loaded from user 0; switch users (but save the old one). + + lda current_user + pha + lda #0 + sta current_user + ; Open the CCP.SYS file. lda #0 @@ -125,7 +132,12 @@ zproc bdos_EXIT lda temp+1 ; start of TPA, in pages jsr bios_RELOCATE - ; Execute it. + ; Restore the old user. + + pla + sta current_user + + ; Execute the CCP. lda #BANK_MAIN jsr bios_SETBANK