Poke_Transporter_GB/source/libstd_replacements.cpp
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

59 lines
1.7 KiB
C++

#define NANOPRINTF_IMPLEMENTATION 1
#include "libstd_replacements.h"
#include "libraries/nanoprintf/nanoprintf.h"
#include <cstdlib>
#include <stdarg.h>
#include <ctype.h>
// recommended for a 32 bit system to have at least 33 bytes available
// source: https://cplusplus.com/reference/cstdlib/itoa/
// unfortunately itoa is not standardized, so we'll have to make do with snprintf
static char conversion_buffer[33];
const char* ptgb::to_string(int intVal)
{
npf_snprintf(conversion_buffer, sizeof(conversion_buffer), "%d", intVal);
return conversion_buffer;
}
const char* ptgb::to_string(unsigned int wordVal)
{
npf_snprintf(conversion_buffer, sizeof(conversion_buffer), "%u", wordVal);
return conversion_buffer;
}
// when compiling with -nostdlib++, we need to provide our own operator new and delete implementations
// Regular operator new
void* operator new(std::size_t size) {
void* ptr = std::malloc(size);
if (!ptr) {
// mimic standard behavior: throw std::bad_alloc
// but we can't use std::bad_alloc without libstdc++
// so instead we can abort or return nullptr
// You can also implement a custom exception if needed
std::abort();
}
return ptr;
}
// nothrow version
void* operator new(std::size_t size, const std::nothrow_t&) noexcept {
return std::malloc(size);
}
// operator delete
void operator delete(void* ptr) noexcept {
std::free(ptr);
}
// nothrow delete
void operator delete(void* ptr, const std::nothrow_t&) noexcept {
std::free(ptr);
}
// sized delete (optional, for C++14 and newer)
void operator delete(void* ptr, std::size_t size) noexcept {
(void)size;
std::free(ptr);
}