divetry.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. {$ASMMODE INTEL}
  2. { lame code, but who cares? :) please don't laugh it out. :) }
  3. Program DiveTry;
  4. Uses Os2Def,PMWin,DIVE,DOSCalls;
  5. { * main program * }
  6. Const ClassName = 'MYVIEW';
  7. idClientWindow = 11000;
  8. WinFlags : Cardinal = fcf_TitleBar+fcf_SysMenu+fcf_SizeBorder+
  9. fcf_MinMax+fcf_TaskList+fcf_NoByteAlign;
  10. Var Anchor, MsgQue : Cardinal;
  11. Message : TQMsg;
  12. Frame, Client : Cardinal;
  13. Picture : Pointer;
  14. PicSize : DWord;
  15. DIVEHandle : HDIVE;
  16. FrameBuffer : Pointer;
  17. DIVEImageBuffer : DWord;
  18. DIVEColorFormat : DWord;
  19. idBlitThread : DWord;
  20. DIVEBlitSetup : TSetup_Blitter;
  21. { * The exported procedure * }
  22. Function ClientWindowProc(Window, Msg : DWord; MP1, MP2: Pointer) : Pointer; cdecl; Export;
  23. Var Li : LongInt;
  24. PS : DWord;
  25. R : TRectL;
  26. P : TPointL;
  27. Rgn : DWord;
  28. DIVEBlitSetup : TSetup_Blitter;
  29. DestFormat : DWord;
  30. Begin
  31. ClientWindowProc:=Nil;
  32. Case Msg Of
  33. wm_Paint: Begin
  34. PS:=WinBeginPaint(Window,0,@r);
  35. WinFillRect(PS,@r,SYSCLR_WINDOW);
  36. Asm
  37. MOV EAX,'565R'
  38. MOV DestFormat,EAX
  39. End;
  40. With DIVEBlitSetup Do Begin
  41. ulStructLen := SizeOf(DIVEBlitSetup); { * Whole record used * }
  42. fInvert := 0; { * Not inverted * }
  43. { * This is the mark for 8 bytes * }
  44. fccSrcColorFormat:=DIVEColorFormat; { * Source data format * }
  45. ulSrcWidth:=640; { * Width in pels * }
  46. ulSrcHeight:=480; { * Height in pels * }
  47. ulSrcPosX:=0; { * X Position of source data * }
  48. ulSrcPosY:=0; { * Y Position of source data * }
  49. { * This is the mark for 28 bytes * }
  50. ulDitherType:=0; { * Dither type * }
  51. { * 32 byte mark * }
  52. fccDstColorFormat:=DestFormat; { * Destination color format * }
  53. ulDstWidth:=640; { * Destination width in pels * }
  54. ulDstHeight:=480; { * Destination height in pels * }
  55. lDstPosX:=0;
  56. lDstPosY:=0;
  57. { * 52 byte mark * }
  58. lScreenPosX:=0;
  59. lScreenPosY:=0;
  60. { * 60 byte mark * }
  61. ulNumDstRects:=1;
  62. pVisDstRects:=@r; { * This is a pointer to an array of visible rectangles. * }
  63. { * 68 bytes = fully used * }
  64. End;
  65. If DIVESetupBlitter(DIVEHandle,@DIVEBlitSetup)<>DIVE_Success Then Begin
  66. WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,'Cannot set up DIVE blitter!',
  67. 'DIVE Error!',0,MB_OK Or MB_ERROR Or MB_MOVEABLE);
  68. End;
  69. {DIVEBlitImage(DIVEHandle,DIVEImageBuffer,DIVE_Buffer_Screen);}
  70. WinEndPaint(PS);
  71. End;
  72. Else ClientWindowProc:=WinDefWindowProc(Window,Msg,MP1,MP2);
  73. End;
  74. End;
  75. Procedure DIVEBlitThread;
  76. Begin
  77. End;
  78. Function LoadFiles : Boolean;
  79. Var RAWFile : File;
  80. Begin
  81. LoadFiles:=False;
  82. Assign(RAWFile,'ANGEL.RAW'); { * Opening File * }
  83. Reset(RAWFile,1);
  84. If IOResult<>0 Then Exit; { * If File Not Found, Then Exit * }
  85. PicSize:=FileSize(RAWFile);
  86. GetMem(Picture,PicSize); { * Allocating Memory * }
  87. BlockRead(RAWFile,Picture^,PicSize); { * Loading File * }
  88. If IOResult<>0 Then Exit; { * If File Corrupted, Then Exit * }
  89. Close(RAWFile);
  90. LoadFiles:=True;
  91. End;
  92. Begin
  93. { * PM Init * }
  94. Anchor:=WinInitialize(0);
  95. { It might be beneficial to set the second parameter of the following }
  96. { call to something large, such as 1000. The OS/2 documentation does }
  97. { not recommend this, however }
  98. MsgQue:=WinCreateMsgQueue(Anchor,0);
  99. If MsgQue=0 Then Halt(254);
  100. { * Loading Graphics File * }
  101. If Not LoadFiles Then Begin
  102. WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,'File Corrupted : ANGEL.RAW',
  103. 'File Loading Error!',0,MB_OK Or MB_ERROR Or MB_MOVEABLE);
  104. WinDestroyMsgQueue(MsgQue);
  105. WinTerminate(Anchor);
  106. End;
  107. { * Opening DIVE, exiting if cannot be initialized * }
  108. If DIVEOpen(DIVEHandle,1,Framebuffer)<>DIVE_Success Then Begin
  109. WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,'DIVE subsystem cannot be initialized!',
  110. 'DIVE Error!',0,MB_OK Or MB_ERROR Or MB_MOVEABLE);
  111. WinDestroyMsgQueue(MsgQue);
  112. WinTerminate(Anchor);
  113. End;
  114. WinRegisterClass(Anchor,ClassName,Proc(@ClientWindowProc),cs_SizeRedraw,SizeOf(Pointer));
  115. Frame:=WinCreateStdWindow(hwnd_Desktop,0,WinFlags,ClassName,'DIVE with FPC/2 Example',
  116. 0,0,idClientWindow, Client);
  117. If (Frame<>0) Then Begin
  118. {$ASMMODE INTEL}
  119. Asm { * Tweakin' rules. :) Anyway, can i make something like this in pascal? (Eg. : DWordNum:='ABCD' ?) * }
  120. MOV EAX,'3BGR'
  121. MOV DIVEColorFormat,EAX
  122. End;
  123. If DIVEAllocImageBuffer(DIVEHandle,DIVEImageBuffer,DIVEColorFormat,640,480,0,Picture)<>DIVE_Success Then Begin
  124. WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,'DIVE image buffer cannot be allocated!',
  125. 'DIVE Error!',0,MB_OK Or MB_ERROR Or MB_MOVEABLE);
  126. DIVEClose(DIVEHandle);
  127. FreeMem(Picture,PicSize);
  128. WinDestroyMsgQueue(MsgQue);
  129. WinTerminate(Anchor);
  130. End;
  131. WinSetWindowPos(Frame,0,0,WinQuerySysValue(hwnd_Desktop,sv_CyScreen)-480,
  132. 640,480,swp_Move+swp_Size+swp_Activate+swp_Show);
  133. While WinGetMsg(Anchor,Message,0,0,0) Do WinDispatchMsg(Anchor,Message);
  134. { * Closing DIVE * }
  135. If DIVEFreeImageBuffer(DIVEHandle,DIVEImageBuffer)<>DIVE_Success Then Begin
  136. WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,'DIVE image buffer cannot be deallocated!',
  137. 'DIVE Error!',0,MB_OK Or MB_ERROR Or MB_MOVEABLE);
  138. End;
  139. DIVEClose(DIVEHandle);
  140. WinDestroyWindow(Frame);
  141. End;
  142. { * Freeing Up Allocated Memory * }
  143. FreeMem(Picture,PicSize);
  144. { * PM Close * }
  145. WinDestroyMsgQueue(MsgQue);
  146. WinTerminate(Anchor);
  147. End.