#include #include #include #include "padread.h" #define BUFSIZE 8192 /*----------------------------------------------------------------------------*/ /* let's have a look at what's in the card slots */ /*----------------------------------------------------------------------------*/ main() { PADVARS p; /* pad variables */ struct DIRENTRY entry, /* file entry */ *d; /* for end of files check */ long done=0, /* flag for getting out */ file=0, /* current file number */ slot=1, /* what card slot */ where=-1, /* position within file */ i; unsigned char *name="bu10:*", /* card slots file names */ fname[26], /* file name */ fbuffer[BUFSIZE]; /* read buffer */ int fd; /* for open */ GetPadBuf(&(p.bb0),&(p.bb1)); /* set addresses */ PadRead(&p); /* initialise */ p.Previous=p.PadData; /* no change */ d=firstfile(name,&entry); /* go to first one */ while(!done) /* while not done */ { /*----------------------------------------------------------------------------*/ /* if valid entry found print info */ /*----------------------------------------------------------------------------*/ if(d) { printf("\nSlot %d File %d\n",slot+1,file+1); disp(&entry); d=0; } /*----------------------------------------------------------------------------*/ /* wait for some changes in pad pattern */ /*----------------------------------------------------------------------------*/ if(PadRead(&p)) /* when changed */ { /*----------------------------------------------------------------------------*/ /* go to next file */ /*----------------------------------------------------------------------------*/ if(p.Pressed&PADLup) { file++; /* assume there's more */ d=nextfile(&entry); /* try going to next one */ if(!d) { file--; /* it was the last file */ printf("last file\n"); } where=-1; /* buffer dirty */ } /*----------------------------------------------------------------------------*/ /* go to previous file */ /*----------------------------------------------------------------------------*/ if(p.Pressed&PADLdown) { if(file!=0) /* 1st file ? */ { file--; /* one step backwards */ d=firstfile(name,&entry); /* back to first one */ i=0; /* initialise counter */ while(i++!=file) d=nextfile(&entry); /* sequential seek */ where=-1; /* buffer dirty */ } else printf("first file\n"); } /*----------------------------------------------------------------------------*/ /* change card slot */ /*----------------------------------------------------------------------------*/ if(p.Pressed&PADLleft || p.Pressed&PADLright) { if(p.Pressed&PADLleft) slot=0; /* set slot # */ else slot=1; *(name+2)='0'+(char)slot; /* set name */ file=0; /* 1st file */ d=firstfile(name,&entry); /* find info */ where=-1; /* buffer dirty */ if(!d) printf("\nSlot %d ??????????\n",slot+1); } /*----------------------------------------------------------------------------*/ /* display file content */ /*----------------------------------------------------------------------------*/ if(p.Pressed&PADRright) { strncpy(fname,name,5); /* bux0: */ strncpy(&fname[5],entry.name,21); /* entry name */ fd=open(fname,O_RDONLY); /* open it */ if(fd>0) /* successful ? */ { printf("\nreading...\n"); i=read(fd,&fbuffer[0],BUFSIZE); /* fill buffer */ close(fd); /* close file */ where=0; /* buffer at start */ dump(&fbuffer[where],where); /* dump 1st block */ } } /*----------------------------------------------------------------------------*/ /* display current file info */ /*----------------------------------------------------------------------------*/ if(p.Pressed&PADRleft) d=(struct DIRENTRY*)1; /*----------------------------------------------------------------------------*/ /* move forward within file */ /*----------------------------------------------------------------------------*/ if(p.Pressed&PADRup && where>=0) { if(where=0) { if(where>0) /* first block ? */ { where-=256; /* previous block */ dump(&fbuffer[where],where); } } /*----------------------------------------------------------------------------*/ /* should we get out ? */ /*----------------------------------------------------------------------------*/ if(p.Pressed&PADselect) done=1; } } }