Skip to content
Snippets Groups Projects
Commit 37c82f6b authored by deuce's avatar deuce
Browse files

Relieve pressure on vstat mutex by doing full screen updates from a copy

of vstat rather than the vstat struct itself.
parent 61f79d8c
No related branches found
No related tags found
No related merge requests found
...@@ -769,7 +769,7 @@ int sdl_getche(void) ...@@ -769,7 +769,7 @@ int sdl_getche(void)
putch(ch); putch(ch);
return(ch); return(ch);
} }
ch=sdl_getch(); sdl_getch();
} }
} }
...@@ -949,7 +949,7 @@ void sdl_draw_cursor(void) ...@@ -949,7 +949,7 @@ void sdl_draw_cursor(void)
/* Called from event thread */ /* Called from event thread */
/* ONLY Called from sdl_full_screen_redraw() which holds the mutex... */ /* ONLY Called from sdl_full_screen_redraw() which holds the mutex... */
int sdl_draw_one_char(unsigned short sch, unsigned int x, unsigned int y) int sdl_draw_one_char(unsigned short sch, unsigned int x, unsigned int y, struct video_stats *vs)
{ {
SDL_Color co; SDL_Color co;
SDL_Rect src; SDL_Rect src;
...@@ -960,30 +960,30 @@ int sdl_draw_one_char(unsigned short sch, unsigned int x, unsigned int y) ...@@ -960,30 +960,30 @@ int sdl_draw_one_char(unsigned short sch, unsigned int x, unsigned int y)
ch=(sch >> 8) & 0x0f; ch=(sch >> 8) & 0x0f;
if(lastfg!=ch) { if(lastfg!=ch) {
co.r=dac_default256[vstat.palette[ch]].red; co.r=dac_default256[vs->palette[ch]].red;
co.g=dac_default256[vstat.palette[ch]].green; co.g=dac_default256[vs->palette[ch]].green;
co.b=dac_default256[vstat.palette[ch]].blue; co.b=dac_default256[vs->palette[ch]].blue;
SDL_SetColors(sdl_font, &co, 1, 1); SDL_SetColors(sdl_font, &co, 1, 1);
lastfg=ch; lastfg=ch;
} }
ch=(sch >> 12) & 0x07; ch=(sch >> 12) & 0x07;
if(lastbg!=ch) { if(lastbg!=ch) {
co.r=dac_default256[vstat.palette[ch]].red; co.r=dac_default256[vs->palette[ch]].red;
co.g=dac_default256[vstat.palette[ch]].green; co.g=dac_default256[vs->palette[ch]].green;
co.b=dac_default256[vstat.palette[ch]].blue; co.b=dac_default256[vs->palette[ch]].blue;
SDL_SetColors(sdl_font, &co, 0, 1); SDL_SetColors(sdl_font, &co, 0, 1);
lastbg=ch; lastbg=ch;
} }
dst.x=x*vstat.charwidth*vstat.scaling; dst.x=x*vs->charwidth*vs->scaling;
dst.y=y*vstat.charheight*vstat.scaling; dst.y=y*vs->charheight*vs->scaling;
dst.w=vstat.charwidth*vstat.scaling; dst.w=vs->charwidth*vs->scaling;
dst.h=vstat.charheight*vstat.scaling; dst.h=vs->charheight*vs->scaling;
src.x=0; src.x=0;
src.w=vstat.charwidth; src.w=vs->charwidth;
src.h=vstat.charheight; src.h=vs->charheight;
src.y=vstat.charheight*vstat.scaling; src.y=vs->charheight*vs->scaling;
ch=sch & 0xff; ch=sch & 0xff;
if((sch >>15) && !(vstat.blink)) if((sch >>15) && !(vs->blink))
src.y *= ' '; src.y *= ' ';
else else
src.y *= ch; src.y *= ch;
...@@ -995,7 +995,6 @@ int sdl_draw_one_char(unsigned short sch, unsigned int x, unsigned int y) ...@@ -995,7 +995,6 @@ int sdl_draw_one_char(unsigned short sch, unsigned int x, unsigned int y)
int sdl_full_screen_redraw(void) int sdl_full_screen_redraw(void)
{ {
static int last_blink; static int last_blink;
int this_blink;
int x; int x;
int y; int y;
unsigned int pos; unsigned int pos;
...@@ -1003,44 +1002,41 @@ int sdl_full_screen_redraw(void) ...@@ -1003,44 +1002,41 @@ int sdl_full_screen_redraw(void)
unsigned short *p; unsigned short *p;
SDL_Rect *rects; SDL_Rect *rects;
int rcount=0; int rcount=0;
struct video_stats vs;
SDL_mutexP(sdl_vstatlock); SDL_mutexP(sdl_vstatlock);
this_blink=vstat.blink; memcpy(&vs, &vstat, sizeof(vs));
if((newvmem=(unsigned short *)malloc(vstat.cols*vstat.rows*sizeof(unsigned short)))==NULL) { if((newvmem=(unsigned short *)malloc(vs.cols*vs.rows*sizeof(unsigned short)))==NULL)
SDL_mutexV(sdl_vstatlock);
return(-1); return(-1);
} memcpy(newvmem, vs.vmem, vs.cols*vs.rows*sizeof(unsigned short));
memcpy(newvmem, vstat.vmem, vstat.cols*vstat.rows*sizeof(unsigned short));
rects=(SDL_Rect *)malloc(sizeof(SDL_Rect)*vstat.cols*vstat.rows);
if(rects==NULL) {
SDL_mutexV(sdl_vstatlock); SDL_mutexV(sdl_vstatlock);
rects=(SDL_Rect *)malloc(sizeof(SDL_Rect)*vs.cols*vs.rows);
if(rects==NULL)
return(-1); return(-1);
}
SDL_mutexP(sdl_updlock); SDL_mutexP(sdl_updlock);
sdl_updated=1; sdl_updated=1;
SDL_mutexV(sdl_updlock); SDL_mutexV(sdl_updlock);
/* Redraw all chars */ /* Redraw all chars */
pos=0; pos=0;
for(y=0;y<vstat.rows;y++) { for(y=0;y<vs.rows;y++) {
for(x=0;x<vstat.cols;x++) { for(x=0;x<vs.cols;x++) {
if((last_vmem==NULL) if((last_vmem==NULL)
|| (last_vmem[pos] != newvmem[pos]) || (last_vmem[pos] != newvmem[pos])
|| (last_blink != this_blink && newvmem[pos]>>15) || (last_blink != vs.blink && newvmem[pos]>>15)
|| (lastcursor_x==x && lastcursor_y==y) || (lastcursor_x==x && lastcursor_y==y)
|| (vstat.curs_col==x && vstat.curs_row==y) || (vs.curs_col==x && vs.curs_row==y)
) { ) {
sdl_draw_one_char(newvmem[pos],x,y); sdl_draw_one_char(newvmem[pos],x,y,&vs);
rects[rcount].x=x*vstat.charwidth*vstat.scaling; rects[rcount].x=x*vs.charwidth*vs.scaling;
rects[rcount].y=y*vstat.charheight*vstat.scaling; rects[rcount].y=y*vs.charheight*vs.scaling;
rects[rcount].w=vstat.charwidth*vstat.scaling; rects[rcount].w=vs.charwidth*vs.scaling;
rects[rcount++].h=vstat.charheight*vstat.scaling; rects[rcount++].h=vs.charheight*vs.scaling;
} }
pos++; pos++;
} }
} }
SDL_mutexV(sdl_vstatlock);
last_blink=this_blink; last_blink=vs.blink;
p=last_vmem; p=last_vmem;
last_vmem=newvmem; last_vmem=newvmem;
free(p); free(p);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment