summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorExpoSeed <43502820+ExpoSeed@users.noreply.github.com>2020-09-02 13:21:51 -0500
committerExpoSeed <43502820+ExpoSeed@users.noreply.github.com>2020-09-02 13:21:51 -0500
commit4acbb4b22c49f72ff69be3bae585abce5ed969dd (patch)
tree6652169de69219da5d0cdabfeb190d51e0b12e14
parent69ba856ad88d4121a02a5be1ce38393b0aa68069 (diff)
Created printf in mGBA (markdown)
-rw-r--r--printf-in-mGBA.md58
1 files changed, 58 insertions, 0 deletions
diff --git a/printf-in-mGBA.md b/printf-in-mGBA.md
new file mode 100644
index 0000000..a0ba761
--- /dev/null
+++ b/printf-in-mGBA.md
@@ -0,0 +1,58 @@
+Credits to Petuh for this tutorial, and for Lunos for finding an archived version.
+
+TODO: rewrite to be in line with the standards of other tutorials. As of now, this is identical to Petuh's original post.
+
+This is for having an mGBA Debug printf function.
+First, download [this](https://cdn.discordapp.com/attachments/744575017051881492/744961612200542288/mGBA_Debug_printf.zip). Pop the files into where they're supposed to go in src and include. Next, add
+```c
+ src/mgba.o(.text);
+ src/printf.o(.text);
+```
+and
+```c
+ src/printf.o(.rodata);
+```
+to `ld_script.txt`. Next, then add `#include "mgba.h" to main.c`, and in `AgbMain`, add `mgba_open();` below `SetDefaultFontsPointer();`.
+Now you are ready to change the `vsprintf` to `vsnprintf`. To do this, add `#include "printf.h"` to `libisagbprn.c`. In `#define AGB_PRINT_STRUCT_ADDR 0x9FE20F8`, change to `#define AGB_PRINT_STRUCT_ADDR (char*) 0x9FE20F8`. Then, change both `vsprintf` to `vsnprintf`.
+OPTIONAL: Printing to strings and testing
+Now is the printing to strings and testing part, both optional. If you want to print to string, add `#include "malloc.h"` to `string_util.c`. Then, add
+```c
+char *ConvertToAscii(const u8 *str)
+{
+ s32 i;
+ char * textBuffer = malloc(128);
+ for (i = 0; *str != EOS; i++, str++)
+ {
+ char modifiedCode = '?';
+ if(*str >= CHAR_a && *str <= CHAR_z)
+ {
+ modifiedCode = *str-(CHAR_A-'a'); // lower-case characters
+ }
+ else if(*str >= CHAR_A && *str <= CHAR_Z)
+ {
+ modifiedCode = *str-(CHAR_A-'A'); // upper-case characters
+ }
+ else if (*str >= CHAR_0 && *str <= CHAR_9)
+ {
+ modifiedCode = *str-(CHAR_0-'0'); // numbers
+ }
+ else if (*str == CHAR_SPACE)
+ {
+ modifiedCode = ' '; // space
+ }
+ textBuffer[i] = modifiedCode;
+ }
+ textBuffer[i] = 0;
+ return textBuffer;
+}
+```
+(credits to Pidgey)
+In `string util.h`, add `char *ConvertToAscii(const u8 *str);`.
+Finally, the testing. make sure you include
+```c
+#include "printf.h"
+#include "mgba.h"
+#include "gba/isagbprint.h"
+```
+in whatever file you test with. optionally, you can include `#include "../gflib/string_util.h"`, and `#include "data.h"` if you want to get for example a species name. Let's test in `wild_encounter.c`. before `CreateMonWithNature(&gEnemyParty[0], species, level, 32, PickWildMonNature());`, add `mgba_printf(MGBA_LOG_DEBUG, "%s", ConvertToAscii(gSpeciesNames[species]));`. If you want to just get a number, you can do `mgba_printf(MGBA_LOG_DEBUG, "%d", species);`.
+That is all. \ No newline at end of file