add a quick TinyMT test

This commit is contained in:
Lephe 2020-05-31 17:06:47 +02:00
parent abeaeb882b
commit 716e6cc5a1
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 47 additions and 2 deletions

View File

@ -5,6 +5,9 @@
#ifndef GINTCTL_LIBS
#define GINTCTL_LIBS
/* gintctl_libs_tinymt(): TinyMT32 random number generation */
void gintctl_libs_tinymt(void);
/* gintctl_libs_libimg(): libimg-based rendering and image transform */
void gintctl_libs_libimg(void);

View File

@ -66,9 +66,12 @@ struct menu menu_perf = {
/* External libraries */
struct menu menu_libs = {
_("Libraries", "External libraries"), .entries = {
_("Libraries", "External and standard libraries"), .entries = {
{ "libimg", gintctl_libs_libimg },
{ "libc: " _("TinyMT32", "TinyMT random number generation"),
gintctl_libs_tinymt },
{ "libimg" _(""," image transforms"),
gintctl_libs_libimg },
{ NULL, NULL },
}};

39
src/libs/tinymt.c Normal file
View File

@ -0,0 +1,39 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/stdlib.h>
#include <gintctl/libs.h>
#include <gintctl/util.h>
void gintctl_libs_tinymt(void)
{
int key = 0;
uint32_t seed = 0xdeadbeef;
srand(seed);
uint32_t values[32];
for(int i = 0; i < 32; i++) values[i] = rand();
dclear(C_WHITE);
#ifdef FX9860G
row_print(1, 1, "TinyMT random");
row_print(2, 1, "Seed: %08X", seed);
for(int i = 0; i < 12; i++)
row_print(3+(i >> 1), (i&1)?13:2, "%08X", values[i]);
#endif
#ifdef FXCG50
row_title("TinyMT random number generation");
row_print(1, 1, "Seed: %08X", seed);
row_print(3, 1, "First values:");
for(int i = 0; i < 32; i++)
row_print(4+(i >> 2), 2+12*(i&3), "%08X", values[i]);
#endif
dupdate();
while(key != KEY_EXIT) key = getkey().key;
}