Path: chuka.playstation.co.uk!news From: James Russell Newsgroups: scee.yaroze.profile Subject: Re: memory card Date: Mon, 08 Jun 1998 10:07:36 +0100 Organization: Sony Computer Entertainment Europe Lines: 119 Message-ID: <357BA9D8.6BE410E3@scee.sony.co.uk> References: <3577AC68.1B73@city.ac.uk> <35789962.1338365@news.playstation.co.uk> NNTP-Posting-Host: camfw01.millennium.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.05 [en] (Win95; I) > If so please post them somewhere so the rest of us who are too lazy to > figure out how to access the memory cards can rip the code off and > possibly help you with it !! Here's some code snippets from my memory card editor. There's directory reading and file read/writing. Cheers, James // Edit file ---------------------------------------------------- void editFile(int fileNum) { int handle; CLEAR; sprintf(strbuffer,"bu10:%s",dirents[fileNum].name); handle = open(strbuffer, O_RDWR); if(handle == -1) { println("Could not open this file!"); println("Press Start to continue."); DRAW; while( GetPad() != PADstart); return; } if( (data = (char*)malloc(dirents[fileNum].size)) == 0) { close(handle); println("Could not allocate enough memory to hold this file!"); println("Press Start to continue."); DRAW; while( GetPad() != PADstart); return; } if(read(handle,data,dirents[fileNum].size) == -1) { close(handle); free(data); println("Error reading from memory card!"); println("Press Start to continue."); DRAW; while( GetPad() != PADstart); return; } size = dirents[fileNum].size; if(editData()) { printat(5,YSIZE-2,"SAVING.... Please wait."); DRAW; CLEAR; CLEARATTR; lseek(handle,0,SEEK_SET); if(write(handle,data,size) == -1) { println("Error writing to memory card!"); println("Press Start to continue."); DRAW; while( GetPad() != PADstart); } } close(handle); free(data); } int numFiles = 0; struct DIRENTRY dirents[15]; void main(void) { struct DIRENTRY file, *filep; PadInit(); initialiseDisplay(); initialiseTextMode(); switch(TestCard(1)) { case 0: printf("\n\nNo memory card present in slot 2.\n"); printf(" Exiting...\n"); break; case 1: // Card or new card detected. case 2: filep = firstfile("bu10:",&file); if(filep == 0) { printf("Can't open card directory or there are no files!\n"); printf(" Exiting...\n"); exit(0); } do { memcpy(&dirents[numFiles++],&file,sizeof(struct DIRENTRY)); } while(nextfile(&file) != 0); mainMenu(); break; case 3: printf("\n\nCommunication or card abnormality detected in slot 2.\n"); printf(" Exiting...\n"); break; case 4: printf("\n\nUninitialised card detected in slot 2.\n"); printf(" Exiting...\n"); break; default: printf("\n\nUnknown error from TestCard(1)\n"); printf(" Exiting...\n"); break; } ResetGraph(1); uninitialiseTextMode(); exit(0); }