Altered debug print function to use vsnprintf and to use Debug_Puts instead of Debug_...
[tpg/acess2.git] / Kernel / drv / vterm.c
index d0f450b..b24f374 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Acess2 Virtual Terminal Driver
  */
-#define DEBUG  1
+#define DEBUG  0
 #include <acess.h>
 #include <fs_devfs.h>
 #include <modules.h>
@@ -19,9 +19,9 @@
 #define MAX_INPUT_CHARS32      64
 #define MAX_INPUT_CHARS8       (MAX_INPUT_CHARS32*4)
 #define VT_SCROLLBACK  2       // 2 Screens of text
-#define DEFAULT_OUTPUT "VGA"
+//#define DEFAULT_OUTPUT       "VGA"
 //#define DEFAULT_OUTPUT       "BochsGA"
-//#define DEFAULT_OUTPUT       "Vesa"
+#define DEFAULT_OUTPUT "Vesa"
 #define DEFAULT_INPUT  "PS2Keyboard"
 #define        DEFAULT_WIDTH   80
 #define        DEFAULT_HEIGHT  25
@@ -63,6 +63,8 @@ extern void   Debug_SetKTerminal(char *File);
 
 // === PROTOTYPES ===
  int   VT_Install(char **Arguments);
+void   VT_InitOutput(void);
+void   VT_InitInput(void);
 char   *VT_ReadDir(tVFS_Node *Node, int Pos);
 tVFS_Node      *VT_FindDir(tVFS_Node *Node, char *Name);
  int   VT_Root_IOCtl(tVFS_Node *Node, int Id, void *Data);
@@ -190,6 +192,9 @@ int VT_Install(char **Arguments)
        // Add to DevFS
        DevFS_AddDevice( &gVT_DrvInfo );
        
+       VT_InitOutput();
+       VT_InitInput();
+       
        // Set kernel output to VT0
        Debug_SetKTerminal("/Devices/VTerm/0");
        
@@ -204,8 +209,12 @@ int VT_Install(char **Arguments)
 void VT_InitOutput()
 {
        giVT_OutputDevHandle = VFS_Open(gsVT_OutputDevice, VFS_OPENFLAG_WRITE);
+       if(giVT_InputDevHandle == -1) {
+               Log_Warning("VTerm", "Oh F**k, I can't open the video device '%s'", gsVT_OutputDevice);
+               return ;
+       }
        VT_SetTerminal( 0 );
-       VT_SetResolution(1, 640, 480);
+       VT_SetResolution(1, 640, 400);
 }
 
 /**
@@ -463,12 +472,7 @@ void VT_SetResolution(int IsTextMode, int Width, int Height)
        giVT_RealHeight = mode.height;
        VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_GETSETMODE, &tmp );
        
-       
-       
-       if(IsTextMode)
-               tmp = VIDEO_BUFFMT_TEXT;
-       else
-               tmp = VIDEO_BUFFMT_FRAMEBUFFER;
+       tmp = IsTextMode ? VIDEO_BUFFMT_TEXT : VIDEO_BUFFMT_FRAMEBUFFER;
        VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp );
 }
 
@@ -484,7 +488,7 @@ void VT_SetTerminal(int ID)
        gpVT_CurTerm = &gVT_Terminals[ID];
        
        // Update cursor
-       if( !(gpVT_CurTerm->Flags & VT_FLAG_HIDECSR) )
+       if( gpVT_CurTerm->Mode == TERM_MODE_TEXT && !(gpVT_CurTerm->Flags & VT_FLAG_HIDECSR) )
        {
                tVideo_IOCtl_Pos        pos;
                pos.x = gpVT_CurTerm->WritePos % gpVT_CurTerm->Width;
@@ -670,41 +674,6 @@ void VT_KBCallBack(Uint32 Codepoint)
        }
 }
 
-/**
- * \fn void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
- * \brief Print a string to the Virtual Terminal
- */
-void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
-{
-       Uint32  val;
-        int    i;
-       for( i = 0; i < Count; i++ )
-       {
-               if( Buffer[i] == 0x1B ) // Escape Sequence
-               {
-                       i ++;
-                       i += VT_int_ParseEscape(Term, (char*)&Buffer[i]);
-                       continue;
-               }
-               
-               if( Buffer[i] < 128 )   // Plain ASCII
-                       VT_int_PutChar(Term, Buffer[i]);
-               else {  // UTF-8
-                       i += ReadUTF8(&Buffer[i], &val);
-                       VT_int_PutChar(Term, val);
-               }
-       }
-       
-       // Update cursor
-       if( Term == gpVT_CurTerm && !(Term->Flags & VT_FLAG_HIDECSR) )
-       {
-               tVideo_IOCtl_Pos        pos;
-               pos.x = Term->WritePos % Term->Width;
-               pos.y = Term->WritePos / Term->Width;
-               VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
-       }
-}
-
 /**
  * \fn void VT_int_ClearLine(tVTerm *Term, int Num)
  * \brief Clears a line in a virtual terminal
@@ -833,6 +802,43 @@ int VT_int_ParseEscape(tVTerm *Term, char *Buffer)
        return j + 1;
 }
 
+/**
+ * \fn void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
+ * \brief Print a string to the Virtual Terminal
+ */
+void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
+{
+       Uint32  val;
+        int    i;
+       for( i = 0; i < Count; i++ )
+       {
+               if( Buffer[i] == 0x1B ) // Escape Sequence
+               {
+                       i ++;
+                       i += VT_int_ParseEscape(Term, (char*)&Buffer[i]);
+                       continue;
+               }
+               
+               if( Buffer[i] < 128 )   // Plain ASCII
+                       VT_int_PutChar(Term, Buffer[i]);
+               else {  // UTF-8
+                       i += ReadUTF8(&Buffer[i], &val);
+                       VT_int_PutChar(Term, val);
+               }
+       }
+       // Update Screen
+       VT_int_UpdateScreen( Term, 0 );
+       
+       // Update cursor
+       if( Term == gpVT_CurTerm && !(Term->Flags & VT_FLAG_HIDECSR) )
+       {
+               tVideo_IOCtl_Pos        pos;
+               pos.x = Term->WritePos % Term->Width;
+               pos.y = Term->WritePos / Term->Width;
+               VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
+       }
+}
+
 /**
  * \fn void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
  * \brief Write a single character to a VTerm
@@ -847,6 +853,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
        {
        case '\0':      return; // Ignore NULL byte
        case '\n':
+               VT_int_UpdateScreen( Term, 0 ); // Update the line before newlining
                Term->WritePos += Term->Width;
        case '\r':
                Term->WritePos -= Term->WritePos % Term->Width;
@@ -927,8 +934,6 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
                //LOG("Scrolled screen");
                VT_int_UpdateScreen( Term, 1 );
        }
-       else
-               VT_int_UpdateScreen( Term, 0 );
        
        //LEAVE('-');
 }

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