Rename unzip tool.
[SquirrelJME.git] / nanocoat / frontend / libretro / loop.c
blob5e4ae33d91d5747fbd3fd4ca86dc31af46232c2d
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <string.h>
12 #include "sjme/nvm.h"
13 #include "sjme/debug.h"
14 #include "sjme/modelessStars.h"
15 #include "3rdparty/libretro/libretro.h"
16 #include "frontend/libretro/shared.h"
18 #if defined(SJME_CONFIG_DEBUG) && defined(SJME_CONFIG_UNIT_TEST)
19 #include "sjme/test/externTest.h"
20 #endif
22 #if defined(SJME_CONFIG_DEBUG) && defined(SJME_CONFIG_UNIT_TEST)
24 /** Did we already check that we are running unit tests? */
25 static sjme_jboolean sjme_libretro_checkRunUnitTests;
27 /** Did we read the environment for unit tests? */
28 static sjme_jboolean sjme_libretro_checkedEnvRunUnitTests;
30 /** Are we running unit tests? */
31 static sjme_jboolean sjme_libretro_doRunUnitTests;
33 /** The next test to run. */
34 static sjme_lpcstr sjme_libretro_nextTest;
36 /**
37 * Check if unit tests should run.
39 * @since 2023/12/21
41 static void sjme_libretro_checkUnitTests(void)
43 struct retro_variable var;
45 /* Do we need to check if we are running unit tests? */
46 if (!sjme_libretro_checkedEnvRunUnitTests)
48 /* Do not check again. */
49 sjme_libretro_checkedEnvRunUnitTests = SJME_JNI_TRUE;
51 /* Ask the front end if we should run unit tests. */
52 memset(&var, 0, sizeof(var));
53 var.key = SJME_LIBRETRO_CONFIG_UNIT_TESTS;
54 sjme_libretro_envCallback(RETRO_ENVIRONMENT_GET_VARIABLE,
55 &var);
57 /* Are we running unit tests? */
58 if (var.value != NULL && 0 == strcmp(var.value, "true"))
60 /* Do run the tests now. */
61 sjme_libretro_doRunUnitTests = SJME_JNI_TRUE;
63 /* Implicit start at first test. */
64 sjme_libretro_nextTest = "";
69 sjme_jboolean sjme_libretro_unitTestAbortHandler(void)
71 return SJME_JNI_TRUE;
74 static sjme_debug_handlerFunctions sjme_libretro_unitTestDebugHandlers =
76 .abort = sjme_libretro_unitTestAbortHandler,
77 .exit = NULL,
78 .message = NULL,
81 /**
82 * Runs unit tests.
84 * @return If they are running.
85 * @since 2023/12/21
87 static sjme_jboolean sjme_libretro_runUnitTests(void)
89 sjme_lpstr argv[2];
91 /* Not running unit tests, so ignore. */
92 if (!sjme_libretro_doRunUnitTests)
93 return SJME_JNI_FALSE;
95 /* Ran out of tests to run? */
96 if (sjme_libretro_nextTest == NULL)
97 return SJME_JNI_TRUE;
99 /* Clear the abort and exit handlers so the tests do not just end. */
100 sjme_debug_handlers = &sjme_libretro_unitTestDebugHandlers;
102 /* Run unit tests. */
103 argv[0] = "libretro";
104 argv[1] = sjme_libretro_nextTest;
105 sjme_test_main(2, argv, &sjme_libretro_nextTest);
107 /* We ran something. */
108 return SJME_JNI_TRUE;
111 #endif
113 sjme_attrUnused RETRO_API void retro_run(void)
115 static sjme_modelessStarState modelessStarState;
116 static sjme_jint tick;
117 uint32_t buf[240*320];
118 int i;
120 static sjme_jint trigger;
121 if (!(trigger++))
122 sjme_message("Impl. %s?", __func__);
124 /* Do a basic animation. */
125 sjme_modelessStars(&modelessStarState, buf,
126 240, 320, 240, tick++);
127 sjme_libretro_videoRefreshCallback(
128 buf, 240, 320, 240 * 4);
130 #if defined(SJME_CONFIG_DEBUG) && defined(SJME_CONFIG_UNIT_TEST)
131 /* Running unit tests? */
132 if (!sjme_libretro_checkRunUnitTests)
134 /* Do not emit again. */
135 sjme_libretro_checkRunUnitTests = SJME_JNI_TRUE;
137 /* Run the check. */
138 sjme_libretro_checkUnitTests();
141 /* Run unit tests in the loop. */
142 if (sjme_libretro_doRunUnitTests)
144 sjme_libretro_runUnitTests();
145 return;
147 #endif