]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/posixdirent.s
The spans do now contain the size of a span, no longer the end offset.
[cc65] / libsrc / atari / posixdirent.s
index 0c401ed120f598016ef2fa7c50efedc74f8202f7..f33a7f04f2912c3533fa98770e44f3f2cb7067fb 100644 (file)
@@ -6,8 +6,13 @@
                .import   findfreeiocb, clriocb
                .import   __oserror, return0, __do_oserror
                .importzp ptr1, tmp1
+.ifdef  DEFAULT_DEVICE
+               .import __defdev
+.endif
 
-_opendir:      sta     ptr1
+
+.proc  _opendir
+               sta     ptr1
                stx     ptr1+1
                jsr     findfreeiocb
                beq     @iocbok
@@ -15,19 +20,36 @@ _opendir:   sta     ptr1
 @iocbok:       stx     diriocb
                jsr     clriocb
                ldx     diriocb
+               ldy     #0              ; '.' -> "D:*.*"
+               lda     (ptr1),y
+               cmp     #'.'
+               bne     @use_parm
+
+; "." was given as parameter, use default device/dir
+
+.ifdef DEFAULT_DEVICE
+               ; construct a "Dn:*.*" like string from the default drive
+               lda     __defdev+1
+               sta     dddefdev+1      ; copy drive number (overwrite 2nd 'D')
+               lda     #<dddefdev
+               sta     ICBAL,x
+               lda     #>dddefdev
+               sta     ICBAH,x
+               bne     @cont
+.else
                lda     #<defdev
                sta     ICBAL,x
                lda     #>defdev
                sta     ICBAH,x
-               ldy     #0              ; '.' -> "D:*.*"
-               lda     (ptr1),y
-               cmp     #'.'
-               beq     @default
-               lda     ptr1
+               bne     @cont
+.endif
+
+@use_parm:     lda     ptr1
                sta     ICBAL,x
                lda     ptr1+1
                sta     ICBAH,x
-@default:      lda     #OPEN
+
+@cont:         lda     #OPEN
                sta     ICCOM,x
                lda     #OPNIN|DIRECT
                sta     ICAX1,x
@@ -38,10 +60,12 @@ _opendir:   sta     ptr1
                tax
                lda     diriocb
                rts
+.endproc
+
 cioerr:                sty     __oserror
                jmp     return0
 
-               .proc   _readdir
+.proc  _readdir
                tax
                lda     #GETREC
                sta     ICCOM,x
@@ -73,45 +97,63 @@ cioerr:             sty     __oserror
                bcs     @break
                cmp     #' '
                bne     @next
+
 @break:                lda     #'.'            ; extension dot
                sta     (ptr1),y
                iny                     ; copy extension
                sty     tmp1
                ldy     #10
-               jsr     copychar
+               lda     (ptr1),y
+               cmp     #' '
+               bne     @hasext
+
+; no extension present: remove the trailing dot and be done
+               ldy     tmp1
+               dey
+               bne     @done
+
+@hasext:       jsr     copychar
                ldy     #11
                jsr     copychar
                ldy     #12
                jsr     copychar
-               lda     #0              ; end of string
+
+@done:         lda     #0              ; end of string
                sta     (ptr1),y
                lda     ptr1
                ldx     ptr1+1
                rts
-               
+
+
 copychar:      lda     (ptr1),y        ; src=y dest=tmp1
+               ldy     tmp1
                cmp     #' '
-               ldy     tmp1
                beq     @break
                sta     (ptr1),y
                iny
                sty     tmp1
 @break:                rts
-               .endproc
+.endproc
 
-               .proc   _closedir
+.proc  _closedir
                tax
                lda     #CLOSE
                sta     ICCOM,x
                jsr     CIOV
                bmi     @cioerr
+               ldx     #0
+               stx     __oserror               ; clear system specific error code
+               txa
                rts
 @cioerr:       jmp     __do_oserror
-               .endproc
+.endproc
 
-               .rodata
+               .data
+.ifdef DEFAULT_DEVICE
+dddefdev:      .byte   "D"
+.endif
 defdev:                .asciiz "D:*.*"
 
                .bss
 diriocb:       .res    1
-entry:         .res    128
+entry:         .res    DSCTSZ