]> git.sur5r.net Git - cc65/blobdiff - libsrc/cbm/write.s
Introduced internal gotoxy that pops both parameters.
[cc65] / libsrc / cbm / write.s
index 26076ffa471c8d9d78ff8aecd1533eae1ffc67d5..20999d2aceba98adca7a6fc21b9134971f4beb88 100644 (file)
@@ -7,7 +7,7 @@
         .export         _write
         .constructor    initstdout
 
-        .import         SETLFS, OPEN, CKOUT, BSOUT, CLRCH
+        .import         SETLFS, OPEN, CKOUT, BSOUT, READST, CLRCH
         .import         rwcommon
         .importzp       sp, ptr1, ptr2, ptr3
 
 ;--------------------------------------------------------------------------
 ; initstdout: Open the stdout and stderr file descriptors for the screen.
 
-.segment        "INIT"
+.segment        "ONCE"
 
 .proc   initstdout
 
-        lda     #LFN_WRITE
-        sta     fdtab+STDOUT_FILENO
-        sta     fdtab+STDERR_FILENO
-        lda     #CBMDEV_SCREEN
-        sta     unittab+STDOUT_FILENO
-        sta     unittab+STDERR_FILENO
         lda     #STDOUT_FILENO + LFN_OFFS
         jsr     @L1
         lda     #STDERR_FILENO + LFN_OFFS
         bne     @L1
         inc     ptr2+1          ; A = *buf++;
 @L1:    jsr     BSOUT
-        bcs     @error          ; Bail out on errors
+
+; Check the status
+
+        pha
+        jsr     READST
+        lsr     a               ; Bit zero is write timeout
+        bne     devnotpresent2
+        pla
+        bcs     @L3
 
 ; Count characters written
 
@@ -87,9 +89,9 @@
         inc     ptr1+1
         bne     @L0
 
-; Wrote all chars, close the output channel
+; Wrote all chars or disk full. Close the output channel
 
-        jsr     CLRCH
+@L3:    jsr     CLRCH
 
 ; Clear _oserror and return the number of chars written
 
 
 ; Error entry: Device not present
 
+devnotpresent2:
+        pla
 devnotpresent:
         lda     #ENODEV
         jmp     __directerrno   ; Sets _errno, clears _oserror, returns -1
@@ -112,7 +116,3 @@ invalidfd:
         jmp     __directerrno   ; Sets _errno, clears _oserror, returns -1
 
 .endproc
-
-
-
-