[CONSRV]: Move the palette hack.
[reactos.git] / reactos / win32ss / user / winsrv / consrv / conoutput.c
index af3325a..bca67fd 100644 (file)
@@ -12,7 +12,7 @@
 #include "consrv.h"
 #include "console.h"
 #include "include/conio.h"
-#include "include/conio2.h"
+#include "include/term.h"
 #include "conoutput.h"
 #include "handle.h"
 
@@ -52,30 +52,110 @@ CSR_API(SrvInvalidateBitMapRect)
 
 NTSTATUS NTAPI
 ConDrvSetConsolePalette(IN PCONSOLE Console,
-                        IN PGRAPHICS_SCREEN_BUFFER Buffer,
+                        // IN PGRAPHICS_SCREEN_BUFFER Buffer,
+                        IN PCONSOLE_SCREEN_BUFFER Buffer,
                         IN HPALETTE PaletteHandle,
-                        IN UINT Usage);
+                        IN UINT PaletteUsage);
 CSR_API(SrvSetConsolePalette)
 {
     NTSTATUS Status;
     PCONSOLE_SETPALETTE SetPaletteRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetPaletteRequest;
-    // PCONSOLE_SCREEN_BUFFER Buffer;
-    PGRAPHICS_SCREEN_BUFFER Buffer;
+    // PGRAPHICS_SCREEN_BUFFER Buffer;
+    PCONSOLE_SCREEN_BUFFER Buffer;
+
+
+/******************************************************************************\
+|************** HACK! HACK! HACK! HACK! HACK! HACK! HACK! HACK! ***************|
+\******************************************************************************/
+
+#define PALETTESIZE 256
+
+    LPLOGPALETTE LogPalette;                  /* Pointer to logical palette */
+    PALETTEENTRY MyPalette[] =
+    { {0,   0,   0x80,0} ,       // 1
+      {0,   0x80,0,   0} ,       // 2
+      {0,   0,   0,   0} ,       // 0
+      {0,   0x80,0x80,0} ,       // 3
+      {0x80,0,   0,   0} ,       // 4
+      {0x80,0,   0x80,0} ,       // 5
+      {0x80,0x80,0,   0} ,       // 6
+      {0xC0,0xC0,0xC0,0} ,       // 7
+      {0x80,0x80,0x80,0} ,       // 8
+      {0,   0,   0xFF,0} ,       // 9
+      {0,   0xFF,0,   0} ,       // 10
+      {0,   0xFF,0xFF,0} ,       // 11
+      {0xFF,0,   0,   0} ,       // 12
+      {0xFF,0,   0xFF,0} ,       // 13
+      {0xFF,0xFF,0,   0} ,       // 14
+      {0xFF,0xFF,0xFF,0} };      // 15
+
+/******************************************************************************\
+|************** HACK! HACK! HACK! HACK! HACK! HACK! HACK! HACK! ***************|
+\******************************************************************************/
 
-    DPRINT("SrvSetConsolePalette\n");
+
+    DPRINT1("SrvSetConsolePalette\n");
 
     // NOTE: Tests show that this function is used only for graphics screen buffers
-    // and otherwise it returns false + sets last error to invalid handle.
+    // and otherwise it returns FALSE + sets last error to invalid handle.
+    // I think it's ridiculous, because if you are in text mode, simulating
+    // a change of VGA palette via DAC registers (done by a call to SetConsolePalette)
+    // cannot be done... So I allow it in ReactOS !
+    /*
     Status = ConSrvGetGraphicsBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
                                      SetPaletteRequest->OutputHandle,
                                      &Buffer, GENERIC_WRITE, TRUE);
+    */
+    Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
+                                   SetPaletteRequest->OutputHandle,
+                                   &Buffer, GENERIC_WRITE, TRUE);
     if (!NT_SUCCESS(Status)) return Status;
 
+
+/******************************************************************************\
+|************** HACK! HACK! HACK! HACK! HACK! HACK! HACK! HACK! ***************|
+\******************************************************************************/
+
+    DPRINT1("HACK: FIXME: SrvSetConsolePalette - Use hacked palette for testing purposes!!\n");
+
+    LogPalette = (LPLOGPALETTE)ConsoleAllocHeap(HEAP_ZERO_MEMORY,
+                                                (sizeof(LOGPALETTE) +
+                                                (sizeof(PALETTEENTRY) * PALETTESIZE)));
+    if (LogPalette)
+    {
+        UINT i;
+
+        LogPalette->palVersion = 0x300;
+        LogPalette->palNumEntries = PALETTESIZE;
+
+        for (i = 0 ; i < PALETTESIZE ; i++)
+        {
+            LogPalette->palPalEntry[i] = MyPalette[i % sizeof(MyPalette)/sizeof(MyPalette[0])];
+        }
+
+        SetPaletteRequest->PaletteHandle = CreatePalette(LogPalette);
+        SetPaletteRequest->Usage = SYSPAL_NOSTATIC256;
+        ConsoleFreeHeap(LogPalette);
+    }
+    else
+    {
+        DPRINT1("SrvSetConsolePalette - Hacked LogPalette is NULL\n");
+    }
+
+/******************************************************************************\
+|************** HACK! HACK! HACK! HACK! HACK! HACK! HACK! HACK! ***************|
+\******************************************************************************/
+
+
+    DPRINT1("ConDrvSetConsolePalette calling...\n");
+
     Status = ConDrvSetConsolePalette(Buffer->Header.Console,
                                      Buffer,
                                      SetPaletteRequest->PaletteHandle,
                                      SetPaletteRequest->Usage);
 
+    DPRINT1("ConDrvSetConsolePalette returned Status 0x%08lx\n", Status);
+
     ConSrvReleaseScreenBuffer(Buffer, TRUE);
     return Status;
 }
@@ -308,6 +388,7 @@ DoWriteConsole(IN PCSR_API_MESSAGE ApiMessage,
 
 // Wait function CSR_WAIT_FUNCTION
 static BOOLEAN
+NTAPI
 WriteConsoleThread(IN PLIST_ENTRY WaitList,
                    IN PCSR_THREAD WaitThread,
                    IN PCSR_API_MESSAGE WaitApiMessage,
@@ -380,7 +461,6 @@ DoWriteConsole(IN PCSR_API_MESSAGE ApiMessage,
                                WriteConsoleThread,
                                ClientThread,
                                ApiMessage,
-                               NULL,
                                NULL))
             {
                 /* Fail */