Commit 51b74a0c authored by deuce's avatar deuce
Browse files

Add new attr2palette() ciolib function that returns the palette entries

(fg and bg) for the given attribute.

Switch cterm to using ccputs() (which has no implementations yet).
parent 138e23ac
......@@ -349,19 +349,34 @@ void bitmap_setvideoflags(int flags)
force_redraws++;
}
void set_vmem_cell(struct vstat_vmem *vmem_ptr, size_t pos, uint16_t cell)
int bitmap_attr2palette(uint8_t attr, uint32_t *fgp, uint32_t *bgp)
{
uint32_t fg = (cell >> 8) & 0x0f;
uint32_t bg = (cell >> 12) & 0x0f;
uint32_t fg = attr & 0x0f;
uint32_t bg = (attr >> 4) & 0x0f;
if(!vstat.bright_background)
bg &= 0x07;
if(vstat.no_bright)
bg &= 0x07;
if (fgp)
*fgp = vstat.palette[fg];
if (bgp)
*bgp = vstat.palette[bg];
return 0;
}
static void set_vmem_cell(struct vstat_vmem *vmem_ptr, size_t pos, uint16_t cell)
{
uint32_t fg;
uint32_t bg;
bitmap_attr2palette(cell>>8, &fg, &bg);
vmem_ptr->vmem[pos] = cell;
vmem_ptr->fgvmem[pos] = vstat.palette[fg];
vmem_ptr->bgvmem[pos] = vstat.palette[bg];
vmem_ptr->fgvmem[pos] = fg;
vmem_ptr->bgvmem[pos] = bg;
}
int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy)
......
......@@ -30,5 +30,6 @@ int bitmap_getvideoflags(void);
void bitmap_setvideoflags(int flags);
void bitmap_setscaling(int new_value);
int bitmap_getscaling(void);
int bitmap_attr2palette(uint8_t attr, uint32_t *fgp, uint32_t *bgp);
#endif
......@@ -121,6 +121,7 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_getscaling(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_setpalette(uint32_t entry, uint16_t r, uint16_t g, uint16_t b);
CIOLIBEXPORT int CIOLIBCALL ciolib_cputch(uint32_t fg_palette, uint32_t bg_palette, int a);
CIOLIBEXPORT int CIOLIBCALL ciolib_ccputs(uint32_t fg_palette, uint32_t bg_palette, const char *str);
CIOLIBEXPORT int CIOLIBCALL ciolib_attr2palette(uint8_t attr, uint32_t *fg, uint32_t *bg);
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
int sdl_video_initialized = 0;
......@@ -167,6 +168,7 @@ int try_sdl_init(int mode)
cio_api.setscaling=sdl_setscaling;
cio_api.getscaling=sdl_getscaling;
cio_api.setpalette=sdl_setpalette;
cio_api.attr2palette=bitmap_attr2palette;
return(1);
}
return(0);
......@@ -214,6 +216,7 @@ int try_x_init(int mode)
cio_api.setscaling=bitmap_setscaling;
cio_api.getscaling=bitmap_getscaling;
cio_api.setpalette=x_setpalette;
cio_api.attr2palette=bitmap_attr2palette;
return(1);
}
return(0);
......@@ -1418,8 +1421,8 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_ccputs(uint32_t fg_palette, uint32_t bg_palet
CIOLIB_INIT();
if (cio_api.ccputs != NULL)
return ciolib_ccputs(fg_palette, bg_palette, s);
if (cio_api.cputch != NULL) {
return cio_api.ccputs(fg_palette, bg_palette, s);
if (cio_api.cputch == NULL) {
int pos;
int ret=0;
int olddmc;
......@@ -1624,3 +1627,10 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_setpalette(uint32_t entry, uint16_t r, uint16
return(cio_api.setpalette(entry, r, g, b));
return(1);
}
CIOLIBEXPORT int CIOLIBCALL ciolib_attr2palette(uint8_t attr, uint32_t *fg, uint32_t *bg)
{
if (cio_api.attr2palette)
return cio_api.attr2palette(attr, fg, bg);
return -1;
}
......
......@@ -315,6 +315,7 @@ typedef struct {
int (*getscaling) (void);
int *ESCDELAY;
int (*setpalette) (uint32_t entry, uint16_t r, uint16_t g, uint16_t b);
int (*attr2palette) (uint8_t attr, uint32_t *fg, uint32_t *bg);
} cioapi_t;
CIOLIBEXPORTVAR cioapi_t cio_api;
......@@ -386,6 +387,7 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_getvideoflags(void);
CIOLIBEXPORT void CIOLIBCALL ciolib_setscaling(int flags);
CIOLIBEXPORT int CIOLIBCALL ciolib_getscaling(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_setpalette(uint32_t entry, uint16_t r, uint16_t g, uint16_t b);
CIOLIBEXPORT int CIOLIBCALL ciolib_attr2palette(uint8_t attr, uint32_t *fg, uint32_t *bg);
/* DoorWay specific stuff that's only applicable to ANSI mode. */
CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
......@@ -450,6 +452,7 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#define setscaling(a) ciolib_setscaling(a)
#define getscaling() ciolib_getscaling()
#define setpalette(e,r,g,b) ciolib_setpalette(e,r,g,b)
#define attr2palette(a,b,c) ciolib_attr2palette(a,b,c)
#endif
#ifdef WITH_SDL
......
......@@ -177,9 +177,11 @@ struct note_params {
#define SETVIDEOFLAGS(a) cterm->ciolib_setvideoflags(cterm,a)
#define GETVIDEOFLAGS() cterm->ciolib_getvideoflags(cterm)
#define PUTCH(a) cterm->ciolib_putch(cterm,a)
#define CPUTCH(a,b,c) cterm->ciolib_cputch(cterm,a,b,c)
#define PUTTEXT(a,b,c,d,e) cterm->ciolib_puttext(cterm,a,b,c,d,e)
#define WINDOW(a,b,c,d) cterm->ciolib_window(cterm,a,b,c,d)
#define CPUTS(a) cterm->ciolib_cputs(cterm,a)
#define CCPUTS(a,b,c) cterm->ciolib_ccputs(cterm,a,b,c)
#define SETFONT(a,b,c) cterm->ciolib_setfont(cterm,a,b,c)
#else
#define GOTOXY(x,y) cterm->ciolib_gotoxy(x, y)
......@@ -195,9 +197,11 @@ struct note_params {
#define SETVIDEOFLAGS(a) cterm->ciolib_setvideoflags(a)
#define GETVIDEOFLAGS() cterm->ciolib_getvideoflags()
#define PUTCH(a) cterm->ciolib_putch(a)
#define CPUTCH(a,b,c) cterm->ciolib_cputch(a,b,c)
#define PUTTEXT(a,b,c,d,e) cterm->ciolib_puttext(a,b,c,d,e)
#define WINDOW(a,b,c,d) cterm->ciolib_window(a,b,c,d)
#define CPUTS(a) cterm->ciolib_cputs(a)
#define CCPUTS(a,b,c) cterm->ciolib_ccputs(a,b,c)
#define SETFONT(a,b,c) cterm->ciolib_setfont(a,b,c)
#endif
......@@ -519,6 +523,11 @@ static int ciolib_putch(struct cterminal *cterm,int a)
return(a1);
}
static int ciolib_cputch(struct cterminal *cterm, uint32_t fg, uint32_t bg, int a)
{
return ciolib_putch(cterm, a);
}
static int ciolib_puttext(struct cterminal *cterm,int sx, int sy, int ex, int ey, void *fill)
{
int x,y;
......@@ -589,6 +598,11 @@ static int ciolib_cputs(struct cterminal *cterm, char *str)
return(ret);
}
static int ciolib_ccputs(struct cterminal *cterm, uint32_t fg, uint32_t bg, char *str)
{
return ciolib_cputs(cterm, str);
}
static int ciolib_setfont(struct cterminal *,int font, int force, int font_num)
{
CTERM_INIT();
......@@ -1998,17 +2012,16 @@ static void do_ansi(struct cterminal *cterm, char *retbuf, size_t retsize, int *
for (i=0; i < seq->param_count; i++) {
switch(seq->param_int[i]) {
case 0:
cterm->fg_color = UINT32_MAX;
cterm->bg_color = UINT32_MAX;
cterm->attr=ti.normattr;
attr2palette(cterm->attr, &cterm->fg_color, &cterm->bg_color);
break;
case 1:
cterm->fg_color = UINT32_MAX;
cterm->attr|=8;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 2:
cterm->fg_color = UINT32_MAX;
cterm->attr&=247;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 4: /* Underscore */
break;
......@@ -2018,107 +2031,105 @@ static void do_ansi(struct cterminal *cterm, char *retbuf, size_t retsize, int *
break;
case 7:
case 27:
cterm->fg_color = UINT32_MAX;
cterm->bg_color = UINT32_MAX;
i=cterm->attr&7;
j=cterm->attr&112;
cterm->attr &= 136;
cterm->attr |= j>>4;
cterm->attr |= i<<4;
attr2palette(cterm->attr, &cterm->fg_color, &cterm->bg_color);
break;
case 8:
cterm->fg_color = UINT32_MAX;
cterm->bg_color = UINT32_MAX;
j=cterm->attr&112;
cterm->attr&=112;
cterm->attr |= j>>4;
attr2palette(cterm->attr, &cterm->fg_color, &cterm->bg_color);
break;
case 22:
cterm->fg_color = UINT32_MAX;
cterm->attr &= 0xf7;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 25:
cterm->attr &= 0x7f;
break;
case 30:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 31:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=4;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 32:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=2;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 33:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=6;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 34:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=1;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 35:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=5;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 36:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=3;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 37:
case 39:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=7;
attr2palette(cterm->attr, &cterm->fg_color, NULL);
break;
case 49:
case 40:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
case 41:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=4<<4;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
case 42:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=2<<4;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
case 43:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=6<<4;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
case 44:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=1<<4;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
case 45:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=5<<4;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
case 46:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=3<<4;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
case 47:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=7<<4;
attr2palette(cterm->attr, NULL, &cterm->bg_color);
break;
}
}
......@@ -2432,9 +2443,11 @@ struct cterminal* CIOLIBCALL cterm_init(int height, int width, int xpos, int ypo
cterm->ciolib_setscaling=ciolib_setscaling;
cterm->ciolib_getscaling=ciolib_getscaling;
cterm->ciolib_putch=ciolib_putch;
cterm->ciolib_cputch=ciolib_cputch;
cterm->ciolib_puttext=ciolib_puttext;
cterm->ciolib_window=ciolib_window;
cterm->ciolib_cputs=ciolib_cputs;
cterm->ciolib_ccputs=ciolib_ccputs;
cterm->ciolib_setfont=ciolib_setfont;
cterm->_wscroll=&_wscroll;
cterm->puttext_can_move=&puttext_can_move;
......@@ -2484,7 +2497,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
case '\n':
*p=0;
CPUTS(outp);
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
outp=p+1;
if(cy==cterm->bottom_margin)
scrollup(cterm);
......@@ -2494,7 +2507,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
case '\b':
*p=0;
CPUTS(outp);
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
outp=p+1;
if(cx>1)
cx--;
......@@ -2504,7 +2517,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
case '\t':
*p=0;
CPUTS(outp);
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
outp=p+1;
for(i=0;i<sizeof(cterm_tabs)/sizeof(cterm_tabs[0]);i++) {
if(cterm_tabs[i]>cx) {
......@@ -2526,7 +2539,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
char ch;
ch=*(p+1);
*(p+1)=0;
CPUTS(outp);
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
*(p+1)=ch;
outp=p+1;
GOTOXY(cx,cy);
......@@ -2537,7 +2550,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
char ch;
ch=*(p+1);
*(p+1)=0;
CPUTS(outp);
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
*(p+1)=ch;
outp=p+1;
scrollup(cterm);
......@@ -2557,7 +2570,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
}
}
CPUTS(outp);
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
*cterm->_wscroll=oldscroll;
}
......
......@@ -166,9 +166,11 @@ struct cterminal {
void (*ciolib_setscaling) (struct cterminal *,int new_value);
int (*ciolib_getscaling) (struct cterminal *);
int (*ciolib_putch) (struct cterminal *,int);
int (*ciolib_cputch) (struct cterminal *,uint32_t,uint32_t,int);
int (*ciolib_puttext) (struct cterminal *,int,int,int,int,void *);
void (*ciolib_window) (struct cterminal *,int,int,int,int);
int (*ciolib_cputs) (struct cterminal *,char *);
int (*ciolib_ccputs) (struct cterminal *,uint32_t,uint32_t,const char *);
int (*ciolib_setfont) (struct cterminal *,int font, int force, int font_num);
#else
void CIOLIBCALL (*ciolib_gotoxy) (int,int);
......@@ -186,9 +188,11 @@ struct cterminal {
void CIOLIBCALL (*ciolib_setscaling) (int new_value);
int CIOLIBCALL (*ciolib_getscaling) (void);
int CIOLIBCALL (*ciolib_putch) (int);
int CIOLIBCALL (*ciolib_cputch) (uint32_t, uint32_t, int);
int CIOLIBCALL (*ciolib_puttext) (int,int,int,int,void *);
void CIOLIBCALL (*ciolib_window) (int,int,int,int);
int CIOLIBCALL (*ciolib_cputs) (char *);
int CIOLIBCALL (*ciolib_ccputs) (uint32_t, uint32_t, const char *);
int CIOLIBCALL (*ciolib_setfont) (int font, int force, int font_num);
#endif
int *_wscroll;
......
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