Commit Graph

73 Commits

Author SHA1 Message Date
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
Philippe Symons
6d60fb8901 Merge branch 'optimizations/reduce-binarysize-remove-libstdc++' into optimizations/implement-zx0-compression 2025-05-25 22:34:45 +02: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
868b23ba45 Disabling new conversion 2025-05-21 11:43:16 -04:00
Philippe Symons
851be36b0d Merge branch 'master' into optimizations/implement-zx0-compression 2025-05-21 13:16:45 +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
Philippe Symons
8e55a2bd52 Bundle charsets per gen for slightly better compression and move some tables back as uncompressed
The ones I moved back as uncompressed tables (EVOLUTIONS and gen_1_index_array) simply didn't compress well
at all. It wasn't worth the runtime decompression cost.
2025-04-28 20:47:55 +02:00
Philippe Symons
75f8e5a26a More optimization:
Remove the RingBuffer entirely.

We can now decompress 512 bytes in 3 ms.
2025-04-27 23:32:02 +02:00
Philippe Symons
67797daf66 Merge branch 'master' into optimizations/reduce-binarysize-remove-libstdc++ 2025-04-24 21:26:14 +02:00
Philippe Symons
532a095d77 Implement zx0 compression
Compress data tables with the ZX0 compression algorithm
2025-04-24 21:14:48 +02:00
The Gears of Progress
dac8939373 Updating pokemon.cpp 2025-04-21 11:29:54 -04:00
The Gears of Progress
a98262b852 Merge branch 'master' of https://github.com/GearsProgress/Poke_Transporter_GB 2025-04-21 11:28:42 -04:00
The Gears of Progress
92020b228d Starting implementation of transfer options 2025-04-21 11:28:33 -04:00
The Gears of Progress
20c5b93f66
Update pokemon.cpp 2025-04-21 11:27:48 -04:00
Philippe Symons
9268cbd42e Reduce binary size by eliminating libstdc++
This commit removes all references to things in the libstdc++ library to remove a decent chunk of bloat.

This means every std::to_string() call, std::string and std::vector. (as well as iostream related stuff).

I replaced those with my own versions ptgb::to_string() and ptgb::vector. Especially the latter is not exactly the same,
but close enough.

I also replaced operator new and delete with my own implementation to avoid pulling in everything related to exceptions
from libstdc++

Another problem was the fact that libtonc uses siscanf, which pulls in everything related to the scanf family of functions
and locale support. The worst part of that was that it included a 13KB "categories" symbol from libc_a-categories.o,
which was pulled in because of the locale support integrated into newlibc's siscanf() function. To fix that, I created a
custom, extremely restricted implementation of siscanf. libtonc only used this function to parse at most 2 integers from a
string anyway.
2025-04-09 20:04:08 +02:00
The Gears of Progress
af21da42b5 continuing work on updated text engine 2025-03-04 11:33:02 -05:00
The Gears of Progress
a805bbad0a Releasing wood gecko 2025-01-11 17:23:09 -05:00
The Gears of Progress
1662ed37e3 Fixing weird split changes 2024-12-19 18:39:37 -05:00
The Gears of Progress
422641c62b Merge branch 'master' of https://github.com/GearsProgress/Poke_Transporter_GB 2024-12-19 18:27:44 -05:00
The Gears of Progress
41f7fcb1aa *Finally* fixing the EXP bug 2024-12-19 18:15:04 -05:00
The Gears of Progress
a5e4e9401c Partial rewrite 2024-12-19 16:30:08 -05:00
The Gears of Progress
b382aec0dc pre Pokemon and Party rewrite 2024-12-19 13:29:47 -05:00
The Gears of Progress
3b945ecf3e v1.1.0 2024-11-01 22:54:05 -04:00
The Gears of Progress
884ebc9216 Adding data packets to GSC 2024-10-31 10:59:36 -04:00
The Gears of Progress
cd2a9971a5 Adding data packets to Red/Blue 2024-10-30 14:56:44 -04:00
The Gears of Progress
1a6d65887f Final push before release v1.0 2024-08-23 12:11:27 -04:00
The Gears of Progress
1ec09842ad Updating tons of graphics 2024-08-19 14:47:29 -04:00
The Gears of Progress
22f7aaac26 Pre-saving space 2024-08-13 15:49:04 -04:00
The Gears of Progress
aa4d2573b8 Fixing bugs 2024-07-11 11:18:38 -04:00
The Gears of Progress
e5ad1e25cf Changing background and fixing bugs 2024-07-02 16:55:47 -04:00
The Gears of Progress
7e82dd7b65 Adding support for gen 2 2024-06-11 16:34:58 -04:00
The Gears of Progress
2cfec76b3c Adding support for Yellow and fixing other bugs 2024-06-07 13:55:01 -04:00
The Gears of Progress
bf7f7f401c Continuing Payload Work 2024-05-02 12:18:24 -05:00
Remnants of Forgotten Disney
5cb282c8a7 Implementing Yellow and Gold/Silver Payloads 2024-04-29 08:29:09 -05:00
Remnants of Forgotten Disney
a4bda4c673 Adding in event stabilization 2024-04-17 09:17:15 -05:00
Remnants of Forgotten Disney
301ccf602b Finalizing Red/Blue Payload 2024-04-07 16:46:39 -05:00
Remnants of Forgotten Disney
a27f1c2c37 Continuing transfer menu implementation 2024-04-02 12:19:06 -05:00
Remnants of Forgotten Disney
13450924c2 Implementing new payload system 2024-03-29 23:39:58 -05:00
Remnants of Forgotten Disney
c825203e70 Modifying save data flags 2024-03-04 16:56:14 -06:00
Remnants of Forgotten Disney
020d27433d Preparing for ASM rewrite 2024-02-24 14:53:12 -06:00
Remnants of Forgotten Disney
1b5f30087a Modifying Pokemon Injection 2024-02-19 08:29:37 -06:00
Remnants of Forgotten Disney
8bb76ca58c Double checking formatting 2023-11-29 08:28:55 -06:00
Remnants of Forgotten Disney
f7120e97bb Finalized graphics 2023-11-18 19:35:30 -06:00
Remnants of Forgotten Disney
ead09e0b49 Fixing double injection corruption 2023-11-18 15:58:59 -06:00
Remnants of Forgotten Disney
fde2cfe68f Adding check for other events 2023-11-18 12:58:48 -06:00
Remnants of Forgotten Disney
a2ebc40054 Finalize language conversion 2023-11-10 19:20:27 -06:00
Remnants of Forgotten Disney
fbb3dccb0f THE POKEDEX ADDITONS WORK 2023-11-01 12:02:52 -05:00
Remnants of Forgotten Disney
e7fd5f1aba Dialouge system update and text formatting 2023-10-28 17:38:58 -05:00
Remnants of Forgotten Disney
0cca5a82ad Default Language Selection 2023-10-26 12:19:24 -05:00
Remnants of Forgotten Disney
18b9815327 Beginning langauge selection menu and char arrays 2023-10-23 22:25:09 -05:00