diff --git a/examples/PoolBox/application/src/font_writer.cpp b/examples/PoolBox/application/src/font_writer.cpp index 0e0207b0..1ed59811 100644 --- a/examples/PoolBox/application/src/font_writer.cpp +++ b/examples/PoolBox/application/src/font_writer.cpp @@ -23,7 +23,7 @@ void font_writer_setup() { void font_writer_update() { auto state = JabyEngine::State::create(JabyEngine::Make::PositionI16(8, 8), wiggle_count); new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl\n", JabyEngine::GPU::Color24::Blue(), &wiggle); - new_font_writer.write(state, "Miau: %i", JabyEngine::GPU::Color24::Red(), &wiggle, 12345); + new_font_writer.write(state, "Mi%iau:", JabyEngine::GPU::Color24::Yellow(), &wiggle, 12345); if(timer.is_expired_for(50_ms)) { timer.reset(); diff --git a/include/stdarg.h b/include/stdarg.h index bbe0e00e..2b82ee31 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -4,5 +4,6 @@ typedef __builtin_va_list va_list; #define va_start __builtin_va_start #define va_end __builtin_va_end +#define next_arg __builtin_next_arg #endif // !__STDARG__H \ No newline at end of file diff --git a/support/src/FontWriter/src/font_writer.cpp b/support/src/FontWriter/src/font_writer.cpp index 5bef0f75..b848382e 100644 --- a/support/src/FontWriter/src/font_writer.cpp +++ b/support/src/FontWriter/src/font_writer.cpp @@ -4,6 +4,30 @@ #include namespace JabyEngine { + static const char* simple_itoa(char (&buffer)[32], int value, int base) { + const bool is_neg = value < 0; + int i = 32 - 2; + + if(is_neg) { + value *= -1; + } + + for(; value && i; i--, value /= base) { + char chr = '0' + value%base; + if(chr > '9') { + chr += ('A' - '9'); + } + buffer[i] = chr; + } + + buffer[32 - 1] = '\0'; + if(is_neg) { + buffer[i] = '-'; + return &buffer[i]; + } + return &buffer[i+1]; + } + void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) { this->prim_buffer = buffer_info; this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked(); @@ -39,12 +63,19 @@ namespace JabyEngine { state.pos.move(primitive->size.width, 0); return true; }; - const auto old_x = state.pos.x; + const auto old_x = state.pos.x; + const char* prev_str = nullptr; + char buffer[32]; while(true) { - const auto cur_char = *str++; + auto cur_char = *str++; switch(cur_char) { case '\0': + if(prev_str) { + str = prev_str; + prev_str = nullptr; + continue; + } return; case '\n': @@ -56,6 +87,18 @@ namespace JabyEngine { state.pos.x += font_size.width; continue; + case '%': + switch(*str) { + case 'i': + prev_str = str + 1; + str = simple_itoa(buffer, -505, 10); + continue; + + case '%': + str++; + break; + } + default: auto& primitive = *this->cur_primitive++; if(!push_char(state, primitive, cur_char)) {