Leaked source code of windows server 2003
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.

369 lines
13 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: p2rd.h
  8. *
  9. * This module contains constants for the P2 internal Ramdac
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. //
  15. // 3Dlabs P2RD RAMDAC definitions
  16. // This set of registers resides at &(pCtrlRegs->ExternalVideo)
  17. //
  18. typedef struct _p2rd_regs
  19. {
  20. RAMDAC_REG RDPaletteWriteAddress;
  21. RAMDAC_REG RDPaletteData;
  22. RAMDAC_REG RDPixelMask;
  23. RAMDAC_REG RDPaletteAddressRead;
  24. RAMDAC_REG RDIndexLow;
  25. RAMDAC_REG RDIndexHigh;
  26. RAMDAC_REG RDIndexedData;
  27. RAMDAC_REG RDIndexControl;
  28. } P2RDRAMDAC, *pP2RDRAMDAC;
  29. //
  30. // structure containing the mapped addresses for each of the P2RD registers.
  31. // We need this since some chips like the Alpha cannot be accessed by simply
  32. // writing to the memory mapped register. So instead we set up the following
  33. // struct of memory addresses at init time and use these instead. All these
  34. // addresses must be passed to WRITE/READ_FAST_ULONG.
  35. // We also keep software copies of various registers in here so we can turn
  36. // on and off individual bits more easily.
  37. //
  38. typedef struct _p2rd_data
  39. {
  40. //
  41. // Register addresses
  42. //
  43. ULONG_PTR RDPaletteWriteAddress;
  44. ULONG_PTR RDPaletteData;
  45. ULONG_PTR RDPixelMask;
  46. ULONG_PTR RDPaletteAddressRead;
  47. ULONG_PTR RDIndexLow;
  48. ULONG_PTR RDIndexHigh;
  49. ULONG_PTR RDIndexedData;
  50. ULONG_PTR RDIndexControl;
  51. //
  52. // RAMDAC state info
  53. //
  54. ULONG cursorModeOff; // cursor disabled
  55. ULONG cursorModeCurrent; // disabled 32/64 mode cursor
  56. ULONG cursorControl; // x & y zoom, etc.
  57. ULONG cursorSize; // see P2RD_CURSOR_SIZE_*
  58. ULONG x, y;
  59. } P2RDData, *pP2RDData;
  60. //
  61. // Macro declared by any function wishing to use the P2ST internal RAMDAC .
  62. // MUST be declared after PERMEDIA_DECL.
  63. //
  64. #define P2RD_DECL_VARS pP2RDData pP2RDinfo
  65. #define P2RD_DECL_INIT pP2RDinfo = (pP2RDData)ppdev->pvPointerData
  66. #define P2RD_DECL \
  67. P2RD_DECL_VARS; \
  68. P2RD_DECL_INIT
  69. //
  70. // use the following macros as the address to pass to the
  71. // WRITE_P2RDREG_ULONG function
  72. //
  73. // Palette Access
  74. #define P2RD_PAL_WR_ADDR (pP2RDinfo->RDPaletteWriteAddress)
  75. #define P2RD_PAL_RD_ADDR (pP2RDinfo->RDPaletteAddressRead)
  76. #define P2RD_PAL_DATA (pP2RDinfo->RDPaletteData)
  77. // Pixel mask
  78. #define P2RD_PIXEL_MASK (pP2RDinfo->RDPixelMask)
  79. // Access to the indexed registers
  80. #define P2RD_INDEX_ADDR_LO (pP2RDinfo->RDIndexLow)
  81. #define P2RD_INDEX_ADDR_HI (pP2RDinfo->RDIndexHigh)
  82. #define P2RD_INDEX_DATA (pP2RDinfo->RDIndexedData)
  83. #define P2RD_INDEX_CONTROL (pP2RDinfo->RDIndexControl)
  84. // Bit field definitions for the direct access registers
  85. #define P2RD_IDX_CTL_AUTOINCREMENT_ENABLED 0x01
  86. // Indexed register definitions accessed via P2RD_LOAD_INDEX_REG() and
  87. // P2RD_READ_INDEX_REG()
  88. #define P2RD_MISC_CONTROL 0x0000
  89. #define P2RD_SYNC_CONTROL 0x0001
  90. #define P2RD_DAC_CONTROL 0x0002
  91. #define P2RD_PIXEL_SIZE 0x0003
  92. #define P2RD_COLOR_FORMAT 0x0004
  93. #define P2RD_CURSOR_MODE 0x0005
  94. #define P2RD_CURSOR_CONTROL 0x0006
  95. #define P2RD_CURSOR_X_LOW 0x0007
  96. #define P2RD_CURSOR_X_HIGH 0x0008
  97. #define P2RD_CURSOR_Y_LOW 0x0009
  98. #define P2RD_CURSOR_Y_HIGH 0x000a
  99. #define P2RD_CURSOR_HOTSPOT_X 0x000b
  100. #define P2RD_CURSOR_HOTSPOT_Y 0x000c
  101. #define P2RD_OVERLAY_KEY 0x000d
  102. #define P2RD_PAN 0x000e
  103. #define P2RD_SENSE 0x000f
  104. #define P2RD_CHECK_CONTROL 0x0018
  105. #define P2RD_CHECK_PIXEL_RED 0x0019
  106. #define P2RD_CHECK_PIXEL_GREEN 0x001a
  107. #define P2RD_CHECK_PIXEL_BLUE 0x001b
  108. #define P2RD_CHECK_LUT_RED 0x001c
  109. #define P2RD_CHECK_LUT_GREEN 0x001d
  110. #define P2RD_CHECK_LUT_BLUE 0x001e
  111. #define P2RD_DCLK_SETUP_1 0x01f0
  112. #define P2RD_DCLK_SETUP_2 0x01f1
  113. #define P2RD_MCLK_SETUP_1 0x01f2
  114. #define P2RD_MCLK_SETUP_2 0x01f3
  115. #define P2RD_DCLK_CONTROL 0x0200
  116. #define P2RD_DCLK0_PRE_SCALE 0x0201
  117. #define P2RD_DCLK0_FEEDBACK_SCALE 0x0202
  118. #define P2RD_DCLK0_POST_SCALE 0x0203
  119. #define P2RD_DCLK1_PRE_SCALE 0x0204
  120. #define P2RD_DCLK1_FEEDBACK_SCALE 0x0205
  121. #define P2RD_DCLK1_POST_SCALE 0x0206
  122. #define P2RD_DCLK2_PRE_SCALE 0x0207
  123. #define P2RD_DCLK2_FEEDBACK_SCALE 0x0208
  124. #define P2RD_DCLK2_POST_SCALE 0x0209
  125. #define P2RD_DCLK3_PRE_SCALE 0x020a
  126. #define P2RD_DCLK3_FEEDBACK_SCALE 0x020b
  127. #define P2RD_DCLK3_POST_SCALE 0x020c
  128. #define P2RD_MCLK_CONTROL 0x020d
  129. #define P2RD_MCLK_PRE_SCALE 0x020e
  130. #define P2RD_MCLK_FEEDBACK_SCALE 0x020f
  131. #define P2RD_MCLK_POST_SCALE 0x0210
  132. #define P2RD_CURSOR_PALETTE_START 0x0303 // 303..32f
  133. #define P2RD_CURSOR_PATTERN_START 0x0400 // 400..7ff
  134. // bit field definitions for the indexed registers
  135. #define P2RD_MISC_CONTROL_OVERLAYS_ENABLED 0x10
  136. #define P2RD_MISC_CONTROL_DIRECT_COLOR_ENABLED 0x08
  137. #define P2RD_MISC_CONTROL_HIGHCOLORRES 0x01
  138. #define P2RD_SYNC_CONTROL_VSYNC_ACTIVE_LOW 0x00
  139. #define P2RD_SYNC_CONTROL_HSYNC_ACTIVE_LOW 0x00
  140. #define P2RD_DAC_CONTROL_BLANK_PEDESTAL_ENABLED 0x80
  141. #define P2RD_PIXEL_SIZE_8BPP 0x00
  142. #define P2RD_PIXEL_SIZE_16BPP 0x01
  143. #define P2RD_PIXEL_SIZE_24_BPP 0x04
  144. #define P2RD_PIXEL_SIZE_32BPP 0x02
  145. #define P2RD_COLOR_FORMAT_CI8 0x0e
  146. #define P2RD_COLOR_FORMAT_8BPP 0x05
  147. #define P2RD_COLOR_FORMAT_15BPP 0x01
  148. #define P2RD_COLOR_FORMAT_16BPP 0x10
  149. #define P2RD_COLOR_FORMAT_32BPP 0x00
  150. #define P2RD_COLOR_FORMAT_LINEAR_EXT 0x40
  151. #define P2RD_CURSOR_MODE_REVERSE 0x40
  152. #define P2RD_CURSOR_MODE_WINDOWS 0x00
  153. #define P2RD_CURSOR_MODE_X 0x10
  154. #define P2RD_CURSOR_MODE_3COLOR 0x20
  155. #define P2RD_CURSOR_MODE_15COLOR 0x30
  156. #define P2RD_CURSOR_MODE_64x64 0x00
  157. #define P2RD_CURSOR_MODE_P0_32x32x2 0x02
  158. #define P2RD_CURSOR_MODE_P1_32x32x2 0x04
  159. #define P2RD_CURSOR_MODE_P2_32x32x2 0x06
  160. #define P2RD_CURSOR_MODE_P3_32x32x2 0x08
  161. #define P2RD_CURSOR_MODE_P01_32x32x4 0x0a
  162. #define P2RD_CURSOR_MODE_P23_32x32x4 0x0c
  163. #define P2RD_CURSOR_MODE_ENABLED 0x01
  164. #define P2RD_CURSOR_CONTROL_RPOS_ENABLED 0x04
  165. #define P2RD_CURSOR_CONTROL_DOUBLE_Y 0x02
  166. #define P2RD_CURSOR_CONTROL_DOUBLE_X 0x01
  167. #define P2RD_DCLK_CONTROL_LOCKED 0x02 // read-only
  168. #define P2RD_DCLK_CONTROL_ENABLED 0x01
  169. #define P2RD_MCLK_CONTROL_LOCKED 0x02 // read-only
  170. #define P2RD_MCLK_CONTROL_ENABLED 0x01
  171. #define P2RD_CURSOR_PALETTE_CURSOR_RGB(RGBIndex, Red, Green, Blue) \
  172. { \
  173. P2RD_LOAD_INDEX_REG(P2RD_CURSOR_PALETTE_START+3*(int)RGBIndex+0, Red); \
  174. P2RD_LOAD_INDEX_REG(P2RD_CURSOR_PALETTE_START+3*(int)RGBIndex+1, Green); \
  175. P2RD_LOAD_INDEX_REG(P2RD_CURSOR_PALETTE_START+3*(int)RGBIndex+2, Blue); \
  176. }
  177. #define P2RD_SYNC_WITH_PERMEDIA
  178. //
  179. // generic read/write routines for P2RD registers
  180. //
  181. #define WRITE_P2RDREG_ULONG(r, d) \
  182. { \
  183. WRITE_REGISTER_ULONG((PULONG)(r), d); \
  184. MEMORY_BARRIER(); \
  185. }
  186. #define READ_P2RDREG_ULONG(r) READ_REGISTER_ULONG((PULONG)(r))
  187. //
  188. // Macro to load a given data value into an internal P2RD register. The
  189. // second macro loads an internal index register assuming that we have
  190. // already zeroed the high address register.
  191. //
  192. #define P2RD_INDEX_REG(index) \
  193. { \
  194. WRITE_P2RDREG_ULONG(P2RD_INDEX_ADDR_LO, (ULONG)((index) & 0xff)); \
  195. WRITE_P2RDREG_ULONG(P2RD_INDEX_ADDR_HI, (ULONG)((index) >> 8)); \
  196. }
  197. #define P2RD_LOAD_DATA(data) \
  198. { \
  199. WRITE_P2RDREG_ULONG(P2RD_INDEX_DATA, (ULONG)((data) & 0xff)); \
  200. }
  201. #define P2RD_LOAD_INDEX_REG(index, data) \
  202. { \
  203. P2RD_INDEX_REG(index); \
  204. WRITE_P2RDREG_ULONG(P2RD_INDEX_DATA, (ULONG)((data) & 0xff)); \
  205. }
  206. #define P2RD_READ_INDEX_REG(index, data) \
  207. { \
  208. P2RD_INDEX_REG(index); \
  209. data = READ_P2RDREG_ULONG(P2RD_INDEX_DATA) & 0xff; \
  210. }
  211. #define P2RD_LOAD_INDEX_REG_LO(index, data) \
  212. { \
  213. WRITE_P2RDREG_ULONG(P2RD_INDEX_ADDR_LO, (ULONG)(index)); \
  214. WRITE_P2RDREG_ULONG(P2RD_INDEX_DATA, (ULONG)(data)); \
  215. }
  216. //
  217. // Macros to load a given RGB triple into the P2RD palette. Send the starting
  218. // index and then send RGB triples. Auto-increment is turned on.
  219. // Use P2RD_PALETTE_START and multiple P2RD_LOAD_PALETTE calls to load
  220. // a contiguous set of entries. Use P2RD_LOAD_PALETTE_INDEX to load a set
  221. // of sparse entries.
  222. //
  223. #define P2RD_PALETTE_START_WR(index) \
  224. { \
  225. WRITE_P2RDREG_ULONG(P2RD_PAL_WR_ADDR, (ULONG)(index)); \
  226. }
  227. #define P2RD_PALETTE_START_RD(index) \
  228. { \
  229. WRITE_P2RDREG_ULONG(P2RD_PAL_RD_ADDR, (ULONG)(index)); \
  230. }
  231. #define P2RD_LOAD_PALETTE(red, green, blue) \
  232. { \
  233. WRITE_P2RDREG_ULONG(P2RD_PAL_DATA, (ULONG)(red)); \
  234. WRITE_P2RDREG_ULONG(P2RD_PAL_DATA, (ULONG)(green)); \
  235. WRITE_P2RDREG_ULONG(P2RD_PAL_DATA, (ULONG)(blue)); \
  236. }
  237. #define P2RD_LOAD_PALETTE_INDEX(index, red, green, blue) \
  238. { \
  239. WRITE_P2RDREG_ULONG(P2RD_PAL_WR_ADDR, (ULONG)(index)); \
  240. WRITE_P2RDREG_ULONG(P2RD_PAL_DATA, (ULONG)(red)); \
  241. WRITE_P2RDREG_ULONG(P2RD_PAL_DATA, (ULONG)(green)); \
  242. WRITE_P2RDREG_ULONG(P2RD_PAL_DATA, (ULONG)(blue)); \
  243. }
  244. //
  245. // Macro to read back a given RGB triple from the P2RD palette. Use after
  246. // a call to P2RD_PALETTE_START_RD
  247. //
  248. #define P2RD_READ_PALETTE(red, green, blue) \
  249. { \
  250. red = (UCHAR)(READ_P2RDREG_ULONG(P2RD_PAL_DATA) & 0xff); \
  251. green = (UCHAR)(READ_P2RDREG_ULONG(P2RD_PAL_DATA) & 0xff); \
  252. blue = (UCHAR)(READ_P2RDREG_ULONG(P2RD_PAL_DATA) & 0xff); \
  253. }
  254. //
  255. // Macros to set/get the pixel read mask. The mask is 8 bits wide and gets
  256. // replicated across all bytes that make up a pixel.
  257. //
  258. #define P2RD_SET_PIXEL_READMASK(mask) \
  259. { \
  260. WRITE_P2RDREG_ULONG(P2RD_PIXEL_MASK, (ULONG)(mask)); \
  261. }
  262. #define P2RD_READ_PIXEL_READMASK(mask) \
  263. { \
  264. mask = READ_P2RDREG_ULONG(P2RD_PIXEL_MASK) & 0xff; \
  265. }
  266. //
  267. // Windows format byte-packed cursor data: each byte represents 4 consecutive
  268. // pixels
  269. //
  270. #define P2RD_CURSOR_2_COLOR_BLACK 0x00
  271. #define P2RD_CURSOR_2_COLOR_WHITE 0x55
  272. #define P2RD_CURSOR_2_COLOR_TRANSPARENT 0xAA
  273. #define P2RD_CURSOR_2_COLOR_HIGHLIGHT 0xFF
  274. #define P2RD_CURSOR_3_COLOR_TRANSPARENT 0x00
  275. #define P2RD_CURSOR_15_COLOR_TRANSPARENT 0x00
  276. //
  277. // Macros to load values into the cursor array usage is
  278. // P2RD_CURSOR_ARRAR_START() followed by n iterations of P2RD_LOAD_CURSOR_ARRAY()
  279. // or P2RD_READ_CURSOR_ARRAY()
  280. //
  281. #define P2RD_CURSOR_ARRAY_START(offset) \
  282. { \
  283. WRITE_P2RDREG_ULONG(P2RD_INDEX_ADDR_LO,(ULONG)(((offset)+P2RD_CURSOR_PATTERN_START) & 0xff));\
  284. WRITE_P2RDREG_ULONG(P2RD_INDEX_ADDR_HI, (ULONG)(((offset)+P2RD_CURSOR_PATTERN_START) >> 8)); \
  285. }
  286. #define P2RD_LOAD_CURSOR_ARRAY(data) \
  287. { \
  288. WRITE_P2RDREG_ULONG(P2RD_INDEX_DATA, (ULONG)(data)); \
  289. }
  290. #define P2RD_READ_CURSOR_ARRAY(data) \
  291. { \
  292. data = READ_P2RDREG_ULONG(P2RD_INDEX_DATA) & 0xff; \
  293. }
  294. // macro to move the cursor
  295. //
  296. #define P2RD_MOVE_CURSOR(x, y) \
  297. { \
  298. WRITE_P2RDREG_ULONG(P2RD_INDEX_ADDR_HI, (ULONG)0); \
  299. P2RD_LOAD_INDEX_REG_LO(P2RD_CURSOR_X_LOW, (ULONG)((x) & 0xff)); \
  300. P2RD_LOAD_INDEX_REG_LO(P2RD_CURSOR_X_HIGH, (ULONG)((x) >> 8)); \
  301. P2RD_LOAD_INDEX_REG_LO(P2RD_CURSOR_Y_LOW, (ULONG)((y) & 0xff)); \
  302. P2RD_LOAD_INDEX_REG_LO(P2RD_CURSOR_Y_HIGH, (ULONG)((y) >> 8)); \
  303. }
  304. // macro to change the cursor hotspot
  305. //
  306. #define P2RD_CURSOR_HOTSPOT(x, y) \
  307. { \
  308. WRITE_P2RDREG_ULONG(P2RD_INDEX_ADDR_HI, (ULONG)(0)); \
  309. P2RD_LOAD_INDEX_REG_LO(P2RD_CURSOR_HOTSPOT_X, (ULONG)(x)); \
  310. P2RD_LOAD_INDEX_REG_LO(P2RD_CURSOR_HOTSPOT_Y, (ULONG)(y)); \
  311. }
  312. // cursor sizes
  313. #define P2RD_CURSOR_SIZE_64_MONO 0
  314. #define P2RD_CURSOR_SIZE_32_MONO 1
  315. #define P2RD_CURSOR_SIZE_64_3COLOR 0
  316. #define P2RD_CURSOR_SIZE_32_3COLOR 1
  317. #define P2RD_CURSOR_SIZE_32_15COLOR 5
  318. #define P2RD_CURSOR_SEL(cursorSize, cursorIndex) (((cursorSize + cursorIndex) & 7) << 1)
  319. //
  320. // exported functions from pointer.c. Anything which is P2RD specific goes
  321. // in this file as well as real pointer stuff.
  322. //
  323. extern BOOL bP2RDCheckCSBuffering(PPDev);
  324. extern BOOL bP2RDSwapCSBuffers(PPDev, LONG);