]> git.sur5r.net Git - cc65/blob - libsrc/telemon30/write.s
Adding files for telemon30
[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 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_TELEMON  XWR0  ; Macro
40                 lda #$0d ; return to the beggining of the line
41                 BRK_TELEMON  XWR0  ; Macro ; 
42         
43
44         ldx     #$0D
45 L3:     
46                 BRK_TELEMON  XWR0  ; Macro
47
48         inc     ptr1
49         bne     L1
50         inc     ptr1+1
51         jmp     L1
52
53 ; No error, return count
54
55 L9:     lda     ptr3
56         ldx     ptr3+1
57         rts
58
59 .endproc
60
61