2010-10-28 20:55:18 +00:00
|
|
|
; 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
|
2010-10-29 19:53:45 +00:00
|
|
|
.ifdef DEFAULT_DEVICE
|
|
|
|
.import __defdev
|
|
|
|
.endif
|
|
|
|
|
2010-10-28 20:55:18 +00:00
|
|
|
|
2010-10-29 19:25:01 +00:00
|
|
|
.proc _opendir
|
|
|
|
sta ptr1
|
2010-10-28 20:55:18 +00:00
|
|
|
stx ptr1+1
|
|
|
|
jsr findfreeiocb
|
|
|
|
beq @iocbok
|
|
|
|
bne cioerr
|
|
|
|
@iocbok: stx diriocb
|
|
|
|
jsr clriocb
|
|
|
|
ldx diriocb
|
2010-10-29 19:53:45 +00:00
|
|
|
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
|
2010-10-28 20:55:18 +00:00
|
|
|
lda #<defdev
|
|
|
|
sta ICBAL,x
|
|
|
|
lda #>defdev
|
|
|
|
sta ICBAH,x
|
2010-10-29 19:53:45 +00:00
|
|
|
bne @cont
|
|
|
|
.endif
|
|
|
|
|
|
|
|
@use_parm: lda ptr1
|
2010-10-28 20:55:18 +00:00
|
|
|
sta ICBAL,x
|
|
|
|
lda ptr1+1
|
|
|
|
sta ICBAH,x
|
2010-10-29 19:53:45 +00:00
|
|
|
|
|
|
|
@cont: lda #OPEN
|
2010-10-28 20:55:18 +00:00
|
|
|
sta ICCOM,x
|
|
|
|
lda #OPNIN|DIRECT
|
|
|
|
sta ICAX1,x
|
|
|
|
jsr CIOV
|
|
|
|
bmi cioerr
|
|
|
|
lda #0
|
|
|
|
sta __oserror
|
|
|
|
tax
|
|
|
|
lda diriocb
|
|
|
|
rts
|
2010-10-29 19:25:01 +00:00
|
|
|
.endproc
|
|
|
|
|
2010-10-28 20:55:18 +00:00
|
|
|
cioerr: sty __oserror
|
|
|
|
jmp return0
|
|
|
|
|
2010-10-28 21:02:09 +00:00
|
|
|
.proc _readdir
|
2010-10-28 20:55:18 +00:00
|
|
|
tax
|
|
|
|
lda #GETREC
|
|
|
|
sta ICCOM,x
|
|
|
|
lda #<entry
|
|
|
|
sta ICBAL,x
|
|
|
|
sta ptr1
|
|
|
|
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
|
2012-07-03 20:10:52 +00:00
|
|
|
cpy #8
|
2010-10-28 20:55:18 +00:00
|
|
|
bcs @break
|
|
|
|
cmp #' '
|
|
|
|
bne @next
|
2010-10-29 19:25:01 +00:00
|
|
|
|
2010-10-28 20:55:18 +00:00
|
|
|
@break: lda #'.' ; extension dot
|
|
|
|
sta (ptr1),y
|
|
|
|
iny ; copy extension
|
|
|
|
sty tmp1
|
|
|
|
ldy #10
|
2010-10-29 19:25:01 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
cmp #' '
|
|
|
|
bne @hasext
|
|
|
|
|
|
|
|
; no extension present: remove the trailing dot and be done
|
|
|
|
ldy tmp1
|
|
|
|
dey
|
|
|
|
bne @done
|
|
|
|
|
|
|
|
@hasext: jsr copychar
|
2012-07-03 20:10:52 +00:00
|
|
|
ldy #13 ; d_type
|
|
|
|
sta (ptr1),y
|
2010-10-28 20:55:18 +00:00
|
|
|
ldy #11
|
|
|
|
jsr copychar
|
|
|
|
ldy #12
|
|
|
|
jsr copychar
|
2010-10-29 19:25:01 +00:00
|
|
|
|
|
|
|
@done: lda #0 ; end of string
|
2010-10-28 20:55:18 +00:00
|
|
|
sta (ptr1),y
|
|
|
|
lda ptr1
|
|
|
|
ldx ptr1+1
|
|
|
|
rts
|
2010-10-29 19:25:01 +00:00
|
|
|
|
|
|
|
|
2010-10-28 20:55:18 +00:00
|
|
|
copychar: lda (ptr1),y ; src=y dest=tmp1
|
2010-10-29 19:25:01 +00:00
|
|
|
ldy tmp1
|
2010-10-28 21:02:09 +00:00
|
|
|
cmp #' '
|
2010-10-28 20:55:18 +00:00
|
|
|
beq @break
|
|
|
|
sta (ptr1),y
|
|
|
|
iny
|
|
|
|
sty tmp1
|
|
|
|
@break: rts
|
2010-10-28 21:02:09 +00:00
|
|
|
.endproc
|
2010-10-28 20:55:18 +00:00
|
|
|
|
2010-10-28 21:02:09 +00:00
|
|
|
.proc _closedir
|
2010-10-28 20:55:18 +00:00
|
|
|
tax
|
|
|
|
lda #CLOSE
|
|
|
|
sta ICCOM,x
|
|
|
|
jsr CIOV
|
|
|
|
bmi @cioerr
|
2010-10-28 21:02:09 +00:00
|
|
|
ldx #0
|
|
|
|
stx __oserror ; clear system specific error code
|
|
|
|
txa
|
2010-10-28 20:55:18 +00:00
|
|
|
rts
|
|
|
|
@cioerr: jmp __do_oserror
|
2010-10-28 21:02:09 +00:00
|
|
|
.endproc
|
2010-10-28 20:55:18 +00:00
|
|
|
|
2010-10-29 19:53:45 +00:00
|
|
|
.data
|
|
|
|
.ifdef DEFAULT_DEVICE
|
|
|
|
dddefdev: .byte "D"
|
|
|
|
.endif
|
2010-10-28 20:55:18 +00:00
|
|
|
defdev: .asciiz "D:*.*"
|
|
|
|
|
|
|
|
.bss
|
|
|
|
diriocb: .res 1
|
2010-10-29 19:25:01 +00:00
|
|
|
entry: .res DSCTSZ
|