Commit 1195dde5 authored by deuce's avatar deuce
Browse files

Break all the graphics modes. I promise to fix them tonight after I

finish work.

This is going to be cool though.  Don't try this at home unless you're me.
parent 02c55ca2
......@@ -132,6 +132,7 @@ int bitmap_init(void (*drawrect_cb) (int xpos, int ypos, int width, int height,
pthread_mutex_init(&screenlock, NULL);
pthread_mutex_lock(&vmem_lock);
vstat.vmem=NULL;
vstat.flags = VIDMODES_FLAG_PALETTE_VMEM;
pthread_mutex_unlock(&vmem_lock);
callbacks.drawrect=drawrect_cb;
......@@ -168,8 +169,11 @@ int bitmap_init_mode(int mode, int *width, int *height)
}
/* Initialize video memory with black background, white foreground */
for (i = 0; i < vstat.cols*vstat.rows; ++i)
for (i = 0; i < vstat.cols*vstat.rows; ++i) {
vstat.vmem->vmem[i] = 0x0700;
vstat.vmem->bgvmem[i] = vstat.palette[0];
vstat.vmem->fgvmem[i] = vstat.palette[7];
}
pthread_mutex_unlock(&vmem_lock);
screenwidth=vstat.charwidth*vstat.cols;
......@@ -345,6 +349,13 @@ void bitmap_setvideoflags(int flags)
force_redraws++;
}
void set_vmem_attr(struct vstat_vmem *vmem_ptr, size_t pos, uint16_t attr)
{
vmem_ptr->vmem[pos] = attr;
vmem_ptr->fgvmem[pos] = vstat.palette[attr >> 8];
vmem_ptr->bgvmem[pos] = vstat.palette[attr & 0xff];
}
int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy)
{
int direction=1;
......@@ -379,6 +390,8 @@ int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy)
for(cy=(direction==-1?(height-1):0); cy<height && cy>=0; cy+=direction) {
sourcepos=((y-1)+cy)*cio_textinfo.screenwidth+(x-1);
memmove(&(vmem_ptr->vmem[sourcepos+destoffset]), &(vmem_ptr->vmem[sourcepos]), sizeof(vmem_ptr->vmem[0])*width);
memmove(&(vmem_ptr->fgvmem[sourcepos+destoffset]), &(vmem_ptr->fgvmem[sourcepos]), sizeof(vmem_ptr->fgvmem[0])*width);
memmove(&(vmem_ptr->bgvmem[sourcepos+destoffset]), &(vmem_ptr->bgvmem[sourcepos]), sizeof(vmem_ptr->bgvmem[0])*width);
}
unlock_vmem(vmem_ptr);
return(1);
......@@ -393,7 +406,7 @@ void bitmap_clreol(void)
pos=(cio_textinfo.cury+cio_textinfo.wintop-2)*cio_textinfo.screenwidth;
vmem_ptr = lock_vmem(&vstat);
for(x=cio_textinfo.curx+cio_textinfo.winleft-2; x<cio_textinfo.winright; x++)
vmem_ptr->vmem[pos+x]=fill;
set_vmem_attr(vmem_ptr, pos+x, fill);
unlock_vmem(vmem_ptr);
}
......@@ -406,7 +419,7 @@ void bitmap_clrscr(void)
vmem_ptr = lock_vmem(&vstat);
for(y=cio_textinfo.wintop-1; y<cio_textinfo.winbottom; y++) {
for(x=cio_textinfo.winleft-1; x<cio_textinfo.winright; x++)
vmem_ptr->vmem[y*cio_textinfo.screenwidth+x]=fill;
set_vmem_attr(vmem_ptr, y*cio_textinfo.screenwidth+x, fill);
}
unlock_vmem(vmem_ptr);
}
......@@ -439,7 +452,7 @@ int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill)
for(x=sx-1;x<ex;x++) {
sch=*(out++);
sch |= (*(out++))<<8;
vmem_ptr->vmem[y*cio_textinfo.screenwidth+x]=sch;
set_vmem_attr(vmem_ptr, y*cio_textinfo.screenwidth+x, sch);
}
}
unlock_vmem(vmem_ptr);
......@@ -838,8 +851,8 @@ void bitmap_gotoxy(int x, int y)
static int bitmap_draw_one_char(struct video_stats *vs, unsigned int xpos, unsigned int ypos)
{
int fg;
int bg;
uint32_t fg;
uint32_t bg;
int xoffset=(xpos-1)*vs->charwidth;
int yoffset=(ypos-1)*vs->charheight;
int x;
......@@ -872,9 +885,12 @@ static int bitmap_draw_one_char(struct video_stats *vs, unsigned int xpos, unsig
vmem_ptr = lock_vmem(vs);
sch=vmem_ptr->vmem[(ypos-1)*cio_textinfo.screenwidth+(xpos-1)];
fg = vmem_ptr->fgvmem[(ypos-1)*cio_textinfo.screenwidth+(xpos-1)];
bg = vmem_ptr->bgvmem[(ypos-1)*cio_textinfo.screenwidth+(xpos-1)];
unlock_vmem(vmem_ptr);
#if 0 // TODO: This needs to be in the put, and needs to be propegated back when flags change...
altfont = (sch>>11 & 0x01) | ((sch>>14) & 0x02);
if(vs->bright_background) {
bg=(sch&0xf000)>>12;
......@@ -897,6 +913,7 @@ static int bitmap_draw_one_char(struct video_stats *vs, unsigned int xpos, unsig
if(vs->no_bright)
fg &= 0x07;
fontoffset=(sch&0xff)*vs->charheight;
#endif
for(y=0; y<vs->charheight; y++) {
memset_u32(&screen[PIXEL_OFFSET(xoffset, yoffset+y)],vs->palette[bg],vs->charwidth);
......@@ -918,7 +935,11 @@ static int update_rect(int sx, int sy, int width, int height, int force)
int redraw_cursor=0;
int lastcharupdated=0;
static unsigned short *last_vmem=NULL;
static uint32_t *last_fgvmem=NULL;
static uint32_t *last_bgvmem=NULL;
static unsigned short *this_vmem=NULL;
static uint32_t *this_fgvmem=NULL;
static uint32_t *this_bgvmem=NULL;
static struct video_stats vs;
struct video_stats cvstat;
struct vstat_vmem cvmem;
......@@ -941,14 +962,28 @@ static int update_rect(int sx, int sy, int width, int height, int force)
height=cio_textinfo.screenheight;
pthread_mutex_lock(&vstatlock);
if(vs.cols!=vstat.cols || vs.rows != vstat.rows || last_vmem==NULL || this_vmem == NULL) {
unsigned short *p;
if(vs.cols!=vstat.cols || vs.rows != vstat.rows || last_vmem==NULL || this_vmem == NULL ||
last_fgvmem==NULL || this_fgvmem == NULL || last_bgvmem==NULL || this_bgvmem == NULL) {
void *p;
p=(unsigned short *)realloc(last_vmem, vstat.cols*vstat.rows*sizeof(unsigned short));
p=realloc(last_vmem, vstat.cols*vstat.rows*sizeof(unsigned short));
if(p==NULL)
return(-1);
last_vmem=p;
memset(last_vmem, 255, vstat.cols*vstat.rows*sizeof(unsigned short));
p=realloc(last_fgvmem, vstat.cols*vstat.rows*sizeof(last_fgvmem[0]));
if(p==NULL)
return(-1);
last_fgvmem=p;
p=realloc(last_bgvmem, vstat.cols*vstat.rows*sizeof(last_bgvmem[0]));
if(p==NULL)
return(-1);
last_bgvmem=p;
memset(last_vmem, 255, vstat.cols*vstat.rows*sizeof(last_vmem[0]));
memset(last_fgvmem, 255, vstat.cols*vstat.rows*sizeof(last_fgvmem[0]));
memset(last_bgvmem, 255, vstat.cols*vstat.rows*sizeof(last_bgvmem[0]));
sx=1;
sy=1;
width=vstat.cols;
......@@ -956,10 +991,21 @@ static int update_rect(int sx, int sy, int width, int height, int force)
force=1;
vs.cols=vstat.cols;
vs.rows=vstat.rows;
p=(unsigned short *)realloc(this_vmem, vstat.cols*vstat.rows*sizeof(unsigned short));
p=realloc(this_vmem, vstat.cols*vstat.rows*sizeof(unsigned short));
if(p==NULL)
return(-1);
this_vmem = p;
p=realloc(this_fgvmem, vstat.cols*vstat.rows*sizeof(this_fgvmem[0]));
if(p==NULL)
return(-1);
this_fgvmem = p;
p=realloc(this_bgvmem, vstat.cols*vstat.rows*sizeof(this_bgvmem[0]));
if(p==NULL)
return(-1);
this_bgvmem = p;
}
/* Redraw cursor */
......@@ -976,18 +1022,27 @@ static int update_rect(int sx, int sy, int width, int height, int force)
cvstat.vmem = &cvmem;
cvstat.vmem->refcount = 1;
cvstat.vmem->vmem = this_vmem;
cvstat.vmem->fgvmem = this_fgvmem;
cvstat.vmem->bgvmem = this_bgvmem;
memcpy(cvstat.vmem->vmem, vmem_ptr->vmem, vstat.cols*vstat.rows*sizeof(unsigned short));
memcpy(cvstat.vmem->fgvmem, vmem_ptr->fgvmem, vstat.cols*vstat.rows*sizeof(vmem_ptr->fgvmem[0]));
memcpy(cvstat.vmem->bgvmem, vmem_ptr->bgvmem, vstat.cols*vstat.rows*sizeof(vmem_ptr->bgvmem[0]));
pthread_mutex_unlock(&vmem_lock);
for(y=0;y<height;y++) {
pos=(sy+y-1)*cvstat.cols+(sx-1);
for(x=0;x<width;x++) {
/* TODO: Need to deal with blink/bgbright here too... */
if(force
|| (last_vmem[pos] != cvstat.vmem->vmem[pos]) /* Different char */
|| (last_fgvmem[pos] != cvstat.vmem->fgvmem[pos]) /* Different foreground colour */
|| (last_bgvmem[pos] != cvstat.vmem->bgvmem[pos]) /* Different background colour */
|| ((cvstat.blink != vs.blink) && (cvstat.vmem->vmem[pos]>>15) && (!cvstat.no_blink)) /* Blinking char */
|| (redraw_cursor && ((vs.curs_col==sx+x && vs.curs_row==sy+y) || (cvstat.curs_col==sx+x && cvstat.curs_row==sy+y))) /* Cursor */
) {
last_vmem[pos] = cvstat.vmem->vmem[pos];
last_fgvmem[pos] = cvstat.vmem->fgvmem[pos];
last_bgvmem[pos] = cvstat.vmem->bgvmem[pos];
bitmap_draw_one_char(&cvstat, sx+x,sy+y);
if(!redraw_cursor && sx+x==cvstat.curs_col && sy+y==cvstat.curs_row)
......
......@@ -119,6 +119,8 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_get_window_info(int *width, int *height, int
CIOLIBEXPORT void CIOLIBCALL ciolib_setscaling(int new_value);
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 pallette_entry, int a);
CIOLIBEXPORT int CIOLIBCALL ciolib_ccputs(uint32_t pallette_entry, const char *str);
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
int sdl_video_initialized = 0;
......@@ -1402,6 +1404,45 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_putch(int a)
}
CIOLIBEXPORT int CIOLIBCALL ciolib_cputch(uint32_t palette_entry, int a)
{
CIOLIB_INIT();
if (cio_api.cputch == NULL || palette_entry == UINT32_MAX)
return ciolib_putch(a);
return cio_api.cputch(palette_entry, a);
}
CIOLIBEXPORT int CIOLIBCALL ciolib_ccputs(uint32_t palette_entry, const char *s)
{
CIOLIB_INIT();
if (palette_entry == UINT32_MAX)
return ciolib_cputs((char *)s);
if (cio_api.ccputs != NULL)
return ciolib_ccputs(palette_entry, s);
if (cio_api.cputch != NULL) {
int pos;
int ret=0;
int olddmc;
olddmc=hold_update;
hold_update=1;
for(pos=0;s[pos];pos++)
{
ret=s[pos];
if(s[pos]=='\n')
ciolib_putch('\r');
ciolib_cputch(palette_entry, s[pos]);
}
hold_update=olddmc;
ciolib_gotoxy(ciolib_wherex(),ciolib_wherey());
return(ret);
}
return cio_api.cputs((char *)s);
}
/* **MUST** be implemented */
CIOLIBEXPORT void CIOLIBCALL ciolib_setcursortype(int a)
{
......
......@@ -266,6 +266,7 @@ typedef struct {
int (*wherex) (void);
int (*wherey) (void);
int (*putch) (int);
int (*cputch) (uint32_t, int);
void (*gotoxy) (int,int);
void (*clrscr) (void);
void (*gettextinfo) (struct text_info *);
......@@ -288,6 +289,7 @@ typedef struct {
void (*insline) (void);
int (*cprintf) (const char *,...);
int (*cputs) (char *);
int (*ccputs) (uint32_t, const char *);
void (*textbackground) (int);
void (*textcolor) (int);
int (*getmouse) (struct mouse_event *mevent);
......@@ -346,6 +348,7 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_gotoxy(int x, int y);
CIOLIBEXPORT void CIOLIBCALL ciolib_clreol(void);
CIOLIBEXPORT void CIOLIBCALL ciolib_clrscr(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_cputs(char *str);
CIOLIBEXPORT int CIOLIBCALL ciolib_ccputs(uint32_t palette_entry, const char *str);
CIOLIBEXPORT int CIOLIBCALL ciolib_cprintf(const char *fmat, ...);
CIOLIBEXPORT void CIOLIBCALL ciolib_textbackground(int colour);
CIOLIBEXPORT void CIOLIBCALL ciolib_textcolor(int colour);
......@@ -357,6 +360,7 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_gettext(int a,int b,int c,int d,void *e);
CIOLIBEXPORT void CIOLIBCALL ciolib_textattr(int a);
CIOLIBEXPORT void CIOLIBCALL ciolib_delay(long a);
CIOLIBEXPORT int CIOLIBCALL ciolib_putch(int a);
CIOLIBEXPORT int CIOLIBCALL ciolib_cputch(uint32_t, int a);
CIOLIBEXPORT void CIOLIBCALL ciolib_setcursortype(int a);
CIOLIBEXPORT void CIOLIBCALL ciolib_textmode(int mode);
CIOLIBEXPORT void CIOLIBCALL ciolib_window(int sx, int sy, int ex, int ey);
......@@ -407,6 +411,7 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#define clreol() ciolib_clreol()
#define clrscr() ciolib_clrscr()
#define cputs(a) ciolib_cputs(a)
#define ccputs(a,b) ciolib_ccputs(a,b)
#define textbackground(a) ciolib_textbackground(a)
#define textcolor(a) ciolib_textcolor(a)
#define highvideo() ciolib_highvideo()
......@@ -417,6 +422,7 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#define textattr(a) ciolib_textattr(a)
#define delay(a) ciolib_delay(a)
#define putch(a) ciolib_putch(a)
#define cputch(a,b) ciolib_cputch(a,b)
#define _setcursortype(a) ciolib_setcursortype(a)
#define textmode(a) ciolib_textmode(a)
#define window(a,b,c,d) ciolib_window(a,b,c,d)
......
......@@ -1998,12 +1998,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;
break;
case 1:
cterm->fg_color = UINT32_MAX;
cterm->attr|=8;
break;
case 2:
cterm->fg_color = UINT32_MAX;
cterm->attr&=247;
break;
case 4: /* Underscore */
......@@ -2014,6 +2018,8 @@ 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;
......@@ -2021,77 +2027,96 @@ static void do_ansi(struct cterminal *cterm, char *retbuf, size_t retsize, int *
cterm->attr |= i<<4;
break;
case 8:
cterm->fg_color = UINT32_MAX;
cterm->bg_color = UINT32_MAX;
j=cterm->attr&112;
cterm->attr&=112;
cterm->attr |= j>>4;
break;
case 22:
cterm->fg_color = UINT32_MAX;
cterm->attr &= 0xf7;
break;
case 25:
cterm->attr &= 0x7f;
break;
case 30:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
break;
case 31:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=4;
break;
case 32:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=2;
break;
case 33:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=6;
break;
case 34:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=1;
break;
case 35:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=5;
break;
case 36:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=3;
break;
case 37:
case 39:
cterm->fg_color = UINT32_MAX;
cterm->attr&=248;
cterm->attr|=7;
break;
case 49:
case 40:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
break;
case 41:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=4<<4;
break;
case 42:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=2<<4;
break;
case 43:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=6<<4;
break;
case 44:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=1<<4;
break;
case 45:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=5<<4;
break;
case 46:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=3<<4;
break;
case 47:
cterm->bg_color = UINT32_MAX;
cterm->attr&=143;
cterm->attr|=7<<4;
break;
......@@ -2360,6 +2385,8 @@ struct cterminal* CIOLIBCALL cterm_init(int height, int width, int xpos, int ypo
cterm->cursor=_NORMALCURSOR;
cterm->autowrap=true;
cterm->origin_mode=false;
cterm->fg_color = UINT32_MAX;
cterm->bg_color = UINT32_MAX;
if(cterm->scrollback!=NULL)
memset(cterm->scrollback,0,cterm->width*2*cterm->backlines);
strcpy(cterm->DA,"\x1b[=67;84;101;114;109;");
......@@ -2975,6 +3002,8 @@ 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 */
......
......@@ -109,6 +109,8 @@ struct cterminal {
int started; // Indicates that conio functions are being called
int c64reversemode; // Commodore 64 reverse mode state
unsigned char attr; // Current attribute
uint32_t fg_color;
uint32_t bg_color;
int save_xpos; // Saved position (for later restore)
int save_ypos;
int sequence; // An escape sequence is being parsed
......
/* $Id$ */
#include <stdlib.h>
#include <stdbool.h>
/* xpdev: */
#include <gen_defs.h> /* FREE_AND_NULL */
......@@ -262,11 +263,13 @@ void release_vmem(struct vstat_vmem *vm)
vm->refcount--;
if (vm->refcount == 0) {
FREE_AND_NULL(vm->vmem);
FREE_AND_NULL(vm->fgvmem);
FREE_AND_NULL(vm->bgvmem);
FREE_AND_NULL(vm);
}
}
static struct vstat_vmem *new_vmem(int cols, int rows)
static struct vstat_vmem *new_vmem(int cols, int rows, bool palette)
{
struct vstat_vmem *ret = malloc(sizeof(struct vstat_vmem));
......@@ -278,6 +281,25 @@ static struct vstat_vmem *new_vmem(int cols, int rows)
free(ret);
return NULL;
}
if (palette) {
ret->fgvmem = malloc(cols*rows*sizeof(ret->fgvmem[0]));
if (ret->fgvmem == NULL) {
free(ret->vmem);
free(ret);
return NULL;
}
ret->bgvmem = malloc(cols*rows*sizeof(ret->bgvmem[0]));
if (ret->bgvmem == NULL) {
free(ret->fgvmem);
free(ret->vmem);
free(ret);
return NULL;
}
}
else {
ret->fgvmem = NULL;
ret->bgvmem = NULL;
}
return ret;
}
......@@ -289,7 +311,7 @@ int load_vmode(struct video_stats *vs, int mode)
if(i==-1)
return(-1);
release_vmem(vs->vmem);
vs->vmem=new_vmem(vparams[i].cols, vparams[i].rows);
vs->vmem=new_vmem(vparams[i].cols, vparams[i].rows, vs->flags & VIDMODES_FLAG_PALETTE_VMEM);
if (vs->vmem == NULL)
return -1;
vs->rows=vparams[i].rows;
......
......@@ -67,6 +67,8 @@ struct video_params {
struct vstat_vmem {
unsigned refcount;
unsigned short *vmem;
uint32_t *fgvmem;
uint32_t *bgvmem;
};
struct video_stats {
......@@ -92,6 +94,8 @@ struct video_stats {
int currattr;
int scaling;
int vmultiplier;
uint32_t flags;
#define VIDMODES_FLAG_PALETTE_VMEM 1
uint32_t palette[16];
struct vstat_vmem *vmem;
};
......
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