From 1aeb5651f5639a8ea956e5dd75f32878a74fe5ee Mon Sep 17 00:00:00 2001 From: cpg Date: Thu, 28 Oct 2010 20:55:18 +0000 Subject: [PATCH] initial version by Stefan A. Haubenthal git-svn-id: svn://svn.cc65.org/cc65/trunk@4828 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/atari/posixdirent.s | 117 +++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 libsrc/atari/posixdirent.s diff --git a/libsrc/atari/posixdirent.s b/libsrc/atari/posixdirent.s new file mode 100644 index 000000000..0c401ed12 --- /dev/null +++ b/libsrc/atari/posixdirent.s @@ -0,0 +1,117 @@ +; Native: Shawn Jefferson, December 2005 +; POSIX: Stefan Haubenthal, April 2008 + + .include "atari.inc" + .export _opendir, _readdir, _closedir + .import findfreeiocb, clriocb + .import __oserror, return0, __do_oserror + .importzp ptr1, tmp1 + +_opendir: sta ptr1 + stx ptr1+1 + jsr findfreeiocb + beq @iocbok + bne cioerr +@iocbok: stx diriocb + jsr clriocb + ldx diriocb + lda #defdev + sta ICBAH,x + ldy #0 ; '.' -> "D:*.*" + lda (ptr1),y + cmp #'.' + beq @default + lda ptr1 + sta ICBAL,x + lda ptr1+1 + sta ICBAH,x +@default: lda #OPEN + sta ICCOM,x + lda #OPNIN|DIRECT + sta ICAX1,x + jsr CIOV + bmi cioerr + lda #0 + sta __oserror + tax + lda diriocb + rts +cioerr: sty __oserror + jmp return0 + + .proc _readdir + tax + lda #GETREC + sta ICCOM,x + lda #entry + sta ICBAH,x + sta ptr1+1 + lda #DSCTSZ + sta ICBLL,x + lda #0 + sta ICBLH,x + jsr CIOV + bmi cioerr + ldy #0 ; FREE SECTORS + lda (ptr1),y + cmp #'0' + bcs cioerr + dey +@next: iny ; remove trailing spaces + iny + iny + lda (ptr1),y + dey + dey + sta (ptr1),y + cpy #9 + bcs @break + cmp #' ' + bne @next +@break: lda #'.' ; extension dot + sta (ptr1),y + iny ; copy extension + sty tmp1 + ldy #10 + jsr copychar + ldy #11 + jsr copychar + ldy #12 + jsr copychar + lda #0 ; end of string + sta (ptr1),y + lda ptr1 + ldx ptr1+1 + rts + +copychar: lda (ptr1),y ; src=y dest=tmp1 + cmp #' ' + ldy tmp1 + beq @break + sta (ptr1),y + iny + sty tmp1 +@break: rts + .endproc + + .proc _closedir + tax + lda #CLOSE + sta ICCOM,x + jsr CIOV + bmi @cioerr + rts +@cioerr: jmp __do_oserror + .endproc + + .rodata +defdev: .asciiz "D:*.*" + + .bss +diriocb: .res 1 +entry: .res 128