From: cuz Date: Tue, 19 Nov 2002 14:27:06 +0000 (+0000) Subject: Add support for append mode X-Git-Tag: V2.12.0~2090 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b2a06ab0417a9d85edf1a74bd31fddb75ab55b8c;p=cc65 Add support for append mode git-svn-id: svn://svn.cc65.org/cc65/trunk@1542 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/cbm/filename.s b/libsrc/cbm/filename.s index 8d00d35be..594c7da91 100644 --- a/libsrc/cbm/filename.s +++ b/libsrc/cbm/filename.s @@ -85,13 +85,13 @@ namecheck: bpl namecheck tax lda __ctype,x - and #(CT_LOWER|CT_DIGIT) + and #CT_ALNUM beq invalidname ; Check the maximum length, store the character nameok: ldx fnlen - cpx #14 ; Maximum length reached? + cpx #16 ; Maximum length reached? bcs invalidname lda (ptr1),y ; Reload char sta fnbuf,x ; Store into buffer @@ -158,8 +158,8 @@ fnunit: .res 1 fnlen: .res 1 .data -fncmd: .byte 's' ; Use as scratch command -fnbuf: .res 20 +fncmd: .byte 's' ; Use as scratch command +fnbuf: .res 22 ; 0:0123456789012345,t,m .rodata ; Characters that are ok in filenames besides digits and letters diff --git a/libsrc/cbm/open.s b/libsrc/cbm/open.s index ad902237a..509951b0f 100644 --- a/libsrc/cbm/open.s +++ b/libsrc/cbm/open.s @@ -50,26 +50,15 @@ parmok: jsr popax ; Get flags bcs nofile stx tmp2 -; Check the flags. We cannot have: -; -; - both, read and write flags set -; - the append flag set -; - - lda tmp3 - and #O_RDWR - beq invflags ; Neither read nor write - cmp #O_RDWR - beq invflags ; Jump if both set - cmp #O_RDONLY - beq doread - -; Write bit is set. We cannot open a file for writing without creating it, -; so check for the O_CREAT bit. +; Check the flags. We cannot have both, read and write flags set, and we cannot +; open a file for writing without creating it. lda tmp3 - and #O_CREAT - beq invflags + and #(O_RDWR | O_CREAT) + cmp #O_RDONLY ; Open for reading? + beq doread ; Yes: Branch + cmp #(O_WRONLY | O_CREAT) ; Open for writing? + bne invflags ; No: Invalid open mode ; If O_TRUNC is set, scratch the file, but ignore any errors @@ -78,10 +67,15 @@ parmok: jsr popax ; Get flags beq notrunc jsr scratch -; Complete the the file name +; Complete the the file name. Check for append mode here. notrunc: - lda #'w' + lda tmp3 ; Get the mode again + ldx #'a' + and #O_APPEND ; Append mode? + bne append ; Branch if yes + ldx #'w' +append: txa jsr fncomplete ; Setup the real open flags