/* * Turbo Vision - Version 2.0 * * Copyright (c) 1994 by Borland International * All Rights Reserved. * * Totally reworked for Unicode by Salvador E. Tropea Copyright (c) 2003 * */ #define Uses_TDrawBuffer #include /**[txh]******************************************************************** Description: Copies count bytes from source to the data buffer starting at indent. The function uses the provided attribute, but if the attribute is 0 the attribute in the buffer is unmodified.@p Added a check to avoid writings passing the end of the buffer.@p ***************************************************************************/ void TDrawBuffer::moveBuf(unsigned indent, const void *source, unsigned attr, unsigned count) { if (!count || (indent >= (unsigned)maxViewWidth)) return; if (count+indent > (unsigned)maxViewWidth) count = maxViewWidth - indent; ushort *dest = &data[indent]; const uchar *s = (const uchar *)source; if (attr) { while (count-- && *s) { ((uchar *)dest)[0] = *s++; ((uchar *)dest++)[1] = (uchar)attr; } } else { while (count-- && *s) { *(uchar *)dest++ = *s++; } } } void TDrawBufferU16::moveBuf(unsigned indent, const void *source, unsigned attr, unsigned count) { if (!count || (indent >= (unsigned)maxViewWidth)) return; if (count+indent > (unsigned)maxViewWidth) count = maxViewWidth - indent; uint16 *dest = &data[indent*2]; const uint16 *s = (const uint16 *)source; if (attr) { while (count-- && *s) { dest[0] = *s++; dest[1] = attr; dest += 2; } } else { while (count-- && *s) { *dest = *s++; dest += 2; } } } /**[txh]******************************************************************** Description: Fills count bytes in the buffer starting at the indent position. If the attribute is 0 the original is left unchanged. If the character is 0 only the attribute is used.@p Added a check to avoid writings passing the end of the buffer.@p ***************************************************************************/ void TDrawBuffer::moveChar(unsigned indent, char c, unsigned attr, unsigned count ) { if (!count || (indent >= (unsigned)maxViewWidth)) return; if (count+indent > (unsigned)maxViewWidth) count = maxViewWidth - indent; ushort *dest=&data[indent]; if (attr) { if (c) { while (count--) { ((uchar*)dest)[0] = c; ((uchar*)dest++)[1] = attr; } } else { dest=(ushort *)((uchar *)dest+1); while (count--) { *(uchar *)dest++ = attr; } } } else { while (count--) { *(uchar *)dest++ = c; } } } void TDrawBufferU16::moveChar(unsigned indent, unsigned c, unsigned attr, unsigned count ) { if (!count || (indent >= (unsigned)maxViewWidth)) return; if (count+indent > (unsigned)maxViewWidth) count = maxViewWidth - indent; uint16 *dest=&data[indent*2]; if (attr) { if (c) { while (count--) { dest[0] = c; dest[1] = attr; dest += 2; } } else { dest++; while (count--) { *dest = attr; dest += 2; } } } else { while (count--) { *dest = c; dest += 2; } } } /**[txh]******************************************************************** Description: That's the same as moveStr but the attrs parameter holds two attributes the lower 8 bits are the normal value and the upper 8 bits define the attribute to be used for text enclosed by ASCII 126. @x{::moveStr}.@p The routine was modified to avoid writes passing the end of the buffer. Additionally was re-writed in assembler (I guess the Borland's original code was assembler, but I didn't take a look to it) because the check slow downs the routine so I wanted to avoid a lose in performance. SET. ***************************************************************************/ void TDrawBuffer::moveCStr( unsigned indent, const char *str, unsigned attrs ) { #if !defined(TVCPU_x86) || !defined(TVComp_GCC) //$todo: implement it in asm for Win32 uchar bh = attrs >> 8, ah = attrs & 0xff; uchar al; ushort *dest = data+indent; ushort *end = data+maxViewWidth; while (*str && dest= maxViewWidth ? \n\ cmpl %%esi,%%edi \n\ jae 2f \n\ \n\ incl %%edx \n\ // character == '~' ? \n\ cmpb $126,%%al \n\ jne 0f \n\ // exchange the attributes \n\ movb %%ah,%%al \n\ movb %%bh,%%ah \n\ movb %%al,%%bh \n\ jmp 1f \n\ .align 2,0x90 \n\ \n\ 0: \n\ movw %%ax,(%%edi) \n\ addl $2,%%edi \n\ \n\ 1: \n\ movb (%%edx),%%al \n\ cmpb $0,%%al \n\ jne 3b \n\ 2: \n\ popl %%ebx \n\ " : : "D"(&data[indent]), "S"(&data[maxViewWidth]), "d"(str), "a"(attrs) //: "%ebx" I save EBX because 2.7.x forgets it ); #endif } void TDrawBufferU16::moveCStr( unsigned indent, const uint16 *str, uint32 attrs ) { uint16 cHigh = attrs >> 16, cColor = attrs & 0xffff; uint16 aux, cChar; uint16 *dest = data+indent*2; uint16 *end = data+maxViewWidth*2; while (*str && dest=0 && maxLen=0 && maxLen