diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index c24e935..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -# CMakeList.txt : Top-level CMake project file, do global configuration -# and include sub-projects here. -# -cmake_minimum_required (VERSION 3.8) - -cmake_policy(SET CMP0074 NEW) -cmake_policy(SET CMP0077 NEW) - - -set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) -set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) -set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) -add_subdirectory(lib/glfw-3.3.8) - - -set(PNG_BUILD_ZLIB ON) -set(PNG_SHARED OFF) -set(PNG_STATIC ON) -set(PNG_EXECUTABLES OFF) -set(PNG_TESTS OFF) -set(BUILD_SHARED_LIBS OFF) -set(SKIP_INSTALL_ALL ON) -set(ZLIB_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/lib/zlib-1.2.13" "${CMAKE_BINARY_DIR}/lib/zlib-1.2.13") -add_subdirectory(lib/zlib-1.2.13) -#set(ZLIB_LIBRARY zlib) -add_subdirectory(lib/lpng1639) - -project ("glew") - -add_library(glew STATIC "lib/glew-2.1.0/src/glew.c" "lib/glew-2.1.0/include/GL/glew.h") -if(WIN32) - target_link_libraries(glew opengl32) -else() - target_link_libraries(glew GL) -endif() -target_include_directories(glew PRIVATE lib/glew-2.1.0/include) -set_target_properties(glew PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED YES C_EXTENSIONS YES) -set_target_properties(glew PROPERTIES COMPILE_FLAGS "-Wno-everything") -target_compile_definitions(glew PUBLIC GLEW_STATIC) - -project ("skunkworks") -set(SOURCE - src/gl.h - src/skunkworks.c - src/skunkworks.h - src/test.c - src/vec2i.c - src/window.c - - include/vec2i.h - include/window.h -) - -add_executable (skunkworks ${SOURCE}) -target_link_libraries(skunkworks glfw glew png_static zlibstatic) -target_include_directories(skunkworks PRIVATE - lib/glfw-3.8.8/include - lib/glew-2.1.0/include - lib/lpng1639 - build/lib/lpng1639 - include -) - -set_target_properties(skunkworks PROPERTIES C_STANDARD 90 C_STANDARD_REQUIRED YES C_EXTENSIONS NO) -set_target_properties(skunkworks PROPERTIES COMPILE_FLAGS "-Wall -Werror -pedantic") -add_custom_command(TARGET skunkworks POST_BUILD - COMMAND $<$:llvm-strip> - ARGS --strip-all $) diff --git a/examples/gsa_simple.c b/examples/gsa_simple.c index ae071ff..9fc635a 100644 --- a/examples/gsa_simple.c +++ b/examples/gsa_simple.c @@ -1,7 +1,9 @@ #include "gamepad.h" +#include "gsa_text.h" #include void init() { + i32 x, y; for(y = 0; y < 11; ++y) { @@ -21,6 +23,12 @@ void init() { maps[0].tiles[17][y + 1] = 0x1201; maps[0].tiles[18][y + 1] = 0x1202; } + + maps[1].half_tile = true; + + /* maps[1].tiles[1][1] = gsa_get_char_tile(0x1010, 's'); */ + font = 0x1010; + gsa_write_text(1, 7, 3, "Game Skunk Advance!!! <3"); } void tick() { diff --git a/include/gsa.h b/include/gsa.h index f77740f..d5b0e02 100644 --- a/include/gsa.h +++ b/include/gsa.h @@ -22,6 +22,7 @@ #endif #include "gsa_input.h" +#include "gsa_text.h" #include "skunkworks.h" #include "vec2i.h" #include "window.h" @@ -39,6 +40,7 @@ struct gsa_map { u16 tiles[TILEMAP_MAX_SIZE][TILEMAP_MAX_SIZE]; i32 w, h; i32 scrollx, scrolly; + bool half_tile; }; extern struct gsa_sprite sprites[MAX_SPRITES]; diff --git a/include/gsa_text.h b/include/gsa_text.h new file mode 100644 index 0000000..d97c802 --- /dev/null +++ b/include/gsa_text.h @@ -0,0 +1,11 @@ +#ifndef GUARD_B34FE9B65AE750F0DF88280BF07BA151 +#define GUARD_B34FE9B65AE750F0DF88280BF07BA151 + +#include "types.h" + +i16 gsa_get_char_tile(u8 ch); +void gsa_write_text(u8 map, u16 x, u16 y, char *str); + +extern i16 font; + +#endif /* GUARD_B34FE9B65AE750F0DF88280BF07BA151 */ diff --git a/meson.build b/meson.build index 32ca09d..84d74fb 100644 --- a/meson.build +++ b/meson.build @@ -47,6 +47,7 @@ skunk_sources = [ 'src/gamepad.c', 'src/gsa.c', 'src/gsa_input.c', + 'src/gsa_text.c', 'src/image32.c', 'src/image8.c', 'src/scaler.c', diff --git a/src/gsa.c b/src/gsa.c index 89a34d9..84d5ded 100644 --- a/src/gsa.c +++ b/src/gsa.c @@ -131,12 +131,13 @@ static void add_render_vert(f32 x, f32 y, f32 tx, f32 ty) { ++next_render_vert; } -static void rect(f32 x, f32 y, f32 w, f32 h, i16 tile) { +static void rect(f32 x, f32 y, f32 w, f32 h, i16 tile, bool half) { f32 tx, ty, ts; + f32 tilesize = half ? 8.f : 16.f; - tx = ((tile % 256) * 16.f) / 4096.f; - ty = ((tile / 256) * 16.f) / 4096.f; - ts = 1.f / 256.f; + tx = ((tile % 256) * tilesize) / 4096.f; + ty = ((tile / 256) * tilesize) / 4096.f; + ts = 1.f / (4096.f / tilesize); if(next_render_vert >= MAX_RENDER_VERTS) { sw_error( @@ -165,7 +166,7 @@ static void update_palette_gl() { } void _gsa_tick() { - i32 i, x, y, startx, starty, endx, endy; + i32 i, x, y, startx, starty, endx, endy, tcmult, tilesize; _gsa_input_tick(); @@ -174,10 +175,12 @@ void _gsa_tick() { next_render_vert = 0; for(i = 0; i < MAX_TILEMAPS; ++i) { - startx = maps[i].scrollx / 16; - starty = maps[i].scrolly / 16; - endx = i32_min(TILEMAP_MAX_SIZE, startx + 20); - endy = i32_min(TILEMAP_MAX_SIZE, starty + 12); + tcmult = maps[i].half_tile ? 2 : 1; + tilesize = maps[i].half_tile ? 8 : 16; + startx = maps[i].scrollx / tilesize; + starty = maps[i].scrolly / tilesize; + endx = i32_min(TILEMAP_MAX_SIZE, startx + 20 * tcmult); + endy = i32_min(TILEMAP_MAX_SIZE, starty + 12 * tcmult); startx = i32_max(0, startx); starty = i32_max(0, starty); @@ -186,11 +189,12 @@ void _gsa_tick() { u16 tile = maps[i].tiles[x][y]; if(tile) { rect( - x * 16 - maps[i].scrollx, - y * 16 - maps[i].scrolly, - 16, - 16, - tile + x * tilesize - maps[i].scrollx, + y * tilesize - maps[i].scrolly, + tilesize, + tilesize, + tile, + maps[i].half_tile ); } } @@ -199,7 +203,7 @@ void _gsa_tick() { for(i = 0; i < MAX_SPRITES; ++i) { if(sprites[i].tile > 0) { - rect(sprites[i].x, sprites[i].y, 16, 16, sprites[i].tile); + rect(sprites[i].x, sprites[i].y, 16, 16, sprites[i].tile, false); } } glClearColor( diff --git a/src/gsa_text.c b/src/gsa_text.c new file mode 100644 index 0000000..07adca1 --- /dev/null +++ b/src/gsa_text.c @@ -0,0 +1,18 @@ +#include "gsa_text.h" +#define GSA_NOMAIN +#include "gsa.h" + +i16 font; + +i16 gsa_get_char_tile(u8 ch) { + return font + (ch % 0x10) + (ch / 0x10) * 0x100; +} + +void gsa_write_text(u8 map, u16 x, u16 y, char *str) { + u8 *strp = (u8 *)str; + while(*strp) { + maps[map].tiles[x][y] = gsa_get_char_tile(*strp); + ++strp; + ++x; + } +}