ibm.ppi 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. function DetectVESA:Boolean;
  12. var Result_:longint;
  13. begin
  14. Result_:=Global_dos_alloc($0200);
  15. Sel:=word(Result_);
  16. Seg:=word(Result_ shr 16);
  17. dregs.RealSP:=0; dregs.RealSS:=0;
  18. dregs.RealES:=Seg; dregs.RealEDI:=0;
  19. dregs.RealEAX:=$4F00; RealIntr($10,dregs);
  20. if isDPMI
  21. then MoveLong(sel,@VGAInfo,256)
  22. else Move(pointer((seg shl 4)+core)^,VGAInfo,256);
  23. global_dos_free(sel);
  24. DetectVesa:=(dregs.RealEAX and $FF=$4F);
  25. isVESA2:=VGAInfo.VESAHiVersion=2;
  26. end;
  27. function GetVESAInfo( Mode : WORD ):Boolean;
  28. var Result_:longint;
  29. begin
  30. Result_:=Global_dos_alloc($0200);
  31. Sel:=word(Result_);
  32. Seg:=word(Result_ shr 16);
  33. dregs.RealECX:=mode;
  34. dregs.RealSP:=0; dregs.RealSS:=0;
  35. dregs.RealES:=Seg; dregs.RealEDI:=0;
  36. dregs.RealEAX:=$4F01; RealIntr($10,dregs);
  37. if isDPMI
  38. then MoveLong(sel,@VESAInfo,256)
  39. else Move(Pointer((seg shl 4)+core)^,VESAINFO,256);
  40. global_dos_free(sel);
  41. { this is wrong because AH is set to one if mode not detected !!!
  42. if (dregs.RealEAX and $ff) =$4F then must be replaced by }
  43. if (dregs.RealEAX and $1ff) =$4F then
  44. begin
  45. GetVESAInfo:=true;
  46. BytesPerLine:=VESAInfo.BPL;
  47. case VESAInfo.BitsPerPixel of
  48. 8 : BytesPerPixel:=1;
  49. 15,16 : BytesPerPixel:=2;
  50. 24 : begin
  51. Oh_Kacke('24-Bit Modis nicht implementiert !');
  52. exit;
  53. end;
  54. end;
  55. _maxx:=VESAInfo.XResolution;
  56. _maxy:=VESAInfo.YResolution;
  57. WinSize:=VESAInfo.Winsize*1024;
  58. WinLoMask:=WinSize-1;
  59. case VESAInfo.WinSize of
  60. 64 : WinShift:=16; { x div 65536 = x shr 16 }
  61. 32 : WinShift:=15; { x div 32768 = x shr 15 }
  62. 16 : WinShift:=14; { ... }
  63. 8 : WinShift:=13;
  64. 4 : WinShift:=12;
  65. 2 : WinShift:=11;
  66. 1 : WinShift:=10;
  67. end;
  68. Granularity:=VESAInfo.WinGranularity;
  69. Granular:=VESAInfo.WinSize div Granularity;
  70. case Granular of
  71. 32 : GranShift:=5;
  72. 16 : GranShift:=4;
  73. 8 : GranShift:=3;
  74. 4 : GranShift:=2;
  75. 2 : GranShift:=1;
  76. 1 : GranShift:=0;
  77. end;
  78. { set selector for writing }
  79. if isDPMI then begin
  80. set_segment_base_address(seg_write,$A000 shl 4);
  81. set_segment_limit(seg_write,$FFFF);
  82. seg_read:=seg_write;
  83. end;
  84. SwitchCS:=hi(VESAInfo.RealWinFuncPtr);
  85. SwitchIP:=lo(VESAInfo.RealWinFuncPtr);
  86. end else GetVESAInfo:=false;
  87. end;
  88. function SetVESAMode(Mode:WORD):Boolean;
  89. begin
  90. dregs.RealEBX:=Mode;
  91. dregs.RealSP:=0; dregs.RealSS:=0;
  92. dregs.RealEAX:=$4F02; RealIntr($10,dregs);
  93. { idem as above !!! }
  94. if (dregs.RealEAX and $1FF) <> $4F then begin
  95. writeln('Couldn''t initialize VESAMode ',HexStr(mode,4));
  96. SetVESAMode:=false;
  97. end
  98. else SetVESAMode:=true;
  99. end;
  100. function GetVESAMode:Integer;
  101. begin
  102. dregs.RealSP:=0; dregs.RealSS:=0;
  103. dregs.RealEAX:=$4F03; RealIntr($10,dregs);
  104. GetVESAMode:=lo(dregs.RealEBX);
  105. end;
  106. procedure InitVESA;
  107. var RM:Word;
  108. begin
  109. isDPMI:=false;
  110. rm:=get_run_mode;
  111. case rm of
  112. 0 : writeln('unknown mode');
  113. 1 : writeln('RAW mode');
  114. 2 : writeln('XMS detected');
  115. 3 : writeln('VCPI detected');
  116. 4 : begin writeln('DPMI detected');
  117. isDPMI:=true;
  118. end;
  119. end; { case }
  120. if isDPMI then begin
  121. seg_write:=allocate_ldt_descriptors(1);
  122. seg_read:=allocate_ldt_descriptors(1);
  123. end else begin
  124. seg_write:=get_DS;
  125. seg_read:=get_DS;
  126. end;
  127. end;
  128. procedure DoneVESA;
  129. begin
  130. if isDPMI then begin
  131. free_ldt_descriptor(seg_read);
  132. free_ldt_descriptor(seg_write);
  133. end;
  134. end;
  135. procedure Switchbank(bank:longint);
  136. begin
  137. asm
  138. leal _DREGS,%edi
  139. movl bank,%eax
  140. movzbl _GRANSHIFT,%ecx
  141. shll %cl,%eax
  142. movl %eax,20(%edi) // RealEDX
  143. movw _SWITCHCS,%ax
  144. movw %ax,44(%edi) // RealCS
  145. movw _SWITCHIP,%ax // RealIP
  146. movw %ax,42(%edi)
  147. xorl %ecx,%ecx
  148. movl %ecx,46(%edi) // RealSS,RealSP
  149. movl %ecx,16(%edi) // RealEBX
  150. movw $0x0301,%ax
  151. int $0x31
  152. end;
  153. end;
  154. {
  155. $Log$
  156. Revision 1.2 1998-10-09 10:26:36 peter
  157. * rename result -> result_
  158. Revision 1.1.1.1 1998/03/25 11:18:42 root
  159. * Restored version
  160. Revision 1.6 1998/01/26 11:58:09 michael
  161. + Added log at the end
  162. Working file: rtl/dos/ppi/ibm.ppi
  163. description:
  164. ----------------------------
  165. revision 1.5
  166. date: 1997/12/11 11:26:54; author: pierre; state: Exp; lines: +165 -165
  167. * forgot dtou !!
  168. ----------------------------
  169. revision 1.4
  170. date: 1997/12/11 11:24:19; author: pierre; state: Exp; lines: +165 -165
  171. * bug in string at line 103 corrected
  172. ----------------------------
  173. revision 1.3
  174. date: 1997/12/04 08:52:35; author: florian; state: Exp; lines: +4 -4
  175. + vesa mode 1280x1024x256 added
  176. ----------------------------
  177. revision 1.2
  178. date: 1997/12/01 12:21:30; author: michael; state: Exp; lines: +13 -1
  179. + added copyright reference in header.
  180. ----------------------------
  181. revision 1.1
  182. date: 1997/11/27 08:33:51; author: michael; state: Exp;
  183. Initial revision
  184. ----------------------------
  185. revision 1.1.1.1
  186. date: 1997/11/27 08:33:51; author: michael; state: Exp; lines: +0 -0
  187. FPC RTL CVS start
  188. =============================================================================
  189. }