]> git.sur5r.net Git - cc65/blob - libsrc/apple2/read.s
Add interrupt handling code from Stefan Haubenthal
[cc65] / libsrc / apple2 / read.s
1 ;
2 ; Ullrich von Bassewitz, 30.05.1998
3 ;
4 ; int read (int fd, void* buf, int count);
5 ;
6 ; THIS IS A HACK!
7 ;
8
9         .export         _read
10         .import         popax, _cputc, RDKEY
11         .importzp       ptr1, ptr2, ptr3
12
13 _read:  jsr     popax           ; get count
14         sta     ptr2
15         stx     ptr2+1          ; save it for later
16         jsr     popax           ; get buf
17         sta     ptr1
18         stx     ptr1+1
19         jsr     popax           ; get fd and discard it
20         lda     #$00
21         sta     ptr3
22         sta     ptr3+1          ; set count
23
24 L1:     lda     ptr2
25         ora     ptr2+1          ; count zero?
26         beq     L9
27         jsr     RDKEY
28         and     #$7F            ; clear high bit.
29         pha
30         jsr     _cputc
31         pla
32         ldy     #$00            ; offset into string
33         sta     (ptr1),y        ; save char
34         inc     ptr1
35         bne     L2
36         inc     ptr1+1
37 L2:     inc     ptr3            ; increment count
38         bne     L3
39         inc     ptr3+1
40 L3:     cmp     #$0D            ; CR?
41         bne     L1
42
43 ; Done, return the count
44
45 L9:     lda     ptr3
46         ldx     ptr3+1
47         rts
48
49
50