| 1 | #include "camera.h" |
|---|
| 2 | |
|---|
| 3 | #ifndef STDLIB_H |
|---|
| 4 | #define STDLIB_H |
|---|
| 5 | |
|---|
| 6 | #define NULL ((void*)0) |
|---|
| 7 | |
|---|
| 8 | #define SEEK_SET 0 |
|---|
| 9 | #define SEEK_CUR 1 |
|---|
| 10 | #define SEEK_END 2 |
|---|
| 11 | |
|---|
| 12 | #define O_RDONLY 0 |
|---|
| 13 | #define O_WRONLY 1 |
|---|
| 14 | #define O_RDWR 2 |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #if !CAM_DRYOS |
|---|
| 18 | |
|---|
| 19 | #define O_TRUNC 0x400 |
|---|
| 20 | #define O_CREAT 0x200 |
|---|
| 21 | |
|---|
| 22 | struct stat |
|---|
| 23 | { |
|---|
| 24 | unsigned long st_dev; /* device ID number */ |
|---|
| 25 | unsigned long st_ino; /* file serial number */ |
|---|
| 26 | unsigned short st_mode; /* file mode (see below) */ |
|---|
| 27 | short st_nlink; /* number of links to file */ |
|---|
| 28 | short st_uid; /* user ID of file's owner */ |
|---|
| 29 | short st_gid; /* group ID of file's group */ |
|---|
| 30 | unsigned long st_rdev; /* device ID, only if special file */ |
|---|
| 31 | unsigned long st_size; /* size of file, in bytes */ |
|---|
| 32 | unsigned long st_atime; /* time of last access */ |
|---|
| 33 | unsigned long st_mtime; /* time of last modification */ |
|---|
| 34 | unsigned long st_ctime; /* time of last change of file status */ |
|---|
| 35 | long st_blksize; |
|---|
| 36 | long st_blocks; |
|---|
| 37 | unsigned char st_attrib; /* file attribute byte (dosFs only) */ |
|---|
| 38 | int reserved1; /* reserved for future use */ |
|---|
| 39 | int reserved2; /* reserved for future use */ |
|---|
| 40 | int reserved3; /* reserved for future use */ |
|---|
| 41 | int reserved4; /* reserved for future use */ |
|---|
| 42 | int reserved5; /* reserved for future use */ |
|---|
| 43 | int reserved6; /* reserved for future use */ |
|---|
| 44 | }; |
|---|
| 45 | |
|---|
| 46 | #else |
|---|
| 47 | |
|---|
| 48 | #define O_APPEND 0x8 // ok for dryos, vx? |
|---|
| 49 | #define O_TRUNC 0x200 |
|---|
| 50 | #define O_CREAT 0x100 |
|---|
| 51 | |
|---|
| 52 | struct stat |
|---|
| 53 | { |
|---|
| 54 | unsigned long st_dev; //? |
|---|
| 55 | unsigned long st_ino; //? |
|---|
| 56 | unsigned short st_mode; //? |
|---|
| 57 | short st_nlink; //? |
|---|
| 58 | short st_uid; //? |
|---|
| 59 | short st_gid; //? |
|---|
| 60 | unsigned long st_atime; //? |
|---|
| 61 | unsigned long st_mtime; //? |
|---|
| 62 | unsigned long st_ctime; //? |
|---|
| 63 | unsigned long st_size; |
|---|
| 64 | long st_blksize; //? |
|---|
| 65 | long st_blocks; //? |
|---|
| 66 | unsigned char st_attrib; |
|---|
| 67 | int reserved1; // |
|---|
| 68 | int reserved2; // |
|---|
| 69 | int reserved3; // |
|---|
| 70 | int reserved4; // |
|---|
| 71 | int reserved5; // |
|---|
| 72 | int reserved6; // |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | #endif |
|---|
| 76 | |
|---|
| 77 | extern int rand(void); |
|---|
| 78 | extern void* srand(unsigned int seed); |
|---|
| 79 | |
|---|
| 80 | extern void qsort (void *__base, int __nelem, int __size, int (*__cmp)(const void *__e1, const void *__e2)); |
|---|
| 81 | |
|---|
| 82 | extern int isdigit(int c); |
|---|
| 83 | extern int isspace(int c); |
|---|
| 84 | extern int isalpha(int c); |
|---|
| 85 | extern int isupper(int c); |
|---|
| 86 | extern int islower(int c); |
|---|
| 87 | extern int ispunct(int c); |
|---|
| 88 | extern int isxdigit(int c); |
|---|
| 89 | |
|---|
| 90 | extern long sprintf(char *s, const char *st, ...); |
|---|
| 91 | |
|---|
| 92 | extern long strlen(const char *s); |
|---|
| 93 | extern int strcmp(const char *s1, const char *s2); |
|---|
| 94 | extern int strncmp(const char *s1, const char *s2, long n); |
|---|
| 95 | extern char *strchr(const char *s, int c); |
|---|
| 96 | extern char *strcpy(char *dest, const char *src); |
|---|
| 97 | extern char *strncpy(char *dest, const char *src, long n); |
|---|
| 98 | extern char *strcat(char *dest, const char *app); |
|---|
| 99 | extern char *strrchr(const char *s, int c); |
|---|
| 100 | extern char *strpbrk(const char *s, const char *accept); |
|---|
| 101 | |
|---|
| 102 | extern long strtol(const char *nptr, char **endptr, int base); |
|---|
| 103 | extern unsigned long strtoul(const char *nptr, char **endptr, int base); |
|---|
| 104 | #define atoi(n) strtol((n),NULL,0) |
|---|
| 105 | |
|---|
| 106 | extern int tolower(int c); |
|---|
| 107 | extern int toupper(int c); |
|---|
| 108 | |
|---|
| 109 | extern void *malloc(long size); |
|---|
| 110 | extern void free(void *p); |
|---|
| 111 | extern void *umalloc(long size); |
|---|
| 112 | extern void ufree(void *p); |
|---|
| 113 | |
|---|
| 114 | extern void *memcpy(void *dest, const void *src, long n); |
|---|
| 115 | extern void *memset(void *s, int c, int n); |
|---|
| 116 | extern int memcmp(const void *s1, const void *s2, long n); |
|---|
| 117 | extern void *memchr(const void *s, int c, int n); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | extern void SleepTask(long msec); |
|---|
| 121 | extern long taskLock(); |
|---|
| 122 | extern long taskUnlock(); |
|---|
| 123 | |
|---|
| 124 | extern long Fopen_Fut(const char *filename, const char *mode); |
|---|
| 125 | extern long Fclose_Fut(long file); |
|---|
| 126 | extern long Fread_Fut(void *buf, long elsize, long count, long f); |
|---|
| 127 | extern long Fwrite_Fut(const void *buf, long elsize, long count, long f); |
|---|
| 128 | extern long Fseek_Fut(long file, long offset, long whence); |
|---|
| 129 | // TODO can we just use these all the time ? |
|---|
| 130 | extern long RenameFile_Fut(const char *oldname, const char *newname); |
|---|
| 131 | extern long MakeDirectory_Fut(const char *name); |
|---|
| 132 | extern long DeleteFile_Fut(const char *name); |
|---|
| 133 | extern long Feof_Fut(long file); |
|---|
| 134 | extern long Fflush_Fut(long file); |
|---|
| 135 | extern char *Fgets_Fut(char *buf, int n, long f); |
|---|
| 136 | |
|---|
| 137 | extern int creat (const char *name, int flags); |
|---|
| 138 | extern int open (const char *name, int flags, int mode ); |
|---|
| 139 | extern int close (int fd); |
|---|
| 140 | extern int write (int fd, const void *buffer, long nbytes); |
|---|
| 141 | extern int read (int fd, void *buffer, long nbytes); |
|---|
| 142 | extern int lseek (int fd, long offset, int whence); |
|---|
| 143 | extern long mkdir(const char *dirname); |
|---|
| 144 | |
|---|
| 145 | // reverse engineered file struct. Appears to be valid for both vxworks and dryos |
|---|
| 146 | // don't use this directly unless you absolutely need to |
|---|
| 147 | // don't EVER try to create one yourself, as this isn't the full structure. |
|---|
| 148 | typedef struct FILE_S { |
|---|
| 149 | int fd; // used by Read/Write |
|---|
| 150 | unsigned len; // +4 verfied in Fseek_FileStream |
|---|
| 151 | int unk0; // +8 |
|---|
| 152 | unsigned pos; // +0xC verified in Fseek_FileStream |
|---|
| 153 | // unk1; // +0x10 |
|---|
| 154 | // unk2; // +0x14 |
|---|
| 155 | // io_buf; // +0x18 32k uncached allocated in Fopen_FileStream |
|---|
| 156 | // unk3; // +0x20 related to StartFileAccess_Sem |
|---|
| 157 | // ...name |
|---|
| 158 | } FILE; |
|---|
| 159 | // these tiny inlines provide type safety, and should optimize away |
|---|
| 160 | static inline FILE *fopen(const char *filename, const char *mode) { |
|---|
| 161 | return (FILE *)Fopen_Fut(filename,mode); |
|---|
| 162 | } |
|---|
| 163 | static inline long fclose(FILE *f) { |
|---|
| 164 | return Fclose_Fut((long)f); |
|---|
| 165 | } |
|---|
| 166 | static inline long fread(void *buf, long elsize, long count, FILE *f) { |
|---|
| 167 | return Fread_Fut(buf,elsize,count,(long)f); |
|---|
| 168 | } |
|---|
| 169 | static inline long fwrite(const void *buf, long elsize, long count, FILE *f) { |
|---|
| 170 | return Fwrite_Fut(buf,elsize,count,(long)f); |
|---|
| 171 | } |
|---|
| 172 | static inline long fseek(FILE *file, long offset, long whence) { |
|---|
| 173 | return Fseek_Fut((long)file,offset,whence); |
|---|
| 174 | } |
|---|
| 175 | static inline long fflush(FILE *file) { |
|---|
| 176 | return Fflush_Fut((long)file); |
|---|
| 177 | } |
|---|
| 178 | static inline long feof(FILE *file) { |
|---|
| 179 | return Feof_Fut((long)file); |
|---|
| 180 | } |
|---|
| 181 | static inline long ftell(FILE *file) { |
|---|
| 182 | if(!file) return -1; |
|---|
| 183 | return file->pos; |
|---|
| 184 | } |
|---|
| 185 | static inline char *fgets(char *buf, int n, FILE *f) { |
|---|
| 186 | return Fgets_Fut(buf,n,(int)f); |
|---|
| 187 | } |
|---|
| 188 | #define fdelete(a) DeleteFile_Fut(a) |
|---|
| 189 | /** |
|---|
| 190 | * No STUBS! |
|---|
| 191 | * You can't use these two directly from THUMB code (core), only from platform. |
|---|
| 192 | */ |
|---|
| 193 | extern int fprintf(FILE *fd, char*buf, ...); |
|---|
| 194 | extern int printf(char *buf, ...); |
|---|
| 195 | |
|---|
| 196 | extern void msleep(long msec); |
|---|
| 197 | extern long task_lock(); |
|---|
| 198 | extern long task_unlock(); |
|---|
| 199 | extern const char *task_name(int id); |
|---|
| 200 | int task_id_list_get(int *idlist,int size); |
|---|
| 201 | extern const char *strerror(int num); |
|---|
| 202 | // on vxworks we could find the actual errno, but this is easier to automate sig |
|---|
| 203 | // doesn't exist on dryos, but we stub it |
|---|
| 204 | extern int errnoOfTaskGet(int tid); |
|---|
| 205 | #define errno (errnoOfTaskGet(0)) |
|---|
| 206 | |
|---|
| 207 | #define DOS_ATTR_RDONLY 0x01 /* read-only file */ |
|---|
| 208 | #define DOS_ATTR_HIDDEN 0x02 /* hidden file */ |
|---|
| 209 | #define DOS_ATTR_SYSTEM 0x04 /* system file */ |
|---|
| 210 | #define DOS_ATTR_VOL_LABEL 0x08 /* volume label (not a file) */ |
|---|
| 211 | #define DOS_ATTR_DIRECTORY 0x10 /* entry is a sub-directory */ |
|---|
| 212 | #define DOS_ATTR_ARCHIVE 0x20 /* file subject to archiving */ |
|---|
| 213 | |
|---|
| 214 | #if !CAM_DRYOS |
|---|
| 215 | struct dirent { |
|---|
| 216 | char d_name[100]; |
|---|
| 217 | }; |
|---|
| 218 | #else |
|---|
| 219 | struct dirent { |
|---|
| 220 | char d_name[13]; |
|---|
| 221 | unsigned long unk1; |
|---|
| 222 | unsigned char attrib; |
|---|
| 223 | unsigned long size; |
|---|
| 224 | unsigned long time1; |
|---|
| 225 | unsigned long time2; |
|---|
| 226 | unsigned long time3; |
|---|
| 227 | }; |
|---|
| 228 | #endif |
|---|
| 229 | |
|---|
| 230 | typedef struct { |
|---|
| 231 | unsigned int fd; |
|---|
| 232 | unsigned int loc; |
|---|
| 233 | struct dirent dir; |
|---|
| 234 | } DIR; |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | extern DIR* opendir (const char* name); |
|---|
| 239 | extern struct dirent* readdir (DIR*); |
|---|
| 240 | extern int closedir (DIR*); |
|---|
| 241 | extern void rewinddir (DIR*); |
|---|
| 242 | extern int stat (const char *name, struct stat *pStat); |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | struct tm |
|---|
| 246 | { |
|---|
| 247 | int tm_sec; /* seconds after the minute - [0, 59] */ |
|---|
| 248 | int tm_min; /* minutes after the hour - [0, 59] */ |
|---|
| 249 | int tm_hour; /* hours after midnight - [0, 23] */ |
|---|
| 250 | int tm_mday; /* day of the month - [1, 31] */ |
|---|
| 251 | int tm_mon; /* months since January - [0, 11] */ |
|---|
| 252 | int tm_year; /* years since 1900 */ |
|---|
| 253 | int tm_wday; /* days since Sunday - [0, 6] */ |
|---|
| 254 | int tm_yday; /* days since January 1 - [0, 365] */ |
|---|
| 255 | int tm_isdst; /* Daylight Saving Time flag */ |
|---|
| 256 | }; |
|---|
| 257 | |
|---|
| 258 | typedef unsigned long time_t; |
|---|
| 259 | |
|---|
| 260 | extern struct tm * localtime(const unsigned long *_tod); |
|---|
| 261 | |
|---|
| 262 | extern int rename(const char *oldname, const char *newname); |
|---|
| 263 | extern int chdir(char *pathname); |
|---|
| 264 | extern int remove(const char *name); |
|---|
| 265 | #ifdef FS_USE_FUT |
|---|
| 266 | #define mkdir(x) MakeDirectory_Fut(x) |
|---|
| 267 | #define rename(x,y) RenameFile_Fut(x,y) |
|---|
| 268 | #define remove(x) DeleteFile_Fut(x) |
|---|
| 269 | #endif |
|---|
| 270 | struct utimbuf { |
|---|
| 271 | unsigned long actime; /* set the access time */ |
|---|
| 272 | unsigned long modtime; /* set the modification time */ |
|---|
| 273 | }; |
|---|
| 274 | |
|---|
| 275 | extern int utime(const char *file, struct utimbuf *newTimes); |
|---|
| 276 | extern unsigned long time(unsigned long *timer); |
|---|
| 277 | extern long strftime(char *s, unsigned long maxsize, const char *format, const struct tm *timp); |
|---|
| 278 | extern time_t mktime(struct tm *timp); |
|---|
| 279 | |
|---|
| 280 | static inline int abs( int v ) { |
|---|
| 281 | return v<0 ? -v : v; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | #endif |
|---|