]> git.sur5r.net Git - cc65/blobdiff - libsrc/cbm/write.s
don't use constructor to setup runtime stack
[cc65] / libsrc / cbm / write.s
index 508deb6b8f2024475772df074ad320ece5fe726f..46bcfe407c825a22dd50857898646cd8b8dcbf1b 100644 (file)
@@ -7,11 +7,11 @@
         .export         _write
         .constructor    initstdout
 
+        .import         SETLFS, OPEN, CKOUT, BSOUT, CLRCH
         .import         rwcommon
-        .import         __errno, __oserror
+        .import         __oserror
         .importzp       sp, ptr1, ptr2, ptr3
 
-        .include        "errno.inc"
         .include        "fcntl.inc"
         .include        "cbm.inc"
         .include        "filedes.inc"
@@ -20,6 +20,8 @@
 ;--------------------------------------------------------------------------
 ; initstdout: Open the stdout and stderr file descriptors for the screen.
 
+.segment        "INIT"
+
 .proc   initstdout
 
         lda     #LFN_WRITE
 
 ;--------------------------------------------------------------------------
 ; _write
-
+                      
+.code
 
 .proc   _write
 
         jsr     rwcommon        ; Pop params, check handle
-        bcs     invalidfd       ; Branch if handle not ok
+        bcs     errout          ; Invalid handle, errno already set
 
 ; Check if the LFN is valid and the file is open for writing
 
         bcs     error
         bcc     @L2
 
-; Read the IEEE488 status
-
-@L0:    jsr     READST
-        cmp     #0
-        bne     error5
-
 ; Output the next character from the buffer
 
-        ldy     #0
+@L0:    ldy     #0
         lda     (ptr2),y
         inc     ptr2
         bne     @L1
         inc     ptr2+1          ; A = *buf++;
 @L1:    jsr     BSOUT
+        bcs     error           ; Bail out on errors
 
 ; Count characters written
 
         ldx     ptr3+1
         rts
 
-; Error entry, file descriptor is invalid
-
-invalidfd:
-        lda     #EINVAL
-        sta     __errno
-        lda     #0
-        sta     __errno+1
-        beq     errout
-
 ; Error entry, file is not open
 
 notopen: