WIP ESP32 port

This commit is contained in:
Xavier Del Campo Romero 2024-01-29 23:58:04 +01:00
parent fd53c7da8c
commit 40c00a9aa4
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
29 changed files with 459 additions and 2 deletions

View File

@ -17,6 +17,8 @@ elseif(CMAKE_TOOLCHAIN_FILE MATCHES "win9x")
set(WIN9X_BUILD 1)
set(SDL1_2_BUILD 1)
set(exec_flags WIN32)
elseif(CMAKE_TOOLCHAIN_FILE MATCHES "esp32")
set(ESP32_BUILD 1)
else()
set(HOST_BUILD 1)
set(SDL1_2_BUILD 1)
@ -46,6 +48,8 @@ elseif(WIN9X_BUILD)
include("cmake/win9x.cmake")
elseif(HOST_BUILD)
include("cmake/host.cmake")
elseif(ESP32_BUILD)
include("cmake/esp32.cmake")
endif()
add_subdirectory("res")

18
cmake/esp32.cmake Normal file
View File

@ -0,0 +1,18 @@
set(cdroot ${CMAKE_BINARY_DIR})
if(NOT DEFINED ENV{IDF_PATH})
message(FATAL_ERROR "Please define environment variable IDF_PATH")
endif()
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
idf_build_process(esp32
BUILD_DIR ${CMAKE_BINARY_DIR})
target_link_libraries(${PROJECT_NAME}
PRIVATE
idf:freertos
idf::spi_flash
idf::newlib
)
idf_build_executable(${PROJECT_NAME})

View File

@ -37,6 +37,15 @@ function(sprite)
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SPRITE_NAME})
add_dependencies(${PROJECT_NAME} ${SPRITE_NAME}_img)
add_dependencies(${SPRITE_NAME}_img tools)
elseif(ESP32_BUILD)
add_custom_command(OUTPUT ${cdroot}/${SPRITE_NAME}.bmp
COMMAND cp ${SPRITE_NAME}_24.bmp ${cdroot}/${SPRITE_NAME}.bmp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${SPRITE_NAME}_24.bmp
VERBATIM)
add_custom_target(${SPRITE_NAME}_img
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${SPRITE_NAME}_24.bmp)
add_dependencies(${PROJECT_NAME} ${SPRITE_NAME}_img)
endif()
endfunction()
@ -76,6 +85,9 @@ function(sound)
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SOUND_NAME})
add_dependencies(${PROJECT_NAME} ${SOUND_NAME}_snd)
add_dependencies(${SOUND_NAME}_snd tools)
elseif(ESP32_BUILD)
add_custom_target(${SOUND_NAME}_snd
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${SOUND_NAME}.wav)
endif()
endfunction()

View File

@ -4,6 +4,8 @@ if(PS1_BUILD)
set(inc ${inc} "ps1/inc")
elseif(SDL1_2_BUILD)
set(inc ${inc} "sdl-1.2/inc")
elseif(ESP32_BUILD)
set(inc ${inc} "esp32/inc")
endif()
add_library(container "src/container.c")

View File

@ -0,0 +1,6 @@
#ifndef CONTAINER_ESP32_H
#define CONTAINER_ESP32_H
#define container_load(path, list, n) container_load_ex(path, list, n)
#endif /* CONTAINER_ESP32_H */

View File

@ -26,6 +26,15 @@ elseif(SDL1_2_BUILD)
"sdl-1.2/src/quad.c")
set(deps ${deps} SDL::SDL)
set(privdeps ${privdeps} header SDL::SDL_gfx)
elseif(ESP32_BUILD)
set(inc ${inc} "esp32/inc")
set(privinc ${privinc} "esp32/privinc")
set(src ${src}
"esp32/src/env.c"
"esp32/src/line.c"
"esp32/src/rect.c"
"esp32/src/sprite.c"
"esp32/src/quad.c")
endif()
add_library(gfx ${src})

View File

@ -0,0 +1,55 @@
#ifndef GFX_ESP32_H
#define GFX_ESP32_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct sprite
{
short x, y, w, h;
unsigned char u, v;
bool transparent;
};
struct quad
{
unsigned char r, g, b;
short x0, x1, x2, x3;
short y0, y1, y2, y3;
unsigned char u0, u1, u2, u3;
unsigned char v0, v1, v2, v3;
short w, h;
bool transparent;
};
struct rect
{
unsigned char r, g, b;
short x, y, w, h;
bool stp;
};
struct stp_4line
{
short x, y;
unsigned char r, g, b;
struct stp_4line_vtx
{
unsigned char r, g, b;
short x, y;
} vertices[4];
};
#define common_get_or_ret(t, x, ret) \
struct t x##__, *const x = &x##__
#ifdef __cplusplus
}
#endif
#endif /* GFX_ESP32_H */

View File

@ -0,0 +1,21 @@
#ifndef GFX_ESP32_PRIVATE_H
#define GFX_ESP32_PRIVATE_H
#include <gfx.h>
#ifdef __cplusplus
extern "C"
{
#endif
enum
{
SCREEN_W = 320,
SCREEN_H = 240
};
#ifdef __cplusplus
}
#endif
#endif /* GFX_ESP32_PRIVATE_H */

59
src/gfx/esp32/src/env.c Normal file
View File

@ -0,0 +1,59 @@
#include <gfx.h>
#include <gfx_private.h>
#include <esp32/gfx_private.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void gfx_deinit(void)
{
}
int gfx_display_size(short *const w, short *const h)
{
*w = SCREEN_W;
*h = SCREEN_H;
return 0;
}
int gfx_init(void)
{
return -1;
}
bool gfx_inside_drawenv(const short x, const short y, const short w,
const short h)
{
return (x + w >= 0)
&& x < screen_w
&& (y + h >= 0)
&& y < screen_h;
}
int gfx_toggle_fullscreen(void)
{
return -1;
}
int gfx_set_fullscreen(const short w, const short h)
{
return -1;
}
bool gfx_fullscreen_available(void)
{
return false;
}
bool gfx_fullscreen(void)
{
return true;
}
int gfx_draw(void)
{
return -1;
}

17
src/gfx/esp32/src/line.c Normal file
View File

@ -0,0 +1,17 @@
#include <gfx.h>
#include <gfx/port.h>
#include <esp32/gfx_private.h>
#include <stddef.h>
void stp_4line_init(struct stp_4line *const l)
{
}
void semitrans_stp_4line_init(struct stp_4line *r)
{
}
int stp_4line_sort(struct stp_4line *const r)
{
return 0;
}

15
src/gfx/esp32/src/quad.c Normal file
View File

@ -0,0 +1,15 @@
#include <gfx.h>
#include <gfx/port.h>
#include <esp32/gfx_private.h>
#include <stddef.h>
#include <stdlib.h>
int quad_from_sprite(const struct sprite *const s, struct quad *const q)
{
return -1;
}
int quad_sort(struct quad *const q)
{
return -1;
}

19
src/gfx/esp32/src/rect.c Normal file
View File

@ -0,0 +1,19 @@
#include <gfx.h>
#include <gfx/port.h>
#include <esp32/gfx_private.h>
int rect_sort(struct rect *const r)
{
return -1;
}
void rect_init(struct rect *const r)
{
*r = (const struct rect){0};
}
void semitrans_rect_init(struct rect *const r)
{
rect_init(r);
r->stp = true;
}

View File

@ -0,0 +1,23 @@
#include <gfx.h>
#include <gfx/port.h>
#include <esp32/gfx_private.h>
void sprite_free(struct sprite *const s)
{
}
int sprite_clone(const struct sprite *const src, struct sprite *const dst)
{
*dst = *src;
return 0;
}
int sprite_from_fp(struct sprite *const s, FILE *const f)
{
return -1;
}
int sprite_sort(struct sprite *const s)
{
return -1;
}

View File

@ -9,6 +9,9 @@ elseif(SDL1_2_BUILD)
set(src ${src} "sdl-1.2/src/keyboard.c")
set(inc ${inc} "sdl-1.2/inc")
set(privdeps ${privdeps} SDL::SDL)
elseif(ESP32_BUILD)
set(src ${src} "esp32/src/keyboard.c")
set(inc ${inc} "esp32/inc")
endif()
add_library(keyboard ${src})

View File

@ -0,0 +1,20 @@
#ifndef KEYBOARD_SDL_1_2_H
#define KEYBOARD_SDL_1_2_H
#include <keyboard.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct keyboard_port
{
int dummy;
};
#ifdef __cplusplus
}
#endif
#endif /* KEYBOARD_SDL_1_2_H */

View File

@ -0,0 +1,12 @@
#include <keyboard.h>
#include <keyboard/port.h>
#include <keyboard/key.h>
void keyboard_update(struct keyboard *const k)
{
}
bool keyboard_available(void)
{
return false;
}

View File

@ -14,6 +14,9 @@ else()
if(WIN9X_BUILD OR ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
set(src ${src} "win9x/src/serial.c")
elseif(ESP32_BUILD)
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
set(priv_deps ${priv_deps} idf::lwip idf::esp_phy)
else()
# Assume POSIX if the command below executes successfully
execute_process(COMMAND uname -m RESULT_VARIABLE result OUTPUT_QUIET)

View File

@ -10,6 +10,9 @@ elseif(SDL1_2_BUILD)
set(src ${src} "sdl-1.2/src/pad.c")
set(inc ${inc} "sdl-1.2/inc")
set(deps ${deps} SDL::SDL)
elseif(ESP32_BUILD)
set(src ${src} "esp32/src/pad.c")
set(inc ${inc} "esp32/inc")
endif()
add_library(pad ${src})

View File

@ -0,0 +1,18 @@
#ifndef PAD_ESP32_H
#define PAD_ESP32_H
#ifdef __cplusplus
extern "C"
{
#endif
struct pad_port
{
int dummy;
};
#ifdef __cplusplus
}
#endif
#endif /* PAD_SDL_1_2_H */

20
src/pad/esp32/src/pad.c Normal file
View File

@ -0,0 +1,20 @@
#include <pad.h>
#include <stdio.h>
void pad_port_update(struct pad *const p)
{
}
void pad_init(const int id, struct pad *const p)
{
}
size_t pad_count(void)
{
return 1;
}
const char *pad_name(const int id)
{
return NULL;
}

View File

@ -11,6 +11,10 @@ elseif(SDL1_2_BUILD)
set(inc ${inc} "sdl-1.2/inc")
set(deps ${deps} SDL::SDL_mixer)
set(privdeps ${privdeps} SDL::SDL header)
elseif(ESP32_BUILD)
set(src
"esp32/src/sound.c")
set(inc ${inc} "esp32/inc")
endif()
add_library(sfx ${src})

View File

@ -0,0 +1,20 @@
#ifndef SFX_ESP32_H
#define SFX_ESP32_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct sound
{
bool loop;
};
#ifdef __cplusplus
}
#endif
#endif /* SFX_SDL1_2_H */

28
src/sfx/esp32/src/sound.c Normal file
View File

@ -0,0 +1,28 @@
#include <sfx.h>
#include <sfx/port.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
void sfx_free(struct sound *const s)
{
}
int sfx_play(const struct sound *const s)
{
return -1;
}
int sfx_sound_from_fp(struct sound *const s, FILE *const f, const size_t sz)
{
return -1;
}
void sfx_deinit(void)
{
}
int sfx_init(void)
{
return -1;
}

View File

@ -17,6 +17,10 @@ elseif(SDL1_2_BUILD)
else()
set(src ${src} "sdl-1.2/src/stubs.c")
endif()
elseif(ESP32_BUILD)
set(src "esp32/src/system.c")
set(inc ${inc} "esp32/inc")
set(privinc ${privinc} "esp32/privinc")
endif()
add_library(system ${src})

View File

@ -0,0 +1,13 @@
#ifndef INIT_ESP32_H
#define INIT_ESP32_H
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif /* INIT_SDL_H */

View File

@ -0,0 +1,15 @@
#ifndef SYSTEM_PRIVATE_H
#define SYSTEM_PRIVATE_H
#ifdef __cplusplus
extern "C"
{
#endif
int system_init_os(void);
#ifdef __cplusplus
}
#endif
#endif /* SYSTEM_PRIVATE_H */

View File

@ -0,0 +1,6 @@
#include <system_private.h>
int system_init_os(void)
{
return 0;
}

View File

@ -0,0 +1,25 @@
#include <system.h>
#include <system_private.h>
#include <gfx.h>
#include <net.h>
#include <sfx.h>
#include <stdio.h>
#include <stdlib.h>
bool system_can_exit(void)
{
return false;
}
void system_loop(void)
{
}
void system_deinit(void)
{
}
int system_init(void)
{
return -1;
}

View File

@ -8,5 +8,8 @@ endif()
add_library(transport ${src})
target_include_directories(transport PUBLIC "inc" PRIVATE "privinc")
enable_testing()
add_subdirectory(test)
if(NOT CMAKE_CROSSCOMPILING)
enable_testing()
add_subdirectory(test)
endif()