]> git.sur5r.net Git - cc65/blob - testcode/lib/ft.c
Include targetutil intermediates in dependency handling.
[cc65] / testcode / lib / ft.c
1 /*
2  * simple file i/o test
3  *
4  * 12-Jun-2000, Christian Groessler
5  *
6  * please compile with
7  *   cl65 -tsystem ft.c getsp.s -o ft.com
8  *
9  * The program asks for a filename (if it hasn't
10  * got one from argv). I then opens the file,
11  * reads the the first 16 bytes and displays them
12  * (as hex values).
13  * The values of sp (cc65 runtime stack pointer)
14  * are displayed at some places. The displayed
15  * value should always be the same.
16  */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <fcntl.h>
21 #include <errno.h>
22 #include <conio.h>
23 #include <unistd.h>
24
25 extern int getsp(void);  /* is provided in getsp.s */
26
27 #ifdef __ATARI__  /* Atari's fd indirection table */
28 extern char __fd_index[];
29 struct fd_t {
30   char usage;
31   char iocb;
32   char dev;
33   char flag;
34 };
35 extern struct fd_t __fd_table[];
36 #endif /* #ifdef __ATARI__ */
37
38 int main(int argc,char **argv)
39 {
40     char *filename,*x;
41     char buf[20];
42     int i,l,lr;
43     int fd;
44     int csp;
45
46     if (argc >= 2) {
47         filename = *(argv+1);
48     }
49     else {
50         printf("\nfilename: ");
51         x = fgets(buf,19,stdin);
52         printf("\n");
53         if (!x) {
54             printf("nothing read\n");
55             return(0);
56         }
57 #if 0
58         l = strlen(x);
59         printf("read: ");
60         for (i=0; i<l; i++) printf("%02X ",*(x+i)); printf("\n");
61 #endif
62         filename = x;
63     }
64     printf("using filename \"%s\"\n",filename);
65     csp = getsp();
66     printf("now opening file... sp = %d\n",csp);
67     fd = open(filename,O_RDONLY);
68     csp = getsp();
69     if (fd == -1) {
70         char x1 = _oserror;
71         printf("open failed: os: %d,\n\terrno: %d, sp = %d\n",x1,errno,csp);
72         cgetc();
73         return(0);
74     }
75     printf("open success -- handle = $%x, sp = %d\n",fd,csp);
76 #ifdef __ATARI__
77     printf("fd_index:\n ");
78     for (i=0; i<12; i++) printf("%02X ",__fd_index[i]);
79     printf("\nfd_table:\n");
80     for (i=0; i<8; i++) {
81         printf(" usa: %d, iocb: %02X, dev: %02X\n",
82                __fd_table[i].usage,
83                __fd_table[i].iocb,
84                __fd_table[i].dev);
85     }
86 #endif /* #ifdef __ATARI__ */
87     lr = read(fd,buf,16);  /* read first 16 bytes */
88     csp = getsp();
89     if (lr == -1) {
90         printf("read failed: %d (sp = %d)\n",errno,csp);
91         cgetc();
92         return(0);
93     }
94     l = close(fd);
95     if (l == -1) {
96         printf("close failed: %d\n",errno);
97         cgetc();
98         return(0);
99     }
100     csp = getsp();
101     printf("\n\nThe data read: (%d bytes, sp = %d)\n",lr,csp);
102     for (i=0; i<lr; i++) {
103         printf("%02X ",buf[i]);
104         if (!((i+1) & 7)) printf("\n");
105     }
106     printf("\n\npress return to exit...");
107     getchar();
108     return(0);
109 }