gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/examples/cross-platform/libc_memcpy/src/libc_memcpy.c
1 //
2 // libc_memcpy.c
3 // Simple test of memcpy/memset/memmove functions in C library string.h
4 //
5
6 #include <stdio.h>
7 #include <string.h>
8
9 #include <gbdk/platform.h>
10 #include <gbdk/font.h>
11 #include <gbdk/console.h>
12
13 uint8_t memcpy_dst[300];
14 const uint8_t memcpy_src[300];
15
16 int benchmark_memcpy(int num, int size)
17 {
18 int i;
19 uint16_t start_time = sys_time;
20 for(i = 0; i < num; i++)
21 memcpy(memcpy_dst, memcpy_src, size);
22 return (int)(sys_time - start_time);
23 }
24
25 void main(void)
26 {
27 font_t ibm_font;
28
29 // init the font system to use IBM font
30 font_init();
31 ibm_font = font_load(font_ibm);
32 font_set(ibm_font);
33
34 // Test memcpy
35 {
36 char dst[4] = "dst";
37 const char* src = "src";
38 printf("memcpy(dst,src,2)\n-> %s\n", memcpy(dst, src, 2));
39 }
40 // Test memmove
41 {
42 char dst[4] = "dst";
43 const char* src = "src";
44 printf("memmove(dst,src,2)\n-> %s\n", memmove(dst, src, 2));
45 }
46 // Test memset
47 {
48 char dst[4] = "dst";
49 printf("memset(dst,x,2)\n-> %s\n", memset(dst, 'x', 2));
50 }
51 // Benchmark memcpy
52 printf("\nBenchmark memcpy:\n");
53 {
54 printf("800*memcpy(d,s,150)\n-> %d frames\n", benchmark_memcpy(800, 150));
55 printf("400*memcpy(d,s,300)\n-> %d frames\n", benchmark_memcpy(400, 300));
56 }
57 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.