mcIO::mcIO(int port, int maxEntries) { int type, free, format; int rv; #ifdef AIOMC_DEBUG printf("mcIO constructor.\n"); #endif this->port = port; mcEntries = NULL; // Make sure memory card was detected mcGetInfo(port, 0, &type, &free, &format); mcSync(MC_WAIT, NULL, &rv); if((rv < -1)) //|| !format //Since we're not using XMC format is always 0 { status = AIO_STATE_ERROR; return; } mcEntries = (mcTable *)memalign(64, sizeof(mcTable) * maxEntries); if(!mcEntries) printf("Failed to allocate memory!"); // TODO: remove when not used anymore sprintf(devname, "mc%d:", port); status = 0; }
int McAccess::getInfo(int *type, int *free, int *format) { int res; WaitSema(_sema); mcGetInfo(_port, _slot, type, free, format); mcSync(0, NULL, &res); SignalSema(_sema); return res; }
int mcIO::freespace() { int type, free, format; int rv; mcGetInfo(port, 0, &type, &free, &format); mcSync(MC_WAIT, NULL, &rv); if(rv < -1) return rv; else return free; }
int main() { int fd, ret; int i; // Initialise SifInitRpc(0); LoadModules(); #ifdef TYPE_MC if(mcInit(MC_TYPE_MC) < 0) { printf("Failed to initialise memcard server!\n"); SleepThread(); } #else if(mcInit(MC_TYPE_XMC) < 0) { printf("Failed to initialise memcard server!\n"); SleepThread(); } #endif printf("\nMemory card library example code - by Sjeep\n\n"); // int mcGetInfo(int port, int slot, int* type, int* free, int* format); // // mcGetInfo retrieves memcard state info, such as the memcard type, free blocks and // the format status. // // mcGetInfo is passed pointers to three variables, which are filled upon completion // of the getinfo rpc command. The mcGetInfo return values are as follows: // // 0 : The same memory card has been connected since the last mcGetInfo call. // -1 : Switched to a formatted memory card. // -2 : Switched to an unformatted memory card. // -10 or less : The memory card could not be detected. // // NOTE: With the MCMAN/MCSERV, *format is always returned as 0 regardless of if // if the memcard is formatted or not. // Since this is the first call, -1 should be returned. mcGetInfo(0, 0, &mc_Type, &mc_Free, &mc_Format); mcSync(0, NULL, &ret); printf("mcGetInfo returned %d\n",ret); printf("Type: %d Free: %d Format: %d\n\n", mc_Type, mc_Free, mc_Format); // Assuming that the same memory card is connected, this should return 0 mcGetInfo(0,0,&mc_Type,&mc_Free,&mc_Format); mcSync(0, NULL, &ret); printf("mcGetInfo returned %d\n",ret); printf("Type: %d Free: %d Format: %d\n\n", mc_Type, mc_Free, mc_Format); // int mcGetDir(int port, int slot, char *name, unsigned mode, int maxent, mcTable* table); // // mcGetDir retrieves the directory structure of a specific path on the memory card. // // The filename is relative to the root of the memory card. Wildcards such as '*' and '?' // may be used. "maxent" is the maximum number of mcTable elements your array specified // by "table" can hold. The mc_getdir return values are as follows: // // 0 or more : The number of file entries that were obtained. // -2 : The memory card is unformatted // -4 : A non-existant path was specified in the "name" parameter // -10 or less : The memory card could not be detected. mcGetDir(0, 0, "/*", 0, ARRAY_ENTRIES - 10, mcDir); mcSync(0, NULL, &ret); printf("mcGetDir returned %d\n\nListing of root directory on memory card:\n\n", ret); for(i=0; i < ret; i++) { if(mcDir[i].attrFile & MC_ATTR_SUBDIR) printf("[DIR] %s\n", mcDir[i].name); else printf("%s - %d bytes\n", mcDir[i].name, mcDir[i].fileSizeByte); } // Check if existing save is present fd = fioOpen("mc0:PS2DEV/icon.sys", O_RDONLY); if(fd <= 0) { printf("\nNo previous save exists, creating...\n"); if((ret = CreateSave()) < 0) { printf("Failed to create save! Errorno: %d\n",ret); SleepThread(); } } else { printf("\nPrevious save exists, listing directory\n\n"); ret = mcGetDir(0, 0, "/PS2DEV/*", 0, ARRAY_ENTRIES, mcDir); printf("mcGetDir returned %d\n\n", ret); for(i=0; i < ret; i++) { if(mcDir[i].attrFile & MC_ATTR_SUBDIR) printf("[DIR] %s\n", mcDir[i].name); else printf("%s - %d bytes\n", mcDir[i].name, mcDir[i].fileSizeByte); } } // Return to the browser, so you can see the PS2Dev icon :) SifExitRpc(); return 0; }