Commit 003e01f4 authored by deuce's avatar deuce
Browse files

Move font updates into ciolib to allow updating the current font.

parent f5990a97
......@@ -1497,6 +1497,46 @@ uint32_t bitmap_map_rgb(uint16_t r, uint16_t g, uint16_t b)
return i + TOTAL_DAC_SIZE + 512;
}
void bitmap_replace_font(uint8_t id, char *name, void *data, size_t size)
{
pthread_mutex_lock(&blinker_lock);
if (id < CONIO_FIRST_FREE_FONT) {
free(name);
free(data);
return;
}
pthread_mutex_lock(&screen.screenlock);
switch (size) {
case 4096:
FREE_AND_NULL(conio_fontdata[id].eight_by_sixteen);
conio_fontdata[id].eight_by_sixteen=data;
FREE_AND_NULL(conio_fontdata[id].desc);
conio_fontdata[id].desc=name;
update_pixels = 1;
break;
case 3584:
FREE_AND_NULL(conio_fontdata[id].eight_by_fourteen);
conio_fontdata[id].eight_by_fourteen=data;
FREE_AND_NULL(conio_fontdata[id].desc);
conio_fontdata[id].desc=name;
break;
case 2048:
FREE_AND_NULL(conio_fontdata[id].eight_by_eight);
conio_fontdata[id].eight_by_eight=data;
FREE_AND_NULL(conio_fontdata[id].desc);
conio_fontdata[id].desc=name;
break;
default:
free(name);
free(data);
}
update_pixels = 1;
pthread_mutex_unlock(&screen.screenlock);
pthread_mutex_unlock(&blinker_lock);
}
/***********************/
/* Called from drivers */
/***********************/
......
......@@ -44,6 +44,7 @@ struct ciolib_pixels *bitmap_getpixels(uint32_t sx, uint32_t sy, uint32_t ex, ui
uint32_t *bitmap_get_modepalette(uint32_t p[16]);
int bitmap_set_modepalette(uint32_t p[16]);
uint32_t bitmap_map_rgb(uint16_t r, uint16_t g, uint16_t b);
void bitmap_replace_font(uint8_t id, char *name, void *data, size_t size);
#endif
#ifdef BITMAP_CIOLIB_DRIVER
......
......@@ -190,6 +190,7 @@ int try_sdl_init(int mode)
cio_api.get_modepalette=bitmap_get_modepalette;
cio_api.set_modepalette=bitmap_set_modepalette;
cio_api.map_rgb = bitmap_map_rgb;
cio_api.replace_font = bitmap_replace_font;
return(1);
}
return(0);
......@@ -245,6 +246,7 @@ int try_x_init(int mode)
cio_api.get_modepalette=bitmap_get_modepalette;
cio_api.set_modepalette=bitmap_set_modepalette;
cio_api.map_rgb = bitmap_map_rgb;
cio_api.replace_font = bitmap_replace_font;
return(1);
}
return(0);
......@@ -1922,3 +1924,15 @@ CIOLIBEXPORT uint32_t CIOLIBCALL ciolib_map_rgb(uint16_t r, uint16_t g, uint16_t
return cio_api.map_rgb(r,g,b);
return UINT32_MAX;
}
CIOLIBEXPORT void CIOLIBCALL ciolib_replace_font(uint8_t id, char *name, void *data, size_t size)
{
CIOLIB_INIT();
if (cio_api.replace_font) {
cio_api.replace_font(id, name, data, size);
return;
}
free(name);
free(data);
}
......
......@@ -363,6 +363,7 @@ typedef struct {
uint32_t *(*get_modepalette)(uint32_t[16]);
int (*set_modepalette)(uint32_t[16]);
uint32_t (*map_rgb)(uint16_t r, uint16_t g, uint16_t b);
void (*replace_font)(uint8_t id, char *name, void *data, size_t size);
} cioapi_t;
CIOLIBEXPORTVAR cioapi_t cio_api;
......@@ -453,6 +454,7 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_setcolour(uint32_t fg, uint32_t bg);
CIOLIBEXPORT uint32_t * CIOLIBCALL ciolib_get_modepalette(uint32_t[16]);
CIOLIBEXPORT int CIOLIBCALL ciolib_set_modepalette(uint32_t[16]);
CIOLIBEXPORT uint32_t CIOLIBCALL ciolib_map_rgb(uint16_t r, uint16_t g, uint16_t b);
CIOLIBEXPORT void CIOLIBCALL ciolib_replace_font(uint8_t id, char *name, void *data, size_t size);
/* DoorWay specific stuff that's only applicable to ANSI mode. */
CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
......@@ -531,6 +533,7 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#define get_modepalette(a) ciolib_get_modepalette(a)
#define set_modepalette(a) ciolib_set_modepalette(a)
#define map_rgb(a,b,c) ciolib_map_rgb(a,b,c)
#define replace_font(a,b,c,d) ciolib_replace_font(a,b,c,d);
#endif
#ifdef WITH_SDL
......
......@@ -2702,37 +2702,10 @@ static void do_ansi(struct cterminal *cterm, char *retbuf, size_t retsize, int *
if (p && *p == ':') {
p++;
i = b64_decode(cterm->fontbuf, sizeof(cterm->fontbuf), p, 0);
switch (i) {
case 4096:
p2 = malloc(i);
if (p2) {
memcpy(p2, cterm->fontbuf, i);
FREE_AND_NULL(conio_fontdata[cterm->font_slot].eight_by_sixteen);
conio_fontdata[cterm->font_slot].eight_by_sixteen=p2;
FREE_AND_NULL(conio_fontdata[cterm->font_slot].desc);
conio_fontdata[cterm->font_slot].desc=strdup("Remote Defined Font");
}
break;
case 3584:
p2 = malloc(i);
if (p2) {
memcpy(p2, cterm->fontbuf, i);
FREE_AND_NULL(conio_fontdata[cterm->font_slot].eight_by_fourteen);
conio_fontdata[cterm->font_slot].eight_by_fourteen=p2;
FREE_AND_NULL(conio_fontdata[cterm->font_slot].desc);
conio_fontdata[cterm->font_slot].desc=strdup("Remote Defined Font");
}
break;
case 2048:
p2 = malloc(i);
if (p2) {
memcpy(p2, cterm->fontbuf, i);
FREE_AND_NULL(conio_fontdata[cterm->font_slot].eight_by_eight);
conio_fontdata[cterm->font_slot].eight_by_eight=p2;
FREE_AND_NULL(conio_fontdata[cterm->font_slot].desc);
conio_fontdata[cterm->font_slot].desc=strdup("Remote Defined Font");
}
break;
p2 = malloc(i);
if (p2) {
memcpy(p2, cterm->fontbuf, i);
replace_font(cterm->font_slot, strdup("Remote Defined Font"), p2, i);
}
}
}
......@@ -3302,29 +3275,7 @@ CIOLIBEXPORT char* CIOLIBCALL cterm_write(struct cterminal * cterm, const void *
if((buf2=(char *)malloc(cterm->font_size))!=NULL) {
memcpy(buf2,cterm->fontbuf,cterm->font_size);
if(cterm->font_slot >= CONIO_FIRST_FREE_FONT && cterm->font_slot < 256) {
switch(cterm->font_size) {
case 4096:
FREE_AND_NULL(conio_fontdata[cterm->font_slot].eight_by_sixteen);
conio_fontdata[cterm->font_slot].eight_by_sixteen=buf2;
FREE_AND_NULL(conio_fontdata[cterm->font_slot].desc);
conio_fontdata[cterm->font_slot].desc=strdup("Remote Defined Font");
break;
case 3584:
FREE_AND_NULL(conio_fontdata[cterm->font_slot].eight_by_fourteen);
conio_fontdata[cterm->font_slot].eight_by_fourteen=buf2;
FREE_AND_NULL(conio_fontdata[cterm->font_slot].desc);
conio_fontdata[cterm->font_slot].desc=strdup("Remote Defined Font");
break;
case 2048:
FREE_AND_NULL(conio_fontdata[cterm->font_slot].eight_by_eight);
conio_fontdata[cterm->font_slot].eight_by_eight=buf2;
FREE_AND_NULL(conio_fontdata[cterm->font_slot].desc);
conio_fontdata[cterm->font_slot].desc=strdup("Remote Defined Font");
break;
default:
FREE_AND_NULL(buf2);
break;
}
replace_font(cterm->font_slot, strdup("Remote Defined Font"), buf2, i);
}
else
FREE_AND_NULL(buf2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment