int gecko_readrange(u32 memstart, u32 memend) { char pcresponse; static char packetbuffer[packetsize] ATTRIBUTE_ALIGN(32); u32 memrange; u32 fullpackets; u32 currentpacket; u32 lastpacketbytes; memrange = memend - memstart; fullpackets = memrange / packetsize; lastpacketbytes = memrange % packetsize; // Full Packet Size for (currentpacket = 0;currentpacket < fullpackets;) { memcpy(packetbuffer, (char*)memstart, packetsize); usb_sendbuffer_safe(gecko_channel,&packetbuffer, packetsize); usb_recvbuffer_safe(gecko_channel,&pcresponse,1); if(pcresponse != 0xAA){ return 0; } memstart += packetsize; currentpacket++; } // Remainder if(lastpacketbytes > 0) { memcpy(packetbuffer, (char*)memstart, lastpacketbytes); usb_sendbuffer_safe(gecko_channel,&packetbuffer, lastpacketbytes); } return 1; }
void DEBUG_print(char* string,int pos){ #ifdef SHOW_DEBUG if(pos == DBG_USBGECKO) { #ifdef PRINTGECKO if(!flushed){ usb_flush(1); flushed = 1; } int size = strlen(string); usb_sendbuffer_safe(1, &size,4); usb_sendbuffer_safe(1, string,size); #endif } else if(pos == DBG_SDGECKOOPEN) { #ifdef SDPRINT if(!f && printToSD) fdebug = fopen( dump_filename, "wb" ); #endif } else if(pos == DBG_SDGECKOAPPEND) { #ifdef SDPRINT if(!fdebug && printToSD) fdebug = fopen( dump_filename, "ab" ); #endif } else if(pos == DBG_SDGECKOCLOSE) { #ifdef SDPRINT if(fdebug) { fclose(fdebug); fdebug = NULL; } #endif } else if(pos == DBG_SDGECKOPRINT) { #ifdef SDPRINT if(!f || (printToSD == 0)) return; fwrite(string, 1, strlen(string), f); #endif } else { memset(text[pos],0,DEBUG_TEXT_WIDTH); strncpy(text[pos], string, DEBUG_TEXT_WIDTH); memset(text[DEBUG_TEXT_WIDTH-1],0,1); texttimes[pos] = gettime(); } #endif }
int gecko_readmem() { u8 startaddress[4]; u8 endaddress[5]; u8 ack_packet = 0xAA; u8 pcresponse; static u8 packetbuffer[packetsize] ATTRIBUTE_ALIGN(32); u32 memstart; u32 memend; u32 memrange; u32 fullpackets; u32 currentpacket; u32 lastpacketbytes; // ACK usb_sendbuffer_safe(gecko_channel,&ack_packet,1); usb_recvbuffer_safe(gecko_channel,&startaddress,4); usb_recvbuffer_safe(gecko_channel,&endaddress,4); memstart = be32(startaddress); memend = be32(endaddress); memrange = memend - memstart; fullpackets = memrange / packetsize; lastpacketbytes = memrange % packetsize; // Full Packet Size for (currentpacket = 0;currentpacket < fullpackets;) { memcpy(packetbuffer, (char*)memstart, packetsize); usb_sendbuffer(gecko_channel,&packetbuffer, packetsize); usb_recvbuffer_safe(gecko_channel,&pcresponse,1); if(pcresponse != 0xAA){ // printf("failed to read packet\n"); return 0; } memstart += packetsize; currentpacket++; } // Remainder if(lastpacketbytes > 0) { memcpy(packetbuffer, (char*)memstart, lastpacketbytes); usb_sendbuffer_safe(gecko_channel,&packetbuffer, lastpacketbytes); usb_recvbuffer_safe(gecko_channel,&pcresponse,1); } // printf("memory dump complete\n"); return 1; }
void gsenddata(const u8 *data, int length, const char *filename) { if (!(geckoinit)) return; // First, send a "\x1b[2B]" line (this will tell geckoreader that binary data is comming up next) const char *binary_data = "\x1b[2B]\n"; usb_sendbuffer_safe(1, binary_data, strlen(binary_data)); u8 filenamelength = filename == NULL ? 0 : strlen(filename); // Send the length usb_sendbuffer_safe(1, (u8 *) &length, 4); usb_sendbuffer_safe(1, (u8 *) &filenamelength, 1); usb_sendbuffer_safe(1, data, length); if (filename != NULL) usb_sendbuffer_safe(1, filename, strlen(filename)); }
//using the gprintf from crediar because it is smaller than mine void gprintf(const char *fmt, ...) { if (!(geckoinit)) return; char astr[4096]; va_list ap; va_start(ap,fmt); vsprintf( astr, fmt, ap ); va_end(ap); usb_sendbuffer_safe( 1, astr, strlen(astr) ); memset(astr, 0, sizeof(astr)); }
void dvd_read_patched_section() { // Check if this read offset+size lies in our patched area, if so, we write a 0xE000 cmd to the drive and read from SDGecko. volatile unsigned long* dvd = (volatile unsigned long*)0xCC006000; u32 dst = dvd[5]; u32 len = dvd[4]; u32 offset = (dvd[3]<<2); int ret = 0; #ifdef DEBUG usb_sendbuffer_safe("New Read: ",10); print_read((void*)dst,len,offset); #endif // If it doesn't let the value about to be passed to the DVD drive be DVD_DMA | DVD_START if((ret=is_frag_read(offset, len))) { #ifdef DEBUG if(ret == 2) { usb_sendbuffer_safe("SPLIT FRAG\r\n",12); } usb_sendbuffer_safe("FRAG READ!\r\n",12); #endif device_frag_read((void*)(dst | 0x80000000), len, offset); dcache_flush_icache_inv((void*)(dst | 0x80000000), len); dvd[3] = 0; dvd[4] = 0x20; dvd[5] = 0; dvd[6] = 0x20; dvd[7] = 3; } else { #ifdef DEBUG usb_sendbuffer_safe("NORM READ!\r\n",12); #endif dvd[7] = 3; // DVD_DMA | DVD_START } }
//using the gprintf from crediar because it is smaller than mine void gprintf( const char *str, ... ) { if (!(geckoinit)) return; char astr[4096]; va_list ap; va_start(ap,str); vsprintf( astr, str, ap ); va_end(ap); usb_sendbuffer_safe( 1, astr, strlen(astr) ); }
int __console_write(struct _reent *r,int fd,const char *ptr,size_t len) { int i = 0; char *tmp = (char*)ptr; console_data_s *con; char chr; if(__gecko_status>=0) { if(__gecko_safe) usb_sendbuffer_safe(__gecko_status,ptr,len); else usb_sendbuffer(__gecko_status,ptr,len); } if(!curr_con) return -1; con = curr_con; if(!tmp || len<=0) return -1; i = 0; while(*tmp!='\0' && i<len) { chr = *tmp++; i++; if ( (chr == 0x1b) && (*tmp == '[') ) { /* escape sequence found */ int k; tmp++; i++; k = __console_parse_escsequence(tmp); tmp += k; i += k; } else { switch(chr) { case '\n': con->cursor_row++; con->cursor_col = 0; break; case '\r': con->cursor_col = 0; break; case '\b': con->cursor_col--; if(con->cursor_col < 0) { con->cursor_col = 0; } break; case '\f': con->cursor_row++; break; case '\t': if(con->cursor_col%TAB_SIZE) con->cursor_col += (con->cursor_col%TAB_SIZE); else con->cursor_col += TAB_SIZE; break; default: __console_drawc(chr); con->cursor_col++; if( con->cursor_col >= con->con_cols) { /* if right border reached wrap around */ con->cursor_row++; con->cursor_col = 0; } } } if( con->cursor_row >= con->con_rows) { /* if bottom border reached scroll */ memcpy(con->destbuffer, con->destbuffer+con->con_stride*(FONT_YSIZE*FONT_YFACTOR+FONT_YGAP), con->con_stride*con->con_yres-FONT_YSIZE); unsigned int cnt = (con->con_stride * (FONT_YSIZE * FONT_YFACTOR + FONT_YGAP))/4; unsigned int *ptr = (unsigned int*)(con->destbuffer + con->con_stride * (con->con_yres - FONT_YSIZE)); while(cnt--) *ptr++ = con->background; con->cursor_row--; } } return i; }
static int usbwrite(struct dbginterface *device,const void *buffer,int size) { int ret; ret = usb_sendbuffer_safe(device->fhndl,buffer,size); return ret; }
//--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- s32 ret; u8 gamestatus = 0x03; u8 versionnumber = 0x80; u32 geckoidcheck; u8 oldconfigbytes[2]; ret = sd_init(); if(!ret){ sd_found = 0; } else { sd_found = 1; } if (*((u32 *) 0x80001804) == 0x53545542 && *((u32 *) 0x80001808) == 0x48415858) loaderhbc = 1; *(u32*)0xCD00643C = 0x00000000; // 32Mhz on Bus gecko_attached = usb_isgeckoalive(EXI_CHANNEL_1); if(gecko_attached){ gecko_channel = 1; if (EXI_GetID(gecko_channel, 0x80, &geckoidcheck) == 1) { if (geckoidcheck != 0) { gecko_attached = FALSE; goto slota; } } else { gecko_attached = FALSE; goto slota; } usb_flushnew(gecko_channel); goto slotb; } slota: gecko_attached = usb_isgeckoalive(EXI_CHANNEL_0); if(gecko_attached){ gecko_channel = 0; if (EXI_GetID(gecko_channel, 0x80, &geckoidcheck) == 1) { if (geckoidcheck != 0) { gecko_attached = FALSE; goto slotb; } } else { gecko_attached = FALSE; goto slotb; } usb_flushnew(gecko_channel); } slotb: sd_load_config(); tempgameconf = (char *) sdbuffer; autobootcheck = 1; memset(gameidbuffer, 0, 8); app_loadgameconfig(gameidbuffer); autobootcheck = 0; loadStartupIOS(); iosversion = IOS_GetVersion(); if(config_not_loaded == 0){ menu_load_config(); config_not_loaded = 1; } if (autoboothbc || !loaderhbc) { if (autoboot == 1) { rebooter_thread(); menu_number = 12; rebooter_thread_state = 0; } } else autoboot = 0; WPAD_Init(); PAD_Init(); VIDEO_Init(); AUDIO_Init (NULL); SYS_SetPowerCallback (power_cb); SYS_SetResetCallback (reset_cb); if (CONF_GetProgressiveScan() > 0 && VIDEO_HaveComponentCable()) { progmode = 1; } if (CONF_GetAspectRatio()) { widescreen = 1; } gfx_init(); gfx_load_gfx(); gfx_load_gfx1(); if (autoboot == 0 || autobootwait > 1) gfx_fade_logo(); VIDEO_WaitVSync(); if(!gecko_attached){ gecko_channel = 2; } gfx_int_stars(); while(1) { if(gecko_attached){ usb_recvbuffer(gecko_channel,&gecko_command,1); switch(gecko_command) { //case 0x04: // gecko_readmem(); //break; case 0x14: // Load DOL load_geckoexe(0); break; case 0x24: // Load DOL load_geckoexe(1); break; case 0x42: // Debugger on, pause start off config_bytes[7] = 0x01; config_bytes[5] = 0x00; usb_recvbuffer_safe(gecko_channel,&oldconfigbytes,2); // Get config config_bytes[0] = oldconfigbytes[0]; switch (oldconfigbytes[1]) { case 0x00: config_bytes[1] = 0x00; break; case 0x01: config_bytes[1] = 0x01; break; case 0x02: config_bytes[1] = 0x00; break; case 0x03: config_bytes[1] = 0x01; break; case 0x04: config_bytes[1] = 0x03; break; case 0x05: config_bytes[1] = 0x03; break; case 0x06: config_bytes[1] = 0x02; break; case 0x07: config_bytes[1] = 0x02; break; } menu_number = 8; apploader_thread(); gecko_command = 0; break; case 0x43: // Debugger on, pause start on config_bytes[7] = 0x01; config_bytes[5] = 0x01; usb_recvbuffer_safe(gecko_channel,&oldconfigbytes,2); // Get config config_bytes[0] = oldconfigbytes[0]; switch (oldconfigbytes[1]) { case 0x00: config_bytes[1] = 0x00; break; case 0x01: config_bytes[1] = 0x01; break; case 0x02: config_bytes[1] = 0x00; break; case 0x03: config_bytes[1] = 0x01; break; case 0x04: config_bytes[1] = 0x03; break; case 0x05: config_bytes[1] = 0x03; break; case 0x06: config_bytes[1] = 0x02; break; case 0x07: config_bytes[1] = 0x02; break; } menu_number = 8; apploader_thread(); gecko_command = 0; break; case 0x50: usb_sendbuffer_safe(gecko_channel,&gamestatus,1); break; case 0x99: usb_sendbuffer_safe(gecko_channel,&versionnumber,1); break; } } if(error_sd || confirm_sd || error_video){ sleep(1); error_sd = 0; confirm_sd = 0; error_video = 0; } if(loadedpng && !alphapng){ // if custom backdrop draw bubbles after image gfx_draw_image(0, 0, 640, 480, tex_logo1, 0, 1, 1,0xff); gfx_draw_stars(); } else{ gfx_draw_stars(); // else if own back drop do in this order due to border clip gfx_draw_image(0, 0, 640, 480, tex_logo1, 0, 1, 1,0xff); }; menu_draw(); gfx_render_direct(); } return 0; }