blob: b215b440a25cfc8dbb3cbe6468b640262b634b78 [file] [log] [blame]
oliverschmidt4f0cf882005-04-12 21:42:40 +00001;
2; Contiki kernel file system (Apple2 version)
3;
oliverschmidt93ffcf12005-04-17 15:40:31 +00004; int __fastcall__ kfs_open(const char* name);
oliverschmidt4f0cf882005-04-12 21:42:40 +00005; int __fastcall__ kfs_read(int fd, void* buf, unsigned count);
6; int __fastcall__ kfs_close(int fd);
7; char* kfs_getdir(void);
8;
oliverschmidt93ffcf12005-04-17 15:40:31 +00009; Be sure to keep the value priority of closeallfiles lower than that of
10; closeallstreams (which is the high level C file I/O counterpart and must be
11; called before closeallfiles).
oliverschmidt4f0cf882005-04-12 21:42:40 +000012
oliverschmidt991ae2b2005-04-17 22:41:32 +000013 .constructor init_kfs
14 .destructor done_kfs, 17
oliverschmidt4f0cf882005-04-12 21:42:40 +000015 .export _kfs_open, _kfs_read, _kfs_close, _kfs_getdir
16 .import _uip_buf, popax
17 .importzp ptr1
18
19PATHNAME := $0280
20MLI := $BF00
21
22OPEN_CALL = $C8
23READ_CALL = $CA
24CLOSE_CALL = $CC
25
26; ------------------------------------------------------------------------
27
28 .bss
29
30PREFIX: .res 1
31
32; ------------------------------------------------------------------------
33
34 .data
35
36OPEN_PARAM:
37 .byte $03 ;PARAM_COUNT
38 .addr PATHNAME ;PATHNAME
39 .addr _uip_buf ;IO_BUFFER
40OPEN_FD: .byte $00 ;REF_NUM
41
42READ_PARAM:
43 .byte $04 ;PARAM_COUNT
44READ_FD: .byte $00 ;REF_NUM
45READ_BUFFER: .addr $0000 ;DATA_BUFFER
46READ_COUNT_IN: .word $0000 ;REQUEST_COUNT
47READ_COUNT_OUT: .word $0000 ;TRANS_COUNT
48
49CLOSE_PARAM:
50 .byte $01 ;PARAM_COUNT
51CLOSE_FD: .byte $00 ;REF_NUM
52
53; ------------------------------------------------------------------------
54
55 .segment "INIT"
56
oliverschmidt991ae2b2005-04-17 22:41:32 +000057init_kfs:
oliverschmidt4f0cf882005-04-12 21:42:40 +000058 lda PATHNAME
59 sec
60 sbc #.strlen("CONTIKI")
61 sta PREFIX
62 rts
63
64; ------------------------------------------------------------------------
65
66 .segment "CONTIKI"
67
68_kfs_open:
oliverschmidt4f0cf882005-04-12 21:42:40 +000069 ; Append name to prefix
70 sta ptr1
71 stx ptr1+1
72 ldy #$00
73 ldx PREFIX
74: lda (ptr1),y
75 beq :+
76 sta PATHNAME+1,x
77 iny
78 inx
79 bne :- ; bra
80: stx PATHNAME
81
82 jsr MLI
83 .byte OPEN_CALL
84 .addr OPEN_PARAM
85 bcs ERROR
86
87 ; Return fd
88 lda OPEN_FD
89 ldx #$00
90 rts
91
92_kfs_read:
93 ; Store count
94 sta READ_COUNT_IN
95 stx READ_COUNT_IN+1
96
97 ; Pop and store buf
98 jsr popax
99 sta READ_BUFFER
100 stx READ_BUFFER+1
101
102 ; Pop and store fd
103 jsr popax
104 sta READ_FD
105
106 jsr MLI
107 .byte READ_CALL
108 .addr READ_PARAM
109 bcs ERROR
110
111 ; Return bytes transfered
112 lda READ_COUNT_OUT
113 ldx READ_COUNT_OUT+1
114 rts
115
oliverschmidt991ae2b2005-04-17 22:41:32 +0000116done_kfs:
oliverschmidt93ffcf12005-04-17 15:40:31 +0000117 lda #$00
118
oliverschmidt4f0cf882005-04-12 21:42:40 +0000119_kfs_close:
120 ; Store fd
121 sta CLOSE_FD
122
123 jsr MLI
124 .byte CLOSE_CALL
125 .addr CLOSE_PARAM
126 bcs ERROR
127
128 ; Return 0
129 tax
130 rts
131
132_kfs_getdir:
133 ; Append '\0' to prefix
134 lda #$00
135 ldx PREFIX
136 sta PATHNAME+1,x
137
138 ; Return prefix
139 lda #<(PATHNAME+1)
140 ldx #>(PATHNAME+1)
141 rts
142
143ERROR:
144 ; Return -1
145 lda #$FF
146 tax
147 rts