if (ticks - vbell_timeout >= 0) in_vbell = FALSE; }
if (ticks - vbell_startpoint >= VBELL_TIMEOUT) in_vbell = FALSE; }
static void do_paint(Context ctx, int may_optimise){    int i, j, our_curs_y;    unsigned long rv, cursor;    pos scrpos;    char ch[1024];    long cursor_background = ERASE_CHAR;    long ticks;    /*     * Check the visual bell state.     */    if (in_vbell) {	ticks = GetTickCount();	if (ticks - vbell_timeout >= 0)	    in_vbell = FALSE;    }    rv = (!rvideo ^ !in_vbell ? ATTR_REVERSE : 0);    /* Depends on:     * screen array, disptop, scrtop,     * selection, rv,      * cfg.blinkpc, blink_is_real, tblinker,      * curs.y, curs.x, blinker, cfg.blink_cur, cursor_on, has_focus, wrapnext     */    /* Has the cursor position or type changed ? */    if (cursor_on) {	if (has_focus) {	    if (blinker || !cfg.blink_cur)		cursor = TATTR_ACTCURS;	    else		cursor = 0;	} else	    cursor = TATTR_PASCURS;	if (wrapnext)	    cursor |= TATTR_RIGHTCURS;    } else	cursor = 0;    our_curs_y = curs.y - disptop;    if (dispcurs && (curstype != cursor ||		     dispcurs !=		     disptext + our_curs_y * (cols + 1) + curs.x)) {	if (dispcurs > disptext && 		(*dispcurs & (CHAR_MASK | CSET_MASK)) == UCSWIDE)	    dispcurs[-1] |= ATTR_INVALID;	if ( (dispcurs[1] & (CHAR_MASK | CSET_MASK)) == UCSWIDE)	    dispcurs[1] |= ATTR_INVALID;	*dispcurs |= ATTR_INVALID;	curstype = 0;    }    dispcurs = NULL;    /* The normal screen data */    for (i = 0; i < rows; i++) {	unsigned long *ldata;	int lattr;	int idx, dirty_line, dirty_run;	unsigned long attr = 0;	int updated_line = 0;	int start = 0;	int ccount = 0;	int last_run_dirty = 0;	scrpos.y = i + disptop;	ldata = lineptr(scrpos.y);	lattr = (ldata[cols] & LATTR_MODE);	idx = i * (cols + 1);	dirty_run = dirty_line = (ldata[cols] != disptext[idx + cols]);	disptext[idx + cols] = ldata[cols];	for (j = 0; j < cols; j++, idx++) {	    unsigned long tattr, tchar;	    unsigned long *d = ldata + j;	    int break_run;	    scrpos.x = j;	    tchar = (*d & (CHAR_MASK | CSET_MASK));	    tattr = (*d & (ATTR_MASK ^ CSET_MASK));	    switch (tchar & CSET_MASK) {	      case ATTR_ASCII:		tchar = unitab_line[tchar & 0xFF];		break;	      case ATTR_LINEDRW:		tchar = unitab_xterm[tchar & 0xFF];		break;	      case ATTR_SCOACS:  		tchar = unitab_scoacs[tchar&0xFF]; 		break;	    }	    tattr |= (tchar & CSET_MASK);	    tchar &= CHAR_MASK;	    if ((d[1] & (CHAR_MASK | CSET_MASK)) == UCSWIDE)		    tattr |= ATTR_WIDE;	    /* Video reversing things */	    tattr = (tattr ^ rv		     ^ (posle(selstart, scrpos) &&			poslt(scrpos, selend) ? ATTR_REVERSE : 0));	    /* 'Real' blinking ? */	    if (blink_is_real && (tattr & ATTR_BLINK)) {		if (has_focus && tblinker) {		    tchar = ' ';		    tattr &= ~CSET_MASK;		    tattr |= ATTR_ACP;		}		tattr &= ~ATTR_BLINK;	    }	    /*	     * Check the font we'll _probably_ be using to see if 	     * the character is wide when we don't want it to be.	     */	    if ((tchar | tattr) != (disptext[idx]& ~ATTR_NARROW)) {		if ((tattr & ATTR_WIDE) == 0 && 		    CharWidth(ctx, (tchar | tattr) & 0xFFFF) == 2)		    tattr |= ATTR_NARROW;	    } else if (disptext[idx]&ATTR_NARROW)		tattr |= ATTR_NARROW;	    /* Cursor here ? Save the 'background' */	    if (i == our_curs_y && j == curs.x) {		cursor_background = tattr | tchar;		dispcurs = disptext + idx;	    }	    if ((disptext[idx] ^ tattr) & ATTR_WIDE)		dirty_line = TRUE;	    break_run = (tattr != attr || j - start >= sizeof(ch));	    /* Special hack for VT100 Linedraw glyphs */	    if ((attr & CSET_MASK) == 0x2300 && tchar >= 0xBA		&& tchar <= 0xBD) break_run = TRUE;	    if (!dbcs_screenfont && !dirty_line) {		if ((tchar | tattr) == disptext[idx])		    break_run = TRUE;		else if (!dirty_run && ccount == 1)		    break_run = TRUE;	    }	    if (break_run) {		if ((dirty_run || last_run_dirty) && ccount > 0) {		    do_text(ctx, start, i, ch, ccount, attr, lattr);		    updated_line = 1;		}		start = j;		ccount = 0;		attr = tattr;		if (dbcs_screenfont)		    last_run_dirty = dirty_run;		dirty_run = dirty_line;	    }	    if ((tchar | tattr) != disptext[idx])		dirty_run = TRUE;	    ch[ccount++] = (char) tchar;	    disptext[idx] = tchar | tattr;	    /* If it's a wide char step along to the next one. */	    if (tattr & ATTR_WIDE) {		if (++j < cols) {		    idx++;		    d++;		    /* Cursor is here ? Ouch! */		    if (i == our_curs_y && j == curs.x) {			cursor_background = *d;			dispcurs = disptext + idx;		    }		    if (disptext[idx] != *d)			dirty_run = TRUE;		    disptext[idx] = *d;		}	    }	}	if (dirty_run && ccount > 0) {	    do_text(ctx, start, i, ch, ccount, attr, lattr);	    updated_line = 1;	}	/* Cursor on this line ? (and changed) */	if (i == our_curs_y && (curstype != cursor || updated_line)) {	    ch[0] = (char) (cursor_background & CHAR_MASK);	    attr = (cursor_background & ATTR_MASK) | cursor;	    do_cursor(ctx, curs.x, i, ch, 1, attr, lattr);	    curstype = cursor;	}    }}