diff --git a/assert.h b/assert.h index ea38f1d..31896ea 100644 --- a/assert.h +++ b/assert.h @@ -1,20 +1,18 @@ #pragma once -#if defined(__dreamcast__) -#include "sh7091/serial.hpp" -#define print__character serial::character -#define print__string serial::string -#define print__integer serial::integer -#else -#error "unknown platform" -#endif +#include "printf/printf.h" + +#define print__character print_char +#define print__string print_cstring +#define print__integer print_integer #define assert(b) \ do { \ if (!(b)) { \ print__string(__FILE__); \ print__character(':'); \ - print__integer(__LINE__, ' '); \ + print__integer(__LINE__); \ + print__character(' '); \ print__string(__func__); \ print__string(": assertion failed: "); \ print__string(#b); \ diff --git a/printf/printf.c b/printf/printf.c index cf6e41a..f0a9f22 100644 --- a/printf/printf.c +++ b/printf/printf.c @@ -103,6 +103,13 @@ void print_cstring(const char * s) } } +void print_integer(const int n) +{ + char s[16]; + int offset = unparse_base10(s, n, 0, 0); + print_string(s, offset); +} + void _printf(const char * format, ...) { va_list args; @@ -121,7 +128,7 @@ void _printf(const char * format, ...) case FORMAT_BASE10_UNSIGNED: { uint32_t num = va_arg(args, uint32_t); - char s[10]; + char s[16]; int offset = unparse_base10_unsigned(s, num, ft.pad_length, ft.fill_char); print_string(s, offset); } @@ -129,7 +136,7 @@ void _printf(const char * format, ...) case FORMAT_BASE10: { int32_t num = va_arg(args, int32_t); - char s[10]; + char s[16]; int offset = unparse_base10(s, num, ft.pad_length, ft.fill_char); print_string(s, offset); } @@ -137,7 +144,7 @@ void _printf(const char * format, ...) case FORMAT_BASE10_64: { int64_t num = va_arg(args, int64_t); - char s[20]; + char s[16]; int offset = unparse_base10_64(s, num, ft.pad_length, ft.fill_char); print_string(s, offset); } @@ -151,7 +158,7 @@ void _printf(const char * format, ...) case FORMAT_BASE16: { uint32_t num = va_arg(args, uint32_t); - char s[8]; + char s[16]; int offset = unparse_base16(s, num, ft.pad_length, ft.fill_char); print_string(s, offset); } @@ -184,7 +191,7 @@ void _printf(const char * format, ...) print_string(s, offset); print_char('.'); int32_t fraction = (int32_t)((num - (float)whole) * 1000.0); - offset = unparse_base10_unsigned(s, fraction, 0, 0); + offset = unparse_base10_unsigned(s, fraction, 3, '0'); print_string(s, offset); } break; diff --git a/printf/printf.h b/printf/printf.h index ad80505..d19495f 100644 --- a/printf/printf.h +++ b/printf/printf.h @@ -25,6 +25,7 @@ void print_string(const char * s, int length); void print_bytes(const uint8_t * s, int length); void print_chars(const uint16_t * s, int length); void print_cstring(const char * s); +void print_integer(const int n); void _printf(const char * format, ...); diff --git a/xm/xm.h b/xm/xm.h index 912207a..b8bea65 100644 --- a/xm/xm.h +++ b/xm/xm.h @@ -4,6 +4,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct __attribute__((packed)) xm_header { int8_t id_text[17]; int8_t module_name[20]; @@ -139,3 +143,7 @@ static_assert((offsetof (struct xm_pattern_format, instrument)) == 1); static_assert((offsetof (struct xm_pattern_format, volume_column_byte)) == 2); static_assert((offsetof (struct xm_pattern_format, effect_type)) == 3); static_assert((offsetof (struct xm_pattern_format, effect_parameter)) == 4); + +#ifdef __cplusplus +} +#endif