From 193a19846230cd653ca61b65d54538974116c1ea Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 5 Oct 2011 13:28:36 +0800 Subject: [PATCH] Kernel - Fixed vterm corruption at end of buffer --- Kernel/drv/vterm.c | 20 ++++++++++++-------- Kernel/include/acess.h | 1 + Kernel/lib.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index b342a78f..1d4b3672 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -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) diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 5df49c12..3d0b3b32 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -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); /** diff --git a/Kernel/lib.c b/Kernel/lib.c index 28edc561..c4251a63 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -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; + +} + -- 2.20.1