- make vga buildable on msvc.
[reactos.git] / reactos / drivers / video / displays / vga / vgavideo / vgavideo.c
index 2f06df4..3ad965f 100644 (file)
@@ -1,9 +1,23 @@
-#include <ddk/ntddvdeo.h>
-#include <ddk/winddi.h>
-#include <ntos/minmax.h>
+#define _WINBASE_
+#define _WINDOWS_H
+#include <stdarg.h>
+#include <windef.h>
+#include <guiddef.h>
+#include <wingdi.h>
+#include <winddi.h>
+#include <winioctl.h>
+#include <ntddvdeo.h>
 #include <stdlib.h>
 #include "vgavideo.h"
 
+#define DDKAPI __stdcall
+#define DDKFASTAPI __fastcall
+#define FASTCALL __fastcall
+#define DDKCDECLAPI __cdecl
+
+VOID DDKAPI WRITE_PORT_UCHAR(IN PUCHAR  Port, IN UCHAR  Value);
+VOID DDKAPI WRITE_PORT_USHORT(IN PUSHORT  Port, IN USHORT  Value);
+
 UCHAR PreCalcReverseByte[256];
 int maskbit[640];
 int y80[480];
@@ -21,36 +35,6 @@ static unsigned char rightMask;
 #define READ_REGISTER_UCHAR(p) (*((volatile UCHAR *)(p)))
 #define WRITE_REGISTER_UCHAR(p,c) (*((volatile CHAR *)(p))) = (c)
 
-INT abs(INT nm)
-{
-  if(nm<0)
-  {
-    return nm * -1;
-  } else
-  {
-    return nm;
-  }
-}
-
-div_t div(int num, int denom)
-{
-  div_t r;
-  if (num > 0 && denom < 0) {
-    num = -num;
-    denom = -denom;
-  }
-  r.quot = num / denom;
-  r.rem = num % denom;
-  if (num < 0 && denom > 0)
-  {
-    if (r.rem > 0)
-    {
-      r.quot++;
-      r.rem -= denom;
-    }
-  }
-  return r;
-}
 
 /*int mod(int num, int denom)
 {
@@ -82,7 +66,7 @@ BYTE bytesPerPixel(ULONG Format)
 
   case BMF_24BPP:
     return 3;
-  
+
   case BMF_32BPP:
     return 4;
 
@@ -144,7 +128,7 @@ VOID vgaPreCalc()
 
   for (j = 0; j < 256; j++)
     {
-      PreCalcReverseByte[j] = 
+      PreCalcReverseByte[j] =
        (((j >> 0) & 0x1) << 7) |
        (((j >> 1) & 0x1) << 6) |
        (((j >> 2) & 0x1) << 5) |
@@ -266,7 +250,7 @@ BOOL vgaHLine(INT x, INT y, INT len, UCHAR c)
   UCHAR a;
   ULONG pre1;
   ULONG orgpre1, orgx, midpre1;
-  ULONG ileftpix, imidpix, irightpix;
+  LONG ileftpix, imidpix, irightpix;
 
   orgx = x;
 
@@ -341,7 +325,7 @@ BOOL vgaHLine(INT x, INT y, INT len, UCHAR c)
 
 BOOL vgaVLine(INT x, INT y, INT len, UCHAR c)
 {
-  ULONG offset, i;
+  INT offset, i;
   UCHAR a;
 
   offset = xconv[x]+y80[y];
@@ -389,12 +373,12 @@ void DIB_BltFromVGA(int x, int y, int w, int h, void *b, int Dest_lDelta)
 {
   ULONG plane;
   ULONG left = x >> 3;
-  ULONG shift = x - (x & ~0x7);  
-  UCHAR pixel, nextpixel;    
-  ULONG rightcount;
-  ULONG i, j;
-  ULONG stride = w >> 3;
-  
+  ULONG shift = x - (x & ~0x7);
+  UCHAR pixel, nextpixel;
+  LONG rightcount;
+  INT i, j;
+  LONG stride = w >> 3;
+
   /* Calculate the number of rightmost bytes not in a dword block. */
   if (w >= 8)
     {
@@ -409,17 +393,17 @@ void DIB_BltFromVGA(int x, int y, int w, int h, void *b, int Dest_lDelta)
   /* Reset the destination. */
   for (j = 0; j < h; j++)
     {
-      memset(b + (j * Dest_lDelta), 0, abs(Dest_lDelta));
+      memset((PVOID)((ULONG_PTR)b + (j * Dest_lDelta)), 0, abs(Dest_lDelta));
     }
 
   for (plane = 0; plane < 4; plane++)
     {
       PUCHAR dest = b;
-      
+
       /* Select the plane we are reading in this iteration. */
       WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x04);
       WRITE_PORT_UCHAR((PUCHAR)GRA_D, plane);
-      
+
       for (j = 0; j < h; j++)
        {
          PULONG destline = (PULONG)dest;
@@ -431,7 +415,7 @@ void DIB_BltFromVGA(int x, int y, int w, int h, void *b, int Dest_lDelta)
              /* Form the data for one plane for an aligned block in the destination. */
              pixel = nextpixel;
              pixel >>= shift;
-             
+
              nextpixel = PreCalcReverseByte[READ_REGISTER_UCHAR(src + 1)];
              pixel |= (nextpixel << (8 - shift));
 
@@ -446,10 +430,10 @@ void DIB_BltFromVGA(int x, int y, int w, int h, void *b, int Dest_lDelta)
              /* Form the data for a complete block. */
              pixel = nextpixel;
              pixel >>= shift;
-             
+
              nextpixel = PreCalcReverseByte[READ_REGISTER_UCHAR(src + 1)];
              pixel |= (nextpixel << (8 - shift));
-             
+
              row = UnpackPixel[pixel] << plane;
 
              /* Store the data for each pixel in the destination. */
@@ -528,9 +512,9 @@ void DIB_BltFromVGA(int x, int y, int w, int h, void *b, int Dest_lDelta)
 void DIB_BltToVGA(int x, int y, int w, int h, void *b, int Source_lDelta, int StartMod)
 {
   PBYTE pb, opb = b;
-  ULONG i, j;
-  ULONG x2 = x + w;
-  ULONG y2 = y + h;
+  LONG i, j;
+  LONG x2 = x + w;
+  LONG y2 = y + h;
   ULONG offset;
   UCHAR a;
 
@@ -986,7 +970,7 @@ void DFB_BltToDIB(int x, int y, int w, int h, void *b, int bw, void *bdib, int d
   int i, j, dib_shift;
 
   bpX = b;
-  dib = bdib + y * dibw + (x / 2);
+  dib = (unsigned char *)bdib + y * dibw + (x / 2);
 
   for (i=w; i>0; i--) {
 
@@ -1015,7 +999,7 @@ void DIB_BltToDFB(int x, int y, int w, int h, void *b, int bw, void *bdib, int d
   int i, j, dib_shift, dib_and;
 
   bpX = b;
-  dib = bdib + y * dibw + (x / 2);
+  dib = (unsigned char *)bdib + y * dibw + (x / 2);
 
   for (i=w; i>0; i--) {