| 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 | #ifndef CAM_DRYOS_2_3_R39 |
|---|
| 53 | struct stat |
|---|
| 54 | { |
|---|
| 55 | unsigned long st_dev; //? |
|---|
| 56 | unsigned long st_ino; //? |
|---|
| 57 | unsigned short st_mode; //? |
|---|
| 58 | short st_nlink; //? |
|---|
| 59 | short st_uid; //? |
|---|
| 60 | short st_gid; //? |
|---|
| 61 | unsigned long st_atime; //? |
|---|
| 62 | unsigned long st_mtime; //? |
|---|
| 63 | unsigned long st_ctime; //? |
|---|
| 64 | unsigned long st_size; |
|---|
| 65 | long st_blksize; //? |
|---|
| 66 | long st_blocks; //? |
|---|
| 67 | unsigned char st_attrib; |
|---|
| 68 | int reserved1; // |
|---|
| 69 | int reserved2; // |
|---|
| 70 | int reserved3; // |
|---|
| 71 | int reserved4; // |
|---|
| 72 | int reserved5; // |
|---|
| 73 | int reserved6; // |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | #else |
|---|
| 77 | struct stat |
|---|
| 78 | { |
|---|
| 79 | unsigned long st_unknown_1; |
|---|
| 80 | unsigned long st_attrib; |
|---|
| 81 | unsigned long st_size; |
|---|
| 82 | unsigned long st_ctime; |
|---|
| 83 | unsigned long st_mtime; |
|---|
| 84 | unsigned long st_unknown_2; |
|---|
| 85 | }; |
|---|
| 86 | #endif//CAM_DRYOS_2_3_R39 |
|---|
| 87 | |
|---|
| 88 | #endif |
|---|
| 89 | |
|---|
| 90 | extern int rand(void); |
|---|
| 91 | extern void* srand(unsigned int seed); |
|---|
| 92 | |
|---|
| 93 | extern void qsort (void *__base, int __nelem, int __size, int (*__cmp)(const void *__e1, const void *__e2)); |
|---|
| 94 | |
|---|
| 95 | extern int isdigit(int c); |
|---|
| 96 | extern int isspace(int c); |
|---|
| 97 | extern int isalpha(int c); |
|---|
| 98 | extern int isupper(int c); |
|---|
| 99 | extern int islower(int c); |
|---|
| 100 | extern int ispunct(int c); |
|---|
| 101 | extern int isxdigit(int c); |
|---|
| 102 | extern int iscntrl(int c); |
|---|
| 103 | extern int isalnum(int c); |
|---|
| 104 | |
|---|
| 105 | extern long sprintf(char *s, const char *st, ...); |
|---|
| 106 | |
|---|
| 107 | extern long strlen(const char *s); |
|---|
| 108 | extern int strcmp(const char *s1, const char *s2); |
|---|
| 109 | extern int strncmp(const char *s1, const char *s2, long n); |
|---|
| 110 | extern char *strchr(const char *s, int c); |
|---|
| 111 | extern char *strcpy(char *dest, const char *src); |
|---|
| 112 | extern char *strncpy(char *dest, const char *src, long n); |
|---|
| 113 | extern char *strcat(char *dest, const char *app); |
|---|
| 114 | extern char *strrchr(const char *s, int c); |
|---|
| 115 | extern char *strpbrk(const char *s, const char *accept); |
|---|
| 116 | |
|---|
| 117 | extern long strtol(const char *nptr, char **endptr, int base); |
|---|
| 118 | extern unsigned long strtoul(const char *nptr, char **endptr, int base); |
|---|
| 119 | #define atoi(n) strtol((n),NULL,0) |
|---|
| 120 | |
|---|
| 121 | extern int tolower(int c); |
|---|
| 122 | extern int toupper(int c); |
|---|
| 123 | |
|---|
| 124 | extern void *malloc(long size); |
|---|
| 125 | extern void free(void *p); |
|---|
| 126 | extern void *umalloc(long size); |
|---|
| 127 | extern void ufree(void *p); |
|---|
| 128 | |
|---|
| 129 | extern void *memcpy(void *dest, const void *src, long n); |
|---|
| 130 | extern void *memset(void *s, int c, int n); |
|---|
| 131 | extern int memcmp(const void *s1, const void *s2, long n); |
|---|
| 132 | extern void *memchr(const void *s, int c, int n); |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | extern void SleepTask(long msec); |
|---|
| 136 | extern long taskLock(); |
|---|
| 137 | extern long taskUnlock(); |
|---|
| 138 | |
|---|
| 139 | extern int creat (const char *name, int flags); |
|---|
| 140 | extern int open (const char *name, int flags, int mode ); |
|---|
| 141 | extern int close (int fd); |
|---|
| 142 | extern int write (int fd, const void *buffer, long nbytes); |
|---|
| 143 | extern int read (int fd, void *buffer, long nbytes); |
|---|
| 144 | extern int lseek (int fd, long offset, int whence); |
|---|
| 145 | extern long mkdir(const char *dirname); |
|---|
| 146 | extern int rename(const char *oldname, const char *newname); |
|---|
| 147 | extern int chdir(char *pathname); |
|---|
| 148 | extern int remove(const char *name); |
|---|
| 149 | |
|---|
| 150 | // reverse engineered file struct. Appears to be valid for both vxworks and dryos |
|---|
| 151 | // don't use this directly unless you absolutely need to |
|---|
| 152 | // don't EVER try to create one yourself, as this isn't the full structure. |
|---|
| 153 | typedef struct FILE_S { |
|---|
| 154 | int fd; // used by Read/Write |
|---|
| 155 | unsigned len; // +4 verfied in Fseek_FileStream |
|---|
| 156 | int unk0; // +8 |
|---|
| 157 | unsigned pos; // +0xC verified in Fseek_FileStream |
|---|
| 158 | // unk1; // +0x10 |
|---|
| 159 | // unk2; // +0x14 |
|---|
| 160 | // io_buf; // +0x18 32k uncached allocated in Fopen_FileStream |
|---|
| 161 | // unk3; // +0x20 related to StartFileAccess_Sem |
|---|
| 162 | // ...name |
|---|
| 163 | } FILE; |
|---|
| 164 | |
|---|
| 165 | extern FILE *fopen(const char *filename, const char *mode); |
|---|
| 166 | extern long fclose(FILE *f); |
|---|
| 167 | extern long fread(void *buf, long elsize, long count, FILE *f); |
|---|
| 168 | extern long fwrite(const void *buf, long elsize, long count, FILE *f); |
|---|
| 169 | extern long fseek(FILE *file, long offset, long whence); |
|---|
| 170 | extern long fflush(FILE *file); |
|---|
| 171 | extern long feof(FILE *file); |
|---|
| 172 | extern long ftell(FILE *file); |
|---|
| 173 | extern char *fgets(char *buf, int n, FILE *f); |
|---|
| 174 | |
|---|
| 175 | /** |
|---|
| 176 | * No STUBS! |
|---|
| 177 | * You can't use these two directly from THUMB code (core), only from platform. |
|---|
| 178 | */ |
|---|
| 179 | extern int fprintf(FILE *fd, char*buf, ...); |
|---|
| 180 | extern int printf(char *buf, ...); |
|---|
| 181 | |
|---|
| 182 | extern void msleep(long msec); |
|---|
| 183 | extern long task_lock(); |
|---|
| 184 | extern long task_unlock(); |
|---|
| 185 | extern const char *task_name(int id); |
|---|
| 186 | int task_id_list_get(int *idlist,int size); |
|---|
| 187 | extern const char *strerror(int num); |
|---|
| 188 | // on vxworks we could find the actual errno, but this is easier to automate sig |
|---|
| 189 | // doesn't exist on dryos, but we stub it |
|---|
| 190 | extern int errnoOfTaskGet(int tid); |
|---|
| 191 | #define errno (errnoOfTaskGet(0)) |
|---|
| 192 | |
|---|
| 193 | #define DOS_ATTR_RDONLY 0x01 /* read-only file */ |
|---|
| 194 | #define DOS_ATTR_HIDDEN 0x02 /* hidden file */ |
|---|
| 195 | #define DOS_ATTR_SYSTEM 0x04 /* system file */ |
|---|
| 196 | #define DOS_ATTR_VOL_LABEL 0x08 /* volume label (not a file) */ |
|---|
| 197 | #define DOS_ATTR_DIRECTORY 0x10 /* entry is a sub-directory */ |
|---|
| 198 | #define DOS_ATTR_ARCHIVE 0x20 /* file subject to archiving */ |
|---|
| 199 | |
|---|
| 200 | #if !CAM_DRYOS |
|---|
| 201 | struct dirent { |
|---|
| 202 | char d_name[100]; |
|---|
| 203 | }; |
|---|
| 204 | #else |
|---|
| 205 | struct dirent { |
|---|
| 206 | char d_name[13]; |
|---|
| 207 | unsigned long unk1; |
|---|
| 208 | unsigned char attrib; |
|---|
| 209 | unsigned long size; |
|---|
| 210 | unsigned long time1; |
|---|
| 211 | unsigned long time2; |
|---|
| 212 | unsigned long time3; |
|---|
| 213 | }; |
|---|
| 214 | #endif |
|---|
| 215 | |
|---|
| 216 | // NOTE this is NOT the actual structure returned by dryos opendir! |
|---|
| 217 | typedef struct { |
|---|
| 218 | unsigned int fd; // first member is an fd from Open in dryos |
|---|
| 219 | unsigned int loc; |
|---|
| 220 | struct dirent dir; |
|---|
| 221 | } DIR; |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | extern DIR* opendir (const char* name); |
|---|
| 225 | extern struct dirent* readdir (DIR*); |
|---|
| 226 | extern int closedir (DIR*); |
|---|
| 227 | extern void rewinddir (DIR*); |
|---|
| 228 | extern int stat (const char *name, struct stat *pStat); |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | struct tm |
|---|
| 232 | { |
|---|
| 233 | int tm_sec; /* seconds after the minute - [0, 59] */ |
|---|
| 234 | int tm_min; /* minutes after the hour - [0, 59] */ |
|---|
| 235 | int tm_hour; /* hours after midnight - [0, 23] */ |
|---|
| 236 | int tm_mday; /* day of the month - [1, 31] */ |
|---|
| 237 | int tm_mon; /* months since January - [0, 11] */ |
|---|
| 238 | int tm_year; /* years since 1900 */ |
|---|
| 239 | int tm_wday; /* days since Sunday - [0, 6] */ |
|---|
| 240 | int tm_yday; /* days since January 1 - [0, 365] */ |
|---|
| 241 | int tm_isdst; /* Daylight Saving Time flag */ |
|---|
| 242 | }; |
|---|
| 243 | |
|---|
| 244 | typedef unsigned long time_t; |
|---|
| 245 | |
|---|
| 246 | extern struct tm * localtime(const unsigned long *_tod); |
|---|
| 247 | |
|---|
| 248 | struct utimbuf { |
|---|
| 249 | unsigned long actime; /* set the access time */ |
|---|
| 250 | unsigned long modtime; /* set the modification time */ |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | extern int utime(const char *file, struct utimbuf *newTimes); |
|---|
| 254 | extern unsigned long time(unsigned long *timer); |
|---|
| 255 | extern long strftime(char *s, unsigned long maxsize, const char *format, const struct tm *timp); |
|---|
| 256 | extern time_t mktime(struct tm *timp); |
|---|
| 257 | |
|---|
| 258 | extern int abs( int v ); |
|---|
| 259 | |
|---|
| 260 | #endif |
|---|