[NEW] extended palette functions

[DEL] old palette functions
[MODIF] mouse function names
[MODIF] map function params now are ints
[NEW] ascii function
[NEW] strlen function
This commit is contained in:
2022-09-11 22:50:44 +02:00
parent 50090e8a17
commit 1f5acd2bfa
9 changed files with 152 additions and 105 deletions

View File

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

View File

@@ -1,38 +1,12 @@
x = 0
x=0
function text(str, x, y, color)
palt(0, false)
print(str, x-1, y-1, 0)
print(str, x , y-1, 0)
print(str, x+1, y-1, 0)
print(str, x-1, y , 0)
print(str, x+1, y , 0)
print(str, x-1, y+1, 0)
print(str, x , y+1, 0)
print(str, x+1, y+1, 0)
palt()
print(str, x, y, color)
function _init()
text="HOLA MINI"
end
function _update()
cls(1)
camera(x, 0)
if btn(KEY_LEFT) then x = x + 1 end
if btn(KEY_RIGHT) then x = x - 1 end
map(0, 0, 0, 0, 16, 16)
rectfill(10, 10, 114, 40, 12)
palt(0, false) palt(9, true)
rect(10, 10, 114, 40, 0)
spr(16, 18, 40, 1, 1, true)
sspr(24, 0, 16, 16, 10, 50, 16, 16, false, false)
palt()
text("HOLA, ESTA ES LA PRIMERA", 14, 15, 5)
text("DEMO DEL NOU E INCREIBLE", 14, 23, 5)
text("JAIL'S ADVENTURE 2!", 14, 31, 5)
circfill(64, 64, 20)
sset(9, 9, 6)
--ovalfill(30,10,100,100,8)
tline(10, 50, 10, 91, 1.125, 1, 0.0, 1.0/32.0)
line(10, 101, 41, 101, 9)
cls(20)
print(text,x,60)
x=x+1
if x>160 then x=-strlen(text)*4 end
end

77
lua.cpp
View File

@@ -52,7 +52,32 @@ extern "C" {
return 0;
}
static int cpp_pal(lua_State *L) {
static int cpp_loadpal(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
loadpal(str);
return 0;
}
static int cpp_setpal(lua_State *L) {
uint8_t index = luaL_checkinteger(L, 1);
uint8_t color = luaL_checkinteger(L, 2);
setpal(index, color);
return 0;
}
static int cpp_getpal(lua_State *L) {
uint8_t index = luaL_checkinteger(L, 1);
lua_pushinteger(L, getpal(index));
return 1;
}
static int cpp_settrans(lua_State *L) {
uint8_t index = luaL_checkinteger(L, 1);
settrans(index);
return 0;
}
static int cpp_gettrans(lua_State *L) {
lua_pushinteger(L, gettrans());
return 1;
}
/* static int cpp_pal(lua_State *L) {
int numargs = lua_gettop(L);
switch (numargs) {
case 0: pal(); return 0;
@@ -75,7 +100,7 @@ extern "C" {
bool t = lua_toboolean(L, 2);
palt(col, t);
return 0;
}
}*/
static int cpp_pset(lua_State *L) {
int x = luaL_checknumber(L, 1);
@@ -376,24 +401,24 @@ extern "C" {
return 1;
}
static int cpp_mouseX(lua_State *L) {
lua_pushinteger(L, mouseX());
static int cpp_mousex(lua_State *L) {
lua_pushinteger(L, mousex());
return 1;
}
static int cpp_mouseY(lua_State *L) {
lua_pushinteger(L, mouseY());
static int cpp_mousey(lua_State *L) {
lua_pushinteger(L, mousey());
return 1;
}
static int cpp_mouseWheel(lua_State *L) {
lua_pushinteger(L, mouseWheel());
static int cpp_mwheel(lua_State *L) {
lua_pushinteger(L, mwheel());
return 1;
}
static int cpp_mouseButton(lua_State *L) {
static int cpp_mbtn(lua_State *L) {
uint8_t i = luaL_checkinteger(L, 1);
lua_pushboolean(L, mouseButton(i));
lua_pushboolean(L, mbtn(i));
return 1;
}
@@ -477,6 +502,17 @@ extern "C" {
lua_pushstring(L, tostr(val));
return 1;
}
static int cpp_ascii(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
int index = luaL_checkinteger(L, 2);
lua_pushinteger(L, ascii(str, index));
return 1;
}
static int cpp_strlen(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
lua_pushinteger(L, strlen(str));
return 1;
}
}
lua_State *L;
@@ -507,8 +543,15 @@ void lua_init() {
lua_pushcfunction(L,cpp_cls); lua_setglobal(L, "cls");
lua_pushcfunction(L,cpp_color); lua_setglobal(L, "color");
lua_pushcfunction(L,cpp_pal); lua_setglobal(L, "pal");
lua_pushcfunction(L,cpp_palt); lua_setglobal(L, "palt");
lua_pushcfunction(L,cpp_loadpal); lua_setglobal(L, "loadpal");
lua_pushcfunction(L,cpp_setpal); lua_setglobal(L, "setpal");
lua_pushcfunction(L,cpp_getpal); lua_setglobal(L, "getpal");
lua_pushcfunction(L,cpp_settrans); lua_setglobal(L, "settrans");
lua_pushcfunction(L,cpp_gettrans); lua_setglobal(L, "gettrans");
/*lua_pushcfunction(L,cpp_pal); lua_setglobal(L, "pal");
lua_pushcfunction(L,cpp_palt); lua_setglobal(L, "palt");*/
lua_pushcfunction(L,cpp_pset); lua_setglobal(L, "pset");
lua_pushcfunction(L,cpp_pget); lua_setglobal(L, "pget");
lua_pushcfunction(L,cpp_line); lua_setglobal(L, "line");
@@ -536,10 +579,10 @@ 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_mousex); lua_setglobal(L, "mousex");
lua_pushcfunction(L,cpp_mousey); lua_setglobal(L, "mousey");
lua_pushcfunction(L,cpp_mwheel); lua_setglobal(L, "mwheel");
lua_pushcfunction(L,cpp_mbtn); lua_setglobal(L, "mbtn");
lua_pushcfunction(L,cpp_time); lua_setglobal(L, "time");
lua_pushcfunction(L,cpp_abs); lua_setglobal(L, "abs");
@@ -556,6 +599,8 @@ void lua_init() {
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_pushcfunction(L,cpp_ascii); lua_setglobal(L, "ascii");
lua_pushcfunction(L,cpp_strlen); lua_setglobal(L, "strlen");
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");

View File

@@ -9,15 +9,15 @@ void do_terminal() {
void do_sprite_editor() {
cls(14);
palt(0, false);
//palt(0, false);
rectfill(0, 0, 160, 7, 2);
rectfill(0, 115, 160, 119, 2);
sspr(0, 0, 128, 32, 0, 83);
sspr(0, 0, 8, 8, 8, 16, 64, 64);
rect(8, 16, 72, 80, 0);
spr(17, mouseX(), mouseY());
if (mouseButton(1) && mouseX()>=8 && mouseY()>=8 && mouseX()<72 && mouseY()<72) {
sset((mouseX()-8)/8, (mouseY()-16)/8);
spr(17, mousex(), mousey());
if (mbtn(1) && mousex()>=8 && mousey()>=8 && mousex()<72 && mousey()<72) {
sset((mousex()-8)/8, (mousey()-16)/8);
}
}

View File

@@ -33,9 +33,9 @@ namespace ds {
int cam[2] = {0, 0};
int clip[4] = {0, 0, screen_width, screen_height};
int clp[4] = {0, 0, screen_width-1, screen_height-1};
uint8_t draw_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
uint8_t screen_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
bool trans[16] = {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
//uint8_t draw_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
//uint8_t screen_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
uint8_t trans = 0;
uint16_t fill_pattern = 0b1111111111111111;
bool fill_trans = false;
}
@@ -46,7 +46,7 @@ SDL_Texture *mini_bak;
Uint32 *pixels;
int pitch;
uint32_t palette[16] = { 0x001a1c2c, 0x005d275d, 0x00b13e53, 0x00ef7d57, 0x00ffcd75, 0x00a7f070, 0x0038b764, 0x00257179,
uint32_t palette[256] = { 0x001a1c2c, 0x005d275d, 0x00b13e53, 0x00ef7d57, 0x00ffcd75, 0x00a7f070, 0x0038b764, 0x00257179,
0x0029366f, 0x003b5dc9, 0x0041a6f6, 0x0073eff7, 0x00f4f4f4, 0x0094b0c2, 0x00566c86, 0x00333c57 };
const char base64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -118,9 +118,9 @@ void reinit() {
ds::cam[0] = ds::cam[1] = 0;
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height;
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1;
for(int i=0;i<16;++i)ds::draw_palette[i]=i;
for(int i=0;i<16;++i)ds::screen_palette[i]=i;
ds::trans[0]=true;for(int i=1;i<16;++i)ds::trans[i]=false;
//for(int i=0;i<16;++i)ds::draw_palette[i]=i;
//for(int i=0;i<16;++i)ds::screen_palette[i]=i;
ds::trans=0;
ds::fill_pattern = 0b1111111111111111;
ds::fill_trans = false;
for (int i=1; i<10; ++i) {
@@ -220,8 +220,8 @@ void setmap(uint8_t surface) {
int main(int argc,char*argv[]){
int bi = 0;
for (int ci=0; ci<96; ci+=2) {
font[ci] = base64font[bi]-48+(base64font[bi+1]-48<<6)+((base64font[bi+2]-48&7)<<12);
font[ci+1] = (base64font[bi+2]-48>>3)+(base64font[bi+3]-48<<3)+(base64font[bi+4]-48<<9);
font[ci] = base64font[bi]-48+((base64font[bi+1]-48)<<6)+((base64font[bi+2]-48&7)<<12);
font[ci+1] = ((base64font[bi+2]-48)>>3)+((base64font[bi+3]-48)<<3)+((base64font[bi+4]-48)<<9);
bi += 5;
}
@@ -300,7 +300,7 @@ int main(int argc,char*argv[]){
loop();
}
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
for (int i=0;i<screen_surface->size;++i) pixels[i] = palette[ds::screen_palette[screen_surface->p[i]]];
for (int i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
SDL_UnlockTexture(mini_bak);
SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
SDL_RenderPresent(mini_ren);
@@ -318,7 +318,35 @@ void color(uint8_t color) {
ds::pen_color=color;
}
void pal() {
void loadpal(const char* filename) {
FILE *f = fopen(filename, "rb");
if (f) {
bmp_header_t header;
fread(&header, 54, 1, f);
if (header.num_colors == 0) header.num_colors = 1 << header.bpp;
header.image_size = (header.bmp_width*header.bmp_height) * (8/header.bpp);
fread(palette, header.num_colors*4, 1, f);
fclose(f);
}
}
void setpal(uint8_t index, uint32_t color) {
palette[index] = color;
}
uint32_t getpal(uint8_t index) {
return palette[index];
}
void settrans(uint8_t index) {
ds::trans = index;
}
uint8_t gettrans() {
return ds::trans;
}
/*void pal() {
for (int i=0; i<16; ++i) {
ds::draw_palette[i] = i;
ds::screen_palette[i] = i;
@@ -342,6 +370,7 @@ void palt(uint16_t bits) {
void palt(uint8_t col, bool t) {
ds::trans[col] = t;
}
*/
void simple_pset(int x, int y, uint8_t color) {
x -= ds::cam[0]; y -= ds::cam[1];
@@ -350,6 +379,12 @@ void simple_pset(int x, int y, uint8_t color) {
}
void pset(int x, int y) {
x -= ds::cam[0]; y -= ds::cam[1];
if (x < ds::clp[0] || x > ds::clp[2] || y < ds::clp[1] || y > ds::clp[3]) return;
if (ds::trans != ds::pen_color) DEST(x, y) = ds::pen_color;
}
/*void pset(int x, int y) {
x -= ds::cam[0]; y -= ds::cam[1];
if (x < ds::clp[0] || x > ds::clp[2] || y < ds::clp[1] || y > ds::clp[3]) return;
int pbx = x % 4, pby = y % 4;
@@ -359,7 +394,7 @@ void pset(int x, int y) {
} else {
if (!ds::fill_trans) DEST(x, y) = ds::draw_palette[ds::pen_color >> 4];
}
}
}*/
void pset(int x, int y, uint8_t color) {
ds::pen_color = color;
@@ -596,7 +631,7 @@ uint8_t sget(int x, int y) {
void sset(int x, int y) {
if (x < 0 || x > (source_surface->w-1) || y < 0 || y > (source_surface->h-1)) return;
SOURCE(x, y) = ds::draw_palette[ds::pen_color & 0xf];
SOURCE(x, y) = ds::pen_color;
}
void sset(int x, int y, uint8_t color) {
@@ -716,17 +751,17 @@ void cvline(int x, int y0, int y1, uint8_t c0, uint8_t c1) {
}
uint8_t mget(uint8_t celx, uint8_t cely) {
uint8_t mget(int celx, int cely) {
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return 0;
return TILES(celx, cely);
}
void mset(uint8_t celx, uint8_t cely, uint8_t snum) {
void mset(int celx, int cely, uint8_t snum) {
if (celx < 0 || celx > (map_surface->w-1) || cely < 0 || cely > (map_surface->h-1)) return;
TILES(celx, cely) = snum;
}
void map(uint8_t celx, uint8_t cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) {
void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer) {
//if (celw <= 0 || celh <= 0 || celw >= TILES_WIDTH || celh >= TILES_HEIGHT) return;
sx -= ds::cam[0]; sy -= ds::cam[1];
if (sx+celw*8 < ds::clp[0] || sx > ds::clp[2] || sy+celh*8 < ds::clp[1] || sy > ds::clp[3]) return;
@@ -758,19 +793,19 @@ bool btnp(uint8_t i) {
return key_just_pressed == i;
}
int mouseX() {
int mousex() {
return mouse_x;
}
int mouseY() {
int mousey() {
return mouse_y;
}
int mouseWheel() {
int mwheel() {
return mouse_wheel;
}
bool mouseButton(uint8_t i) {
bool mbtn(uint8_t i) {
return mouse_buttons & SDL_BUTTON(i);
}
@@ -790,7 +825,7 @@ float sgn(float x) {
return x >= 0 ? 1 : -1;
}
#ifndef __LINUX__
#ifdef __WINDOWS__
float ceil(float x) {
return SDL_ceilf(x);
@@ -863,3 +898,7 @@ void pdebug() {
}
}
}
uint8_t ascii(const char *str, uint8_t index) {
return str[index];
}

28
mini.h
View File

@@ -121,11 +121,18 @@ void setmap(uint8_t surface);
void cls(uint8_t color=0);
void color(uint8_t color=6);
void pal();
void loadpal(const char* filename);
void setpal(uint8_t index, uint32_t color);
uint32_t getpal(uint8_t index);
void settrans(uint8_t index);
uint8_t gettrans();
/*void pal();
void pal(uint8_t c0, uint8_t c1, uint8_t p = 0);
void palt();
void palt(uint16_t bits);
void palt(uint8_t col, bool t);
void palt(uint8_t col, bool t);*/
void pset(int x, int y);
void pset(int x, int y, uint8_t color);
@@ -182,17 +189,17 @@ void cline(int x0, int y0, int x1, int y1, uint8_t c0, uint8_t c1);
void chline(int x0, int y, int x1, uint8_t c0, uint8_t c1);
void cvline(int x, int y0, int y1, uint8_t c0, uint8_t c1);
uint8_t mget(uint8_t celx, uint8_t cely);
void mset(uint8_t celx, uint8_t cely, uint8_t snum);
void map(uint8_t celx, uint8_t cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer=0);
uint8_t mget(int celx, int cely);
void mset(int celx, int cely, uint8_t snum);
void map(int celx, int cely, int sx, int sy, uint8_t celw, uint8_t celh, uint8_t layer=0);
bool btn(uint8_t i);
bool btnp(uint8_t i);
int mouseX();
int mouseY();
int mouseWheel();
bool mouseButton(uint8_t i);
int mousex();
int mousey();
int mwheel();
bool mbtn(uint8_t i);
float time();
@@ -201,7 +208,7 @@ float time();
float flr(float x);
float sgn(float x);
#ifndef __LINUX__
#ifdef __WINDOWS__
float ceil(float x);
float sin(float x);
float cos(float x);
@@ -221,3 +228,4 @@ const char* tostr(int val);
void debug(const char *str);
void pdebug();
uint8_t ascii(const char *str, uint8_t index);

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

View File

@@ -1,19 +0,0 @@
JASC-PAL
0100
16
26 28 44
93 39 93
177 62 83
239 125 87
255 205 117
167 240 112
56 183 100
37 113 121
41 54 111
59 93 201
65 166 246
115 239 247
244 244 244
148 176 194
86 108 134
51 60 87