vesa.inc 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Carl Eric Codere
  5. This include implements VESA basic access.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. type
  13. palrec = packed record { record used for set/get DAC palette }
  14. blue, green, red, align: byte;
  15. end;
  16. const
  17. { VESA attributes }
  18. attrSwitchDAC = $01; { DAC is switchable (1.2) }
  19. attrNotVGACompatible = $02; { Video is NOT VGA compatible (2.0) }
  20. attrSnowCheck = $04; { Video must use snow checking(2.0) }
  21. { mode attribute bits }
  22. modeAvail = $01; { Hardware supports this mode (1.0) }
  23. modeExtendInfo = $02; { Extended information (1.0) }
  24. modeBIOSSupport = $04; { TTY BIOS Support (1.0) }
  25. modeColor = $08; { This is a color mode (1.0) }
  26. modeGraphics = $10; { This is a graphics mode (1.0) }
  27. modeNotVGACompatible = $20; { this mode is NOT I/O VGA compatible (2.0)}
  28. modeNoWindowed = $40; { This mode does not support Windows (2.0) }
  29. modeLinearBuffer = $80; { This mode supports linear buffers (2.0) }
  30. { window attributes }
  31. winSupported = $01;
  32. winReadable = $02;
  33. winWritable = $04;
  34. { memory model }
  35. modelText = $00;
  36. modelCGA = $01;
  37. modelHerc = $02;
  38. model4plane = $03;
  39. modelPacked = $04;
  40. modelModeX = $05;
  41. modelRGB = $06;
  42. modelYUV = $07;
  43. {$ifndef dpmi}
  44. {$i vesah.inc}
  45. { otherwise it's already included in graph.pp }
  46. {$endif dpmi}
  47. var
  48. BytesPerLine: word; { Number of bytes per scanline }
  49. YOffset : word; { Pixel offset for VESA page flipping }
  50. { window management }
  51. ReadWindow : byte; { Window number for reading. }
  52. WriteWindow: byte; { Window number for writing. }
  53. winReadSeg : word; { Address of segment for read }
  54. winWriteSeg: word; { Address of segment for writes}
  55. CurrentReadBank : integer; { active read bank }
  56. CurrentWriteBank: integer; { active write bank }
  57. BankShift : word; { address to shift by when switching banks. }
  58. { linear mode specific stuff }
  59. InLinear : boolean; { true if in linear mode }
  60. LinearPageOfs : longint; { offset used to set active page }
  61. FrameBufferLinearAddress : longint;
  62. ScanLines: word; { maximum number of scan lines for mode }
  63. function hexstr(val : longint;cnt : byte) : string;
  64. const
  65. HexTbl : array[0..15] of char='0123456789ABCDEF';
  66. var
  67. i : longint;
  68. begin
  69. hexstr[0]:=char(cnt);
  70. for i:=cnt downto 1 do
  71. begin
  72. hexstr[i]:=hextbl[val and $f];
  73. val:=val shr 4;
  74. end;
  75. end;
  76. {$IFDEF DPMI}
  77. function getVESAInfo(var VESAInfo: TVESAInfo) : boolean;
  78. var
  79. ptrlong : longint;
  80. VESAPtr : ^TVESAInfo;
  81. st : string[4];
  82. regs : TDPMIRegisters;
  83. {$ifndef fpc}
  84. ModeSel: word;
  85. offs: longint;
  86. {$endif fpc}
  87. { added... }
  88. modelist: PmodeList;
  89. i: longint;
  90. RealSeg : word;
  91. begin
  92. { Allocate real mode buffer }
  93. {$ifndef fpc}
  94. Ptrlong:=GlobalDosAlloc(sizeof(TVESAInfo));
  95. { Get selector value }
  96. VESAPtr := pointer(Ptrlong shl 16);
  97. {$else fpc}
  98. Ptrlong:=Global_Dos_Alloc(sizeof(TVESAInfo));
  99. New(VESAPtr);
  100. {$endif fpc}
  101. { Get segment value }
  102. RealSeg := word(Ptrlong shr 16);
  103. if not assigned(VESAPtr) then
  104. RunError(203);
  105. FillChar(regs, sizeof(regs), #0);
  106. { Get VESA Mode information ... }
  107. regs.eax := $4f00;
  108. regs.es := RealSeg;
  109. regs.edi := $00;
  110. RealIntr($10, regs);
  111. {$ifdef fpc}
  112. { no far pointer support in FPC yet, so move the vesa info into a memory }
  113. { block in the DS slector space (JM) }
  114. dosmemget(RealSeg,0,VesaPtr^,SizeOf(TVESAInfo));
  115. {$endif fpc}
  116. St:=Vesaptr^.signature;
  117. if st<>'VESA' then
  118. begin
  119. {$ifdef logging}
  120. LogLn('No VESA detected.');
  121. {$endif logging}
  122. getVesaInfo := FALSE;
  123. {$ifndef fpc}
  124. GlobalDosFree(word(PtrLong and $ffff));
  125. {$else fpc}
  126. If not Global_Dos_Free(word(PtrLong and $ffff)) then
  127. RunError(216);
  128. { also free the extra allocated buffer }
  129. Dispose(VESAPtr);
  130. {$endif fpc}
  131. exit;
  132. end
  133. else
  134. getVesaInfo := TRUE;
  135. {$ifndef fpc}
  136. { The mode pointer buffer points to a real mode memory }
  137. { Therefore steps to get the modes: }
  138. { 1. Allocate Selector and SetLimit to max number of }
  139. { of possible modes. }
  140. ModeSel := AllocSelector(0);
  141. SetSelectorLimit(ModeSel, 256*sizeof(word));
  142. { 2. Set Selector linear address to the real mode pointer }
  143. { returned. }
  144. offs := longint(longint(VESAPtr^.ModeList) shr 16) shl 4;
  145. {shouldn't the OR in the next line be a + ?? (JM)}
  146. offs := offs OR (Longint(VESAPtr^.ModeList) and $ffff);
  147. SetSelectorBase(ModeSel, offs);
  148. { copy VESA mode information to a protected mode buffer and }
  149. { then free the real mode buffer... }
  150. Move(VESAPtr^, VESAInfo, sizeof(VESAInfo));
  151. GlobalDosFree(word(PtrLong and $ffff));
  152. { ModeList points to the mode list }
  153. { We must copy it somewhere... }
  154. ModeList := Ptr(ModeSel, 0);
  155. {$else fpc}
  156. { No far pointer support, so the Ptr(ModeSel, 0) doesn't work. }
  157. { Immediately copy everything to a buffer in the DS selector space }
  158. New(ModeList);
  159. { The following may copy data from outside the VESA buffer, but it }
  160. { shouldn't get past the 1MB limit, since that would mean the buffer }
  161. { has been allocated in the BIOS or high memory region, which seems }
  162. { impossible to me (JM)}
  163. DosMemGet(word(longint(VESAPtr^.ModeList) shr 16),
  164. word(longint(VESAPtr^.ModeList) and $ffff), ModeList^,256*sizeof(word));
  165. { copy VESA mode information to a protected mode buffer and }
  166. { then free the real mode buffer... }
  167. Move(VESAPtr^, VESAInfo, sizeof(VESAInfo));
  168. If not Global_Dos_Free(word(PtrLong and $ffff)) then
  169. RunError(216);
  170. Dispose(VESAPtr);
  171. {$endif fpc}
  172. i:=0;
  173. new(VESAInfo.ModeList);
  174. while ModeList^[i]<> $ffff do
  175. begin
  176. {$ifdef logging}
  177. LogLn('Found mode $'+hexstr(ModeList^[i],4));
  178. {$endif loggin}
  179. VESAInfo.ModeList^[i] := ModeList^[i];
  180. Inc(i);
  181. end;
  182. VESAInfo.ModeList^[i]:=$ffff;
  183. { Free the temporary selector used to get mode information }
  184. {$ifdef logging}
  185. LogLn(strf(i) + ' modes found.');
  186. {$endif logging}
  187. {$ifndef fpc}
  188. FreeSelector(ModeSel);
  189. {$else fpc}
  190. Dispose(ModeList);
  191. {$endif fpc}
  192. end;
  193. function getVESAModeInfo(var ModeInfo: TVESAModeInfo;mode:word):boolean;
  194. var
  195. Ptr: longint;
  196. {$ifndef fpc}
  197. VESAPtr : ^TVESAModeInfo;
  198. {$endif fpc}
  199. regs : TDPMIRegisters;
  200. RealSeg: word;
  201. begin
  202. { Alllocate real mode buffer }
  203. {$ifndef fpc}
  204. Ptr:=GlobalDosAlloc(sizeof(TVESAModeInfo));
  205. { get the selector value }
  206. VESAPtr := pointer(longint(Ptr shl 16));
  207. if not assigned(VESAPtr) then
  208. RunError(203);
  209. {$else fpc}
  210. Ptr:=Global_Dos_Alloc(sizeof(TVESAModeInfo));
  211. {$endif fpc}
  212. { get the segment value }
  213. RealSeg := word(Ptr shr 16);
  214. { setup interrupt registers }
  215. FillChar(regs, sizeof(regs), #0);
  216. { call VESA mode information...}
  217. regs.eax := $4f01;
  218. regs.es := RealSeg;
  219. regs.edi := $00;
  220. regs.ecx := mode;
  221. RealIntr($10, regs);
  222. if word(regs.eax) <> $4f then
  223. getVESAModeInfo := FALSE
  224. else
  225. getVESAModeInfo := TRUE;
  226. { copy to protected mode buffer ... }
  227. {$ifndef fpc}
  228. Move(VESAPtr^, ModeInfo, sizeof(ModeInfo));
  229. {$else fpc}
  230. DosMemGet(RealSeg,0,ModeInfo,sizeof(ModeInfo));
  231. {$endif fpc}
  232. { free real mode memory }
  233. {$ifndef fpc}
  234. GlobalDosFree(Word(Ptr and $ffff));
  235. {$else fpc}
  236. If not Global_Dos_Free(Word(Ptr and $ffff)) then
  237. RunError(216);
  238. {$endif fpc}
  239. end;
  240. {$ELSE}
  241. function getVESAInfo(var VESAInfo: TVESAInfo) : boolean; assembler;
  242. asm
  243. mov ax,4F00h
  244. les di,VESAInfo
  245. int 10h
  246. sub ax,004Fh {make sure we got 004Fh back}
  247. cmp ax,1
  248. sbb al,al
  249. cmp word ptr es:[di],'V'or('E'shl 8) {signature should be 'VESA'}
  250. jne @@ERR
  251. cmp word ptr es:[di+2],'S'or('A'shl 8)
  252. je @@X
  253. @@ERR:
  254. mov al,0
  255. @@X:
  256. end;
  257. function getVESAModeInfo(var ModeInfo: TVESAModeInfo;mode:word):boolean;assembler;
  258. asm
  259. mov ax,4F01h
  260. mov cx,mode
  261. les di,ModeInfo
  262. int 10h
  263. sub ax,004Fh {make sure it's 004Fh}
  264. cmp ax,1
  265. sbb al,al
  266. end;
  267. {$ENDIF}
  268. function SearchVESAModes(mode: Word): boolean;
  269. {********************************************************}
  270. { Searches for a specific DEFINED vesa mode. If the mode }
  271. { is not available for some reason, then returns FALSE }
  272. { otherwise returns TRUE. }
  273. {********************************************************}
  274. var
  275. i: word;
  276. ModeSupported : Boolean;
  277. begin
  278. i:=0;
  279. { let's assume it's not available ... }
  280. ModeSupported := FALSE;
  281. { This is a STUB VESA implementation }
  282. if VESAInfo.ModeList^[0] = $FFFF then exit;
  283. repeat
  284. if VESAInfo.ModeList^[i] = mode then
  285. begin
  286. { we found it, the card supports this mode... }
  287. ModeSupported := TRUE;
  288. break;
  289. end;
  290. Inc(i);
  291. until VESAInfo.ModeList^[i] = $ffff;
  292. { now check if the hardware supports it... }
  293. If ModeSupported then
  294. begin
  295. { we have to init everything to zero, since VBE < 1.1 }
  296. { may not setup fields correctly. }
  297. FillChar(VESAModeInfo, sizeof(VESAModeInfo), #0);
  298. If GetVESAModeInfo(VESAModeInfo, Mode) And
  299. ((VESAModeInfo.attr and modeAvail) <> 0) then
  300. ModeSupported := TRUE
  301. else
  302. ModeSupported := FALSE;
  303. end;
  304. SearchVESAModes := ModeSupported;
  305. end;
  306. procedure SetBankIndex(win: byte; BankNr: Integer); assembler;
  307. asm
  308. mov ax,4f05h
  309. mov bh,00h
  310. mov bl,[Win]
  311. mov dx,[BankNr]
  312. {$ifdef fpc}
  313. push ebp
  314. {$endif fpc}
  315. int 10h
  316. {$ifdef fpc}
  317. pop ebp
  318. {$endif fpc}
  319. end;
  320. {********************************************************}
  321. { There are two routines for setting banks. This may in }
  322. { in some cases optimize a bit some operations, if the }
  323. { hardware supports it, because one window is used for }
  324. { reading and one window is used for writing. }
  325. {********************************************************}
  326. procedure SetReadBank(BankNr: Integer);
  327. begin
  328. { check if this is the current bank... if so do nothing. }
  329. if BankNr = CurrentReadBank then exit;
  330. {$ifdef logging}
  331. { LogLn('Setting read bank to '+strf(BankNr));}
  332. {$endif logging}
  333. CurrentReadBank := BankNr; { save current bank number }
  334. BankNr := BankNr shl BankShift; { adjust to window granularity }
  335. { we set both banks, since one may read only }
  336. SetBankIndex(ReadWindow, BankNr);
  337. { if the hardware supports only one window }
  338. { then there is only one single bank, so }
  339. { update both bank numbers. }
  340. if ReadWindow = WriteWindow then
  341. CurrentWriteBank := CurrentReadBank;
  342. end;
  343. procedure SetWriteBank(BankNr: Integer);
  344. begin
  345. { check if this is the current bank... if so do nothing. }
  346. if BankNr = CurrentWriteBank then exit;
  347. {$ifdef logging}
  348. { LogLn('Setting write bank to '+strf(BankNr));}
  349. {$endif logging}
  350. CurrentWriteBank := BankNr; { save current bank number }
  351. BankNr := BankNr shl BankShift; { adjust to window granularity }
  352. { we set both banks, since one may read only }
  353. SetBankIndex(WriteWindow, BankNr);
  354. { if the hardware supports only one window }
  355. { then there is only one single bank, so }
  356. { update both bank numbers. }
  357. if ReadWindow = WriteWindow then
  358. CurrentReadBank := CurrentWriteBank;
  359. end;
  360. {************************************************************************}
  361. {* 8-bit pixels VESA mode routines *}
  362. {************************************************************************}
  363. procedure PutPixVESA256(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  364. var
  365. offs : longint;
  366. begin
  367. X:= X + StartXViewPort;
  368. Y:= Y + StartYViewPort;
  369. { convert to absolute coordinates and then verify clipping...}
  370. if ClipPixels then
  371. Begin
  372. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  373. exit;
  374. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  375. exit;
  376. end;
  377. Y := Y + YOffset; { adjust pixel for correct virtual page }
  378. offs := longint(y) * BytesPerLine + x;
  379. begin
  380. SetWriteBank(integer(offs shr 16));
  381. mem[WinWriteSeg : word(offs)] := byte(color);
  382. end;
  383. end;
  384. procedure DirectPutPixVESA256(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  385. var
  386. offs : longint;
  387. col : byte;
  388. begin
  389. offs := (longint(y) + YOffset) * BytesPerLine + x;
  390. Case CurrentWriteMode of
  391. XorPut:
  392. Begin
  393. SetReadBank(integer(offs shr 16));
  394. col := mem[WinReadSeg : word(offs)] xor byte(CurrentColor);
  395. End;
  396. AndPut:
  397. Begin
  398. SetReadBank(integer(offs shr 16));
  399. col := mem[WinReadSeg : word(offs)] And byte(CurrentColor);
  400. End;
  401. OrPut:
  402. Begin
  403. SetReadBank(integer(offs shr 16));
  404. col := mem[WinReadSeg : word(offs)] or byte(currentcolor);
  405. End
  406. else
  407. Begin
  408. If CurrentWriteMode <> NotPut then
  409. col := Byte(CurrentColor)
  410. else col := Not(Byte(CurrentColor));
  411. End
  412. End;
  413. SetWriteBank(integer(offs shr 16));
  414. mem[WinWriteSeg : word(offs)] := Col;
  415. end;
  416. function GetPixVESA256(x, y : integer): word; {$ifndef fpc}far;{$endif fpc}
  417. var
  418. offs : longint;
  419. begin
  420. X:= X + StartXViewPort;
  421. Y:= Y + StartYViewPort + YOffset;
  422. offs := longint(y) * BytesPerLine + x;
  423. SetReadBank(integer(offs shr 16));
  424. GetPixVESA256:=mem[WinReadSeg : word(offs)];
  425. end;
  426. Procedure GetScanLineVESA256(x1, x2, y: integer; var data); {$ifndef fpc}far;{$endif}
  427. var offs: Longint;
  428. l, amount, bankrest, index, pixels: longint;
  429. curbank: integer;
  430. begin
  431. inc(x1,StartXViewPort);
  432. inc(x2,StartXViewPort);
  433. {$ifdef logging}
  434. LogLn('getscanline256 '+strf(x1)+' - '+strf(x2)+' at '+strf(y+StartYViewPort));
  435. {$endif logging}
  436. index := 0;
  437. amount := x2-x1+1;
  438. Offs:=(Longint(y)+StartYViewPort+YOffset)*bytesperline+x1;
  439. Repeat
  440. curbank := integer(offs shr 16);
  441. SetReadBank(curbank);
  442. {$ifdef logging}
  443. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  444. {$endif logging}
  445. If ((amount >= 4) and
  446. ((offs and 3) = 0)) or
  447. (amount >= 4+4-(offs and 3)) Then
  448. { allign target }
  449. Begin
  450. If (offs and 3) <> 0 then
  451. { this cannot go past a window boundary bacause the }
  452. { size of a window is always a multiple of 4 }
  453. Begin
  454. {$ifdef logging}
  455. LogLn('Alligning by reading '+strf(4-(offs and 3))+' pixels');
  456. {$endif logging}
  457. for l := 1 to 4-(offs and 3) do
  458. WordArray(Data)[index+l-1] :=
  459. Mem[WinReadSeg:word(offs)+l-1];
  460. inc(index, l);
  461. inc(offs, l);
  462. dec(amount, l);
  463. End;
  464. {$ifdef logging}
  465. LogLn('Offset is now '+hexstr(offs,8)+', amount left: '+strf(amount));
  466. {$endif logging}
  467. { offs is now 4-bytes alligned }
  468. If amount <= ($10000-(Offs and $ffff)) Then
  469. bankrest := amount
  470. else {the rest won't fit anymore in the current window }
  471. bankrest := $10000 - (Offs and $ffff);
  472. { it is possible that by aligning, we ended up in a new }
  473. { bank, so set the correct bank again to make sure }
  474. setreadbank(offs shr 16);
  475. {$ifdef logging}
  476. LogLn('Rest to be read from this window: '+strf(bankrest));
  477. {$endif logging}
  478. For l := 0 to (Bankrest div 4)-1 Do
  479. begin
  480. pixels := MemL[WinWriteSeg:word(offs)+l*4];
  481. WordArray(Data)[index+l*4] := pixels and $ff;
  482. pixels := pixels shr 8;
  483. WordArray(Data)[index+l*4+1] := pixels and $ff;
  484. pixels := pixels shr 8;
  485. WordArray(Data)[index+l*4+2] := pixels and $ff;
  486. pixels := pixels shr 8;
  487. WordArray(Data)[index+l*4+3] := pixels{ and $ff};
  488. end;
  489. inc(index,l*4+4);
  490. inc(offs,l*4+4);
  491. dec(amount,l*4+4);
  492. {$ifdef logging}
  493. LogLn('Offset is now '+hexstr(offs,8)+', amount left: '+strf(amount));
  494. {$endif logging}
  495. End
  496. Else
  497. Begin
  498. {$ifdef logging}
  499. LogLn('Leftover: '+strf(amount)+' at offset '+hexstr(offs,8));
  500. {$endif logging}
  501. For l := 0 to amount - 1 do
  502. begin
  503. { this may cross a bank at any time, so adjust }
  504. { because this loop alwys runs for very little pixels, }
  505. { there's little gained by splitting it up }
  506. setreadbank(offs shr 16);
  507. WordArray(Data)[index+l] := mem[WinReadSeg:word(offs)];
  508. inc(offs);
  509. end;
  510. amount := 0
  511. End
  512. Until amount = 0;
  513. end;
  514. procedure HLineVESA256(x,x2,y: integer); {$ifndef fpc}far;{$endif fpc}
  515. var Offs: Longint;
  516. mask, l, bankrest: longint;
  517. curbank, hlength: integer;
  518. Begin
  519. { must we swap the values? }
  520. if x > x2 then
  521. Begin
  522. x := x xor x2;
  523. x2 := x xor x2;
  524. x:= x xor x2;
  525. end;
  526. { First convert to global coordinates }
  527. X := X + StartXViewPort;
  528. X2 := X2 + StartXViewPort;
  529. Y := Y + StartYViewPort;
  530. if ClipPixels then
  531. Begin
  532. if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
  533. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  534. exit;
  535. end;
  536. {$ifdef logging2}
  537. LogLn('hline '+strf(x)+' - '+strf(x2)+' on '+strf(y)+' in mode '+strf(currentwritemode));
  538. {$endif logging2}
  539. HLength := x2 - x + 1;
  540. {$ifdef logging2}
  541. LogLn('length: '+strf(hlength));
  542. {$endif logging2}
  543. if HLength>0 then
  544. begin
  545. Offs:=(Longint(y)+YOffset)*bytesperline+x;
  546. {$ifdef logging2}
  547. LogLn('Offs: '+strf(offs)+' -- '+hexstr(offs,8));
  548. {$endif logging2}
  549. Mask := byte(CurrentColor)+byte(CurrentColor) shl 8;
  550. Mask := Mask + Mask shl 16;
  551. Case CurrentWriteMode of
  552. AndPut:
  553. Begin
  554. Repeat
  555. curbank := integer(offs shr 16);
  556. SetWriteBank(curbank);
  557. SetReadBank(curbank);
  558. {$ifdef logging2}
  559. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  560. {$endif logging2}
  561. If ((HLength >= 4) and
  562. ((offs and 3) = 0)) or
  563. (HLength >= 4+4-(offs and 3)) Then
  564. { align target }
  565. Begin
  566. l := 0;
  567. If (offs and 3) <> 0 then
  568. { this cannot go past a window boundary bacause the }
  569. { size of a window is always a multiple of 4 }
  570. Begin
  571. {$ifdef logging2}
  572. LogLn('Alligning by drawing '+strf(4-(offs and 3))+' pixels');
  573. {$endif logging2}
  574. for l := 1 to 4-(offs and 3) do
  575. Mem[WinWriteSeg:word(offs)+l-1] :=
  576. Mem[WinReadSeg:word(offs)+l-1] And Byte(CurrentColor);
  577. End;
  578. Dec(HLength, l);
  579. inc(offs, l);
  580. {$ifdef logging2}
  581. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  582. {$endif logging}
  583. { offs is now 4-bytes alligned }
  584. If HLength <= ($10000-(Offs and $ffff)) Then
  585. bankrest := HLength
  586. else {the rest won't fit anymore in the current window }
  587. bankrest := $10000 - (Offs and $ffff);
  588. { it is possible that by aligningm we ended up in a new }
  589. { bank, so set the correct bank again to make sure }
  590. setwritebank(offs shr 16);
  591. setreadbank(offs shr 16);
  592. {$ifdef logging2}
  593. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  594. {$endif logging}
  595. For l := 0 to (Bankrest div 4)-1 Do
  596. MemL[WinWriteSeg:word(offs)+l*4] :=
  597. MemL[WinReadSeg:word(offs)+l*4] And Mask;
  598. inc(offs,l*4+4);
  599. dec(hlength,l*4+4);
  600. {$ifdef logging2}
  601. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  602. {$endif logging}
  603. End
  604. Else
  605. Begin
  606. {$ifdef logging2}
  607. LogLn('Drawing leftover: '+strf(HLength)+' at offset '+hexstr(offs,8));
  608. {$endif logging}
  609. For l := 0 to HLength - 1 do
  610. begin
  611. { this may cross a bank at any time, so adjust }
  612. { becauese this loop alwys runs for very little pixels, }
  613. { there's little gained by splitting it up }
  614. setreadbank(offs shr 16);
  615. setwritebank(offs shr 16);
  616. Mem[WinWriteSeg:word(offs)] :=
  617. Mem[WinReadSeg:word(offs)] And byte(currentColor);
  618. inc(offs);
  619. end;
  620. HLength := 0
  621. End
  622. Until HLength = 0;
  623. End;
  624. XorPut:
  625. Begin
  626. Repeat
  627. curbank := integer(offs shr 16);
  628. SetWriteBank(curbank);
  629. SetReadBank(curbank);
  630. {$ifdef logging2}
  631. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  632. {$endif logging}
  633. If ((HLength >= 4) and
  634. ((offs and 3) = 0)) or
  635. (HLength >= 4+4-(offs and 3)) Then
  636. { allign target }
  637. Begin
  638. l := 0;
  639. If (offs and 3) <> 0 then
  640. { this cannot go past a window boundary bacause the }
  641. { size of a window is always a multiple of 4 }
  642. Begin
  643. {$ifdef logging2}
  644. LogLn('Alligning by drawing '+strf(4-(offs and 3))+' pixels');
  645. {$endif logging}
  646. for l := 1 to 4-(offs and 3) do
  647. Mem[WinWriteSeg:word(offs)+l-1] :=
  648. Mem[WinReadSeg:word(offs)+l-1] Xor Byte(CurrentColor);
  649. End;
  650. Dec(HLength, l);
  651. inc(offs, l);
  652. {$ifdef logging2}
  653. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  654. {$endif logging}
  655. { offs is now 4-bytes alligned }
  656. If HLength <= ($10000-(Offs and $ffff)) Then
  657. bankrest := HLength
  658. else {the rest won't fit anymore in the current window }
  659. bankrest := $10000 - (Offs and $ffff);
  660. { it is possible that by aligningm we ended up in a new }
  661. { bank, so set the correct bank again to make sure }
  662. setwritebank(offs shr 16);
  663. setreadbank(offs shr 16);
  664. {$ifdef logging2}
  665. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  666. {$endif logging}
  667. For l := 0 to (Bankrest div 4)-1 Do
  668. MemL[WinWriteSeg:word(offs)+l*4] :=
  669. MemL[WinReadSeg:word(offs)+l*4] Xor Mask;
  670. inc(offs,l*4+4);
  671. dec(hlength,l*4+4);
  672. {$ifdef logging2}
  673. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  674. {$endif logging}
  675. End
  676. Else
  677. Begin
  678. {$ifdef logging2}
  679. LogLn('Drawing leftover: '+strf(HLength)+' at offset '+hexstr(offs,8));
  680. {$endif logging}
  681. For l := 0 to HLength - 1 do
  682. begin
  683. { this may cross a bank at any time, so adjust }
  684. { because this loop alwys runs for very little pixels, }
  685. { there's little gained by splitting it up }
  686. setreadbank(offs shr 16);
  687. setwritebank(offs shr 16);
  688. Mem[WinWriteSeg:word(offs)] :=
  689. Mem[WinReadSeg:word(offs)] xor byte(currentColor);
  690. inc(offs);
  691. end;
  692. HLength := 0
  693. End
  694. Until HLength = 0;
  695. End;
  696. OrPut:
  697. Begin
  698. Repeat
  699. curbank := integer(offs shr 16);
  700. SetWriteBank(curbank);
  701. SetReadBank(curbank);
  702. {$ifdef logging2}
  703. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  704. {$endif logging}
  705. If ((HLength >= 4) and
  706. ((offs and 3) = 0)) or
  707. (HLength >= 4+4-(offs and 3)) Then
  708. { allign target }
  709. Begin
  710. l := 0;
  711. If (offs and 3) <> 0 then
  712. { this cannot go past a window boundary bacause the }
  713. { size of a window is always a multiple of 4 }
  714. Begin
  715. {$ifdef logging2}
  716. LogLn('Alligning by drawing '+strf(4-(offs and 3))+' pixels');
  717. {$endif logging}
  718. for l := 1 to 4-(offs and 3) do
  719. Mem[WinWriteSeg:word(offs)+l-1] :=
  720. Mem[WinReadSeg:word(offs)+l-1] Or Byte(CurrentColor);
  721. End;
  722. Dec(HLength, l);
  723. inc(offs, l);
  724. { it is possible that by aligningm we ended up in a new }
  725. { bank, so set the correct bank again to make sure }
  726. setwritebank(offs shr 16);
  727. setreadbank(offs shr 16);
  728. {$ifdef logging2}
  729. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  730. {$endif logging}
  731. { offs is now 4-bytes alligned }
  732. If HLength <= ($10000-(Offs and $ffff)) Then
  733. bankrest := HLength
  734. else {the rest won't fit anymore in the current window }
  735. bankrest := $10000 - (Offs and $ffff);
  736. {$ifdef logging2}
  737. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  738. {$endif logging}
  739. For l := 0 to (Bankrest div 4)-1 Do
  740. MemL[WinWriteSeg:offs+l*4] :=
  741. MemL[WinReadSeg:word(offs)+l*4] Or Mask;
  742. inc(offs,l*4+4);
  743. dec(hlength,l*4+4);
  744. {$ifdef logging2}
  745. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  746. {$endif logging}
  747. End
  748. Else
  749. Begin
  750. {$ifdef logging2}
  751. LogLn('Drawing leftover: '+strf(HLength)+' at offset '+hexstr(offs,8));
  752. {$endif logging}
  753. For l := 0 to HLength - 1 do
  754. begin
  755. { this may cross a bank at any time, so adjust }
  756. { because this loop alwys runs for very little pixels, }
  757. { there's little gained by splitting it up }
  758. setreadbank(offs shr 16);
  759. setwritebank(offs shr 16);
  760. Mem[WinWriteSeg:word(offs)] :=
  761. Mem[WinReadSeg:word(offs)] And byte(currentColor);
  762. inc(offs);
  763. end;
  764. HLength := 0
  765. End
  766. Until HLength = 0;
  767. End
  768. Else
  769. Begin
  770. If CurrentWriteMode = NotPut Then
  771. Mask := Not(Mask);
  772. Repeat
  773. curbank := integer(offs shr 16);
  774. SetWriteBank(curbank);
  775. {$ifdef logging2}
  776. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8)+' -- '+strf(offs));
  777. {$endif logging}
  778. If ((HLength >= 4) and
  779. ((offs and 3) = 0)) or
  780. (HLength >= 4+4-(offs and 3)) Then
  781. { allign target }
  782. Begin
  783. l := 0;
  784. If (offs and 3) <> 0 then
  785. { this cannot go past a window boundary bacause the }
  786. { size of a window is always a multiple of 4 }
  787. Begin
  788. {$ifdef logging2}
  789. LogLn('Alligning by drawing '+strf(4-(offs and 3))+' pixels');
  790. {$endif logging}
  791. for l := 1 to 4-(offs and 3) do
  792. Mem[WinWriteSeg:word(offs)+l-1] := Byte(Mask);
  793. End;
  794. Dec(HLength, l);
  795. inc(offs, l);
  796. {$ifdef logging2}
  797. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  798. {$endif logging}
  799. { offs is now 4-bytes alligned }
  800. If HLength <= ($10000-(Offs and $ffff)) Then
  801. bankrest := HLength
  802. else {the rest won't fit anymore in the current window }
  803. bankrest := $10000 - (Offs and $ffff);
  804. { it is possible that by aligningm we ended up in a new }
  805. { bank, so set the correct bank again to make sure }
  806. setwritebank(offs shr 16);
  807. {$ifdef logging2}
  808. LogLn('Rest to be drawn in this window: '+strf(bankrest)+' -- '+hexstr(bankrest,8));
  809. {$endif logging}
  810. For l := 0 to (Bankrest div 4)-1 Do
  811. MemL[WinWriteSeg:word(offs)+l*4] := Mask;
  812. inc(offs,l*4+4);
  813. dec(hlength,l*4+4);
  814. {$ifdef logging2}
  815. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(hlength));
  816. {$endif logging}
  817. End
  818. Else
  819. Begin
  820. {$ifdef logging2}
  821. LogLn('Drawing leftover: '+strf(HLength)+' at offset '+hexstr(offs,8));
  822. {$endif logging}
  823. For l := 0 to HLength - 1 do
  824. begin
  825. { this may cross a bank at any time, so adjust }
  826. { because this loop alwys runs for very little pixels, }
  827. { there's little gained by splitting it up }
  828. setwritebank(offs shr 16);
  829. Mem[WinWriteSeg:word(offs)] := byte(mask);
  830. inc(offs);
  831. end;
  832. HLength := 0
  833. End
  834. Until HLength = 0;
  835. End;
  836. End;
  837. end;
  838. end;
  839. procedure VLineVESA256(x,y,y2: integer); {$ifndef fpc}far;{$endif fpc}
  840. var Offs: Longint;
  841. l, bankrest: longint;
  842. curbank, vlength: integer;
  843. col: byte;
  844. Begin
  845. { must we swap the values? }
  846. if y > y2 then
  847. Begin
  848. y := y xor y2;
  849. y2 := y xor y2;
  850. y:= y xor y2;
  851. end;
  852. { First convert to global coordinates }
  853. X := X + StartXViewPort;
  854. Y := Y + StartYViewPort;
  855. Y2 := Y2 + StartYViewPort;
  856. if ClipPixels then
  857. Begin
  858. if LineClipped(x,y,x,y2,StartXViewPort,StartYViewPort,
  859. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  860. exit;
  861. end;
  862. Col := Byte(CurrentColor);
  863. {$ifdef logging2}
  864. LogLn('vline '+strf(y)+' - '+strf(y2)+' on '+strf(x)+' in mode '+strf(currentwritemode));
  865. {$endif logging}
  866. VLength := y2 - y + 1;
  867. {$ifdef logging2}
  868. LogLn('length: '+strf(vlength));
  869. {$endif logging}
  870. if VLength>0 then
  871. begin
  872. Offs:=(Longint(y)+YOffset)*bytesperline+x;
  873. {$ifdef logging2}
  874. LogLn('Offs: '+strf(offs)+' -- '+hexstr(offs,8));
  875. {$endif logging}
  876. Case CurrentWriteMode of
  877. AndPut:
  878. Begin
  879. Repeat
  880. curbank := integer(offs shr 16);
  881. SetWriteBank(curbank);
  882. SetReadBank(curbank);
  883. {$ifdef logging2}
  884. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  885. {$endif logging}
  886. If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
  887. bankrest := VLength
  888. else {the rest won't fit anymore in the current window }
  889. bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
  890. {$ifdef logging2}
  891. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  892. {$endif logging}
  893. For l := 0 to Bankrest-1 Do
  894. begin
  895. Mem[WinWriteSeg:word(offs)] :=
  896. Mem[WinReadSeg:word(offs)] And Col;
  897. inc(offs,bytesperline);
  898. end;
  899. dec(VLength,l+1);
  900. {$ifdef logging2}
  901. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(vlength));
  902. {$endif logging}
  903. Until VLength = 0;
  904. End;
  905. XorPut:
  906. Begin
  907. Repeat
  908. curbank := integer(offs shr 16);
  909. SetWriteBank(curbank);
  910. SetReadBank(curbank);
  911. {$ifdef logging2}
  912. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  913. {$endif logging}
  914. If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
  915. bankrest := VLength
  916. else {the rest won't fit anymore in the current window }
  917. bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
  918. {$ifdef logging2}
  919. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  920. {$endif logging}
  921. For l := 0 to Bankrest-1 Do
  922. begin
  923. Mem[WinWriteSeg:word(offs)] :=
  924. Mem[WinReadSeg:word(offs)] Xor Col;
  925. inc(offs,bytesperline);
  926. end;
  927. dec(VLength,l+1);
  928. {$ifdef logging2}
  929. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(vlength));
  930. {$endif logging}
  931. Until VLength = 0;
  932. End;
  933. OrPut:
  934. Begin
  935. Repeat
  936. curbank := integer(offs shr 16);
  937. SetWriteBank(curbank);
  938. SetReadBank(curbank);
  939. {$ifdef logging2}
  940. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  941. {$endif logging}
  942. If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
  943. bankrest := VLength
  944. else {the rest won't fit anymore in the current window }
  945. bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
  946. {$ifdef logging2}
  947. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  948. {$endif logging}
  949. For l := 0 to Bankrest-1 Do
  950. begin
  951. Mem[WinWriteSeg:word(offs)] :=
  952. Mem[WinReadSeg:word(offs)] Or Col;
  953. inc(offs,bytesperline);
  954. end;
  955. dec(VLength,l+1);
  956. {$ifdef logging2}
  957. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(vlength));
  958. {$endif logging}
  959. Until VLength = 0;
  960. End;
  961. Else
  962. Begin
  963. If CurrentWriteMode = NotPut Then
  964. Col := Not(Col);
  965. Repeat
  966. curbank := integer(offs shr 16);
  967. SetWriteBank(curbank);
  968. {$ifdef logging2}
  969. LogLn('set bank '+strf(curbank)+' for offset '+hexstr(offs,8));
  970. {$endif logging}
  971. If (VLength-1)*bytesperline <= ($10000-(Offs and $ffff)) Then
  972. bankrest := VLength
  973. else {the rest won't fit anymore in the current window }
  974. bankrest := (($10000 - (Offs and $ffff)) div bytesperline)+1;
  975. {$ifdef logging2}
  976. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  977. {$endif logging}
  978. For l := 0 to Bankrest-1 Do
  979. begin
  980. Mem[WinWriteSeg:word(offs)] := Col;
  981. inc(offs,bytesperline);
  982. end;
  983. dec(VLength,l+1);
  984. {$ifdef logging2}
  985. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(vlength));
  986. {$endif logging}
  987. Until VLength = 0;
  988. End;
  989. End;
  990. end;
  991. end;
  992. procedure PatternLineVESA256(x1,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  993. {********************************************************}
  994. { Draws a horizontal patterned line according to the }
  995. { current Fill Settings. }
  996. {********************************************************}
  997. { Important notes: }
  998. { - CurrentColor must be set correctly before entering }
  999. { this routine. }
  1000. {********************************************************}
  1001. type
  1002. TVESA256Fill = Record
  1003. case byte of
  1004. 0: (data1, data2: longint);
  1005. 1: (pat: array[0..7] of byte);
  1006. end;
  1007. var
  1008. fill: TVESA256Fill;
  1009. bankrest, l : longint;
  1010. offs, amount: longint;
  1011. i : smallint;
  1012. j : smallint;
  1013. OldWriteMode : word;
  1014. TmpFillPattern, patternPos : byte;
  1015. begin
  1016. { convert to global coordinates ... }
  1017. x1 := x1 + StartXViewPort;
  1018. x2 := x2 + StartXViewPort;
  1019. y := y + StartYViewPort;
  1020. { if line was fully clipped then exit...}
  1021. if LineClipped(x1,y,x2,y,StartXViewPort,StartYViewPort,
  1022. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  1023. exit;
  1024. OldWriteMode := CurrentWriteMode;
  1025. CurrentWriteMode := NormalPut;
  1026. { Get the current pattern }
  1027. TmpFillPattern := FillPatternTable
  1028. [FillSettings.Pattern][((y + startYViewPort) and $7)+1];
  1029. {$ifdef logging2}
  1030. LogLn('patternline '+strf(x1)+' - '+strf(x2)+' on '+strf(y));
  1031. {$endif logging2}
  1032. { how long is the line }
  1033. amount := x2 - x1 + 1;
  1034. { offset to start at }
  1035. offs := (longint(y)+yoffset)*bytesperline+x1;
  1036. { convert the pattern data into the actual color sequence }
  1037. j := 1;
  1038. FillChar(fill,sizeOf(fill),byte(currentBkColor));
  1039. for i := 0 to 7 do
  1040. begin
  1041. if TmpFillPattern and j <> 0 then
  1042. fill.pat[7-i] := currentColor;
  1043. {$ifopt q+}
  1044. {$q-}
  1045. {$define overflowOn}
  1046. {$endif}
  1047. j := j shl 1;
  1048. {$ifdef overflowOn}
  1049. {$q+}
  1050. {$undef overflowOn}
  1051. {$endif}
  1052. end;
  1053. Repeat
  1054. SetWriteBank(integer(offs shr 16));
  1055. If (amount > 7) and
  1056. (((offs and 7) = 0) or
  1057. (amount > 7+8-(offs and 7))) Then
  1058. Begin
  1059. { align target }
  1060. l := 0;
  1061. If (offs and 7) <> 0 then
  1062. { this cannot go past a window boundary bacause the }
  1063. { size of a window is always a multiple of 8 }
  1064. Begin
  1065. { position in the pattern where to start }
  1066. patternPos := offs and 7;
  1067. {$ifdef logging2}
  1068. LogLn('Aligning by drawing '+strf(8-(offs and 7))+' pixels');
  1069. {$endif logging2}
  1070. for l := 1 to 8-(offs and 7) do
  1071. begin
  1072. Mem[WinWriteSeg:word(offs)+l-1] := fill.pat[patternPos and 7];
  1073. inc(patternPos)
  1074. end;
  1075. End;
  1076. Dec(amount, l);
  1077. inc(offs, l);
  1078. {$ifdef logging2}
  1079. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(amount));
  1080. {$endif logging2}
  1081. { offs is now 8-bytes alligned }
  1082. If amount <= ($10000-(Offs and $ffff)) Then
  1083. bankrest := amount
  1084. else {the rest won't fit anymore in the current window }
  1085. bankrest := $10000 - (Offs and $ffff);
  1086. { it is possible that by aligningm we ended up in a new }
  1087. { bank, so set the correct bank again to make sure }
  1088. setwritebank(offs shr 16);
  1089. {$ifdef logging2}
  1090. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  1091. {$endif logging2}
  1092. for l := 0 to (bankrest div 8)-1 Do
  1093. begin
  1094. MemL[WinWriteSeg:word(offs)+l*8] := fill.data1;
  1095. MemL[WinWriteSeg:word(offs)+l*8+4] := fill.data2;
  1096. end;
  1097. inc(offs,l*8+8);
  1098. dec(amount,l*8+8);
  1099. {$ifdef logging2}
  1100. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(amount));
  1101. {$endif logging2}
  1102. End
  1103. Else
  1104. Begin
  1105. {$ifdef logging2}
  1106. LogLn('Drawing leftover: '+strf(amount)+' at offset '+hexstr(offs,8));
  1107. {$endif logging2}
  1108. patternPos := offs and 7;
  1109. For l := 0 to amount - 1 do
  1110. begin
  1111. { this may cross a bank at any time, so adjust }
  1112. { because this loop alwys runs for very little pixels, }
  1113. { there's little gained by splitting it up }
  1114. setwritebank(offs shr 16);
  1115. Mem[WinWriteSeg:word(offs)] := fill.pat[patternPos and 7];
  1116. inc(offs);
  1117. inc(patternPos);
  1118. end;
  1119. amount := 0;
  1120. End
  1121. Until amount = 0;
  1122. currentWriteMode := oldWriteMode;
  1123. end;
  1124. {************************************************************************}
  1125. {* 256 colors VESA mode routines Linear mode *}
  1126. {************************************************************************}
  1127. {$ifdef FPC}
  1128. type
  1129. pbyte = ^byte;
  1130. pword = ^word;
  1131. procedure DirectPutPixVESA256Linear(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1132. var
  1133. offs : longint;
  1134. col : byte;
  1135. begin
  1136. offs := longint(y) * BytesPerLine + x;
  1137. Case CurrentWriteMode of
  1138. XorPut:
  1139. Begin
  1140. if UseNoSelector then
  1141. col:=pbyte(LFBPointer+offs+LinearPageOfs)^
  1142. else
  1143. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1144. col := col xor byte(CurrentColor);
  1145. End;
  1146. AndPut:
  1147. Begin
  1148. if UseNoSelector then
  1149. col:=pbyte(LFBPointer+offs+LinearPageOfs)^
  1150. else
  1151. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1152. col := col and byte(CurrentColor);
  1153. End;
  1154. OrPut:
  1155. Begin
  1156. if UseNoSelector then
  1157. col:=pbyte(LFBPointer+offs+LinearPageOfs)^
  1158. else
  1159. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1160. col := col or byte(CurrentColor);
  1161. End
  1162. else
  1163. Begin
  1164. If CurrentWriteMode <> NotPut then
  1165. col := Byte(CurrentColor)
  1166. else col := Not(Byte(CurrentColor));
  1167. End
  1168. End;
  1169. if UseNoSelector then
  1170. pbyte(LFBPointer+offs+LinearPageOfs)^:=col
  1171. else
  1172. seg_move(get_ds,longint(@col),WinWriteSeg,offs+LinearPageOfs,1);
  1173. end;
  1174. procedure PutPixVESA256Linear(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1175. var
  1176. offs : longint;
  1177. begin
  1178. X:= X + StartXViewPort;
  1179. Y:= Y + StartYViewPort;
  1180. { convert to absolute coordinates and then verify clipping...}
  1181. if ClipPixels then
  1182. Begin
  1183. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1184. exit;
  1185. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1186. exit;
  1187. end;
  1188. offs := longint(y) * BytesPerLine + x;
  1189. {$ifdef logging}
  1190. logln('putpix offset: '+hexstr(offs,8)+', color: '+strf(color)+', lpo: $'+
  1191. hexstr(LinearPageOfs,8));
  1192. {$endif logging}
  1193. if UseNoSelector then
  1194. pbyte(LFBPointer+offs+LinearPageOfs)^:=byte(color)
  1195. else
  1196. seg_move(get_ds,longint(@color),WinWriteSeg,offs+LinearPageOfs,1);
  1197. end;
  1198. function GetPixVESA256Linear(x, y : integer): word; {$ifndef fpc}far;{$endif fpc}
  1199. var
  1200. offs : longint;
  1201. col : byte;
  1202. begin
  1203. X:= X + StartXViewPort;
  1204. Y:= Y + StartYViewPort;
  1205. offs := longint(y) * BytesPerLine + x;
  1206. {$ifdef logging}
  1207. logln('getpix offset: '+hexstr(offs,8)+', lpo: $'+
  1208. hexstr(LinearPageOfs,8));
  1209. {$endif logging}
  1210. if UseNoSelector then
  1211. col:=pbyte(LFBPointer+offs+LinearPageOfs)^
  1212. else
  1213. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1214. GetPixVESA256Linear:=col;
  1215. end;
  1216. (*
  1217. function SetVESADisplayStart(PageNum : word;x,y : integer):Boolean;
  1218. var
  1219. dregs : registers;
  1220. begin
  1221. if PageNum>VesaModeInfo.NumberOfPages then
  1222. PageNum:=0;
  1223. {$ifdef DEBUG}
  1224. if PageNum>0 then
  1225. writeln(stderr,'Setting Display Page ',PageNum);
  1226. {$endif DEBUG}
  1227. dregs.RealEBX:=0{ $80 for Wait for retrace };
  1228. dregs.RealECX:=x;
  1229. dregs.RealEDX:=y+PageNum*maxy;
  1230. dregs.RealSP:=0;
  1231. dregs.RealSS:=0;
  1232. dregs.RealEAX:=$4F07; RealIntr($10,dregs);
  1233. { idem as above !!! }
  1234. if (dregs.RealEAX and $1FF) <> $4F then
  1235. begin
  1236. {$ifdef DEBUG}
  1237. writeln(stderr,'Set Display start error');
  1238. {$endif DEBUG}
  1239. SetVESADisplayStart:=false;
  1240. end
  1241. else
  1242. SetVESADisplayStart:=true;
  1243. end;
  1244. *)
  1245. {$endif FPC}
  1246. {************************************************************************}
  1247. {* 15/16bit pixels VESA mode routines *}
  1248. {************************************************************************}
  1249. procedure PutPixVESA32kOr64k(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1250. var
  1251. offs : longint;
  1252. begin
  1253. {$ifdef logging}
  1254. logln('putpixvesa32kor64k('+strf(x)+','+strf(y)+')');
  1255. {$endif logging}
  1256. X:= X + StartXViewPort;
  1257. Y:= Y + StartYViewPort;
  1258. { convert to absolute coordinates and then verify clipping...}
  1259. if ClipPixels then
  1260. Begin
  1261. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1262. exit;
  1263. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1264. exit;
  1265. end;
  1266. Y := Y + YOffset; { adjust pixel for correct virtual page }
  1267. offs := longint(y) * BytesPerLine + 2*x;
  1268. SetWriteBank(integer(offs shr 16));
  1269. {$ifdef logging}
  1270. logln('putpixvesa32kor64k offset: '+strf(word(offs)));
  1271. {$endif logging}
  1272. memW[WinWriteSeg : word(offs)] := color;
  1273. end;
  1274. function GetPixVESA32kOr64k(x, y : integer): word; {$ifndef fpc}far;{$endif fpc}
  1275. var
  1276. offs : longint;
  1277. begin
  1278. X:= X + StartXViewPort;
  1279. Y:= Y + StartYViewPort + YOffset;
  1280. offs := longint(y) * BytesPerLine + 2*x;
  1281. SetReadBank(integer(offs shr 16));
  1282. GetPixVESA32kOr64k:=memW[WinReadSeg : word(offs)];
  1283. end;
  1284. procedure DirectPutPixVESA32kOr64k(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1285. var
  1286. offs : longint;
  1287. col : word;
  1288. begin
  1289. {$ifdef logging}
  1290. logln('directputpixvesa32kor64k('+strf(x)+','+strf(y)+')');
  1291. {$endif logging}
  1292. y:= Y + YOffset;
  1293. offs := longint(y) * BytesPerLine + 2*x;
  1294. SetWriteBank(integer((offs shr 16) and $ff));
  1295. Case CurrentWriteMode of
  1296. XorPut:
  1297. Begin
  1298. SetReadBank(integer(offs shr 16));
  1299. memW[WinWriteSeg : word(offs)] := memW[WinReadSeg : word(offs)] xor currentcolor;
  1300. End;
  1301. AndPut:
  1302. Begin
  1303. SetReadBank(integer(offs shr 16));
  1304. memW[WinWriteSeg : word(offs)] := memW[WinReadSeg : word(offs)] And currentcolor;
  1305. End;
  1306. OrPut:
  1307. Begin
  1308. SetReadBank(integer(offs shr 16));
  1309. memW[WinWriteSeg : word(offs)] := memW[WinReadSeg : word(offs)] or currentcolor;
  1310. End
  1311. else
  1312. Begin
  1313. If CurrentWriteMode <> NotPut Then
  1314. col := CurrentColor
  1315. Else col := Not(CurrentColor);
  1316. {$ifdef logging}
  1317. logln('directputpixvesa32kor64k offset: '+strf(word(offs)));
  1318. {$endif logging}
  1319. memW[WinWriteSeg : word(offs)] := Col;
  1320. End
  1321. End;
  1322. end;
  1323. {$ifdef FPC}
  1324. {************************************************************************}
  1325. {* 15/16bit pixels VESA mode routines Linear mode *}
  1326. {************************************************************************}
  1327. procedure PutPixVESA32kor64kLinear(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1328. var
  1329. offs : longint;
  1330. begin
  1331. X:= X + StartXViewPort;
  1332. Y:= Y + StartYViewPort;
  1333. { convert to absolute coordinates and then verify clipping...}
  1334. if ClipPixels then
  1335. Begin
  1336. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1337. exit;
  1338. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1339. exit;
  1340. end;
  1341. offs := longint(y) * BytesPerLine + 2*x;
  1342. if UseNoSelector then
  1343. pword(LFBPointer+offs+LinearPageOfs)^:=color
  1344. else
  1345. seg_move(get_ds,longint(@color),WinWriteSeg,offs+LinearPageOfs,2);
  1346. end;
  1347. function GetPixVESA32kor64kLinear(x, y : integer): word; {$ifndef fpc}far;{$endif fpc}
  1348. var
  1349. offs : longint;
  1350. color : word;
  1351. begin
  1352. X:= X + StartXViewPort;
  1353. Y:= Y + StartYViewPort;
  1354. offs := longint(y) * BytesPerLine + 2*x;
  1355. if UseNoSelector then
  1356. color:=pword(LFBPointer+offs+LinearPageOfs)^
  1357. else
  1358. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@color),2);
  1359. GetPixVESA32kor64kLinear:=color;
  1360. end;
  1361. procedure DirectPutPixVESA32kor64kLinear(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1362. var
  1363. offs : longint;
  1364. col : word;
  1365. begin
  1366. offs := longint(y) * BytesPerLine + 2*x;
  1367. Case CurrentWriteMode of
  1368. XorPut:
  1369. Begin
  1370. if UseNoSelector then
  1371. col:=pword(LFBPointer+offs+LinearPageOfs)^
  1372. else
  1373. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@col),2);
  1374. col := col xor currentcolor;
  1375. End;
  1376. AndPut:
  1377. Begin
  1378. if UseNoSelector then
  1379. col:=pword(LFBPointer+offs+LinearPageOfs)^
  1380. else
  1381. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@col),2);
  1382. col := col and currentcolor;
  1383. End;
  1384. OrPut:
  1385. Begin
  1386. if UseNoSelector then
  1387. col:=pword(LFBPointer+offs+LinearPageOfs)^
  1388. else
  1389. seg_move(WinWriteSeg,offs+LinearPageOfs,get_ds,longint(@col),2);
  1390. col := col or currentcolor;
  1391. End
  1392. else
  1393. Begin
  1394. If CurrentWriteMode <> NotPut Then
  1395. col := CurrentColor
  1396. Else col := Not(CurrentColor);
  1397. End
  1398. End;
  1399. if UseNoSelector then
  1400. pword(LFBPointer+offs+LinearPageOfs)^:=col
  1401. else
  1402. seg_move(get_ds,longint(@col),WinWriteSeg,offs+LinearPageOfs,2);
  1403. end;
  1404. {$endif FPC}
  1405. {************************************************************************}
  1406. {* 4-bit pixels VESA mode routines *}
  1407. {************************************************************************}
  1408. procedure PutPixVESA16(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1409. var
  1410. offs : longint;
  1411. dummy : byte;
  1412. begin
  1413. X:= X + StartXViewPort;
  1414. Y:= Y + StartYViewPort;
  1415. { convert to absolute coordinates and then verify clipping...}
  1416. if ClipPixels then
  1417. Begin
  1418. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1419. exit;
  1420. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1421. exit;
  1422. end;
  1423. Y := Y + YOffset; { adjust pixel for correct virtual page }
  1424. { }
  1425. offs := longint(y) * BytesPerLine + (x div 8);
  1426. SetWriteBank(integer(offs shr 16));
  1427. PortW[$3ce] := $0f01; { Index 01 : Enable ops on all 4 planes }
  1428. PortW[$3ce] := color shl 8; { Index 00 : Enable correct plane and write color }
  1429. Port[$3ce] := 8; { Index 08 : Bitmask register. }
  1430. Port[$3cf] := $80 shr (x and $7); { Select correct bits to modify }
  1431. dummy := Mem[WinWriteSeg: offs]; { Latch the data into host space. }
  1432. Mem[WinWriteSeg: offs] := dummy; { Write the data into video memory }
  1433. PortW[$3ce] := $ff08; { Enable all bit planes. }
  1434. PortW[$3ce] := $0001; { Index 01 : Disable ops on all four planes. }
  1435. { }
  1436. end;
  1437. Function GetPixVESA16(X,Y: Integer):word; {$ifndef fpc}far;{$endif fpc}
  1438. Var dummy, offset: Word;
  1439. shift: byte;
  1440. Begin
  1441. X:= X + StartXViewPort;
  1442. Y:= Y + StartYViewPort + YOffset;
  1443. offset := longint(Y) * BytesPerLine + (x div 8);
  1444. SetReadBank(integer(offset shr 16));
  1445. Port[$3ce] := 4;
  1446. shift := 7 - (X and 7);
  1447. Port[$3cf] := 0;
  1448. dummy := (Mem[WinReadSeg:offset] shr shift) and 1;
  1449. Port[$3cf] := 1;
  1450. dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 1);
  1451. Port[$3cf] := 2;
  1452. dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 2);
  1453. Port[$3cf] := 3;
  1454. dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 3);
  1455. GetPixVESA16 := dummy;
  1456. end;
  1457. procedure DirectPutPixVESA16(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1458. var
  1459. offs : longint;
  1460. dummy : byte;
  1461. Color : word;
  1462. begin
  1463. y:= Y + YOffset;
  1464. case CurrentWriteMode of
  1465. XORPut:
  1466. begin
  1467. { getpixel wants local/relative coordinates }
  1468. Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
  1469. Color := CurrentColor Xor Color;
  1470. end;
  1471. OrPut:
  1472. begin
  1473. { getpixel wants local/relative coordinates }
  1474. Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
  1475. Color := CurrentColor Or Color;
  1476. end;
  1477. AndPut:
  1478. begin
  1479. { getpixel wants local/relative coordinates }
  1480. Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
  1481. Color := CurrentColor And Color;
  1482. end;
  1483. NotPut:
  1484. begin
  1485. Color := Not Color;
  1486. end
  1487. else
  1488. Color := CurrentColor;
  1489. end;
  1490. offs := longint(y) * BytesPerLine + (x div 8);
  1491. SetWriteBank(integer(offs shr 16));
  1492. PortW[$3ce] := $0f01; { Index 01 : Enable ops on all 4 planes }
  1493. PortW[$3ce] := color shl 8; { Index 00 : Enable correct plane and write color }
  1494. Port[$3ce] := 8; { Index 08 : Bitmask register. }
  1495. Port[$3cf] := $80 shr (x and $7); { Select correct bits to modify }
  1496. dummy := Mem[WinWriteSeg: offs]; { Latch the data into host space. }
  1497. Mem[WinWriteSeg: offs] := dummy; { Write the data into video memory }
  1498. PortW[$3ce] := $ff08; { Enable all bit planes. }
  1499. PortW[$3ce] := $0001; { Index 01 : Disable ops on all four planes. }
  1500. end;
  1501. {************************************************************************}
  1502. {* VESA Palette entries *}
  1503. {************************************************************************}
  1504. {$IFDEF DPMI}
  1505. {$ifdef fpc}
  1506. Procedure SetVESARGBAllPalette(const Palette:PaletteType);
  1507. var
  1508. pal: array[0..255] of palrec;
  1509. regs: TDPMIRegisters;
  1510. c, Ptr: longint;
  1511. RealSeg: word;
  1512. FunctionNr : byte; { use blankbit or normal RAMDAC programming? }
  1513. begin
  1514. if DirectColor then
  1515. Begin
  1516. _GraphResult := grError;
  1517. exit;
  1518. end;
  1519. { use the set/get palette function }
  1520. if VESAInfo.Version >= $0200 then
  1521. Begin
  1522. { check if blanking bit must be set when programming }
  1523. { the RAMDAC. }
  1524. if (VESAInfo.caps and attrSnowCheck) <> 0 then
  1525. FunctionNr := $80
  1526. else
  1527. FunctionNr := $00;
  1528. fillChar(pal,sizeof(pal),0);
  1529. { Convert to vesa format }
  1530. for c := 0 to 255 do
  1531. begin
  1532. pal[c].red := byte(palette.colors[c].red);
  1533. pal[c].green := byte(palette.colors[c].green);
  1534. pal[c].blue := byte(palette.colors[c].blue);
  1535. end;
  1536. { Alllocate real mode buffer }
  1537. Ptr:=Global_Dos_Alloc(sizeof(pal));
  1538. {get the segment value}
  1539. RealSeg := word(Ptr shr 16);
  1540. { setup interrupt registers }
  1541. FillChar(regs, sizeof(regs), #0);
  1542. { copy palette values to real mode buffer }
  1543. DosMemPut(RealSeg,0,pal,sizeof(pal));
  1544. regs.eax := $4F09;
  1545. regs.ebx := FunctionNr;
  1546. regs.ecx := 256;
  1547. regs.edx := 0;
  1548. regs.es := RealSeg;
  1549. regs.edi := 0; { offset is always zero }
  1550. RealIntr($10, regs);
  1551. { free real mode memory }
  1552. If not Global_Dos_Free(word(Ptr and $ffff)) then
  1553. RunError(216);
  1554. if word(regs.eax) <> $004F then
  1555. begin
  1556. _GraphResult := grError;
  1557. exit;
  1558. end;
  1559. end
  1560. else
  1561. { assume it's fully VGA compatible palette-wise. }
  1562. Begin
  1563. SetVGARGBAllPalette(palette);
  1564. end;
  1565. setallpalettedefault(palette);
  1566. end;
  1567. {$endif fpc}
  1568. Procedure SetVESARGBPalette(ColorNum, RedValue, GreenValue,
  1569. BlueValue : Integer);
  1570. var
  1571. pal: palrec;
  1572. regs: TDPMIRegisters;
  1573. Ptr: longint;
  1574. {$ifndef fpc}
  1575. PalPtr : ^PalRec;
  1576. {$endif fpc}
  1577. RealSeg: word;
  1578. FunctionNr : byte; { use blankbit or normal RAMDAC programming? }
  1579. begin
  1580. if DirectColor then
  1581. Begin
  1582. {$ifdef logging}
  1583. logln('setvesargbpalette called with directcolor = true');
  1584. {$endif logging}
  1585. _GraphResult := grError;
  1586. exit;
  1587. end;
  1588. pal.align := 0;
  1589. pal.red := byte(RedValue) shr 2;
  1590. pal.green := byte(GreenValue) shr 2;
  1591. pal.blue := byte(BlueValue) shr 2;
  1592. { use the set/get palette function }
  1593. if VESAInfo.Version >= $0200 then
  1594. Begin
  1595. { check if blanking bit must be set when programming }
  1596. { the RAMDAC. }
  1597. if (VESAInfo.caps and attrSnowCheck) <> 0 then
  1598. FunctionNr := $80
  1599. else
  1600. FunctionNr := $00;
  1601. { Alllocate real mode buffer }
  1602. {$ifndef fpc}
  1603. Ptr:=GlobalDosAlloc(sizeof(palrec));
  1604. { get the selector values }
  1605. PalPtr := pointer(Ptr shl 16);
  1606. if not assigned(PalPtr) then
  1607. RunError(203);
  1608. {$else fpc}
  1609. Ptr:=Global_Dos_Alloc(sizeof(palrec));
  1610. {$endif fpc}
  1611. {get the segment value}
  1612. RealSeg := word(Ptr shr 16);
  1613. { setup interrupt registers }
  1614. FillChar(regs, sizeof(regs), #0);
  1615. { copy palette values to real mode buffer }
  1616. {$ifndef fpc}
  1617. move(pal, palptr^, sizeof(pal));
  1618. {$else fpc}
  1619. DosMemPut(RealSeg,0,pal,sizeof(pal));
  1620. {$endif fpc}
  1621. regs.eax := $4F09;
  1622. regs.ebx := FunctionNr;
  1623. regs.ecx := $01;
  1624. regs.edx := ColorNum;
  1625. regs.es := RealSeg;
  1626. regs.edi := 0; { offset is always zero }
  1627. RealIntr($10, regs);
  1628. { free real mode memory }
  1629. {$ifndef fpc}
  1630. GlobalDosFree(word(Ptr and $ffff));
  1631. {$else fpc}
  1632. If not Global_Dos_Free(word(Ptr and $ffff)) then
  1633. RunError(216);
  1634. {$endif fpc}
  1635. if word(regs.eax) <> $004F then
  1636. begin
  1637. {$ifdef logging}
  1638. logln('setvesargbpalette failed while directcolor = false!');
  1639. {$endif logging}
  1640. _GraphResult := grError;
  1641. exit;
  1642. end;
  1643. end
  1644. else
  1645. { assume it's fully VGA compatible palette-wise. }
  1646. Begin
  1647. SetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1648. end;
  1649. end;
  1650. Procedure GetVESARGBPalette(ColorNum: integer; Var
  1651. RedValue, GreenValue, BlueValue : integer);
  1652. var
  1653. pal: PalRec;
  1654. {$ifndef fpc}
  1655. palptr : ^PalRec;
  1656. {$endif fpc}
  1657. regs : TDPMIRegisters;
  1658. RealSeg: word;
  1659. ptr: longint;
  1660. begin
  1661. if DirectColor then
  1662. Begin
  1663. {$ifdef logging}
  1664. logln('getvesargbpalette called with directcolor = true');
  1665. {$endif logging}
  1666. _GraphResult := grError;
  1667. exit;
  1668. end;
  1669. { use the set/get palette function }
  1670. if VESAInfo.Version >= $0200 then
  1671. Begin
  1672. { Alllocate real mode buffer }
  1673. {$ifndef fpc}
  1674. Ptr:=GlobalDosAlloc(sizeof(palrec));
  1675. { get the selector value }
  1676. PalPtr := pointer(longint(Ptr and $0000ffff) shl 16);
  1677. if not assigned(PalPtr) then
  1678. RunError(203);
  1679. {$else fpc}
  1680. Ptr:=Global_Dos_Alloc(sizeof(palrec));
  1681. {$endif fpc}
  1682. { get the segment value }
  1683. RealSeg := word(Ptr shr 16);
  1684. { setup interrupt registers }
  1685. FillChar(regs, sizeof(regs), #0);
  1686. regs.eax := $4F09;
  1687. regs.ebx := $01; { get palette data }
  1688. regs.ecx := $01;
  1689. regs.edx := ColorNum;
  1690. regs.es := RealSeg;
  1691. regs.edi := 0; { offset is always zero }
  1692. RealIntr($10, regs);
  1693. { copy to protected mode buffer ... }
  1694. {$ifndef fpc}
  1695. Move(PalPtr^, Pal, sizeof(pal));
  1696. {$else fpc}
  1697. DosMemGet(RealSeg,0,Pal,sizeof(pal));
  1698. {$endif fpc}
  1699. { free real mode memory }
  1700. {$ifndef fpc}
  1701. GlobalDosFree(word(Ptr and $ffff));
  1702. {$else fpc}
  1703. If not Global_Dos_Free(word(Ptr and $ffff)) then
  1704. RunError(216);
  1705. {$endif fpc}
  1706. if word(regs.eax) <> $004F then
  1707. begin
  1708. {$ifdef logging}
  1709. logln('getvesargbpalette failed while directcolor = false!');
  1710. {$endif logging}
  1711. _GraphResult := grError;
  1712. exit;
  1713. end
  1714. else
  1715. begin
  1716. RedValue := Integer(pal.Red);
  1717. GreenValue := Integer(pal.Green);
  1718. BlueValue := Integer(pal.Blue);
  1719. end;
  1720. end
  1721. else
  1722. GetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1723. end;
  1724. {$ELSE}
  1725. Procedure SetVESARGBPalette(ColorNum, RedValue, GreenValue,
  1726. BlueValue : Integer); far;
  1727. var
  1728. FunctionNr : byte; { use blankbit or normal RAMDAC programming? }
  1729. pal: ^palrec;
  1730. Error : boolean; { VBE call error }
  1731. begin
  1732. if DirectColor then
  1733. Begin
  1734. _GraphResult := grError;
  1735. exit;
  1736. end;
  1737. Error := FALSE;
  1738. new(pal);
  1739. if not assigned(pal) then RunError(203);
  1740. pal^.align := 0;
  1741. pal^.red := byte(RedValue);
  1742. pal^.green := byte(GreenValue);
  1743. pal^.blue := byte(BlueValue);
  1744. { use the set/get palette function }
  1745. if VESAInfo.Version >= $0200 then
  1746. Begin
  1747. { check if blanking bit must be set when programming }
  1748. { the RAMDAC. }
  1749. if (VESAInfo.caps and attrSnowCheck) <> 0 then
  1750. FunctionNr := $80
  1751. else
  1752. FunctionNr := $00;
  1753. asm
  1754. mov ax, 4F09h { Set/Get Palette data }
  1755. mov bl, [FunctionNr] { Set palette data }
  1756. mov cx, 01h { update one palette reg. }
  1757. mov dx, [ColorNum] { register number to update }
  1758. les di, [pal] { get palette address }
  1759. int 10h
  1760. cmp ax, 004Fh { check if success }
  1761. jz @noerror
  1762. mov [Error], TRUE
  1763. @noerror:
  1764. end;
  1765. if not Error then
  1766. Dispose(pal)
  1767. else
  1768. begin
  1769. _GraphResult := grError;
  1770. exit;
  1771. end;
  1772. end
  1773. else
  1774. { assume it's fully VGA compatible palette-wise. }
  1775. Begin
  1776. SetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1777. end;
  1778. end;
  1779. Procedure GetVESARGBPalette(ColorNum: integer; Var RedValue, GreenValue,
  1780. BlueValue : integer); far;
  1781. var
  1782. Error: boolean;
  1783. pal: ^palrec;
  1784. begin
  1785. if DirectColor then
  1786. Begin
  1787. _GraphResult := grError;
  1788. exit;
  1789. end;
  1790. Error := FALSE;
  1791. new(pal);
  1792. if not assigned(pal) then RunError(203);
  1793. FillChar(pal^, sizeof(palrec), #0);
  1794. { use the set/get palette function }
  1795. if VESAInfo.Version >= $0200 then
  1796. Begin
  1797. asm
  1798. mov ax, 4F09h { Set/Get Palette data }
  1799. mov bl, 01h { Set palette data }
  1800. mov cx, 01h { update one palette reg. }
  1801. mov dx, [ColorNum] { register number to update }
  1802. les di, [pal] { get palette address }
  1803. int 10h
  1804. cmp ax, 004Fh { check if success }
  1805. jz @noerror
  1806. mov [Error], TRUE
  1807. @noerror:
  1808. end;
  1809. if not Error then
  1810. begin
  1811. RedValue := Integer(pal^.Red);
  1812. GreenValue := Integer(pal^.Green);
  1813. BlueValue := Integer(pal^.Blue);
  1814. Dispose(pal);
  1815. end
  1816. else
  1817. begin
  1818. _GraphResult := grError;
  1819. exit;
  1820. end;
  1821. end
  1822. else
  1823. GetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1824. end;
  1825. {$ENDIF}
  1826. type
  1827. heaperrorproc=function(size:longint):integer;
  1828. Const
  1829. HeapErrorIsHooked : boolean = false;
  1830. OldHeapError : HeapErrorProc = nil;
  1831. DsLimit : dword = 0;
  1832. function NewHeapError(size : longint) : integer;
  1833. begin
  1834. set_segment_limit(get_ds,DsLimit);
  1835. NewHeapError:=OldHeapError(size);
  1836. DsLimit:=get_segment_limit(get_ds);
  1837. { The base of ds can be changed
  1838. we need to compute the address again PM }
  1839. LFBPointer:=pointer(FrameBufferLinearAddress-get_segment_base_address(get_ds));
  1840. if dword(LFBPointer)+dword(VESAInfo.TotalMem shl 16)-1 > DsLimit then
  1841. set_segment_limit(get_ds,dword(LFBPointer)+dword(VESAInfo.TotalMem shl 16)-1);
  1842. end;
  1843. procedure HookHeapError;
  1844. begin
  1845. if HeapErrorIsHooked then
  1846. exit;
  1847. DsLimit:=get_segment_limit(get_ds);
  1848. OldHeapError:=HeapErrorProc(HeapError);
  1849. HeapError:=@NewHeapError;
  1850. HeapErrorIsHooked:=true;
  1851. end;
  1852. procedure UnHookHeapError;
  1853. begin
  1854. if not HeapErrorIsHooked then
  1855. exit;
  1856. LFBPointer:=nil;
  1857. set_segment_limit(get_ds,DsLimit);
  1858. HeapError:=OldHeapError;
  1859. HeapErrorIsHooked:=false;
  1860. end;
  1861. function SetupLinear(var ModeInfo: TVESAModeInfo;mode : word) : boolean;
  1862. begin
  1863. SetUpLinear:=false;
  1864. {$ifdef FPC}
  1865. case mode of
  1866. m320x200x32k,
  1867. m320x200x64k,
  1868. m640x480x32k,
  1869. m640x480x64k,
  1870. m800x600x32k,
  1871. m800x600x64k,
  1872. m1024x768x32k,
  1873. m1024x768x64k,
  1874. m1280x1024x32k,
  1875. m1280x1024x64k :
  1876. begin
  1877. DirectPutPixel:=@DirectPutPixVESA32kor64kLinear;
  1878. PutPixel:=@PutPixVESA32kor64kLinear;
  1879. GetPixel:=@GetPixVESA32kor64kLinear;
  1880. { linear mode for lines not yet implemented PM }
  1881. HLine:=@HLineDefault;
  1882. VLine:=@VLineDefault;
  1883. GetScanLine := @GetScanLineDefault;
  1884. PatternLine := @PatternLineDefault;
  1885. end;
  1886. m640x400x256,
  1887. m640x480x256,
  1888. m800x600x256,
  1889. m1024x768x256,
  1890. m1280x1024x256:
  1891. begin
  1892. DirectPutPixel:=@DirectPutPixVESA256Linear;
  1893. PutPixel:=@PutPixVESA256Linear;
  1894. GetPixel:=@GetPixVESA256Linear;
  1895. { linear mode for lines not yet implemented PM }
  1896. HLine:=@HLineDefault;
  1897. VLine:=@VLineDefault;
  1898. GetScanLine := @GetScanLineDefault;
  1899. PatternLine := @PatternLineDefault;
  1900. end;
  1901. else
  1902. exit;
  1903. end;
  1904. FrameBufferLinearAddress:=Get_linear_addr(VESAModeInfo.PhysAddress and $FFFF0000,
  1905. VESAInfo.TotalMem shl 16);
  1906. {$ifdef logging}
  1907. logln('framebuffer linear address: '+hexstr(FrameBufferLinearAddress div (1024*1024),8));
  1908. logln('total mem shl 16: '+strf(vesainfo.totalmem shl 16));
  1909. {$endif logging}
  1910. if int31error<>0 then
  1911. begin
  1912. {$ifdef logging}
  1913. logln('Unable to get linear address for '+hexstr(VESAModeInfo.PhysAddress,8));
  1914. {$endif logging}
  1915. writeln(stderr,'Unable to get linear address for ',hexstr(VESAModeInfo.PhysAddress,8));
  1916. exit;
  1917. end;
  1918. if UseNoSelector then
  1919. begin
  1920. HookHeapError;
  1921. LFBPointer:=pointer(FrameBufferLinearAddress-get_segment_base_address(get_ds));
  1922. if dword(LFBPointer)+dword(VESAInfo.TotalMem shl 16)-1 > dword(get_segment_limit(get_ds)) then
  1923. set_segment_limit(get_ds,dword(LFBPointer)+dword(VESAInfo.TotalMem shl 16)-1);
  1924. end
  1925. else
  1926. begin
  1927. WinWriteSeg:=allocate_ldt_descriptors(1);
  1928. {$ifdef logging}
  1929. logln('writeseg1: '+hexstr(winwriteseg,8));
  1930. {$endif logging}
  1931. set_segment_base_address(WinWriteSeg,FrameBufferLinearAddress);
  1932. set_segment_limit(WinWriteSeg,(VESAInfo.TotalMem shl 16)-1);
  1933. lock_linear_region(FrameBufferLinearAddress,(VESAInfo.TotalMem shl 16));
  1934. if int31error<>0 then
  1935. begin
  1936. {$ifdef logging}
  1937. logln('Error in linear memory selectors creation');
  1938. {$endif logging}
  1939. writeln(stderr,'Error in linear memory selectors creation');
  1940. exit;
  1941. end;
  1942. end;
  1943. LinearPageOfs := 0;
  1944. InLinear:=true;
  1945. SetUpLinear:=true;
  1946. { WinSize:=(VGAInfo.TotalMem shl 16);
  1947. WinLoMask:=(VGAInfo.TotalMem shl 16)-1;
  1948. WinShift:=15;
  1949. Temp:=VGAInfo.TotalMem;
  1950. while Temp>0 do
  1951. begin
  1952. inc(WinShift);
  1953. Temp:=Temp shr 1;
  1954. end; }
  1955. {$endif FPC}
  1956. end;
  1957. procedure SetupWindows(var ModeInfo: TVESAModeInfo);
  1958. begin
  1959. InLinear:=false;
  1960. { now we check the windowing scheme ...}
  1961. if (ModeInfo.WinAAttr and WinSupported) <> 0 then
  1962. { is this window supported ... }
  1963. begin
  1964. { now check if the window is R/W }
  1965. if (ModeInfo.WinAAttr and WinReadable) <> 0 then
  1966. begin
  1967. ReadWindow := 0;
  1968. WinReadSeg := ModeInfo.WinASeg;
  1969. end;
  1970. if (ModeInfo.WinAAttr and WinWritable) <> 0 then
  1971. begin
  1972. WriteWindow := 0;
  1973. WinWriteSeg := ModeInfo.WinASeg;
  1974. end;
  1975. end;
  1976. if (ModeInfo.WinBAttr and WinSupported) <> 0 then
  1977. { is this window supported ... }
  1978. begin
  1979. { OPTIMIZATION ... }
  1980. { if window A supports both read/write, then we try to optimize }
  1981. { everything, by using a different window for Read and/or write.}
  1982. if (WinReadSeg <> 0) and (WinWriteSeg <> 0) then
  1983. begin
  1984. { check if winB supports read }
  1985. if (ModeInfo.WinBAttr and winReadable) <> 0 then
  1986. begin
  1987. WinReadSeg := ModeInfo.WinBSeg;
  1988. ReadWindow := 1;
  1989. end
  1990. else
  1991. { check if WinB supports write }
  1992. if (ModeInfo.WinBAttr and WinWritable) <> 0 then
  1993. begin
  1994. WinWriteSeg := ModeInfo.WinBSeg;
  1995. WriteWindow := 1;
  1996. end;
  1997. end
  1998. else
  1999. { Window A only supported Read OR Write, no we have to make }
  2000. { sure that window B supports the other mode. }
  2001. if (WinReadSeg = 0) and (WinWriteSeg<>0) then
  2002. begin
  2003. if (ModeInfo.WinBAttr and WinReadable <> 0) then
  2004. begin
  2005. ReadWindow := 1;
  2006. WinReadSeg := ModeInfo.WinBSeg;
  2007. end
  2008. else
  2009. { impossible, this VESA mode is WRITE only! }
  2010. begin
  2011. WriteLn('Invalid VESA Window attribute.');
  2012. Halt(255);
  2013. end;
  2014. end
  2015. else
  2016. if (winWriteSeg = 0) and (WinReadSeg<>0) then
  2017. begin
  2018. if (ModeInfo.WinBAttr and WinWritable) <> 0 then
  2019. begin
  2020. WriteWindow := 1;
  2021. WinWriteSeg := ModeInfo.WinBSeg;
  2022. end
  2023. else
  2024. { impossible, this VESA mode is READ only! }
  2025. begin
  2026. WriteLn('Invalid VESA Window attribute.');
  2027. Halt(255);
  2028. end;
  2029. end
  2030. else
  2031. if (winReadSeg = 0) and (winWriteSeg = 0) then
  2032. { no read/write in this mode! }
  2033. begin
  2034. WriteLn('Invalid VESA Window attribute.');
  2035. Halt(255);
  2036. end;
  2037. YOffset := 0;
  2038. end;
  2039. { if both windows are not supported, then we can assume }
  2040. { that there is ONE single NON relocatable window. }
  2041. if (WinWriteSeg = 0) and (WinReadSeg = 0) then
  2042. begin
  2043. WinWriteSeg := ModeInfo.WinASeg;
  2044. WinReadSeg := ModeInfo.WinASeg;
  2045. end;
  2046. { 16-bit Protected mode checking code... }
  2047. { change segment values to protected mode }
  2048. { selectors. }
  2049. if WinReadSeg = $A000 then
  2050. WinReadSeg := SegA000
  2051. else
  2052. if WinReadSeg = $B000 then
  2053. WinReadSeg := SegB000
  2054. else
  2055. if WinReadSeg = $B800 then
  2056. WinReadSeg := SegB800
  2057. else
  2058. begin
  2059. WriteLn('Invalid segment address.');
  2060. Halt(255);
  2061. end;
  2062. if WinWriteSeg = $A000 then
  2063. WinWriteSeg := SegA000
  2064. else
  2065. if WinWriteSeg = $B000 then
  2066. WinWriteSeg := SegB000
  2067. else
  2068. if WinWriteSeg = $B800 then
  2069. WinWriteSeg := SegB800
  2070. else
  2071. begin
  2072. WriteLn('Invalid segment address.');
  2073. Halt(255);
  2074. end;
  2075. end;
  2076. function setVESAMode(mode:word):boolean;
  2077. var i:word;
  2078. res: boolean;
  2079. begin
  2080. { Init mode information, for compatibility with VBE < 1.1 }
  2081. FillChar(VESAModeInfo, sizeof(TVESAModeInfo), #0);
  2082. { get the video mode information }
  2083. if getVESAModeInfo(VESAmodeinfo, mode) then
  2084. begin
  2085. { checks if the hardware supports the video mode. }
  2086. if (VESAModeInfo.attr and modeAvail) = 0 then
  2087. begin
  2088. SetVESAmode := FALSE;
  2089. {$ifdef logging}
  2090. logln(' vesa mode '+strf(mode)+' not supported!!!');
  2091. {$endif logging}
  2092. _GraphResult := grError;
  2093. exit;
  2094. end;
  2095. SetVESAMode := TRUE;
  2096. BankShift := 0;
  2097. while (64 shr BankShift) <> VESAModeInfo.WinGranularity do
  2098. Inc(BankShift);
  2099. CurrentWriteBank := -1;
  2100. CurrentReadBank := -1;
  2101. BytesPerLine := VESAModeInfo.BytesPerScanLine;
  2102. { These are the window adresses ... }
  2103. WinWriteSeg := 0; { This is the segment to use for writes }
  2104. WinReadSeg := 0; { This is the segment to use for reads }
  2105. ReadWindow := 0;
  2106. WriteWindow := 0;
  2107. { VBE 2.0 and higher supports >= non VGA linear buffer types...}
  2108. { this is backward compatible. }
  2109. if (((VESAModeInfo.Attr and ModeNoWindowed) <> 0) or UseLFB) and
  2110. ((VESAModeInfo.Attr and ModeLinearBuffer) <> 0) then
  2111. begin
  2112. if not SetupLinear(VESAModeInfo,mode) then
  2113. SetUpWindows(VESAModeInfo);
  2114. end
  2115. else
  2116. { if linear and windowed is supported, then use windowed }
  2117. { method. }
  2118. SetUpWindows(VESAModeInfo);
  2119. {$ifdef logging}
  2120. LogLn('Entering vesa mode '+strf(mode));
  2121. LogLn('Read segment: $'+hexstr(winreadseg,4));
  2122. LogLn('Write segment: $'+hexstr(winwriteseg,4));
  2123. LogLn('Window granularity: '+strf(VESAModeInfo.WinGranularity)+'kb');
  2124. LogLn('Window size: '+strf(VESAModeInfo.winSize)+'kb');
  2125. LogLn('Bytes per line: '+strf(bytesperline));
  2126. {$endif logging}
  2127. { Select the correct mode number if we're going to use linear access! }
  2128. if InLinear then
  2129. inc(mode,$4000);
  2130. asm
  2131. mov ax,4F02h
  2132. mov bx,mode
  2133. {$ifdef fpc}
  2134. push ebp
  2135. {$endif fpc}
  2136. int 10h
  2137. {$ifdef fpc}
  2138. pop ebp
  2139. {$endif fpc}
  2140. sub ax,004Fh
  2141. cmp ax,1
  2142. sbb al,al
  2143. mov res,al
  2144. end;
  2145. if not res then
  2146. _GraphResult := GrNotDetected
  2147. else _GraphResult := grOk;
  2148. end;
  2149. end;
  2150. (*
  2151. function getVESAMode:word;assembler;
  2152. asm {return -1 if error}
  2153. mov ax,4F03h
  2154. {$ifdef fpc}
  2155. push ebp
  2156. {$endif fpc}
  2157. int 10h
  2158. {$ifdef fpc}
  2159. pop ebp
  2160. {$endif fpc}
  2161. cmp ax,004Fh
  2162. je @@OK
  2163. mov ax,-1
  2164. jmp @@X
  2165. @@OK:
  2166. mov ax,bx
  2167. @@X:
  2168. end;
  2169. *)
  2170. {************************************************************************}
  2171. {* VESA Modes inits *}
  2172. {************************************************************************}
  2173. {$IFDEF DPMI}
  2174. {******************************************************** }
  2175. { Function GetMaxScanLines() }
  2176. {-------------------------------------------------------- }
  2177. { This routine returns the maximum number of scan lines }
  2178. { possible for this mode. This is done using the Get }
  2179. { Scan Line length VBE function. }
  2180. {******************************************************** }
  2181. function GetMaxScanLines: word;
  2182. var
  2183. regs : TDPMIRegisters;
  2184. begin
  2185. FillChar(regs, sizeof(regs), #0);
  2186. { play it safe, call the real mode int, the 32-bit entry point }
  2187. { may not be defined as stated in VBE v3.0 }
  2188. regs.eax := $4f06; {_ setup function }
  2189. regs.ebx := $0001; { get scan line length }
  2190. RealIntr($10, regs);
  2191. GetMaxScanLines := (regs.edx and $0000ffff);
  2192. end;
  2193. {$ELSE}
  2194. function GetMaxScanLines: word; assembler;
  2195. asm
  2196. mov ax, 4f06h
  2197. mov bx, 0001h
  2198. int 10h
  2199. mov ax, dx
  2200. end;
  2201. {$ENDIF}
  2202. procedure Init1280x1024x64k; {$ifndef fpc}far;{$endif fpc}
  2203. begin
  2204. SetVesaMode(m1280x1024x64k);
  2205. { Get maximum number of scanlines for page flipping }
  2206. ScanLines := GetMaxScanLines;
  2207. end;
  2208. procedure Init1280x1024x32k; {$ifndef fpc}far;{$endif fpc}
  2209. begin
  2210. SetVESAMode(m1280x1024x32k);
  2211. { Get maximum number of scanlines for page flipping }
  2212. ScanLines := GetMaxScanLines;
  2213. end;
  2214. procedure Init1280x1024x256; {$ifndef fpc}far;{$endif fpc}
  2215. begin
  2216. SetVESAMode(m1280x1024x256);
  2217. { Get maximum number of scanlines for page flipping }
  2218. ScanLines := GetMaxScanLines;
  2219. end;
  2220. procedure Init1280x1024x16; {$ifndef fpc}far;{$endif fpc}
  2221. begin
  2222. SetVESAMode(m1280x1024x16);
  2223. { Get maximum number of scanlines for page flipping }
  2224. ScanLines := GetMaxScanLines;
  2225. end;
  2226. procedure Init1024x768x64k; {$ifndef fpc}far;{$endif fpc}
  2227. begin
  2228. SetVESAMode(m1024x768x64k);
  2229. { Get maximum number of scanlines for page flipping }
  2230. ScanLines := GetMaxScanLines;
  2231. end;
  2232. procedure Init640x480x32k; {$ifndef fpc}far;{$endif fpc}
  2233. begin
  2234. SetVESAMode(m640x480x32k);
  2235. { Get maximum number of scanlines for page flipping }
  2236. ScanLines := GetMaxScanLines;
  2237. end;
  2238. procedure Init1024x768x256; {$ifndef fpc}far;{$endif fpc}
  2239. begin
  2240. SetVESAMode(m1024x768x256);
  2241. { Get maximum number of scanlines for page flipping }
  2242. ScanLines := GetMaxScanLines;
  2243. end;
  2244. procedure Init1024x768x16; {$ifndef fpc}far;{$endif fpc}
  2245. begin
  2246. SetVESAMode(m1024x768x16);
  2247. { Get maximum number of scanlines for page flipping }
  2248. ScanLines := GetMaxScanLines;
  2249. end;
  2250. procedure Init800x600x64k; {$ifndef fpc}far;{$endif fpc}
  2251. begin
  2252. SetVESAMode(m800x600x64k);
  2253. { Get maximum number of scanlines for page flipping }
  2254. ScanLines := GetMaxScanLines;
  2255. end;
  2256. procedure Init800x600x32k; {$ifndef fpc}far;{$endif fpc}
  2257. begin
  2258. SetVESAMode(m800x600x32k);
  2259. { Get maximum number of scanlines for page flipping }
  2260. ScanLines := GetMaxScanLines;
  2261. end;
  2262. procedure Init800x600x256; {$ifndef fpc}far;{$endif fpc}
  2263. begin
  2264. SetVESAMode(m800x600x256);
  2265. { Get maximum number of scanlines for page flipping }
  2266. ScanLines := GetMaxScanLines;
  2267. end;
  2268. procedure Init800x600x16; {$ifndef fpc}far;{$endif fpc}
  2269. begin
  2270. SetVesaMode(m800x600x16);
  2271. { Get maximum number of scanlines for page flipping }
  2272. ScanLines := GetMaxScanLines;
  2273. end;
  2274. procedure Init640x480x64k; {$ifndef fpc}far;{$endif fpc}
  2275. begin
  2276. SetVESAMode(m640x480x64k);
  2277. { Get maximum number of scanlines for page flipping }
  2278. ScanLines := GetMaxScanLines;
  2279. end;
  2280. procedure Init640x480x256; {$ifndef fpc}far;{$endif fpc}
  2281. begin
  2282. SetVESAMode(m640x480x256);
  2283. { Get maximum number of scanlines for page flipping }
  2284. ScanLines := GetMaxScanLines;
  2285. end;
  2286. procedure Init640x400x256; {$ifndef fpc}far;{$endif fpc}
  2287. begin
  2288. SetVESAMode(m640x400x256);
  2289. { Get maximum number of scanlines for page flipping }
  2290. ScanLines := GetMaxScanLines;
  2291. end;
  2292. procedure Init320x200x64k; {$ifndef fpc}far;{$endif fpc}
  2293. begin
  2294. SetVESAMode(m320x200x64k);
  2295. { Get maximum number of scanlines for page flipping }
  2296. ScanLines := GetMaxScanLines;
  2297. end;
  2298. procedure Init320x200x32k; {$ifndef fpc}far;{$endif fpc}
  2299. begin
  2300. SetVESAMode(m320x200x32k);
  2301. { Get maximum number of scanlines for page flipping }
  2302. ScanLines := GetMaxScanLines;
  2303. end;
  2304. {$IFDEF DPMI}
  2305. Procedure SaveStateVESA; {$ifndef fpc}far;{$endif fpc}
  2306. var
  2307. PtrLong: longint;
  2308. regs: TDPMIRegisters;
  2309. begin
  2310. SaveSupported := FALSE;
  2311. SavePtr := nil;
  2312. {$ifdef logging}
  2313. LogLn('Get the video mode...');
  2314. {$endif logging}
  2315. { Get the video mode }
  2316. asm
  2317. mov ah,0fh
  2318. {$ifdef fpc}
  2319. push ebp
  2320. {$endif fpc}
  2321. int 10h
  2322. {$ifdef fpc}
  2323. pop ebp
  2324. {$endif fpc}
  2325. mov [VideoMode], al
  2326. end;
  2327. { saving/restoring video state screws up Windows (JM) }
  2328. if inWindows then
  2329. exit;
  2330. {$ifdef logging}
  2331. LogLn('Prepare to save VESA video state');
  2332. {$endif logging}
  2333. { Prepare to save video state...}
  2334. asm
  2335. mov ax, 4F04h { get buffer size to save state }
  2336. mov dx, 00h
  2337. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2338. {$ifdef fpc}
  2339. push ebp
  2340. {$endif fpc}
  2341. int 10h
  2342. {$ifdef fpc}
  2343. pop ebp
  2344. {$endif fpc}
  2345. mov [StateSize], bx
  2346. cmp al,04fh
  2347. jnz @notok
  2348. mov [SaveSupported],TRUE
  2349. @notok:
  2350. end;
  2351. regs.eax := $4f04;
  2352. regs.edx := $0000;
  2353. regs.ecx := $000F;
  2354. RealIntr($10, regs);
  2355. StateSize := word(regs.ebx);
  2356. if byte(regs.eax) = $4f then
  2357. SaveSupported := TRUE;
  2358. if SaveSupported then
  2359. begin
  2360. {$ifdef logging}
  2361. LogLn('allocating VESA save buffer of '+strf(64*StateSize));
  2362. {$endif logging}
  2363. {$ifndef fpc}
  2364. PtrLong:=GlobalDosAlloc(64*StateSize); { values returned in 64-byte blocks }
  2365. {$else fpc}
  2366. PtrLong:=Global_Dos_Alloc(64*StateSize); { values returned in 64-byte blocks }
  2367. {$endif fpc}
  2368. if PtrLong = 0 then
  2369. RunError(203);
  2370. SavePtr := pointer(longint(PtrLong and $0000ffff) shl 16);
  2371. {$ifndef fpc}
  2372. { In FPC mode, we can't do anything with this (no far pointers) }
  2373. { However, we still need to keep it to be able to free the }
  2374. { memory afterwards. Since this data is not accessed in PM code, }
  2375. { there's no need to save it in a seperate buffer (JM) }
  2376. if not assigned(SavePtr) then
  2377. RunError(203);
  2378. {$endif fpc}
  2379. RealStateSeg := word(PtrLong shr 16);
  2380. FillChar(regs, sizeof(regs), #0);
  2381. { call the real mode interrupt ... }
  2382. regs.eax := $4F04; { save the state buffer }
  2383. regs.ecx := $0F; { Save DAC / Data areas / Hardware states }
  2384. regs.edx := $01; { save state }
  2385. regs.es := RealStateSeg;
  2386. regs.ebx := 0;
  2387. RealIntr($10,regs);
  2388. FillChar(regs, sizeof(regs), #0);
  2389. { restore state, according to Ralph Brown Interrupt list }
  2390. { some BIOS corrupt the hardware after a save... }
  2391. regs.eax := $4F04; { restore the state buffer }
  2392. regs.ecx := $0F; { rest DAC / Data areas / Hardware states }
  2393. regs.edx := $02;
  2394. regs.es := RealStateSeg;
  2395. regs.ebx := 0;
  2396. RealIntr($10,regs);
  2397. end;
  2398. end;
  2399. procedure RestoreStateVESA; {$ifndef fpc}far;{$endif fpc}
  2400. var
  2401. regs:TDPMIRegisters;
  2402. begin
  2403. { go back to the old video mode...}
  2404. asm
  2405. mov ah,00
  2406. mov al,[VideoMode]
  2407. {$ifdef fpc}
  2408. push ebp
  2409. {$endif fpc}
  2410. int 10h
  2411. {$ifdef fpc}
  2412. pop ebp
  2413. {$endif fpc}
  2414. end;
  2415. { then restore all state information }
  2416. {$ifndef fpc}
  2417. if assigned(SavePtr) and (SaveSupported=TRUE) then
  2418. {$else fpc}
  2419. { No far pointer support, so it's possible that that assigned(SavePtr) }
  2420. { would return false under FPC. Just check if it's different from nil. }
  2421. if (SavePtr <> nil) and (SaveSupported=TRUE) then
  2422. {$endif fpc}
  2423. begin
  2424. FillChar(regs, sizeof(regs), #0);
  2425. { restore state, according to Ralph Brown Interrupt list }
  2426. { some BIOS corrupt the hardware after a save... }
  2427. regs.eax := $4F04; { restore the state buffer }
  2428. regs.ecx := $0F; { rest DAC / Data areas / Hardware states }
  2429. regs.edx := $02; { restore state }
  2430. regs.es := RealStateSeg;
  2431. regs.ebx := 0;
  2432. RealIntr($10,regs);
  2433. {$ifndef fpc}
  2434. if GlobalDosFree(longint(SavePtr) shr 16)<>0 then
  2435. {$else fpc}
  2436. if Not(Global_Dos_Free(longint(SavePtr) shr 16)) then
  2437. {$endif fpc}
  2438. RunError(216);
  2439. SavePtr := nil;
  2440. end;
  2441. end;
  2442. {$ELSE}
  2443. {**************************************************************}
  2444. {* Real mode routines *}
  2445. {**************************************************************}
  2446. Procedure SaveStateVESA; far;
  2447. begin
  2448. SavePtr := nil;
  2449. SaveSupported := FALSE;
  2450. { Get the video mode }
  2451. asm
  2452. mov ah,0fh
  2453. int 10h
  2454. mov [VideoMode], al
  2455. end;
  2456. { Prepare to save video state...}
  2457. asm
  2458. mov ax, 4f04h { get buffer size to save state }
  2459. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2460. mov dx, 00h
  2461. int 10h
  2462. mov [StateSize], bx
  2463. cmp al,04fh
  2464. jnz @notok
  2465. mov [SaveSupported],TRUE
  2466. @notok:
  2467. end;
  2468. if SaveSupported then
  2469. Begin
  2470. GetMem(SavePtr, 64*StateSize); { values returned in 64-byte blocks }
  2471. if not assigned(SavePtr) then
  2472. RunError(203);
  2473. asm
  2474. mov ax, 4F04h { save the state buffer }
  2475. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2476. mov dx, 01h
  2477. mov es, WORD PTR [SavePtr+2]
  2478. mov bx, WORD PTR [SavePtr]
  2479. int 10h
  2480. end;
  2481. { restore state, according to Ralph Brown Interrupt list }
  2482. { some BIOS corrupt the hardware after a save... }
  2483. asm
  2484. mov ax, 4F04h { save the state buffer }
  2485. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2486. mov dx, 02h
  2487. mov es, WORD PTR [SavePtr+2]
  2488. mov bx, WORD PTR [SavePtr]
  2489. int 10h
  2490. end;
  2491. end;
  2492. end;
  2493. procedure RestoreStateVESA; far;
  2494. begin
  2495. { go back to the old video mode...}
  2496. asm
  2497. mov ah,00
  2498. mov al,[VideoMode]
  2499. int 10h
  2500. end;
  2501. { then restore all state information }
  2502. if assigned(SavePtr) and (SaveSupported=TRUE) then
  2503. begin
  2504. { restore state, according to Ralph Brown Interrupt list }
  2505. asm
  2506. mov ax, 4F04h { save the state buffer }
  2507. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2508. mov dx, 02h { restore state }
  2509. mov es, WORD PTR [SavePtr+2]
  2510. mov bx, WORD PTR [SavePtr]
  2511. int 10h
  2512. end;
  2513. FreeMem(SavePtr, 64*StateSize);
  2514. SavePtr := nil;
  2515. end;
  2516. end;
  2517. {$ENDIF DPMI}
  2518. {************************************************************************}
  2519. {* VESA Page flipping routines *}
  2520. {************************************************************************}
  2521. { Note: These routines, according to the VBE3 specification, will NOT }
  2522. { work with the 24 bpp modes, because of the alignment. }
  2523. {************************************************************************}
  2524. {******************************************************** }
  2525. { Procedure SetVisualVESA() }
  2526. {-------------------------------------------------------- }
  2527. { This routine changes the page which will be displayed }
  2528. { on the screen, since the method has changed somewhat }
  2529. { between VBE versions , we will use the old method where }
  2530. { the new pixel offset is used to display different pages }
  2531. {******************************************************** }
  2532. procedure SetVisualVESA(page: word); {$ifndef fpc}far;{$endif fpc}
  2533. var
  2534. newStartVisible : word;
  2535. begin
  2536. if page > HardwarePages then
  2537. begin
  2538. _graphresult := grError;
  2539. exit;
  2540. end;
  2541. newStartVisible := (MaxY+1)*page;
  2542. if newStartVisible > ScanLines then
  2543. begin
  2544. _graphresult := grError;
  2545. exit;
  2546. end;
  2547. asm
  2548. mov ax, 4f07h
  2549. mov bx, 0000h { set display start }
  2550. mov cx, 0000h { pixel zero ! }
  2551. mov dx, [NewStartVisible] { new scanline }
  2552. {$ifdef fpc}
  2553. push ebp
  2554. {$endif}
  2555. int 10h
  2556. {$ifdef fpc}
  2557. pop ebp
  2558. {$endif}
  2559. end;
  2560. end;
  2561. procedure SetActiveVESA(page: word); {$ifndef fpc}far;{$endif fpc}
  2562. begin
  2563. { video offset is in pixels under VESA VBE! }
  2564. { This value is reset after a mode set to page ZERO = YOffset = 0 ) }
  2565. if page > HardwarePages then
  2566. begin
  2567. _graphresult := grError;
  2568. exit;
  2569. end;
  2570. YOffset := (MaxY+1)*page;
  2571. LinearPageOfs := YOffset*(MaxX+1);
  2572. end;
  2573. {
  2574. $Log$
  2575. Revision 1.9 2002-09-07 16:01:19 peter
  2576. * old logs removed and tabs fixed
  2577. }