summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-04-27 14:41:49 +0200
committerBad Diode <bd@badd10de.dev>2021-04-27 14:41:49 +0200
commit778fe214d136efeda7d072f933a0cf8ff1840f85 (patch)
treeefa86b0ac8cbf713f6d83bb0760b237854dc8387
parent3e38d5561d3e2e60f79ec5387f167bb12170c0f9 (diff)
downloadgba-experiments-778fe214d136efeda7d072f933a0cf8ff1840f85.tar.gz
gba-experiments-778fe214d136efeda7d072f933a0cf8ff1840f85.zip
Testing BIOS calls
-rw-r--r--Makefile4
-rw-r--r--src/bios_calls.s9
-rw-r--r--src/main.c48
3 files changed, 33 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 1979bf8..7202bb9 100644
--- a/Makefile
+++ b/Makefile
@@ -14,8 +14,10 @@ LIBGBA += $(LIBGBA_DIR)/lib/libmm.a
14# Source code location and files to watch for changes. 14# Source code location and files to watch for changes.
15SRC_DIR := src 15SRC_DIR := src
16SRC_MAIN := $(SRC_DIR)/main.c 16SRC_MAIN := $(SRC_DIR)/main.c
17ASM_FILES := $(wildcard $(SRC_DIR)/*.s)
17WATCH_SRC := $(wildcard $(SRC_DIR)/*.c) 18WATCH_SRC := $(wildcard $(SRC_DIR)/*.c)
18WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) 19WATCH_SRC += $(wildcard $(SRC_DIR)/*.h)
20WATCH_SRC += $(wildcard $(SRC_DIR)/*.s)
19 21
20# Output library names and executables. 22# Output library names and executables.
21TARGET := experiments 23TARGET := experiments
@@ -57,7 +59,7 @@ $(BIN): $(ELF)
57 59
58# Link files. 60# Link files.
59$(ELF): $(SRC_MAIN) $(WATCH_SRC) 61$(ELF): $(SRC_MAIN) $(WATCH_SRC)
60 $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(LDLIBS) 62 $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(ASM_FILES) $(LDLIBS)
61 63
62# Create build directory if needed. 64# Create build directory if needed.
63$(BUILD_DIR): 65$(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 @@
1@ Bios division call.
2 .text @ aka .section .text
3 .code 16 @ aka .thumb
4 .align 2 @ aka .balign 4
5 .global bios_div
6 .thumb_func
7bios_div:
8 swi 0x06
9 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 @@
13// TODO: Cleanup OBJ/OAM memory copying and access. 13// TODO: Cleanup OBJ/OAM memory copying and access.
14// 14//
15 15
16//
17// BIOS calls
18//
19
20int bios_div(int num, int denom);
21
22int normal_div(int num, int denom) {
23 return num / denom;
24};
25
16int main(void) { 26int main(void) {
17 // Configure the display in mode 0 to show OBJs, where tile memory is 27 // Configure the display in mode 0 to show OBJs, where tile memory is
18 // sequential. 28 // sequential.
@@ -22,42 +32,26 @@ int main(void) {
22 init_sprite_pal(0, COLOR_WHITE); 32 init_sprite_pal(0, COLOR_WHITE);
23 init_sprites(0); 33 init_sprites(0);
24 init_button_sprites(); 34 init_button_sprites();
25 Color colors[16] = {
26 COLOR_BLUE,
27 COLOR_BLUE,
28 COLOR_BLUE,
29 COLOR_BLUE,
30 COLOR_BLUE,
31 COLOR_BLUE,
32 COLOR_BLUE,
33 COLOR_BLUE,
34 COLOR_BLUE,
35 COLOR_BLUE,
36 COLOR_BLUE,
37 COLOR_BLUE,
38 COLOR_BLUE,
39 COLOR_BLUE,
40 COLOR_BLUE,
41 COLOR_BLUE,
42 };
43 35
44 size_t n_iter = 10000; 36 // Initialize text engine.
37 txt_init(0, COLOR_RED, 0);
38
39 size_t n_iter = 1000;
45 profile_start(); 40 profile_start();
41 int test = 0;
46 for (size_t i = 0; i < n_iter; ++i) { 42 for (size_t i = 0; i < n_iter; ++i) {
47 dma_copy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color), 3); 43 txt_printf("Bios div: %d\n", bios_div(5 * i, 5));
48 } 44 }
49 u32 dma_copy_perf = profile_stop(); 45 u32 bios_div_perf = profile_stop();
50 46
51 profile_start(); 47 profile_start();
52 for (size_t i = 0; i < n_iter; ++i) { 48 for (size_t i = 0; i < n_iter; ++i) {
53 memcpy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color)); 49 txt_printf("Code div: %d\n", normal_div(5 * i, 5));
54 } 50 }
55 u32 memcpy_perf = profile_stop(); 51 u32 code_perf = profile_stop();
56 52
57 // Initialize text engine. 53 txt_printf("C code div perf: %d\n", code_perf);
58 txt_init(0, COLOR_RED, 0); 54 txt_printf("BIOS div perf: %d\n", bios_div_perf);
59 txt_printf("N. cycles memcpy: %d\n", memcpy_perf);
60 txt_printf("N. cycles dma_copy: %d\n", dma_copy_perf);
61 55
62 int frame_counter = 0; 56 int frame_counter = 0;
63 while(true) { 57 while(true) {