2014-11-20 00:53:36 +01:00
|
|
|
///////////////////////////////////////
|
|
|
|
// SDMC example //
|
|
|
|
///////////////////////////////////////
|
2014-01-24 23:33:46 +01:00
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
//this example shows you how to load a binary image file from the SD card and display it on the lower screen
|
2014-12-26 02:11:13 +01:00
|
|
|
//for this to work you should copy test.bin to same folder as your .3dsx
|
2014-11-20 00:53:36 +01:00
|
|
|
//this file was generated with GIMP by saving a 240x320 image to raw RGB
|
2014-11-28 22:34:46 +01:00
|
|
|
#include <string.h>
|
2014-12-26 02:11:13 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-01-24 23:33:46 +01:00
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
#include <3ds.h>
|
|
|
|
#include "costable.h"
|
2014-03-02 16:11:04 +01:00
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
//this will contain the data read from SDMC
|
|
|
|
u8* buffer;
|
2014-01-24 23:33:46 +01:00
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
//3DS has VFPs so we could just use cos
|
|
|
|
//but we're old school so LUT4life
|
2014-01-24 23:33:46 +01:00
|
|
|
s32 pcCos(u16 v)
|
|
|
|
{
|
|
|
|
return costable[v&0x1FF];
|
|
|
|
}
|
|
|
|
|
|
|
|
void renderEffect()
|
|
|
|
{
|
2014-11-20 00:53:36 +01:00
|
|
|
static int cnt;
|
|
|
|
u8* bufAdr=gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
int i, j;
|
|
|
|
for(i=1;i<400;i++)
|
|
|
|
{
|
|
|
|
for(j=1;j<240;j++)
|
|
|
|
{
|
|
|
|
u32 v=(j+i*240)*3;
|
2014-11-20 00:53:36 +01:00
|
|
|
bufAdr[v]=(pcCos(i+cnt)+4096)/32;
|
|
|
|
bufAdr[v+1]=(pcCos(j-256+cnt)+4096)/64;
|
|
|
|
bufAdr[v+2]=(pcCos(i+128-cnt)+4096)/32;
|
2014-01-24 23:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 00:53:36 +01:00
|
|
|
|
|
|
|
cnt++;
|
2014-01-24 23:33:46 +01:00
|
|
|
}
|
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
int main(int argc, char** argv)
|
2014-01-24 23:33:46 +01:00
|
|
|
{
|
2014-12-26 02:11:13 +01:00
|
|
|
|
2015-01-03 01:06:22 +01:00
|
|
|
gfxInitDefault(); //makes displaying to screen easier
|
2014-12-26 02:11:13 +01:00
|
|
|
|
|
|
|
FILE *file = fopen("test.bin","rb");
|
|
|
|
if (file == NULL) goto exit;
|
|
|
|
|
|
|
|
// seek to end of file
|
|
|
|
fseek(file,0,SEEK_END);
|
|
|
|
|
|
|
|
// file pointer tells us the size
|
|
|
|
off_t size = ftell(file);
|
|
|
|
|
|
|
|
// seek back to start
|
|
|
|
fseek(file,0,SEEK_SET);
|
|
|
|
|
|
|
|
//allocate a buffer
|
|
|
|
buffer=malloc(size);
|
2014-11-20 00:53:36 +01:00
|
|
|
if(!buffer)goto exit;
|
2014-01-24 23:33:46 +01:00
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
//read contents !
|
2014-12-26 02:11:13 +01:00
|
|
|
off_t bytesRead = fread(buffer,1,size,file);
|
2014-11-20 00:53:36 +01:00
|
|
|
|
|
|
|
//close the file because we like being nice and tidy
|
2014-12-26 02:11:13 +01:00
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
if(size!=bytesRead)goto exit;
|
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
while(aptMainLoop())
|
2014-01-24 23:33:46 +01:00
|
|
|
{
|
2014-11-20 00:53:36 +01:00
|
|
|
//exit when user hits B
|
|
|
|
hidScanInput();
|
|
|
|
if(keysHeld()&KEY_B)break;
|
|
|
|
|
|
|
|
//render rainbow
|
|
|
|
renderEffect();
|
|
|
|
|
|
|
|
//copy buffer to lower screen (don't have to do it every frame)
|
|
|
|
memcpy(gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), buffer, size);
|
|
|
|
|
|
|
|
//wait & swap
|
|
|
|
gfxSwapBuffersGpu();
|
2015-11-11 21:13:31 +01:00
|
|
|
gspWaitForEvent(GSPGPU_EVENT_VBlank0, false);
|
2014-01-24 23:33:46 +01:00
|
|
|
}
|
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
//cleanup and return
|
|
|
|
//returning from main() returns to hbmenu when run under ninjhax
|
|
|
|
exit:
|
2014-12-26 02:11:13 +01:00
|
|
|
|
2014-11-20 00:53:36 +01:00
|
|
|
//closing all services even more so
|
|
|
|
gfxExit();
|
2014-01-24 23:33:46 +01:00
|
|
|
return 0;
|
|
|
|
}
|