summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-01-05 17:26:36 -0500
committerFranklin Wei <git@fwei.tk>2018-01-05 17:47:03 -0500
commitd105dfd03f17d4dd3ef14b83b67353b94b3742de (patch)
treecebcb99be89e7a9def8465531b5cafabcb740ceb /apps/plugins
parentf90bb989852524a940d5fbab3726412f520f2b59 (diff)
downloadrockbox-d105dfd03f17d4dd3ef14b83b67353b94b3742de.zip
rockbox-d105dfd03f17d4dd3ef14b83b67353b94b3742de.tar.gz
rockbox-d105dfd03f17d4dd3ef14b83b67353b94b3742de.tar.bz2
rockbox-d105dfd03f17d4dd3ef14b83b67353b94b3742de.tar.xz
Add a test_sdl plugin
This plugin plays a rough sine wave and is mostly useful for debugging crashes associated with SDL. Probably not worth merging. Change-Id: I58ea675f6f996c15bff11fd35445456e41f9fd60
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/CATEGORIES1
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/sdl/SOURCES.test_sdl1
-rw-r--r--apps/plugins/sdl/progs/helloworld.c84
-rw-r--r--apps/plugins/sdl/sdl.make33
5 files changed, 116 insertions, 4 deletions
diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES
index 652a0b3..0e3a44e 100644
--- a/apps/plugins/CATEGORIES
+++ b/apps/plugins/CATEGORIES
@@ -166,6 +166,7 @@ test_gfx,apps
test_resize,apps
test_sampr,apps
test_scanrate,apps
+test_sdl,apps
test_touchscreen,apps
test_viewports,apps
test_greylib_bitmap_scale,viewers
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index 3a622fe..f0b1008 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -78,6 +78,7 @@ iriverify.c
(!defined(LCD_STRIDEFORMAT) || (LCD_STRIDEFORMAT != VERTICAL_STRIDE))
#if (PLUGIN_BUFFER_SIZE > 0x14000)
duke3d.c
+test_sdl.c
#endif
#endif
diff --git a/apps/plugins/sdl/SOURCES.test_sdl b/apps/plugins/sdl/SOURCES.test_sdl
new file mode 100644
index 0000000..74cd5b1
--- /dev/null
+++ b/apps/plugins/sdl/SOURCES.test_sdl
@@ -0,0 +1 @@
+progs/helloworld.c
diff --git a/apps/plugins/sdl/progs/helloworld.c b/apps/plugins/sdl/progs/helloworld.c
new file mode 100644
index 0000000..c98529d
--- /dev/null
+++ b/apps/plugins/sdl/progs/helloworld.c
@@ -0,0 +1,84 @@
+#include "SDL.h"
+
+#ifdef ROCKBOX
+#ifndef COMBINED_SDL
+#define main my_main
+#else
+#define main testsound_main
+#endif
+#else
+#include <math.h>
+#endif
+
+double phase = 0;
+
+void fill_audio(void *udata, Uint8 *stream, int len)
+{
+ for(int i = 0; i < len; ++i)
+ {
+ *stream++ = 127 * sin(phase);
+ phase += M_PI / 100;
+ if(phase > 2 * M_PI)
+ phase -= 2 * M_PI;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ SDL_Surface *screen;
+ SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
+ SDL_Cursor *cursor[3];
+ int current;
+
+ /* Load the SDL library */
+ if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ screen = SDL_SetVideoMode(LCD_WIDTH,LCD_HEIGHT,24,SDL_ANYFORMAT);
+ if (screen==NULL) {
+ fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError());
+ return(1);
+ }
+
+ SDL_FillRect(screen, NULL, 0xff00ff);
+
+ SDL_AudioSpec wanted;
+
+ /* Set the audio format */
+ wanted.freq = 44100;
+ wanted.format = AUDIO_S8;
+ wanted.channels = 2; /* 1 = mono, 2 = stereo */
+ wanted.samples = 1024; /* Good low-latency value for callback */
+ wanted.callback = fill_audio;
+ wanted.userdata = NULL;
+
+
+ /* Open the audio device, forcing the desired format */
+ if ( SDL_OpenAudio(&wanted, NULL) < 0 ) {
+ fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
+ return(-1);
+ }
+
+ SDL_PauseAudio(0);
+
+ while (!quit) {
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ switch(event.type) {
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_KEYDOWN:
+ case SDL_QUIT:
+ quit = SDL_TRUE;
+ break;
+ }
+ }
+ SDL_Flip(screen);
+ SDL_Delay(10);
+ }
+ SDL_CloseAudio();
+
+ SDL_Quit();
+ return(0);
+}
diff --git a/apps/plugins/sdl/sdl.make b/apps/plugins/sdl/sdl.make
index 9834638..50164dd 100644
--- a/apps/plugins/sdl/sdl.make
+++ b/apps/plugins/sdl/sdl.make
@@ -12,18 +12,20 @@ SDL_OBJDIR := $(BUILDDIR)/apps/plugins/sdl
SDL_SRC := $(call preprocess, $(SDL_SRCDIR)/SOURCES)
DUKE3D_SRC := $(call preprocess, $(SDL_SRCDIR)/SOURCES.duke)
+TESTSDL_SRC := $(call preprocess, $(SDL_SRCDIR)/SOURCES.test_sdl)
SDL_OBJ := $(call c2obj, $(SDL_SRC))
DUKE3D_OBJ = $(call c2obj, $(DUKE3D_SRC))
+TESTSDL_OBJ = $(call c2obj, $(TESTSDL_SRC))
# add source files to OTHER_SRC to get automatic dependencies
-OTHER_SRC += $(SDL_SRC) $(DUKE3D_SRC)
+OTHER_SRC += $(SDL_SRC) $(DUKE3D_SRC) $(TESTSDL_SRC)
OTHER_INC += -I$(SDL_SRCDIR)/include
# include comes first because of possible system SDL headers taking
# precedence
SDLFLAGS = -I$(SDL_SRCDIR)/include $(filter-out -O%,$(PLUGINFLAGS)) \
--O3 -Wno-unused-parameter -Xpreprocessor -Wno-undef -Wcast-align -w
+-O3 -Wno-unused-parameter -Xpreprocessor -Wno-undef -Wcast-align -w -save-temps
ifeq ($(ARCH_VERSION),6)
SDLFLAGS += -mfloat-abi=softfp
@@ -32,11 +34,15 @@ endif
ifndef APP_TYPE
### no target has a big enough plugin buffer
ROCKS += $(SDL_OBJDIR)/duke3d.ovl
+ ROCKS += $(SDL_OBJDIR)/test_sdl.ovl
DUKE3D_OUTLDS = $(SDL_OBJDIR)/duke3d.link
- SDL_OVLFLAGS = -T$(DUKE3D_OUTLDS) -Wl,--gc-sections -Wl,-Map,$(basename $@).map
+ TESTSDL_OUTLDS = $(SDL_OBJDIR)/test_sdl.link
+ DUKE3D_OVLFLAGS = -T$(DUKE3D_OUTLDS) -Wl,--gc-sections -Wl,-Map,$(basename $@).map
+ TESTSDL_OVLFLAGS = -T$(TESTSDL_OUTLDS) -Wl,--gc-sections -Wl,-Map,$(basename $@).map
else
### simulator
ROCKS += $(SDL_OBJDIR)/duke3d.rock
+ ROCKS += $(SDL_OBJDIR)/test_sdl.rock
endif
$(SDL_OBJDIR)/duke3d.rock: $(SDL_OBJ) $(DUKE3D_OBJ) $(TLSFLIB)
@@ -51,9 +57,28 @@ $(SDL_OBJDIR)/duke3d.ovl: $(SDL_OBJ) $(DUKE3D_OBJ) $(TLSFLIB) $(DUKE3D_OUTLDS)
$(SILENT)$(CC) $(PLUGINFLAGS) -o $(basename $@).elf \
$(filter %.o, $^) \
$(filter %.a, $+) \
- -lgcc $(SDL_OVLFLAGS)
+ -lgcc $(DUKE3D_OVLFLAGS)
$(call PRINTS,LD $(@F))$(call objcopy,$(basename $@).elf,$@)
+###
+
+$(SDL_OBJDIR)/test_sdl.rock: $(SDL_OBJ) $(TESTSDL_OBJ) $(TLSFLIB)
+
+$(SDL_OBJDIR)/test_sdl.refmap: $(SDL_OBJ) $(TESTSDL_OBJ) $(TLSFLIB)
+
+$(TESTSDL_OUTLDS): $(PLUGIN_LDS) $(SDL_OBJDIR)/test_sdl.refmap
+ $(call PRINTS,PP $(@F))$(call preprocess2file,$<,$@,-DOVERLAY_OFFSET=$(shell \
+ $(TOOLSDIR)/ovl_offset.pl $(SDL_OBJDIR)/test_sdl.refmap))
+
+$(SDL_OBJDIR)/test_sdl.ovl: $(SDL_OBJ) $(TESTSDL_OBJ) $(TLSFLIB) $(TESTSDL_OUTLDS)
+ $(SILENT)$(CC) $(PLUGINFLAGS) -o $(basename $@).elf \
+ $(filter %.o, $^) \
+ $(filter %.a, $+) \
+ -lgcc $(TESTSDL_OVLFLAGS)
+ $(call PRINTS,LD $(@F))$(call objcopy,$(basename $@).elf,$@)
+
+###
+
$(SDL_OBJDIR)/%.o: $(SDL_SRCDIR)/%.c $(SDL_SRCDIR)/sdl.make $(BUILDDIR)/sysfont.h
$(SILENT)mkdir -p $(dir $@)
$(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) -I$(dir $<) $(SDLFLAGS) -c $< -o $@