blob: fa3e060b510cf27d6e93497801f3641de7762073 [file] [log] [blame]
kthacker6de67752006-04-17 15:02:26 +00001/*
2 * Copyright (c) 2004, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
33 * $Id: cfs-cpc.c,v 1.1 2006/04/17 15:02:35 kthacker Exp $
34 */
35#include "contiki.h"
36
37#include "log.h"
38#include "cfs.h"
39#include "cfs-service.h"
40
41extern void _readdir(void *);
42
43struct cpc_dir
44{
45 char *buffer;
46 char *ptr;
47};
48
49//#include <cbm.h>
50#include <string.h>
51
52static int s_open(const char *n, int f);
53static void s_close(int f);
54static int s_read(int f, char *b, unsigned int l);
55static int s_write(int f, char *b, unsigned int l);
56static int s_opendir(struct cfs_dir *p, const char *n);
57static int s_readdir(struct cfs_dir *p, struct cfs_dirent *e);
58static int s_closedir(struct cfs_dir *p);
59
60static const struct cfs_service_interface interface =
61 {
62 CFS_SERVICE_VERSION,
63 s_open,
64 s_close,
65 s_read,
66 s_write,
67 s_opendir,
68 s_readdir,
69 s_closedir
70 };
71
72EK_EVENTHANDLER(cpc_cfs_eventhandler, ev, data);
PulkoMandy9e960752014-06-28 17:13:16 +020073EK_PROCESS(proc, CFS_SERVICE_NAME ": AMSDOS", EK_PRIO_NORMAL,
kthacker6de67752006-04-17 15:02:26 +000074 cpc_cfs_eventhandler, NULL, (void *)&interface);
75
76/*---------------------------------------------------------------------------*/
77EK_PROCESS_INIT(cfs_cpc_init, arg)
78{
79 arg_free(arg);
80 ek_service_start(CFS_SERVICE_NAME, &proc);
81}
82/*---------------------------------------------------------------------------*/
83EK_EVENTHANDLER(cpc_cfs_eventhandler, ev, data)
84{
85 switch(ev) {
86 case EK_EVENT_INIT:
87 case EK_EVENT_REPLACE:
PulkoMandy9e960752014-06-28 17:13:16 +020088 log_message("Starting AMSDOS CFS", "");
kthacker6de67752006-04-17 15:02:26 +000089 break;
90 case EK_EVENT_REQUEST_REPLACE:
91 ek_replace((struct ek_proc *)data, &interface);
92 break;
93 case EK_EVENT_REQUEST_EXIT:
94 ek_exit();
95 break;
96 }
97}
PulkoMandy9e960752014-06-28 17:13:16 +020098
99
kthacker6de67752006-04-17 15:02:26 +0000100/*---------------------------------------------------------------------------*/
101static int
102s_open(const char *n, int f)
103{
104 // if(cbm_open(2, 8, f, n) == 0) {
105 // return 2;
106 // }
107 return -1;
108}
109/*---------------------------------------------------------------------------*/
110static void
111s_close(int f)
112{
113 // cbm_close(f);
114}
115/*---------------------------------------------------------------------------*/
116static int
117s_read(int f, char *b, unsigned int l)
118{
119 return 0; //return cbm_read(f, b, l);
120}
121/*---------------------------------------------------------------------------*/
122static int
123s_write(int f, char *b, unsigned int l)
124{
125 return 0; // return cbm_write(f, b, l);
126}
127/*---------------------------------------------------------------------------*/
128static int
129s_opendir(struct cfs_dir *p, const char *n)
130{
131 struct cpc_dir *cpcdir = (struct cpc_dir *)p;
132
133 char *buffer = malloc(2048);
134
135 if (buffer)
136 {
137 cpcdir->buffer = buffer;
138 cpcdir->ptr = buffer;
139 _readdir(buffer);
140 return 0;
141 }
142 return 1;
143}
144/*---------------------------------------------------------------------------*/
145static int
146s_readdir(struct cfs_dir *p, struct cfs_dirent *e)
147{
148 int i;
149 int size;
150 int npos;
151 struct cpc_dir *cpcdir = (struct cpc_dir *)p;
PulkoMandy9e960752014-06-28 17:13:16 +0200152 unsigned char *ptr = cpcdir->ptr;
kthacker6de67752006-04-17 15:02:26 +0000153
154 if (ptr[0]!=0xff)
155 return 1;
156
157 ptr++;
158
159 npos = 0;
160 for (i=0; i<8; i++)
161 {
162 char ch = ptr[0]&0x07f;
163 ptr++;
164 e->name[npos] = ch;
165 npos++;
166 }
167 e->name[npos] = '.';
168 npos++;
169 for (i=0; i<3; i++)
170 {
171 char ch = ptr[0]&0x07f;
172 ptr++;
173 e->name[npos] = ch;
174 npos++;
175 }
176 e->name[npos] = '\0';
177
178 size = (ptr[0]&0x0ff) + ((ptr[1]&0x0ff)<<8);
179 size = size*1024;
180 ptr+=2;
181 e->size = size;
182 cpcdir->ptr = ptr;
183
184 return 0;
185
186/* 1 = if no more dir entries
187 0 = more dir entries */
188}
189/*---------------------------------------------------------------------------*/
190static int
191s_closedir(struct cfs_dir *p)
192{
193 struct cpc_dir *cpcdir = (struct cpc_dir *)p;
194 free(cpcdir->buffer);
195 return 1;
196}
197/*---------------------------------------------------------------------------*/