Skip to content

Commit

Permalink
Updated to the latest ctrulib, Fixed some minor bugs.
Browse files Browse the repository at this point in the history
Working with citra, untested on real hardware but should be OK.
IR should now work.
Let's add some 3D drawing and sound now !
  • Loading branch information
firew0lf committed Dec 14, 2015
1 parent b4d025d commit 2e782ed
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 91 deletions.
4 changes: 4 additions & 0 deletions libs/sf2dlib/libsf2d/Makefile
Expand Up @@ -30,6 +30,10 @@ CFLAGS := -g -Wall -O2\
$(ARCH)

CFLAGS += $(INCLUDE) -DARM11 -D_3DS

#WILL HAVE TO BE REMOVED SOON
CFLAGS += -DLIBCTRU_NO_DEPRECATION

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS := -g $(ARCH)
Expand Down
26 changes: 13 additions & 13 deletions libs/sf2dlib/libsf2d/source/sf2d.c
Expand Up @@ -35,7 +35,7 @@ static float ortho_matrix_bot[4*4];
//Apt hook cookie
static aptHookCookie apt_hook_cookie;
//Functions
static void apt_hook_func(int hook, void* param);
static void apt_hook_func(APT_HookType hook, void *param);
static void reset_gpu_apt_resume();

int sf2d_init()
Expand Down Expand Up @@ -87,7 +87,7 @@ int sf2d_init_advanced(int gpucmd_size, int temppool_size)
cur_side = GFX_LEFT;

GPUCMD_Finalize();
GPUCMD_FlushAndRun(NULL);
GPUCMD_FlushAndRun();
gspWaitForP3D();

sf2d_pool_reset();
Expand Down Expand Up @@ -144,8 +144,8 @@ void sf2d_start_frame(gfxScreen_t screen, gfx3dSide_t side)
} else {
screen_w = 320;
}
GPU_SetViewport((u32 *)osConvertVirtToPhys((u32)gpu_depth_fb_addr),
(u32 *)osConvertVirtToPhys((u32)gpu_fb_addr),
GPU_SetViewport((u32 *)osConvertVirtToPhys(gpu_depth_fb_addr),
(u32 *)osConvertVirtToPhys(gpu_fb_addr),
0, 0, 240, screen_w);

GPU_DepthMap(-1.0f, 0.0f);
Expand All @@ -154,8 +154,8 @@ void sf2d_start_frame(gfxScreen_t screen, gfx3dSide_t side)
GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP);
GPU_SetBlendingColor(0,0,0,0);
GPU_SetDepthTestAndWriteMask(true, GPU_GEQUAL, GPU_WRITE_ALL);
GPUCMD_AddMaskedWrite(GPUREG_0062, 0x1, 0);
GPUCMD_AddWrite(GPUREG_0118, 0);
GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_TEST1, 0x1, 0);
GPUCMD_AddWrite(GPUREG_EARLYDEPTH_TEST2, 0);

GPU_SetAlphaBlending(
GPU_BLEND_ADD,
Expand All @@ -177,23 +177,23 @@ void sf2d_end_frame()
{
GPU_FinishDrawing();
GPUCMD_Finalize();
GPUCMD_FlushAndRun(NULL);
GPUCMD_FlushAndRun();
gspWaitForP3D();

//Copy the GPU rendered FB to the screen FB
if (cur_screen == GFX_TOP) {
GX_SetDisplayTransfer(NULL, gpu_fb_addr, GX_BUFFER_DIM(240, 400),
GX_DisplayTransfer(gpu_fb_addr, GX_BUFFER_DIM(240, 400),
(u32 *)gfxGetFramebuffer(GFX_TOP, cur_side, NULL, NULL),
GX_BUFFER_DIM(240, 400), 0x1000);
} else {
GX_SetDisplayTransfer(NULL, gpu_fb_addr, GX_BUFFER_DIM(240, 320),
GX_DisplayTransfer(gpu_fb_addr, GX_BUFFER_DIM(240, 320),
(u32 *)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL),
GX_BUFFER_DIM(240, 320), 0x1000);
}
gspWaitForPPF();

//Clear the screen
GX_SetMemoryFill(NULL,
GX_MemoryFill(
gpu_fb_addr, clear_color, &gpu_fb_addr[240*400], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH,
gpu_depth_fb_addr, 0, &gpu_depth_fb_addr[240*400], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH);
gspWaitForPSC0();
Expand All @@ -203,7 +203,7 @@ void sf2d_swapbuffers()
{
gfxSwapBuffersGpu();
if (vblank_wait) {
gspWaitForEvent(GSPEVENT_VBlank0, false);
gspWaitForEvent(GSPGPU_EVENT_VBlank0, false);
}
//Calculate FPS
frames++;
Expand Down Expand Up @@ -289,7 +289,7 @@ gfx3dSide_t sf2d_get_current_side()
return cur_side;
}

static void apt_hook_func(int hook, void* param)
static void apt_hook_func(APT_HookType hook, void *param)
{
if (hook == APTHOOK_ONRESTORE) {
reset_gpu_apt_resume();
Expand All @@ -308,6 +308,6 @@ static void reset_gpu_apt_resume()
}

GPUCMD_Finalize();
GPUCMD_FlushAndRun(NULL);
GPUCMD_FlushAndRun();
gspWaitForP3D();
}
8 changes: 4 additions & 4 deletions libs/sf2dlib/libsf2d/source/sf2d_draw.c
Expand Up @@ -29,7 +29,7 @@ void sf2d_draw_line(int x0, int y0, int x1, int y1, u32 color)

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -69,7 +69,7 @@ void sf2d_draw_rectangle(int x, int y, int w, int h, u32 color)

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -122,7 +122,7 @@ void sf2d_draw_rectangle_rotate(int x, int y, int w, int h, u32 color, float rad

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -177,7 +177,7 @@ void sf2d_draw_fill_circle(int x, int y, int radius, u32 color)

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
Expand Down
24 changes: 12 additions & 12 deletions libs/sf2dlib/libsf2d/source/sf2d_texture.c
Expand Up @@ -83,7 +83,7 @@ sf2d_texture *sf2d_create_texture(int width, int height, sf2d_texfmt pixel_forma
texture->data = data;

if (place == SF2D_PLACE_VRAM) {
GX_SetMemoryFill(NULL, texture->data, 0x00000000, (u32*)&((u8*)texture->data)[texture->data_size], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH,
GX_MemoryFill(texture->data, 0x00000000, (u32*)&((u8*)texture->data)[texture->data_size], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH,
NULL, 0x00000000, NULL, 0);
gspWaitForPSC0();
} else {
Expand Down Expand Up @@ -146,7 +146,7 @@ void sf2d_bind_texture(const sf2d_texture *texture, GPU_TEXUNIT unit)

GPU_SetTexture(
unit,
(u32 *)osConvertVirtToPhys((u32)texture->data),
(u32 *)osConvertVirtToPhys(texture->data),
texture->pow2_w,
texture->pow2_h,
texture->params,
Expand All @@ -170,7 +170,7 @@ void sf2d_bind_texture_color(const sf2d_texture *texture, GPU_TEXUNIT unit, u32

GPU_SetTexture(
unit,
(u32 *)osConvertVirtToPhys((u32)texture->data),
(u32 *)osConvertVirtToPhys(texture->data),
texture->pow2_w,
texture->pow2_h,
texture->params,
Expand All @@ -194,7 +194,7 @@ void sf2d_bind_texture_parameters(const sf2d_texture *texture, GPU_TEXUNIT unit,

GPU_SetTexture(
unit,
(u32 *)osConvertVirtToPhys((u32)texture->data),
(u32 *)osConvertVirtToPhys(texture->data),
texture->pow2_w,
texture->pow2_h,
params,
Expand Down Expand Up @@ -235,7 +235,7 @@ static inline void sf2d_draw_texture_generic(const sf2d_texture *texture, int x,

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -304,7 +304,7 @@ static inline void sf2d_draw_texture_rotate_hotspot_generic(const sf2d_texture *

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -366,7 +366,7 @@ static inline void sf2d_draw_texture_part_generic(const sf2d_texture *texture, i

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -414,7 +414,7 @@ static inline void sf2d_draw_texture_scale_generic(const sf2d_texture *texture,

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -464,7 +464,7 @@ static inline void sf2d_draw_texture_part_scale_generic(const sf2d_texture *text

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -524,7 +524,7 @@ static inline void sf2d_draw_texture_part_rotate_scale_generic(const sf2d_textur

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -573,7 +573,7 @@ static inline void sf2d_draw_texture_depth_generic(const sf2d_texture *texture,

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down Expand Up @@ -618,7 +618,7 @@ void sf2d_draw_quad_uv(const sf2d_texture *texture, float left, float top, float

GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
(u32*)osConvertVirtToPhys(vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 2, GPU_FLOAT),
0xFFFC, //0b1100
0x10,
Expand Down
2 changes: 1 addition & 1 deletion libs/sftdlib/libsftd/source/texture_atlas.c
Expand Up @@ -63,7 +63,7 @@ int texture_atlas_insert(texture_atlas *atlas, unsigned int character, const voi
}
}

GSPGPU_FlushDataCache(NULL, atlas->tex->data, atlas->tex->data_size);
GSPGPU_FlushDataCache(atlas->tex->data, atlas->tex->data_size);

return 1;
}
Expand Down
4 changes: 0 additions & 4 deletions source/cam.c
Expand Up @@ -585,10 +585,6 @@ struct { char *name; int value; } cam_constants[] = {
*/
{"WHITE_BALANCE_7000K", WHITE_BALANCE_7000K},
/***
@field WHITE_BALANCE_MAX
*/
{"WHITE_BALANCE_MAX", WHITE_BALANCE_MAX },
/***
@field WHITE_BALANCE_TUNGSTEN
*/
{"WHITE_BALANCE_TUNGSTEN", WHITE_BALANCE_TUNGSTEN },
Expand Down
4 changes: 2 additions & 2 deletions source/cfgu.c
Expand Up @@ -19,7 +19,7 @@ Initialize the CFGU module.
@function init
*/
static int cfgu_init(lua_State *L) {
initCfgu();
cfguInit();

return 0;
}
Expand All @@ -29,7 +29,7 @@ Disable the CFGU module.
@function shutdown
*/
static int cfgu_shutdown(lua_State *L) {
exitCfgu();
cfguExit();

return 0;
}
Expand Down
36 changes: 18 additions & 18 deletions source/fs.c
Expand Up @@ -15,9 +15,9 @@ The `fs` module.
#include <lauxlib.h>

Handle *fsuHandle;
FS_archive sdmcArchive;
FS_Archive sdmcArchive;
#ifdef ROMFS
FS_archive romfsArchive;
FS_Archive romfsArchive;
#endif

/***
Expand Down Expand Up @@ -73,9 +73,9 @@ static int fs_list(lua_State *L) {

// Get default archive
#ifdef ROMFS
FS_archive archive = romfsArchive;
FS_Archive archive = romfsArchive;
#else
FS_archive archive = sdmcArchive;
FS_Archive archive = sdmcArchive;
#endif
// Archive path override (and skip path prefix)
if (strncmp(path, "sdmc:", 5) == 0) {
Expand All @@ -88,14 +88,14 @@ static int fs_list(lua_State *L) {
#endif
}

FS_path dirPath = FS_makePath(PATH_CHAR, path);
FS_Path dirPath = fsMakePath(PATH_ASCII, path);

Handle dirHandle;
FSUSER_OpenDirectory(fsuHandle, &dirHandle, archive, dirPath);
FSUSER_OpenDirectory(&dirHandle, archive, dirPath);

u32 entriesRead = 0;
do {
FS_dirent buffer;
FS_DirectoryEntry buffer;

FSDIR_Read(dirHandle, &entriesRead, 1, &buffer);

Expand All @@ -113,13 +113,13 @@ static int fs_list(lua_State *L) {
lua_setfield(L, -2, "shortName");
lua_pushstring(L, (const char *)buffer.shortExt);
lua_setfield(L, -2, "shortExt");
lua_pushboolean(L, buffer.isDirectory);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_DIRECTORY);
lua_setfield(L, -2, "isDirectory");
lua_pushboolean(L, buffer.isHidden);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_HIDDEN);
lua_setfield(L, -2, "isHidden");
lua_pushboolean(L, buffer.isArchive);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_ARCHIVE);
lua_setfield(L, -2, "isArchive");
lua_pushboolean(L, buffer.isReadOnly);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_READ_ONLY);
lua_setfield(L, -2, "isReadOnly");
lua_pushinteger(L, buffer.fileSize);
lua_setfield(L, -2, "fileSize");
Expand Down Expand Up @@ -214,22 +214,22 @@ void load_fs_lib(lua_State *L) {
fsInit();

fsuHandle = fsGetSessionHandle();
FSUSER_Initialize(fsuHandle);
FSUSER_Initialize(*fsuHandle);

sdmcArchive = (FS_archive){ARCH_SDMC, FS_makePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(fsuHandle, &sdmcArchive);
sdmcArchive = (FS_Archive){ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(&sdmcArchive);
#ifdef ROMFS
romfsArchive = (FS_archive){ARCH_ROMFS, FS_makePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(fsuHandle, &romfsArchive);
romfsArchive = (FS_Archive){ARCHIVE_ROMFS, fsMakePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(&romfsArchive);
#endif

luaL_requiref(L, "ctr.fs", luaopen_fs_lib, false);
}

void unload_fs_lib(lua_State *L) {
FSUSER_CloseArchive(fsuHandle, &sdmcArchive);
FSUSER_CloseArchive(&sdmcArchive);
#ifdef ROMFS
FSUSER_CloseArchive(fsuHandle, &romfsArchive);
FSUSER_CloseArchive(&romfsArchive);
#endif

fsExit();
Expand Down
2 changes: 1 addition & 1 deletion source/gfx.c
Expand Up @@ -9,7 +9,7 @@ The `gfx` module.
#include <sftd.h>

#include <3ds/vram.h>
#include <3ds/services/gsp.h>
//#include <3ds/services/gsp.h>

#include <lua.h>
#include <lauxlib.h>
Expand Down

0 comments on commit 2e782ed

Please sign in to comment.