Commit before the BIG changes...

This commit is contained in:
2021-11-24 15:21:40 +01:00
parent 452a7d14f2
commit 160da08c3d
5 changed files with 165 additions and 81 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
mini.exe
mini
vscode/*
.vscode/*

4
game.ini Normal file
View File

@@ -0,0 +1,4 @@
title=AEE: El Laberinto de Akhenotep
width=160
height=120
zoom=4

187
lua.cpp
View File

@@ -23,7 +23,7 @@ extern "C" {
}
uint8_t c0 = luaL_checkinteger(L, 1);
uint8_t c1 = luaL_checkinteger(L, 2);
uint8_t p = luaL_optinteger(L, 1, 0);
uint8_t p = luaL_optinteger(L, 3, 0);
pal(c0, c1, p);
return 0;
}
@@ -41,8 +41,8 @@ extern "C" {
}
static int cpp_pset(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
if (lua_gettop(L) > 2) {
uint8_t color = luaL_checkinteger(L, 3);
pset(x, y, color);
@@ -53,17 +53,17 @@ extern "C" {
}
static int cpp_pget(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
lua_pushinteger(L, pget(x, y));
return 1;
}
static int cpp_line(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int y1 = luaL_checkinteger(L, 4);
int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5);
line(x0, y0, x1, y1, color);
@@ -74,9 +74,9 @@ extern "C" {
}
static int cpp_hline(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int x0 = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4);
hline(x0, y, x1, color);
@@ -87,9 +87,9 @@ extern "C" {
}
static int cpp_vline(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int y1 = luaL_checkinteger(L, 3);
int x = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int y1 = luaL_checknumber(L, 3);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4);
vline(x, y0, y1, color);
@@ -100,10 +100,10 @@ extern "C" {
}
static int cpp_rect(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int y1 = luaL_checkinteger(L, 4);
int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5);
rect(x0, y0, x1, y1, color);
@@ -114,10 +114,10 @@ extern "C" {
}
static int cpp_rectfill(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int y1 = luaL_checkinteger(L, 4);
int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5);
rectfill(x0, y0, x1, y1, color);
@@ -136,8 +136,8 @@ extern "C" {
static int cpp_print(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
int x = luaL_checkinteger(L, 2);
int y = luaL_checkinteger(L, 3);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4);
print(str, x, y, color);
@@ -148,10 +148,10 @@ extern "C" {
}
static int cpp_clip(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int w = luaL_checkinteger(L, 3);
int h = luaL_checkinteger(L, 4);
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int w = luaL_checknumber(L, 3);
int h = luaL_checknumber(L, 4);
clip(x, y, w, h);
return 0;
}
@@ -164,9 +164,9 @@ extern "C" {
}
static int cpp_circ(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int r = luaL_optinteger(L, 3, 4);
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int r = luaL_optnumber(L, 3, 4);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4);
circ(x, y, r, color);
@@ -177,9 +177,9 @@ extern "C" {
}
static int cpp_circfill(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int r = luaL_optinteger(L, 3, 4);
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int r = luaL_optnumber(L, 3, 4);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4);
circfill(x, y, r, color);
@@ -190,10 +190,10 @@ extern "C" {
}
static int cpp_oval(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int y1 = luaL_checkinteger(L, 4);
int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5);
oval(x0, y0, x1, y1, color);
@@ -204,10 +204,10 @@ extern "C" {
}
static int cpp_ovalfill(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int y1 = luaL_checkinteger(L, 4);
int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5);
ovalfill(x0, y0, x1, y1, color);
@@ -218,8 +218,8 @@ extern "C" {
}
static int cpp_sset(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
if (lua_gettop(L) > 2) {
uint8_t color = luaL_checkinteger(L, 3);
sset(x, y, color);
@@ -230,16 +230,16 @@ extern "C" {
}
static int cpp_sget(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
lua_pushinteger(L, sget(x, y));
return 1;
}
static int cpp_spr(lua_State *L) {
uint8_t n = luaL_checkinteger(L, 1);
int x = luaL_checkinteger(L, 2);
int y = luaL_checkinteger(L, 3);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
float w = luaL_optnumber(L, 4, 1.0f);
float h = luaL_optnumber(L, 5, 1.0f);
bool flip_x = lua_toboolean(L, 6);
@@ -249,14 +249,14 @@ extern "C" {
}
static int cpp_sspr(lua_State *L) {
int sx = luaL_checkinteger(L, 1);
int sy = luaL_checkinteger(L, 2);
int sw = luaL_checkinteger(L, 3);
int sh = luaL_checkinteger(L, 4);
int dx = luaL_checkinteger(L, 5);
int dy = luaL_checkinteger(L, 6);
int dw = luaL_optinteger(L, 7, 0);
int dh = luaL_optinteger(L, 8, 0);
int sx = luaL_checknumber(L, 1);
int sy = luaL_checknumber(L, 2);
int sw = luaL_checknumber(L, 3);
int sh = luaL_checknumber(L, 4);
int dx = luaL_checknumber(L, 5);
int dy = luaL_checknumber(L, 6);
int dw = luaL_optnumber(L, 7, 0);
int dh = luaL_optnumber(L, 8, 0);
bool flip_x = lua_toboolean(L, 9);
bool flip_y = lua_toboolean(L, 10);
sspr(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
@@ -264,10 +264,10 @@ extern "C" {
}
static int cpp_tline(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int y1 = luaL_checkinteger(L, 4);
int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4);
float mx = luaL_checknumber(L, 5);
float my = luaL_checknumber(L, 6);
float mdx = luaL_optnumber(L, 7, 0.125f);
@@ -277,9 +277,9 @@ extern "C" {
}
static int cpp_thline(lua_State *L) {
int x0 = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int x1 = luaL_checkinteger(L, 3);
int x0 = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3);
float mx = luaL_checknumber(L, 4);
float my = luaL_checknumber(L, 5);
float mdx = luaL_optnumber(L, 6, 0.125f);
@@ -289,9 +289,9 @@ extern "C" {
}
static int cpp_tvline(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y0 = luaL_checkinteger(L, 2);
int y1 = luaL_checkinteger(L, 3);
int x = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2);
int y1 = luaL_checknumber(L, 3);
float mx = luaL_checknumber(L, 4);
float my = luaL_checknumber(L, 5);
float mdx = luaL_optnumber(L, 6, 0.0f);
@@ -301,27 +301,27 @@ extern "C" {
}
static int cpp_mset(lua_State *L) {
int celx = luaL_checkinteger(L, 1);
int cely = luaL_checkinteger(L, 2);
int celx = luaL_checknumber(L, 1);
int cely = luaL_checknumber(L, 2);
uint8_t snum = luaL_checkinteger(L, 3);
mset(celx, cely, snum);
return 0;
}
static int cpp_mget(lua_State *L) {
int celx = luaL_checkinteger(L, 1);
int cely = luaL_checkinteger(L, 2);
int celx = luaL_checknumber(L, 1);
int cely = luaL_checknumber(L, 2);
lua_pushinteger(L, mget(celx, cely));
return 1;
}
static int cpp_map(lua_State *L) {
uint8_t celx = luaL_checkinteger(L, 1);
uint8_t cely = luaL_checkinteger(L, 2);
int sx = luaL_checkinteger(L, 3);
int sy = luaL_checkinteger(L, 4);
uint8_t celw = luaL_checkinteger(L, 5);
uint8_t celh = luaL_checkinteger(L, 6);
uint8_t celx = luaL_checknumber(L, 1);
uint8_t cely = luaL_checknumber(L, 2);
int sx = luaL_checknumber(L, 3);
int sy = luaL_checknumber(L, 4);
uint8_t celw = luaL_checknumber(L, 5);
uint8_t celh = luaL_checknumber(L, 6);
uint8_t layer = luaL_optinteger(L, 7, 0);
map(celx, cely, sx, sy, celw, celh, layer);
return 0;
@@ -339,6 +339,27 @@ extern "C" {
return 1;
}
static int cpp_mouseX(lua_State *L) {
lua_pushinteger(L, mouseX());
return 1;
}
static int cpp_mouseY(lua_State *L) {
lua_pushinteger(L, mouseY());
return 1;
}
static int cpp_mouseWheel(lua_State *L) {
lua_pushinteger(L, mouseWheel());
return 1;
}
static int cpp_mouseButton(lua_State *L) {
uint8_t i = luaL_checkinteger(L, 1);
lua_pushboolean(L, mouseButton(i));
return 1;
}
static int cpp_time(lua_State *L) {
lua_pushnumber(L, time());
return 1;
@@ -414,7 +435,11 @@ extern "C" {
srand(x);
return 0;
}
static int cpp_tostr(lua_State *L) {
int val = luaL_checknumber(L, 1);
lua_pushstring(L, tostr(val));
return 1;
}
}
lua_State *L;
@@ -467,6 +492,11 @@ void lua_init() {
lua_pushcfunction(L,cpp_map); lua_setglobal(L, "map");
lua_pushcfunction(L,cpp_btn); lua_setglobal(L, "btn");
lua_pushcfunction(L,cpp_btnp); lua_setglobal(L, "btnp");
lua_pushcfunction(L,cpp_mouseX); lua_setglobal(L, "mouseX");
lua_pushcfunction(L,cpp_mouseY); lua_setglobal(L, "mouseY");
lua_pushcfunction(L,cpp_mouseWheel); lua_setglobal(L, "mouseWheel");
lua_pushcfunction(L,cpp_mouseButton); lua_setglobal(L, "mouseButton");
lua_pushcfunction(L,cpp_time); lua_setglobal(L, "time");
lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs");
lua_pushcfunction(L,cpp_ceil); lua_setglobal(L, "ceil");
@@ -481,6 +511,7 @@ void lua_init() {
lua_pushcfunction(L,cpp_min); lua_setglobal(L, "min");
lua_pushcfunction(L,cpp_rnd); lua_setglobal(L, "rnd");
lua_pushcfunction(L,cpp_srand); lua_setglobal(L, "srand");
lua_pushcfunction(L,cpp_tostr); lua_setglobal(L, "tostr");
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");

View File

@@ -1,8 +1,17 @@
#include "mini.h"
#include <stdio.h>
#include <string.h>
#include "lua.h"
struct surface_t {
uint8_t *pointer;
uint16_t w, h;
uint32_t size_in_bytes;
};
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
char window_title[256];
#define SCREEN_WIDTH 160
#define SCREEN_HEIGHT 120
#define SCREEN_SIZE_BYTES SCREEN_WIDTH*SCREEN_HEIGHT
@@ -43,11 +52,15 @@ uint8_t tiles[TILES_SIZE_BYTES];
uint32_t palette[16] = { 0x1a1c2c00, 0x5d275d00, 0xb13e5300, 0xef7d5700, 0xffcd7500, 0xa7f07000, 0x38b76400, 0x25717900,
0x29366f00, 0x3b5dc900, 0x41a6f600, 0x73eff700, 0xf4f4f400, 0x94b0c200, 0x566c8600, 0x333c5700 };
const char base64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char base64font[241] = "00@B@]0X__OnZDYK[G10:9BTDEG5j20@1h000RB:_]OBjW?odl]Wlil9_oTT__omT@@02:DA477ADid@Z=nm]_[g9a[]oIi?;a9m]_mBjGB[M]99o_][]e]M"
"_?A]c_[eiLGBZ]e]mZ]o]Z]mlW:O9IABdTdZ000hR00__H[7?iH]3Oih;1?mXm5GjhB3M]897o]H]5^Mhm1ZchM5>LhB2]eXm2]oXZ5mlh<gJbBBJbJP?0Zm";
uint16_t font[96];
char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAVIc+dJHMMM/h/qBgBgVqq+//eIUi/dJzhAAhzAAA/eM"
"AMShAAAQsjAAAwsjAAAeSzAAAcU3AAAEqRAAABVaiAAMezhAAAAAMAADH4wAASb2SAAMAttAQYcefACGOe+AAAVVAAAAbbAA";
const int debug_line_size = (SCREEN_WIDTH/4);
const int debug_num_lines = (SCREEN_HEIGHT/6);
const int debug_total_size = debug_line_size*debug_num_lines;
@@ -58,9 +71,30 @@ int debug_cursor = 0;
const Uint8 *keys;
Uint8 key_just_pressed = 0;
int mouse_x, mouse_y;
int mouse_x, mouse_y, mouse_wheel;
Uint32 mouse_buttons;
char* get_value(char* line) {
char* equal_character = strchr(line, '=');
if (equal_character == NULL) return NULL;
*equal_character = '\0';
return ++equal_character;
}
void read_ini() {
FILE *f = fopen("game.ini", "r");
char line[256];
if (f == NULL) return;
while (fgets(line, sizeof(line), f)) {
char *value = get_value(line);
if (value != NULL) {
//if (strcmp(value, "title") == 0)
}
}
fclose(f);
}
void reinit() {
ds::pen_color = 6;
ds::cam[0] = ds::cam[1] = 0;
@@ -111,6 +145,7 @@ int main(int argc,char*argv[]){
while(!exit) {
key_just_pressed = 0;
mouse_wheel = 0;
while(SDL_PollEvent(&mini_eve)) {
if (mini_eve.type == SDL_QUIT) { exit=true; break; }
if (mini_eve.type == SDL_KEYDOWN) {
@@ -131,6 +166,9 @@ int main(int argc,char*argv[]){
key_just_pressed = mini_eve.key.keysym.scancode;
}
}
if (mini_eve.type == SDL_MOUSEWHEEL) {
mouse_wheel = mini_eve.wheel.y;
}
}
keys = SDL_GetKeyboardState(NULL);
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
@@ -608,6 +646,10 @@ int mouseY() {
return mouse_y;
}
int mouseWheel() {
return mouse_wheel;
}
bool mouseButton(uint8_t i) {
return mouse_buttons & SDL_BUTTON(i);
}
@@ -672,6 +714,10 @@ int rnd(int x) {
srand(x);
}*/
char tostr_tmp[256];
const char* tostr(int val) {
return SDL_itoa(val, tostr_tmp, 10);
}
void debug_one_line_up() {
for (int i=0; i<debug_total_size-debug_line_size;++i) debug_text[i] = debug_text[i+debug_line_size];

3
mini.h
View File

@@ -183,6 +183,7 @@ bool btnp(uint8_t i);
int mouseX();
int mouseY();
int mouseWheel();
bool mouseButton(uint8_t i);
float time();
@@ -207,6 +208,8 @@ float min(float x, float y);
int rnd(int x);
//void srand(int x);
const char* tostr(int val);
void debug(const char *str);
void pdebug();