MCPcopy Create free account
hub / github.com/devkitPro/libctru / ndspFindAndLoadComponent

Function ndspFindAndLoadComponent

libctru/source/ndsp/ndsp.c:462–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462static bool ndspFindAndLoadComponent(void)
463{
464 Result rc;
465 Handle rsrc;
466 void* bin;
467
468 componentProgMask = 0xFF;
469 componentDataMask = 0xFF;
470
471 // Try loading the DSP component from the filesystem
472 do
473 {
474 static const char dsp_filename[] = "/3ds/dspfirm.cdc";
475 FS_Path archPath = { PATH_EMPTY, 1, "" };
476 FS_Path filePath = { PATH_ASCII, sizeof(dsp_filename), dsp_filename };
477
478 rc = FSUSER_OpenFileDirectly(&rsrc, ARCHIVE_SDMC, archPath, filePath, FS_OPEN_READ, 0);
479 if (R_FAILED(rc)) break;
480
481 u64 size = 0;
482 rc = FSFILE_GetSize(rsrc, &size);
483 if (R_FAILED(rc)) { FSFILE_Close(rsrc); break; }
484
485 bin = malloc(size);
486 if (!bin) { FSFILE_Close(rsrc); break; }
487
488 u32 dummy = 0;
489 rc = FSFILE_Read(rsrc, &dummy, 0, bin, size);
490 FSFILE_Close(rsrc);
491 if (R_FAILED(rc)) { free(bin); return false; }
492
493 componentBin = bin;
494 componentSize = size;
495 componentFree = true;
496 return true;
497 } while (0);
498
499 // Try loading the DSP component from hb:ndsp
500 rsrc = envGetHandle("hb:ndsp");
501 if (rsrc) do
502 {
503 extern char* fake_heap_end;
504 u32 mapAddr = ((u32)fake_heap_end+0xFFF) &~ 0xFFF;
505 rc = svcMapMemoryBlock(rsrc, mapAddr, MEMPERM_READWRITE, MEMPERM_READWRITE);
506 if (R_FAILED(rc)) break;
507
508 componentSize = *(u32*)(mapAddr + 0x104);
509 bin = malloc(componentSize);
510 if (bin)
511 memcpy(bin, (void*)mapAddr, componentSize);
512 svcUnmapMemoryBlock(rsrc, mapAddr);
513 if (!bin) break;
514
515 componentBin = bin;
516 componentFree = true;
517 return true;
518 } while (0);
519

Callers 1

ndspInitFunction · 0.85

Calls 5

FSUSER_OpenFileDirectlyFunction · 0.85
FSFILE_GetSizeFunction · 0.85
FSFILE_CloseFunction · 0.85
FSFILE_ReadFunction · 0.85
envGetHandleFunction · 0.85

Tested by

no test coverage detected