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.
25 extern int getsp(void); /* is provided in getsp.s */
27 /* Atari's fd indirection table */
29 extern char __fd_index[];
36 extern struct fd_t __fd_table[];
39 int main(int argc,char **argv)
51 printf("\nfilename: ");
52 x = fgets(buf,19,stdin);
55 printf("nothing read\n");
61 for (i=0; i<l; i++) printf("%02X ",*(x+i)); printf("\n");
65 printf("using filename \"%s\"\n",filename);
67 printf("now opening file... sp = %d\n",csp);
68 fd = open(filename,O_RDONLY);
72 printf("open failed: os: %d,\n\terrno: %d, sp = %d\n",x1,errno,csp);
76 printf("open success -- handle = $%x, sp = %d\n",fd,csp);
78 printf("fd_index:\n ");
79 for (i=0; i<12; i++) printf("%02X ",__fd_index[i]);
80 printf("\nfd_table:\n");
82 printf(" usa: %d, iocb: %02X, dev: %02X\n",
88 lr = read(fd,buf,16); /* read first 16 bytes */
91 printf("read failed: %d (sp = %d)\n",errno,csp);
97 printf("close failed: %d\n",errno);
102 printf("\n\nThe data read: (%d bytes, sp = %d)\n",lr,csp);
103 for (i=0; i<lr; i++) {
104 printf("%02X ",buf[i]);
105 if (!((i+1) & 7)) printf("\n");
107 printf("\n\npress return to exit...");