|
@@ -14,12 +14,15 @@
|
|
|
#define MONITOR_HOR_RES 320
|
|
#define MONITOR_HOR_RES 320
|
|
|
#define MONITOR_VER_RES 240
|
|
#define MONITOR_VER_RES 240
|
|
|
#ifndef MONITOR_ZOOM
|
|
#ifndef MONITOR_ZOOM
|
|
|
-#define MONITOR_ZOOM 1
|
|
|
|
|
|
|
+#define MONITOR_ZOOM 1
|
|
|
#endif
|
|
#endif
|
|
|
-#define SDL_REFR_PERIOD 50
|
|
|
|
|
-void monitor_sdl_init(void);
|
|
|
|
|
-void monitor_sdl_refr_core(void);
|
|
|
|
|
-void monitor_sdl_clean_up(void);
|
|
|
|
|
|
|
+#define SDL_REFR_PERIOD 50
|
|
|
|
|
+void
|
|
|
|
|
+monitor_sdl_init(void);
|
|
|
|
|
+void
|
|
|
|
|
+monitor_sdl_refr_core(void);
|
|
|
|
|
+void
|
|
|
|
|
+monitor_sdl_clean_up(void);
|
|
|
|
|
|
|
|
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES];
|
|
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES];
|
|
|
|
|
|
|
@@ -30,22 +33,23 @@ time_get_ms(wasm_exec_env_t exec_env)
|
|
|
gettimeofday(&tv, NULL);
|
|
gettimeofday(&tv, NULL);
|
|
|
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
|
|
long long time_in_mill = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
|
|
|
|
|
|
|
|
- return (int) time_in_mill;
|
|
|
|
|
|
|
+ return (int)time_in_mill;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-SDL_Window * window;
|
|
|
|
|
-SDL_Renderer * renderer;
|
|
|
|
|
-SDL_Texture * texture;
|
|
|
|
|
|
|
+SDL_Window *window;
|
|
|
|
|
+SDL_Renderer *renderer;
|
|
|
|
|
+SDL_Texture *texture;
|
|
|
static volatile bool sdl_inited = false;
|
|
static volatile bool sdl_inited = false;
|
|
|
static volatile bool sdl_refr_qry = false;
|
|
static volatile bool sdl_refr_qry = false;
|
|
|
static volatile bool sdl_quit_qry = false;
|
|
static volatile bool sdl_quit_qry = false;
|
|
|
|
|
|
|
|
-void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
- const lv_color_t * color)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
+ const lv_color_t *color)
|
|
|
{
|
|
{
|
|
|
/*Return if the area is out the screen*/
|
|
/*Return if the area is out the screen*/
|
|
|
if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1
|
|
if (x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1
|
|
|
- || y1 > MONITOR_VER_RES - 1) {
|
|
|
|
|
|
|
+ || y1 > MONITOR_VER_RES - 1) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -71,8 +75,8 @@ void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
* @param y2 bottom coordinate
|
|
* @param y2 bottom coordinate
|
|
|
* @param color fill color
|
|
* @param color fill color
|
|
|
*/
|
|
*/
|
|
|
-void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
- lv_color_t *color)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color)
|
|
|
{
|
|
{
|
|
|
/*Return if the area is out the screen*/
|
|
/*Return if the area is out the screen*/
|
|
|
if (x2 < 0)
|
|
if (x2 < 0)
|
|
@@ -92,7 +96,7 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
|
|
|
int32_t x;
|
|
int32_t x;
|
|
|
int32_t y;
|
|
int32_t y;
|
|
|
- uint32_t color32 = color->full; //lv_color_to32(color);
|
|
|
|
|
|
|
+ uint32_t color32 = color->full; // lv_color_to32(color);
|
|
|
|
|
|
|
|
for (x = act_x1; x <= act_x2; x++) {
|
|
for (x = act_x1; x <= act_x2; x++) {
|
|
|
for (y = act_y1; y <= act_y2; y++) {
|
|
for (y = act_y1; y <= act_y2; y++) {
|
|
@@ -111,8 +115,9 @@ void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
* @param y2 bottom coordinate
|
|
* @param y2 bottom coordinate
|
|
|
* @param color an array of colors
|
|
* @param color an array of colors
|
|
|
*/
|
|
*/
|
|
|
-void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
- const lv_color_t *color)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
+ const lv_color_t *color)
|
|
|
{
|
|
{
|
|
|
/*Return if the area is out the screen*/
|
|
/*Return if the area is out the screen*/
|
|
|
if (x2 < 0)
|
|
if (x2 < 0)
|
|
@@ -135,7 +140,8 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
|
|
|
for (y = act_y1; y <= act_y2; y++) {
|
|
for (y = act_y1; y <= act_y2; y++) {
|
|
|
for (x = act_x1; x <= act_x2; x++) {
|
|
for (x = act_x1; x <= act_x2; x++) {
|
|
|
- tft_fb[y * MONITOR_HOR_RES + x] = color->full; //lv_color_to32(*color);
|
|
|
|
|
|
|
+ tft_fb[y * MONITOR_HOR_RES + x] =
|
|
|
|
|
+ color->full; // lv_color_to32(*color);
|
|
|
color++;
|
|
color++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -145,38 +151,33 @@ void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
sdl_refr_qry = true;
|
|
sdl_refr_qry = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
void
|
|
void
|
|
|
display_init(void)
|
|
display_init(void)
|
|
|
-{
|
|
|
|
|
-}
|
|
|
|
|
|
|
+{}
|
|
|
|
|
|
|
|
void
|
|
void
|
|
|
-display_flush(wasm_exec_env_t exec_env,
|
|
|
|
|
- int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
- lv_color_t *color)
|
|
|
|
|
|
|
+display_flush(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
|
|
|
|
|
+ int32_t y2, lv_color_t *color)
|
|
|
{
|
|
{
|
|
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
|
|
|
|
|
|
- if (!wasm_runtime_validate_native_addr(module_inst,
|
|
|
|
|
- color, sizeof(lv_color_t)))
|
|
|
|
|
|
|
+ if (!wasm_runtime_validate_native_addr(module_inst, color,
|
|
|
|
|
+ sizeof(lv_color_t)))
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
monitor_flush(x1, y1, x2, y2, color);
|
|
monitor_flush(x1, y1, x2, y2, color);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void
|
|
void
|
|
|
-display_fill(wasm_exec_env_t exec_env,
|
|
|
|
|
- int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
- lv_color_t *color)
|
|
|
|
|
|
|
+display_fill(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
|
|
|
|
|
+ int32_t y2, lv_color_t *color)
|
|
|
{
|
|
{
|
|
|
monitor_fill(x1, y1, x2, y2, color);
|
|
monitor_fill(x1, y1, x2, y2, color);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void
|
|
void
|
|
|
-display_map(wasm_exec_env_t exec_env,
|
|
|
|
|
- int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
|
|
|
|
- const lv_color_t *color)
|
|
|
|
|
|
|
+display_map(wasm_exec_env_t exec_env, int32_t x1, int32_t y1, int32_t x2,
|
|
|
|
|
+ int32_t y2, const lv_color_t *color)
|
|
|
{
|
|
{
|
|
|
monitor_map(x1, y1, x2, y2, color);
|
|
monitor_map(x1, y1, x2, y2, color);
|
|
|
}
|
|
}
|
|
@@ -188,20 +189,17 @@ typedef struct display_input_data {
|
|
|
} display_input_data;
|
|
} display_input_data;
|
|
|
|
|
|
|
|
bool
|
|
bool
|
|
|
-display_input_read(wasm_exec_env_t exec_env,
|
|
|
|
|
- void *input_data_app)
|
|
|
|
|
|
|
+display_input_read(wasm_exec_env_t exec_env, void *input_data_app)
|
|
|
{
|
|
{
|
|
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
|
- display_input_data *data_app = (display_input_data*)input_data_app;
|
|
|
|
|
|
|
+ display_input_data *data_app = (display_input_data *)input_data_app;
|
|
|
bool ret;
|
|
bool ret;
|
|
|
|
|
|
|
|
- if (!wasm_runtime_validate_native_addr(module_inst,
|
|
|
|
|
- data_app,
|
|
|
|
|
|
|
+ if (!wasm_runtime_validate_native_addr(module_inst, data_app,
|
|
|
sizeof(display_input_data)))
|
|
sizeof(display_input_data)))
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- lv_indev_data_t data = {0};
|
|
|
|
|
|
|
+ lv_indev_data_t data = { 0 };
|
|
|
|
|
|
|
|
ret = mouse_read(&data);
|
|
ret = mouse_read(&data);
|
|
|
|
|
|
|
@@ -215,27 +213,26 @@ display_input_read(wasm_exec_env_t exec_env,
|
|
|
|
|
|
|
|
void
|
|
void
|
|
|
display_deinit(wasm_exec_env_t exec_env)
|
|
display_deinit(wasm_exec_env_t exec_env)
|
|
|
-{
|
|
|
|
|
-}
|
|
|
|
|
|
|
+{}
|
|
|
|
|
|
|
|
void
|
|
void
|
|
|
-display_vdb_write(wasm_exec_env_t exec_env,
|
|
|
|
|
- void *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
|
|
|
|
|
- lv_color_t *color, lv_opa_t opa)
|
|
|
|
|
|
|
+display_vdb_write(wasm_exec_env_t exec_env, void *buf, lv_coord_t buf_w,
|
|
|
|
|
+ lv_coord_t x, lv_coord_t y, lv_color_t *color, lv_opa_t opa)
|
|
|
{
|
|
{
|
|
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
|
- unsigned char *buf_xy = (unsigned char*)buf + 4 * x + 4 * y * buf_w;
|
|
|
|
|
|
|
+ unsigned char *buf_xy = (unsigned char *)buf + 4 * x + 4 * y * buf_w;
|
|
|
|
|
|
|
|
- if (!wasm_runtime_validate_native_addr(module_inst,
|
|
|
|
|
- color, sizeof(lv_color_t)))
|
|
|
|
|
|
|
+ if (!wasm_runtime_validate_native_addr(module_inst, color,
|
|
|
|
|
+ sizeof(lv_color_t)))
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
*(lv_color_t *)buf_xy = *color;
|
|
*(lv_color_t *)buf_xy = *color;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int monitor_sdl_refr_thread(void * param)
|
|
|
|
|
|
|
+int
|
|
|
|
|
+monitor_sdl_refr_thread(void *param)
|
|
|
{
|
|
{
|
|
|
- (void) param;
|
|
|
|
|
|
|
+ (void)param;
|
|
|
|
|
|
|
|
/*If not OSX initialize SDL in the Thread*/
|
|
/*If not OSX initialize SDL in the Thread*/
|
|
|
monitor_sdl_init();
|
|
monitor_sdl_init();
|
|
@@ -250,14 +247,16 @@ int monitor_sdl_refr_thread(void * param)
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
-extern void mouse_handler(SDL_Event *event);
|
|
|
|
|
-void monitor_sdl_refr_core(void)
|
|
|
|
|
|
|
+extern void
|
|
|
|
|
+mouse_handler(SDL_Event *event);
|
|
|
|
|
+void
|
|
|
|
|
+monitor_sdl_refr_core(void)
|
|
|
{
|
|
{
|
|
|
if (sdl_refr_qry != false) {
|
|
if (sdl_refr_qry != false) {
|
|
|
sdl_refr_qry = false;
|
|
sdl_refr_qry = false;
|
|
|
|
|
|
|
|
SDL_UpdateTexture(texture, NULL, tft_fb,
|
|
SDL_UpdateTexture(texture, NULL, tft_fb,
|
|
|
- MONITOR_HOR_RES * sizeof(uint32_t));
|
|
|
|
|
|
|
+ MONITOR_HOR_RES * sizeof(uint32_t));
|
|
|
SDL_RenderClear(renderer);
|
|
SDL_RenderClear(renderer);
|
|
|
/*Update the renderer with the texture containing the rendered image*/
|
|
/*Update the renderer with the texture containing the rendered image*/
|
|
|
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
|
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
|
@@ -272,29 +271,29 @@ void monitor_sdl_refr_core(void)
|
|
|
if ((&event)->type == SDL_WINDOWEVENT) {
|
|
if ((&event)->type == SDL_WINDOWEVENT) {
|
|
|
switch ((&event)->window.event) {
|
|
switch ((&event)->window.event) {
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
|
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
|
|
- case SDL_WINDOWEVENT_TAKE_FOCUS:
|
|
|
|
|
|
|
+ case SDL_WINDOWEVENT_TAKE_FOCUS:
|
|
|
#endif
|
|
#endif
|
|
|
- case SDL_WINDOWEVENT_EXPOSED:
|
|
|
|
|
-
|
|
|
|
|
- SDL_UpdateTexture(texture, NULL, tft_fb,
|
|
|
|
|
- MONITOR_HOR_RES * sizeof(uint32_t));
|
|
|
|
|
- SDL_RenderClear(renderer);
|
|
|
|
|
- SDL_RenderCopy(renderer, texture, NULL, NULL);
|
|
|
|
|
- SDL_RenderPresent(renderer);
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ case SDL_WINDOWEVENT_EXPOSED:
|
|
|
|
|
+
|
|
|
|
|
+ SDL_UpdateTexture(texture, NULL, tft_fb,
|
|
|
|
|
+ MONITOR_HOR_RES * sizeof(uint32_t));
|
|
|
|
|
+ SDL_RenderClear(renderer);
|
|
|
|
|
+ SDL_RenderCopy(renderer, texture, NULL, NULL);
|
|
|
|
|
+ SDL_RenderPresent(renderer);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*Sleep some time*/
|
|
/*Sleep some time*/
|
|
|
SDL_Delay(SDL_REFR_PERIOD);
|
|
SDL_Delay(SDL_REFR_PERIOD);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-int quit_filter(void * userdata, SDL_Event * event)
|
|
|
|
|
|
|
+int
|
|
|
|
|
+quit_filter(void *userdata, SDL_Event *event)
|
|
|
{
|
|
{
|
|
|
- (void) userdata;
|
|
|
|
|
|
|
+ (void)userdata;
|
|
|
|
|
|
|
|
if (event->type == SDL_QUIT) {
|
|
if (event->type == SDL_QUIT) {
|
|
|
sdl_quit_qry = true;
|
|
sdl_quit_qry = true;
|
|
@@ -303,7 +302,8 @@ int quit_filter(void * userdata, SDL_Event * event)
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void monitor_sdl_clean_up(void)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+monitor_sdl_clean_up(void)
|
|
|
{
|
|
{
|
|
|
SDL_DestroyTexture(texture);
|
|
SDL_DestroyTexture(texture);
|
|
|
SDL_DestroyRenderer(renderer);
|
|
SDL_DestroyRenderer(renderer);
|
|
@@ -311,34 +311,37 @@ void monitor_sdl_clean_up(void)
|
|
|
SDL_Quit();
|
|
SDL_Quit();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void monitor_sdl_init(void)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+monitor_sdl_init(void)
|
|
|
{
|
|
{
|
|
|
/*Initialize the SDL*/
|
|
/*Initialize the SDL*/
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
|
|
|
|
|
|
SDL_SetEventFilter(quit_filter, NULL);
|
|
SDL_SetEventFilter(quit_filter, NULL);
|
|
|
|
|
|
|
|
- window = SDL_CreateWindow("TFT Simulator", SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
|
- SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
|
- MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
|
|
|
|
|
|
|
+ window = SDL_CreateWindow(
|
|
|
|
|
+ "TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
|
+ MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM,
|
|
|
|
|
+ 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
|
|
|
|
|
|
|
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
|
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
|
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
|
|
|
- SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES);
|
|
|
|
|
|
|
+ SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES,
|
|
|
|
|
+ MONITOR_VER_RES);
|
|
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
|
|
|
|
|
|
|
/*Initialize the frame buffer to gray (77 is an empirical value) */
|
|
/*Initialize the frame buffer to gray (77 is an empirical value) */
|
|
|
memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
|
|
memset(tft_fb, 0x44, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
|
|
|
SDL_UpdateTexture(texture, NULL, tft_fb,
|
|
SDL_UpdateTexture(texture, NULL, tft_fb,
|
|
|
- MONITOR_HOR_RES * sizeof(uint32_t));
|
|
|
|
|
|
|
+ MONITOR_HOR_RES * sizeof(uint32_t));
|
|
|
sdl_refr_qry = true;
|
|
sdl_refr_qry = true;
|
|
|
sdl_inited = true;
|
|
sdl_inited = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void display_SDL_init()
|
|
|
|
|
|
|
+void
|
|
|
|
|
+display_SDL_init()
|
|
|
{
|
|
{
|
|
|
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
|
|
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
|
|
|
while (sdl_inited == false)
|
|
while (sdl_inited == false)
|
|
|
; /*Wait until 'sdl_refr' initializes the SDL*/
|
|
; /*Wait until 'sdl_refr' initializes the SDL*/
|
|
|
}
|
|
}
|
|
|
-
|
|
|