From ec0a3c65da8c3d47895ab2e5b4cec8cf2070f6eb Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 20 Nov 2011 22:28:53 +0800 Subject: [PATCH] Kernel - Cleaning up a little (implemented MIN and MAX functions) --- Kernel/drv/vterm.c | 26 +++++++++++++++++--------- Kernel/include/acess.h | 3 +++ Kernel/lib.c | 6 +++--- Modules/Input/PS2KbMouse/ps2mouse.c | 3 --- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index 82eac3e1..4fd06167 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -890,7 +890,7 @@ void VT_KBCallBack(Uint32 Codepoint) { tVTerm *term = gpVT_CurTerm; - // Key Up + // Catch VT binds switch( Codepoint & KEY_ACTION_MASK ) { case KEY_ACTION_RELEASE: @@ -928,22 +928,30 @@ void VT_KBCallBack(Uint32 Codepoint) case KEY_F10: VT_SetTerminal(9); return; case KEY_F11: VT_SetTerminal(10); return; case KEY_F12: VT_SetTerminal(11); return; + } + + // Scrolling is only valid in text mode + if(gpVT_CurTerm->Mode != TERM_MODE_TEXT) + break; + + switch(Codepoint & KEY_CODEPOINT_MASK) + { // Scrolling case KEY_PGUP: if( gpVT_CurTerm->Flags & VT_FLAG_ALTBUF ) return ; - if( gpVT_CurTerm->ViewPos > gpVT_CurTerm->Width ) - gpVT_CurTerm->ViewPos -= gpVT_CurTerm->Width; - else - gpVT_CurTerm->ViewPos = 0; + gpVT_CurTerm->ViewPos = MAX( + 0, + gpVT_CurTerm->ViewPos - gpVT_CurTerm->Width + ); return; case KEY_PGDOWN: if( gpVT_CurTerm->Flags & VT_FLAG_ALTBUF ) return ; - 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); + gpVT_CurTerm->ViewPos = MIN( + gpVT_CurTerm->ViewPos + gpVT_CurTerm->Width, + gpVT_CurTerm->Width * gpVT_CurTerm->Height*giVT_Scrollback + ); return; } break; diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index ac575010..0d0e1bb8 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -541,6 +541,9 @@ extern int DivUp(int num, int dem); //! Divide and Modulo 64-bit unsigned integer extern Uint64 DivMod64U(Uint64 Num, Uint64 Den, Uint64 *Rem); +static inline int MIN(int a, int b) { return a < b ? a : b; } +static inline int MAX(int a, int b) { return a > b ? a : b; } + #include #include #include diff --git a/Kernel/lib.c b/Kernel/lib.c index 369b7b0b..c1e2807e 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -490,11 +490,11 @@ char *strcpy(char *__str1, const char *__str2) * \brief Copy a string to a new location * \note Copies at most `max` chars */ -char *strncpy(char *__str1, const char *__str2, size_t max) +char *strncpy(char *__str1, const char *__str2, size_t __max) { - while(*__str2 && max-- >= 1) + while(*__str2 && __max-- >= 1) *__str1++ = *__str2++; - if(max) + if(__max) *__str1 = '\0'; // Terminate String return __str1; } diff --git a/Modules/Input/PS2KbMouse/ps2mouse.c b/Modules/Input/PS2KbMouse/ps2mouse.c index 69df8a4e..e80a1413 100644 --- a/Modules/Input/PS2KbMouse/ps2mouse.c +++ b/Modules/Input/PS2KbMouse/ps2mouse.c @@ -10,9 +10,6 @@ #include #include "common.h" -static inline int MIN(int a, int b) { return (a < b) ? a : b; } -static inline int MAX(int a, int b) { return (a > b) ? a : b; } - // == CONSTANTS == #define NUM_AXIES 2 // X+Y #define NUM_BUTTONS 5 // Left, Right, Scroll Click, Scroll Up, Scroll Down -- 2.20.1