diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..c7b900f0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,23 @@ +IndentWidth: 4 +Language: Cpp +UseTab: Never +ColumnLimit: 120 +PointerAlignment: Left +BreakBeforeBraces: Attach +SpaceAfterCStyleCast: false +Cpp11BracedListStyle: false +IndentCaseLabels: true +BinPackArguments: true +BinPackParameters: true +AlignAfterOpenBracket: Align +AlignOperands: true +BreakBeforeTernaryOperators: true +BreakBeforeBinaryOperators: None +AllowShortBlocksOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AlignEscapedNewlines: Left +AlignTrailingComments: true +SortIncludes: false diff --git a/include/Famicom/famicom.h b/include/Famicom/famicom.h index 98e7cdcf..b1b63014 100644 --- a/include/Famicom/famicom.h +++ b/include/Famicom/famicom.h @@ -8,6 +8,34 @@ extern "C" { #endif +#define NESTAG_END "END" +#define NESTAG_VEQ "VEQ" +#define NESTAG_VNE "VNE" +#define NESTAG_GID "GID" +#define NESTAG_GNM "GNM" +#define NESTAG_CPN "CPN" +#define NESTAG_OFS "OFS" +#define NESTAG_HSC "HSC" +#define NESTAG_GNO "GNO" +#define NESTAG_BBR "BBR" +#define NESTAG_QDS "QDS" +#define NESTAG_SPE "SPE" +#define NESTAG_TCS "TCS" +#define NESTAG_ICS "ICS" +#define NESTAG_ESZ "ESZ" +#define NESTAG_ROM "ROM" +#define NESTAG_MOV "MOV" +#define NESTAG_NHD "NHD" +#define NESTAG_DIF "DIF" +#define NESTAG_PAT "PAT" +#define NESTAG_PAD "PAD" +#define NESTAG_FIL "FIL" +#define NESTAG_ISZ "ISZ" +#define NESTAG_IFM "IFM" +#define NESTAG_REM "REM" +#define NESTAG_APL "APL" +#define NESTAG_FGN "FGN" + typedef void* (*MALLOC_ALIGN_FUNC)(size_t size, u32 align); typedef void (*MALLOC_FREE_FUNC)(void* ptr); typedef size_t (*MALLOC_GETMEMBLOCKSIZE_FUNC)(void* ptr); diff --git a/include/famicom_emu.h b/include/famicom_emu.h index 242feea9..ef76d633 100644 --- a/include/famicom_emu.h +++ b/include/famicom_emu.h @@ -15,16 +15,11 @@ typedef struct game_famicom_emu_s { extern void* my_malloc_func[]; -void my_alloc_cleanup(); -void my_zelda_getmemblocksize(void *); -void my_zelda_gettotalfreesize(); -void* my_zelda_malloc_align(size_t, u32); -void my_zelda_free(void *); -void famicom_emu_main(GAME *); -void famicom_emu_init(GAME_FAMICOM_EMU *); -void famicom_emu_cleanup(GAME *); -int famicom_gba_getImage(u32, int *); -void famicom_gba_removeImage(void *); +extern void famicom_emu_main(GAME* game); +extern void famicom_emu_init(GAME* game); +extern void famicom_emu_cleanup(GAME* game); +extern int famicom_gba_getImage(u32 rom_id, int* ptr); +extern void famicom_gba_removeImage(void* ); #ifdef __cplusplus } diff --git a/src/famicom_emu.c b/src/famicom_emu.c index c25965a3..d0feba2b 100644 --- a/src/famicom_emu.c +++ b/src/famicom_emu.c @@ -1,20 +1,63 @@ #include "famicom_emu.h" -#include "m_malloc.h" +#include "Famicom/famicom.h" #include "_mem.h" #include "dolphin/gx.h" -#include "Famicom/famicom.h" -#include "m_scene.h" #include "jsyswrap.h" +#include "libc64/sprintf.h" #include "m_common_data.h" #include "m_debug.h" -#include "libc64/sprintf.h" +#include "m_malloc.h" +#include "m_scene.h" -int famicom_done; -int famicom_done_countdown; -void* freeXfbBase; -u32 freeXfbSize; +static int famicom_done = FALSE; +static int famicom_done_countdown = 0; +static void* freeXfbBase = NULL; +static u32 freeXfbSize = 0; + +static void my_alloc_init(GAME* game, void* start, size_t size) { + u32 freebytes; + u32 alloc; + u32 aligned; + u32 tsize; + + freebytes = game_getFreeBytes(game); + alloc = (u32)THA_alloc16(&game->tha, freebytes); + aligned = ALIGN_NEXT(alloc, 16); + tsize = aligned - alloc; + + zelda_InitArena((void*)aligned, freebytes - tsize); + + if ((start != NULL) && (size != 0)) { + zelda_AddBlockArena(start, size); + } +} + +static void my_alloc_cleanup() { + zelda_CleanupArena(); +} + +static void my_zelda_getmemblocksize(void* ptr) { + zelda_GetMemBlockSize(ptr); +} + +static void my_zelda_gettotalfreesize() { + zelda_GetTotalFreeSize(); +} + +static void* my_zelda_malloc_align(size_t size, u32 align) { + void* aligned = zelda_malloc_align(size, align); + + if (aligned != NULL) { + memset(aligned, 0xFF, size); + } + return aligned; +} + +static void my_zelda_free(void* ptr) { + zelda_free(ptr); +} void* my_malloc_func[] = { my_zelda_malloc_align, @@ -23,62 +66,8 @@ void* my_malloc_func[] = { my_zelda_gettotalfreesize, }; - - -void my_alloc_init(GAME_FAMICOM_EMU* famicom, void* start, size_t size){ - - u32 freebytes; - u32 alloc; - u32 aligned; - u32 tsize; - - freebytes = game_getFreeBytes(&famicom->game); - alloc = (u32)THA_alloc16(&famicom->game.tha, freebytes); - aligned = ALIGN_NEXT(alloc, 16); - tsize = aligned - alloc; - - zelda_InitArena((void*)aligned, freebytes - tsize); - - if((start != NULL) && (size != 0)){ - - zelda_AddBlockArena(start, size); - } - -} - -void my_alloc_cleanup(){ - - zelda_CleanupArena(); -} - -void my_zelda_getmemblocksize(void* ptr){ - - zelda_GetMemBlockSize(ptr); -} - -void my_zelda_gettotalfreesize(){ - - zelda_GetTotalFreeSize(); -} - -void* my_zelda_malloc_align(size_t size, u32 align){ - - void* aligned = zelda_malloc_align(size, align); - - if(aligned != NULL){ - - memset(aligned, 0xFF, size); - } - return aligned; -} - -void my_zelda_free(void* ptr){ - - zelda_free(ptr); -} - -void famicom_emu_main(GAME* famicom){ - static GXColor black_color = {0,0,0,0}; +extern void famicom_emu_main(GAME* famicom) { + static GXColor black_color = { 0, 0, 0, 0 }; GXColor t; int i; int padid; @@ -86,20 +75,17 @@ void famicom_emu_main(GAME* famicom){ u32 combo; void* manager; - if(famicom_done == 0){ - if(famicom_rom_load_check() < 0){ + if (famicom_done == 0) { + if (famicom_rom_load_check() < 0) { Common_Set(famicom_2DBAC, Common_Get(famicom_2DBAC) | 1); famicom_done = 1; famicom_done_countdown = 0; - } - else{ - for(padid = 0,i = 4; i != 0; i--, padid++){ - - current_pad = &gamePT->pads[padid]; + } else { + for (padid = 0, i = 4; i != 0; i--, padid++) { + current_pad = &gamePT->pads[padid]; combo = current_pad->now.button | current_pad->on.button; - if(combo == (BUTTON_Z | BUTTON_R | BUTTON_L) || (combo == 0xF0)){ - + if (combo == (BUTTON_L | BUTTON_R | BUTTON_Z) || combo == (BUTTON_L | BUTTON_R | BUTTON_X | BUTTON_Y)) { famicom_done = 1; famicom_done_countdown = 60; JC_JFWDisplay_startFadeOut(JC_JFWDisplay_getManager(), famicom_done_countdown); @@ -109,7 +95,7 @@ void famicom_emu_main(GAME* famicom){ } } if (famicom_done != 0) { - if ( famicom_done_countdown == 0) { + if (famicom_done_countdown == 0) { return_emu_game(famicom); } else { famicom_done_countdown -= 1; @@ -119,127 +105,99 @@ void famicom_emu_main(GAME* famicom){ JW_BeginFrame(); famicom->disable_display = 1; - if(famicom_done == 0){ - + if (famicom_done == 0) { famicom_1frame(); - } - else{ + } else { manager = JC_JFWDisplay_getManager(); - t = black_color; + t = black_color; JC_JFWDisplay_clearEfb(manager, &t); } JW_EndFrame(); } - -void famicom_emu_init(GAME_FAMICOM_EMU* famicom){ - +extern void famicom_emu_init(GAME* game) { int rom_id; u8 player; int debug; void* manager; GXRenderModeObj* render; - + famicom_done = 0; famicom_done_countdown = 0; - game_resize_hyral(&famicom->game, 0); - Common_Set(famicom_287F9, 0); - - rom_id = Common_Get(current_famicom_rom); + game_resize_hyral(game, 0); + Common_Set(famicom_287F9, 0); + + rom_id = Common_Get(current_famicom_rom); player = Common_Get(player_no); save_game_image = (GETREG(HREG, 4) == 1); - debug = GETREG(HREG,3); + debug = GETREG(HREG, 3); - if((rom_id > 0) && ( debug != 0)){ - rom_id = debug & (-debug & ~debug) >> 0x1f; + if ((rom_id > 0) && (debug != 0)) { + rom_id = debug > 0 ? debug : 0; } - - famicom->game.exec = famicom_emu_main; - famicom->game.cleanup = famicom_emu_cleanup; - - while(sAdo_SubGameOK() == 0){ + game->exec = famicom_emu_main; + game->cleanup = famicom_emu_cleanup; + + while (sAdo_SubGameOK() == FALSE) { VIWaitForRetrace(); sAdo_GameFrame(); } manager = JC_JFWDisplay_getManager(); - render = JC_JFWDisplay_getRenderMode(manager); + render = JC_JFWDisplay_getRenderMode(manager); freeXfbBase = JC_JFWDisplay_changeToSingleXfb(manager, 1); freeXfbSize = render->fbWidth * render->xfbHeight * sizeof(u16); - my_alloc_init(famicom, freeXfbBase, freeXfbSize); + my_alloc_init(game, freeXfbBase, freeXfbSize); - if(famicom_init(rom_id, my_malloc_func, player) != 0){ + if (famicom_init(rom_id, my_malloc_func, player) != 0) { Common_Set(famicom_2DBAC, Common_Get(famicom_2DBAC) | 1); - return_emu_game(&famicom->game); + return_emu_game(game); } } - -void famicom_emu_cleanup(GAME* game){ - +extern void famicom_emu_cleanup(GAME* game) { JC_JFWDisplay_startFadeIn(JC_JFWDisplay_getManager(), 1); - if(famicom_cleanup() != 0){ - + if (famicom_cleanup() != 0) { Common_Set(famicom_2DBAC, Common_Get(famicom_2DBAC) | 2); } my_alloc_cleanup(); - if(freeXfbBase != NULL){ - - JC_JFWDisplay_changeToDoubleXfb(JC_JFWDisplay_getManager()); + if (freeXfbBase != NULL) { + JC_JFWDisplay_changeToDoubleXfb(JC_JFWDisplay_getManager()); freeXfbBase = NULL; freeXfbSize = 0; } sAdo_SubGameEnd(); } -int famicom_gba_getImage(u32 rom_id, int* ptr){ +extern int famicom_gba_getImage(u32 rom_id, int* ptr) { static char* names[] = { - "cluclu", - "usa_balloon", - "donkey", - "usa_jr_math", - "pinball", - "tennis", - "usa_golf", - NULL, - "usa_baseball", - NULL, - "usa_donkey3", - "donkeyjr", - "soccer", - "exbike", - NULL, - "usa_icecl", - "mario", - "smario", - NULL + "cluclu", "usa_balloon", "donkey", "usa_jr_math", "pinball", "tennis", "usa_golf", + NULL, "usa_baseball", NULL, "usa_donkey3", "donkeyjr", "soccer", "exbike", + NULL, "usa_icecl", "mario", "smario", NULL, }; - + char buf[256]; u32 resource; int block; char* rom; - - if(rom_id > 0x13){ + if (rom_id > 19) { return 0; } - - rom = names[(rom_id == 0) ? 0 : rom_id -1]; - - if(rom == NULL){ + rom = names[(rom_id == 0) ? 0 : rom_id - 1]; + + if (rom == NULL) { return 0; - } - else{ - sprintf(buf, "/FAMICOM/GBA/jb_%s.bin.szs", rom); - resource = JC__JKRGetResource(buf); - if((resource != 0) && (ptr != NULL)){ + } else { + sprintf(buf, "/FAMICOM/GBA/jb_%s.bin.szs", rom); + resource = JC__JKRGetResource(buf); + if ((resource != 0) && (ptr != NULL)) { block = JC__JKRGetMemBlockSize(0, resource); *ptr = block; } @@ -247,7 +205,6 @@ int famicom_gba_getImage(u32 rom_id, int* ptr){ return resource; } -void famicom_gba_removeImage(void* p){ - +extern void famicom_gba_removeImage(void* p) { JC__JKRRemoveResource(p); -} \ No newline at end of file +}