Commit Graph

264 Commits

Author SHA1 Message Date
The Gears of Progress
1acbe99f93 Updating debug ROM to first check if real ROM has been inserted 2026-01-19 15:32:53 -05:00
The Gears of Progress
f50d42f61f Updating accent characters 2026-01-13 20:24:03 -05:00
The Gears of Progress
2309f7c493 Adding text debug menu 2026-01-11 17:33:02 -05:00
The Gears of Progress
2482bb486b Modifying decompression function to be based on indexes 2026-01-11 17:09:30 -05:00
The Gears of Progress
1055094ab9 Modifying text_helper to not have static text sections 2026-01-11 15:02:16 -05:00
The Gears of Progress
97e1333078 Removing extra debug info 2026-01-03 17:31:30 -05:00
The Gears of Progress
fff4588d4a Updating packet debug features and restricting data offset to positive numbers 2026-01-03 17:29:36 -05:00
The Gears of Progress
a5ff585596
Merge pull request #76 from GearsProgress/latest-release
Refactoring to latest "latest release" branch
2025-12-06 15:50:56 -05:00
The Gears of Progress
9ca5c650d0 Working on debugging 2025-12-03 22:08:35 -05:00
Philippe Symons
a7b2703bf8 Replace the PCCS code with a git submodule
This eliminates duplicate code. - Only maintain the code in one place!

To make sure the submodule is getting cloned too after cloning Poke_Transporter_GB, execute:
git submodule update --init --recursive

To update the submodule to a newer commit/different branch:

cd PCCS
git pull
git checkout <commit_or_branchname>
cd ..
git add PCCS
git commit
git push

The way it works is that a specific commit is tied to your Poke_Transporter_GB repository's PCCS folder.
2025-11-27 23:14:29 +01:00
The Gears of Progress
a98a58eb4e Final finishing touches 2025-10-12 16:41:48 -04:00
The Gears of Progress
ba1a075701 Adding PCCS 2025-10-12 15:08:33 -04:00
The Gears of Progress
a0793c72c0 Fixing issues before implementing the CPCS 2025-09-20 17:17:20 -04:00
The Gears of Progress
ed6ee974f8 Fixing connection textbox 2025-08-06 23:08:00 -04:00
The Gears of Progress
ba9e30e8d0 Fixing a few bugs before merge 2025-07-28 16:18:51 -04:00
The Gears of Progress
1f325657ec
Merge pull request #55 from risingPhil/feature/use-lz10-instead-of-zx0 2025-07-18 14:18:57 -05:00
The Gears of Progress
788a0909b3
Merge pull request #53 from easyaspi314/text-and-box-rewrite 2025-07-18 13:23:38 -05:00
Philippe Symons
79b6cc64a2 Remove benchmark code again 2025-07-18 16:24:59 +02:00
Philippe Symons
47cd143de6 Replace ZX0 by the builtin LZ10 compression.
LZ10 decompression is builtin to the GBA's bios, so we don't need ZX0. It's also significantly faster
(618 usec instead of 2311 usec in my personal benchmark code for decompression of the same data)

And it seems like by doing so, we saved 1 KB as well!

So, seems like replacing ZX0 is the right move.

The reason I didn't initially is because I misunderstood the documentation. I assumed LZ77UnCompWram could only uncompress into EWRAM, not IWRAM.
But it turns out it can do both.

And using standardized tools is usually better than using a custom implementation.

The only downside of this right now, is that we can no longer stream text tables through a smaller buffer than the entire decompressed size.

Anyway, things seem to work fine, so bye bye ZX0. It's been fun.
2025-07-18 16:19:34 +02:00
Philippe Symons
6b89ff8367 Remove test_decompress again 2025-07-18 13:15:56 +02:00
Philippe Symons
2689ffd3cf Optimize Gameboy payloads for size by generating the payloads at runtime and generate binary patches
This commit moves payload_builder and the z80_asm code to the data-generator subproject in order to generate the gameboy payloads
at compile time instead of at runtime.

In addition, we select a couple of base payloads (more than 1 for compressibility's sake) and generate binary patches to transform them into
other payloads. We then generate a binary file with both the base payload and binary patches and compress these files with zx0.

This reduces the rom size by about 8 KB.
2025-07-18 12:48:50 +02:00
easyaspi314
750641c78f Prepare for trouble... and make it.... fixed point?
To protect the world from the soft float library...
To unite all arithmetic within our binary...
To denounce the evils of floating point precision...
To save more kilobytes - that's our vision....

(god this is cringe)

All floating point math has been eliminated, and replaced with
equivalent or near-equivalent fixed-point math.

sprite_data.cpp uses Q16, and get_rand_range uses a full Q32 to
ensure that the exact same results are generated as before, at
the cost of some inline assembly to do a umull (__aeabi_lmul is a
little excessive when the lower 32 bits are discarded)

This eliminates all of the expensive double precision float library,
saving a few kilobytes.

Additionally, the unneccessary parts of nanoprintf have been
disabled. There is no need for precision specifiers, long longs, or
floats.
2025-06-30 13:05:32 -04:00
Philippe Symons
4833a3344e Avoid pulling in the verdana9 and sys8Font fonts from libtonc
I eliminated these fonts by redefining code from tte_init_chr4c.c and tte_main.c files in libtonc.

Both the original tte_init_chr4c and tte_init_base functions had some code to use either verdana9 or sys8Font as default if the user
did not specify a font instance.

But we don't need it.

To eliminate this code, we not only had to define a custom version that omits this code, but also had to redefine other functions from those .c files
in order to make the linker not try to pull in those .o files from libtonc and use our versions instead.
2025-06-27 18:00:23 +02:00
Philippe Symons
5e7118c0c7 Compress the gb_rom_values and gba_rom_values tables with ZX0. 2025-06-27 16:04:04 +02:00
The Gears of Progress
9e488ae2af Fixing Windows Environment 2025-06-24 16:35:32 -04:00
Philippe Symons
32db0d690d Implement custom malloc -> rom space: -3 KB, IWRAM: -1 KB
I found another way to optimize the rom space by implementing a custom malloc, free, realloc and calloc
function.

This reduces rom size by 3 KB and IWRAM usage by 1 KB. (elimination of __malloc_av). The original
implementation is much more complex and larger than it needs to be.

The custom malloc is implemented as a bitmap allocator. It keeps a bitmap to track which pages of the
heap are allocated. Like the original allocator, it uses the free space in EWRAM after the multiboot gba
rom. But unlike the original allocator, we control the size with CUSTOM_MALLOC_POOL_SIZE.

The custom malloc can be disabled with USE_CUSTOM_MALLOC.
2025-06-20 22:39:42 +02:00
Philippe Symons
5750abba2c Merge remote-tracking branch 'upstream/text-and-box-rewrite' into optimizations/implement-zx0-compression
Conflicts:
	source/payload_builder.cpp
2025-06-18 21:07:11 +02:00
Philippe Symons
be58d28781 Merge remote-tracking branch 'upstream/text-and-box-rewrite' into optimizations/reduce-binarysize-remove-libstdc++ 2025-06-18 20:59:18 +02:00
The Gears of Progress
9ebfd1bf57 Adding to gitignore 2025-06-18 14:45:12 -04:00
Philippe Symons
9352f67d63 Remove decompression benchmark and re-enable debug screen in credits 2025-06-18 10:54:47 +02:00
Philippe Symons
eef173b0d2 Fix crash + unrelated buffer overflow + some optimizations
There was a crash happening with ptgb::vector when you'd press A on the CONFIRM button of the box screen. It only occurred on actual gba hardware and
was a real heisenbug: as soon as you'd add code to display logs on screen, the problem would disappear. So it was very difficult to figure this one
out. We're not even entirely sure why, but it looks like the malloc/realloc/free use in ptgb::vector would cause issues.

Maybe it was alignment, but after messing with the code we also saw a warning appear in the terminal telling us that realloc wouldn't properly
deal with non-POD types. It complained about this very thing while referring to the add_track() function, which stores ptgb::vectors inside another
ptgb::vector. We also didn't have a custom copy constructor yet to actually copy the buffer instead of its pointer.
All of these could potentially have led to the crash. But debugging during the link cable flow was difficult, so we were never able to confirm it in
a debugger, log or dump.

Because I suspected the high IWRAM consumption (especially now with ZX0 decompression) for a while, I also did an optimization in mystery_gift_builder
to pass global_memory_buffer as its section_30_data buffer instead. This reduces IWRAM consumption by 4 KB.

There was another problem I discovered during my crash hunt: the out_array (now payload_buffer) was allocated as a 672 byte array, but the payloads
were actually 707 bytes. Therefore writing this to the buffer caused a buffer overflow, thereby corrupting the global variables appearing after it in
IWRAM. It turned out eventually that none of these variables were really critical, but it could explain some minor bugs GearsProgress has seen.

I also did a few performance optimizations:

- At various stages in the code, for loops were used to copy data from one buffer into another byte-by-byte. This was far from optimal because the gba
cpu can load/copy 4 bytes at a time if you ask it to. So I replaced those with memcpy(), which is a hand-optimized assembly function to copy data
using this principle.

- generate_payload was being called twice: once at start_link and once at continue_link, giving the exact same result, even though it was already
being stored in a global buffer allocated in IWRAM. This was also a fairly heavy function. So I optimized the code to only initialize it once in
the script chain and then just retrieve the buffer.

- generate_payload was constructing the eventual payload twice even within the same call. That's because it first merged z80_rng_seed, z80_payload
and z80_patchlist into a full_data ptgb::vector, after which it then copied the data again to out_array (now called payload_buffer). I eliminated the
full_data vector now.
2025-06-18 10:23:03 +02:00
The Gears of Progress
48b55d9b9c Adding sprite locations for all English games 2025-06-06 15:30:26 -04:00
The Gears of Progress
42815f166f Starting to add sprite compatibility 2025-05-27 16:48:04 -04:00
Philippe Symons
53662cff9d Merge remote-tracking branch 'upstream/text-and-box-rewrite' into optimizations/reduce-binarysize-remove-libstdc++ 2025-05-27 22:44:18 +02:00
Philippe Symons
13d4b3f7d5 Fix ptgb_write_debug() after merge 2025-05-27 22:39:16 +02:00
Philippe Symons
7f20f6f58e Merge remote-tracking branch 'upstream/text-and-box-rewrite' into optimizations/implement-zx0-compression 2025-05-27 22:31:05 +02:00
The Gears of Progress
03c3e0540b Applying patch for graphics issues 2025-05-27 15:13:42 -04:00
Philippe Symons
ce4c807bab Merge branch 'optimizations/reduce-binarysize-remove-libstdc++' into optimizations/implement-zx0-compression 2025-05-25 22:45:47 +02:00
Philippe Symons
1d77f8f848 Merge remote-tracking branch 'upstream/text-and-box-rewrite' into optimizations/reduce-binarysize-remove-libstdc++ 2025-05-25 22:45:26 +02:00
Philippe Symons
6d60fb8901 Merge branch 'optimizations/reduce-binarysize-remove-libstdc++' into optimizations/implement-zx0-compression 2025-05-25 22:34:45 +02:00
The Gears of Progress
e5375b9155 Fixing post-transfer text box 2025-05-25 15:41:09 -04:00
Philippe Symons
c918f20f19 Merge remote-tracking branch 'upstream/text-and-box-rewrite' into optimizations/reduce-binarysize-remove-libstdc++ 2025-05-25 21:03:59 +02:00
The Gears of Progress
dd0dc20837 Fixing sprite corruption and adding game pak sprite debug toggle 2025-05-25 13:00:07 -04:00
The Gears of Progress
868b23ba45 Disabling new conversion 2025-05-21 11:43:16 -04:00
Philippe Symons
a8d2575f5d Move reading dialogue text out of the text_loop() to conserve IWRAM 2025-05-21 17:39:52 +02:00
Philippe Symons
903ccb0d21 Some minor optimizations 2025-05-21 17:29:12 +02:00
Philippe Symons
851be36b0d Merge branch 'master' into optimizations/implement-zx0-compression 2025-05-21 13:16:45 +02:00
Philippe Symons
26fd1e2dd3 Add compression for the text data, output stack usage .su files and rework script_array
Add a binary table format and convert the text entries into this format in text_helper/main.py. It then gets compressed with zx0.

The new text_data_table and streamed_data_table classes exist to read the various entries from this binary table. streamed_data_table specifically
exists to use a decompression buffer that is smaller than the actual binary table. But it requires a decompression buffer that is
still larger than ZX0_DEFAULT_WINDOW_SIZE (default: 2048 bytes) and will only be able to decompress in
chunks of (<decompression_buffer_size> - <ZX0_DEFAULT_WINDOW_SIZE>) bytes

Try to keep the binary text tables sufficiently small though, because since zx0 doesn't actually support random access,
getting to the last entry is significantly more expensive than reading the first one. And unless you use streamed_data_table,
it also requires <uncompressed_size> bytes of stack space, therefore IWRAM to decompress them.

I also had to rework script_array because it can no longer reference the strings directly. Instead we now reference the DIA_* "enum" values.
We also no longer store an array of script_obj instances, because these were getting stored in IWRAM since they're non-const global variables
originally. Instead we now have const arrays of script_obj_params structs, which should end up in .rodata -> therefore EWRAM.

Right now, script_obj only supports the PTGB text table (originally the dialogue array). But if the need arises to support other tables as well,
I'd consider adding a separate enum to script_obj_params to indicate the specific table.

The compilation process will also output .su files in the build folder from now on. These files indicate the stack frame size for every function in
every compilation unit, so be sure to check them from time to time. Note that they will only show the stack consumption for that specific function.
So to get the worst case stack consumption, you need to manually add all the functions in a certain stack flow.
2025-05-21 12:21:06 +02:00
Philippe Symons
12d1d10fc7 Revert MOVESETS -> bring it back as uncompressed data in pokemon_data.cpp
... and add a comment why.
2025-04-30 12:41:46 +02:00
Philippe Symons
4c93ff869c Optimize the MOVESETS table for compression + eliminate 4 KB "handles" buffer from
libsysbase_libsysbase_a-handle_manager.o

So, I optimized the MOVESETS table to only store the "overriding" bits in the movesets of the evolutions
in relation to their base forms. That only improved compression slightly (about 300 bytes)

I also eliminated 4 KB of IWRAM usage by libsysbase_libsysbase_a-handle_manager.o because of the "handles"
buffer. We're not using it and we REALLY need our IWRAM. (and it also reduces the rom size with 4KB too!)
2025-04-29 22:22:38 +02:00