Skip to content

Commit

Permalink
fix bug when an error is generated in fseek, it won't crash now
Browse files Browse the repository at this point in the history
  • Loading branch information
jedeoric committed Nov 21, 2023
1 parent 1dc8dfa commit 1e5a0c9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/functions/files/xfseek.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
; [IN] RES fd
.out .sprintf("|MODIFY:TR0:XFSEEK_ROUTINE")
.out .sprintf("|MODIFY:TR7:XFSEEK_ROUTINE")
.out .sprintf("|MODIFY:TR7:XFSEEK_ROUTINE")
.out .sprintf("|MODIFY:TR4:XFSEEK_ROUTINE")
.out .sprintf("|MODIFY:RESB:XFSEEK_ROUTINE")
.out .sprintf("|MODIFY:RES:XFSEEK_ROUTINE")

;EBADF : le descripteur de flux (FILE *) passé en paramètre est invalide.
;EINVAL : le référentiel proposé (paramètre whence) n'est pas valide.

pha


sta TR0
lda RES
Expand All @@ -36,6 +37,7 @@

lda #EBADF
rts

@continue_xfseek:
ldx TR4 ; Whence
ldy TR7 ; save Y
Expand All @@ -50,7 +52,6 @@
lda KERNEL_XFSEEK_SAVE_RESB+1
sta RESB+1

pla

cpx #SEEK_CUR
beq @move
Expand All @@ -60,8 +61,8 @@
beq @go_beginning
lda #EINVAL ; Return error
rts
@go_end:

@go_end:
lda CH376_DATA
ldx CH376_DATA
ldy CH376_DATA
Expand Down Expand Up @@ -89,6 +90,7 @@
rts

@error_bad_seek:

lda #$FF ; EBADSEEK
rts

Expand Down Expand Up @@ -136,13 +138,11 @@
cmp #$14
bne @error_bad_seek


lda #EOK ; Return ok
rts


@go_beginning:
pha
sta TR6
; Seek from the beginning of the file
lda #$00
tay
Expand All @@ -153,12 +153,11 @@
bne @error_bad_seek

; And seek with offset now

lda RES5+1
sta RESB

ldy TR7
pla
lda TR6
ldx RES5


Expand All @@ -170,7 +169,6 @@
lda KERNEL_XFSEEK_SAVE_RES
jsr compute_fp_struct


jsr _set_to_0_seek_file

; Add the offset passed in arg into struct
Expand Down
Empty file removed src/include/process.mac
Empty file.
Empty file removed src/include/process_bss.inc
Empty file.

0 comments on commit 1e5a0c9

Please sign in to comment.