Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

370 lines
10 KiB

  1. /*/****************************************************************************
  2. * name: fixed.c
  3. *
  4. * description:
  5. *
  6. * designed: Benoit Leblanc
  7. * last modified: $Author: bleblanc $, $Date: 94/06/23 13:00:39 $
  8. *
  9. * version: $Id: fixed.c 1.2 94/06/23 13:00:39 bleblanc Exp $
  10. *
  11. *
  12. * void mtxSetDisplayStart(dword x, dword y)
  13. * void AdjustDBWindow(void)
  14. *
  15. ******************************************************************************/
  16. #include "switches.h"
  17. #ifdef WINDOWS_NT
  18. #if defined(ALLOC_PRAGMA)
  19. #pragma alloc_text(PAGE,mtxSetDisplayStart)
  20. #endif
  21. #endif /* #ifdef WINDOWS_NT */
  22. #ifdef OS2
  23. #include <os2.h>
  24. #pragma intrinsic(strcat, strcpy)
  25. #endif
  26. #ifdef WINDOWS
  27. #include "windows.h"
  28. #endif
  29. #include "bind.h"
  30. #include "defbind.h"
  31. #include "sxci.h"
  32. #include "def.h"
  33. #include "mga.h"
  34. #include "mgai_c.h"
  35. #include "mgai.h"
  36. #ifdef _WINDOWS_DLL16
  37. /*** Definition for pool memory ***/
  38. #define PAN_X 0
  39. #define PAN_Y 1
  40. #define PAN_DISP_WIDTH 2
  41. #define PAN_DISP_HEIGHT 3
  42. #define DB_SCALE 4
  43. #define PAN_BOUND_LEFT 5
  44. #define PAN_BOUND_TOP 6
  45. #define PAN_BOUND_RIGHT 7
  46. #define PAN_BOUND_BOTTOM 8
  47. extern word NbSxciLoaded;
  48. extern word FAR *pDllMem;
  49. void AdjustDBWindow(void);
  50. #endif
  51. #ifdef WINDOWS_NT
  52. PUCHAR pMgaBaseAddr;
  53. #else
  54. extern volatile byte _Far *pMgaBaseAddr;
  55. #endif
  56. extern byte iBoard;
  57. extern HwData Hw[NB_BOARD_MAX+1];
  58. extern dword ProductMGA[NB_BOARD_MAX];
  59. extern byte VideoBuf[NB_BOARD_MAX][VIDEOBUF_S];
  60. /*----------------------------------------------------------
  61. * mtxSetDisplayStart
  62. *
  63. * Set the display start address
  64. *
  65. * This function sets the video display start address. This is
  66. * useful for scrolling and panning within the frame buffer.
  67. * Although any X coordinate will be accepted by this function,
  68. * it will be rounded to the nearest 16-pixel boundary (this
  69. * 16 pixel boundary is a hardware restriction). There is no
  70. * restriction on the y coordinate values that can be used as
  71. * the video display start.
  72. * It is up to the user to be sure that he remains within the
  73. * limits of the available frame buffer.
  74. *
  75. *----------------------------------------------------------*/
  76. void mtxSetDisplayStart(dword x, dword y)
  77. {
  78. byte ValExt;
  79. dword Addr, PhysAddr;
  80. dword StartBank=0;
  81. byte ByteCount, TmpByte, DUB_SEL;
  82. dword TmpDword;
  83. Hw[iBoard].CurrentXStart = x;
  84. Hw[iBoard].CurrentYStart = y;
  85. /* PACK PIXEL */
  86. if (Hw[iBoard].pCurrentHwMode->PixWidth == 24) /* PACK PIXEL */
  87. x = ((x * 3) >> 2) + (Hw[iBoard].YDstOrg >> 2);
  88. else
  89. x = x + Hw[iBoard].YDstOrg;
  90. {
  91. word PixByte;
  92. if (Hw[iBoard].pCurrentHwMode->PixWidth == 24) /* PACK PIXEL */
  93. PixByte = 32;
  94. else
  95. PixByte = Hw[iBoard].pCurrentHwMode->PixWidth;
  96. if(PixByte == 15)
  97. PixByte = 16;
  98. PixByte /= 8;
  99. if (Hw[iBoard].pCurrentHwMode->PixWidth == 24) /* PACK PIXEL */
  100. PhysAddr = ((y * ((Hw[iBoard].pCurrentHwMode->FbPitch * 3) >> 2)) + x) * PixByte;
  101. else
  102. PhysAddr = ((y * Hw[iBoard].pCurrentHwMode->FbPitch) + x) * PixByte;
  103. }
  104. switch (ProductMGA[iBoard])
  105. {
  106. case MGA_ULT_1M:
  107. case MGA_ULT_2M:
  108. case MGA_PCI_2M:
  109. StartBank = 0;
  110. break;
  111. case MGA_IMP_3M:
  112. if (PhysAddr < 2097152)
  113. StartBank = 0;
  114. else if (PhysAddr < 3145728)
  115. StartBank = 1;
  116. break;
  117. case MGA_IMP_3M_Z:
  118. if (PhysAddr < 524288)
  119. StartBank = 0;
  120. else if (PhysAddr < 2621440)
  121. StartBank = 1;
  122. break;
  123. case MGA_PRO_4M5:
  124. case MGA_PRO_4M5_Z:
  125. if (PhysAddr < 2097152)
  126. StartBank = 0;
  127. else if (PhysAddr < 4194304)
  128. StartBank = 1;
  129. else if (PhysAddr < 6291456)
  130. StartBank = 2;
  131. break;
  132. case MGA_PCI_4M:
  133. if (PhysAddr < 2097152)
  134. StartBank = 0;
  135. else
  136. StartBank = 1;
  137. break;
  138. default:
  139. StartBank = 0;
  140. }
  141. /*** ACCESS TO DUBIC : We program the start bank ***/
  142. /*** ----- DUBIC PATCH Disable mouse IRQ and proceed ------ ***/
  143. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 0x08);
  144. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DUB_SEL), DUB_SEL);
  145. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DUB_SEL), 0x00);
  146. /*** ------------------------------------------------------ ***/
  147. mgaWriteBYTE(*(pMgaBaseAddr+DUBIC_OFFSET + DUBIC_NDX_PTR), DUBIC_DUB_CTL);
  148. for (TmpDword = 0, ByteCount = 0; ByteCount <= 3; ByteCount++)
  149. {
  150. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), TmpByte);
  151. TmpDword |= ((dword)TmpByte << (8 * ByteCount));
  152. }
  153. TmpDword &= ~DUBIC_START_BK_M;
  154. TmpDword |= StartBank << DUBIC_START_BK_A;
  155. mgaWriteBYTE(*(pMgaBaseAddr+DUBIC_OFFSET + DUBIC_NDX_PTR), DUBIC_DUB_CTL);
  156. for (ByteCount = 0; ByteCount <= 3; ByteCount++)
  157. {
  158. TmpByte = (byte)(TmpDword >> (8 * ByteCount));
  159. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), TmpByte);
  160. }
  161. /*** ----- DUBIC PATCH ReEnable mouse IRQ ----------------- ***/
  162. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 0x08);
  163. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DUB_SEL), DUB_SEL);
  164. /*** ------------------------------------------------------ ***/
  165. /* Adjusting x to 16-bit boundary */
  166. if (Hw[iBoard].pCurrentHwMode->PixWidth != 24) /* PACK PIXEL */
  167. x = x & 0xfffffff0;
  168. #ifdef _WINDOWS_DLL16
  169. if(NbSxciLoaded)
  170. {
  171. *(pDllMem+PAN_X) = (word)x;
  172. *(pDllMem+PAN_Y) = (word)y;
  173. AdjustDBWindow();
  174. }
  175. #endif
  176. if (Hw[iBoard].pCurrentHwMode->PixWidth == 24)
  177. Addr = (y * ( ((Hw[iBoard].pCurrentHwMode->DispWidth * 3) >> 2) / 8)) + (x/8);
  178. else
  179. Addr = (y * (Hw[iBoard].pCurrentHwMode->DispWidth / 8)) + (x/8);
  180. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + VGA_CRTC_INDEX), VGA_START_ADDRESS_LOW);
  181. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + VGA_CRTC_DATA), (byte)Addr);
  182. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + VGA_CRTC_INDEX), VGA_START_ADDRESS_HIGH);
  183. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + VGA_CRTC_DATA), (byte)(Addr >> 8));
  184. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + VGA_AUXILIARY_INDEX), VGA_CRTC_EXTENDED_ADDRESS);
  185. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET + VGA_AUXILIARY_DATA), ValExt);
  186. ValExt = (ValExt & 0xfc) | ((byte)((Addr&0x00030000) >> 16));
  187. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + VGA_AUXILIARY_DATA), ValExt);
  188. }
  189. #ifdef _WINDOWS_DLL16
  190. /* IFDEF ADDED BY C. Toutant */
  191. /*----------------------------------------------------------
  192. * AdjustDBWindow
  193. *
  194. * Adjust the double buffering window
  195. *
  196. *----------------------------------------------------------*/
  197. void AdjustDBWindow(void)
  198. {
  199. short DBXMin,DBXMax,DBYMin,DBYMax;
  200. WORD PorchX, PorchY;
  201. bool OutFlag;
  202. byte DUB_SEL;
  203. word Width, Height;
  204. word xPan, yPan;
  205. word Scale;
  206. static word Cpt3Times;
  207. word BoxLeft, BoxTop, BoxRight, BoxBottom;
  208. OutFlag = FALSE;
  209. xPan = *(pDllMem+PAN_X);
  210. yPan = *(pDllMem+PAN_Y);
  211. BoxLeft = *(pDllMem+PAN_BOUND_LEFT) - *(pDllMem+PAN_X);
  212. BoxTop = *(pDllMem+PAN_BOUND_TOP) - *(pDllMem+PAN_Y);
  213. BoxRight = *(pDllMem+PAN_BOUND_RIGHT) - *(pDllMem+PAN_X);
  214. BoxBottom = *(pDllMem+PAN_BOUND_BOTTOM) - *(pDllMem+PAN_Y);
  215. Scale = *(pDllMem+DB_SCALE);
  216. Width = *(pDllMem+PAN_DISP_WIDTH) / Scale;
  217. Height = *(pDllMem+PAN_DISP_HEIGHT) / Scale;
  218. PorchX = *((WORD*)(VideoBuf[iBoard] + VIDEOBUF_DBWinXOffset)) / Scale;
  219. PorchY = *((WORD*)(VideoBuf[iBoard] + VIDEOBUF_DBWinYOffset)) / Scale;
  220. DBXMin = BoxLeft + PorchX;
  221. if((short)DBXMin < (short)PorchX)
  222. DBXMin = PorchX;
  223. if((short)DBXMin > (short)PorchX + Width)
  224. OutFlag = TRUE;
  225. DBXMax = BoxRight + PorchX;
  226. if((short)DBXMax < (short)PorchX)
  227. OutFlag = TRUE;
  228. if((short)DBXMax > (short)(PorchX + Width))
  229. DBXMax = PorchX + Width;
  230. DBYMin = BoxTop + PorchY;
  231. if((short)DBYMin < (short)PorchY)
  232. DBYMin = PorchY;
  233. if((short)DBYMin > (short)(PorchY + Height))
  234. OutFlag = TRUE;
  235. DBYMax = BoxBottom + PorchY;
  236. if((short)DBYMax < (short)PorchY)
  237. OutFlag = TRUE;
  238. if((short)DBYMax > (short)(PorchY + Height))
  239. DBYMax = PorchY + Height;
  240. DBYMin = DBYMin * Scale;
  241. DBYMax = DBYMax * Scale;
  242. if(OutFlag == TRUE)
  243. {
  244. DBXMin = 0;
  245. DBYMin = 0;
  246. DBXMax = 0;
  247. DBYMax = 0;
  248. }
  249. /*** ----- DUBIC PATCH Disable mouse IRQ and proceed ------ ***/
  250. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 0x08);
  251. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DUB_SEL), DUB_SEL);
  252. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DUB_SEL), 0x00);
  253. /*** ------------------------------------------------------ ***/
  254. /*** WRITE ***/
  255. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), DUBIC_DBX_MIN);
  256. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)DBXMin);
  257. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)(DBXMin >> 8));
  258. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), DUBIC_DBY_MIN);
  259. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)DBYMin);
  260. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)(DBYMin >> 8));
  261. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), DUBIC_DBX_MAX);
  262. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)DBXMax);
  263. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)(DBXMax >> 8));
  264. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), DUBIC_DBY_MAX);
  265. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)DBYMax);
  266. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), (BYTE)(DBYMax >> 8));
  267. /*** ----- DUBIC PATCH ReEnable mouse IRQ ----------------- ***/
  268. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 0x08);
  269. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DUB_SEL), DUB_SEL);
  270. /*** ------------------------------------------------------ ***/
  271. }
  272. #endif /* #ifdef _WINDOWS_DLL16 */