]> git.sur5r.net Git - cc65/blob - libsrc/telemon30/write.s
Correcting spaces
[cc65] / libsrc / telemon30 / write.s
1 ;
2 ; Ullrich von Bassewitz, 2003-04-13
3 ;
4 ; int write (int fd, const void* buf, int count);
5 ;
6 ; This function is a hack!
7 ;
8
9         .export         _write
10         .import         popax
11         .importzp       ptr1, ptr2, ptr3, tmp1
12
13         .include        "telemon30.inc"
14
15 .proc   _write
16
17         sta     ptr3
18         stx     ptr3+1          ; save count as result
19
20         eor     #$FF
21         sta     ptr2
22         txa
23         eor     #$FF
24         sta     ptr2+1          ; Remember -count-1
25
26         jsr     popax           ; get buf
27         sta     ptr1
28         stx     ptr1+1
29         jsr     popax           ; get fd and discard
30
31                 ; if fd=0001 then it stdout
32                 
33                 
34                 cpx     #0
35                 beq     next
36                 jmp     L1
37 next:           
38                 cmp     #1
39                 beq     L1              
40                 
41                 ; Here it's a file opened
42                 lda     ptr1
43                 sta     PTR_READ_DEST
44                 lda     ptr1+1
45                 sta     PTR_READ_DEST+1
46                 lda     ptr3
47                 ldy     ptr3+1
48                 BRK_TELEMON  XFWRITE
49                 rts
50                 
51                 
52 L1:     inc     ptr2
53         bne     L2
54         inc     ptr2+1
55         beq     L9
56 L2:     ldy     #0
57         lda     (ptr1),y
58         tax
59         cpx     #$0A            ; Check for \n
60         bne     L3
61                 BRK_TELEMON  XWR0  ; Macro
62                 lda #$0d ; return to the beggining of the line
63                 BRK_TELEMON  XWR0  ; Macro ; 
64         
65
66         ldx     #$0D
67 L3:     
68                 BRK_TELEMON  XWR0  ; Macro
69
70         inc     ptr1
71         bne     L1
72         inc     ptr1+1
73         jmp     L1
74
75 ; No error, return count
76
77 L9:     lda     ptr3
78         ldx     ptr3+1
79         rts
80
81 .endproc
82
83