gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit b5e9f5e1c0279ea412a9c418dfdc9fbf1ea795d2 parent c4c174d593a7591b74b1ad1701a6b44843225297 Author: Toxa <untoxa@mail.ru> Date: Fri, 5 Apr 2024 16:14:28 +0300 refactor EMU_printf() - remove dependency from stdio.h (currently working in the Emulicious emu), add similar EMU_fmtbuf() Diffstat:
| M | gbdk-lib/examples/cross-platform/emu_debug/src/emu_debug.c | 2 | +- |
| M | gbdk-lib/include/gbdk/emu_debug.h | 17 | ++++++++++++++--- |
| M | gbdk-lib/libc/targets/sm83/emu_debug_printf.s | 57 | ++++++++++++++++++++++++++------------------------------- |
| M | gbdk-lib/libc/targets/z80/emu_debug_printf.s | 48 | ++++++++++++++++++------------------------------ |
4 files changed, 59 insertions(+), 65 deletions(-)
diff --git a/gbdk-lib/examples/cross-platform/emu_debug/src/emu_debug.c b/gbdk-lib/examples/cross-platform/emu_debug/src/emu_debug.c @@ -155,7 +155,7 @@ int main(void) uint8_t var0 = 16; int16_t var1 = -10; - EMU_printf("var0: %hd; var1: %d; var0*var1=%d", (uint8_t)var0, var1, var0 * var1); + EMU_printf("var0: %hd; var1: %d; var0*var1=%d\n", (uint8_t)var0, var1, var0 * var1); // The EMU_TEXT() macro will accept a non-quoted string EMU_TEXT("The End"); diff --git a/gbdk-lib/include/gbdk/emu_debug.h b/gbdk-lib/include/gbdk/emu_debug.h @@ -142,8 +142,6 @@ void EMU_profiler_message(void); @param format The format string as per printf Does not return the number of characters printed. - Result string MUST BE LESS OR EQUAL THAN 128 BYTES LONG, INCLUDING THE TRAILIG ZERO BYTE! - Currently supported: \li \%hx (char as hex) \li \%hu (unsigned char) @@ -157,10 +155,23 @@ void EMU_profiler_message(void); Warning: to correctly pass chars for printing as chars, they *must* be explicitly re-cast as such when calling the function. See @ref docs_chars_varargs for more details. + + Currently supported in the Emulicious emulator */ -void EMU_printf(const char *format, ...) OLDCALL; +void EMU_printf(const char *format, ...) PRESERVES_REGS(a, b, c); #define BGB_printf(...) EMU_printf(__VA_ARGS__) +/** Print the string and arguments in the buffer buffer by the pointer given by format to the emulator debug message window + + @param format The format string as per printf + @param data Buffer containing arguments, for example some struct + + @see EMU_printf for the format string description + + Currently supported in the Emulicious emulator +*/ +void EMU_fmtbuf(const unsigned char * format, void * data) PRESERVES_REGS(a, b, c); + #ifdef NINTENDO static void * __EMU_PROFILER_INIT = &EMU_profiler_message; #endif // NINTENDO diff --git a/gbdk-lib/libc/targets/sm83/emu_debug_printf.s b/gbdk-lib/libc/targets/sm83/emu_debug_printf.s @@ -3,41 +3,36 @@ .title "EMU_debug" .module EMU_debug - .globl _sprintf + .area _HOME - .area _DATA +;;void EMU_printf(const unsigned char * fmt, ...) +_EMU_printf:: + ldhl sp, #2 + ld d, h + ld e, l + inc de + inc de + ld a, (hl+) + ld h, (hl) + ld l, a -ret_save: - .ds 0x02 -printf_buffer: - .ds 0x80 + ld d, d + jr 1$ + .dw 0x6464 + .dw 0x0200 +1$: + ret - .area _HOME - - ;; EMU_printf(fmt, ...) -_EMU_printf:: - di - pop de - ld hl, #ret_save - ld (hl), e - inc hl - ld (hl), d - - ld de, #printf_buffer - push de - call _sprintf - pop hl +;;void EMU_fmtbuf(const unsigned char * fmt, void * data) +_EMU_fmtbuf:: + ld h, d + ld l, e + ld d, b + ld e, c - ld d,d + ld d, d jr 1$ .dw 0x6464 - .dw 0x0001 - .dw #printf_buffer - .dw 0 + .dw 0x0200 1$: - ld hl, #ret_save - ld a, (hl+) - ld h, (hl) - ld l, a - ei - jp (hl) + ret diff --git a/gbdk-lib/libc/targets/z80/emu_debug_printf.s b/gbdk-lib/libc/targets/z80/emu_debug_printf.s @@ -3,42 +3,30 @@ .title "EMU_debug" .module EMU_debug - .globl _sprintf - - .area _DATA - -ret_save: - .ds 0x02 -printf_buffer: - .ds 0x80 - .area _HOME - ;; EMU_printf(fmt, ...) +;;void EMU_printf(const unsigned char * fmt, ...) _EMU_printf:: - di - pop de - ld hl, #ret_save - ld (hl), e + ld hl, #2 + add hl, sp + ld e, (hl) + inc hl + ld d, (hl) inc hl - ld (hl), d + ex de, hl - ld de, #printf_buffer - push de - call _sprintf - pop hl + ld d, d + jr 1$ + .dw 0x6464 + .dw 0x0200 +1$: + ret - ld d,d +;;void EMU_fmtbuf(const unsigned char * fmt, void * data) +_EMU_fmtbuf:: + ld d, d jr 1$ .dw 0x6464 - .dw 0x0001 - .dw #printf_buffer - .dw 0 + .dw 0x0200 1$: - ld hl, #ret_save - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - ei - jp (hl) + ret
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.