- Seguim treballant en polir bugs i deixar guapeta la API

This commit is contained in:
2025-02-17 14:01:34 +01:00
parent 29a90f4b46
commit 88e406dae0
5 changed files with 575 additions and 516 deletions

View File

@@ -2,7 +2,7 @@
x=0 x=0
function _init() function mini.init()
--text=other.peiv() --text=other.peiv()
--keyRight = tonumber(getconf("keyright")) or KEY_RIGHT --keyRight = tonumber(getconf("keyright")) or KEY_RIGHT
--keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT --keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
@@ -10,23 +10,34 @@ function _init()
--turbo(false) --turbo(false)
--local perico = "péricòñ" --local perico = "péricòñ"
--print(utf8.len(perico)) --print(utf8.len(perico))
ants = 0xc936;
s = surface.load("tiles01.gif") s = surface.load("tiles01.gif")
--surface.source(s) --surface.source(s)
p = palette.load("tiles01.gif") p = palette.load("tiles01.gif")
palette.set(p) palette.set(p)
palette.setTransparent(255)
print(#p) print(#p)
surface.save(s, "data/copy.gif", p) surface.save(s, "data/copy.gif")
s = surface.load("copy.gif") s = surface.load("copy.gif")
--draw.source(s) --draw.source(s)
system.setBeat(4)
end end
function _update() function mini.update()
if key.press(key.ESCAPE) then if keyboard.keyPressed(key.ESCAPE) then
sys.quit() system.quit()
end end
draw.cls(5) if system.isBeat() then
draw.blit(s, 0, 0, 64, 64, 10, 10) ants = (ants >> 12) | ((ants<<4)&0xffff)
end
surface.cls(5)
draw.surface(s, 0, 0, 64, 64, 10, 10)
draw.rect(10, 10, 73, 73, 8)
draw.setPattern(ants)
draw.rect(10, 10, 73, 73, 0)
draw.setPattern(0xffff)
--draw.print(#p,0,0,2) --draw.print(#p,0,0,2)
end end

View File

@@ -47,7 +47,7 @@ namespace gif
static void put_loop(gif_t *gif, uint16_t loop); static void put_loop(gif_t *gif, uint16_t loop);
gif_t *create(const char *fname, uint16_t width, uint16_t height, uint8_t *palette, uint8_t depth, uint8_t bgindex, int loop) gif_t *create(const char *fname, uint16_t width, uint16_t height, uint8_t *palette, uint8_t depth, int16_t bgindex, int loop)
{ {
gif_t *gif = (gif_t*)calloc(1, sizeof(*gif) + (bgindex < 0 ? 2 : 1)*width*height); gif_t *gif = (gif_t*)calloc(1, sizeof(*gif) + (bgindex < 0 ? 2 : 1)*width*height);
gif->w = width; gif->h = height; gif->w = width; gif->h = height;

619
lua.cpp
View File

@@ -8,7 +8,7 @@ namespace fs = std::filesystem;
extern "C" { extern "C" {
// surf // surface
// =============================================== // ===============================================
static int cpp_surf_new(lua_State *L) { static int cpp_surf_new(lua_State *L) {
@@ -28,11 +28,10 @@ extern "C" {
uint8_t surface = luaL_checkinteger(L, 1); uint8_t surface = luaL_checkinteger(L, 1);
const char* str = luaL_checkstring(L, 2); const char* str = luaL_checkstring(L, 2);
int r,g,b;
uint8_t pal[256*3];
uint8_t *p=pal;
if (lua_istable(L, -1)) { if (lua_istable(L, -1)) {
const int len = SDL_min(256, lua_rawlen(L, -1)); const int len = SDL_min(256, lua_rawlen(L, -1));
uint8_t *pal = (uint8_t*)malloc(len*3);
uint8_t *p=pal;
for (int i=1;i<=len;++i) { for (int i=1;i<=len;++i) {
lua_rawgeti(L, -1, i); lua_rawgeti(L, -1, i);
lua_getfield(L, -1, "r"); lua_getfield(L, -1, "r");
@@ -47,9 +46,11 @@ extern "C" {
lua_pop(L, 1); lua_pop(L, 1);
//pal[i-1] = (r<<16)+(g<<8)+b; //pal[i-1] = (r<<16)+(g<<8)+b;
} }
savesurf(surface, str, pal, len-1);
} else {
savesurf(surface, str, nullptr);
} }
savesurf(surface, str, pal);
return 0; return 0;
} }
@@ -66,8 +67,128 @@ extern "C" {
return 2; return 2;
} }
static int cpp_surf_setTarget(lua_State *L) {
const int numargs = lua_gettop(L);
switch (numargs) {
case 0: {
setdest(0);
return 0;
}
case 1: {
uint8_t surface = luaL_checkinteger(L, 1);
setdest(surface);
return 0;
}
default:
return luaL_error(L, "Function 'surface.setTarget' Unexpected number of parameters.");
};
}
// pal static int cpp_surf_cls(lua_State *L) {
uint8_t color = luaL_optinteger(L, 1, 0);
cls(color);
return 0;
}
static int cpp_surf_setPixel(lua_State *L) {
const int numargs = lua_gettop(L);
switch (numargs) {
case 3: {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
uint8_t color = luaL_checkinteger(L, 3);
pset(x, y, color);
return 0;
}
case 4: {
uint8_t surface = luaL_checkinteger(L, 1);
setsource(surface);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
uint8_t color = luaL_checkinteger(L, 4);
sset(x, y, color);
return 0;
}
default:
return luaL_error(L, "Function 'surface.setPixel' Unexpected number of parameters.");
};
}
static int cpp_surf_getPixel(lua_State *L) {
const int numargs = lua_gettop(L);
switch (numargs) {
case 2: {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
lua_pushinteger(L, pget(x, y));
return 1;
}
case 3: {
uint8_t surface = luaL_checkinteger(L, 1);
setsource(surface);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
lua_pushinteger(L, sget(x, y));
return 1;
}
default:
return luaL_error(L, "Function 'surface.getPixel' Unexpected number of parameters.");
};
}
// map
// ===============================================
static int cpp_map_load(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
setmap(loadsurf(str));
return 0;
}
static int cpp_map_save(lua_State *L) {
uint8_t surface = getmap();
const char* str = luaL_checkstring(L, 1);
savesurf(surface, str, nullptr);
return 0;
}
static int cpp_map_set(lua_State *L) {
uint8_t surface = luaL_checkinteger(L, 1);
setmap(surface);
return 0;
}
static int cpp_map_draw(lua_State *L) {
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;
}
static int cpp_map_getTile(lua_State *L) {
int celx = luaL_checknumber(L, 1);
int cely = luaL_checknumber(L, 2);
lua_pushinteger(L, mget(celx, cely));
return 1;
}
static int cpp_map_setTile(lua_State *L) {
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;
}
// palette
// =============================================== // ===============================================
static int cpp_pal_load(lua_State *L) { static int cpp_pal_load(lua_State *L) {
@@ -150,134 +271,51 @@ extern "C" {
} }
} }
static int cpp_pal_sub(lua_State *L) {
const int numargs = lua_gettop(L); // subpalette
uint8_t index, index2, color; // ===============================================
switch (numargs) { static int cpp_subpalette_resetAll(lua_State *L) {
case 0:
reset_subpal(); reset_subpal();
break; return 0;
case 1: }
index = luaL_checkinteger(L, 1);
subpal(index,index); static int cpp_subpalette_set(lua_State *L) {
break; uint8_t index, color;
case 2:
index = luaL_checkinteger(L, 1); index = luaL_checkinteger(L, 1);
color = luaL_checkinteger(L, 2); color = luaL_checkinteger(L, 2);
subpal(index, color); subpal(index, color);
break; return 0;
case 3: }
static int cpp_subpalette_reset(lua_State *L) {
uint8_t index;
index = luaL_checkinteger(L, 1);
subpal(index,index);
return 0;
}
static int cpp_subpalette_setRange(lua_State *L) {
uint8_t index, index2, color;
index = luaL_checkinteger(L, 1); index = luaL_checkinteger(L, 1);
index2 = luaL_checkinteger(L, 2); index2 = luaL_checkinteger(L, 2);
color = luaL_checkinteger(L, 3); color = luaL_checkinteger(L, 3);
for (int i=index;i<=index2;++i) subpal(i, color); for (int i=index;i<=index2;++i) subpal(i, color);
break; return 0;
} }
static int cpp_subpalette_resetRange(lua_State *L) {
uint8_t index, index2;
index = luaL_checkinteger(L, 1);
index2 = luaL_checkinteger(L, 2);
for (int i=index;i<=index2;++i) subpal(i, i);
return 0; return 0;
} }
// draw // viewport
// =============================================== // ===============================================
static int cpp_draw_dest(lua_State *L) { static int cpp_viewport_clip(lua_State *L) {
const int numargs = lua_gettop(L);
switch (numargs) {
case 0: {
setdest(0);
return 0;
}
case 1: {
uint8_t surface = luaL_checkinteger(L, 1);
setdest(surface);
return 0;
}
case 2: {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
lua_pushinteger(L, pget(x, y));
return 1;
}
case 3: {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
uint8_t color = luaL_checkinteger(L, 3);
pset(x, y, color);
return 0;
}
default:
return luaL_error(L, "Function 'draw.dest' Unexpected number of parameters.");
};
}
static int cpp_draw_source(lua_State *L) {
const int numargs = lua_gettop(L);
switch (numargs) {
case 1: {
uint8_t surface = luaL_checkinteger(L, 1);
setsource(surface);
return 0;
}
case 2: {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
lua_pushinteger(L, sget(x, y));
return 1;
}
case 3: {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
uint8_t color = luaL_checkinteger(L, 3);
sset(x, y, color);
return 0;
}
default:
return luaL_error(L, "Function 'draw.source' Unexpected number of parameters.");
};
}
static int cpp_draw_map(lua_State *L) {
const int numargs = lua_gettop(L);
switch (numargs) {
case 1: {
uint8_t surface = luaL_checkinteger(L, 1);
setmap(surface);
return 0;
}
case 2: {
int celx = luaL_checknumber(L, 1);
int cely = luaL_checknumber(L, 2);
lua_pushinteger(L, mget(celx, cely));
return 1;
}
case 3: {
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;
}
default: {
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;
}
};
}
static int cpp_draw_cls(lua_State *L) {
uint8_t color = luaL_optinteger(L, 1, 0);
cls(color);
return 0;
}
static int cpp_draw_clip(lua_State *L) {
if (lua_gettop(L) == 0) { if (lua_gettop(L) == 0) {
clip(); clip();
} else { } else {
@@ -290,7 +328,7 @@ extern "C" {
return 0; return 0;
} }
static int cpp_draw_origin(lua_State *L) { static int cpp_viewport_origin(lua_State *L) {
if (lua_gettop(L) == 0) { if (lua_gettop(L) == 0) {
lua_pushinteger(L, camx()); lua_pushinteger(L, camx());
lua_pushinteger(L, camy()); lua_pushinteger(L, camy());
@@ -303,7 +341,7 @@ extern "C" {
} }
} }
static int cpp_draw_tolocal(lua_State *L) { static int cpp_viewport_tolocal(lua_State *L) {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
lua_pushinteger(L, x+camx()); lua_pushinteger(L, x+camx());
@@ -311,7 +349,11 @@ extern "C" {
return 2; return 2;
} }
static int cpp_draw_pen(lua_State *L) {
// draw
// ===============================================
/*static int cpp_draw_pen(lua_State *L) {
uint8_t col = luaL_optinteger(L, 1, 6); uint8_t col = luaL_optinteger(L, 1, 6);
color(col); color(col);
return 0; return 0;
@@ -321,19 +363,15 @@ extern "C" {
uint8_t col = luaL_optinteger(L, 1, 6); uint8_t col = luaL_optinteger(L, 1, 6);
bcolor(col); bcolor(col);
return 0; return 0;
} }*/
static int cpp_draw_line(lua_State *L) { static int cpp_draw_line(lua_State *L) {
int x0 = luaL_checknumber(L, 1); int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2); int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4); int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5); uint8_t color = luaL_checkinteger(L, 5);
line(x0, y0, x1, y1, color); line(x0, y0, x1, y1, color);
} else {
line(x0, y0, x1, y1);
}
return 0; return 0;
} }
@@ -341,12 +379,8 @@ extern "C" {
int x0 = luaL_checknumber(L, 1); int x0 = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int x1 = luaL_checknumber(L, 3);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4); uint8_t color = luaL_checkinteger(L, 4);
hline(x0, y, x1, color); hline(x0, y, x1, color);
} else {
hline(x0, y, x1);
}
return 0; return 0;
} }
@@ -354,12 +388,8 @@ extern "C" {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2); int y0 = luaL_checknumber(L, 2);
int y1 = luaL_checknumber(L, 3); int y1 = luaL_checknumber(L, 3);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4); uint8_t color = luaL_checkinteger(L, 4);
vline(x, y0, y1, color); vline(x, y0, y1, color);
} else {
vline(x, y0, y1);
}
return 0; return 0;
} }
@@ -368,12 +398,8 @@ extern "C" {
int y0 = luaL_checknumber(L, 2); int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4); int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5); uint8_t color = luaL_checkinteger(L, 5);
rect(x0, y0, x1, y1, color); rect(x0, y0, x1, y1, color);
} else {
rect(x0, y0, x1, y1);
}
return 0; return 0;
} }
@@ -382,12 +408,8 @@ extern "C" {
int y0 = luaL_checknumber(L, 2); int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4); int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5); uint8_t color = luaL_checkinteger(L, 5);
rectfill(x0, y0, x1, y1, color); rectfill(x0, y0, x1, y1, color);
} else {
rectfill(x0, y0, x1, y1);
}
return 0; return 0;
} }
@@ -395,12 +417,8 @@ extern "C" {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
int r = luaL_optnumber(L, 3, 4); int r = luaL_optnumber(L, 3, 4);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4); uint8_t color = luaL_checkinteger(L, 4);
circ(x, y, r, color); circ(x, y, r, color);
} else {
circ(x, y, r);
}
return 0; return 0;
} }
@@ -408,12 +426,8 @@ extern "C" {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
int r = luaL_optnumber(L, 3, 4); int r = luaL_optnumber(L, 3, 4);
if (lua_gettop(L) > 3) {
uint8_t color = luaL_checkinteger(L, 4); uint8_t color = luaL_checkinteger(L, 4);
circfill(x, y, r, color); circfill(x, y, r, color);
} else {
circfill(x, y, r);
}
return 0; return 0;
} }
@@ -422,12 +436,8 @@ extern "C" {
int y0 = luaL_checknumber(L, 2); int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4); int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5); uint8_t color = luaL_checkinteger(L, 5);
oval(x0, y0, x1, y1, color); oval(x0, y0, x1, y1, color);
} else {
oval(x0, y0, x1, y1);
}
return 0; return 0;
} }
@@ -436,12 +446,8 @@ extern "C" {
int y0 = luaL_checknumber(L, 2); int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int x1 = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4); int y1 = luaL_checknumber(L, 4);
if (lua_gettop(L) > 4) {
uint8_t color = luaL_checkinteger(L, 5); uint8_t color = luaL_checkinteger(L, 5);
ovalfill(x0, y0, x1, y1, color); ovalfill(x0, y0, x1, y1, color);
} else {
ovalfill(x0, y0, x1, y1);
}
return 0; return 0;
} }
@@ -452,7 +458,7 @@ extern "C" {
return 0; return 0;
} }
static int cpp_draw_tline(lua_State *L) { /*static int cpp_draw_tline(lua_State *L) {
int x0 = luaL_checknumber(L, 1); int x0 = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2); int y0 = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int x1 = luaL_checknumber(L, 3);
@@ -487,37 +493,41 @@ extern "C" {
float mdy = luaL_optnumber(L, 7, 0.125f); float mdy = luaL_optnumber(L, 7, 0.125f);
tvline(x, y0, y1, mx, my, mdx, mdy); tvline(x, y0, y1, mx, my, mdx, mdy);
return 0; return 0;
} }*/
static int cpp_draw_blit(lua_State *L) { static int cpp_draw_surface(lua_State *L) {
int sx = luaL_checknumber(L, 1); uint8_t surface = luaL_checkinteger(L, 1);
int sy = luaL_checknumber(L, 2); setsource(surface);
int sw = luaL_checknumber(L, 3); int sx = luaL_checknumber(L, 2);
int sh = luaL_checknumber(L, 4); int sy = luaL_checknumber(L, 3);
int dx = luaL_checknumber(L, 5); int sw = luaL_checknumber(L, 4);
int dy = luaL_checknumber(L, 6); int sh = luaL_checknumber(L, 5);
int dw = luaL_optnumber(L, 7, 0); int dx = luaL_checknumber(L, 6);
int dh = luaL_optnumber(L, 8, 0); int dy = luaL_checknumber(L, 7);
bool flip_x = lua_toboolean(L, 9); int dw = luaL_optnumber(L, 8, 0);
bool flip_y = lua_toboolean(L, 10); int dh = luaL_optnumber(L, 9, 0);
bool invert = lua_toboolean(L, 11); bool flip_x = lua_toboolean(L, 10);
bool flip_y = lua_toboolean(L, 11);
bool invert = lua_toboolean(L, 12);
blit(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, invert); blit(sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y, invert);
return 0; return 0;
} }
static int cpp_draw_blit_r(lua_State *L) { static int cpp_draw_surfaceRotated(lua_State *L) {
int sx = luaL_checknumber(L, 1); uint8_t surface = luaL_checkinteger(L, 1);
int sy = luaL_checknumber(L, 2); setsource(surface);
int sw = luaL_checknumber(L, 3); int sx = luaL_checknumber(L, 2);
int sh = luaL_checknumber(L, 4); int sy = luaL_checknumber(L, 3);
int dx = luaL_checknumber(L, 5); int sw = luaL_checknumber(L, 4);
int dy = luaL_checknumber(L, 6); int sh = luaL_checknumber(L, 5);
float a = luaL_checknumber(L, 7); int dx = luaL_checknumber(L, 6);
int dy = luaL_checknumber(L, 7);
float a = luaL_checknumber(L, 8);
blit_r(sx, sy, sw, sh, dx, dy, a); blit_r(sx, sy, sw, sh, dx, dy, a);
return 0; return 0;
} }
static int cpp_draw_print(lua_State *L) { static int cpp_draw_text(lua_State *L) {
const char* str = luaL_checkstring(L, 1); const char* str = luaL_checkstring(L, 1);
int x = luaL_checknumber(L, 2); int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3); int y = luaL_checknumber(L, 3);
@@ -557,15 +567,15 @@ extern "C" {
return 0; return 0;
} }
static int cpp_music_pos(lua_State *L) { static int cpp_music_setPosition(lua_State *L) {
if (lua_gettop(L) >= 1) {
musicpos(luaL_checknumber(L, 1)); musicpos(luaL_checknumber(L, 1));
return 0; return 0;
} else { }
static int cpp_music_getPosition(lua_State *L) {
lua_pushnumber(L, musicpos()); lua_pushnumber(L, musicpos());
return 1; return 1;
} }
}
// sound // sound
@@ -605,13 +615,18 @@ extern "C" {
return 1; return 1;
} }
static int cpp_sys_beat(lua_State *L) { static int cpp_sys_setBeat(lua_State *L) {
int16_t beats = luaL_optnumber(L, 1, -1); int16_t beats = luaL_optnumber(L, 1, -1);
lua_pushboolean(L, beat(beats)); beat(beats);
return 0;
}
static int cpp_sys_isBeat(lua_State *L) {
lua_pushboolean(L, beat(-1));
return 1; return 1;
} }
static int cpp_sys_turbo(lua_State *L) { static int cpp_sys_setTurbo(lua_State *L) {
if (lua_gettop(L) >= 1) { if (lua_gettop(L) >= 1) {
setturbo(lua_toboolean(L, 1)); setturbo(lua_toboolean(L, 1));
return 0; return 0;
@@ -641,59 +656,51 @@ extern "C" {
// win // win
// =============================================== // ===============================================
static int cpp_win_zoom(lua_State *L) { static int cpp_win_getZoom(lua_State *L) {
const int value = luaL_optinteger(L, 1, 0);
if (value==0) {
lua_pushinteger(L, getzoom()); lua_pushinteger(L, getzoom());
return 1; return 1;
} else { }
static int cpp_win_setZoom(lua_State *L) {
const int value = luaL_optinteger(L, 1, 0);
setzoom(value); setzoom(value);
return 0; return 0;
} }
}
static int cpp_win_fullscreen(lua_State *L) { static int cpp_win_getFullscreen(lua_State *L) {
if (lua_gettop(L) >= 1) {
setfullscreen(lua_toboolean(L, 1));
return 0;
} else {
lua_pushboolean(L, getfullscreen()); lua_pushboolean(L, getfullscreen());
return 1; return 1;
} }
static int cpp_win_setFullscreen(lua_State *L) {
setfullscreen(lua_toboolean(L, 1));
return 0;
} }
static int cpp_win_cursor(lua_State *L) { static int cpp_win_showCursor(lua_State *L) {
if (lua_gettop(L) >= 1) {
setcursor(lua_toboolean(L, 1)); setcursor(lua_toboolean(L, 1));
return 0; return 0;
} else {
lua_pushboolean(L, getcursor());
return 1;
}
} }
static int cpp_win_res(lua_State *L) { static int cpp_win_getResolution(lua_State *L) {
if (lua_gettop(L) >= 2) {
const int w = luaL_optinteger(L, 1, 160);
const int h = luaL_optinteger(L, 2, 120);
setres(w, h);
return 0;
} else {
lua_pushinteger(L, scrw()); lua_pushinteger(L, scrw());
lua_pushinteger(L, scrh()); lua_pushinteger(L, scrh());
return 2; return 2;
} }
static int cpp_win_setResolution(lua_State *L) {
const int w = luaL_optinteger(L, 1, 160);
const int h = luaL_optinteger(L, 2, 120);
setres(w, h);
return 0;
} }
// conf // conf
// =============================================== // ===============================================
static int cpp_conf_key(lua_State *L) { static int cpp_conf_getKey(lua_State *L) {
const int numargs = lua_gettop(L);
const char* key = luaL_checkstring(L, 1); const char* key = luaL_checkstring(L, 1);
switch (numargs) {
case 1: {
const char* value = getconfig(key); const char* value = getconfig(key);
if (value==NULL) { if (value==NULL) {
lua_pushnil(L); lua_pushnil(L);
@@ -702,15 +709,13 @@ extern "C" {
} }
return 1; return 1;
} }
case 2: {
static int cpp_conf_setKey(lua_State *L) {
const char* key = luaL_checkstring(L, 1);
const char* value = luaL_checkstring(L, 2); const char* value = luaL_checkstring(L, 2);
setconfig(key, value); setconfig(key, value);
return 0; return 0;
} }
default:
return luaL_error(L, "Function 'conf.key' Unexpected number of parameters.");
}
}
static int cpp_conf_folder(lua_State *L) { static int cpp_conf_folder(lua_State *L) {
lua_pushstring(L, configfolder()); lua_pushstring(L, configfolder());
@@ -780,12 +785,13 @@ extern "C" {
} }
static int cpp_pad_press(lua_State *L) { static int cpp_pad_press(lua_State *L) {
if (lua_gettop(L) >=1 ) {
int8_t i = luaL_checkinteger(L, 1); int8_t i = luaL_checkinteger(L, 1);
lua_pushboolean(L, padp(i)); lua_pushboolean(L, padp(i));
} else { return 1;
lua_pushinteger(L, wpad());
} }
static int cpp_pad_any(lua_State *L) {
lua_pushinteger(L, wpad());
return 1; return 1;
} }
@@ -801,65 +807,69 @@ bool lua_is_playing() {
} }
void push_lua_funcs() { void push_lua_funcs() {
lua_newtable(L);
lua_setglobal(L, "mini");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_surf_new); lua_setfield(L, -2, "new"); lua_pushcfunction(L,cpp_surf_new); lua_setfield(L, -2, "new");
lua_pushcfunction(L,cpp_surf_load); lua_setfield(L, -2, "load"); lua_pushcfunction(L,cpp_surf_load); lua_setfield(L, -2, "load");
lua_pushcfunction(L,cpp_surf_save); lua_setfield(L, -2, "save"); lua_pushcfunction(L,cpp_surf_save); lua_setfield(L, -2, "save");
lua_pushcfunction(L,cpp_surf_free); lua_setfield(L, -2, "free"); lua_pushcfunction(L,cpp_surf_free); lua_setfield(L, -2, "free");
lua_pushcfunction(L,cpp_surf_getSize); lua_setfield(L, -2, "getSize"); lua_pushcfunction(L,cpp_surf_getSize); lua_setfield(L, -2, "getSize");
// setTarget lua_pushcfunction(L,cpp_surf_setTarget); lua_setfield(L, -2, "setTarget");
// cls lua_pushcfunction(L,cpp_surf_cls); lua_setfield(L, -2, "cls");
// setPixel lua_pushcfunction(L,cpp_surf_setPixel); lua_setfield(L, -2, "setPixel");
// getPixel lua_pushcfunction(L,cpp_surf_getPixel); lua_setfield(L, -2, "getPixel");
lua_setglobal(L, "surface"); lua_setglobal(L, "surface");
map.load lua_newtable(L);
map.save lua_pushcfunction(L,cpp_map_load); lua_setfield(L, -2, "load");
map.draw lua_pushcfunction(L,cpp_map_save); lua_setfield(L, -2, "save");
map.getTile lua_pushcfunction(L,cpp_map_set); lua_setfield(L, -2, "set");
map.setTile lua_pushcfunction(L,cpp_map_draw); lua_setfield(L, -2, "draw");
lua_pushcfunction(L,cpp_map_getTile); lua_setfield(L, -2, "getTile");
lua_pushcfunction(L,cpp_map_setTile); lua_setfield(L, -2, "setTile");
lua_setglobal(L, "map");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_pal_load); lua_setfield(L, -2, "load"); lua_pushcfunction(L,cpp_pal_load); lua_setfield(L, -2, "load");
lua_pushcfunction(L,cpp_pal_set); lua_setfield(L, -2, "set"); lua_pushcfunction(L,cpp_pal_set); lua_setfield(L, -2, "set");
lua_pushcfunction(L,cpp_pal_getColor); lua_setfield(L, -2, "getColor"); lua_pushcfunction(L,cpp_pal_getColor); lua_setfield(L, -2, "getColor");
lua_pushcfunction(L,cpp_pal_setColor); lua_setfield(L, -2, "setColor"); lua_pushcfunction(L,cpp_pal_setColor); lua_setfield(L, -2, "setColor");
lua_pushcfunction(L,cpp_pal_trans); lua_setfield(L, -2, "trans"); lua_pushcfunction(L,cpp_pal_trans); lua_setfield(L, -2, "setTransparent");
lua_pushcfunction(L,cpp_pal_sub); lua_setfield(L, -2, "sub");
lua_setglobal(L, "palette"); lua_setglobal(L, "palette");
subpalette.resetAll lua_newtable(L);
subpalette.set lua_pushcfunction(L,cpp_subpalette_resetAll); lua_setfield(L, -2, "resetAll");
subpalette.reset lua_pushcfunction(L,cpp_subpalette_set); lua_setfield(L, -2, "set");
subpalette.setRange lua_pushcfunction(L,cpp_subpalette_reset); lua_setfield(L, -2, "reset");
subpalette.resetRange lua_pushcfunction(L,cpp_subpalette_setRange); lua_setfield(L, -2, "setRange");
lua_pushcfunction(L,cpp_subpalette_resetRange); lua_setfield(L, -2, "resetRange");
lua_setglobal(L, "subpalette");
lua_newtable(L);
lua_pushcfunction(L,cpp_viewport_clip); lua_setfield(L, -2, "clip");
lua_pushcfunction(L,cpp_viewport_origin); lua_setfield(L, -2, "origin");
lua_pushcfunction(L,cpp_viewport_tolocal); lua_setfield(L, -2, "tolocal");
lua_setglobal(L, "viewport");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_draw_dest); lua_setfield(L, -2, "dest");
lua_pushcfunction(L,cpp_draw_source); lua_setfield(L, -2, "source");
lua_pushcfunction(L,cpp_draw_map); lua_setfield(L, -2, "map");
lua_pushcfunction(L,cpp_draw_cls); lua_setfield(L, -2, "cls");
lua_pushcfunction(L,cpp_draw_clip); lua_setfield(L, -2, "clip");
lua_pushcfunction(L,cpp_draw_origin); lua_setfield(L, -2, "origin");
lua_pushcfunction(L,cpp_draw_tolocal); lua_setfield(L, -2, "tolocal");
lua_pushcfunction(L,cpp_draw_pen); lua_setfield(L, -2, "pen");
lua_pushcfunction(L,cpp_draw_paper); lua_setfield(L, -2, "paper");
lua_pushcfunction(L,cpp_draw_line); lua_setfield(L, -2, "line"); lua_pushcfunction(L,cpp_draw_line); lua_setfield(L, -2, "line");
lua_pushcfunction(L,cpp_draw_hline); lua_setfield(L, -2, "hline"); lua_pushcfunction(L,cpp_draw_hline); lua_setfield(L, -2, "hline");
lua_pushcfunction(L,cpp_draw_vline); lua_setfield(L, -2, "vline"); lua_pushcfunction(L,cpp_draw_vline); lua_setfield(L, -2, "vline");
lua_pushcfunction(L,cpp_draw_rect); lua_setfield(L, -2, "rect"); lua_pushcfunction(L,cpp_draw_rect); lua_setfield(L, -2, "rect");
lua_pushcfunction(L,cpp_draw_rectfill); lua_setfield(L, -2, "rectfill"); lua_pushcfunction(L,cpp_draw_rectfill); lua_setfield(L, -2, "rectFill");
lua_pushcfunction(L,cpp_draw_circ); lua_setfield(L, -2, "circ"); lua_pushcfunction(L,cpp_draw_circ); lua_setfield(L, -2, "circ");
lua_pushcfunction(L,cpp_draw_circfill); lua_setfield(L, -2, "circfill"); lua_pushcfunction(L,cpp_draw_circfill); lua_setfield(L, -2, "circFill");
lua_pushcfunction(L,cpp_draw_oval); lua_setfield(L, -2, "oval"); lua_pushcfunction(L,cpp_draw_oval); lua_setfield(L, -2, "oval");
lua_pushcfunction(L,cpp_draw_ovalfill); lua_setfield(L, -2, "ovalfill"); lua_pushcfunction(L,cpp_draw_ovalfill); lua_setfield(L, -2, "ovalFill");
lua_pushcfunction(L,cpp_draw_pattern); lua_setfield(L, -2, "pattern"); lua_pushcfunction(L,cpp_draw_pattern); lua_setfield(L, -2, "setPattern");
lua_pushcfunction(L,cpp_draw_tline); lua_setfield(L, -2, "tline"); //lua_pushcfunction(L,cpp_draw_tline); lua_setfield(L, -2, "tline");
lua_pushcfunction(L,cpp_draw_thline); lua_setfield(L, -2, "thline"); //lua_pushcfunction(L,cpp_draw_thline); lua_setfield(L, -2, "thline");
lua_pushcfunction(L,cpp_draw_tvline); lua_setfield(L, -2, "tvline"); //lua_pushcfunction(L,cpp_draw_tvline); lua_setfield(L, -2, "tvline");
lua_pushcfunction(L,cpp_draw_blit); lua_setfield(L, -2, "blit"); lua_pushcfunction(L,cpp_draw_surface); lua_setfield(L, -2, "surface");
lua_pushcfunction(L,cpp_draw_blit_r); lua_setfield(L, -2, "blit_r"); lua_pushcfunction(L,cpp_draw_surfaceRotated); lua_setfield(L, -2, "surfaceRotated");
lua_pushcfunction(L,cpp_draw_print); lua_setfield(L, -2, "print"); lua_pushcfunction(L,cpp_draw_text); lua_setfield(L, -2, "text");
lua_setglobal(L, "draw"); lua_setglobal(L, "draw");
lua_newtable(L); lua_newtable(L);
@@ -867,7 +877,8 @@ void push_lua_funcs() {
lua_pushcfunction(L,cpp_music_pause); lua_setfield(L, -2, "pause"); lua_pushcfunction(L,cpp_music_pause); lua_setfield(L, -2, "pause");
lua_pushcfunction(L,cpp_music_resume); lua_setfield(L, -2, "resume"); lua_pushcfunction(L,cpp_music_resume); lua_setfield(L, -2, "resume");
lua_pushcfunction(L,cpp_music_stop); lua_setfield(L, -2, "stop"); lua_pushcfunction(L,cpp_music_stop); lua_setfield(L, -2, "stop");
lua_pushcfunction(L,cpp_music_pos); lua_setfield(L, -2, "pos"); lua_pushcfunction(L,cpp_music_setPosition); lua_setfield(L, -2, "setPosition");
lua_pushcfunction(L,cpp_music_getPosition); lua_setfield(L, -2, "getPosition");
lua_setglobal(L, "music"); lua_setglobal(L, "music");
lua_newtable(L); lua_newtable(L);
@@ -878,37 +889,44 @@ void push_lua_funcs() {
lua_setglobal(L, "sound"); lua_setglobal(L, "sound");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_sys_time); lua_setfield(L, -2, "time"); lua_pushcfunction(L,cpp_sys_time); lua_setfield(L, -2, "getTime");
lua_pushcfunction(L,cpp_sys_beat); lua_setfield(L, -2, "beat"); lua_pushcfunction(L,cpp_sys_setBeat); lua_setfield(L, -2, "setBeat");
lua_pushcfunction(L,cpp_sys_turbo); lua_setfield(L, -2, "turbo"); lua_pushcfunction(L,cpp_sys_isBeat); lua_setfield(L, -2, "isBeat");
lua_pushcfunction(L,cpp_sys_dir); lua_setfield(L, -2, "dir"); lua_pushcfunction(L,cpp_sys_setTurbo); lua_setfield(L, -2, "setTurbo");
lua_pushcfunction(L,cpp_sys_dir); lua_setfield(L, -2, "getFilesInDataDirectory");
lua_pushcfunction(L,cpp_sys_exit); lua_setfield(L, -2, "quit"); lua_pushcfunction(L,cpp_sys_exit); lua_setfield(L, -2, "quit");
lua_setglobal(L, "sys"); lua_setglobal(L, "system");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_win_zoom); lua_setfield(L, -2, "zoom"); lua_pushcfunction(L,cpp_win_setZoom); lua_setfield(L, -2, "setZoom");
lua_pushcfunction(L,cpp_win_fullscreen);lua_setfield(L, -2, "fullscreen"); lua_pushcfunction(L,cpp_win_getZoom); lua_setfield(L, -2, "getZoom");
lua_pushcfunction(L,cpp_win_cursor); lua_setfield(L, -2, "cursor"); lua_pushcfunction(L,cpp_win_setFullscreen); lua_setfield(L, -2, "setFullscreen");
lua_pushcfunction(L,cpp_win_res); lua_setfield(L, -2, "res"); lua_pushcfunction(L,cpp_win_getFullscreen); lua_setfield(L, -2, "getFullscreen");
lua_setglobal(L, "win"); lua_pushcfunction(L,cpp_win_showCursor); lua_setfield(L, -2, "showCursor");
lua_pushcfunction(L,cpp_win_getResolution); lua_setfield(L, -2, "getResolution");
lua_pushcfunction(L,cpp_win_setResolution); lua_setfield(L, -2, "setResolution");
lua_setglobal(L, "window");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_conf_key); lua_setfield(L, -2, "key"); lua_pushcfunction(L,cpp_conf_setKey); lua_setfield(L, -2, "setKey");
lua_pushcfunction(L,cpp_conf_folder); lua_setfield(L, -2, "folder"); lua_pushcfunction(L,cpp_conf_getKey); lua_setfield(L, -2, "getKey");
lua_setglobal(L, "conf"); lua_pushcfunction(L,cpp_conf_folder); lua_setfield(L, -2, "getConfigFolder");
lua_setglobal(L, "config");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_mouse_pos); lua_setfield(L, -2, "pos"); lua_pushcfunction(L,cpp_mouse_pos); lua_setfield(L, -2, "getPos");
lua_pushcfunction(L,cpp_mouse_wheel); lua_setfield(L, -2, "wheel"); lua_pushcfunction(L,cpp_mouse_wheel); lua_setfield(L, -2, "getWheel");
lua_pushcfunction(L,cpp_mouse_down); lua_setfield(L, -2, "down"); lua_pushcfunction(L,cpp_mouse_down); lua_setfield(L, -2, "buttonDown");
lua_pushcfunction(L,cpp_mouse_press); lua_setfield(L, -2, "press"); lua_pushcfunction(L,cpp_mouse_press); lua_setfield(L, -2, "buttonPressed");
lua_setglobal(L, "mouse"); lua_setglobal(L, "mouse");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_key_down); lua_setfield(L, -2, "down"); lua_pushcfunction(L,cpp_key_down); lua_setfield(L, -2, "keyDown");
lua_pushcfunction(L,cpp_key_press); lua_setfield(L, -2, "press"); lua_pushcfunction(L,cpp_key_press); lua_setfield(L, -2, "keyPressed");
lua_pushcfunction(L,cpp_key_any); lua_setfield(L, -2, "any"); lua_pushcfunction(L,cpp_key_any); lua_setfield(L, -2, "anyKeyPressed");
lua_setglobal(L, "keyboard");
lua_newtable(L);
lua_pushinteger(L, 0); lua_setfield(L, -2, "UNKNOWN"); lua_pushinteger(L, 0); lua_setfield(L, -2, "UNKNOWN");
lua_pushinteger(L, 4); lua_setfield(L, -2, "A"); lua_pushinteger(L, 4); lua_setfield(L, -2, "A");
lua_pushinteger(L, 5); lua_setfield(L, -2, "B"); lua_pushinteger(L, 5); lua_setfield(L, -2, "B");
@@ -1020,9 +1038,12 @@ void push_lua_funcs() {
lua_setglobal(L, "key"); lua_setglobal(L, "key");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_pad_down); lua_setfield(L, -2, "down"); lua_pushcfunction(L,cpp_pad_down); lua_setfield(L, -2, "buttonDown");
lua_pushcfunction(L,cpp_pad_press); lua_setfield(L, -2, "press"); lua_pushcfunction(L,cpp_pad_press); lua_setfield(L, -2, "buttonPressed");
lua_pushcfunction(L,cpp_pad_any); lua_setfield(L, -2, "anyButtonPressed");
lua_setglobal(L, "gamepad");
lua_newtable(L);
lua_pushinteger(L, -1); lua_setfield(L, -2, "INVALID"); lua_pushinteger(L, -1); lua_setfield(L, -2, "INVALID");
lua_pushinteger(L, 0); lua_setfield(L, -2, "A"); lua_pushinteger(L, 0); lua_setfield(L, -2, "A");
lua_pushinteger(L, 1); lua_setfield(L, -2, "B"); lua_pushinteger(L, 1); lua_setfield(L, -2, "B");
@@ -1046,7 +1067,7 @@ void push_lua_funcs() {
lua_pushinteger(L, 19); lua_setfield(L, -2, "PADDLE4"); lua_pushinteger(L, 19); lua_setfield(L, -2, "PADDLE4");
lua_pushinteger(L, 20); lua_setfield(L, -2, "TOUCHPAD"); lua_pushinteger(L, 20); lua_setfield(L, -2, "TOUCHPAD");
lua_setglobal(L, "pad"); lua_setglobal(L, "button");
} }
@@ -1084,42 +1105,58 @@ void lua_init(const char *main_lua_file) {
} }
free(buffer); free(buffer);
if (lua_pcall(L,0, LUA_MULTRET, 0)) { if (lua_pcall(L,0, LUA_MULTRET, 0)) {
debug("RUNTIME ERROR: "); debug("RUNTIME ERROR [BOOT]: ");
debug("%s\n",lua_tostring(L, -1)); //debug("%s\n",lua_tostring(L, -1));
//lua_pop(L,1);
luaL_traceback(L, L, NULL, 1);
debug("%s\n", lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
return; return;
} }
// Check if _init and _update exist // Check if _init and _update exist
lua_getglobal(L, "_init"); lua_getglobal(L, "mini");
lua_getfield(L, -1, "init");
if (lua_isfunction(L,-1)) init_exists = true; if (lua_isfunction(L,-1)) init_exists = true;
lua_pop(L,1); lua_pop(L,1);
lua_pop(L,1);
lua_getglobal(L, "_update"); lua_getglobal(L, "mini");
lua_getfield(L, -1, "update");
if (lua_isfunction(L,-1)) update_exists = true; if (lua_isfunction(L,-1)) update_exists = true;
lua_pop(L,1); lua_pop(L,1);
lua_pop(L,1);
is_playing = true; is_playing = true;
} }
void lua_call_init() { void lua_call_init() {
if (!init_exists) return; if (!init_exists) return;
lua_getglobal(L, "_init"); lua_getglobal(L, "mini");
lua_getfield(L, -1, "init");
if (lua_pcall(L, 0, 0, 0)) { if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR: "); debug("RUNTIME ERROR [INIT]: ");
debug("%s\n",lua_tostring(L, -1)); debug("%s\n",lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
luaL_traceback(L, L, NULL, 1);
debug("%s\n", lua_tostring(L, -1));
lua_pop(L,1);
is_playing = false; is_playing = false;
} }
} }
void lua_call_update() { void lua_call_update() {
if (!update_exists) return; if (!update_exists) return;
lua_getglobal(L, "_update"); lua_getglobal(L, "mini");
lua_getfield(L, -1, "update");
if (lua_pcall(L, 0, 0, 0)) { if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR: "); debug("RUNTIME ERROR [UPDATE]: ");
debug("%s\n",lua_tostring(L, -1)); debug("%s\n",lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
luaL_traceback(L, L, NULL, 1);
debug("%s\n", lua_tostring(L, -1));
lua_pop(L,1);
is_playing = false; is_playing = false;
} }
} }

View File

@@ -7,6 +7,8 @@
//#include "SDL2/SDL_mixer.h" //#include "SDL2/SDL_mixer.h"
#include "jail_audio.h" #include "jail_audio.h"
#define MAX_TEXTURES 10
#ifdef MACOS_BUNDLE #ifdef MACOS_BUNDLE
#include <libgen.h> #include <libgen.h>
#endif #endif
@@ -33,7 +35,7 @@ bool screen_cursor = true;
int desktop_width = 0; int desktop_width = 0;
int desktop_height = 0; int desktop_height = 0;
surface_t surfaces[10]; surface_t surfaces[MAX_TEXTURES];
surface_t *screen_surface = &surfaces[0]; surface_t *screen_surface = &surfaces[0];
surface_t *dest_surface = screen_surface; surface_t *dest_surface = screen_surface;
surface_t *source_surface = NULL; surface_t *source_surface = NULL;
@@ -164,7 +166,7 @@ void reinit() {
ds::trans=0; ds::trans=0;
ds::fill_pattern = 0b1111111111111111; ds::fill_pattern = 0b1111111111111111;
ds::fill_trans = false; ds::fill_trans = false;
for (int i=1; i<10; ++i) { for (int i=1; i<MAX_TEXTURES; ++i) {
if (surfaces[i].p != NULL) free(surfaces[i].p); if (surfaces[i].p != NULL) free(surfaces[i].p);
surfaces[i].p = NULL; surfaces[i].p = NULL;
} }
@@ -194,7 +196,7 @@ int scrh() {
uint8_t newsurf(int w, int h) { uint8_t newsurf(int w, int h) {
int i = 0; int i = 0;
while (i<10 && surfaces[i].p != NULL) ++i; while (i<MAX_TEXTURES && surfaces[i].p != NULL) ++i;
//[TODO] Gestionar el cas en que no queden surfaces lliures //[TODO] Gestionar el cas en que no queden surfaces lliures
surfaces[i].w = w; surfaces[i].w = w;
surfaces[i].h = h; surfaces[i].h = h;
@@ -205,7 +207,7 @@ uint8_t newsurf(int w, int h) {
uint8_t loadsurf(const char* filename) { uint8_t loadsurf(const char* filename) {
int i = 0; int i = 0;
while (i<10 && surfaces[i].p != NULL) ++i; while (i<MAX_TEXTURES && surfaces[i].p != NULL) ++i;
//[TODO] Gestionar el cas en que no queden surfaces lliures //[TODO] Gestionar el cas en que no queden surfaces lliures
int size; int size;
@@ -217,9 +219,11 @@ uint8_t loadsurf(const char* filename) {
return i; return i;
} }
void savesurf(uint8_t surface, const char* filename, uint8_t *pal) void savesurf(uint8_t surface, const char* filename, uint8_t *pal, uint8_t colors)
{ {
gif::gif_t *file = gif::create(filename, surfaces[surface].w, surfaces[surface].h, pal, (pal?8:0), 0, -1); uint8_t depth=colors;
do { depth = depth >> 1; } while (depth!=0);
gif::gif_t *file = gif::create(filename, surfaces[surface].w, surfaces[surface].h, pal, (pal?depth:0), -1, -1);
memcpy(file->frame, surfaces[surface].p, surfaces[surface].w*surfaces[surface].h); memcpy(file->frame, surfaces[surface].p, surfaces[surface].w*surfaces[surface].h);
gif::addFrame(file, 0); gif::addFrame(file, 0);
gif::close(file); gif::close(file);
@@ -260,6 +264,12 @@ void setmap(uint8_t surface) {
map_surface = &surfaces[surface]; map_surface = &surfaces[surface];
} }
uint8_t getmap()
{
for (int i=0; i<MAX_TEXTURES; ++i) if (map_surface == &surfaces[i]) return i;
return 0;
}
void createDisplay() { void createDisplay() {
if (screen_zoom <= 0) screen_zoom = 1; if (screen_zoom <= 0) screen_zoom = 1;
while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--; while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--;
@@ -468,7 +478,7 @@ int main(int argc,char*argv[]){
//Mix_Quit(); //Mix_Quit();
for (int i=0;i<10;++i) freesurf(i); for (int i=0;i<MAX_TEXTURES;++i) freesurf(i);
dest_surface = source_surface = map_surface = NULL; dest_surface = source_surface = map_surface = NULL;
destroyDisplay(); destroyDisplay();
SDL_Quit(); SDL_Quit();
@@ -684,7 +694,7 @@ void rectfill(int x0, int y0, int x1, int y1, uint8_t color) {
} }
void fillp(uint16_t pat, bool transparent) { void fillp(uint16_t pat, bool transparent) {
ds::fill_trans = transparent; ds::fill_trans = true; //transparent;
ds::fill_pattern = pat; ds::fill_pattern = pat;
do_pset=(pat==0xffff?pset_fast:pset_pattern); do_pset=(pat==0xffff?pset_fast:pset_pattern);
} }

3
mini.h
View File

@@ -119,7 +119,7 @@ int scrh();
uint8_t newsurf(int w, int h); uint8_t newsurf(int w, int h);
uint8_t loadsurf(const char* filename); uint8_t loadsurf(const char* filename);
void savesurf(uint8_t surface, const char* filename, uint8_t *pal); void savesurf(uint8_t surface, const char* filename, uint8_t *pal, uint8_t colors=0);
void freesurf(uint8_t surface); void freesurf(uint8_t surface);
int surfw(uint8_t surface); int surfw(uint8_t surface);
int surfh(uint8_t surface); int surfh(uint8_t surface);
@@ -127,6 +127,7 @@ int surfh(uint8_t surface);
void setdest(uint8_t surface); void setdest(uint8_t surface);
void setsource(uint8_t surface); void setsource(uint8_t surface);
void setmap(uint8_t surface); void setmap(uint8_t surface);
uint8_t getmap();
void cls(uint8_t color=0); void cls(uint8_t color=0);
void color(uint8_t color=6); void color(uint8_t color=6);