]> git.sur5r.net Git - cc65/blob - libsrc/lynx/read.s
Added the telldir() function.
[cc65] / libsrc / lynx / read.s
1 ;
2 ; Karri Kaksonen, 2010
3 ;
4 ; This function reads count bytes from the place where the address counter is.
5 ; Use lseek to place the address counter where you want to read from.
6 ;
7 ; The file descriptor is ignored in this implementation. The read operation
8 ; reads bytes from a raw cart and does not understand the concept of files.
9 ; So if you read over the end of file you get data from the next file.
10 ;
11 ; The count-parameter can be positive (Atari style) or negative (BLL style).
12 ; In any case the read routine will work correctly.
13 ;
14 ; int __fastcall__ read(int fd,void *buf,int count)
15 ;
16         .importzp       _FileDestPtr
17         .import         lynxread0
18         .import         pushax,ldaxysp,ldax0sp,incsp6
19         .export         _read
20
21 .segment        "CODE"
22
23 .proc   _read: near
24
25 .segment        "CODE"
26
27         jsr     pushax
28         ldy     #$03
29         jsr     ldaxysp
30         sta     _FileDestPtr
31         stx     _FileDestPtr+1
32         jsr     ldax0sp
33         phx                     ; The BLL kit uses negative counts
34         plx                     ; while the basic Lynx uses positive
35         bmi     @1              ; make all counts negative
36         eor     #$FF
37         pha
38         txa
39         eor     #$FF
40         bra     @2
41 @1:     pha
42         txa
43 @2:     tay
44         plx
45         jsr     lynxread0
46         jsr     ldax0sp
47         jmp     incsp6
48
49 .endproc
50