Nintendo 3DS >> C/C++

Linear Memory


參考資訊:
1. libctru doc
2. 3ds-examples

說明:

API
void* linearAlloc(size_t size)
size_t linearGetSize(void *mem)
void linearFree(void *mem)
u32 linearSpaceFree(void)

main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <3ds.h>
 
int main(void)
{
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    uint32_t fsize = linearSpaceFree();
    printf("linear free size: %d\n", fsize);

    if (fsize > 128) {
        int c = 0;
        u16 *p = linearAlloc(128);
        printf("linear ptr: %p (size: %d)\n", p, linearGetSize(p));

        for (c=0; c<128; c++) {
            p[c] = c;
        }
        for (c=0; c<128; c++) {
            if (p[c] != c) {
                printf("mismatch at 0x%x\n", c);
            }
        }
        linearFree(p);
    }
 
    gspWaitForVBlank();
    gfxSwapBuffers();
    svcSleepThread(3000000000LL);
    gfxExit();
    return 0;
}

完成


返回上一頁