4 * 12-Jun-2000, Christian Groessler
7 * cl65 -tsystem ft.c getsp.s -o ft.com
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
13 * The values of sp (cc65 runtime stack pointer)
14 * are displayed at some places. The displayed
15 * value should always be the same.
24 extern int getsp(void); /* is provided in getsp.s */
26 #ifdef __ATARI__ /* Atari's fd indirection table */
27 extern char __fd_index[];
34 extern struct fd_t __fd_table[];
35 #endif /* #ifdef __ATARI__ */
37 int main(int argc,char **argv)
49 printf("\nfilename: ");
50 x = fgets(buf,19,stdin);
53 printf("nothing read\n");
59 for (i=0; i<l; i++) printf("%02X ",*(x+i)); printf("\n");
63 printf("using filename \"%s\"\n",filename);
65 printf("now opening file... sp = %d\n",csp);
66 fd = open(filename,O_RDONLY);
70 printf("open failed: os: %d,\n\terrno: %d, sp = %d\n",x1,errno,csp);
74 printf("open success -- handle = $%x, sp = %d\n",fd,csp);
76 printf("fd_index:\n ");
77 for (i=0; i<12; i++) printf("%02X ",__fd_index[i]);
78 printf("\nfd_table:\n");
80 printf(" usa: %d, iocb: %02X, dev: %02X\n",
85 #endif /* #ifdef __ATARI__ */
86 lr = read(fd,buf,16); /* read first 16 bytes */
89 printf("read failed: %d (sp = %d)\n",errno,csp);
95 printf("close failed: %d\n",errno);
100 printf("\n\nThe data read: (%d bytes, sp = %d)\n",lr,csp);
101 for (i=0; i<lr; i++) {
102 printf("%02X ",buf[i]);
103 if (!((i+1) & 7)) printf("\n");
105 printf("\n\npress return to exit...");