[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

@@ -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];
}