From 778fe214d136efeda7d072f933a0cf8ff1840f85 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 27 Apr 2021 14:41:49 +0200 Subject: Testing BIOS calls --- Makefile | 4 +++- src/bios_calls.s | 9 +++++++++ src/main.c | 48 +++++++++++++++++++++--------------------------- 3 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 src/bios_calls.s diff --git a/Makefile b/Makefile index 1979bf8..7202bb9 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,10 @@ LIBGBA += $(LIBGBA_DIR)/lib/libmm.a # Source code location and files to watch for changes. SRC_DIR := src SRC_MAIN := $(SRC_DIR)/main.c +ASM_FILES := $(wildcard $(SRC_DIR)/*.s) WATCH_SRC := $(wildcard $(SRC_DIR)/*.c) WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) +WATCH_SRC += $(wildcard $(SRC_DIR)/*.s) # Output library names and executables. TARGET := experiments @@ -57,7 +59,7 @@ $(BIN): $(ELF) # Link files. $(ELF): $(SRC_MAIN) $(WATCH_SRC) - $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(LDLIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(ASM_FILES) $(LDLIBS) # Create build directory if needed. $(BUILD_DIR): diff --git a/src/bios_calls.s b/src/bios_calls.s new file mode 100644 index 0000000..2268b4d --- /dev/null +++ b/src/bios_calls.s @@ -0,0 +1,9 @@ +@ Bios division call. + .text @ aka .section .text + .code 16 @ aka .thumb + .align 2 @ aka .balign 4 + .global bios_div + .thumb_func +bios_div: + swi 0x06 + bx lr diff --git a/src/main.c b/src/main.c index 88bc3b8..decd40d 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,16 @@ // TODO: Cleanup OBJ/OAM memory copying and access. // +// +// BIOS calls +// + +int bios_div(int num, int denom); + +int normal_div(int num, int denom) { + return num / denom; +}; + int main(void) { // Configure the display in mode 0 to show OBJs, where tile memory is // sequential. @@ -22,42 +32,26 @@ int main(void) { init_sprite_pal(0, COLOR_WHITE); init_sprites(0); init_button_sprites(); - Color colors[16] = { - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - COLOR_BLUE, - }; - size_t n_iter = 10000; + // Initialize text engine. + txt_init(0, COLOR_RED, 0); + + size_t n_iter = 1000; profile_start(); + int test = 0; for (size_t i = 0; i < n_iter; ++i) { - dma_copy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color), 3); + txt_printf("Bios div: %d\n", bios_div(5 * i, 5)); } - u32 dma_copy_perf = profile_stop(); + u32 bios_div_perf = profile_stop(); profile_start(); for (size_t i = 0; i < n_iter; ++i) { - memcpy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color)); + txt_printf("Code div: %d\n", normal_div(5 * i, 5)); } - u32 memcpy_perf = profile_stop(); + u32 code_perf = profile_stop(); - // Initialize text engine. - txt_init(0, COLOR_RED, 0); - txt_printf("N. cycles memcpy: %d\n", memcpy_perf); - txt_printf("N. cycles dma_copy: %d\n", dma_copy_perf); + txt_printf("C code div perf: %d\n", code_perf); + txt_printf("BIOS div perf: %d\n", bios_div_perf); int frame_counter = 0; while(true) { -- cgit v1.2.1