Kernel - Fixed vterm corruption at end of buffer
authorJohn Hodge <[email protected]>
Wed, 5 Oct 2011 05:28:36 +0000 (13:28 +0800)
committerJohn Hodge <[email protected]>
Wed, 5 Oct 2011 05:28:36 +0000 (13:28 +0800)
Kernel/drv/vterm.c
Kernel/include/acess.h
Kernel/lib.c

index b342a78..1d4b367 100644 (file)
@@ -24,6 +24,7 @@
 #define        DEFAULT_WIDTH   640
 #define        DEFAULT_HEIGHT  480
 #define DEFAULT_SCROLLBACK     2       // 2 Screens of text + current screen
+//#define DEFAULT_SCROLLBACK   0
 #define        DEFAULT_COLOUR  (VT_COL_BLACK|(0xAAA<<16))
 
 #define        VT_FLAG_HIDECSR 0x01
@@ -802,10 +803,10 @@ void VT_KBCallBack(Uint32 Codepoint)
                case KEY_PGDOWN:
                        if( gpVT_CurTerm->Flags & VT_FLAG_ALTBUF )
                                return ;
-                       if( gpVT_CurTerm->ViewPos < gpVT_CurTerm->Width*gpVT_CurTerm->Height*(giVT_Scrollback-1) )
+                       if( gpVT_CurTerm->ViewPos < gpVT_CurTerm->Width*gpVT_CurTerm->Height*(giVT_Scrollback) )
                                gpVT_CurTerm->ViewPos += gpVT_CurTerm->Width;
                        else
-                               gpVT_CurTerm->ViewPos = gpVT_CurTerm->Width*gpVT_CurTerm->Height*(giVT_Scrollback-1);
+                               gpVT_CurTerm->ViewPos = gpVT_CurTerm->Width*gpVT_CurTerm->Height*(giVT_Scrollback);
                        return;
                }
        }
@@ -1351,7 +1352,8 @@ void VT_int_ScrollText(tVTerm *Term, int Count)
         int    height, init_write_pos;
         int    len, i;
         int    scroll_top, scroll_height;
-       
+
+       // Get buffer pointer and attributes    
        if( Term->Flags & VT_FLAG_ALTBUF )
        {
                buf = Term->AltBuf;
@@ -1363,22 +1365,24 @@ void VT_int_ScrollText(tVTerm *Term, int Count)
        else
        {
                buf = Term->Text;
-               height = Term->TextHeight*giVT_Scrollback;
+               height = Term->TextHeight*(giVT_Scrollback+1);
                init_write_pos = Term->WritePos;
                scroll_top = 0;
                scroll_height = height;
        }
-       
+
+       // Scroll text downwards        
        if( Count > 0 )
        {
                 int    base;
+       
+               // Set up
                if(Count > scroll_height)       Count = scroll_height;
-//             Debug("Scroll: Count = %i", Count);
                base = Term->TextWidth*(scroll_top + scroll_height - Count);
                len = Term->TextWidth*(scroll_height - Count);
                
                // Scroll terminal cache
-               memcpy(
+               memmove(
                        &buf[Term->TextWidth*scroll_top],
                        &buf[Term->TextWidth*(scroll_top+Count)],
                        len*sizeof(tVT_Char)
@@ -1413,7 +1417,7 @@ void VT_int_ScrollText(tVTerm *Term, int Count)
                len = Term->TextWidth*(scroll_height - Count);
                
                // Scroll terminal cache
-               memcpy(
+               memmove(
                        &buf[Term->TextWidth*(scroll_top+Count)],
                        &buf[Term->TextWidth*scroll_top],
                        len*sizeof(tVT_Char)
index 5df49c1..3d0b3b3 100644 (file)
@@ -328,6 +328,7 @@ extern int  MM_GetPageNode(tPAddr PAddr, void **Node);
 extern int     memcmp(const void *m1, const void *m2, size_t count);
 extern void    *memcpy(void *dest, const void *src, size_t count);
 extern void    *memcpyd(void *dest, const void *src, size_t count);
+extern void    *memmove(void *dest, const void *src, size_t len);
 extern void    *memset(void *dest, int val, size_t count);
 extern void    *memsetd(void *dest, Uint32 val, size_t count);
 /**
index 28edc56..c4251a6 100644 (file)
@@ -81,6 +81,7 @@ EXPORT(ModUtil_SetIdent);
 EXPORT(UnHex);
 EXPORT(SwapEndian16);
 EXPORT(SwapEndian32);
+EXPORT(memmove);
 
 // === CODE ===
 /**
@@ -948,3 +949,35 @@ Uint32 SwapEndian32(Uint32 Val)
 {
        return ((Val&0xFF)<<24) | ((Val&0xFF00)<<8) | ((Val>>8)&0xFF00) | ((Val>>24)&0xFF);
 }
+
+void *memmove(void *__dest, const void *__src, size_t len)
+{
+       size_t  block_size;
+       char    *dest = __dest;
+       const char      *src = __src;
+       void    *ret = __dest;
+       
+       if( (tVAddr)dest > (tVAddr)src + len )
+               return memcpy(dest, src, len);
+       if( (tVAddr)dest + len < (tVAddr)src )
+               return memcpy(dest, src, len);
+       
+       if( (tVAddr)dest < (tVAddr)src )
+               block_size = (tVAddr)src - (tVAddr)dest;
+       else
+               block_size = (tVAddr)dest - (tVAddr)src;
+       
+       block_size &= ~0xF;
+       
+       while(len >= block_size)
+       {
+               memcpy(dest, src, block_size);
+               len -= block_size;
+               dest += block_size;
+               src += block_size;
+       }
+       memcpy(dest, src, len);
+       return ret;
+       
+}
+

UCC git Repository :: git.ucc.asn.au