Kernel/VTerm - "Fix" wrapping issue in VTerm (why was old behavior there?)
authorJohn Hodge (sonata) <[email protected]>
Wed, 5 Nov 2014 09:33:49 +0000 (17:33 +0800)
committerJohn Hodge (sonata) <[email protected]>
Wed, 5 Nov 2014 09:33:49 +0000 (17:33 +0800)
KernelLand/Kernel/debug.c
KernelLand/Kernel/drv/pty.c
KernelLand/Kernel/drv/vterm_output.c
KernelLand/Kernel/drv/vterm_termbuf.c

index 18c7ebb..eed38de 100644 (file)
@@ -7,7 +7,7 @@
 #include <debug_hooks.h>
 
 #define        DEBUG_MAX_LINE_LEN      256
-#define        LOCK_DEBUG_OUTPUT       1       // Avoid interleaving of output lines?
+#define        LOCK_DEBUG_OUTPUT       0       // Avoid interleaving of output lines?
 #define TRACE_TO_KTERM         0       // Send ENTER/DEBUG/LEAVE to debug?
 
 // === IMPORTS ===
@@ -77,9 +77,8 @@ static void Debug_Puts(int UseKTerm, const char *Str)
                IPStack_SendDebugText(Str);
 
        // Output to the kernel terminal
-       if( UseKTerm && gbDebug_IsKPanic < 2 && giDebug_KTerm != -1)
+       if( UseKTerm && gbDebug_IsKPanic < 2 && giDebug_KTerm != -1 && gbInPutChar == 0)
        {
-               if(gbInPutChar) return ;
                gbInPutChar = 1;
                VFS_Write(giDebug_KTerm, len, Str);
                gbInPutChar = 0;
@@ -137,7 +136,10 @@ void Debug_KernelPanic(void)
 bool LogF(const char *Fmt, ...)
 {
        #if LOCK_DEBUG_OUTPUT
-       if(CPU_HAS_LOCK(&glDebug_Lock)) return true;
+       if(CPU_HAS_LOCK(&glDebug_Lock)) {
+               Debug_Puts("[#]");
+               return true;
+       }
        SHORTLOCK(&glDebug_Lock);
        #endif
        
@@ -265,16 +267,13 @@ void Panic(const char *Fmt, ...)
 
 void Debug_SetKTerminal(const char *File)
 {
-        int    tmp;
        if(giDebug_KTerm != -1) {
-               tmp = giDebug_KTerm;
+               // Clear FD to -1 before closing (prevents writes to closed FD)
+               int oldfd = giDebug_KTerm;
                giDebug_KTerm = -1;
-               VFS_Close(tmp);
+               VFS_Close(oldfd);
        }
-       tmp = VFS_Open(File, VFS_OPENFLAG_WRITE);
-//     Log_Log("Debug", "Opened '%s' as 0x%x", File, tmp);
-       giDebug_KTerm = tmp;
-//     Log_Log("Debug", "Returning to %p", __builtin_return_address(0));
+       giDebug_KTerm = VFS_Open(File, VFS_OPENFLAG_WRITE);
 }
 
 void Debug_Enter(const char *FuncName, const char *ArgTypes, ...)
index 2e79323..d1f74c5 100644 (file)
@@ -627,12 +627,14 @@ size_t PTY_WriteClient(tVFS_Node *Node, off_t Offset, size_t Length, const void
        // If the server has terminated, send SIGPIPE
        if( pty->ServerNode && pty->ServerNode->ReferenceCount == 0 )
        {
+               LOG("SIGPIPE, server has terminated");
                Threads_PostSignal(SIGPIPE);
                errno = EIO;
                return -1;
        }       
 
        // Write to either FIFO or directly to output function
+       LOG("pty->OutputFcn = %p", pty->OutputFcn);
        if( pty->OutputFcn ) {
                pty->OutputFcn(pty->OutputHandle, Length, Buffer);
                return Length;
index 79afaa7..95c552f 100644 (file)
@@ -5,9 +5,9 @@
  * drv/vterm_input.c
  * - Virtual Terminal - Input code
  */
+#define DEBUG  0
 #include "vterm.h"
 #include <api_drv_video.h>
-#define DEBUG  0
 
 // === CODE ===
 /**
@@ -94,7 +94,7 @@ void VT_int_UpdateCursor( tVTerm *Term, int bShow )
 
        if( Term != gpVT_CurTerm )      return ;
        
-       ENTER("pTerm bShow", Term, Show);
+       ENTER("pTerm bShow", Term, bShow);
 
        if( !bShow )
        {
@@ -135,10 +135,13 @@ void VT_int_UpdateCursor( tVTerm *Term, int bShow )
  */
 void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
 {
-       // Only update if this is the current terminal
-       if( Term != gpVT_CurTerm )      return;
-
        ENTER("pTerm iUpdateAll", Term, UpdateAll);
+       // Only update if this is the current terminal
+       if( Term != gpVT_CurTerm ) {
+               LOG("Term != gpVT_CurTerm (%p)", gpVT_CurTerm);
+               LEAVE('-');
+               return;
+       }
                
        switch( Term->Mode )
        {
@@ -146,7 +149,7 @@ void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
                size_t view_pos = (Term->Flags & VT_FLAG_ALTBUF) ? 0 : Term->ViewTopRow*Term->TextWidth;
                const tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
                const tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
-               LOG("view_pos = %i, wrpos = %p, buffer=%p", view_pos, wrpos, buffer);
+               LOG("view_pos = %i, wrpos = %p (R%i,C%i), buffer=%p", view_pos, wrpos, wrpos->Row, wrpos->Col, buffer);
                // Re copy the entire screen?
                if(UpdateAll) {
                        VFS_WriteAt(
@@ -159,6 +162,7 @@ void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
                // Only copy the current line
                else {
                        size_t  ofs = wrpos->Row * Term->TextWidth;
+                       LOG("ofs = %i", ofs);
                        VFS_WriteAt(
                                giVT_OutputDevHandle,
                                (ofs - view_pos)*sizeof(tVT_Char),
index ed95480..1a14f82 100644 (file)
@@ -79,7 +79,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
        {
                ASSERTC(wrpos->Col, <=, Term->TextWidth);
                VT_int_UpdateScreen( Term, 0 );
-               //wrpos->Row ++;
+               wrpos->Row ++;
                wrpos->Col = 0;
        }
 
@@ -124,7 +124,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
        case '\0':      // Ignore NULL byte
                return;
        case '\n':
-               LOG("Newline, update");
+               LOG("Newline, update @ %i", write_pos);
                VT_int_UpdateScreen( Term, 0 ); // Update the line before newlining
                wrpos->Row ++;
                // TODO: Force scroll?
@@ -170,11 +170,12 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
                buffer[ write_pos ].Colour = Term->CurColour;
                // Update the line before wrapping
                if( (write_pos + 1) % Term->TextWidth == 0 ) {
-                       LOG("Line wrap, update");
+                       LOG("Line wrap, update @ %i", write_pos);
                        VT_int_UpdateScreen( Term, 0 );
+                       // NOTE: Code at the top of PutChar handles the actual wrapping
                }
-               write_pos ++;
                wrpos->Col ++;
+               write_pos ++;
                break;
        }
        

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