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:
parent
86e92e42e5
commit
661fd32ba4
@ -31,11 +31,17 @@ static volatile uint16_t& flags = *reinterpret_cast<uint16_t*>(0x4FFF700);
|
|||||||
*
|
*
|
||||||
* Max length of 0x100 (256) including null terminator.
|
* 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
|
}; // namespace reg
|
||||||
|
|
||||||
void puts(const mtl::string_view& msg, level lvl) {
|
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;
|
reg::flags = lvl | 0x100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user