git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 6e02cc37f8dcd2eea2b66d841671606735cca8fb
parent 15540103061a591ca7db8bd12169047ffeb57f60
Author: bbbbbr <bbbbbr@users.noreply.github.com>
Date:   Thu, 27 Jan 2022 23:13:06 -0800

Merge pull request #309 from bbbbbr/emu_debug

Change BGB_DEBUG functions and examples to generic EMU_DEBUG
Diffstat:
Mdocs/pages/04_coding_guidelines.md2+-
Mdocs/pages/09_migrating_new_versions.md6+++---
Mdocs/pages/10_release_notes.md4+++-
Dgbdk-lib/examples/ap/bgb_debug/Makefile17-----------------
Dgbdk-lib/examples/ap/bgb_debug/bgb_debug.c147-------------------------------------------------------------------------------
Agbdk-lib/examples/ap/emu_debug/Makefile17+++++++++++++++++
Agbdk-lib/examples/ap/emu_debug/emu_debug.c147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/examples/ap/lcd_isr_wobble/lcd_isr_wobble.c2+-
Mgbdk-lib/examples/ap/scroller/text_scroller.c2+-
Dgbdk-lib/examples/gb/bgb_debug/Makefile17-----------------
Dgbdk-lib/examples/gb/bgb_debug/bgb_debug.c147-------------------------------------------------------------------------------
Agbdk-lib/examples/gb/emu_debug/Makefile17+++++++++++++++++
Agbdk-lib/examples/gb/emu_debug/emu_debug.c147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/examples/gb/lcd_isr_wobble/lcd_isr_wobble.c2+-
Mgbdk-lib/examples/gb/scroller/text_scroller.c2+-
Mgbdk-lib/include/gb/bgb_emu.h150+++----------------------------------------------------------------------------
Agbdk-lib/include/gb/emu_debug.h161+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/targets/gbz80/ap/Makefile2+-
Mgbdk-lib/libc/targets/gbz80/ap/crt0.s2+-
Dgbdk-lib/libc/targets/gbz80/bgb_emu.s20--------------------
Dgbdk-lib/libc/targets/gbz80/bgb_emu_printf.s43-------------------------------------------
Mgbdk-lib/libc/targets/gbz80/duck/Makefile2+-
Mgbdk-lib/libc/targets/gbz80/duck/crt0.s2+-
Agbdk-lib/libc/targets/gbz80/emu_debug.s20++++++++++++++++++++
Agbdk-lib/libc/targets/gbz80/emu_debug_printf.s43+++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/targets/gbz80/gb/Makefile2+-
Mgbdk-lib/libc/targets/gbz80/gb/crt0.s2+-
27 files changed, 574 insertions(+), 551 deletions(-)

diff --git a/docs/pages/04_coding_guidelines.md b/docs/pages/04_coding_guidelines.md @@ -182,7 +182,7 @@ For example: printf("%hx %hx", (unsigned char)i, (unsigned char)i); Some functions that accept varargs: - - @ref BGB_printf, @ref gprintf(), @ref printf(), @ref sprintf() + - @ref EMU_printf, @ref gprintf(), @ref printf(), @ref sprintf() Also See: - Other cases of char to int promotion: http://sdcc.sourceforge.net/doc/sdccman.pdf#chapter.6 diff --git a/docs/pages/09_migrating_new_versions.md b/docs/pages/09_migrating_new_versions.md @@ -5,7 +5,8 @@ This section contains information that may be useful to know or important when u # GBDK 2020 versions ## Porting to GBDK 2020 4.0.6 - - No significant changes required + - Renamed `bgb_emu.h` to `emu_debug.h` and BGB_* functions to EMU_* + - Aliases for the BGB_* ones and a `bgb_emu.h` shim are present for backward compatibility, but updating to the new naming is recommended ## Porting to GBDK 2020 4.0.5 @@ -19,8 +20,7 @@ This section contains information that may be useful to know or important when u - set_bkg_1bit_data has been renamed to @ref set_bkg_1bpp_data - The following header files which are now cross platform were moved from `gb/` to `gbdk/`: `bcd.h`, `console.h`, `far_ptr.h`, `font.h`, `gbdecompress.h`, `gbdk-lib.h`, `incbin.h`, `metasprites.h`, `platform.h`, `version.h` - When including them use `#include <gbdk/...>` instead of `#include <gb/>` - - + ## Porting to GBDK 2020 4.0.4 - GBDK now requires SDCC 12238 or higher - Made sample.h, cgb.h and sgb.h independent from gb.h diff --git a/docs/pages/10_release_notes.md b/docs/pages/10_release_notes.md @@ -21,6 +21,8 @@ https://github.com/gbdk-2020/gbdk-2020/releases - `#define AT(A) __at(A)` - Added check for OAM overflow to metasprite calls for GB/CGB - Added constant definitions @ref PSG_LATCH, @ref PSG_CH0, @ref PSG_CH1, @ref PSG_CH2, @ref PSG_CH3, @ref PSG_VOLUME for SMS/GG + - Renamed `bgb_emu.h` to `emu_debug.h` and BGB_* functions to EMU_*. + - Aliases for the BGB_* ones and a `bgb_emu.h` shim are present for backward compatibility - Changed headers to wrap SDCC specific features (such as `NONBANKED`) with `#ifdef __SDCC` - Changed @ref rand() and @ref arand() to return `uint8_t` instead of `int8_t` (closer to the standard) - Fixed declaration for @ref PCM_SAMPLE and definition for @ref AUD3WAVE @@ -72,7 +74,7 @@ https://github.com/gbdk-2020/gbdk-2020/releases - Added @ref BANK(), @ref BANKREF(), @ref BANKREF_EXTERN() - Added @ref INCBIN(), @ref BANK(), @ref INCBIN_SIZE(), @ref INCBIN_EXTERN() - Added generic @ref SWITCH_ROM() and @ref SWITCH_RAM() - - Added @ref BGB_printf() and updated bgb debug output. + - Added @ref BGB_printf() and updated emulator debug output. - Added @ref set_native_tile_data(), @ref set_tile_map(), @ref set_1bpp_colors, @ref set_bkg_1bpp_data, @ref set_sprite_1bpp_data, @ref set_2bpp_palette, @ref set_bkg_2bpp_data, @ref set_sprite_2bpp_data, @ref set_tile_2bpp_data (sms/gg only), @ref set_bkg_4bpp_data (sms/gg only), @ref set_sprite_4bpp_data (sms/gg only) - Added RLE decompression support: @ref rle_init(), @ref rle_decompress(), - Changed @ref itoa(), @ref uitoa(), @ref ltoa(), @ref ultoa() to now require a radix value (base) argument to be passed. On the Game Boy and Analogue Pocket the parameter is required but not utilized. diff --git a/gbdk-lib/examples/ap/bgb_debug/Makefile b/gbdk-lib/examples/ap/bgb_debug/Makefile @@ -1,17 +0,0 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS -Wm-yc - -BINS = bgb_debug.pocket - -all: $(BINS) - -compile.bat: Makefile - @echo "REM Automatically generated from Makefile" > compile.bat - @make -sn | sed y/\\//\\\\/ | grep -v make >> compile.bat - -# Compile and link single file in one pass -%.pocket: %.c - $(CC) -o $@ $< - -clean: - rm -f *.o *.lst *.map *.pocket *~ *.rel *.cdb *.ihx *.lnk *.sym *.asm *.noi - diff --git a/gbdk-lib/examples/ap/bgb_debug/bgb_debug.c b/gbdk-lib/examples/ap/bgb_debug/bgb_debug.c @@ -1,147 +0,0 @@ -#include <gb/gb.h> -#include <stdint.h> -#include <stdio.h> // Just for printf() -#include <gb/cgb.h> // Just for the cpu_fast()/slow() calls in CGB 2x example - -#include <gb/bgb_emu.h> // Use this include to add the BGB functions - - -// This example shows how to use support for profiling -// and logging to the debug window in the BGB emulator. -// -// 1. Build this ROM (bgb_debug.gb) then load it in the BGB emulator -// 2. Open the internal BGB debugger by pressing the "ESC" key -// 3. From the debugger menu choose "debug messages" to open the debug messages window -// 4. Reset the gameboy (you may need to press F9 in the debugger to resume running) -// 5. The debug window will show the BGB messages -// -// See the BGB Manual for more information -// ("expressions, breakpoint conditions, and debug messages") -// https://bgb.bircd.org/manual.html#expressions - -int main(void) -{ - int c; - - SHOW_BKG; - DISPLAY_ON; - enable_interrupts(); - - // Display a message on the GameBoy's screen - printf("Message to the \nGameBoy screen\n"); - - // Log a message to the BGB debug message window - BGB_MESSAGE(""); // new line - BGB_MESSAGE("Message to the BGB console"); - - // ==== Normal Speed Mode ==== - // Profile code: a single NOP instruction - // - // In BGB the clock units are "1 nop in [CGB] doublespeed mode". - // So when *not* running in CGB doublespeed mode you - // have to divide by 2 to get the correct cycle count. - // - // You should see the message "NOP TIME: 2". - // - // So in this case, divide the printed value by 2 = The NOP took "1" cycle - - __critical { // Temporarily turn off interrupts for more accurate measurements - BGB_PROFILE_BEGIN("Profile a single NOP instruction at Normal Speed"); - __asm__("nop"); - BGB_PROFILE_END("NOP TIME:"); - } - - - // ==== Color Game Boy in Double Speed Mode ==== - // Profile code: a single NOP instruction - // - // The BGB_PROFILE_BEGIN/END macros don't support the - // Color Game Boy (CGB) in double speed mode (cpu_fast()). - // The example below shows what to use instead (and how to - // check for a CGB and turn on Double Speed mode). - // - // Check and only run this test if on CGB hardware - if (DEVICE_SUPPORTS_COLOR) { - - // Set CGB into double speed mode - // (Requires passing -Wm-yc or -Wm-yC with Lcc during build time) - cpu_fast(); - // Set some default DMG styled colors in the CGB Palette - set_default_palette(); - - // In CGB Double Speed mode, you don't have to - // divide by 2 to get the cycle count. - // - // You should see the message "NOP TIME: 1". - - __critical { // Temporarily turn off interrupts for more accurate measurements - BGB_PROFILE_BEGIN("Profile a single NOP instruction at CGB Double Speed"); - __asm__("nop"); - // The "-4+" subtracts 4 clocks to compensate for the ones - // used by the debug message itself (Normal speed uses -8) - BGB_MESSAGE("NOP TIME:%-4+LASTCLKS%"); - } - - // Return the CGB to normal speed - cpu_slow(); - } - - - __critical { // Temporarily turn off interrupts for more accurate measurements - - // Profile code in a loop - BGB_PROFILE_BEGIN("Profile code in a loop"); - for(c=0; c<5; c++) { - // Do something - printf("%d\n", c); - } - // Elapsed cycle count output is in hex. - // Remember to divide by 2 for the result (Normal Speed) - BGB_PROFILE_END("LOOP TIME:"); - } - - - // ==== Some other things you can print ==== - - // TOTALCLKS shows the clocks counter ("internal divider") in the BGB IO map - BGB_MESSAGE("Total Clocks: %TOTALCLKS%"); - - // CLKS2VBLANK - BGB_MESSAGE("Clocks until VBLANK: %CLKS2VBLANK%"); - - // Which Banks are currently active (for MBC based cartridges) - BGB_MESSAGE("Current ROM bank: %ROMBANK%"); - BGB_MESSAGE("Current SRAM bank: %SRAMBANK%"); - // These are only banked in the CGB - BGB_MESSAGE("Current VRAM bank: %VRAMBANK%"); - BGB_MESSAGE("Current WRAM bank: %WRAMBANK%"); - - // Registers (All in this case, or individual ones) - BGB_MESSAGE("All Registers: %ALLREGS%"); - - // Simple addition with a register - BGB_MESSAGE("Register A + 1: %(A+1)%"); - - // Read the LY Register a couple times - // (Current Y coordinate being rendered to the LCD) - BGB_MESSAGE("LY Register (0xFF44): %($ff44)%"); - BGB_MESSAGE("LY Register (0xFF44): %($ff44)%"); - // Now print a conditional debug message using it - BGB_MESSAGE("Is LY Register > Line 67: %($ff44)>67%Yes;No;"); - - // Print some profile info using a built-in function. - BGB_MESSAGE("The following lines contain: PROFILE,(SP+$0),(SP+$1),A,TOTALCLKS,ROMBANK,WRAMBANK"); - BGB_profiler_message(); - // It's equivalent to: - BGB_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); - - uint8_t var0 = 16; - int16_t var1 = -10; - // - BGB_printf("var0: %hd; var1: %d; var0*var1=%d", (uint8_t)var0, var1, var0 * var1); - - // The BGB_TEXT() macro will accept a non-quoted string - BGB_TEXT("The End"); - - return 0; -} diff --git a/gbdk-lib/examples/ap/emu_debug/Makefile b/gbdk-lib/examples/ap/emu_debug/Makefile @@ -0,0 +1,17 @@ +CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS -Wm-yc + +BINS = emu_debug.pocket + +all: $(BINS) + +compile.bat: Makefile + @echo "REM Automatically generated from Makefile" > compile.bat + @make -sn | sed y/\\//\\\\/ | grep -v make >> compile.bat + +# Compile and link single file in one pass +%.pocket: %.c + $(CC) -o $@ $< + +clean: + rm -f *.o *.lst *.map *.pocket *~ *.rel *.cdb *.ihx *.lnk *.sym *.asm *.noi + diff --git a/gbdk-lib/examples/ap/emu_debug/emu_debug.c b/gbdk-lib/examples/ap/emu_debug/emu_debug.c @@ -0,0 +1,147 @@ +#include <gb/gb.h> +#include <stdint.h> +#include <stdio.h> // Just for printf() +#include <gb/cgb.h> // Just for the cpu_fast()/slow() calls in CGB 2x example + +#include <gb/emu_debug.h> // Use this include to add the Emu debug functions + + +// This example shows how to use support for profiling +// and logging to the debug window in the emulator (BGB or Emulicious). +// +// 1. Build this ROM (emu_debug.gb) then load it in the emulator (BGB or Emulicious) +// 2. Open the internal debugger by pressing the "ESC" or "F1" key +// 3. From the debugger menu choose "debug messages" to open the debug messages window +// 4. Reset the gameboy (you may need to press F9 in the debugger to resume running) +// 5. The debug window will show the debug messages +// +// See the BGB Manual for more information +// ("expressions, breakpoint conditions, and debug messages") +// https://bgb.bircd.org/manual.html#expressions + +int main(void) +{ + int c; + + SHOW_BKG; + DISPLAY_ON; + enable_interrupts(); + + // Display a message on the GameBoy's screen + printf("Message to the \nGameBoy screen\n"); + + // Log a message to the Emulator debug message window + EMU_MESSAGE(""); // new line + EMU_MESSAGE("Message to the EMU console"); + + // ==== Normal Speed Mode ==== + // Profile code: a single NOP instruction + // + // The clock units are "1 nop in [CGB] doublespeed mode". + // So when *not* running in CGB doublespeed mode you + // have to divide by 2 to get the correct cycle count. + // + // You should see the message "NOP TIME: 2". + // + // So in this case, divide the printed value by 2 = The NOP took "1" cycle + + __critical { // Temporarily turn off interrupts for more accurate measurements + EMU_PROFILE_BEGIN("Profile a single NOP instruction at Normal Speed"); + __asm__("nop"); + EMU_PROFILE_END("NOP TIME:"); + } + + + // ==== Color Game Boy in Double Speed Mode ==== + // Profile code: a single NOP instruction + // + // The EMU_PROFILE_BEGIN/END macros don't support the + // Color Game Boy (CGB) in double speed mode (cpu_fast()). + // The example below shows what to use instead (and how to + // check for a CGB and turn on Double Speed mode). + // + // Check and only run this test if on CGB hardware + if (DEVICE_SUPPORTS_COLOR) { + + // Set CGB into double speed mode + // (Requires passing -Wm-yc or -Wm-yC with Lcc during build time) + cpu_fast(); + // Set some default DMG styled colors in the CGB Palette + set_default_palette(); + + // In CGB Double Speed mode, you don't have to + // divide by 2 to get the cycle count. + // + // You should see the message "NOP TIME: 1". + + __critical { // Temporarily turn off interrupts for more accurate measurements + EMU_PROFILE_BEGIN("Profile a single NOP instruction at CGB Double Speed"); + __asm__("nop"); + // The "-4+" subtracts 4 clocks to compensate for the ones + // used by the debug message itself (Normal speed uses -8) + EMU_MESSAGE("NOP TIME:%-4+LASTCLKS%"); + } + + // Return the CGB to normal speed + cpu_slow(); + } + + + __critical { // Temporarily turn off interrupts for more accurate measurements + + // Profile code in a loop + EMU_PROFILE_BEGIN("Profile code in a loop"); + for(c=0; c<5; c++) { + // Do something + printf("%d\n", c); + } + // Elapsed cycle count output is in hex. + // Remember to divide by 2 for the result (Normal Speed) + EMU_PROFILE_END("LOOP TIME:"); + } + + + // ==== Some other things you can print ==== + + // TOTALCLKS shows the clocks counter ("internal divider") in the BGB IO map + EMU_MESSAGE("Total Clocks: %TOTALCLKS%"); + + // CLKS2VBLANK + EMU_MESSAGE("Clocks until VBLANK: %CLKS2VBLANK%"); + + // Which Banks are currently active (for MBC based cartridges) + EMU_MESSAGE("Current ROM bank: %ROMBANK%"); + EMU_MESSAGE("Current SRAM bank: %SRAMBANK%"); + // These are only banked in the CGB + EMU_MESSAGE("Current VRAM bank: %VRAMBANK%"); + EMU_MESSAGE("Current WRAM bank: %WRAMBANK%"); + + // Registers (All in this case, or individual ones) + EMU_MESSAGE("All Registers: %ALLREGS%"); + + // Simple addition with a register + EMU_MESSAGE("Register A + 1: %(A+1)%"); + + // Read the LY Register a couple times + // (Current Y coordinate being rendered to the LCD) + EMU_MESSAGE("LY Register (0xFF44): %($ff44)%"); + EMU_MESSAGE("LY Register (0xFF44): %($ff44)%"); + // Now print a conditional debug message using it + EMU_MESSAGE("Is LY Register > Line 67: %($ff44)>67%Yes;No;"); + + // Print some profile info using a built-in function. + EMU_MESSAGE("The following lines contain: PROFILE,(SP+$0),(SP+$1),A,TOTALCLKS,ROMBANK,WRAMBANK"); + EMU_profiler_message(); + // It's equivalent to: + EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); + + uint8_t var0 = 16; + int16_t var1 = -10; + // + EMU_printf("var0: %hd; var1: %d; var0*var1=%d", (uint8_t)var0, var1, var0 * var1); + + // The EMU_TEXT() macro will accept a non-quoted string + EMU_TEXT("The End"); + + return 0; +} diff --git a/gbdk-lib/examples/ap/lcd_isr_wobble/lcd_isr_wobble.c b/gbdk-lib/examples/ap/lcd_isr_wobble/lcd_isr_wobble.c @@ -2,7 +2,7 @@ #include <stdint.h> #include <stdio.h> -#include <gb/bgb_emu.h> +#include <gb/emu_debug.h> const uint8_t scanline_offsets_tbl[] = {0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0}; const uint8_t * scanline_offsets = scanline_offsets_tbl; diff --git a/gbdk-lib/examples/ap/scroller/text_scroller.c b/gbdk-lib/examples/ap/scroller/text_scroller.c @@ -2,7 +2,7 @@ #include <stdint.h> #include <stdio.h> -#include <gb/bgb_emu.h> +#include <gb/emu_debug.h> const uint8_t scanline_offsets_tbl[] = {0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0}; const uint8_t * scanline_offsets = scanline_offsets_tbl; diff --git a/gbdk-lib/examples/gb/bgb_debug/Makefile b/gbdk-lib/examples/gb/bgb_debug/Makefile @@ -1,17 +0,0 @@ -CC = ../../../bin/lcc -Wl-m -Wl-j -Wm-yS -Wm-yc - -BINS = bgb_debug.gb - -all: $(BINS) - -compile.bat: Makefile - @echo "REM Automatically generated from Makefile" > compile.bat - @make -sn | sed y/\\//\\\\/ | grep -v make >> compile.bat - -# Compile and link single file in one pass -%.gb: %.c - $(CC) -o $@ $< - -clean: - rm -f *.o *.lst *.map *.gb *~ *.rel *.cdb *.ihx *.lnk *.sym *.asm *.noi - diff --git a/gbdk-lib/examples/gb/bgb_debug/bgb_debug.c b/gbdk-lib/examples/gb/bgb_debug/bgb_debug.c @@ -1,147 +0,0 @@ -#include <gb/gb.h> -#include <stdint.h> -#include <stdio.h> // Just for printf() -#include <gb/cgb.h> // Just for the cpu_fast()/slow() calls in CGB 2x example - -#include <gb/bgb_emu.h> // Use this include to add the BGB functions - - -// This example shows how to use support for profiling -// and logging to the debug window in the BGB emulator. -// -// 1. Build this ROM (bgb_debug.gb) then load it in the BGB emulator -// 2. Open the internal BGB debugger by pressing the "ESC" key -// 3. From the debugger menu choose "debug messages" to open the debug messages window -// 4. Reset the gameboy (you may need to press F9 in the debugger to resume running) -// 5. The debug window will show the BGB messages -// -// See the BGB Manual for more information -// ("expressions, breakpoint conditions, and debug messages") -// https://bgb.bircd.org/manual.html#expressions - -int main(void) -{ - int c; - - SHOW_BKG; - DISPLAY_ON; - enable_interrupts(); - - // Display a message on the GameBoy's screen - printf("Message to the \nGameBoy screen\n"); - - // Log a message to the BGB debug message window - BGB_MESSAGE(""); // new line - BGB_MESSAGE("Message to the BGB console"); - - // ==== Normal Speed Mode ==== - // Profile code: a single NOP instruction - // - // In BGB the clock units are "1 nop in [CGB] doublespeed mode". - // So when *not* running in CGB doublespeed mode you - // have to divide by 2 to get the correct cycle count. - // - // You should see the message "NOP TIME: 2". - // - // So in this case, divide the printed value by 2 = The NOP took "1" cycle - - __critical { // Temporarily turn off interrupts for more accurate measurements - BGB_PROFILE_BEGIN("Profile a single NOP instruction at Normal Speed"); - __asm__("nop"); - BGB_PROFILE_END("NOP TIME:"); - } - - - // ==== Color Game Boy in Double Speed Mode ==== - // Profile code: a single NOP instruction - // - // The BGB_PROFILE_BEGIN/END macros don't support the - // Color Game Boy (CGB) in double speed mode (cpu_fast()). - // The example below shows what to use instead (and how to - // check for a CGB and turn on Double Speed mode). - // - // Check and only run this test if on CGB hardware - if (DEVICE_SUPPORTS_COLOR) { - - // Set CGB into double speed mode - // (Requires passing -Wm-yc or -Wm-yC with Lcc during build time) - cpu_fast(); - // Set some default DMG styled colors in the CGB Palette - set_default_palette(); - - // In CGB Double Speed mode, you don't have to - // divide by 2 to get the cycle count. - // - // You should see the message "NOP TIME: 1". - - __critical { // Temporarily turn off interrupts for more accurate measurements - BGB_PROFILE_BEGIN("Profile a single NOP instruction at CGB Double Speed"); - __asm__("nop"); - // The "-4+" subtracts 4 clocks to compensate for the ones - // used by the debug message itself (Normal speed uses -8) - BGB_MESSAGE("NOP TIME:%-4+LASTCLKS%"); - } - - // Return the CGB to normal speed - cpu_slow(); - } - - - __critical { // Temporarily turn off interrupts for more accurate measurements - - // Profile code in a loop - BGB_PROFILE_BEGIN("Profile code in a loop"); - for(c=0; c<5; c++) { - // Do something - printf("%d\n", c); - } - // Elapsed cycle count output is in hex. - // Remember to divide by 2 for the result (Normal Speed) - BGB_PROFILE_END("LOOP TIME:"); - } - - - // ==== Some other things you can print ==== - - // TOTALCLKS shows the clocks counter ("internal divider") in the BGB IO map - BGB_MESSAGE("Total Clocks: %TOTALCLKS%"); - - // CLKS2VBLANK - BGB_MESSAGE("Clocks until VBLANK: %CLKS2VBLANK%"); - - // Which Banks are currently active (for MBC based cartridges) - BGB_MESSAGE("Current ROM bank: %ROMBANK%"); - BGB_MESSAGE("Current SRAM bank: %SRAMBANK%"); - // These are only banked in the CGB - BGB_MESSAGE("Current VRAM bank: %VRAMBANK%"); - BGB_MESSAGE("Current WRAM bank: %WRAMBANK%"); - - // Registers (All in this case, or individual ones) - BGB_MESSAGE("All Registers: %ALLREGS%"); - - // Simple addition with a register - BGB_MESSAGE("Register A + 1: %(A+1)%"); - - // Read the LY Register a couple times - // (Current Y coordinate being rendered to the LCD) - BGB_MESSAGE("LY Register (0xFF44): %($ff44)%"); - BGB_MESSAGE("LY Register (0xFF44): %($ff44)%"); - // Now print a conditional debug message using it - BGB_MESSAGE("Is LY Register > Line 67: %($ff44)>67%Yes;No;"); - - // Print some profile info using a built-in function. - BGB_MESSAGE("The following lines contain: PROFILE,(SP+$0),(SP+$1),A,TOTALCLKS,ROMBANK,WRAMBANK"); - BGB_profiler_message(); - // It's equivalent to: - BGB_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); - - uint8_t var0 = 16; - int16_t var1 = -10; - // - BGB_printf("var0: %hd; var1: %d; var0*var1=%d", (uint8_t)var0, var1, var0 * var1); - - // The BGB_TEXT() macro will accept a non-quoted string - BGB_TEXT("The End"); - - return 0; -} diff --git a/gbdk-lib/examples/gb/emu_debug/Makefile b/gbdk-lib/examples/gb/emu_debug/Makefile @@ -0,0 +1,17 @@ +CC = ../../../bin/lcc -Wl-m -Wl-j -Wm-yS -Wm-yc + +BINS = emu_debug.gb + +all: $(BINS) + +compile.bat: Makefile + @echo "REM Automatically generated from Makefile" > compile.bat + @make -sn | sed y/\\//\\\\/ | grep -v make >> compile.bat + +# Compile and link single file in one pass +%.gb: %.c + $(CC) -o $@ $< + +clean: + rm -f *.o *.lst *.map *.gb *~ *.rel *.cdb *.ihx *.lnk *.sym *.asm *.noi + diff --git a/gbdk-lib/examples/gb/emu_debug/emu_debug.c b/gbdk-lib/examples/gb/emu_debug/emu_debug.c @@ -0,0 +1,147 @@ +#include <gb/gb.h> +#include <stdint.h> +#include <stdio.h> // Just for printf() +#include <gb/cgb.h> // Just for the cpu_fast()/slow() calls in CGB 2x example + +#include <gb/emu_debug.h> // Use this include to add the Emu debug functions + + +// This example shows how to use support for profiling +// and logging to the debug window in the emulator (BGB or Emulicious). +// +// 1. Build this ROM (emu_debug.gb) then load it in the emulator (BGB or Emulicious) +// 2. Open the internal debugger by pressing the "ESC" or "F1" key +// 3. From the debugger menu choose "debug messages" to open the debug messages window +// 4. Reset the gameboy (you may need to press F9 in the debugger to resume running) +// 5. The debug window will show the debug messages +// +// See the BGB Manual for more information +// ("expressions, breakpoint conditions, and debug messages") +// https://bgb.bircd.org/manual.html#expressions + +int main(void) +{ + int c; + + SHOW_BKG; + DISPLAY_ON; + enable_interrupts(); + + // Display a message on the GameBoy's screen + printf("Message to the \nGameBoy screen\n"); + + // Log a message to the Emulator debug message window + EMU_MESSAGE(""); // new line + EMU_MESSAGE("Message to the EMU console"); + + // ==== Normal Speed Mode ==== + // Profile code: a single NOP instruction + // + // The clock units are "1 nop in [CGB] doublespeed mode". + // So when *not* running in CGB doublespeed mode you + // have to divide by 2 to get the correct cycle count. + // + // You should see the message "NOP TIME: 2". + // + // So in this case, divide the printed value by 2 = The NOP took "1" cycle + + __critical { // Temporarily turn off interrupts for more accurate measurements + EMU_PROFILE_BEGIN("Profile a single NOP instruction at Normal Speed"); + __asm__("nop"); + EMU_PROFILE_END("NOP TIME:"); + } + + + // ==== Color Game Boy in Double Speed Mode ==== + // Profile code: a single NOP instruction + // + // The EMU_PROFILE_BEGIN/END macros don't support the + // Color Game Boy (CGB) in double speed mode (cpu_fast()). + // The example below shows what to use instead (and how to + // check for a CGB and turn on Double Speed mode). + // + // Check and only run this test if on CGB hardware + if (DEVICE_SUPPORTS_COLOR) { + + // Set CGB into double speed mode + // (Requires passing -Wm-yc or -Wm-yC with Lcc during build time) + cpu_fast(); + // Set some default DMG styled colors in the CGB Palette + set_default_palette(); + + // In CGB Double Speed mode, you don't have to + // divide by 2 to get the cycle count. + // + // You should see the message "NOP TIME: 1". + + __critical { // Temporarily turn off interrupts for more accurate measurements + EMU_PROFILE_BEGIN("Profile a single NOP instruction at CGB Double Speed"); + __asm__("nop"); + // The "-4+" subtracts 4 clocks to compensate for the ones + // used by the debug message itself (Normal speed uses -8) + EMU_MESSAGE("NOP TIME:%-4+LASTCLKS%"); + } + + // Return the CGB to normal speed + cpu_slow(); + } + + + __critical { // Temporarily turn off interrupts for more accurate measurements + + // Profile code in a loop + EMU_PROFILE_BEGIN("Profile code in a loop"); + for(c=0; c<5; c++) { + // Do something + printf("%d\n", c); + } + // Elapsed cycle count output is in hex. + // Remember to divide by 2 for the result (Normal Speed) + EMU_PROFILE_END("LOOP TIME:"); + } + + + // ==== Some other things you can print ==== + + // TOTALCLKS shows the clocks counter ("internal divider") in the BGB IO map + EMU_MESSAGE("Total Clocks: %TOTALCLKS%"); + + // CLKS2VBLANK + EMU_MESSAGE("Clocks until VBLANK: %CLKS2VBLANK%"); + + // Which Banks are currently active (for MBC based cartridges) + EMU_MESSAGE("Current ROM bank: %ROMBANK%"); + EMU_MESSAGE("Current SRAM bank: %SRAMBANK%"); + // These are only banked in the CGB + EMU_MESSAGE("Current VRAM bank: %VRAMBANK%"); + EMU_MESSAGE("Current WRAM bank: %WRAMBANK%"); + + // Registers (All in this case, or individual ones) + EMU_MESSAGE("All Registers: %ALLREGS%"); + + // Simple addition with a register + EMU_MESSAGE("Register A + 1: %(A+1)%"); + + // Read the LY Register a couple times + // (Current Y coordinate being rendered to the LCD) + EMU_MESSAGE("LY Register (0xFF44): %($ff44)%"); + EMU_MESSAGE("LY Register (0xFF44): %($ff44)%"); + // Now print a conditional debug message using it + EMU_MESSAGE("Is LY Register > Line 67: %($ff44)>67%Yes;No;"); + + // Print some profile info using a built-in function. + EMU_MESSAGE("The following lines contain: PROFILE,(SP+$0),(SP+$1),A,TOTALCLKS,ROMBANK,WRAMBANK"); + EMU_profiler_message(); + // It's equivalent to: + EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); + + uint8_t var0 = 16; + int16_t var1 = -10; + // + EMU_printf("var0: %hd; var1: %d; var0*var1=%d", (uint8_t)var0, var1, var0 * var1); + + // The EMU_TEXT() macro will accept a non-quoted string + EMU_TEXT("The End"); + + return 0; +} diff --git a/gbdk-lib/examples/gb/lcd_isr_wobble/lcd_isr_wobble.c b/gbdk-lib/examples/gb/lcd_isr_wobble/lcd_isr_wobble.c @@ -2,7 +2,7 @@ #include <stdint.h> #include <stdio.h> -#include <gb/bgb_emu.h> +#include <gb/emu_debug.h> const uint8_t scanline_offsets_tbl[] = {0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0}; const uint8_t * scanline_offsets = scanline_offsets_tbl; diff --git a/gbdk-lib/examples/gb/scroller/text_scroller.c b/gbdk-lib/examples/gb/scroller/text_scroller.c @@ -2,7 +2,7 @@ #include <stdint.h> #include <stdio.h> -#include <gb/bgb_emu.h> +#include <gb/emu_debug.h> const uint8_t scanline_offsets_tbl[] = {0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0}; const uint8_t * scanline_offsets = scanline_offsets_tbl; diff --git a/gbdk-lib/include/gb/bgb_emu.h b/gbdk-lib/include/gb/bgb_emu.h @@ -1,152 +1,13 @@ /** @file gb/bgb_emu.h - Debug window logging and profiling support for the BGB emulator. - - Also see the `bgb_debug` example project included with gbdk. - - See the BGB Manual for more information - ("expressions, breakpoint conditions, and debug messages") - http://bgb.bircd.org/manual.html#expressions + Shim for legacy use of @ref bgb_emu.h which has been + migrated to @ref emu_debug.h + See the `emu_debug` example project included with gbdk. */ #ifndef __BGB_EMU_INCLUDE #define __BGB_EMU_INCLUDE -#include <types.h> - -/** Macro to display a message in the BGB emulator debug message window - - @param message_text Quoted text string to display in the debug message window - - The following special parameters can be - used when bracketed with "%" characters. - \li CPU registers: AF, BC, DE, HL, SP, PC, B, C, D, - E, H, L, A, ZERO, ZF, Z, CARRY, CY, IME, ALLREGS - \li Other state values: ROMBANK, XRAMBANK, SRAMBANK, - WRAMBANK, VRAMBANK, TOTALCLKS, LASTCLKS, CLKS2VBLANK - - Example: print a message along with the currently active ROM bank. - \code{.c} - BGB_MESSAGE("Current ROM Bank is: %ROMBANK%"); - \endcode - - - See the BGB Manual for more information - ("expressions, breakpoint conditions, and debug messages") - http://bgb.bircd.org/manual.html#expressions - - @see BGB_PROFILE_BEGIN(), BGB_PROFILE_END() - */ -#define BGB_MESSAGE(message_text) BGB_MESSAGE1(BGB_MACRONAME(__LINE__), message_text) -/// \cond DOXYGEN_DO_NOT_DOCUMENT -#define BGB_MACRONAME(A) BGB_MACRONAME1(A) -#define BGB_MACRONAME1(A) BGBLOG##A - -#define BGB_MESSAGE1(name, message_text) \ -__asm \ -.MACRO name msg_t, ?llbl\ - ld d, d \ - jr llbl \ - .dw 0x6464 \ - .dw 0x0000 \ - .ascii msg_t \ -llbl: \ -.ENDM \ -name ^/message_text/ \ -__endasm - -#define BGB_MESSAGE_SUFFIX(message_text, message_suffix) BGB_MESSAGE3(BGB_MACRONAME(__LINE__), message_text, message_suffix) -#define BGB_MESSAGE3(name, message_text, message_suffix) \ -__asm \ -.MACRO name msg_t, msg_s, ?llbl\ - ld d, d \ - jr llbl \ - .dw 0x6464 \ - .dw 0x0000 \ - .ascii msg_t \ - .ascii msg_s \ -llbl: \ -.ENDM \ -name ^/message_text/, ^/message_suffix/ \ -__endasm -/// \endcond DOXYGEN_DO_NOT_DOCUMENT - -/** Macro to __Start__ a profiling block for the BGB emulator - - @param MSG Quoted text string to display in the - debug message window along with the result - - To complete the profiling block and print - the result call @ref BGB_PROFILE_END. - - @see BGB_PROFILE_END(), BGB_MESSAGE() - */ -#define BGB_PROFILE_BEGIN(MSG) BGB_MESSAGE_SUFFIX(MSG, "%ZEROCLKS%"); -/** Macro to __End__ a profiling block and print the results in the BGB emulator debug message window - - @param MSG Quoted text string to display in the - debug message window along with the result - - This should only be called after a previous call - to @ref BGB_PROFILE_BEGIN() - - The results are in BGB clock units, which are - "1 nop in [CGB] doublespeed mode". - - So when running in Normal Speed mode (i.e. non-CGB doublespeed) - the printed result should be __divided by 2__ to get the actual - ellapsed cycle count. - - If running in CB Double Speed mode use the below call instead, - it correctly compensates for the speed difference. In this - scenario, the result does __not need to be divided by 2__ to - get the ellapsed cycle count. - \code{.c} - BGB_MESSAGE("NOP TIME: %-4+LASTCLKS%"); - \endcode - - @see BGB_PROFILE_BEGIN(), BGB_MESSAGE() - */ -#define BGB_PROFILE_END(MSG) BGB_MESSAGE_SUFFIX(MSG,"%-8+LASTCLKS%"); -#define BGB_TEXT(MSG) BGB_MESSAGE(MSG) - -/** Display preset debug information in the BGB debug messages window. - - This function is equivalent to: - \code{.c} - BGB_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); - \endcode - -*/ -void BGB_profiler_message(); - -/** Print the string and arguments given by format to the BGB emulator debug message window - - @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) - \li \%hd (signed char) - \li \%c (character) - \li \%u (unsigned int) - \li \%d (signed int) - \li \%x (unsigned int as hex) - \li \%s (string) - - 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. - */ -void BGB_printf(const char *format, ...) OLDCALL; - -static void * __BGB_PROFILER_INIT = &BGB_profiler_message; - -/** BGB will break into debugger when encounters this line - */ -#define BGB_BREAKPOINT __asm__("ld b, b"); +#include <gb/emu_debug.h> -#endif - +#endif diff --git a/gbdk-lib/include/gb/emu_debug.h b/gbdk-lib/include/gb/emu_debug.h @@ -0,0 +1,161 @@ +/** @file gb/emu_debug.h + + Debug window logging and profiling support for emulators (BGB, Emulicious, etc). + + Also see the `emu_debug` example project included with gbdk. + + See the BGB Manual for more information + ("expressions, breakpoint conditions, and debug messages") + http://bgb.bircd.org/manual.html#expressions + +*/ +#ifndef __EMU_DEBUG_INCLUDE +#define __EMU_DEBUG_INCLUDE + +#include <types.h> + +/** Macro to display a message in the emulator debug message window + + @param message_text Quoted text string to display in the debug message window + + The following special parameters can be + used when bracketed with "%" characters. + \li CPU registers: AF, BC, DE, HL, SP, PC, B, C, D, + E, H, L, A, ZERO, ZF, Z, CARRY, CY, IME, ALLREGS + \li Other state values: ROMBANK, XRAMBANK, SRAMBANK, + WRAMBANK, VRAMBANK, TOTALCLKS, LASTCLKS, CLKS2VBLANK + + Example: print a message along with the currently active ROM bank. + \code{.c} + EMU_MESSAGE("Current ROM Bank is: %ROMBANK%"); + \endcode + + + See the BGB Manual for more information + ("expressions, breakpoint conditions, and debug messages") + http://bgb.bircd.org/manual.html#expressions + + @see EMU_PROFILE_BEGIN(), EMU_PROFILE_END() + */ +#define EMU_MESSAGE(message_text) EMU_MESSAGE1(EMU_MACRONAME(__LINE__), message_text) +#define BGB_MESSAGE(message_text) EMU_MESSAGE(message_text) + +/// \cond DOXYGEN_DO_NOT_DOCUMENT +#define EMU_MACRONAME(A) EMU_MACRONAME1(A) +#define EMU_MACRONAME1(A) EMULOG##A + +#define EMU_MESSAGE1(name, message_text) \ +__asm \ +.MACRO name msg_t, ?llbl\ + ld d, d \ + jr llbl \ + .dw 0x6464 \ + .dw 0x0000 \ + .ascii msg_t \ +llbl: \ +.ENDM \ +name ^/message_text/ \ +__endasm + +#define EMU_MESSAGE_SUFFIX(message_text, message_suffix) EMU_MESSAGE3(EMU_MACRONAME(__LINE__), message_text, message_suffix) +#define EMU_MESSAGE3(name, message_text, message_suffix) \ +__asm \ +.MACRO name msg_t, msg_s, ?llbl\ + ld d, d \ + jr llbl \ + .dw 0x6464 \ + .dw 0x0000 \ + .ascii msg_t \ + .ascii msg_s \ +llbl: \ +.ENDM \ +name ^/message_text/, ^/message_suffix/ \ +__endasm +/// \endcond DOXYGEN_DO_NOT_DOCUMENT + +/** Macro to __Start__ a profiling block for the emulator (BGB, Emulicious, etc) + + @param MSG Quoted text string to display in the + debug message window along with the result + + To complete the profiling block and print + the result call @ref EMU_PROFILE_END. + + @see EMU_PROFILE_END(), EMU_MESSAGE() + */ +#define EMU_PROFILE_BEGIN(MSG) EMU_MESSAGE_SUFFIX(MSG, "%ZEROCLKS%"); +#define BGB_PROFILE_BEGIN(MSG) EMU_PROFILE_BEGIN(MSG) +/** Macro to __End__ a profiling block and print the results in the emulator debug message window + + @param MSG Quoted text string to display in the + debug message window along with the result + + This should only be called after a previous call + to @ref EMU_PROFILE_BEGIN() + + The results are in Emulator clock units, which are + "1 nop in [CGB] doublespeed mode". + + So when running in Normal Speed mode (i.e. non-CGB doublespeed) + the printed result should be __divided by 2__ to get the actual + ellapsed cycle count. + + If running in CB Double Speed mode use the below call instead, + it correctly compensates for the speed difference. In this + scenario, the result does __not need to be divided by 2__ to + get the ellapsed cycle count. + \code{.c} + EMU_MESSAGE("NOP TIME: %-4+LASTCLKS%"); + \endcode + + @see EMU_PROFILE_BEGIN(), EMU_MESSAGE() + */ +#define EMU_PROFILE_END(MSG) EMU_MESSAGE_SUFFIX(MSG,"%-8+LASTCLKS%"); +#define BGB_PROFILE_END(MSG) EMU_PROFILE_END(MSG) + +#define EMU_TEXT(MSG) EMU_MESSAGE(MSG) +#define BGB_TEXT(MSG) EMU_TEXT(MSG) + +/** Display preset debug information in the Emulator debug messages window. + + This function is equivalent to: + \code{.c} + EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); + \endcode + +*/ +void EMU_profiler_message(); +#define BGB_profiler_message() EMU_profiler_message() + +/** Print the string and arguments given by format to the emulator debug message window + + @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) + \li \%hd (signed char) + \li \%c (character) + \li \%u (unsigned int) + \li \%d (signed int) + \li \%x (unsigned int as hex) + \li \%s (string) + + 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. + */ +void EMU_printf(const char *format, ...) OLDCALL; +#define BGB_printf(...) EMU_printf(__VA_ARGS__) + +static void * __EMU_PROFILER_INIT = &EMU_profiler_message; + +/** The Emulator will break into debugger when encounters this line + */ +#define EMU_BREAKPOINT __asm__("ld b, b"); +#define BGB_BREAKPOINT EMU_BREAKPOINT + +#endif diff --git a/gbdk-lib/libc/targets/gbz80/ap/Makefile b/gbdk-lib/libc/targets/gbz80/ap/Makefile @@ -20,7 +20,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ set_1bit_data.s \ sgb.s font.s font_color.s delay.s \ - bgb_emu.s bgb_emu_printf.s \ + emu_debug.s emu_debug_printf.s \ nowait.s far_ptr.s \ lcd.s joy.s tim.s tim_nested.s tim_common.s \ crash_handler.s \ diff --git a/gbdk-lib/libc/targets/gbz80/ap/crt0.s b/gbdk-lib/libc/targets/gbz80/ap/crt0.s @@ -10,7 +10,7 @@ ;; RST vectors ; .org 0x00 ; Trap, utilized by crash_handler.h -; .org 0x08 ; --profile handler utilized by bgb_emu.h +; .org 0x08 ; --profile handler utilized by emu_debug.h ; .org 0x10 ; empty diff --git a/gbdk-lib/libc/targets/gbz80/bgb_emu.s b/gbdk-lib/libc/targets/gbz80/bgb_emu.s @@ -1,20 +0,0 @@ - .include "global.s" - - .title "BGB_emu" - .module BGB_emu - - .area _EMU_HEADER (ABS) - - .org 0x08 - JP _BGB_profiler_message - - .area _HOME - - ;; BGB profiler message -_BGB_profiler_message:: - LD D, D - JR 1$ - .dw 0x6464 - .dw 0 - .ascii "PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%" -1$: RET diff --git a/gbdk-lib/libc/targets/gbz80/bgb_emu_printf.s b/gbdk-lib/libc/targets/gbz80/bgb_emu_printf.s @@ -1,43 +0,0 @@ - .include "global.s" - - .title "BGB_emu" - .module BGB_emu - - .globl _sprintf - - .area _DATA - -ret_save: - .ds 0x02 -printf_buffer: - .ds 0x80 - - .area _HOME - - ;; BGB_printf(fmt, ...) -_BGB_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 - - ld d,d - jr 1$ - .dw 0x6464 - .dw 0x0001 - .dw #printf_buffer - .dw 0 -1$: - ld hl, #ret_save - ld a, (hl+) - ld h, (hl) - ld l, a - ei - jp (hl) diff --git a/gbdk-lib/libc/targets/gbz80/duck/Makefile b/gbdk-lib/libc/targets/gbz80/duck/Makefile @@ -20,7 +20,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ set_1bit_data.s \ sgb.s font.s font_color.s delay.s \ - bgb_emu.s bgb_emu_printf.s \ + emu_debug.s emu_debug_printf.s \ nowait.s far_ptr.s \ lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ crash_handler.s \ diff --git a/gbdk-lib/libc/targets/gbz80/duck/crt0.s b/gbdk-lib/libc/targets/gbz80/duck/crt0.s @@ -11,7 +11,7 @@ .org 0x00 ; MEGADUCK entry point/reset JP .code_start -; .org 0x08 ; --profile handler utilized by bgb_emu.h +; .org 0x08 ; --profile handler utilized by emu_debug.h ; .org 0x10 ; empty diff --git a/gbdk-lib/libc/targets/gbz80/emu_debug.s b/gbdk-lib/libc/targets/gbz80/emu_debug.s @@ -0,0 +1,20 @@ + .include "global.s" + + .title "EMU_debug" + .module EMU_debug + + .area _EMU_HEADER (ABS) + + .org 0x08 + JP _EMU_profiler_message + + .area _HOME + + ;; EMU profiler message +_EMU_profiler_message:: + LD D, D + JR 1$ + .dw 0x6464 + .dw 0 + .ascii "PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%" +1$: RET diff --git a/gbdk-lib/libc/targets/gbz80/emu_debug_printf.s b/gbdk-lib/libc/targets/gbz80/emu_debug_printf.s @@ -0,0 +1,43 @@ + .include "global.s" + + .title "EMU_debug" + .module EMU_debug + + .globl _sprintf + + .area _DATA + +ret_save: + .ds 0x02 +printf_buffer: + .ds 0x80 + + .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 + + ld d,d + jr 1$ + .dw 0x6464 + .dw 0x0001 + .dw #printf_buffer + .dw 0 +1$: + ld hl, #ret_save + ld a, (hl+) + ld h, (hl) + ld l, a + ei + jp (hl) diff --git a/gbdk-lib/libc/targets/gbz80/gb/Makefile b/gbdk-lib/libc/targets/gbz80/gb/Makefile @@ -20,7 +20,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ set_1bit_data.s \ sgb.s font.s font_color.s delay.s \ - bgb_emu.s bgb_emu_printf.s \ + emu_debug.s emu_debug_printf.s \ nowait.s far_ptr.s \ lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ crash_handler.s \ diff --git a/gbdk-lib/libc/targets/gbz80/gb/crt0.s b/gbdk-lib/libc/targets/gbz80/gb/crt0.s @@ -10,7 +10,7 @@ ;; RST vectors ; .org 0x00 ; Trap, utilized by crash_handler.h -; .org 0x08 ; --profile handler utilized by bgb_emu.h +; .org 0x08 ; --profile handler utilized by emu_debug.h ; .org 0x10 ; empty

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.