]> git.sur5r.net Git - cc65/blob - libsrc/telemon24/write.s
32bbf617c65a249706b111732106d664d621c631
[cc65] / libsrc / telemon24 / 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        "telemon24.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 L1:     inc     ptr2
31         bne     L2
32         inc     ptr2+1
33         beq     L9
34 L2:     ldy     #0
35         lda     (ptr1),y
36         tax
37         cpx     #$0A            ; Check for \n
38         bne     L3
39         brk
40         .byt $10
41
42         ldx     #$0D
43 L3:     
44         brk
45         .byt $10
46         inc     ptr1
47         bne     L1
48         inc     ptr1+1
49         jmp     L1
50
51 ; No error, return count
52
53 L9:     lda     ptr3
54         ldx     ptr3+1
55         rts
56
57 .endproc
58
59