]> git.sur5r.net Git - cc65/blob - libsrc/lynx/lynx-cart.s
Lynx update including file routines that access a file system on a cartridge
[cc65] / libsrc / lynx / lynx-cart.s
1 ; ***
2 ; CC65 Lynx Library
3 ;
4 ; Originally by Bastian Schick
5 ; http://www.geocities.com/SiliconValley/Byte/4242/lynx/
6 ;
7 ; Ported to cc65 (http://www.cc65.org) by
8 ; Shawn Jefferson, June 2004
9
10 ; This version by Karri Kaksonen, December 2010
11 ;
12 ; Helper stuff for the cartridge file functions. This version can deal
13 ; with 1024 bytes/block carts that are using CART0 as a read strobe.
14 ; Also the default crt0.s supports this most common Lynx cart format.
15
16         .include "lynx.inc"
17         .include "extzp.inc"
18         .export  lynxskip0, lynxread0
19         .export  lynxblock 
20
21 __BLOCKSIZE0__ = 1024
22
23         .code
24
25 ;**********************************
26 ; Skip bytes on bank 0
27 ; X:Y count (EOR $FFFF)
28 ;**********************************
29 lynxskip0:
30         inx
31         bne @0
32         iny
33         beq exit
34 @0:     jsr readbyte0
35         bra lynxskip0
36
37 ;**********************************
38 ; Read bytes from bank 0
39 ; X:Y count (EOR $ffff)
40 ;**********************************
41 lynxread0:
42         inx
43         bne @1
44         iny
45         beq exit
46 @1:     jsr readbyte0
47         sta (_FileDestPtr)
48         inc _FileDestPtr
49         bne lynxread0
50         inc _FileDestPtr+1
51         bra lynxread0
52
53 ;**********************************
54 ; Read one byte from cartridge
55 ;**********************************
56 readbyte0:
57         lda RCART0
58         inc _FileBlockByte
59         bne exit
60         inc _FileBlockByte+1
61         bne exit
62
63 ;**********************************
64 ; Select a block 
65 ;**********************************
66 lynxblock:
67         pha
68         phx
69         phy
70         lda __iodat
71         and #$fc
72         tay
73         ora #2
74         tax
75         lda _FileCurrBlock
76         inc _FileCurrBlock
77         sec
78         bra @2
79 @0:     bcc @1
80         stx IODAT
81         clc
82 @1:     inx
83         stx SYSCTL1
84         dex
85 @2:     stx SYSCTL1
86         rol
87         sty IODAT
88         bne @0
89         lda __iodat
90         sta IODAT
91         stz _FileBlockByte
92         lda #$100-(>__BLOCKSIZE0__)
93         sta _FileBlockByte+1
94         ply
95         plx
96         pla
97
98 exit:   rts
99