]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/read.s
DIO functions always set _oserror.
[cc65] / libsrc / atari / read.s
index b5b6ee0111fcce80a2f8bfff9b30b5dd23a6559c..19d33cb66d51c9b07aeb8c5e30911d4a1068bfd8 100644 (file)
@@ -1,5 +1,5 @@
 ;
-; Christian Groessler, May-2004
+; Christian Groessler, Jul-2005
 ;
 ; int __fastcall__ read(int fd,void *buf,int count)
 ;
@@ -8,43 +8,57 @@
        .import __rwsetup,__do_oserror,__inviocb,__oserror
        .export _read
 
-_read: jsr     __rwsetup       ; do common setup for read and write
-       beq     done            ; if size 0, it's a no-op
-       cpx     #$FF            ; invalid iocb?
-       beq     _inviocb
+_read: jsr     __rwsetup       ; do common setup for read and write
+       beq     done            ; if size 0, it's a no-op
+       cpx     #$FF            ; invalid iocb?
+       beq     _inviocb
 
 .ifdef LINEBUF
        ; E: should be always at IOCB #0
        ; fixme: what happens when user closes and reopens stdin?
-       cpx     #0              ; E: handler (line oriented keyboard input)?
-       beq     do_line
+       cpx     #0              ; E: handler (line oriented keyboard input)?
+       beq     do_line
 .endif
 
-       lda     #GETCHR         ; iocb command code
-       sta     ICCOM,x
-       jsr     CIOV            ; read it
-       bpl     done
-       cpy     #EOFERR         ; eof is treated specially
-       beq     done
-       jmp     __do_oserror    ; update errno
-
-done:  lda     ICBLL,x         ; buf len lo
-       pha                     ; save
-       lda     ICBLH,x         ; get buf len hi
-       tax                     ; to X
-okdone:        lda     #0
-       sta     __oserror       ; clear system dependend error code
-       pla                     ; get buf len lo
+       lda     #GETCHR         ; iocb command code
+       sta     ICCOM,x
+       jsr     CIOV            ; read it
+       bpl     done
+       cpy     #EOFERR         ; eof is treated specially
+       beq     done
+       jmp     __do_oserror    ; update errno
+
+done:  lda     ICBLL,x         ; buf len lo
+       pha                     ; save
+       lda     ICBLH,x         ; get buf len hi
+       tax                     ; to X
+okdone:        lda     #0
+       sta     __oserror       ; clear system dependend error code
+       pla                     ; get buf len lo
        rts
 
 _inviocb:
-       jmp     __inviocb
+       jmp     __inviocb
 
 
 .ifdef LINEBUF
 
 ; line oriented input
 
+       .segment        "EXTZP" : zeropage
+
+index: .res    1               ; index into line buffer
+buflen:        .res    1               ; length of used part of buffer
+cbs:   .res    1               ; current buffer size: buflen - index
+dataptr:.res   2               ; temp pointer to user buffer
+copylen:.res   1               ; temp counter
+
+       .bss
+
+linebuf:.res   LINEBUF         ; the line buffer
+
+        .code
+
 do_line:
        lda     buflen          ; line buffer active?
        bne     use_buf         ; yes, get data from there
@@ -86,8 +100,8 @@ do_line:
 newbuf:
        lda     ICBLL,x         ; get # of bytes read
        sta     buflen
-       lda     #0
-       sta     index
+       lda     #0
+       sta     index           ; fresh buffer
 
        ; restore user buffer address & length
        pla
@@ -103,6 +117,7 @@ newbuf:
        sta     ICBLL,x
 
        ; fall into use_buf
+       lda     buflen
 
 ; return bytes from line buffer
 ; use buflen and index to access buffer
@@ -110,7 +125,6 @@ newbuf:
 ; use dataptr as a temporary pointer
 
 use_buf:
-       lda     buflen
        sec
        sbc     index           ; size of unread data in the buffer
        sta     cbs
@@ -129,7 +143,7 @@ icbll_copy:
 
        lda     ICBAL,x         ; buffer address
        sta     dataptr
-       lda     ICBAH,x         ; buffer address
+       lda     ICBAH,x         ; buffer address
        sta     dataptr+1
        lda     ICBLL,x
        sta     copylen
@@ -162,21 +176,7 @@ c1:        ldx     #0
 btsmall:
        lda     cbs
        sta     ICBLL,x
-       bne     icbll_copy
-
-;      brk                     ; not reached
-
-       .zeropage
-
-index: .res    1               ; index into line buffer
-buflen:        .res    1               ; length of used part of buffer
-cbs:   .res    1               ; current buffer size: buflen - index
-dataptr:.res   2               ; temp pointer to user buffer
-copylen:.res   1               ; temp counter
-
-       .bss
-
-linebuf:.res   LINEBUF         ; the line buffer
+       bpl     icbll_copy
 
 .endif         ; .ifdef LINEBUF