From 7be61cfb1a55feb9ab30cfda9e78ed33c74eb097 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 6 Jan 2018 21:12:42 -0500 Subject: add assert support to pokeemerald. --- include/assert.h | 43 +++++++++++++++++++++++++++++++++++++++++++ include/config.h | 10 ++++++++++ include/global.h | 1 + 3 files changed, 54 insertions(+) create mode 100755 include/assert.h (limited to 'include') diff --git a/include/assert.h b/include/assert.h new file mode 100755 index 000000000..0c1e5bf77 --- /dev/null +++ b/include/assert.h @@ -0,0 +1,43 @@ +#ifndef GUARD_GBASDKASSERT_H +#define GUARD_GBASDKASSERT_H + +// this header is based on the +// GBA SDK IsAgbAssert.h. + +#ifdef NOAGBPRN + #define AGBPrintInit() + #define AGBPutc(pBuf) + #define AGBPrint(pBuf) + #define AGBPrintf(...) + #define AGBPrintFlush1Block() + #define AGBPrintFlush() + #define AGBAssert(pFile, nLine, pExpression, nStopProgram) +#else + // without NOAGBPRN defined, this enables asserts for usage + // on a standard GBA debugger unit or in emulators that + // support it. + + void AGBPrintInit(void); + void AGBPutc(const char pBuf); + void AGBPrint(const char *pBuf); + void AGBPrintf(const char *pBuf, ...); + void AGBPrintFlush1Block(void); + void AGBPrintFlush(void); + void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopProgram); +#endif + +// when using AGB_WARNING, be sure to flush after as AGBAssert does not flush the string to console +// immediately after usage. +#ifdef NOAGBPRN + #define AGB_ASSERT(expression) +#else + #define AGB_ASSERT(expression) (expression) ? ((void *)0) : AGBAssert(__FILE__, __LINE__, #expression, 1); +#endif + +#ifdef NOAGBPRN + #define AGB_WARNING(expression) +#else + #define AGB_WARNING(expression) (expression) ? ((void *)0) : AGBAssert(__FILE__, __LINE__, #expression, 0); +#endif + +#endif diff --git a/include/config.h b/include/config.h index 162af3143..ce8e4ae74 100644 --- a/include/config.h +++ b/include/config.h @@ -1,6 +1,16 @@ #ifndef GUARD_CONFIG_H #define GUARD_CONFIG_H +// In the Generation 3 games, Asserts were used in various debug builds. +// Ruby/Sapphire and Emerald do not have these asserts while Fire Red +// still has them in the ROM. This is because the developers forgot +// to define NOAGBPRN before release, which is actually supposed to be +// NDEBUG, however this has been changed as Ruby's actual debug build +// does not use the AGBPrint features. +#define NOAGBPRN +// NOTE: Don't try to enable assert right now as many pointers +// still exist in defines and WILL likely result in a broken ROM. + #define ENGLISH #ifdef ENGLISH diff --git a/include/global.h b/include/global.h index 7943fc569..1d0962cf6 100644 --- a/include/global.h +++ b/include/global.h @@ -3,6 +3,7 @@ #include "gba/gba.h" #include "config.h" +#include "assert.h" // Prevent cross-jump optimization. #define BLOCK_CROSS_JUMP asm(""); -- cgit v1.2.3 From 419e6d885baa060506489a947718b8610173b450 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 6 Jan 2018 21:38:34 -0500 Subject: use firered isagbprint header. --- include/assert.h | 43 ----------------------------------------- include/gba/gba.h | 1 + include/gba/isagbprint.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 43 deletions(-) delete mode 100755 include/assert.h create mode 100755 include/gba/isagbprint.h (limited to 'include') diff --git a/include/assert.h b/include/assert.h deleted file mode 100755 index 0c1e5bf77..000000000 --- a/include/assert.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef GUARD_GBASDKASSERT_H -#define GUARD_GBASDKASSERT_H - -// this header is based on the -// GBA SDK IsAgbAssert.h. - -#ifdef NOAGBPRN - #define AGBPrintInit() - #define AGBPutc(pBuf) - #define AGBPrint(pBuf) - #define AGBPrintf(...) - #define AGBPrintFlush1Block() - #define AGBPrintFlush() - #define AGBAssert(pFile, nLine, pExpression, nStopProgram) -#else - // without NOAGBPRN defined, this enables asserts for usage - // on a standard GBA debugger unit or in emulators that - // support it. - - void AGBPrintInit(void); - void AGBPutc(const char pBuf); - void AGBPrint(const char *pBuf); - void AGBPrintf(const char *pBuf, ...); - void AGBPrintFlush1Block(void); - void AGBPrintFlush(void); - void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopProgram); -#endif - -// when using AGB_WARNING, be sure to flush after as AGBAssert does not flush the string to console -// immediately after usage. -#ifdef NOAGBPRN - #define AGB_ASSERT(expression) -#else - #define AGB_ASSERT(expression) (expression) ? ((void *)0) : AGBAssert(__FILE__, __LINE__, #expression, 1); -#endif - -#ifdef NOAGBPRN - #define AGB_WARNING(expression) -#else - #define AGB_WARNING(expression) (expression) ? ((void *)0) : AGBAssert(__FILE__, __LINE__, #expression, 0); -#endif - -#endif diff --git a/include/gba/gba.h b/include/gba/gba.h index 42ae3cdde..349344031 100644 --- a/include/gba/gba.h +++ b/include/gba/gba.h @@ -7,5 +7,6 @@ #include "gba/multiboot.h" #include "gba/syscall.h" #include "gba/macro.h" +#include "gba/isagbprint.h" #endif // GUARD_GBA_GBA_H diff --git a/include/gba/isagbprint.h b/include/gba/isagbprint.h new file mode 100755 index 000000000..c5eb456c3 --- /dev/null +++ b/include/gba/isagbprint.h @@ -0,0 +1,50 @@ +#ifndef GUARD_GBA_ISAGBPRINT_H +#define GUARD_GBA_ISAGBPRINT_H + +#ifdef NDEBUG +#define AGBPrintInit() +#define AGBPutc(cChr) +#define AGBPrint(pBuf) +#define AGBPrintf(pBuf, ...) +#define AGBPrintFlush1Block() +#define AGBPrintFlush() +#define AGBAssert(pFile, nLine, pExpression, nStopProgram) +#else +void AGBPrintInit(void); +void AGBPutc(const char cChr); +void AGBPrint(const char *pBuf); +void AGBPrintf(const char *pBuf, ...); +void AGBPrintFlush1Block(void); +void AGBPrintFlush(void); +void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopProgram); +#endif + +#undef AGB_ASSERT +#ifdef NDEBUG +#define AGB_ASSERT(exp) +#else +#define AGB_ASSERT(exp) (exp) ? ((void*)0) : AGBAssert(__FILE__, __LINE__, #exp, 1); +#endif + +#undef AGB_WARNING +#ifdef NDEBUG +#define AGB_WARNING(exp) +#else +#define AGB_WARNING(exp) (exp) ? ((void*)0) : AGBAssert(__FILE__, __LINE__, #exp, 0); +#endif + +// for matching purposes + +#ifdef NDEBUG +#define AGB_ASSERT_EX(exp, file, line) +#else +#define AGB_ASSERT_EX(exp, file, line) (exp) ? ((void*)0) : AGBAssert(file, line, #exp, 1); +#endif + +#ifdef NDEBUG +#define AGB_WARNING_EX(exp, file, line) +#else +#define AGB_WARNING_EX(exp, file, line) (exp) ? ((void*)0) : AGBAssert(file, line, #exp, 0); +#endif + +#endif // GUARD_GBA_ISAGBPRINT_H -- cgit v1.2.3 From 10ddfac7abab614d2c4488244cee35054ed06fa8 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 6 Jan 2018 22:00:08 -0500 Subject: consistency --- include/config.h | 4 ++-- include/global.h | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/config.h b/include/config.h index ce8e4ae74..7ee4503c7 100644 --- a/include/config.h +++ b/include/config.h @@ -4,10 +4,10 @@ // In the Generation 3 games, Asserts were used in various debug builds. // Ruby/Sapphire and Emerald do not have these asserts while Fire Red // still has them in the ROM. This is because the developers forgot -// to define NOAGBPRN before release, which is actually supposed to be +// to define NDEBUG before release, which is actually supposed to be // NDEBUG, however this has been changed as Ruby's actual debug build // does not use the AGBPrint features. -#define NOAGBPRN +#define NDEBUG // NOTE: Don't try to enable assert right now as many pointers // still exist in defines and WILL likely result in a broken ROM. diff --git a/include/global.h b/include/global.h index 1d0962cf6..3e260fd2a 100644 --- a/include/global.h +++ b/include/global.h @@ -1,9 +1,8 @@ #ifndef GUARD_GLOBAL_H #define GUARD_GLOBAL_H +#include "config.h" // we need to define config before gba headers as print stuff needs the functions nulled before defines. #include "gba/gba.h" -#include "config.h" -#include "assert.h" // Prevent cross-jump optimization. #define BLOCK_CROSS_JUMP asm(""); -- cgit v1.2.3 From d98c14444ade7e975585e991ef89c7597295f1b4 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 7 Jan 2018 23:46:35 -0500 Subject: NDEBUG which is supposed to be NDEBUG... --- include/config.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/config.h b/include/config.h index 7ee4503c7..53502c6c2 100644 --- a/include/config.h +++ b/include/config.h @@ -4,9 +4,8 @@ // In the Generation 3 games, Asserts were used in various debug builds. // Ruby/Sapphire and Emerald do not have these asserts while Fire Red // still has them in the ROM. This is because the developers forgot -// to define NDEBUG before release, which is actually supposed to be -// NDEBUG, however this has been changed as Ruby's actual debug build -// does not use the AGBPrint features. +// to define NDEBUG before release, however this has been changed as +// Ruby's actual debug build does not use the AGBPrint features. #define NDEBUG // NOTE: Don't try to enable assert right now as many pointers // still exist in defines and WILL likely result in a broken ROM. -- cgit v1.2.3 From 0bf530da12f671c678f7e524b4318213d49b30e0 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 8 Jan 2018 22:03:07 -0500 Subject: nocashgba printf --- include/config.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/config.h b/include/config.h index 53502c6c2..318ed39d8 100644 --- a/include/config.h +++ b/include/config.h @@ -7,6 +7,14 @@ // to define NDEBUG before release, however this has been changed as // Ruby's actual debug build does not use the AGBPrint features. #define NDEBUG + +// To enable print debugging, comment out "#define NDEBUG". This allows +// the various AGBPrint functions to be used. (See include/gba/isagbprint.h). +// Some emulators support a debug console window: uncomment NoCashGBAPrint() +// and NoCashGBAPrintf() in libisagbprn.c to use no$gba's own proprietary +// printing system. Use NoCashGBAPrint() and NoCashGBAPrintf() like you +// would normally use AGBPrint() and AGBPrintf(). + // NOTE: Don't try to enable assert right now as many pointers // still exist in defines and WILL likely result in a broken ROM. -- cgit v1.2.3