//--------------------------------------------------------------------------------- int main() { //--------------------------------------------------------------------------------- VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); PAD_Init(); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); console_init(xfb,20,64,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*2); VIDEO_SetNextFramebuffer(xfb); printf("Memory Card Demo\n\n"); while (1) { printf("Insert A card in slot B and press A\n"); do { PAD_ScanPads(); if (PAD_ButtonsDown(0) & PAD_BUTTON_START) PSOreload(); VIDEO_WaitVSync(); } while ( !(PAD_ButtonsDown(0) & PAD_BUTTON_A)); printf("Mounting card ...\n"); CARD_Init("DEMO","00"); int SlotB_error = CARD_Mount(CARD_SLOTB, SysArea, card_removed); printf("slot B code %d\n",SlotB_error); int CardError; if (SlotB_error >= 0) { unsigned int SectorSize = 0; CARD_GetSectorSize(CARD_SLOTB,&SectorSize); printf("Sector size is %d bytes.\n\n",SectorSize); char *CardBuffer = (char *)memalign(32,SectorSize); printf("Starting directory\n"); card_dir CardDir; card_file CardFile; CardError = CARD_FindFirst(CARD_SLOTB, &CardDir, true); bool found = false; while ( CARD_ERROR_NOFILE != CardError ) { printf("%s %s %s\n",CardDir.filename,CardDir.gamecode,CardDir.company); CardError = CARD_FindNext(&CardDir); if ( 0 == strcmp (DemoFileName, (char *)CardDir.filename)) found = true; }; printf("Finished directory\n\n"); if (found) { printf("Test file contains :- \n"); CardError = CARD_Open(CARD_SLOTB ,DemoFileName,&CardFile); CARD_Read(&CardFile,CardBuffer,SectorSize,0); printf("%s\n",CardBuffer); CARD_Close(&CardFile); CARD_Delete(CARD_SLOTB,DemoFileName); } else { printf("writing test file ...\n"); CardError = CARD_Create(CARD_SLOTB ,DemoFileName,SectorSize,&CardFile); if (0 == CardError) { time_t gc_time; gc_time = time(NULL); sprintf(CardBuffer,"This text was written by MemCardDemo\nat %s\n",ctime(&gc_time)); CardError = CARD_Write(&CardFile,CardBuffer,SectorSize,0); CardError = CARD_Close(&CardFile); } } CARD_Unmount(CARD_SLOTB); free(CardBuffer); } } }
//--------------------------------------------------------------------------------- int main() { //--------------------------------------------------------------------------------- VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); PAD_Init(); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); console_init(xfb,20,64,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*2); VIDEO_SetNextFramebuffer(xfb); int slot = CARD_SLOTA; u32 i; int tomenu = 0; u16 buttonsDown; u8 pressed = 0; int filesize; int bytesdone = 0; while(1){ VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK); listpos=0; tomenu=0; pressed = 0; printf("\x1b[2;0H"); printf("Memory Card Loader 0.2 by Suloku\n"); printf("********************************\n\n"); printf("Press A or B button to select a slot.\n"); while (1){ PAD_ScanPads(); buttonsDown=PAD_ButtonsDown(0); if (buttonsDown & PAD_BUTTON_A){ slot = CARD_SLOTA; pressed = 1;} if (buttonsDown & PAD_BUTTON_B){ slot = CARD_SLOTB; pressed = 1;} if (buttonsDown & PAD_BUTTON_START){ PSOreload();} VIDEO_WaitVSync(); if (pressed) break; } printf("Mounting card in slot %s...", (slot==0?"A":"B")); int Slot_error = MountCard(slot); printf("code %d. ",Slot_error); int CardError; if (Slot_error >= 0) { printf("Sector size is %d bytes.\n",sectsize); printf("Reading memory card files..."); card_dir CardDir; card_file CardFile; CardError = CARD_FindFirst(slot, &CardDir, true); cardcount = 0; while ( CARD_ERROR_NOFILE != CardError ) { if (strncmp ("DOLX", (char *)CardDir.gamecode, 4) == 0){ memcpy (&CardList[cardcount], &CardDir, sizeof (card_dir)); cardcount++; } CardError = CARD_FindNext(&CardDir); } printf("finished.\n\n"); if (cardcount == 0){ printf("No dol files in memory card in slot %s\n\n", (slot==0?"A":"B")); waitA(); }else{ while (1){ pressed = 0; VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK); printf("\x1b[2;0H"); printf("Memory Card Loader 0.1 by Suloku\n"); printf("********************************\n\n"); printf("Dol files in memory card %s: %d\n\n", (slot==0?"A":"B"), cardcount); if (listpos!=0) printf ("/\\/\\\n"); else printf(" \n"); for (i=listpos; i<listpos+10; i++){ printf (" "); if (i==listpos) printf ("-->"); printf("%s \n",CardList[i].filename); if (i>= cardcount )break; } printf("\x1b[18;0H"); if (cardcount >=10 && listpos != cardcount-1) printf ("\\/\\/\n"); else{ printf(" \n"); } printf("\n\t\tPress B button to go back to slot select.\n\n"); while (1){ PAD_ScanPads(); buttonsDown=PAD_ButtonsDown(0); if (buttonsDown & PAD_BUTTON_UP){ listpos--; if (listpos <0) listpos = 0; pressed = 1; } if (buttonsDown & PAD_BUTTON_DOWN){ listpos++; if (listpos >= cardcount-1) listpos = cardcount-1; pressed = 1; } if (buttonsDown & PAD_BUTTON_LEFT){ listpos-=10; if (listpos <0) listpos = 0; pressed = 1; } if (buttonsDown & PAD_BUTTON_RIGHT){ listpos+=10; if (listpos >= cardcount-1) listpos = cardcount-1; pressed = 1; } if (buttonsDown & PAD_BUTTON_A){ printf("Loading %s...\n", CardList[listpos].filename); /*** Initialise for this company & gamecode ***/ //add null char company[2] = gamecode[4] = 0; memcpy (company, &CardList[listpos].company, 2); memcpy (gamecode, &CardList[listpos].gamecode, 4); CARD_SetCompany(company); CARD_SetGamecode(gamecode); CardError = CARD_Open(slot ,(char*)&CardList[listpos].filename,&CardFile); if (CardError < 0) { CARD_Unmount (slot); printf("Error %d while opening file.\n", CardError); waitA(); }else{ /*** Copy the file contents to the buffer ***/ filesize = CardFile.len; u8 *dolbuffer = (u8*) memalign(32, filesize); while (bytesdone < filesize) { CardError= CARD_Read(&CardFile, dolbuffer+bytesdone, sectsize, bytesdone); bytesdone += sectsize; } CARD_Close(&CardFile); CARD_Unmount(slot); //boot dol //This will load cli_buffer and cli_size getclifrombuffer(dolbuffer, filesize); if (cli_buffer!=NULL){ // Build a command line to pass to the DOL int argc2 = 0; char *argv2[1024]; //add a terminating null character for last argument if needed if (cli_buffer[cli_size-1] != '\0'){ cli_buffer[cli_size] = '\0'; cli_size += 1; } // CLI parse char bootpath[CARD_FILENAMELEN+10]; sprintf(bootpath, "mc%d:/%s", slot, (char*)&CardList[listpos].filename); argv2[argc2] = bootpath; argc2++; // First argument is at the beginning of the file if(cli_buffer[0] != '\r' && cli_buffer[0] != '\n') { argv2[argc2] = cli_buffer; argc2++; } // Search for the others after each newline int i; for(i = 0; i < cli_size; i++) { if(cli_buffer[i] == '\r' || cli_buffer[i] == '\n') { cli_buffer[i] = '\0'; } else if(cli_buffer[i - 1] == '\0') { argv2[argc2] = cli_buffer + i; argc2++; if(argc2 >= 1024) break; } } DOLtoARAM(dolbuffer, argc2, argc2 == 0 ? NULL : argv2); }else{ DOLtoARAM(dolbuffer, 0, NULL); } //If we get here dol was invalid if(dolbuffer != NULL) free(dolbuffer); printf("Not a valid dol file.\n"); waitA(); tomenu = 1; } pressed = 1; } if (buttonsDown & PAD_BUTTON_B){ pressed = 1;tomenu=1;} if (buttonsDown & PAD_BUTTON_START){ PSOreload();} VIDEO_WaitVSync(); if (pressed) break; } if (tomenu) break; } } CARD_Unmount(slot); }else{ printf("\n\nCan't mount card in slot %s!\n", (slot==0?"A":"B")); waitA(); } } return 0; }