void screenInit() { //Grab the buffer size for each screen (TV and gamepad) int buf0_size = OSScreenGetBufferSizeEx(0); int buf1_size = OSScreenGetBufferSizeEx(1); __os_snprintf(log_buf, 0x400, "Screen sizes %x, %x\n", buf0_size, buf1_size); OSReport(log_buf); //Set the buffer area. screenBuffer = MEM1_alloc(buf0_size + buf1_size, 0x40); __os_snprintf(log_buf, 0x400, "Allocated screen buffers at %x\n", screenBuffer); OSReport(log_buf); OSScreenSetBufferEx(0, screenBuffer); OSScreenSetBufferEx(1, (screenBuffer + buf0_size)); OSReport("Set screen buffers\n"); OSScreenEnableEx(0, 1); OSScreenEnableEx(1, 1); //Clear both framebuffers. for (int ii = 0; ii < 2; ii++) { fillScreen(0,0,0,0); flipBuffers(); } }
// Draw the title bar and the main guy void drawtitle(struct cGlobals *caveGlobals) { __os_snprintf(caveGlobals->player1, 8, "@"); __os_snprintf(caveGlobals->titlebar1, 128, "Food: HP: / == C@VE == Feed Dog With + "); __os_snprintf(caveGlobals->titlebar3, 128, " %d %d %d ", caveGlobals->food, caveGlobals->curhealth, caveGlobals->maxhealth ); // X+Y for debug // __os_snprintf(caveGlobals->titlebar2, 128, "X %d / Y %d", caveGlobals->row, caveGlobals->col); __os_snprintf(caveGlobals->mystat, 64, " "); drawString(-4, -1, caveGlobals->titlebar1); drawString(-4, -1, caveGlobals->titlebar3); drawString(46, 17, caveGlobals->titlebar2); drawString(caveGlobals->row, caveGlobals->col, caveGlobals->player1); drawString(25, 17, caveGlobals->mystat); }
DECL(int, FSInit, void) { if ((int)bss_ptr == 0x0a000000) { // allocate memory for our stuff void *mem_ptr = memalign(sizeof(struct bss_t), 0x40); if(!mem_ptr) return real_FSInit(); // copy pointer bss_ptr = mem_ptr; memset(bss_ptr, 0, sizeof(struct bss_t)); // setup exceptions setup_os_exceptions(); // create game mount path prefix __os_snprintf(bss.mount_base, sizeof(bss.mount_base), "%s%s/%s%s", CAFE_OS_SD_PATH, SD_GAMES_PATH, GAME_DIR_NAME, CONTENT_PATH); // create game save path prefix __os_snprintf(bss.save_base, sizeof(bss.save_base), "%s%s/%s", CAFE_OS_SD_PATH, SD_SAVES_PATH, GAME_DIR_NAME); logger_connect(&bss.global_sock); // Call real FSInit int result = real_FSInit(); // Mount sdcard FSClient *pClient = (FSClient*) MEMAllocFromDefaultHeap(sizeof(FSClient)); if (!pClient) return 0; FSCmdBlock *pCmd = (FSCmdBlock*) MEMAllocFromDefaultHeap(sizeof(FSCmdBlock)); if (!pCmd) { MEMFreeToDefaultHeap(pClient); return 0; } FSInitCmdBlock(pCmd); FSAddClientEx(pClient, 0, FS_RET_NO_ERROR); fs_mount_sd(bss.global_sock, pClient, pCmd); FSDelClient(pClient); MEMFreeToDefaultHeap(pCmd); MEMFreeToDefaultHeap(pClient); return result; } return real_FSInit(); }
void _start() { asm( "lis %r1, 0x1ab5 ;" "ori %r1, %r1, 0xd138 ;" ); unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit", &coreinit_handle); unsigned int(*MEMGetTotalFreeSizeForExpHeap)(void*expHeap); OSDynLoad_FindExport(coreinit_handle, 0, "MEMGetTotalFreeSizeForExpHeap", &MEMGetTotalFreeSizeForExpHeap); unsigned char *str; void *expHeap = (void*)0; float expSize = 0.f; /* this area appears semi-safe to search through */ for(str = (unsigned char*)0x15000000; str < (unsigned char*)0x25000000; str+=4) { if(*(unsigned int*)str == 0x45585048) { void *tmpHeap = str; float tmpSize = (float)MEMGetTotalFreeSizeForExpHeap(tmpHeap); if(tmpSize > expSize) { expHeap = tmpHeap; expSize = tmpSize; } } } if(expHeap != (void*)0) { char buf[64]; __os_snprintf(buf,64,"Biggest ExpHeap is %08x with %.2fMB left", expHeap, expSize/1024/1024); OSFatal(buf); } OSFatal("No Heaps found!"); }
void start() { asm("stwu %r1,-0x2000(%r1)"); unsigned int * start = (unsigned int*)BUFFER_ADDR; int i; for (i = 0; i < 150; start += 1) { if (*start == CODE_START) i++; } memcpy((void *)BUFFER_ADDR, (void *)BUFFER_ADDR + 0x800, 0x600); unsigned int * code_addr = (unsigned int *)(BUFFER_ADDR + 0x2C); unsigned int * code_addr_2 = (unsigned int *)(BUFFER_ADDR + 0x44); *code_addr = (int)start; *code_addr_2 = (int)start; asm( "lis %r1, 0x1dd7 ;" "ori %r1, %r1, 0xb814 ;" ); rop(); /* Debug printing */ char msg[255]; __os_snprintf(msg, 255, "0x%08x 0x%08x", *code_addr, start); OSFatal(msg); }
DECL(int, FSGetFreeSpaceSizeAsync, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error, void *asyncParams) { int client = GetCurClient(pClient); if (client != -1) { // log //fs_log_string(bss.socket_fs[client], path, BYTE_REMOVE); char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "FSGetFreeSpaceSizeAsync: %s", path); fs_log_string(bss.global_sock, buffer, BYTE_LOG_STR); // change path if it is a save folder int pathType = getPathType(path); if (pathType == PATH_TYPE_SAVE) { int len = strlen(path); int len_base = getNewPathLen(pathType); char new_path[len + len_base + 1]; compute_new_path(new_path, path, len, pathType); // log new path fs_log_string(bss.socket_fs[client], new_path, BYTE_LOG_STR); return real_FSGetFreeSpaceSizeAsync(pClient, pCmd, new_path, returnedFreeSize, error, asyncParams); } } return real_FSGetFreeSpaceSizeAsync(pClient, pCmd, path, returnedFreeSize, error, asyncParams); }
static int my_attach_cb(HIDClient *p_client, HIDDevice *p_device, unsigned int attach) { char buf[64]; __os_snprintf(buf,64,"%s:%04x %04x",attach?"attach":"detach",SWAP16(p_device->vid),SWAP16(p_device->pid)); charprintf(buf); if( attach && SWAP16(p_device->vid) == 0x057e && SWAP16(p_device->pid) == 0x0337 ) { unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); void*(*OSAllocFromSystem)(unsigned int v1, unsigned int v2); OSDynLoad_FindExport(coreinit_handle,0,"OSAllocFromSystem",&OSAllocFromSystem); void(*memset)(void *dst, unsigned char wat, unsigned int len); OSDynLoad_FindExport(coreinit_handle,0,"memset",&memset); unsigned char *buf = OSAllocFromSystem(64,64); memset(buf,0,64); buf[0] = 0x13; struct my_cb_user *usr = OSAllocFromSystem(64,64); usr->buf = buf; unsigned int nsyshid_handle; OSDynLoad_Acquire("nsyshid.rpl", &nsyshid_handle); usr->nsyshid_handle = nsyshid_handle; OSDynLoad_FindExport(usr->nsyshid_handle,0,"HIDRead",&usr->HIDRead); OSDynLoad_FindExport(usr->nsyshid_handle,0,"HIDWrite",&usr->HIDWrite); usr->transfersize = p_device->max_packet_size_rx; int(*HIDWrite)(unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user) = usr->HIDWrite; HIDWrite(p_device->handle, usr->buf, 1, my_write_cb, usr); return DEVICE_USED; } return DEVICE_UNUSED; }
DECL(int, OSDynLoad_GetModuleName, unsigned int *handle, char *name_buffer, int *name_buffer_size) { int result = real_OSDynLoad_GetModuleName(handle, name_buffer, name_buffer_size); if ((int)bss_ptr != 0x0a000000) { char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "OSDynLoad_GetModuleName: %s result %i", (name_buffer && result == 0) ? name_buffer : "NULL", result); log_string(bss.global_sock, buffer, BYTE_LOG_STR); } return result; }
DECL(int, OSDynLoad_IsModuleLoaded, char* rpl, unsigned int *handle, int r5 __attribute__((unused))) { int result = real_OSDynLoad_IsModuleLoaded(rpl, handle, 1); if ((int)bss_ptr != 0x0a000000) { char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "OSDynLoad_IsModuleLoaded: %s result %i", rpl, result); log_string(bss.global_sock, buffer, BYTE_LOG_STR); } return result; }
static void my_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned int bytes_transfered, void *p_user) { if(error == 0) { struct my_cb_user *usr = (struct my_cb_user*)p_user; char leprint[64]; __os_snprintf(leprint,64,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],buf[8],buf[9]); charprintf(leprint); int(*HIDRead)(unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user) = usr->HIDRead; HIDRead(handle, usr->buf, bytes_transfered, my_read_cb, usr); } }
/* Open a specific controller under /dev/uhs */ int UhsOpenController(int controller_num) { /* Symbol loading */ unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); int (*IOS_Open)(char *path, int mode); OSDynLoad_FindExport(coreinit_handle, false, "IOS_Open", &IOS_Open); /* Build the path name and return a handle */ char path[32]; __os_snprintf(path, 32, "/dev/uhs/%d", controller_num); return IOS_Open(path, 0); }
DECL(int, FSGetVolumeState_log, void *pClient) { int result = real_FSGetVolumeState_log(pClient); if ((int)bss_ptr != 0x0a000000) { if (result > 1) { int error = real_FSGetLastError_log(pClient); char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "FSGetVolumeState: %i, last error = %i", result, error); log_string(bss.global_sock, buffer, BYTE_LOG_STR); } } return result; }
void dog(struct cGlobals *caveGlobals) { // Figure out the players last position and put the dog there caveGlobals->dogrow = caveGlobals->row; caveGlobals->dogcol = caveGlobals->col; // Increment his "health" caveGlobals->dogsteps += 1; // Health levels if (caveGlobals->dogsteps <= 0) { __os_snprintf(caveGlobals->dogstat, 64, "Dog: Cheater!"); } if (caveGlobals->dogsteps > 0 && caveGlobals->dogsteps <= 60) { __os_snprintf(caveGlobals->dogstat, 64, "Dog: Full"); } if (caveGlobals->dogsteps > 61 && caveGlobals->dogsteps <= 120) { __os_snprintf(caveGlobals->dogstat, 64, "Dog: Peckish"); } if (caveGlobals->dogsteps > 121 && caveGlobals->dogsteps <= 180) { __os_snprintf(caveGlobals->dogstat, 64, "Dog: Hungry"); } if (caveGlobals->dogsteps > 181 && caveGlobals->dogsteps <= 240) { __os_snprintf(caveGlobals->dogstat, 64, "Dog: Starving"); } if (caveGlobals->dogsteps > 241 && caveGlobals->dogsteps <= 300) { __os_snprintf(caveGlobals->dogstat, 64, "Dog: Desperate"); } if (caveGlobals->dogsteps > 301) { __os_snprintf(caveGlobals->dogstat, 64, "Dog: Dead"); caveGlobals->dogalive = 0; } // Puts a symbol where the player used to be (or not if dead) print his status if (caveGlobals->dogalive == 1 ) { __os_snprintf(caveGlobals->doggy, 8, "d"); drawString(caveGlobals->dogrow, caveGlobals->dogcol, caveGlobals->doggy); } drawString(-4, 17, caveGlobals->dogstat); }
DECL(int, FSRollbackQuotaAsync, void *pClient, void *pCmd, char *path, int error, FSAsyncParams *asyncParams) { int client = GetCurClient(pClient); if (client != -1) { // log char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "FSRollbackQuotaAsync: %s", path); log_string(bss.global_sock, buffer, BYTE_LOG_STR); // change path if it is a save folder if (is_savefile(path)) { int len = strlen(path); int len_base = (strlen(bss.save_base) + 8); char new_path[len + len_base + 1]; compute_new_path(new_path, path, len, 1); // log new path log_string(bss.socket_fs[client], new_path, BYTE_LOG_STR); return real_FSRollbackQuotaAsync(pClient, pCmd, new_path, error, asyncParams); } } return real_FSRollbackQuotaAsync(pClient, pCmd, path, error, asyncParams); }
DECL(int, OSDynLoad_Acquire, char* rpl, unsigned int *handle, int r5 __attribute__((unused))) { // Get only the filename (in case there is folders in the module name ... like zombiu) char *ptr = rpl; while(*ptr) { if (*ptr == '/') { rpl = ptr + 1; } ptr++; } // Look if RPL is in our table and load it from SD Card CheckAndLoadRPL(rpl); int result = real_OSDynLoad_Acquire(rpl, handle, 0); if ((int)bss_ptr != 0x0a000000) { char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "OSDynLoad_Acquire: %s result: %i", rpl, result); log_string(bss.global_sock, buffer, BYTE_LOG_STR); } return result; }
DECL(int, FSGetFreeSpaceSize, void *pClient, void *pCmd, char *path, uint64_t *returnedFreeSize, int error) { int client = GetCurClient(pClient); if (client != -1) { // log //log_string(bss.socket_fs[client], path, BYTE_REMOVE); char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "FSGetFreeSpaceSize: %s", path); log_string(bss.global_sock, buffer, BYTE_LOG_STR); // change path if it is a save folder if (is_savefile(path)) { int len = strlen(path); int len_base = (strlen(bss.save_base) + 8); char new_path[len + len_base + 1]; compute_new_path(new_path, path, len, 1); // log new path log_string(bss.socket_fs[client], new_path, BYTE_LOG_STR); return real_FSGetFreeSpaceSize(pClient, pCmd, new_path, returnedFreeSize, error); } } return real_FSGetFreeSpaceSize(pClient, pCmd, path, returnedFreeSize, error); }
DECL(int, FSRollbackQuota, void *pClient, void *pCmd, const char *path, int error) { int client = GetCurClient(pClient); if (client != -1) { // log char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "FSRollbackQuota: %s", path); fs_log_string(bss.global_sock, buffer, BYTE_LOG_STR); // change path if it is a save folder int pathType = getPathType(path); if (pathType == PATH_TYPE_SAVE) { int len = strlen(path); int len_base = getNewPathLen(pathType); char new_path[len + len_base + 1]; compute_new_path(new_path, path, len, pathType); // log new path fs_log_string(bss.socket_fs[client], new_path, BYTE_LOG_STR); return real_FSRollbackQuota(pClient, pCmd, new_path, error); } } return real_FSRollbackQuota(pClient, pCmd, path, error); }
/* ***************************************************************************** * Dynamic RPL loading to memory * ****************************************************************************/ static int LoadRPLToMemory(s_rpx_rpl *rpl_entry) { if ((int)bss_ptr != 0x0a000000) { char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "CheckAndLoadRPL(%s) found and loading", rpl_entry->name); log_string(bss.global_sock, buffer, BYTE_LOG_STR); } // initialize FS FSInit(); FSClient *pClient = (FSClient*) MEMAllocFromDefaultHeap(sizeof(FSClient)); if (!pClient) return 0; FSCmdBlock *pCmd = (FSCmdBlock*) MEMAllocFromDefaultHeap(sizeof(FSCmdBlock)); if (!pCmd) { MEMFreeToDefaultHeap(pClient); return 0; } // calculate path length for SD access of RPL int path_len = strlen(CAFE_OS_SD_PATH) + strlen(SD_GAMES_PATH) + strlen(GAME_DIR_NAME) + strlen(RPX_RPL_PATH) + strlen(rpl_entry->name) + 3; char *path_rpl = MEMAllocFromDefaultHeap(path_len); if(!path_rpl) { MEMFreeToDefaultHeap(pCmd); MEMFreeToDefaultHeap(pClient); return 0; } // create path __os_snprintf(path_rpl, path_len, "%s%s/%s%s/%s", CAFE_OS_SD_PATH, SD_GAMES_PATH, GAME_DIR_NAME, RPX_RPL_PATH, rpl_entry->name); // malloc mem for read file unsigned char* dataBuf = (unsigned char*)MEMAllocFromDefaultHeapEx(0x1000, 0x40); if(!dataBuf) { MEMFreeToDefaultHeap(pCmd); MEMFreeToDefaultHeap(pClient); MEMFreeToDefaultHeap(path_rpl); return 0; } // do more initial FS stuff FSInitCmdBlock(pCmd); FSAddClientEx(pClient, 0, FS_RET_NO_ERROR); // set RPL size to 0 to avoid wrong RPL being loaded when opening file fails rpl_entry->size = 0; rpl_entry->offset = 0; int fd = 0; if (real_FSOpenFile(pClient, pCmd, path_rpl, "r", &fd, FS_RET_ALL_ERROR) == FS_STATUS_OK) { int ret; int rpl_size = 0; // Get current memory area s_mem_area* mem_area = (s_mem_area*)(MEM_AREA_ARRAY); int mem_area_addr_start = mem_area->address; int mem_area_addr_end = mem_area->address + mem_area->size; int mem_area_offset = 0; // Copy rpl in memory while ((ret = FSReadFile(pClient, pCmd, dataBuf, 0x1, 0x1000, fd, 0, FS_RET_ALL_ERROR)) > 0) { // Copy in memory and save offset for (int j = 0; j < ret; j++) { if ((mem_area_addr_start + mem_area_offset) >= mem_area_addr_end) { // Set next memory area mem_area = mem_area->next; mem_area_addr_start = mem_area->address; mem_area_addr_end = mem_area->address + mem_area->size; mem_area_offset = 0; } *(volatile unsigned char*)(mem_area_addr_start + mem_area_offset) = dataBuf[j]; mem_area_offset += 1; } rpl_size += ret; } // Fill rpl entry rpl_entry->area = (s_mem_area*)(MEM_AREA_ARRAY); rpl_entry->offset = 0; rpl_entry->size = rpl_size; // flush memory // DCFlushRange((void*)rpl_entry, sizeof(s_rpx_rpl)); // DCFlushRange((void*)rpl_entry->address, rpl_entry->size); if ((int)bss_ptr != 0x0a000000) { char buffer[200]; __os_snprintf(buffer, sizeof(buffer), "CheckAndLoadRPL(%s) file loaded 0x%08X %i", rpl_entry->name, rpl_entry->area->address, rpl_entry->size); log_string(bss.global_sock, buffer, BYTE_LOG_STR); } FSCloseFile(pClient, pCmd, fd, FS_RET_NO_ERROR); } FSDelClient(pClient); MEMFreeToDefaultHeap(dataBuf); MEMFreeToDefaultHeap(pCmd); MEMFreeToDefaultHeap(pClient); MEMFreeToDefaultHeap(path_rpl); return 1; }
void changelevel(struct cGlobals *caveGlobals) { // Have an array! Height then width! (Need to clean this up later...) // By the way, Gamepad is -4, -1 to 65, 17! and TV is -4, -1 to 101, 27! if (caveGlobals->level == 1) { unsigned char lMapArray[17][62] = { { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 2, 2, 2, 2, 2, 1, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 2, 2, 2, 2, 2, 1, 0, 0, 0, 1, 2, 2, 2, 4, 2, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 8, 2, 1, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 2, 2, 2, 2, 2, 1, 0, 0, 0, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 2, 1, 0, 0, 0, 1, 2, 2, 3, 3, 3, 3, 3, 3, 5, 2, 2, 2, 4, 2,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2, 2, 2, 2, 2, 7, 2, 2, 2, 2, 1, 2, 2, 2, 1, 0, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 6, 2, 2, 2, 2, 6, 2, 2, 2, 1, 0, 1, 2, 2, 2, 4, 2, 2, 2, 2, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 } }; // Put the player where she belongs! caveGlobals->row = 3; caveGlobals->col = 3; // Fill our global array int i; int j; for( i = 0; i < 17; i++) { for( j = 0; j < 62; j++) { caveGlobals->nMapArray[i][j]=lMapArray[i][j]; } } // Who made it??? __os_snprintf(caveGlobals->titlebar2, 128, "Map by: SonyUSA"); } if (caveGlobals->level == 2) { unsigned char lMapArray[17][62] = { {1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1}, {1,6,2,8,2,6,1,0,0,0,1,7,1,0,0,0,1,8,1,0,0,0,1,7,1,0,0,1,2,8,2,2,2,2,2,1,0,0,0,0,1,2,2,2,1,0,0,1,6,1,0,0,0,0,1,2,2,2,2,7,2,1}, {1,2,2,2,2,2,1,0,0,0,1,2,1,0,0,0,1,2,1,0,0,0,1,2,1,0,0,1,1,1,1,1,1,2,1,1,0,0,0,0,1,2,7,2,1,0,0,1,8,1,0,0,1,1,1,2,1,1,1,1,2,1}, {1,2,1,1,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2,1,0,0,0,0,1,2,1,0,1,2,1,0,0,0,0,0,0,1,2,1,0,0,1,2,1,0,0,0,1,7,1,1,1,1,2,1,0,0,0,0,1,2,2,2,2,7,2,1}, {0,0,0,0,0,0,0,1,2,2,2,2,2,1,0,0,0,0,1,2,1,1,1,2,1,1,1,1,1,1,1,1,2,1,0,0,1,2,1,1,1,1,1,2,2,2,2,2,2,1,0,0,0,0,1,2,1,1,1,1,2,1}, {0,0,0,0,0,0,0,1,2,2,6,2,2,1,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,1,2,2,2,2,2,2,2,1,1,1,1,1,1,0,0,0,0,1,2,1,0,0,1,2,1}, {1,1,1,1,1,1,1,1,2,2,8,2,2,1,0,0,0,0,1,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,2,2,2,2,2,2,2,1,0,0,0,0,0,1,1,1,1,1,2,1,1,1,1,2,1}, {1,2,2,2,2,2,2,2,2,2,6,2,2,1,0,0,0,0,1,7,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,8,2,2,2,7,1,0,0,0,0,0,1,9,2,2,2,2,2,2,2,2,2,1}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1} }; // Put the player where she belongs! caveGlobals->row = 1; caveGlobals->col = 15; // Fill our global array int i; int j; for( i = 0; i < 17; i++) { for( j = 0; j < 62; j++) { caveGlobals->nMapArray[i][j]=lMapArray[i][j]; } } // Who made it??? __os_snprintf(caveGlobals->titlebar2, 128, "Map by: ScarletDreamz"); } if (caveGlobals->level == 3) { unsigned char lMapArray[17][62] = { { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; // Put the player where she belongs! caveGlobals->row = 5; caveGlobals->col = 8; // Fill our global array int i; int j; for( i = 0; i < 17; i++) { for( j = 0; j < 62; j++) { caveGlobals->nMapArray[i][j]=lMapArray[i][j]; } } // Who made it??? __os_snprintf(caveGlobals->titlebar2, 128, "Map by: SonyUSA"); } if (caveGlobals->level == 4) { unsigned char lMapArray[17][62] = { {1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,11,8,2,2,2,2,2,2,1,1,1,1,1,1,1,0,0,0,0,0,1,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0}, {1,2,2,2,2,2,2,2,2,10,2,2,2,2,2,8,1,0,0,0,0,1,2,7,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0}, {1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,0,0,0,0,0,1,2,2,2,1,0,3,3,3,3,1,3,1,3,3,1,2,1,3,3,1,3,1,3,3,1,2,1,3,3,1,2,1,0,3,1,3,1,3,3,0}, {1,2,2,2,2,2,2,2,2,1,2,8,2,2,2,2,1,0,1,1,1,1,1,4,1,1,1,1,3,3,3,1,3,1,0,3,1,2,1,3,0,1,2,1,3,0,1,1,1,3,3,1,2,1,0,3,1,2,1,3,0,0}, {1,1,2,1,1,2,1,1,1,1,1,1,1,1,1,4,1,1,2,2,2,2,2,2,2,2,2,1,0,3,3,1,2,1,0,0,1,2,1,0,0,1,2,1,1,0,1,2,10,3,0,1,2,1,0,0,1,2,1,3,0,0}, {0,1,4,1,1,2,1,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,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7,2,2,7,2,2,7,2,2,7,2,2,7,2,2,2,4,2,2,4,2,2,2,2,6,2,2,6,2,2,1}, {0,3,3,3,3,3,3,3,3,3,2,2,2,2,2,1,0,0,1,2,2,2,2,1,1,1,1,1,2,2,2,2,7,2,2,2,7,2,7,2,2,2,2,2,7,2,1,1,1,1,1,1,1,1,2,2,2,6,8,2,6,1}, {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1} }; // Put the player where she belongs! caveGlobals->row = 2; caveGlobals->col = 2; // Fill our global array int i; int j; for( i = 0; i < 17; i++) { for( j = 0; j < 62; j++) { caveGlobals->nMapArray[i][j]=lMapArray[i][j]; } } // Who made it??? __os_snprintf(caveGlobals->titlebar2, 128, "Map by: SonyUSA"); } if (caveGlobals->level == 5) { unsigned char lMapArray[17][62] = { {1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,8,8,8}, {1,2,2,2,1,2,2,2,2,7,8,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,8,8,8}, {1,2,8,2,5,2,2,2,2,2,7,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,8,8,8}, {1,1,4,1,1,1,1,1,1,1,10,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2}, {0,1,2,1,0,0,0,0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,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,1,2,1,2,2,2,2,2,2,2,1,2,8,2,1,2,2,2,2,2,0,0,0}, {0,1,2,1,7,1,6,1,0,1,2,1,0,1,2,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,1,2,1,2,2,2,2,2,2,2,1,2,9,2,1,2,2,2,2,2,0,0,0}, {0,1,2,1,7,1,6,1,0,1,2,1,1,1,2,2,2,7,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,2,1,1,1,1,10,1,1,1,1,2,2,2,1,2,2,2,2,2,0,0,0}, {0,1,8,1,8,1,11,1,0,1,2,2,2,4,2,2,6,2,7,2,5,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,0,0,0}, {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,0,0,0} }; // Put the player where she belongs! caveGlobals->row = 1; caveGlobals->col = 1; // Fill our global array int i; int j; for( i = 0; i < 17; i++) { for( j = 0; j < 62; j++) { caveGlobals->nMapArray[i][j]=lMapArray[i][j]; } } // Who made it??? __os_snprintf(caveGlobals->titlebar2, 128, "Map by: Sivart0"); } }
void drawmap(struct cGlobals *caveGlobals) { // Matrix Pieces #define TILE_VOID 0 #define TILE_WALL 1 #define TILE_FLOOR 2 #define TILE_WATER 3 #define TILE_CLOSEDOOR 4 #define TILE_OPENDOOR 5 #define TILE_TRAP 6 #define TILE_HTRAP 7 #define TILE_FOOD 8 #define TILE_STAIRS 9 #define TILE_SDOOR 10 #define TILE_POTION 11 // Draw each element in the matrix using a viewscope of 4 tiles around the player int y; int x; // Make sure we don't look outside the matrix on accident... int yy = caveGlobals->col-4; if (yy < 0) { yy = 0;} int xx = caveGlobals->row-4; if (xx < 0) { xx = 0;} // Now draw everything! for( y = yy; y < caveGlobals->col+5 && y < 17; y++ ) { for( x = xx; x < caveGlobals->row+5 && x < 62; x++ ) { switch ( caveGlobals->nMapArray[y][x] ) { case TILE_VOID: __os_snprintf(caveGlobals->mapbuff, 2800, "."); drawString(x, y, caveGlobals->mapbuff); break; case TILE_WALL: __os_snprintf(caveGlobals->mapbuff, 2800, "#"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_FLOOR: __os_snprintf(caveGlobals->mapbuff, 2800, " "); drawString(x, y, caveGlobals->mapbuff); break; case TILE_WATER: __os_snprintf(caveGlobals->mapbuff, 2800, "~"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_CLOSEDOOR: __os_snprintf(caveGlobals->mapbuff, 2800, "+"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_OPENDOOR: __os_snprintf(caveGlobals->mapbuff, 2800, "/"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_TRAP: __os_snprintf(caveGlobals->mapbuff, 2800, "*"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_HTRAP: __os_snprintf(caveGlobals->mapbuff, 2800, " "); drawString(x, y, caveGlobals->mapbuff); break; case TILE_FOOD: __os_snprintf(caveGlobals->mapbuff, 2800, "F"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_STAIRS: __os_snprintf(caveGlobals->mapbuff, 2800, ">"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_SDOOR: __os_snprintf(caveGlobals->mapbuff, 2800, "#"); drawString(x, y, caveGlobals->mapbuff); break; case TILE_POTION: __os_snprintf(caveGlobals->mapbuff, 2800, "p"); drawString(x, y, caveGlobals->mapbuff); break; } } } }
int __entry_menu(int argc, char** argv) { InitOSFunctionPointers(); InitVPadFunctionPointers(); InitFSFunctionPointers(); mount_sd_fat("sd"); //Setup BATs for later InjectSyscall36((unsigned int)injectBAT); RunSyscall36(); InstallExceptionHandler(); initInputs(); initVideo(); videoDebugMessage(0, "All running!"); //*((int*)0x04) = 4243; unsigned char* MEM2core = 0; unsigned int coreSize = 0; LoadFileToMem("sd://stella.elf", &MEM2core, &coreSize); void* core = (void*)CORES_BASE_ADDRESS; memcpy(core, MEM2core, coreSize); //Move core to MEM1 free(MEM2core); int error = loadCore(core); //Load core symbols (UDynLoad) char buf[255]; __os_snprintf(buf, 255, "Core loaded, error %d. Core at 0x%X", error, core); videoDebugMessage(1, buf); unsigned char* game = 0; unsigned int gameSize = 0; LoadFileToMem("sd://game.bin", &game, &gameSize); error = setupCore((void*)game, gameSize); //Initialise core __os_snprintf(buf, 255, "Setup core, error %d, game at %X size %X", error, game, gameSize); videoDebugMessage(2, buf); testVideoOutput(); while (1) { pollInputs(); if (UIInputCheckButton()) { break; } } //cleanup shutdownVideo(); memset(core, 0, coreSize); //Delete core from memory or HBL will cry every time memset(game, 0, gameSize); InjectSyscall36((unsigned int)clearBAT); RunSyscall36(); return 0; }
void _main() { /****************************> Fix Stack <****************************/ //Load a good stack asm( "lis %r1, 0x1ab5 ;" "ori %r1, %r1, 0xd138 ;" ); /****************************> Get Handles <****************************/ //Get a handle to coreinit.rpl unsigned int coreinit_handle, vpad_handle, sysapp_handle, avm_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); OSDynLoad_Acquire("vpad.rpl", &vpad_handle); OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); // CreeperMario: Get a handle to the audio/video manager - avm.rpl OSDynLoad_Acquire("avm.rpl", &avm_handle); // STUFF VPADData vpad_data; int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *err); OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead); // Sysapp stuff int(*SYSLaunchMenu)(); OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchMenu", &SYSLaunchMenu); // please dont break stuff... int(*SYSLaunchTitle) (int bit1, int bit2); OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchTitle", &SYSLaunchTitle); int(*_Exit)(); OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); /****************************> External Prototypes <****************************/ //OSScreen functions void(*OSScreenInit)(); unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum); unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr); //OS Memory functions void*(*memset)(void * dest, uint32_t value, uint32_t bytes); void*(*OSAllocFromSystem)(uint32_t size, int align); void(*OSFreeToSystem)(void *ptr); //IM functions int(*IM_Open)(); int(*IM_Close)(int fd); int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b); // CreeperMario: TV Screen scaling functions bool(*AVMSetTVScale)(int width, int height); /****************************> Exports <****************************/ //OSScreen functions OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit); OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx); OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx); //OS Memory functions OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset); OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); //IM functions OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open); OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close); OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState); // CreeperMario: TV Screen scaling functions OSDynLoad_FindExport(avm_handle, 0, "AVMSetTVScale", &AVMSetTVScale); /*** CreeperMario: Set the TV screen to the proper 'scale factor'. ***/ AVMSetTVScale(854, 480); /****************************> Initial Setup <****************************/ //Restart system to get lib access int fd = IM_Open(); void *mem = OSAllocFromSystem(0x100, 64); memset(mem, 0, 0x100); //set restart flag to force quit browser IM_SetDeviceState(fd, mem, 3, 0, 0); IM_Close(fd); OSFreeToSystem(mem); //wait a bit for browser end unsigned int t1 = 0x15000000; while(t1--) ; //Call the Screen initilzation function. OSScreenInit(); //Grab the buffer size for each screen (TV and gamepad) int buf0_size = OSScreenGetBufferSizeEx(0); int buf1_size = OSScreenGetBufferSizeEx(1); //Set the buffer area. OSScreenSetBufferEx(0, (void *)0xF4000000); OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size); //Clear both framebuffers. doclearstuff(); // Define struct for global variables! struct cGlobals caveGlobals; // Variables n stuff! caveGlobals.food = 0; caveGlobals.row = 1; caveGlobals.col = 1; caveGlobals.level = 1; caveGlobals.dogsteps = 0; caveGlobals.dogalive = 1; caveGlobals.mysteps = 0; caveGlobals.maxhealth = 10; caveGlobals.curhealth = 10; // Start at level 1 (obviously!) changelevel(&caveGlobals); // Draw Buffers and Initial Screen __os_snprintf(caveGlobals.mystat, 64, " "); doclearstuff(); drawstuff(&caveGlobals); flipBuffers(); int err; while(1) { VPADRead(0, &vpad_data, 1, &err); // Quit if (vpad_data.btn_trigger & BUTTON_HOME) { doclearstuff(); __os_snprintf(caveGlobals.endgame, 256, "Thanks for Playing!\nYour Final Level: %d \n\n\nBy: SonyUSA", caveGlobals.level); drawString(0, 0, caveGlobals.endgame); flipBuffers(); t1 = 0x50000000; while(t1--) ; //Maybe fix for exit crash? doclearstuff(); flipBuffers(); doclearstuff(); flipBuffers(); //Ape escape! SYSLaunchMenu(); _Exit(); } //Grab Stuff (A) if (vpad_data.btn_release & BUTTON_A) { //Checks for Food if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 8) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "Got it!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.food += 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2; drawstuff(&caveGlobals); flipBuffers(); } //Check for Potions if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 11) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "*Gulp!*"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth += 5; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2; //Make sure we don't go over health limit if (caveGlobals.curhealth > caveGlobals.maxhealth) { caveGlobals.curhealth = caveGlobals.maxhealth; } drawstuff(&caveGlobals); dog(&caveGlobals); flipBuffers(); } //Checks for Stairs if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 9) { caveGlobals.level += 1; doclearstuff(); changelevel(&caveGlobals); drawstuff(&caveGlobals); flipBuffers(); } } //Search for Hidden Traps and Doors if (vpad_data.btn_trigger & BUTTON_Y) { doclearstuff(); drawstuff(&caveGlobals); dog(&caveGlobals); //Ask the player which way to search __os_snprintf(caveGlobals.mystat, 64, "Search Which Way?"); drawString(22, 17, caveGlobals.mystat); flipBuffers(); //Lets use a while loop so players cant just hold down search while they are walking! Cheating gits! while(2) { VPADRead(0, &vpad_data, 1, &err); // Search Up if (vpad_data.btn_release & BUTTON_UP) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Down if (vpad_data.btn_release & BUTTON_DOWN) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Right if (vpad_data.btn_release & BUTTON_RIGHT) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Left if (vpad_data.btn_release & BUTTON_LEFT) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } } } //Open and Close Doors (X + Direction) if (vpad_data.btn_hold & BUTTON_X) { if (vpad_data.btn_trigger & BUTTON_DOWN) { if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_UP) { if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_LEFT) { if (isclosedoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_RIGHT) { if (isclosedoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4; flipBuffers(); } } } // Movement //Down if (vpad_data.btn_trigger & BUTTON_DOWN) { if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.col += 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Up if (vpad_data.btn_trigger & BUTTON_UP) { if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.col -= 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Left if (vpad_data.btn_trigger & BUTTON_LEFT) { if (canmove(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.row -= 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Right if (vpad_data.btn_trigger & BUTTON_RIGHT) { if (canmove(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.row += 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Feed the doggy if (vpad_data.btn_trigger & BUTTON_PLUS) { if (caveGlobals.dogalive == 1) { if (caveGlobals.food >= 1) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "*crunch* Woof!"); drawString(24, 17, caveGlobals.mystat); caveGlobals.food -= 1; caveGlobals.dogsteps -= 60; //Make sure we don't go negative in dog health if (caveGlobals.dogsteps <= 0) { caveGlobals.dogsteps = 0;} drawstuff(&caveGlobals); dog(&caveGlobals); flipBuffers(); } } } // Check if the player is dead if(caveGlobals.curhealth == 0) { doclearstuff(); __os_snprintf(caveGlobals.endgame, 256, "You're Dead!\nNow how will you get iosu? :/ \n\nThanks for Playing! \n\n\nBy: SonyUSA"); drawString(0, 0, caveGlobals.endgame); flipBuffers(); t1 = 0x80000000; while(t1--) ; SYSLaunchMenu(); _Exit(); } // Cheat and go to next level with Minus key if(vpad_data.btn_release & BUTTON_MINUS) { caveGlobals.level += 1; doclearstuff(); changelevel(&caveGlobals); drawstuff(&caveGlobals); flipBuffers(); } } }
void _start() { /* Load a good stack */ asm( "lis %r1, 0x1ab5 ;" "ori %r1, %r1, 0xd138 ;" ); /* Get a handle to coreinit.rpl */ uint32_t coreinit_h; OSDynLoad_Acquire("coreinit.rpl", &coreinit_h); /* Memory allocation and FS functions */ void* (*OSAllocFromSystem)(uint32_t size, int align); int (*FSInit)(); int (*FSAddClient)(void *client, int unk1); int (*FSInitCmdBlock)(void *cmd); int (*FSOpenDir)(void *client, void *cmd, char *path, uint32_t *dir_handle, int unk1); int (*FSReadDir)(void *client, void *cmd, uint32_t dir_handle, void *buffer, int unk1); int (*FSGetMountSource)(void *client, void *cmd, int type, mount_source *source, int unk1); int (*FSMount)(void *client, void *cmd, mount_source *source, char *mountpath, uint32_t pathlength, int unk1); int (*FSOpenFile)(void *client, void *cmd, char *filepath, char *amode, uint32_t *file_handle, int unk1); int (*FSReadFile)(void *client, void *cmd, void *buffer, uint32_t size, uint32_t length, uint32_t file_handle, int unk1, int unk2); OSDynLoad_FindExport(coreinit_h, 0, "OSAllocFromSystem", &OSAllocFromSystem); OSDynLoad_FindExport(coreinit_h, 0, "FSInit", &FSInit); OSDynLoad_FindExport(coreinit_h, 0, "FSAddClient", &FSAddClient); OSDynLoad_FindExport(coreinit_h, 0, "FSInitCmdBlock", &FSInitCmdBlock); OSDynLoad_FindExport(coreinit_h, 0, "FSOpenDir", &FSOpenDir); OSDynLoad_FindExport(coreinit_h, 0, "FSReadDir", &FSReadDir); OSDynLoad_FindExport(coreinit_h, 0, "FSGetMountSource", &FSGetMountSource); OSDynLoad_FindExport(coreinit_h, 0, "FSMount", &FSMount); OSDynLoad_FindExport(coreinit_h, 0, "FSOpenFile", &FSOpenFile); OSDynLoad_FindExport(coreinit_h, 0, "FSReadFile", &FSReadFile); FSInit(); /* Set up the client and command blocks */ void *client = OSAllocFromSystem(0x1700, 0x20); void *cmd = OSAllocFromSystem(0xA80, 0x20); if (!(client && cmd)) OSFatal("Failed to allocate client and command block"); FSAddClient(client, 0); FSInitCmdBlock(cmd); // todo: check permissions and throw exception if no mounting permissions available // OSLockMutex - Probably not. It's a single thread, nothing else can access this, Cross-F does this here mount_source m_source; // allocate mount source int ms_result = FSGetMountSource(client, cmd, 0, &m_source, 0); // type 0 = external device if(ms_result != 0) { char buf[256]; __os_snprintf(buf, 256, "FSGetMountSource returned error code %d", ms_result); OSFatal(buf); } char mountPath[128]; // usually /vol/external01 int m_result = FSMount(client, cmd, &m_source, mountPath, sizeof(mountPath), -1); if(m_result != 0) { char buf[256]; __os_snprintf(buf, 256, "FSMount returned error code %d", m_result); OSFatal(buf); } // OSUnlockMutex char defaultMountPath[] = "/vol/external01"; if(!strcmp(mountPath, defaultMountPath)) { char buf[256]; __os_snprintf(buf, 256, "FSMount returned nonstandard mount path: %s", mountPath); OSFatal(buf); } uint32_t file_handle; int open_result = FSOpenFile(client, cmd, "/vol/external01/SMASHD.txt", "r", &file_handle, 0); if(open_result != 0) { char buf[256]; __os_snprintf(buf, 256, "FSOpenFile returned error code %d", open_result); OSFatal(buf); } uint32_t *file_buffer = OSAllocFromSystem(0x200, 0x20); int read_result = FSReadFile(client, cmd, file_buffer, 1, 25, file_handle, 0, -1); // todo: is size correct? one char one byte; read whole file, not just a few bytes if(read_result != 0) { char buf[256]; __os_snprintf(buf, 256, "FSReadFile returned error code %d", read_result); OSFatal(buf); } char *message = (char*)&file_buffer[25]; OSFatal(message); }
void _start() { /* Get a handle to coreinit.rpl */ unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); //OS memory functions void* (*memcpy)(void *dest, void *src, uint32_t length); void* (*memset)(void * dest, uint32_t value, uint32_t bytes); void* (*OSAllocFromSystem)(uint32_t size, int align); void (*OSFreeToSystem)(void *ptr); OSDynLoad_FindExport(coreinit_handle, 0, "memcpy", &memcpy); OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset); OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); void (*OSCoherencyBarrier)(); OSDynLoad_FindExport(coreinit_handle, 0, "OSCoherencyBarrier", &OSCoherencyBarrier); void (*_Exit)(); OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); //DC memory functions void (*DCFlushRangeNoSync)(void *buffer, uint32_t length); void (*DCInvalidateRange)(void *buffer, uint32_t length); OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRangeNoSync", &DCFlushRangeNoSync); OSDynLoad_FindExport(coreinit_handle, 0, "DCInvalidateRange", &DCInvalidateRange); //LC memory functions void* (*LCAlloc)( uint32_t bytes ); void (*LCDealloc)(); uint32_t (*LCHardwareIsAvailable)(); uint32_t (*LCIsDMAEnabled)(); void (*LCEnableDMA)(); void (*LCDisableDMA)(); void (*LCLoadDMABlocks)(void* lc_addr, void* src_addr, uint32_t blocks); void (*LCStoreDMABlocks)(void* dest_addr, void* lc_addr, uint32_t blocks); void (*LCWaitDMAQueue)( uint32_t length ); OSDynLoad_FindExport(coreinit_handle, 0, "LCAlloc", &LCAlloc); OSDynLoad_FindExport(coreinit_handle, 0, "LCDealloc", &LCDealloc); OSDynLoad_FindExport(coreinit_handle, 0, "LCHardwareIsAvailable", &LCHardwareIsAvailable); OSDynLoad_FindExport(coreinit_handle, 0, "LCIsDMAEnabled", &LCIsDMAEnabled); OSDynLoad_FindExport(coreinit_handle, 0, "LCEnableDMA", &LCEnableDMA); OSDynLoad_FindExport(coreinit_handle, 0, "LCDisableDMA", &LCDisableDMA); OSDynLoad_FindExport(coreinit_handle, 0, "LCLoadDMABlocks", &LCLoadDMABlocks); OSDynLoad_FindExport(coreinit_handle, 0, "LCStoreDMABlocks", &LCStoreDMABlocks); OSDynLoad_FindExport(coreinit_handle, 0, "LCWaitDMAQueue", &LCWaitDMAQueue); //Used for keeping track of vairables to print to screen char output[1000]; //Alloc 64 byte alligned space void* src_addr=OSAllocFromSystem(512,64); void* dest_addr=OSAllocFromSystem(512,64); //Store some debug values __os_snprintf(output, 1000, "src_addr:%02x,",(uint32_t)src_addr); __os_snprintf(output+strlen(output), 255, "dest_addr: %02x,", (uint32_t)dest_addr); //Number of 32bit blocks to copy. Must be multiple of 2 between [0,127] uint32_t blocks=2; //2 32bit blocks //Do something to the source memset(src_addr,1,64); //Grab values for debug uint32_t * src_val=src_addr; uint32_t * dest_val=dest_addr; __os_snprintf(output+strlen(output), 255, "Old src_val: %02x\n",src_val[0]); __os_snprintf(output+strlen(output), 255, "Old dest_val: %02x,",dest_val[0]); //Get some locked cache address space void *lc_addr=LCAlloc(512); //512 Minmum. Must be multiple of 512. //Calculate size from blocks to flush/invalidate range properly uint32_t size; //If blocks is set to 0, the transaction will default to 128 blocks if(blocks==0) { size=32*128; } else { size=32*blocks; } //Flush the range at the source to ensure cache gets written back to memory. DCFlushRangeNoSync(src_addr,size); //Invalidate the range at the destination DCInvalidateRange(dest_addr,size); //Sync OSCoherencyBarrier(); //Check to see of DMA hardware is avaliable if(LCHardwareIsAvailable()!=1) { OSFatal("Hardware is not avaliable."); } //Gets the current state of DMA, so we can restore it after our copy uint32_t dmaState=LCIsDMAEnabled(); //Checks to see if DMA is enabled, if not it will try to enable it. if(dmaState!=1) { LCEnableDMA(); dmaState=LCIsDMAEnabled(); if(dmaState!=1) { OSFatal("Can't enable DMA"); } } //Load memory to locked cache LCLoadDMABlocks(lc_addr,src_addr,blocks); LCWaitDMAQueue(0); //Store memory from locked cache LCStoreDMABlocks(dest_addr,lc_addr,blocks); LCWaitDMAQueue(0); //If DMA was not previously enabled, then disable it to restore state. if(dmaState!=1) { LCDisableDMA(); dmaState=LCIsDMAEnabled(); //If DMA failed to disable, return error code if(dmaState!=1) { OSFatal("Couldn't Disable DMA"); } } __os_snprintf(output+strlen(output), 255, "New src_val: %02x,",src_val[0]); __os_snprintf(output+strlen(output), 255, "New dest_val: %02x,",dest_val[0]); //Cleanup LCDealloc(lc_addr); OSFreeToSystem(dest_addr); OSFreeToSystem(src_addr); OSFatal(output); }
void _entryPoint() { /****************************> Get Handles <****************************/ //Get a handle to coreinit.rpl unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); //Get a handle to vpad.rpl */ unsigned int vpad_handle; OSDynLoad_Acquire("vpad.rpl", &vpad_handle); /****************************> External Prototypes <****************************/ //VPAD functions int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error); //OS functions void(*_Exit)(); /****************************> Exports <****************************/ //VPAD functions OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead); //OS functions OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); /****************************> Globals <****************************/ struct renderFlags flags; flags.y=0; flags.x=0; flags.a=0; flags.b=0; __os_snprintf(flags.aPressed, 32, "A button pressed"); __os_snprintf(flags.bPressed, 32, "B button pressed"); __os_snprintf(flags.xPressed, 32, "X button pressed"); __os_snprintf(flags.yPressed, 32, "Y button pressed"); /****************************> VPAD Loop <****************************/ /* Enter the VPAD loop */ int error; VPADData vpad_data; //Read initial vpad status VPADRead(0, &vpad_data, 1, &error); while(1) { VPADRead(0, &vpad_data, 1, &error); //button A if (vpad_data.btn_hold & BUTTON_A) flags.a=1; //button B if (vpad_data.btn_hold & BUTTON_B) flags.b=1; //button X if (vpad_data.btn_hold & BUTTON_X) flags.x=1; //button Y if (vpad_data.btn_hold & BUTTON_Y) flags.y=1; //end if(vpad_data.btn_hold & BUTTON_HOME) break; render(&flags); } //WARNING: DO NOT CHANGE THIS. YOU MUST CLEAR THE FRAMEBUFFERS AND IMMEDIATELY CALL EXIT FROM THIS FUNCTION. RETURNING TO LOADER CAUSES FREEZE. int ii=0; for(ii;ii<2;ii++) { fillScreen(0,0,0,0); flipBuffers(); } _Exit(); }