blob: 414170e5738c072d58d7f1bfb704eab2a7ec386d [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;
9
oliverschmidt991ae2b2005-04-17 22:41:32 +000010 .constructor init_kfs
oliverschmidtffab45c2005-04-19 21:36:33 +000011 .destructor done_kfs
oliverschmidt4f0cf882005-04-12 21:42:40 +000012 .export _kfs_open, _kfs_read, _kfs_close, _kfs_getdir
13 .import _uip_buf, popax
14 .importzp ptr1
15
16PATHNAME := $0280
17MLI := $BF00
18
oliverschmidtbeed9202005-05-18 23:25:40 +000019GET_PREFIX_CALL = $C7
oliverschmidt4f0cf882005-04-12 21:42:40 +000020OPEN_CALL = $C8
21READ_CALL = $CA
22CLOSE_CALL = $CC
23
24; ------------------------------------------------------------------------
25
26 .bss
27
28PREFIX: .res 1
29
30; ------------------------------------------------------------------------
31
32 .data
33
34OPEN_PARAM:
35 .byte $03 ;PARAM_COUNT
36 .addr PATHNAME ;PATHNAME
37 .addr _uip_buf ;IO_BUFFER
38OPEN_FD: .byte $00 ;REF_NUM
39
40READ_PARAM:
41 .byte $04 ;PARAM_COUNT
42READ_FD: .byte $00 ;REF_NUM
43READ_BUFFER: .addr $0000 ;DATA_BUFFER
44READ_COUNT_IN: .word $0000 ;REQUEST_COUNT
45READ_COUNT_OUT: .word $0000 ;TRANS_COUNT
46
47CLOSE_PARAM:
48 .byte $01 ;PARAM_COUNT
49CLOSE_FD: .byte $00 ;REF_NUM
50
51; ------------------------------------------------------------------------
52
53 .segment "INIT"
54
oliverschmidt991ae2b2005-04-17 22:41:32 +000055init_kfs:
oliverschmidtbeed9202005-05-18 23:25:40 +000056 ; Check for full pathname
57 lda PATHNAME+1
58 cmp #'/'
59 beq prefix
60
61 ; Save name incl. length
62 ldx PATHNAME
63: lda PATHNAME,x
64 sta _uip_buf,x
65 dex
66 bpl :-
67
68 jsr MLI
69 .byte GET_PREFIX_CALL
70 .addr GET_PREFIX_PARAM
71
72 ; Append name to prefix
oliverschmidt4f0cf882005-04-12 21:42:40 +000073 lda PATHNAME
oliverschmidtbeed9202005-05-18 23:25:40 +000074 clc
75 adc _uip_buf
76 sta PATHNAME
77 tax
78 ldy _uip_buf
79: lda _uip_buf,y
80 sta PATHNAME,x
81 dex
82 dey
83 bne :-
84
85prefix: lda PATHNAME
oliverschmidt4f0cf882005-04-12 21:42:40 +000086 sec
87 sbc #.strlen("CONTIKI")
88 sta PREFIX
89 rts
90
oliverschmidtbeed9202005-05-18 23:25:40 +000091GET_PREFIX_PARAM:
92 .byte $01 ; PARAM_COUNT
93 .addr PATHNAME ; DATA_BUFFER
94
oliverschmidt4f0cf882005-04-12 21:42:40 +000095; ------------------------------------------------------------------------
96
97 .segment "CONTIKI"
98
99_kfs_open:
oliverschmidt4f0cf882005-04-12 21:42:40 +0000100 ; Append name to prefix
101 sta ptr1
102 stx ptr1+1
103 ldy #$00
104 ldx PREFIX
105: lda (ptr1),y
106 beq :+
107 sta PATHNAME+1,x
108 iny
109 inx
110 bne :- ; bra
111: stx PATHNAME
112
113 jsr MLI
114 .byte OPEN_CALL
115 .addr OPEN_PARAM
116 bcs ERROR
117
118 ; Return fd
119 lda OPEN_FD
120 ldx #$00
121 rts
122
123_kfs_read:
124 ; Store count
125 sta READ_COUNT_IN
126 stx READ_COUNT_IN+1
127
128 ; Pop and store buf
129 jsr popax
130 sta READ_BUFFER
131 stx READ_BUFFER+1
132
133 ; Pop and store fd
134 jsr popax
135 sta READ_FD
136
137 jsr MLI
138 .byte READ_CALL
139 .addr READ_PARAM
140 bcs ERROR
141
142 ; Return bytes transfered
143 lda READ_COUNT_OUT
144 ldx READ_COUNT_OUT+1
145 rts
146
oliverschmidt991ae2b2005-04-17 22:41:32 +0000147done_kfs:
oliverschmidt93ffcf12005-04-17 15:40:31 +0000148 lda #$00
149
oliverschmidt4f0cf882005-04-12 21:42:40 +0000150_kfs_close:
151 ; Store fd
152 sta CLOSE_FD
153
154 jsr MLI
155 .byte CLOSE_CALL
156 .addr CLOSE_PARAM
157 bcs ERROR
158
159 ; Return 0
160 tax
161 rts
162
163_kfs_getdir:
164 ; Append '\0' to prefix
165 lda #$00
166 ldx PREFIX
167 sta PATHNAME+1,x
168
169 ; Return prefix
170 lda #<(PATHNAME+1)
171 ldx #>(PATHNAME+1)
172 rts
173
174ERROR:
175 ; Return -1
176 lda #$FF
177 tax
178 rts