Skip to content

Commit 026a74e

Browse files
feat: revision 0.0.17 (#8)
* fix: change background color * fix: correct colors RGB * fix: wrap draw rect * fix: wrap font size * docs: update links in README.md * style: refact rect wrap * docs: bump version * feat: add again FPS_MODE config * feat: todo geoclip_line * feat: better debug game/engine lua script * feat: start support love2d * feat: new logos for love and core native * feat: colorize gly engine logo * feat: alias for love samples in cmake * feat: change splashscreen in cmake * feat: add flag FPS_MODE to cmake * feat: add flag FPS_DELTA to cmake * docs: mainpage in doxygen * docs: add params in lua api * docs: link for gly type * docs: create .gitattributes to ignore lua
1 parent a14b2e6 commit 026a74e

File tree

14 files changed

+399
-79
lines changed

14 files changed

+399
-79
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.lua linguist-generated

.github/workflows/DOCS.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/checkout@master
2424
-
2525
run: |
26-
docker run --rm -v $(pwd):/app -w /app rodrigodornelles/doxygen doxygen
26+
docker run --rm -v $(pwd):/app -w /app rodrigodornelles/doxygen:lua doxygen
2727
-
2828
uses: actions/configure-pages@v3
2929
-

CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,29 @@ list(REMOVE_ITEM lua_files "${LUA_DIR}/onelua.c")
8080
add_library(lua-static STATIC ${lua_files})
8181
find_program(LUAC lua PATHS ${LUA_DIR} REQUIRED NO_DEFAULT_PATH)
8282

83+
# Loading / Splash Screen
84+
if(DEFINED ENGINE AND ENGINE STREQUAL "@love")
85+
set(ENGINE_LOGO 2 CACHE STRING "" FORCE)
86+
elseif(DEFINED ENGINE AND ENGINE MATCHES "^\\@")
87+
set(ENGINE_LOGO 1 CACHE STRING "" FORCE)
88+
else()
89+
set(ENGINE_LOGO 3 CACHE STRING "" FORCE)
90+
endif()
91+
target_compile_definitions(${PROJECT_NAME} PRIVATE ENGINE_LOGO=${ENGINE_LOGO})
92+
8393
# Engine
8494
set(ENGINE_VERSION "0.0.16")
8595
set(ENGINE_DIR "${CMAKE_SOURCE_DIR}/vendor/engine")
8696
set(ENGINE_CLI "${ENGINE_DIR}/src/cli/main.lua")
8797
set(ENGINE_DOWNLOAD "https://github.com/gamelly/gly-engine/archive/refs/tags/${ENGINE_VERSION}.tar.gz")
8898
set(ENGINE_HEADER "${ENGINE_DIR}/bytecode.h")
99+
set(ENGINE_LOVE_DIR1 "${ENGINE_DIR}/love")
100+
set(ENGINE_LOVE_DIR2 "${CMAKE_SOURCE_DIR}/vendor/love")
101+
set(ENGINE_LOVE_DOWNLOAD "https://github.com/gamelly/love-engine/archive/refs/heads/main.zip")
89102
if(NOT EXISTS ${ENGINE_HEADER})
90103
FetchContent_Populate(dep_engine URL ${ENGINE_DOWNLOAD} SOURCE_DIR ${ENGINE_DIR})
91104
file(MAKE_DIRECTORY "${ENGINE_DIR}/lite")
105+
file(MAKE_DIRECTORY "${ENGINE_DIR}/love")
92106
file(MAKE_DIRECTORY "${ENGINE_DIR}/native")
93107
file(MAKE_DIRECTORY "${ENGINE_DIR}/samples/template")
94108
execute_process(
@@ -108,6 +122,11 @@ if(NOT EXISTS ${ENGINE_HEADER})
108122
set(ENGINE "@lite")
109123
endif()
110124
if(DEFINED ENGINE)
125+
if (ENGINE STREQUAL "@love" AND NOT EXISTS "${ENGINE_LOVE_DIR1}/main.lua")
126+
message(WARNING "currently LOVE2D is experimental.")
127+
FetchContent_Populate(dep_love URL ${ENGINE_LOVE_DOWNLOAD} SOURCE_DIR ${ENGINE_LOVE_DIR2})
128+
file(COPY "${ENGINE_LOVE_DIR2}/src/main.lua" DESTINATION "${ENGINE_LOVE_DIR1}")
129+
endif()
111130
if (ENGINE MATCHES "^\\@")
112131
string(SUBSTRING "${ENGINE}" 1 -1 ENGINE)
113132
set(ENGINE "${ENGINE_DIR}/${ENGINE}/main.lua")
@@ -126,6 +145,10 @@ endif()
126145
# Game
127146
string(LENGTH "${GAME}" GAME_LENGTH)
128147
set(GAME_HEADER "${CMAKE_SOURCE_DIR}/vendor/game/bytecode.h")
148+
if (DEFINED GAME AND GAME_LENGTH AND GAME MATCHES "^\\@love:")
149+
string(SUBSTRING "${GAME}" 6 -1 GAME)
150+
set(GAME "${ENGINE_LOVE_DIR2}/samples/${GAME}/main.lua")
151+
endif()
129152
if (DEFINED GAME AND GAME_LENGTH AND GAME MATCHES "^\\@")
130153
string(SUBSTRING "${GAME}" 1 -1 GAME)
131154
set(GAME "${ENGINE_DIR}/samples/${GAME}/game.lua")
@@ -155,5 +178,13 @@ if(LUA_OPTMIZE)
155178
)
156179
endif()
157180

181+
# CFGs
182+
if(DEFINED FPS_MODE)
183+
target_compile_definitions(${PROJECT_NAME} PRIVATE FPS_MODE=${FPS_MODE})
184+
endif()
185+
if(DEFINED FPS_DELTA)
186+
target_compile_definitions(${PROJECT_NAME} PRIVATE FPS_DELTA=${FPS_DELTA})
187+
endif()
188+
158189
target_link_libraries(${PROJECT_NAME} lua-static)
159190
target_link_libraries(${PROJECT_NAME} m)

Doxyfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Custom Configs
22
DOXYFILE_ENCODING = UTF-8
33
PROJECT_NAME = "Core Native GBA"
4-
PROJECT_NUMBER = 0.0.12
4+
PROJECT_NUMBER = 0.0.17
55
PROJECT_BRIEF = "create your own game-engine with just lua for nitendo game boy advance console."
66
PROJECT_LOGO =
77
OUTPUT_DIRECTORY = .
@@ -13,12 +13,12 @@ HAVE_DOT = YES
1313
EXTRACT_ALL = YES
1414
USE_MATHJAX = YES
1515
EXTRACT_STATIC = YES
16-
SHORT_NAMES = YES
16+
SHORT_NAMES = NO
1717
OPTIMIZE_OUTPUT_FOR_C = YES
1818
INLINE_GROUPED_CLASSES = YES
1919
INLINE_SIMPLE_STRUCTS = YES
2020
TYPEDEF_HIDES_STRUCT = YES
21-
SOURCE_BROWSER = NO
21+
SOURCE_BROWSER = YES
2222
VERBATIM_HEADERS = NO
2323
PREDEFINED = DOXYGEN=
2424
PLANTUML_JAR_PATH = $(PLANTUML_JAR_PATH)
@@ -27,7 +27,9 @@ PLANTUML_INCLUDE_PATH =
2727
OUTPUT_LANGUAGE = English
2828
FILE_PATTERNS = *.c *.h
2929
EXTENSION_MAPPING = h=c
30-
INPUT = src
30+
FILTER_PATTERNS = *.md="lua mainpage.lua"
31+
INPUT = README.md src
32+
USE_MDFILE_AS_MAINPAGE = README.md
3133
MARKDOWN_ID_STYLE = GITHUB
3234
# Theme: https://jothepro.github.io/doxygen-awesome-css/
3335
GENERATE_TREEVIEW = YES

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,48 @@
33
[<img align="right" height="168px" src="https://raw.githubusercontent.com/RodrigoDornelles/RodrigoDornelles/refs/heads/master/media/pong-gba-gly-engine.gif">](#core-native-gba)
44

55
This project is a basic micro-gameengine to run lua in the **Nintendo Game Boy Advanced**,
6-
which can be expanded to a custom engine, such as [Gly Engine](https://github.com/gamelly/gly-engine).
6+
which can be expanded to a custom engine, such as [Gly Engine](https://github.com/gamelly/gly-engine) or [Love2d](https://github.com/gamelly/love-engine).
77

88
* [online ide](https://playground.gamely.com.br)
9-
* [limitations](https://docs.gamely.com.br/a00232#limits-in-gameboy-advanced)
10-
* [documentation](https://docs.gamely.com.br/a00188.html)
9+
* [limitations](https://docs.gamely.com.br/limits#limits-in-gameboy-advanced)
10+
* [documentation](https://docs.gamely.com.br/group__homebrew#nintendo_gba)
1111

1212
<br/>
1313

1414
| :warning: Attention |
1515
| :------------------ |
1616
| there is no sanitization, error handling or observation of resource consumption, all of this takes up precious CPU time, bad code will make the game crash with a black screen.<br><br>**Developing a multiplatform game with desktop support is recommended, especially for testing Lua code!** |
1717

18-
## How to build
18+
## Building: [Pong](https://github.com/gamelly/gly-engine/blob/main/samples/pong/game.lua) Example with `Gly Engine`
1919

20-
use [devkitpro/devkitarm](https://hub.docker.com/r/devkitpro/devkitarm) container if you do not have [devkitpro](https://devkitpro.org/wiki/devkitPro_pacman) installed.
21-
22-
### Clone repo
23-
20+
```sql
21+
cmake -Bbuild -H. -DGAME=@pong
2422
```
25-
git clone https://github.com/gamelly/core-native-gba
23+
24+
```sql
25+
make -C build
2626
```
2727

28-
### Configure project
28+
## Building: [Pong](https://github.com/gamelly/love-engine/blob/main/samples/pong/main.lua) Example with `Love2D`
2929

30+
```sql
31+
cmake -Bbuild -H. -DGAME=@love:pong -DENGINE=@love
3032
```
31-
cmake -Bbuild -H. -DGAME=vendor/engine/examples/pong/game.lua
33+
34+
```sql
35+
make -C build
3236
```
3337

34-
### Build cartbridge rom `.gba`
38+
## Building: Your Own Game with a Self-Made Engine
3539

40+
```sql
41+
cmake -Bbuild -H. -DGAME=path/game.lua -DENGINE=path/engine.lua
3642
```
43+
44+
```sql
3745
make -C build
3846
```
3947

40-
## Run
48+
---
4149

42-
```
43-
VisualBoyAdvance build/bin/game.gba
44-
```
50+
:whale: use [devkitpro/devkitarm](https://hub.docker.com/r/devkitpro/devkitarm) docker image if you do not have [devkitpro](https://devkitpro.org/wiki/devkitPro_pacman) installed.

mainpage.lua

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/draw.c

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ static int native_draw_flush(lua_State *L)
1010
return 0;
1111
}
1212

13+
/**
14+
* @param[in] color @c int
15+
*/
1316
static int native_draw_clear(lua_State *L)
1417
{
1518
color_t t = { .pixel2 = luaL_checkinteger(L, 1) };
@@ -19,6 +22,9 @@ static int native_draw_clear(lua_State *L)
1922
return 0;
2023
}
2124

25+
/**
26+
* @param[in] color @c int
27+
*/
2228
static int native_draw_color(lua_State *L)
2329
{
2430
color_t t = { .pixel2 = luaL_checkinteger(L, 1) };
@@ -28,30 +34,57 @@ static int native_draw_color(lua_State *L)
2834
return 0;
2935
}
3036

37+
/**
38+
* @param[in] mode @c int
39+
* @param[in] x @c double
40+
* @param[in] y @c double
41+
* @param[in] width @c double
42+
* @param[in] height @c double
43+
*/
3144
static int native_draw_rect(lua_State *L)
3245
{
3346
uint8_t mode = luaL_checkinteger(L, 1);
34-
uint8_t posx = luaL_checknumber(L, 2);
35-
uint8_t posy = luaL_checknumber(L, 3);
36-
uint8_t width = luaL_checknumber(L, 4);
37-
uint8_t height = luaL_checknumber(L, 5);
38-
draw_queue_push(48, mode, 0, 1, 0);
39-
draw_queue_push(50, posx, posy, width, height);
47+
int32_t posx = luaL_checknumber(L, 2);
48+
int32_t posy = luaL_checknumber(L, 3);
49+
int32_t width = luaL_checknumber(L, 4);
50+
int32_t height = luaL_checknumber(L, 5);
51+
52+
if (geoclip_rect(&posx, &posy, &width, &height)) {
53+
draw_queue_push(48, mode, 0, 1, 0);
54+
draw_queue_push(50, (uint8_t) posx, (uint8_t) posy, (uint8_t) width, (uint8_t) height);
55+
}
56+
4057
lua_settop(L, 0);
4158
return 0;
4259
}
4360

61+
/**
62+
* @param[in] x1 @c double
63+
* @param[in] y1 @c double
64+
* @param[in] x2 @c double
65+
* @param[in] y2 @c double
66+
*/
4467
static int native_draw_line(lua_State *L)
4568
{
46-
uint8_t x1 = luaL_checknumber(L, 1);
47-
uint8_t y1 = luaL_checknumber(L, 2);
48-
uint8_t x2 = luaL_checknumber(L, 3);
49-
uint8_t y2 = luaL_checknumber(L, 4);
50-
draw_queue_push(51, x1, y1, x2, y2);
69+
int32_t x1 = luaL_checknumber(L, 1);
70+
int32_t y1 = luaL_checknumber(L, 2);
71+
int32_t x2 = luaL_checknumber(L, 3);
72+
int32_t y2 = luaL_checknumber(L, 4);
73+
74+
if (geoclip_line(&x1, &y1, &x2, &y2)) {
75+
draw_queue_push(51, (uint8_t) x1, (uint8_t) y1, (uint8_t) x2, (uint8_t) y2);
76+
}
77+
5178
lua_settop(L, 0);
5279
return 0;
5380
}
5481

82+
83+
/**
84+
* @param[in] source @c string
85+
* @param[in] x @c double
86+
* @param[in] y @c double
87+
*/
5588
static int native_draw_image(lua_State *L) {
5689
uint8_t x = luaL_checknumber(L, 2);
5790
uint8_t y = luaL_checknumber(L, 3);

src/draw_color.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@ uint8_t draw_mode;
1010
void draw_cmd_color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
1111
{
1212
if (draw_mode != 3) {
13-
tint.c16.color.r = r;
14-
tint.c16.color.g = g;
15-
tint.c16.color.b = b;
13+
tint.c16.color.r = r>>3;
14+
tint.c16.color.g = g>>3;
15+
tint.c16.color.b = b>>3;
1616
} else {
17-
clear.c16.color.r = r;
18-
clear.c16.color.g = g;
19-
clear.c16.color.b = b;
17+
clear.c16.color.r = r>>3;
18+
clear.c16.color.g = g>>3;
19+
clear.c16.color.b = b>>3;
2020
}
2121

2222
if (flush_mode) {
23+
static const uint32_t *end = (uint32_t *) (0x06000000 + (240 * 160 * 2));
24+
static uint16_t old_clear = 0;
2325
draw_color.arr[0] = clear.pixel;
2426
draw_color.arr[1] = clear.pixel;
27+
if (old_clear != clear.pixel) {
28+
uint32_t *i = (uint32_t *) 0x06000000;
29+
while (i < end) {
30+
*i++ = draw_color.pixel2;
31+
}
32+
old_clear = clear.pixel;
33+
}
2534
} else {
2635
draw_color.arr[0] = tint.pixel;
2736
draw_color.arr[1] = tint.pixel;

src/draw_logo.c

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,64 @@
11
#include "zeebo.h"
22

33
#ifndef ENGINE_LOGO
4-
#define ENGINE_LOGO 1
4+
#error invalid ENGINE_LOGO
55
#endif
66

7+
/**
8+
* https://github.com/gamelly/gly-type
9+
*/
710
extern void gly_type_render(uint8_t, uint8_t, uint8_t, char*, void*);
811

912
void draw_logo()
1013
{
11-
#if ENGINE_LOGO != 0
14+
#if ENGINE_LOGO > 0
1215
draw_queue_page(1);
13-
draw_queue_push(49, 0xFF, 0xFF, 0xFF, 0);
1416
draw_queue_push(48, 3, 0, 1, 0);
1517
draw_queue_push(49, 0, 0, 0, 0);
1618
#if ENGINE_LOGO == 1
19+
static const uint8_t ver_x = 97;
20+
static const uint8_t ver_y = 80;
21+
draw_queue_push(48, 0, 0, 1, 0);
22+
draw_queue_push(49, 0x00, 0x00, 0xFF, 0);
23+
draw_queue_push(50, 90, 45, 50, 15);
24+
draw_queue_push(49, 0x00, 0xFF, 0x67, 0);
25+
draw_queue_push(50, 90, 45+15, 50, 5);
26+
draw_queue_push(49, 0xFF, 0xe7, 0x00, 0);
27+
draw_queue_push(50, 90, 45+20, 50, 5);
28+
draw_queue_push(49, 0xFF, 0x76, 0x00, 0);
29+
draw_queue_push(50, 90, 45+25, 50, 5);
30+
draw_queue_push(49, 0xFF, 0x00, 0x00, 0);
31+
draw_queue_push(50, 90, 45+30, 50, 5);
32+
draw_queue_push(49, 0xFF, 0x00, 0xFF, 0);
33+
draw_queue_push(50, 90, 45+35, 50, 10);
34+
draw_queue_push(48, 1, 0, 1, 0);
35+
draw_queue_push(49, 0xFF, 0xFF, 0xFF, 0);
36+
gly_type_render(95, 56, 12, "gly", draw_queue_clojure(51));
37+
gly_type_render(95, 72, 5, "engine", draw_queue_clojure(51));
38+
draw_queue_push(50, 90, 45, 50, 45);
39+
#elif ENGINE_LOGO == 2
40+
static const uint8_t ver_x = 97;
41+
static const uint8_t ver_y = 84;
42+
draw_queue_push(48, 0, 0, 1, 0);
43+
draw_queue_push(49, 0x80, 0xC0, 0xFF, 0);
44+
draw_queue_push(50, 90, 45, 50, 22);
45+
draw_queue_push(49, 0xFF, 0x80, 0x80, 0);
46+
draw_queue_push(50, 90, 45+22, 50, 23);
47+
draw_queue_push(48, 1, 0, 1, 0);
48+
draw_queue_push(49, 0xFF, 0xFF, 0xFF, 0);
49+
gly_type_render(95, 67-5, 9, "LOVE", draw_queue_clojure(51));
50+
draw_queue_push(51, 90+40, 45+2, 90+48, 45+2);
51+
draw_queue_push(51, 90+48, 45+2, 90+48, 45+6);
1752
draw_queue_push(50, 90, 45, 50, 45);
18-
gly_type_render(95, 60, 12, "gly", draw_queue_clojure(51));
19-
#else
20-
gly_type_render(95, 67, 5, "native", draw_queue_clojure(51));
53+
#elif ENGINE_LOGO == 3
54+
static const uint8_t ver_x = 107;
55+
static const uint8_t ver_y = 80;
56+
gly_type_render(95, 50, 5, "GameBoy", draw_queue_clojure(51));
57+
gly_type_render(95, 56, 4, "advanced", draw_queue_clojure(51));
58+
gly_type_render(95, 62, 10, "CORE", draw_queue_clojure(51));
59+
gly_type_render(95, 74, 5, "native", draw_queue_clojure(51));
2160
#endif
22-
gly_type_render(95, 74, 5, "engine", draw_queue_clojure(51));
23-
gly_type_render(97, 80, 4, "0.0.16", draw_queue_clojure(51));
61+
gly_type_render(ver_x, ver_y, 4, "0.0.17", draw_queue_clojure(51));
2462
draw_queue_burn(1);
2563
#endif
2664
}

0 commit comments

Comments
 (0)