void Display::slidersUpdate(){ bool change = false; if (Cfg::sliders.bank != Cfg::sliders.previousBank){ sliders(); Cfg::sliders.previousBank = Cfg::sliders.bank; change = true; } CCParam* sliderCC; for (u8 s = 0; s < 16; ++s){ sliderCC = &Cfg::sliders.ccs[Cfg::sliders.bank][s]; if (Cfg::ccChangedVblank[(*sliderCC).channel][(*sliderCC).cc]){ updateSliderUpMap(s); change = true; } } DC_FlushAll(); dmaCopy(this->slidersBg2Map, bgGetMapPtr(subbg2), 1536); if (change){ DC_FlushAll(); dmaCopy(this->slidersBg3Map, bgGetMapPtr(subbg3), 1536); } showBank(Cfg::sliders.bank, 3); }
void ndsloadstub() { void (*func_ptr)(void) = (void*)ARM9STUBVMA; #ifndef BOOTHB swiDecompressLZSSWram((void*)ndsloader_lz, (void*)BOOTLDR_NDS); *((u32*)(BOOTLDR_NDS-8)) = *((u32*)ndsloader_lz) >> 8; #endif DC_FlushAll(); DC_InvalidateAll(); IC_InvalidateAll(); BOOTFLAG = 0; VRAM_C_CR = VRAM_ENABLE | VRAM_C_LCD; #ifndef BOOTHB NDSHEADER->arm7executeAddress = 0x06000000; #endif memcpy16((void*)ARM9STUBVMA, arm9stub_bin, arm9stub_bin_size); memcpy16(VRAM_C, arm7stub_bin, arm7stub_bin_size); VRAM_C_CR = VRAM_ENABLE | VRAM_C_ARM7_0x06000000; DC_FlushAll(); DC_InvalidateAll(); IC_InvalidateAll(); #ifdef BOOTHB resetARM7(0x06000000); #endif func_ptr(); }
void updateOAM(OAMTable * oam) { DC_FlushAll(); dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->oamBuffer, OAM, SPRITE_COUNT * sizeof(SpriteEntry)); }
void Display::modeSelektor(){ //Displaying bg3, and mode sprites bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(subbg3); s8 i; for (i = 0; i < 4; ++i){ modesSprite->display(64 + i, 32 + 128 * (i % 2), 16 + 96 * (i / 2), OBJPRIORITY_0, i); } oamUpdate(&oamSub); input->paused = true; while(!(Cfg::modeSelector && input->pad->select() == DOWN) && input->modeSelektor() != 1){ swiWaitForVBlank(); } Cfg::modeSelector = false; oamClear(&oamSub, 64, 4); if (Cfg::mode == SLIDERS){ dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(this->subbg3), slidersBg3SubTilesLen); dmaCopy(this->slidersBg3Map, bgGetMapPtr(this->subbg3), 1536); } else { bgSetPriority(this->subbg3, 2); bgHide(this->subbg3); } }
// MIXER Functions //------------------------------------------------------------------------- void Display::mixer(){ clearGfx(); DC_FlushAll(); dmaCopy(mixerBgSubTiles, bgGetGfxPtr(subbg2), mixerBgSubTilesLen); dmaCopy(mixerBgSubMap, bgGetMapPtr(subbg2), mixerBgSubMapLen); for (u8 i = 0; i < 8; ++i) muteSprite->display(i, i*32 , 163, 1, 1); bgHide(mainbg3); save->writeCcs(); }
void Display::editKaossParams(){ CCParam* ccParam = NULL; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<3; ++i){ if (i == 0){ echo(0, RED, 5, 7 + 8*(i%8), "X"); ccParam = &Cfg::kaoss.x[Cfg::kaoss.bank]; } if (i == 1){ echo(0, RED, 5, 7 + 8*(i%8), "Y"); ccParam = &Cfg::kaoss.y[Cfg::kaoss.bank]; } if (i == 2){ echo(0, RED, 5, 7 + 8*(i%8), "Z"); ccParam = &Cfg::kaoss.z[Cfg::kaoss.bank]; } echo(0, WHITE, 8, 7 + 8*(i%8), "CC"); paramsEditSprite->display(16+i, 56 + 64*(i%8), 72, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 10, 6 + 8*(i%8), (*ccParam).cc); paramsEditSprite->display(32+i, 56 + 64*(i%8), 88, OBJPRIORITY_0, 1); echo(0, WHITE, 13, 7 + 8*(i%8), "CH"); paramsEditSprite->display(48+i, 56 + 64*(i%8), 112, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 15, 6 + 8*(i%8), 1 + (*ccParam).channel); paramsEditSprite->display(64+i, 56 + 64*(i%8), 128, OBJPRIORITY_0, 1); } oamUpdate(&oamSub); input->editKaossParams(); Cfg::editParams = true; swiWaitForVBlank(); } Cfg::editParams = false; save->write(); oamClear(&oamSub, 16, 80); consoleClear(); if (Cfg::mode == SLIDERS){ dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(this->subbg3), slidersBg3SubTilesLen); dmaCopy(slidersBg3Map, bgGetMapPtr(this->subbg3), 1536); } else { bgSetPriority(this->subbg3, 2); bgHide(this->subbg3); } }
// SLIDERS Functions //------------------------------------------------------------------------- void Display::sliders(){ clearGfx(); for(u8 i = 0; i<16; ++i){ this->updateSliderMap(i); this->updateSliderUpMap(i); } DC_FlushAll(); dmaCopy(slidersBg2SubTiles, bgGetGfxPtr(subbg2), slidersBg2SubTilesLen); dmaCopy(slidersBg3SubTiles, bgGetGfxPtr(subbg3), slidersBg3SubTilesLen); DC_FlushAll(); dmaCopy(slidersBg2Map, bgGetMapPtr(subbg2), 1536); dmaCopy(slidersBg3Map, bgGetMapPtr(subbg3), 1536); echo(1, LIGHT_GREY, 1, 2, "BANK:"); echo(1, WHITE, 6, 3, "BANK-"); echo(1, WHITE, 6, 19, "BANK;"); bgHide(mainbg3); save->writeCcs(); }
void SampleDisplay::penUp(u8 px, u8 py) { // Swap selstart and selend if they are in the wrong order if(selend < selstart) { u32 tmp = selstart; selstart = selend; selend = tmp; } if( pen_on_zoom_in || pen_on_zoom_out || pen_on_scroll_left || pen_on_scroll_right || pen_on_scrollthingy || pen_on_scrollbar) { pen_on_zoom_in = pen_on_zoom_out = pen_on_scroll_left = pen_on_scroll_right = pen_on_scrollthingy = pen_on_scrollbar = false; draw(); } else if(pen_on_loop_start_point) { if(snap_to_zero_crossings) { s32 oldstart = smp->getLoopStart(); s32 zerocrossing = find_zero_crossing_near(smp->getLoopStart()); if(zerocrossing != -1) { smp->setLoopLength(smp->getLoopLength() - (zerocrossing - oldstart)); smp->setLoopStart(zerocrossing); DC_FlushAll(); draw(); } } } else if(pen_on_loop_end_point) { if(snap_to_zero_crossings) { s32 zerocrossing = find_zero_crossing_near(smp->getLoopStart() + smp->getLoopLength()); if(zerocrossing != -1) { smp->setLoopLength( zerocrossing - smp->getLoopStart() ); DC_FlushAll(); draw(); } } } pen_on_loop_start_point = false; pen_on_loop_end_point = false; }
void Display::editMixerParams(){ CCParam ccParam; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); echo(0, RED, 0, 13, "MIXER"); echo(0, RED, 12, 13, "MUTES"); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<8; ++i){ ccParam = Cfg::mixer.ccs[i]; echo(0, WHITE, 2, 1 + 4*(i%8), "CC"); paramsEditSprite->display(16+i, 8 + 32*(i%8), 24, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 4, 4*(i%8), ccParam.cc); paramsEditSprite->display(32+i, 8 + 32*(i%8), 40, OBJPRIORITY_0, 1); echo(0, WHITE, 6, 1 + 4*(i%8), "CH"); paramsEditSprite->display(48+i, 8 + 32*(i%8), 56, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 8, 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(64+i, 8 + 32*(i%8), 72, OBJPRIORITY_0, 1); ccParam = Cfg::mixer.mutes[i]; echo(0, WHITE, 14, 1 + 4*(i%8), "CC"); paramsEditSprite->display(24+i, 8 + 32*(i%8), 120, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 16, 4*(i%8), ccParam.cc); paramsEditSprite->display(40+i, 8 + 32*(i%8), 136, OBJPRIORITY_0, 1); echo(0, WHITE, 18, 1 + 4*(i%8), "CH"); paramsEditSprite->display(56+i, 8 + 32*(i%8), 152, OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 20, 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(72+i, 8 + 32*(i%8), 168, OBJPRIORITY_0, 1); } oamUpdate(&oamSub); input->editMixerParams(); Cfg::editParams = true; swiWaitForVBlank(); } save->write(); Cfg::editParams = false; oamClear(&oamSub, 16, 80); consoleClear(); }
void nandread() { if(*((u32*)0x02ffe230) != 0x4b344445 && *((u32*)0x02ffe230) != 0x484e4145)return; void (*FS_InitCtx)(u8*); int (*FS_Open)(u8*, char*, u32); int (*FS_Close)(u8*); int (*FS_Read)(u8*, u8*, u32); u8 ctx[0x48]; if(*((u32*)0x02ffe230) == 0x4b344445) { FS_InitCtx = (void*)0x20a1c6c; FS_Open = (void*)0x20a1ea4; FS_Close = (void*)0x20a1f28; } else if(*((u32*)0x02ffe230) == 0x484e4145)//launcher. note that this launcher stuff is for on-the-fly patching stuff, no nand-based only hax. { FS_InitCtx = (void*)0x26baf99; FS_Open = (void*)0x26bb4c5; FS_Close = (void*)0x26bb511; FS_Read = (void*)0x26bb581; } if(*((u32*)0x02ffe230) == 0x4b344445) { nandread_asm(); DC_FlushAll(); REG_IME = 1; FS_InitCtx(ctx); if(FS_Open(ctx, "nand:/<tmpjump>", 1)==1)FS_Close(ctx); REG_IME = 0; } else if(*((u32*)0x02ffe230) == 0x484e4145) { REG_IME = 1; FS_InitCtx(ctx); if(FS_Open(ctx, "nand:/sys/arm7hax.bin", 1)==1) { FS_Read(ctx, (void*)0x3780260, 0x40);//this is the beginning of the nand_read_sectors func. since this data won't get written there until after that func returns, another read is triggered below. FS_Close(ctx); FS_InitCtx(ctx); if(FS_Open(ctx, "nand:/<tmpjump>", 1)==1)FS_Close(ctx);//unless the arm7hax code returns,(my local code doesn't) this will hang. } REG_IME = 0; } }
void PA_PlaySoundEx2(u8 PA_Channel, const void* data, s32 length, u8 volume, int freq, s16 format, bool repeat, int repeatPoint){ DC_FlushAll(); PA_IPC.Sound[PA_Channel].Busy = 1; // now busy // keep this in for compatibility with some functions // Sound commands //PA_IPC.Sound[PA_Channel].Command |= (1<<PAIPC_PLAY); // play PA_IPC.Sound[PA_Channel].Data = (u32*)data; PA_IPC.Sound[PA_Channel].Volume = volume; PA_IPC.Sound[PA_Channel].Pan = 64; PA_IPC.Sound[PA_Channel].Rate = freq; PA_IPC.Sound[PA_Channel].Length = length-4; PA_IPC.Sound[PA_Channel].Format = format; PA_IPC.Sound[PA_Channel].Repeat = repeat; PA_IPC.Sound[PA_Channel].RepeatPoint = repeatPoint; PA_IPC.Sound[PA_Channel].Duty = 0; // PA_IPC.Sound[PA_Channel].Pause = 0; PA_IPC.Sound[PA_Channel].Command |= (1<<PAIPC_PLAY); // play }
void RecordBox::stopRecording() { int size = CommandStopRecording(); // Security check if(size < RECORDBOX_CROP_SAMPLES_END + RECORDBOX_CROP_SAMPLES_START) { free(sound_data); sample = NULL; onOk(); #ifdef DEBUG printf("omfg\n"); #endif return; } // Get pointer to sound data and shrink it beautiful u32 newsize = size - RECORDBOX_CROP_SAMPLES_END*2; // Crop the end because it contains the clicking of the button sound_data = (u16*)realloc(sound_data, newsize); //Cut the first few samples if(RECORDBOX_CROP_SAMPLES_START < newsize) { memmove(sound_data, sound_data+RECORDBOX_CROP_SAMPLES_START*2, newsize-RECORDBOX_CROP_SAMPLES_START*2); newsize -= RECORDBOX_CROP_SAMPLES_START*2; sound_data = (u16*)realloc(sound_data, newsize); } sample = new Sample(sound_data, newsize/2, RECORDBOX_SAMPLING_FREQ); sample->setName("rec"); //smp->cutSilence(); // Cut silence in the beginning (experiMENTAL!) recording = false; DC_FlushAll(); onOk(); }
rtems_device_driver sound_initialize (rtems_device_major_number major, rtems_device_minor_number minor, void *arg) { rtems_status_code status; printk ("[+] sound started\n"); /* register the devices */ status = rtems_io_register_name ("/dev/pcm", major, 0); if (status != RTEMS_SUCCESSFUL) { printk ("[!] error registering sound\n"); rtems_fatal_error_occurred (status); } /* reset IPCs structs */ IPC->soundData = NULL; memset ((void *)my_IPC, 0, sizeof (*my_IPC)); DC_FlushAll (); return RTEMS_SUCCESSFUL; }
void Display::editSliderParams(){ CCParam ccParam; u8 color; bgSetPriority(this->subbg3, 1); DC_FlushAll(); dmaCopy(greyedBgSubTiles, bgGetGfxPtr(this->subbg3), greyedBgSubTilesLen); dmaCopy(greyedBgSubMap, bgGetMapPtr(this->subbg3), greyedBgSubMapLen); bgShow(this->subbg3); while(!(Cfg::editParams && input->pad->start() == DOWN)){ for (u8 i = 0; i<16; ++i){ ccParam = Cfg::sliders.ccs[Cfg::sliders.bank][i]; color = Cfg::sliders.colors[Cfg::sliders.bank][i]; echo(0, WHITE, 12*(i/8) , 1 + 4*(i%8), "CC"); paramsEditSprite->display(16+i, 8 + 32*(i%8), 8 + 96*(i/8), OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 2 + 12*(i/8) , 4*(i%8), ccParam.cc); paramsEditSprite->display(32+i, 8 + 32*(i%8), 24 + 96*(i/8), OBJPRIORITY_0, 1); echo(0, WHITE, 4+12*(i/8) , 1 + 4*(i%8), "CH"); paramsEditSprite->display(48+i, 8 + 32*(i%8), 40 + 96*(i/8), OBJPRIORITY_0, 0); iprintf("\x1b[%d;%dH%3d", 6 + 12*(i/8) , 4*(i%8), 1 + ccParam.channel); paramsEditSprite->display(64+i, 8 + 32*(i%8), 56 + 96*(i/8), OBJPRIORITY_0, 1); paramsEditSprite->display(80+i, 8 + 32*(i%8), 72 + 96*(i/8), OBJPRIORITY_0, color + 2); } oamUpdate(&oamSub); input->editSliderParams(); Cfg::editParams = true; swiWaitForVBlank(); } save->write(); Cfg::editParams = false; oamClear(&oamSub, 16, 80); consoleClear(); sliders(); }
int main(void) { neoClearContext(); DC_FlushAll(); memset((void*)NEOIPC, 0, sizeof(TNeoIPC)); //NEOIPC->arm7Ready = 0; //NEOIPC->arm9Ready = 0; NEOIPC->audioCommand = 0; NEOIPC->audioResult = 0; //NEOIPC->audioEnabled = 1; NEOIPC->globalAudioEnabled = 1; //NEOIPC->pZ80DaaTable = Z80DaaTable; neoIPCInit(); guiSystemInit(); bool initOk = systemInit(); if(!initOk) { systemPanic("systemInit failed", 0); return 0; } //neoCrt0(); neoSystemInit(); guiFrameNew(TGuiLayoutMain); guiSystemProcess(); guiFramePush(TGuiLayoutRomSelect); g_neo->active = false; neoSystemExecute(); return 0; }
rtems_device_driver sound_write (rtems_device_major_number major, rtems_device_minor_number minor, void *arg) { rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *) arg; static TransferSound snd; /* XXX not exclusive */ while (IPC->soundData != NULL); snd.count = 1; snd.data[0].data = rw_args->buffer; snd.data[0].len = rw_args->count; snd.data[0].rate = freq; snd.data[0].vol = volume; snd.data[0].pan = pan; snd.data[0].format = format; IPC->soundData = &snd; DC_FlushAll (); rw_args->bytes_moved = rw_args->count; return RTEMS_SUCCESSFUL; }
/// Para un origen 8 bits por pixel. void BndsModifier::screenshotToBmp1BitBase64(const char* filename) { FILE* file=fopen(filename, "wb"); int imageWidth = 256; // 215 int imageHeight = 192; // 170 int imageXOffset = 0; // 41 int imageYOffset = 0; int imageSize = imageWidth*imageHeight/8; u16 offset = sizeof(INFOHEADER)+sizeof(HEADER)+(sizeof(INFOPALETTE)*2); u8* temp=(u8*)malloc(imageSize+offset); HEADER* header=(HEADER*)temp; INFOHEADER* infoheader=(INFOHEADER*)(temp+sizeof(HEADER)); INFOPALETTE* palette0=(INFOPALETTE*)(temp+sizeof(HEADER)+sizeof(INFOHEADER)); INFOPALETTE* palette1=(INFOPALETTE*)(temp+sizeof(HEADER)+sizeof(INFOHEADER)+sizeof(INFOPALETTE)); write16(&header->type, 0x4D42); write32(&header->size, imageSize+offset); write32(&header->offset, offset); write16(&header->reserved1, 0); write16(&header->reserved2, 0); write16(&infoheader->bits, 1); write32(&infoheader->size, sizeof(INFOHEADER)); write32(&infoheader->compression, 0); write32(&infoheader->width, imageWidth); write32(&infoheader->height, imageHeight); write16(&infoheader->planes, 1); write32(&infoheader->imagesize, imageSize); write32(&infoheader->xresolution, 0); write32(&infoheader->yresolution, 0); write32(&infoheader->importantcolours, 0); write32(&infoheader->ncolours, 2); write8(&palette0->blue, 0x00); write8(&palette0->green, 0x00); write8(&palette0->red, 0x00); write8(&palette0->reserved, 0x00); write8(&palette1->blue, 0xFF); write8(&palette1->green, 0xFF); write8(&palette1->red, 0xFF); write8(&palette1->reserved, 0x00); for (int y = imageYOffset; y < imageHeight; y++) { for (int x = imageXOffset; x < imageWidth; x++) { u8 pixel = getPixel8bpp ( x, y, (u16*)bgGetGfxPtr(g_video->backgroundMain()) ); drawPixel1bpp ( x - imageXOffset, (192 - y) - imageYOffset, pixel, temp, offset ); } // end for } // end for DC_FlushAll(); /// Codifica el archivo BMP en Base64. string encoded = base64_encode(reinterpret_cast<const unsigned char*>(temp), imageSize+offset); //fwrite(temp, 1, imageSize+offset, file); fwrite(encoded.data(), 1, encoded.size(), file); fclose(file); free(temp); }
void SampleDisplay::penMove(u8 px, u8 py) { if((smp==0) || ( (active==false) && (loop_points_visible==false) && (draw_mode == false) ) ) return; if(pen_on_loop_start_point) { s32 olstart = smp->getLoopStart(); s32 newstart = pixelToSample((s32)px-(s32)x-1-(s32)loop_touch_offset); smp->setLoopStartAndLength(newstart, MAX(0, (s32)smp->getLoopLength() - (newstart - olstart))); DC_FlushAll(); } else if(pen_on_loop_end_point) { s32 newlength = (s32)pixelToSample((s32)px-(s32)x-1-(s32)loop_touch_offset) - smp->getLoopStart(); if(newlength < 0) { u32 newstart = smp->getLoopStart() + newlength; smp->setLoopStart(newstart); newlength = 0; } smp->setLoopLength(newlength); DC_FlushAll(); } else if(pen_on_scrollthingy) { scrollthingypos = my_clamp(px - x - pen_x_on_scrollthingy - SCROLLBUTTON_HEIGHT, 0, width - 2*SCROLLBUTTON_HEIGHT+2 - scrollthingywidth); u32 window_width = width - 2; u32 disp_width = window_width << zoom_level; u32 scroll_width = width - 2*SCROLLBUTTON_HEIGHT+2 - scrollthingywidth; scrollpos = scrollthingypos * (disp_width - window_width) / scroll_width; } else if( !pen_on_zoom_in && !pen_on_zoom_out && !pen_on_scroll_left && !pen_on_scroll_right && !pen_on_scrollbar) { if(active and !draw_mode) { if(px<x+1) selend = pixelToSample(0); else if(px-x<width-1) selend = pixelToSample(px-x); else selend = pixelToSample(width-2); if(selstart != selend) selection_exists = true; } else if(draw_mode) { int draw_x = my_clamp(px - x - 1, 0, width-2); int draw_y = my_clamp(py - y - 1, 0, DRAW_HEIGHT-1); u32 sx1 = pixelToSample(draw_last_x); u32 sx2 = pixelToSample(draw_x); s16 sy1, sy2; if(smp->is16bit()) { sy1 = 65535 * (DRAW_HEIGHT/2 - draw_last_y) / DRAW_HEIGHT; sy2 = 65535 * (DRAW_HEIGHT/2 - draw_y) / DRAW_HEIGHT; } else { sy1 = 255 * (DRAW_HEIGHT/2 - draw_last_y) / DRAW_HEIGHT; sy2 = 255 * (DRAW_HEIGHT/2 - draw_y) / DRAW_HEIGHT; } smp->drawLine(sx1, sy1, sx2, sy2); DC_FlushAll(); draw_last_x = draw_x; draw_last_y = draw_y; } } draw(); }
//copy our sprite to object attribute memory static inline void updateOAM(u32 Count) { DC_FlushAll(); glMemCopy32CPU(sprites, OAM, Count * sizeof(SpriteEntry)); }
void ScreenEngine::updateOAM() { DC_FlushAll(); dmaCopy(_sprites, _oam, 128 * sizeof(SpriteEntry)); }
void Instrument::setVolEnvEnabled(bool is_enabled) { vol_env_on = is_enabled; DC_FlushAll(); }
//copy our sprite to object attribute memory void updateOAM(void) { DC_FlushAll(); dmaCopy(sprites, OAM, 128 * sizeof(SpriteEntry)); }
//--------------------------------------------------------------------------------- int loadNDS(int socket, u32 remote) { //--------------------------------------------------------------------------------- int len; int i=0; ioctl(socket,FIONBIO,&i); len = recvall(socket,__NDSHeader,512,0); if (len != 512) { kprintf("Error reading header.\n"); return 1; } int arm7dest = __NDSHeader->arm7destination; int arm7size = __NDSHeader->arm7binarySize; int arm9dest = __NDSHeader->arm9destination; int arm9size = __NDSHeader->arm9binarySize; volatile int response = 0; if (arm9dest + arm9size > (int)_start) response = 1; if (arm7dest >= 0x02000000 && arm7dest < 0x03000000 && arm7dest + arm7size > (int)_start) response = 2; send(socket,(int *)&response,sizeof(response),0); if(response) return 1; kprintf("Reading arm7 binary: "); if (progressRead(socket,(char *)memUncached((void*)0x02000000),arm7size)) { kprintf("\nReceive error.\n"); return 1; } fifoSendValue32(FIFO_USER_01,1); while(!fifoCheckValue32(FIFO_USER_01)) { swiIntrWait(1,IRQ_FIFO_NOT_EMPTY); } fifoGetValue32(FIFO_USER_01); kprintf("Reading arm9 binary: "); if(progressRead(socket,(char *)arm9dest,arm9size)) { kprintf("\nReceive error.\n"); return 1; } volatile int cmdlen=0; char *cmdline; if (arm9size != 0){ cmdline = (char*)(arm9dest+arm9size); } else { cmdline = (char*)(arm7dest+arm7size); } len = recvall(socket,(char*)&cmdlen,4,0); if (cmdlen) { len = recvall(socket,cmdline,cmdlen,0); __system_argv->argvMagic = ARGV_MAGIC; __system_argv->commandLine = cmdline; __system_argv->length = cmdlen; __system_argv->host = remote; } Wifi_DisableWifi(); DC_FlushAll(); REG_IPC_SYNC = 0; fifoSendValue32(FIFO_USER_01,2); fifoSendValue32(FIFO_USER_01,__NDSHeader->arm9executeAddress); irqDisable(IRQ_ALL); REG_IME = 0; //clear out ARM9 DMA channels for (i=0; i<4; i++) { DMA_CR(i) = 0; DMA_SRC(i) = 0; DMA_DEST(i) = 0; TIMER_CR(i) = 0; TIMER_DATA(i) = 0; } u16 *mainregs = (u16*)0x04000000; u16 *subregs = (u16*)0x04001000; for (i=0; i<43; i++) { mainregs[i] = 0; subregs[i] = 0; } REG_DISPSTAT = 0; dmaFillWords(0, BG_PALETTE, (2*1024)); VRAM_A_CR = 0x80; dmaFillWords(0, VRAM, 128*1024); VRAM_A_CR = 0; VRAM_B_CR = 0; // Don't mess with the ARM7's VRAM // VRAM_C_CR = 0; VRAM_D_CR = 0; VRAM_E_CR = 0; VRAM_F_CR = 0; VRAM_G_CR = 0; VRAM_H_CR = 0; VRAM_I_CR = 0; REG_POWERCNT = 0x820F; //set shared ram to ARM7 WRAM_CR = 0x03; // Return to passme loop *((vu32*)0x02FFFE04) = (u32)0xE59FF018; // ldr pc, 0x02FFFE24 *((vu32*)0x02FFFE24) = (u32)0x02FFFE04; // Set ARM9 Loop address REG_IPC_SYNC = 0x500; arm9Reset(); while(1); }
void iconTitleUpdate (int isdir, const char* name) { writeRow (0,name); writeRow (1,""); writeRow (2,""); writeRow (3,""); if (isdir) { // text writeRow (2,"[directory]"); // icon clearIcon(); } else if(strlen(name) >= 5 && strcasecmp(name + strlen(name) - 5, ".argv") == 0) { // look through the argv file for the corresponding nds file FILE *fp; char *line = NULL, *p = NULL; size_t size = 0; ssize_t rc; // open the argv file fp = fopen(name,"rb"); if(fp == NULL) { writeRow(2, "(can't open file!)"); clearIcon(); fclose(fp); return; } // read each line while((rc = __getline(&line, &size, fp)) > 0) { // remove comments if((p = strchr(line, '#')) != NULL) *p = 0; // skip leading whitespace for(p = line; *p && isspace((int)*p); ++p) ; if(*p) break; } // done with the file at this point fclose(fp); if(p && *p) { // we found an argument struct stat st; // truncate everything after first argument strtok(p, "\n\r\t "); if(strlen(p) < 4 || strcasecmp(p + strlen(p) - 4, ".nds") != 0) { // this is not an nds file! writeRow(2, "(invalid argv file!)"); clearIcon(); } else { // let's see if this is a file or directory rc = stat(p, &st); if(rc != 0) { // stat failed writeRow(2, "(can't find argument!)"); clearIcon(); } else if(S_ISDIR(st.st_mode)) { // this is a directory! writeRow(2, "(invalid argv file!)"); clearIcon(); } else { iconTitleUpdate(false, p); } } } else { writeRow(2, "(no argument!)"); clearIcon(); } // clean up the allocated line free(line); } else { // this is an nds file! FILE *fp; unsigned int Icon_title_offset; int ret; // open file for reading info fp=fopen (name,"rb"); if (fp==NULL) { // text writeRow (2,"(can't open file!)"); // icon clearIcon(); fclose (fp); return; } ret=fseek (fp, offsetof(tNDSHeader, bannerOffset), SEEK_SET); if (ret==0) ret=fread (&Icon_title_offset, sizeof(int), 1, fp); // read if seek succeed else ret=0; // if seek fails set to !=1 if (ret!=1) { // text writeRow (2,"(can't read file!)"); // icon clearIcon(); fclose (fp); return; } if (Icon_title_offset==0) { // text writeRow (2,"(no title/icon)"); // icon clearIcon(); fclose (fp); return; } ret=fseek (fp,Icon_title_offset,SEEK_SET); if (ret==0) ret=fread (&banner, sizeof(banner), 1, fp); // read if seek succeed else ret=0; // if seek fails set to !=1 if (ret!=1) { // text writeRow (2,"(can't read icon/title!)"); // icon clearIcon(); fclose (fp); return; } // close file! fclose (fp); // turn unicode into ascii (kind of) // and convert 0x0A into 0x00 int i; char *p = (char*)banner.titles[0]; for (i = 0; i < sizeof(banner.titles[0]); i = i+2) { if ((p[i] == 0x0A) || (p[i] == 0xFF)) p[i/2] = 0; else p[i/2] = p[i]; } // text for(i = 0; i < 3; ++i) { writeRow (i+1, p); p += strlen(p)+1; } // icon DC_FlushAll(); dmaCopy(banner.icon, sprite, sizeof(banner.icon)); dmaCopy(banner.palette, SPRITE_PALETTE, sizeof(banner.palette)); } }