Commit d388ae4d authored by deuce's avatar deuce
Browse files

Have ciolib track current extended fg/bg colours, and add new setcolours()

function.  This allows simple fixing of clreol() and clrscrn() which were
not aware of 256-colour mode.

cputs and cputch aren't really needed anymore, but they may be useful, so
leave them in.
parent 9ef66469
......@@ -454,6 +454,8 @@ void bitmap_clreol(void)
vmem_ptr = lock_vmem(&vstat);
for(x=cio_textinfo.curx+cio_textinfo.winleft-2; x<cio_textinfo.winright; x++) {
set_vmem_cell(vmem_ptr, pos+x, fill);
vmem_ptr->fgvmem[pos+x] = ciolib_fg;
vmem_ptr->bgvmem[pos+x] = ciolib_bg;
pthread_mutex_unlock(&vmem_lock);
bitmap_draw_one_char(&vstat, x+1, row);
pthread_mutex_lock(&vmem_lock);
......@@ -471,6 +473,8 @@ void bitmap_clrscr(void)
for(y=cio_textinfo.wintop-1; y<cio_textinfo.winbottom; y++) {
for(x=cio_textinfo.winleft-1; x<cio_textinfo.winright; x++) {
set_vmem_cell(vmem_ptr, y*cio_textinfo.screenwidth+x, fill);
vmem_ptr->fgvmem[y*cio_textinfo.screenwidth+x] = ciolib_fg;
vmem_ptr->bgvmem[y*cio_textinfo.screenwidth+x] = ciolib_bg;
pthread_mutex_unlock(&vmem_lock);
bitmap_draw_one_char(&vstat, x+1, y+1);
pthread_mutex_lock(&vmem_lock);
......@@ -620,12 +624,20 @@ int bitmap_setfont(int font, int force, int font_num)
int newmode=-1;
struct text_info ti;
char *old;
uint32_t *oldf;
uint32_t *oldb;
int ow,oh;
int row,col;
char *new;
uint32_t *newf;
uint32_t *newb;
int attr;
char *pold;
uint32_t *poldf;
uint32_t *poldb;
char *pnew;
uint32_t *pnewf;
uint32_t *pnewb;
int result = CIOLIB_SETFONT_CHARHEIGHT_NOT_SUPPORTED;
if(!bitmap_initialized)
......@@ -698,43 +710,70 @@ int bitmap_setfont(int font, int force, int font_num)
oh=ti.screenheight;
old=malloc(ow*oh*2);
if(old) {
gettext(1,1,ow,oh,old);
oldf=malloc(ow*oh*sizeof(oldf[0]));
oldb=malloc(ow*oh*sizeof(oldf[0]));
if(old && oldf && oldb) {
pgettext(1,1,ow,oh,old,oldf,oldb);
textmode(newmode);
new=malloc(ti.screenwidth*ti.screenheight*2);
newf=malloc(ti.screenwidth*ti.screenheight*sizeof(newf[0]));
newb=malloc(ti.screenwidth*ti.screenheight*sizeof(newb[0]));
if(!new) {
free(old);
FREE_AND_NULL(oldf);
FREE_AND_NULL(oldb);
return CIOLIB_SETFONT_MALLOC_FAILURE;
}
pold=old;
poldf=oldf;
poldb=oldb;
pnew=new;
pnewf=newf;
pnewb=newb;
for(row=0; row<ti.screenheight; row++) {
for(col=0; col<ti.screenwidth; col++) {
if(row < oh) {
if(col < ow) {
*(new++)=*(old++);
*(new++)=*(old++);
*(newf++)=*(oldf++);
*(newb++)=*(oldb++);
}
else {
*(new++)=space;
*(new++)=attr;
*(newf++) = ciolib_fg;
*(newb++) = ciolib_bg;
}
}
else {
*(new++)=space;
*(new++)=attr;
*(newf++) = ciolib_fg;
*(newb++) = ciolib_bg;
}
}
if(row < oh) {
for(;col<ow;col++) {
old++;
old++;
oldf++;
oldb++;
}
}
}
puttext(1,1,ti.screenwidth,ti.screenheight,new);
pputtext(1,1,ti.screenwidth,ti.screenheight,pnew,pnewf,pnewb);
free(pnew);
free(pnewf);
free(pnewb);
free(pold);
free(poldf);
free(poldb);
}
else {
FREE_AND_NULL(old);
FREE_AND_NULL(oldf);
FREE_AND_NULL(oldb);
}
}
bitmap_loadfont(NULL);
......@@ -895,7 +934,6 @@ error_return:
static void bitmap_draw_cursor(struct video_stats *vs)
{
int y;
char attr;
int pixel;
int xoffset,yoffset;
int yo, xw, yw;
......@@ -909,13 +947,12 @@ static void bitmap_draw_cursor(struct video_stats *vs)
yoffset=(vs->curs_row-1)*vs->charheight;
if(xoffset < 0 || yoffset < 0)
return;
attr=cio_textinfo.attribute&0x0f;
pthread_mutex_lock(&screenlock);
for(y=vs->curs_start; y<=vs->curs_end; y++) {
if(xoffset < screenwidth && (yoffset+y) < screenheight) {
pixel=PIXEL_OFFSET(xoffset, yoffset+y);
memset_u32(screen+pixel,vs->palette[attr],vs->charwidth);
memset_u32(screen+pixel,ciolib_fg,vs->charwidth);
}
}
pthread_mutex_unlock(&screenlock);
......
......@@ -72,6 +72,8 @@ CIOLIBEXPORT cioapi_t cio_api;
static const int tabs[]={1,9,17,25,33,41,49,57,65,73,81,89,97,105,113,121,129,137,145};
static int ungotch;
struct text_info cio_textinfo;
uint32_t ciolib_fg;
uint32_t ciolib_bg;
static int lastmode=C80;
CIOLIBEXPORT int _wscroll=1;
CIOLIBEXPORT int directvideo=0;
......@@ -131,6 +133,7 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_freepixels(struct ciolib_pixels *pixels);
CIOLIBEXPORT struct ciolib_screen * CIOLIBCALL ciolib_savescreen(void);
CIOLIBEXPORT void CIOLIBCALL ciolib_freescreen(struct ciolib_screen *);
CIOLIBEXPORT int CIOLIBCALL ciolib_restorescreen(struct ciolib_screen *scrn);
CIOLIBEXPORT void CIOLIBCALL ciolib_setcolour(uint32_t fg, uint32_t bg);
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
int sdl_video_initialized = 0;
......@@ -881,18 +884,21 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_clreol(void)
free(buf);
return;
}
for (i = 0; i < width*height; i++) {
fgbuf[i] = ciolib_fg;
bgbuf[i] = ciolib_bg;
}
}
for(i=0;i<width*height*2;) {
ciolib_attr2palette(cio_textinfo.attribute, &fgbuf[i>>1], &bgbuf[i>>1]);
buf[i++]=' ';
buf[i++]=cio_textinfo.attribute;
}
ciolib_puttext(
ciolib_pputtext(
cio_textinfo.curx+cio_textinfo.winleft-1,
cio_textinfo.cury+cio_textinfo.wintop-1,
cio_textinfo.winright,
cio_textinfo.cury+cio_textinfo.wintop-1,
buf);
buf, fgbuf, bgbuf);
if (fgbuf)
free(fgbuf);
if (bgbuf)
......@@ -933,6 +939,10 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_clrscr(void)
free(buf);
return;
}
for (i = 0; i < width*height; i++) {
fgbuf[i] = ciolib_fg;
bgbuf[i] = ciolib_bg;
}
}
for(i=0;i<width*height*2;) {
buf[i++]=' ';
......@@ -1394,6 +1404,7 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_textattr(int a)
}
cio_textinfo.attribute=a;
ciolib_attr2palette(a, &ciolib_fg, &ciolib_bg);
}
/* Optional */
......@@ -1522,12 +1533,8 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_putch(int a)
{
CIOLIB_INIT();
if (cio_api.putch == NULL) {
uint32_t fg,bg;
ciolib_attr2palette(cio_textinfo.attribute, &fg, &bg);
return ciolib_cputch(fg, bg, a);
}
if (cio_api.putch == NULL)
return ciolib_cputch(ciolib_fg, ciolib_bg, a);
return cio_api.putch(a);
}
......@@ -1821,6 +1828,8 @@ CIOLIBEXPORT struct ciolib_screen * CIOLIBCALL ciolib_savescreen(void)
ret->pixels = ciolib_getpixels(0, 0, vparams[vmode].charwidth * vparams[vmode].cols - 1, vparams[vmode].charheight * vparams[vmode].rows - 1);
ciolib_pgettext(1, 1, vparams[vmode].cols, vparams[vmode].rows, ret->vmem, ret->foreground, ret->background);
ret->fg_colour = ciolib_fg;
ret->bg_colour = ciolib_bg;
return ret;
}
......@@ -1854,5 +1863,12 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_restorescreen(struct ciolib_screen *scrn)
ciolib_window(scrn->text_info.winleft, scrn->text_info.wintop, scrn->text_info.winright, scrn->text_info.winbottom);
vmode = find_vmode(scrn->text_info.currmode);
ciolib_setpixels(0, 0, vparams[vmode].charwidth * vparams[vmode].cols - 1, vparams[vmode].charheight * vparams[vmode].rows - 1, 0, 0, scrn->pixels);
ciolib_setcolour(scrn->fg_colour, scrn->bg_colour);
return 1;
}
CIOLIBEXPORT void CIOLIBCALL ciolib_setcolour(uint32_t fg, uint32_t bg)
{
ciolib_fg = fg;
ciolib_bg = bg;
}
......
......@@ -231,6 +231,8 @@ struct text_info {
};
CIOLIBEXPORTVAR struct text_info cio_textinfo;
CIOLIBEXPORTVAR uint32_t ciolib_fg;
CIOLIBEXPORTVAR uint32_t ciolib_bg;
struct mouse_event {
int event;
......@@ -259,6 +261,8 @@ struct ciolib_pixels {
};
struct ciolib_screen {
uint32_t fg_colour;
uint32_t bg_colour;
struct ciolib_pixels *pixels;
void *vmem;
uint32_t *foreground;
......@@ -416,7 +420,7 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_freepixels(struct ciolib_pixels *pixels);
CIOLIBEXPORT struct ciolib_screen * CIOLIBCALL ciolib_savescreen(void);
CIOLIBEXPORT void CIOLIBCALL ciolib_freescreen(struct ciolib_screen *);
CIOLIBEXPORT int CIOLIBCALL ciolib_restorescreen(struct ciolib_screen *scrn);
CIOLIBEXPORT void CIOLIBCALL ciolib_setcolour(uint32_t fg, uint32_t bg);
/* DoorWay specific stuff that's only applicable to ANSI mode. */
CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
......@@ -491,6 +495,7 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#define savescreen() ciolib_savescreen()
#define freescreen(a) ciolib_freescreen(a)
#define restorescreen(a) ciolib_restorescreen(a)
#define setcolour(a,b) ciolib_setcolour(a,b)
#endif
#ifdef WITH_SDL
......
......@@ -2353,6 +2353,7 @@ static void do_ansi(struct cterminal *cterm, char *retbuf, size_t retsize, int *
}
}
TEXTATTR(cterm->attr);
setcolour(cterm->fg_color, cterm->bg_color);
break;
case 'n': /* Device Status Report */
seq_default(seq, 0, 0);
......@@ -2732,7 +2733,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
case '\n':
*p=0;
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
CPUTS(outp);
outp=p+1;
if(cy==cterm->bottom_margin)
scrollup(cterm);
......@@ -2742,7 +2743,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
case '\b':
*p=0;
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
CPUTS(outp);
outp=p+1;
if(cx>1)
cx--;
......@@ -2752,7 +2753,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
case '\t':
*p=0;
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
CPUTS(outp);
outp=p+1;
for(i=0;i<sizeof(cterm_tabs)/sizeof(cterm_tabs[0]);i++) {
if(cterm_tabs[i]>cx) {
......@@ -2774,7 +2775,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
char ch;
ch=*(p+1);
*(p+1)=0;
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
CPUTS(outp);
*(p+1)=ch;
outp=p+1;
GOTOXY(cx,cy);
......@@ -2785,7 +2786,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
char ch;
ch=*(p+1);
*(p+1)=0;
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
CPUTS(outp);
*(p+1)=ch;
outp=p+1;
scrollup(cterm);
......@@ -2805,7 +2806,7 @@ static void ctputs(struct cterminal *cterm, char *buf)
break;
}
}
CCPUTS(cterm->fg_color, cterm->bg_color, outp);
CPUTS(outp);
*cterm->_wscroll=oldscroll;
}
......@@ -2921,6 +2922,7 @@ CIOLIBEXPORT char* CIOLIBCALL cterm_write(struct cterminal * cterm, const void *
WINDOW(cterm->x,cterm->y,cterm->x+cterm->width-1,cterm->y+cterm->height-1);
GOTOXY(cterm->xpos,cterm->ypos);
TEXTATTR(cterm->attr);
setcolour(cterm->fg_color, cterm->bg_color);
SETCURSORTYPE(cterm->cursor);
ch[1]=0;
if(buflen==-1)
......@@ -3343,8 +3345,6 @@ CIOLIBEXPORT char* CIOLIBCALL cterm_write(struct cterminal * cterm, const void *
case 156: /* Purple */
case 158: /* Yellow */
case 159: /* Cyan */
cterm->fg_color = UINT32_MAX;
cterm->bg_color = UINT32_MAX;
cterm->attr &= 0xf0;
switch(buf[j]) {
case 5: /* White */
......
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