Skip to content

Commit

Permalink
Merge pull request #175 from davidgiven/ccp
Browse files Browse the repository at this point in the history
Fix some user number handling.
  • Loading branch information
davidgiven authored Sep 14, 2024
2 parents c00f059 + 440d578 commit c443c92
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
37 changes: 30 additions & 7 deletions lib/xfcb.S
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

ZEROPAGE
__fcb: .fill 2
__olduser: .fill 1

; Preserves XA.
zproc xfcb_clear
Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/bdos/exit.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c443c92

Please sign in to comment.