dive.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. {****************************************************************************
  2. DIVE interface unit
  3. FPC Pascal Runtime Library for OS/2
  4. Copyright (c) 1999-2000 by Karoly Balogh (aka Charlie/INQ)
  5. The FPC Pascal runtime library is distributed under the Library GNU Public
  6. License v2. So is this unit. The Library GNU Public License requires you to
  7. distribute the source code of this unit with any product that uses it.
  8. Because the EMX library isn't under the LGPL, we grant you an exception to
  9. this, and that is, when you compile a program with the Free Pascal Compiler,
  10. you do not need to ship source code with that program, AS LONG AS YOU ARE
  11. USING UNMODIFIED CODE! If you modify this code, you MUST change the next
  12. line:
  13. <This an official, unmodified Free Pascal source code file.>
  14. Send us your modified files, we can work together if you want!
  15. Free Pascal is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. Library GNU General Public License for more details.
  19. You should have received a copy of the Library GNU General Public License
  20. along with Free Pascal; see the file COPYING.LIB. If not, write to
  21. the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  22. Boston, MA 02110-1301, USA.
  23. ****************************************************************************}
  24. Unit DIVE;
  25. {Warning: This code is alfa. Future versions of this unit will propably
  26. not be compatible.}
  27. Interface
  28. Uses OS2Def, PMWin, MMBase;
  29. Const Max_Dive_Instances = 64;
  30. DIVE_Success = $00000000;
  31. DIVE_Err_Invalid_Instance = $00001000;
  32. DIVE_Err_Source_Format = $00001001;
  33. DIVE_Err_Destination_Format = $00001002;
  34. DIVE_Err_Blitter_Not_Setup = $00001003;
  35. DIVE_Err_Insufficient_Length = $00001004;
  36. DIVE_Err_Too_Many_Instances = $00001005;
  37. DIVE_Err_No_Direct_Access = $00001006;
  38. DIVE_Err_Not_Bank_Switched = $00001007;
  39. DIVE_Err_Invalid_Bank_Number = $00001008;
  40. DIVE_Err_FB_Not_Acquired = $00001009;
  41. DIVE_Err_FB_Already_Acquired = $0000100A;
  42. DIVE_Err_Acquire_Failed = $0000100B;
  43. DIVE_Err_Bank_Switch_Failed = $0000100C;
  44. DIVE_Err_Deacquire_Failed = $0000100D;
  45. DIVE_Err_Invalid_Palette = $0000100E;
  46. DIVE_Err_Invalid_Destination_RECTL = $0000100F;
  47. DIVE_Err_Invalid_Buffer_Number = $00001010;
  48. DIVE_Err_SSMDD_Not_Installed = $00001011;
  49. DIVE_Err_Buffer_Already_Accessed = $00001012;
  50. DIVE_Err_Buffer_Not_Accessed = $00001013;
  51. DIVE_Err_Too_Many_Bufffers = $00001014;
  52. DIVE_Err_Allocation_Error = $00001015;
  53. DIVE_Err_Invalid_Linesize = $00001016;
  54. DIVE_Err_Fatal_Exception = $00001017;
  55. DIVE_Err_Invalid_Conversion = $00001018;
  56. DIVE_Err_VSD_Error = $00001019;
  57. DIVE_Err_Color_Support = $0000101A;
  58. DIVE_Err_Out_Of_Range = $0000101B;
  59. DIVE_Warn_No_Size = $00001100;
  60. DIVE_Buffer_Screen = $00000000;
  61. DIVE_Buffer_Graphics_Plane = $00000001;
  62. DIVE_Buffer_Alternate_Plane = $00000002;
  63. DIVE_Fully_Visible = $FFFFFFFF;
  64. { * Use either of the two defines as the bRGB2Entries pointer to have DIVE * }
  65. { * query and set the physical or default palette as source or destination. * }
  66. DIVE_Palette_Physical = $00000000;
  67. DIVE_Palette_Default = $FFFFFFFF;
  68. Type HDIVE = cardinal;
  69. { * Blitter setup structures * }
  70. TSetup_Blitter = Record
  71. ulStructLen : cardinal; { * ulStructLen tells how much of the structure is used. * }
  72. { * Comments here show appropriate values, so don't count ;) * }
  73. fInvert : cardinal; { * Image is inverted on blit * }
  74. { * fInvert use: * }
  75. { * %0001 = 01 = $01 horizontal flip * }
  76. { * %0010 = 02 = $02 vertical flip * }
  77. { * This is the mark for 8 bytes * }
  78. fccSrcColorFormat : FourCC; { * Source data format * }
  79. ulSrcWidth : cardinal; { * Width in pels * }
  80. ulSrcHeight : cardinal; { * Height in pels * }
  81. { * The following are for displaying a sub-portion of the image. * }
  82. ulSrcPosX : cardinal; { * X Position of source data * }
  83. ulSrcPosY : cardinal; { * Y Position of source data * }
  84. { * This is the mark for 28 bytes * }
  85. ulDitherType : cardinal; { * Dither type * }
  86. { * 32 byte mark * }
  87. fccDstColorFormat : FourCC; { * Destination color format * }
  88. ulDstWidth : cardinal; { * Destination width in pels * }
  89. ulDstHeight : cardinal; { * Destination height in pels * }
  90. lDstPosX : LongInt;
  91. lDstPosY : LongInt;
  92. { * 52 byte mark * }
  93. lScreenPosX : LongInt;
  94. lScreenPosY : LongInt;
  95. { * 60 byte mark * }
  96. ulNumDstRects : cardinal;
  97. pVisDstRects : PRectl; { * This is a pointer to an array of visible rectangles. * }
  98. { * 68 bytes = fully used * }
  99. End;
  100. PSetup_Blitter = ^TSetup_Blitter;
  101. { * Stuff for DiveQueryCaps() * }
  102. TDIVE_CAPS = Record
  103. ulStructLen : cardinal; { * SizeOf(TDIVE_CAPS) * }
  104. ulPlaneCount : cardinal; { * Number of defined planes * }
  105. { * Following info applies to ulPlaneID * }
  106. fScreenDirect : Boolean; { * Direct screen access (was type BOOL in C) * }
  107. fBankSwitched : Boolean; { * VRAM bank-switched? (was type BOOL in C) * }
  108. ulDepth : cardinal; { * Number of bits per pixel * }
  109. ulHorizontalResolution : cardinal;
  110. ulVerticalResolution : cardinal;
  111. ulScanLineBytes : cardinal;
  112. fccColorEncoding : FourCC;
  113. ulApertureSize : cardinal;
  114. ulInputFormats : cardinal; { * Number of input color formats * }
  115. ulOutputFormats : cardinal;
  116. ulFormatLength : cardinal; { * Length of format buffer * }
  117. pFormatData : Pointer; { * Pointer to format buffer of FOURCC's * }
  118. End;
  119. PDIVE_CAPS = ^TDIVE_CAPS;
  120. Function DiveQueryCaps(DiveCaps: PDIVE_CAPS; ulPlaneBufNum : cardinal) : cardinal; cdecl;
  121. Function DiveOpen(Var phDiveInst : cardinal; fNonScreenInstance : cardinal;
  122. Var ppFrameBuffer : Pointer) : cardinal; cdecl;
  123. Function DiveClose(hDiveInst : cardinal) : cardinal; cdecl;
  124. Function DiveSetupBlitter(hDiveInst : cardinal; pSetupBlitter : PSetup_Blitter) : cardinal; cdecl;
  125. Function DiveBlitImage(hDiveInst : cardinal; ulSrcBufNumber : cardinal; ulDstBufNumber : cardinal) : cardinal; cdecl;
  126. Function DiveAcquireFrameBuffer(hDiveInst : cardinal; prectlDst : PRectl) : cardinal; cdecl;
  127. Function DiveDeacquireFrameBuffer(hDiveInst : cardinal) : cardinal; cdecl;
  128. Function DiveCalcFrameBufferAddress(hDiveInst : cardinal;
  129. prectlDest : PRectl;
  130. Var pDestinationAddress : Pointer;
  131. Var ulBankNumber : cardinal;
  132. Var ulRemLinesInBank : cardinal) : cardinal; cdecl;
  133. Function DiveSwitchBank(hDiveInst : cardinal; ulBankNumber : cardinal) : cardinal; cdecl;
  134. { Notes on DiveAllocImageBuffer:
  135. If pbImageBuffer is not NULL, the buffer is associated rather than
  136. allocated. If pbImageBuffer is not NULL and the buffer number
  137. pointed to by pulBufferNumber is non-zero, a new buffer pointer is
  138. associated with the buffer number. Even though no memory is
  139. allocated by DiveAllocImageBuffer when user-allocated buffers are
  140. associated, DiveFreeImageBuffer should be called to release the
  141. buffer association to avoid using up available buffer indexes.
  142. The specified line size will be used if a buffer is allocated in
  143. system memory, or if a user buffer is associated. If the
  144. specified line size is zero, the allocated line size is rounded up
  145. to the nearest DWORD boundry. }
  146. Function DiveAllocImageBuffer(hDiveInst : cardinal;
  147. Var ulBufferNumber : cardinal;
  148. fccColorSpace : FourCC;
  149. ulWidth : cardinal;
  150. ulHeight : cardinal;
  151. ulLineSizeBytes : cardinal;
  152. Var bImageBuffer : Pointer) : cardinal; cdecl;
  153. Function DiveFreeImageBuffer(hDiveInst : cardinal; ulBufferNumber : cardinal) : cardinal; cdecl;
  154. Function DiveBeginImageBufferAccess(hDiveInst : cardinal;
  155. ulBufferNumber : cardinal;
  156. Var pbImageBuffer : Pointer;
  157. Var ulBufferScanLineBytes : cardinal;
  158. Var ulBufferScanLines : cardinal) : cardinal; cdecl;
  159. Function DiveEndImageBufferAccess(hDiveInst : cardinal; ulBufferNumber : cardinal) : cardinal; cdecl;
  160. {/* Notes on palettes:
  161. Neither DiveSetSourcePalette nor DiveSetDestinationPalette API's will set
  162. the physical palette. If your application MUST set the PHYSICAL palette,
  163. try using no more than 236 entries (the middle 236: 10-245, thus leaving
  164. the top and bottom 10 entries for the Workplace Shell). If your
  165. application MUST use ALL 256 entries, it must do so as a full-screen
  166. (i.e. maximized) application. Remember, No WM_REALIZEPALETTE message
  167. will be sent to other running applications, meaning they will not redraw
  168. and their colors will be all wrong. It is not recommended that a
  169. developer use these commands:
  170. To set physical palette, do the following:
  171. hps = WinGetPS ( HWND_DESKTOP );
  172. hdc = GpiQueryDevice ( hps );
  173. GpiCreateLogColorTable ( hps, LCOL_PURECOLOR | LCOL_REALIZABLE,
  174. LCOLF_CONSECRGB, 0, 256, (PLONG)plRGB2Entries );
  175. Gre32EntrY3 ( hdc, 0L, 0x000060C6L );
  176. WinInvalidateRect ( HWND_DESKTOP, (PRECTL)NULL, TRUE );
  177. WinReleasePS ( hps );
  178. To reset physical palette, do the following:
  179. hps = WinGetPS ( HWND_DESKTOP );
  180. hdc = GpiQueryDevice ( hps );
  181. Gre32EntrY3 ( hdc, 0L, 0x000060C7L );
  182. WinInvalidateRect ( HWND_DESKTOP, (PRECTL)NULL, TRUE );
  183. WinReleasePS ( hps );
  184. */}
  185. Function DiveSetDestinationPalette(hDiveInst : cardinal;
  186. ulStartIndex : cardinal;
  187. ulNumEntries : cardinal;
  188. Var bRGB2Entries : Pointer) : cardinal; cdecl;
  189. Function DiveSetSourcePalette(hDiveInst : cardinal;
  190. ulStartIndex : cardinal;
  191. ulNumEntries : cardinal;
  192. Var bRGB2Entries : Pointer) : cardinal; cdecl;
  193. Function DiveSetTransparentBlitMode(hDiveInst : cardinal;
  194. ulStartIndex : cardinal;
  195. ulValue1 : cardinal;
  196. ulValue2 : cardinal) : cardinal; cdecl;
  197. Implementation
  198. Function DiveQueryCaps(DiveCaps : PDIVE_CAPS; ulPlaneBufNum : cardinal) : cardinal; cdecl;
  199. External 'DIVE' Index 1;
  200. Function DiveOpen(Var phDiveInst : cardinal; fNonScreenInstance : cardinal; Var ppFrameBuffer : Pointer) : cardinal; cdecl;
  201. External 'DIVE' Index 2;
  202. Function DiveClose(hDiveInst : cardinal) : cardinal; cdecl;
  203. External 'DIVE' Index 3;
  204. Function DiveSetupBlitter(hDiveInst : cardinal; pSetupBlitter : PSetup_Blitter) : cardinal; cdecl;
  205. External 'DIVE' Index 4;
  206. Function DiveBlitImage(hDiveInst : cardinal; ulSrcBufNumber : cardinal; ulDstBufNumber : cardinal) : cardinal; cdecl;
  207. External 'DIVE' Index 5;
  208. Function DiveAcquireFrameBuffer(hDiveInst : cardinal; prectlDst : PRectl) : cardinal; cdecl;
  209. External 'DIVE' Index 6;
  210. Function DiveDeacquireFrameBuffer(hDiveInst : cardinal) : cardinal; cdecl;
  211. External 'DIVE' Index 8;
  212. Function DiveCalcFrameBufferAddress(hDiveInst : cardinal;
  213. prectlDest : PRectl;
  214. Var pDestinationAddress : Pointer;
  215. Var ulBankNumber : cardinal;
  216. Var ulRemLinesInBank : cardinal) : cardinal; cdecl;
  217. External 'DIVE' Index 11;
  218. Function DiveSwitchBank(hDiveInst : cardinal; ulBankNumber : cardinal) : cardinal; cdecl;
  219. External 'DIVE' Index 7;
  220. Function DiveAllocImageBuffer(hDiveInst : cardinal;
  221. Var ulBufferNumber : cardinal;
  222. fccColorSpace : FourCC;
  223. ulWidth : cardinal;
  224. ulHeight : cardinal;
  225. ulLineSizeBytes : cardinal;
  226. Var bImageBuffer : Pointer) : cardinal; cdecl;
  227. External 'DIVE' Index 12;
  228. Function DiveFreeImageBuffer(hDiveInst : cardinal;
  229. ulBufferNumber : cardinal) : cardinal; cdecl;
  230. External 'DIVE' Index 13;
  231. Function DiveBeginImageBufferAccess(hDiveInst : cardinal;
  232. ulBufferNumber : cardinal;
  233. Var pbImageBuffer : Pointer;
  234. Var ulBufferScanLineBytes : cardinal;
  235. Var ulBufferScanLines : cardinal) : cardinal; cdecl;
  236. External 'DIVE' Index 14;
  237. Function DiveEndImageBufferAccess(hDiveInst : cardinal; ulBufferNumber : cardinal) : cardinal; cdecl;
  238. External 'DIVE' Index 15;
  239. Function DiveSetDestinationPalette(hDiveInst : cardinal;
  240. ulStartIndex : cardinal;
  241. ulNumEntries : cardinal;
  242. Var bRGB2Entries : Pointer) : cardinal; cdecl;
  243. External 'DIVE' Index 9;
  244. Function DiveSetSourcePalette(hDiveInst : cardinal;
  245. ulStartIndex : cardinal;
  246. ulNumEntries : cardinal;
  247. Var bRGB2Entries : Pointer) : cardinal; cdecl;
  248. External 'DIVE' Index 10;
  249. Function DiveSetTransparentBlitMode(hDiveInst : cardinal;
  250. ulStartIndex : cardinal;
  251. ulValue1 : cardinal;
  252. ulValue2 : cardinal) : cardinal; cdecl;
  253. External 'DIVE' Index 18;
  254. End.