Change debug::puts to use raw char* and copy

In order to handle the self-assign case, string::operator= moves the
string, which may copy the string in reverse. The MGBA string register
does not allow this I believe. In order to avoid this, it now uses a raw
character buffer and is copied using string_view::copy.
string_view::copy will always copy the string forward.
This commit is contained in:
Myles Busig 2024-03-07 15:58:51 -07:00
parent 1c1e156d55
commit 67f16364ec

View File

@ -31,11 +31,17 @@ static volatile uint16_t& flags = *reinterpret_cast<uint16_t*>(0x4FFF700);
*
* Max length of 0x100 (256) including null terminator.
*/
static mtl::string_ext string(reinterpret_cast<char*>(0x4FFF600), 256);
static char* string = reinterpret_cast<char*>(0x4FFF600);
constexpr static size_t string_len = 255;
}; // namespace reg
void puts(const mtl::string_view& msg, level lvl) {
reg::string = msg;
size_t count = msg.length();
if (count > reg::string_len) { count = reg::string_len; }
// Must be copied manually because the MGBA string register does
// not allow copying in reverse (I think)
msg.copy(reg::string, count);
reg::flags = lvl | 0x100;
}