From 272cd213391b5ce87cb2aeac263b3eedb0f19a07 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Wed, 20 Dec 2017 15:33:08 -0500 Subject: Add NDEBUG (NOAGBPRN) support to pokeruby. --- src/libs/libc.c | 143 ---------------------------------------------- src/libs/libisagbprn.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 143 deletions(-) delete mode 100644 src/libs/libc.c create mode 100755 src/libs/libisagbprn.c (limited to 'src/libs') diff --git a/src/libs/libc.c b/src/libs/libc.c deleted file mode 100644 index 920673e3e..000000000 --- a/src/libs/libc.c +++ /dev/null @@ -1,143 +0,0 @@ -#include "global.h" -#include - -#define LBLOCKSIZE (sizeof(long)) - -// Nonzero if (long)X contains a NULL byte. -#define CONTAINSNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) - -// Nonzero if X is not aligned on a "long" boundary. -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) - -void *memcpy(void *dst0, const void *src0, size_t len0) -{ - char *dst = dst0; - const char *src = src0; - long *aligned_dst; - const long *aligned_src; - unsigned int len = len0; - - // If the size is small, or either src or dst is unaligned, - // then go to the byte copy loop. This should be rare. - if (len >= 16 && !(UNALIGNED(src) | UNALIGNED(dst))) - { - aligned_dst = (long *)dst; - aligned_src = (long *)src; - - // Copy 4X long words at a time if possible. - while (len >= 16) - { - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - len -= 16; - } - - // Copy one long word at a time if possible - while (len >= 4) - { - *aligned_dst++ = *aligned_src++; - len -= 4; - } - - dst = (char *)aligned_dst; - src = (char *)aligned_src; - } - - // Pick up any remaining bytes with a byte copier. - while (len--) - *dst++ = *src++; - - return dst0; -} - -void *memset(void *m, int c, size_t n) -{ - char *s = (char *)m; - int count, i; - unsigned long buffer; - unsigned long *aligned_addr; - unsigned char *unaligned_addr; - - // If the size is small or m is unaligned, - // then go to the byte copy loop. This should be rare. - if (n >= LBLOCKSIZE && !UNALIGNED(m)) - { - // We know that n is large and m is word-aligned. - aligned_addr = (unsigned long *)m; - - // Store C into each char sized location in buffer so that - // we can set large blocks quickly. - c &= 0xFF; - if (LBLOCKSIZE == 4) - { - buffer = (c << 8) | c; - buffer |= (buffer << 16); - } - else - { - buffer = 0; - for (i = 0; i < LBLOCKSIZE; i++) - buffer = (buffer << 8) | c; - } - - while (n >= LBLOCKSIZE * 4) - { - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - n -= LBLOCKSIZE * 4; - } - while (n >= LBLOCKSIZE) - { - *aligned_addr++ = buffer; - n -= LBLOCKSIZE; - } - - s = (char *)aligned_addr; - } - - // Pick up the remainder with a bytewise loop. - while (n--) - *s++ = (char)c; - - return m; -} - -int strcmp(const char *s1, const char *s2) -{ - unsigned long *a1; - unsigned long *a2; - - // If s1 or s2 are unaligned, then skip this and compare bytes. - if (!(UNALIGNED(s1) | UNALIGNED(s2))) - { - // Compare them a word at a time. - a1 = (unsigned long *)s1; - a2 = (unsigned long *)s2; - while (*a1 == *a2) - { - // If *a1 == *a2, and we find a null in *a1, - // then the strings must be equal, so return zero. - if (CONTAINSNULL(*a1)) - return 0; - - a1++; - a2++; - } - - s1 = (char *)a1; - s2 = (char *)a2; - } - - // Check the remaining few bytes. - while (*s1 != '\0' && *s1 == *s2) - { - s1++; - s2++; - } - - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -} diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c new file mode 100755 index 000000000..64ccb6351 --- /dev/null +++ b/src/libs/libisagbprn.c @@ -0,0 +1,151 @@ +#include +#include +#include "gba/gba.h" +#include "config.h" + +#define AGB_PRINT_FLUSH_ADDR 0x9FE209D +#define AGB_PRINT_STRUCT_ADDR 0x9FE20F8 +#define AGB_PRINT_PROTECT_ADDR 0x9FE2FFE +#define WSCNT_DATA (WAITCNT_PHI_OUT_16MHZ | WAITCNT_WS0_S_2 | WAITCNT_WS0_N_4) + +struct AGBPrintStruct +{ + u16 m_nRequest; + u16 m_nBank; + u16 m_nGet; + u16 m_nPut; +}; + +typedef void (*LPFN_PRINT_FLUSH)(void); + +#ifndef NOAGBPRN +void AGBPrintFlush1Block(void); + +void AGBPrintInit(void) +{ + volatile struct AGBPrintStruct *pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; + u16 *pWSCNT = (u16 *)REG_ADDR_WAITCNT; + u16 *pProtect = (u16 *)AGB_PRINT_PROTECT_ADDR; + u16 nOldWSCNT = *pWSCNT; + *pWSCNT = WSCNT_DATA; + *pProtect = 0x20; + pPrint->m_nRequest = pPrint->m_nGet = pPrint->m_nPut = 0; + pPrint->m_nBank = 0xFD; + *pProtect = 0; + *pWSCNT = nOldWSCNT; +} + +static void AGBPutcInternal(const char cChr) +{ + volatile struct AGBPrintStruct *pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; + u16 *pPrintBuf = (u16 *)(0x8000000 + (pPrint->m_nBank << 16)); + u16 *pProtect = (u16 *)AGB_PRINT_PROTECT_ADDR; + u16 nData = pPrintBuf[pPrint->m_nPut / 2]; + *pProtect = 0x20; + nData = (pPrint->m_nPut & 1) ? (nData & 0xFF) | (cChr << 8) : (nData & 0xFF00) | cChr; + pPrintBuf[pPrint->m_nPut / 2] = nData; + pPrint->m_nPut++; + *pProtect = 0; +} + +void AGBPutc(const char cChr) +{ + u16 *pWSCNT = (u16 *)REG_ADDR_WAITCNT; + u16 nOldWSCNT = *pWSCNT; + volatile struct AGBPrintStruct *pPrint; + *pWSCNT = WSCNT_DATA; + AGBPutcInternal(cChr); + *pWSCNT = nOldWSCNT; + pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; + if (pPrint->m_nPut == ((pPrint->m_nGet - 1) & 0xFFFF)) + AGBPrintFlush1Block(); +} + +void AGBPrint(const char *pBuf) +{ + volatile struct AGBPrintStruct *pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; + u16 *pWSCNT = (u16 *)REG_ADDR_WAITCNT; + u16 nOldWSCNT = *pWSCNT; + *pWSCNT = WSCNT_DATA; + while (*pBuf) + { + AGBPutc(*pBuf); + pBuf++; + } + *pWSCNT = nOldWSCNT; +} + +void AGBPrintf(const char *pBuf, ...) +{ + char bufPrint[0x100]; + va_list vArgv; + va_start(vArgv, pBuf); + vsprintf(bufPrint, pBuf, vArgv); + va_end(vArgv); + AGBPrint(bufPrint); +} + +static void AGBPrintTransferDataInternal(u32 bAllData) +{ + LPFN_PRINT_FLUSH lpfnFuncFlush; + u16 *pIME; + u16 nIME; + u16 *pWSCNT; + u16 nOldWSCNT; + u16 *pProtect; + volatile struct AGBPrintStruct *pPrint; + + pProtect = (u16 *)AGB_PRINT_PROTECT_ADDR; + pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; + lpfnFuncFlush = (LPFN_PRINT_FLUSH)AGB_PRINT_FLUSH_ADDR; + pIME = (u16 *)REG_ADDR_IME; + nIME = *pIME; + pWSCNT = (u16 *)REG_ADDR_WAITCNT; + nOldWSCNT = *pWSCNT; + *pIME = nIME & ~1; + *pWSCNT = WSCNT_DATA; + + if (bAllData) + { + while (pPrint->m_nPut != pPrint->m_nGet) + { + *pProtect = 0x20; + lpfnFuncFlush(); + *pProtect = 0; + } + } + else if (pPrint->m_nPut != pPrint->m_nGet) + { + *pProtect = 0x20; + lpfnFuncFlush(); + *pProtect = 0; + } + + *pWSCNT = nOldWSCNT; + *pIME = nIME; +} + +void AGBPrintFlush1Block(void) +{ + AGBPrintTransferDataInternal(FALSE); +} + +void AGBPrintFlush(void) +{ + AGBPrintTransferDataInternal(TRUE); +} + +void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopProgram) +{ + if (nStopProgram) + { + AGBPrintf("ASSERTION FAILED FILE=[%s] LINE=[%d] EXP=[%s] \n", pFile, nLine, pExpression); + AGBPrintFlush(); + asm(".hword 0xEFFF"); + } + else + { + AGBPrintf("WARING FILE=[%s] LINE=[%d] EXP=[%s] \n", pFile, nLine, pExpression); + } +} +#endif -- cgit v1.2.3 From d50dcfcdd37aedab6352e4953cb2be04f2691113 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Tue, 2 Jan 2018 00:53:26 -0500 Subject: add no print support. --- src/libs/libisagbprn.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index 64ccb6351..9691d1b90 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -2,12 +2,17 @@ #include #include "gba/gba.h" #include "config.h" +#include "assert.h" #define AGB_PRINT_FLUSH_ADDR 0x9FE209D #define AGB_PRINT_STRUCT_ADDR 0x9FE20F8 #define AGB_PRINT_PROTECT_ADDR 0x9FE2FFE #define WSCNT_DATA (WAITCNT_PHI_OUT_16MHZ | WAITCNT_WS0_S_2 | WAITCNT_WS0_N_4) +// for auto no$gba support, the string "no$gba" should be at this address. +#define NOGBAIDADDR 0x4FFFA00 +#define NOGBAPRINTADDR 0x4FFFA14 + struct AGBPrintStruct { u16 m_nRequest; @@ -61,18 +66,29 @@ void AGBPutc(const char cChr) AGBPrintFlush1Block(); } +#undef AGBPrint // dont break the function + void AGBPrint(const char *pBuf) { - volatile struct AGBPrintStruct *pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; - u16 *pWSCNT = (u16 *)REG_ADDR_WAITCNT; - u16 nOldWSCNT = *pWSCNT; - *pWSCNT = WSCNT_DATA; - while (*pBuf) - { - AGBPutc(*pBuf); - pBuf++; - } - *pWSCNT = nOldWSCNT; + volatile struct AGBPrintStruct *pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; + u16 *pWSCNT = (u16 *)REG_ADDR_WAITCNT; + u16 nOldWSCNT = *pWSCNT; + *pWSCNT = WSCNT_DATA; + while (*pBuf) + { + AGBPutc(*pBuf); + pBuf++; + } + *pWSCNT = nOldWSCNT; +} + +// I have to define this twice to avoid messing AGBPrint up. If there's a better way of doing this, please fix it. +// currently cannot use IsNoGba due to no$gba doing a gloriously fuck up of a job and +// breaking the version identifier. +#define AGBPrint(pBuf) \ +{ \ + NOGBAPrint(pBuf); \ + AGBPrint(pBuf); \ } void AGBPrintf(const char *pBuf, ...) @@ -148,4 +164,12 @@ void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopP AGBPrintf("WARING FILE=[%s] LINE=[%d] EXP=[%s] \n", pFile, nLine, pExpression); } } + +// nogba print function + +void NOGBAPrint(const char *pBuf) +{ + *(volatile u32*)NOGBAPRINTADDR = (u32)pBuf; +} + #endif -- cgit v1.2.3 From ab06b56532026db85a9cba1c21c8b2235fcdf222 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Tue, 2 Jan 2018 00:56:11 -0500 Subject: formatting --- src/libs/libisagbprn.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index 9691d1b90..ef0d51f26 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -70,16 +70,16 @@ void AGBPutc(const char cChr) void AGBPrint(const char *pBuf) { - volatile struct AGBPrintStruct *pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; - u16 *pWSCNT = (u16 *)REG_ADDR_WAITCNT; - u16 nOldWSCNT = *pWSCNT; - *pWSCNT = WSCNT_DATA; - while (*pBuf) - { - AGBPutc(*pBuf); - pBuf++; - } - *pWSCNT = nOldWSCNT; + volatile struct AGBPrintStruct *pPrint = (struct AGBPrintStruct *)AGB_PRINT_STRUCT_ADDR; + u16 *pWSCNT = (u16 *)REG_ADDR_WAITCNT; + u16 nOldWSCNT = *pWSCNT; + *pWSCNT = WSCNT_DATA; + while (*pBuf) + { + AGBPutc(*pBuf); + pBuf++; + } + *pWSCNT = nOldWSCNT; } // I have to define this twice to avoid messing AGBPrint up. If there's a better way of doing this, please fix it. -- cgit v1.2.3 From d4df8046d45e50e19d2305bd4388e47087949960 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 6 Jan 2018 21:52:05 -0500 Subject: use firered isagbprint.h and NDEBUG --- src/libs/libisagbprn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index 867044217..eccc31f48 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -25,7 +25,7 @@ struct AGBPrintStruct typedef void (*LPFN_PRINT_FLUSH)(void); -#ifndef NOAGBPRN +#ifndef NDEBUG void AGBPrintFlush1Block(void); void AGBPrintInit(void) -- cgit v1.2.3 From a289caaf97cddbf212fc860013b8815323a84921 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 8 Jan 2018 17:03:06 -0500 Subject: let the user deal with nogbaprint, forget this --- src/libs/libisagbprn.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index eccc31f48..c066a41a0 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -2,16 +2,14 @@ #include #include "gba/gba.h" #include "config.h" -#include "assert.h" #define AGB_PRINT_FLUSH_ADDR 0x9FE209D #define AGB_PRINT_STRUCT_ADDR 0x9FE20F8 #define AGB_PRINT_PROTECT_ADDR 0x9FE2FFE #define WSCNT_DATA (WAITCNT_PHI_OUT_16MHZ | WAITCNT_WS0_S_2 | WAITCNT_WS0_N_4) -// TODO: make no$gba support not shit - // for auto no$gba support, the string "no$gba" should be at this address. +// except it's not, blame Martin, hence I'm letting the user deal with this nonsense. #define NOGBAIDADDR 0x4FFFA00 #define NOGBAPRINTADDR 0x4FFFA14 @@ -26,6 +24,7 @@ struct AGBPrintStruct typedef void (*LPFN_PRINT_FLUSH)(void); #ifndef NDEBUG + void AGBPrintFlush1Block(void); void AGBPrintInit(void) @@ -156,12 +155,12 @@ void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopP } } -// TODO: Find a way to seamlessly support no$gba without shit hack defines -// nogba print function +// nogba print function, uncomment to use /* void NOGBAPrint(const char *pBuf) { *(volatile u32*)NOGBAPRINTADDR = (u32)pBuf; -}*/ +} +*/ #endif -- cgit v1.2.3 From 1c6c7da6fba8903d8eff02ac12465a4098ebca47 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 8 Jan 2018 21:40:37 -0500 Subject: nogba to nocashgba --- src/libs/libisagbprn.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index c066a41a0..007f90bb7 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -10,8 +10,8 @@ // for auto no$gba support, the string "no$gba" should be at this address. // except it's not, blame Martin, hence I'm letting the user deal with this nonsense. -#define NOGBAIDADDR 0x4FFFA00 -#define NOGBAPRINTADDR 0x4FFFA14 +#define NOCASHGBAIDADDR 0x4FFFA00 +#define NOCASHGBAPRINTADDR 0x4FFFA14 struct AGBPrintStruct { @@ -155,11 +155,11 @@ void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopP } } -// nogba print function, uncomment to use +// no$gba print function, uncomment to use /* -void NOGBAPrint(const char *pBuf) +void NoCashGBAPrint(const char *pBuf) { - *(volatile u32*)NOGBAPRINTADDR = (u32)pBuf; + *(volatile u32*)NOCASHGBAPRINTADDR = (u32)pBuf; } */ -- cgit v1.2.3 From dcf12f9ecdbaab26afb8899eaa05f4cab09a5f82 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 8 Jan 2018 22:01:47 -0500 Subject: nocashgba printf --- src/libs/libisagbprn.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index 007f90bb7..a9656f3c5 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -155,12 +155,22 @@ void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopP } } -// no$gba print function, uncomment to use +// no$gba print functions, uncomment to use /* void NoCashGBAPrint(const char *pBuf) { *(volatile u32*)NOCASHGBAPRINTADDR = (u32)pBuf; } + +void NoCashGBAPrintf(const char *pBuf, ...) +{ + char bufPrint[0x100]; + va_list vArgv; + va_start(vArgv, pBuf); + vsprintf(bufPrint, pBuf, vArgv); + va_end(vArgv); + NoCashGBAPrint(bufPrint); +} */ #endif -- cgit v1.2.3 From 3c375850d12d774cb75803093ad80aa2783e4566 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Tue, 9 Jan 2018 19:28:01 -0500 Subject: comment --- src/libs/libisagbprn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index a9656f3c5..98231dcf5 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -8,8 +8,8 @@ #define AGB_PRINT_PROTECT_ADDR 0x9FE2FFE #define WSCNT_DATA (WAITCNT_PHI_OUT_16MHZ | WAITCNT_WS0_S_2 | WAITCNT_WS0_N_4) -// for auto no$gba support, the string "no$gba" should be at this address. -// except it's not, blame Martin, hence I'm letting the user deal with this nonsense. +// originally for auto no$gba support, the string "no$gba" should be at this address, +// the user needs to read this string out as the memory viewer won't show it. #define NOCASHGBAIDADDR 0x4FFFA00 #define NOCASHGBAPRINTADDR 0x4FFFA14 -- cgit v1.2.3 From a51b95150ba86a3982f613886471626f742aeacd Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Tue, 9 Jan 2018 19:40:14 -0500 Subject: both print defines for nocashgba --- src/libs/libisagbprn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libs') diff --git a/src/libs/libisagbprn.c b/src/libs/libisagbprn.c index 98231dcf5..e0e979e95 100755 --- a/src/libs/libisagbprn.c +++ b/src/libs/libisagbprn.c @@ -11,7 +11,8 @@ // originally for auto no$gba support, the string "no$gba" should be at this address, // the user needs to read this string out as the memory viewer won't show it. #define NOCASHGBAIDADDR 0x4FFFA00 -#define NOCASHGBAPRINTADDR 0x4FFFA14 +#define NOCASHGBAPRINTADDR1 0x4FFFA10 // automatically adds a newline after the string has finished +#define NOCASHGBAPRINTADDR2 0x4FFFA14 // does not automatically add the newline. by default, NOCASHGBAPRINTADDR2 is used. this is used to keep strings consistent between no$gba and VBA-RR, but a user can choose to forgo this. struct AGBPrintStruct { @@ -159,7 +160,7 @@ void AGBAssert(const char *pFile, int nLine, const char *pExpression, int nStopP /* void NoCashGBAPrint(const char *pBuf) { - *(volatile u32*)NOCASHGBAPRINTADDR = (u32)pBuf; + *(volatile u32*)NOCASHGBAPRINTADDR2 = (u32)pBuf; } void NoCashGBAPrintf(const char *pBuf, ...) -- cgit v1.2.3