vesa.inc 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663
  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 logging}
  1030. LogLn('patternline '+strf(x1)+' - '+strf(x2)+' on '+strf(y));
  1031. {$endif logging}
  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 logging}
  1068. LogLn('Aligning by drawing '+strf(8-(offs and 7))+' pixels');
  1069. {$endif logging}
  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 logging}
  1079. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(amount));
  1080. {$endif logging}
  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 logging}
  1090. LogLn('Rest to be drawn in this window: '+strf(bankrest));
  1091. {$endif logging}
  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 logging}
  1100. LogLn('Offset is now '+hexstr(offs,8)+', length left: '+strf(amount));
  1101. {$endif logging}
  1102. End
  1103. Else
  1104. Begin
  1105. {$ifdef logging}
  1106. LogLn('Drawing leftover: '+strf(amount)+' at offset '+hexstr(offs,8));
  1107. {$endif logging}
  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. procedure DirectPutPixVESA256Linear(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1129. var
  1130. offs : longint;
  1131. col : byte;
  1132. begin
  1133. offs := longint(y) * BytesPerLine + x;
  1134. Case CurrentWriteMode of
  1135. XorPut:
  1136. Begin
  1137. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1138. col := col xor byte(CurrentColor);
  1139. End;
  1140. AndPut:
  1141. Begin
  1142. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1143. col := col and byte(CurrentColor);
  1144. End;
  1145. OrPut:
  1146. Begin
  1147. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1148. col := col or byte(CurrentColor);
  1149. End
  1150. else
  1151. Begin
  1152. If CurrentWriteMode <> NotPut then
  1153. col := Byte(CurrentColor)
  1154. else col := Not(Byte(CurrentColor));
  1155. End
  1156. End;
  1157. seg_move(get_ds,longint(@col),WinWriteSeg,offs+LinearPageOfs,1);
  1158. end;
  1159. procedure PutPixVESA256Linear(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1160. var
  1161. offs : longint;
  1162. begin
  1163. X:= X + StartXViewPort;
  1164. Y:= Y + StartYViewPort;
  1165. { convert to absolute coordinates and then verify clipping...}
  1166. if ClipPixels then
  1167. Begin
  1168. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1169. exit;
  1170. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1171. exit;
  1172. end;
  1173. offs := longint(y) * BytesPerLine + x;
  1174. seg_move(get_ds,longint(@color),WinWriteSeg,offs+LinearPageOfs,1);
  1175. end;
  1176. function GetPixVESA256Linear(x, y : integer): word; {$ifndef fpc}far;{$endif fpc}
  1177. var
  1178. offs : longint;
  1179. col : byte;
  1180. begin
  1181. X:= X + StartXViewPort;
  1182. Y:= Y + StartYViewPort;
  1183. offs := longint(y) * BytesPerLine + x;
  1184. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@col),1);
  1185. GetPixVESA256Linear:=col;
  1186. end;
  1187. (*
  1188. function SetVESADisplayStart(PageNum : word;x,y : integer):Boolean;
  1189. var
  1190. dregs : registers;
  1191. begin
  1192. if PageNum>VesaModeInfo.NumberOfPages then
  1193. PageNum:=0;
  1194. {$ifdef DEBUG}
  1195. if PageNum>0 then
  1196. writeln(stderr,'Setting Display Page ',PageNum);
  1197. {$endif DEBUG}
  1198. dregs.RealEBX:=0{ $80 for Wait for retrace };
  1199. dregs.RealECX:=x;
  1200. dregs.RealEDX:=y+PageNum*maxy;
  1201. dregs.RealSP:=0;
  1202. dregs.RealSS:=0;
  1203. dregs.RealEAX:=$4F07; RealIntr($10,dregs);
  1204. { idem as above !!! }
  1205. if (dregs.RealEAX and $1FF) <> $4F then
  1206. begin
  1207. {$ifdef DEBUG}
  1208. writeln(stderr,'Set Display start error');
  1209. {$endif DEBUG}
  1210. SetVESADisplayStart:=false;
  1211. end
  1212. else
  1213. SetVESADisplayStart:=true;
  1214. end;
  1215. *)
  1216. {$endif FPC}
  1217. {************************************************************************}
  1218. {* 15/16bit pixels VESA mode routines *}
  1219. {************************************************************************}
  1220. procedure PutPixVESA32kOr64k(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1221. var
  1222. offs : longint;
  1223. begin
  1224. X:= X + StartXViewPort;
  1225. Y:= Y + StartYViewPort;
  1226. { convert to absolute coordinates and then verify clipping...}
  1227. if ClipPixels then
  1228. Begin
  1229. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1230. exit;
  1231. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1232. exit;
  1233. end;
  1234. Y := Y + YOffset; { adjust pixel for correct virtual page }
  1235. offs := longint(y) * BytesPerLine + 2*x;
  1236. SetWriteBank(integer(offs shr 16));
  1237. memW[WinWriteSeg : word(offs)] := color;
  1238. end;
  1239. function GetPixVESA32kOr64k(x, y : integer): word; {$ifndef fpc}far;{$endif fpc}
  1240. var
  1241. offs : longint;
  1242. begin
  1243. X:= X + StartXViewPort;
  1244. Y:= Y + StartYViewPort + YOffset;
  1245. offs := longint(y) * BytesPerLine + 2*x;
  1246. SetReadBank(integer(offs shr 16));
  1247. GetPixVESA32kOr64k:=memW[WinReadSeg : word(offs)];
  1248. end;
  1249. procedure DirectPutPixVESA32kOr64k(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1250. var
  1251. offs : longint;
  1252. col : word;
  1253. begin
  1254. y:= Y + YOffset;
  1255. offs := longint(y) * BytesPerLine + 2*x;
  1256. SetWriteBank(integer((offs shr 16) and $ff));
  1257. Case CurrentWriteMode of
  1258. XorPut:
  1259. Begin
  1260. SetReadBank(integer(offs shr 16));
  1261. memW[WinWriteSeg : word(offs)] := memW[WinReadSeg : word(offs)] xor currentcolor;
  1262. End;
  1263. AndPut:
  1264. Begin
  1265. SetReadBank(integer(offs shr 16));
  1266. memW[WinWriteSeg : word(offs)] := memW[WinReadSeg : word(offs)] And currentcolor;
  1267. End;
  1268. OrPut:
  1269. Begin
  1270. SetReadBank(integer(offs shr 16));
  1271. memW[WinWriteSeg : word(offs)] := memW[WinReadSeg : word(offs)] or currentcolor;
  1272. End
  1273. else
  1274. Begin
  1275. If CurrentWriteMode <> NotPut Then
  1276. col := CurrentColor
  1277. Else col := Not(CurrentColor);
  1278. memW[WinWriteSeg : word(offs)] := Col;
  1279. End
  1280. End;
  1281. end;
  1282. {$ifdef FPC}
  1283. {************************************************************************}
  1284. {* 15/16bit pixels VESA mode routines Linear mode *}
  1285. {************************************************************************}
  1286. procedure PutPixVESA32kor64kLinear(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1287. var
  1288. offs : longint;
  1289. begin
  1290. X:= X + StartXViewPort;
  1291. Y:= Y + StartYViewPort;
  1292. { convert to absolute coordinates and then verify clipping...}
  1293. if ClipPixels then
  1294. Begin
  1295. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1296. exit;
  1297. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1298. exit;
  1299. end;
  1300. offs := longint(y) * BytesPerLine + 2*x;
  1301. seg_move(get_ds,longint(@color),WinWriteSeg,offs+LinearPageOfs,2);
  1302. end;
  1303. function GetPixVESA32kor64kLinear(x, y : integer): word; {$ifndef fpc}far;{$endif fpc}
  1304. var
  1305. offs : longint;
  1306. color : word;
  1307. begin
  1308. X:= X + StartXViewPort;
  1309. Y:= Y + StartYViewPort;
  1310. offs := longint(y) * BytesPerLine + 2*x;
  1311. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@color),2);
  1312. GetPixVESA32kor64kLinear:=color;
  1313. end;
  1314. procedure DirectPutPixVESA32kor64kLinear(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1315. var
  1316. offs : longint;
  1317. col : word;
  1318. begin
  1319. offs := longint(y) * BytesPerLine + 2*x;
  1320. Case CurrentWriteMode of
  1321. XorPut:
  1322. Begin
  1323. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@col),2);
  1324. col := col xor currentcolor;
  1325. End;
  1326. AndPut:
  1327. Begin
  1328. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@col),2);
  1329. col := col and currentcolor;
  1330. End;
  1331. OrPut:
  1332. Begin
  1333. seg_move(WinReadSeg,offs+LinearPageOfs,get_ds,longint(@col),2);
  1334. col := col or currentcolor;
  1335. End
  1336. else
  1337. Begin
  1338. If CurrentWriteMode <> NotPut Then
  1339. col := CurrentColor
  1340. Else col := Not(CurrentColor);
  1341. End
  1342. End;
  1343. seg_move(get_ds,longint(@col),WinWriteSeg,offs+LinearPageOfs,2);
  1344. end;
  1345. {$endif FPC}
  1346. {************************************************************************}
  1347. {* 4-bit pixels VESA mode routines *}
  1348. {************************************************************************}
  1349. procedure PutPixVESA16(x, y : integer; color : word); {$ifndef fpc}far;{$endif fpc}
  1350. var
  1351. offs : longint;
  1352. dummy : byte;
  1353. begin
  1354. X:= X + StartXViewPort;
  1355. Y:= Y + StartYViewPort;
  1356. { convert to absolute coordinates and then verify clipping...}
  1357. if ClipPixels then
  1358. Begin
  1359. if (X < StartXViewPort) or (X > (StartXViewPort + ViewWidth)) then
  1360. exit;
  1361. if (Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)) then
  1362. exit;
  1363. end;
  1364. Y := Y + YOffset; { adjust pixel for correct virtual page }
  1365. { }
  1366. offs := longint(y) * BytesPerLine + (x div 8);
  1367. SetWriteBank(integer(offs shr 16));
  1368. PortW[$3ce] := $0f01; { Index 01 : Enable ops on all 4 planes }
  1369. PortW[$3ce] := color shl 8; { Index 00 : Enable correct plane and write color }
  1370. Port[$3ce] := 8; { Index 08 : Bitmask register. }
  1371. Port[$3cf] := $80 shr (x and $7); { Select correct bits to modify }
  1372. dummy := Mem[WinWriteSeg: offs]; { Latch the data into host space. }
  1373. Mem[WinWriteSeg: offs] := dummy; { Write the data into video memory }
  1374. PortW[$3ce] := $ff08; { Enable all bit planes. }
  1375. PortW[$3ce] := $0001; { Index 01 : Disable ops on all four planes. }
  1376. { }
  1377. end;
  1378. Function GetPixVESA16(X,Y: Integer):word; {$ifndef fpc}far;{$endif fpc}
  1379. Var dummy, offset: Word;
  1380. shift: byte;
  1381. Begin
  1382. X:= X + StartXViewPort;
  1383. Y:= Y + StartYViewPort + YOffset;
  1384. offset := longint(Y) * BytesPerLine + (x div 8);
  1385. SetReadBank(integer(offset shr 16));
  1386. Port[$3ce] := 4;
  1387. shift := 7 - (X and 7);
  1388. Port[$3cf] := 0;
  1389. dummy := (Mem[WinReadSeg:offset] shr shift) and 1;
  1390. Port[$3cf] := 1;
  1391. dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 1);
  1392. Port[$3cf] := 2;
  1393. dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 2);
  1394. Port[$3cf] := 3;
  1395. dummy := dummy or (((Mem[WinReadSeg:offset] shr shift) and 1) shl 3);
  1396. GetPixVESA16 := dummy;
  1397. end;
  1398. procedure DirectPutPixVESA16(x, y : integer); {$ifndef fpc}far;{$endif fpc}
  1399. var
  1400. offs : longint;
  1401. dummy : byte;
  1402. Color : word;
  1403. begin
  1404. y:= Y + YOffset;
  1405. case CurrentWriteMode of
  1406. XORPut:
  1407. begin
  1408. { getpixel wants local/relative coordinates }
  1409. Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
  1410. Color := CurrentColor Xor Color;
  1411. end;
  1412. OrPut:
  1413. begin
  1414. { getpixel wants local/relative coordinates }
  1415. Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
  1416. Color := CurrentColor Or Color;
  1417. end;
  1418. AndPut:
  1419. begin
  1420. { getpixel wants local/relative coordinates }
  1421. Color := GetPixVESA16(x-StartXViewPort,y-StartYViewPort);
  1422. Color := CurrentColor And Color;
  1423. end;
  1424. NotPut:
  1425. begin
  1426. Color := Not Color;
  1427. end
  1428. else
  1429. Color := CurrentColor;
  1430. end;
  1431. offs := longint(y) * BytesPerLine + (x div 8);
  1432. SetWriteBank(integer(offs shr 16));
  1433. PortW[$3ce] := $0f01; { Index 01 : Enable ops on all 4 planes }
  1434. PortW[$3ce] := color shl 8; { Index 00 : Enable correct plane and write color }
  1435. Port[$3ce] := 8; { Index 08 : Bitmask register. }
  1436. Port[$3cf] := $80 shr (x and $7); { Select correct bits to modify }
  1437. dummy := Mem[WinWriteSeg: offs]; { Latch the data into host space. }
  1438. Mem[WinWriteSeg: offs] := dummy; { Write the data into video memory }
  1439. PortW[$3ce] := $ff08; { Enable all bit planes. }
  1440. PortW[$3ce] := $0001; { Index 01 : Disable ops on all four planes. }
  1441. end;
  1442. {************************************************************************}
  1443. {* VESA Palette entries *}
  1444. {************************************************************************}
  1445. {$IFDEF DPMI}
  1446. Procedure SetVESARGBPalette(ColorNum, RedValue, GreenValue,
  1447. BlueValue : Integer);
  1448. var
  1449. pal: palrec;
  1450. regs: TDPMIRegisters;
  1451. Ptr: longint;
  1452. {$ifndef fpc}
  1453. PalPtr : ^PalRec;
  1454. {$endif fpc}
  1455. RealSeg: word;
  1456. FunctionNr : byte; { use blankbit or normal RAMDAC programming? }
  1457. begin
  1458. if DirectColor then
  1459. Begin
  1460. _GraphResult := grError;
  1461. exit;
  1462. end;
  1463. pal.align := 0;
  1464. pal.red := byte(RedValue);
  1465. pal.green := byte(GreenValue);
  1466. pal.blue := byte(BlueValue);
  1467. { use the set/get palette function }
  1468. if VESAInfo.Version >= $0200 then
  1469. Begin
  1470. { check if blanking bit must be set when programming }
  1471. { the RAMDAC. }
  1472. if (VESAInfo.caps and attrSnowCheck) <> 0 then
  1473. FunctionNr := $80
  1474. else
  1475. FunctionNr := $00;
  1476. { Alllocate real mode buffer }
  1477. {$ifndef fpc}
  1478. Ptr:=GlobalDosAlloc(sizeof(palrec));
  1479. { get the selector values }
  1480. PalPtr := pointer(Ptr shl 16);
  1481. if not assigned(PalPtr) then
  1482. RunError(203);
  1483. {$else fpc}
  1484. Ptr:=Global_Dos_Alloc(sizeof(palrec));
  1485. {$endif fpc}
  1486. {get the segment value}
  1487. RealSeg := word(Ptr shr 16);
  1488. { setup interrupt registers }
  1489. FillChar(regs, sizeof(regs), #0);
  1490. { copy palette values to real mode buffer }
  1491. {$ifndef fpc}
  1492. move(pal, palptr^, sizeof(pal));
  1493. {$else fpc}
  1494. DosMemPut(RealSeg,0,pal,sizeof(pal));
  1495. {$endif fpc}
  1496. regs.eax := $4F09;
  1497. regs.ebx := FunctionNr;
  1498. regs.ecx := $01;
  1499. regs.edx := ColorNum;
  1500. regs.es := RealSeg;
  1501. regs.edi := 0; { offset is always zero }
  1502. RealIntr($10, regs);
  1503. { free real mode memory }
  1504. {$ifndef fpc}
  1505. GlobalDosFree(word(Ptr and $ffff));
  1506. {$else fpc}
  1507. If not Global_Dos_Free(word(Ptr and $ffff)) then
  1508. RunError(216);
  1509. {$endif fpc}
  1510. if word(regs.eax) <> $004F then
  1511. begin
  1512. _GraphResult := grError;
  1513. exit;
  1514. end;
  1515. end
  1516. else
  1517. { assume it's fully VGA compatible palette-wise. }
  1518. Begin
  1519. SetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1520. end;
  1521. end;
  1522. Procedure GetVESARGBPalette(ColorNum: integer; Var
  1523. RedValue, GreenValue, BlueValue : integer);
  1524. var
  1525. pal: PalRec;
  1526. {$ifndef fpc}
  1527. palptr : ^PalRec;
  1528. {$endif fpc}
  1529. regs : TDPMIRegisters;
  1530. RealSeg: word;
  1531. ptr: longint;
  1532. begin
  1533. if DirectColor then
  1534. Begin
  1535. _GraphResult := grError;
  1536. exit;
  1537. end;
  1538. { use the set/get palette function }
  1539. if VESAInfo.Version >= $0200 then
  1540. Begin
  1541. { Alllocate real mode buffer }
  1542. {$ifndef fpc}
  1543. Ptr:=GlobalDosAlloc(sizeof(palrec));
  1544. { get the selector value }
  1545. PalPtr := pointer(longint(Ptr and $0000ffff) shl 16);
  1546. if not assigned(PalPtr) then
  1547. RunError(203);
  1548. {$else fpc}
  1549. Ptr:=Global_Dos_Alloc(sizeof(palrec));
  1550. {$endif fpc}
  1551. { get the segment value }
  1552. RealSeg := word(Ptr shr 16);
  1553. { setup interrupt registers }
  1554. FillChar(regs, sizeof(regs), #0);
  1555. regs.eax := $4F09;
  1556. regs.ebx := $01; { get palette data }
  1557. regs.ecx := $01;
  1558. regs.edx := ColorNum;
  1559. regs.es := RealSeg;
  1560. regs.edi := 0; { offset is always zero }
  1561. RealIntr($10, regs);
  1562. { copy to protected mode buffer ... }
  1563. {$ifndef fpc}
  1564. Move(PalPtr^, Pal, sizeof(pal));
  1565. {$else fpc}
  1566. DosMemGet(RealSeg,0,Pal,sizeof(pal));
  1567. {$endif fpc}
  1568. { free real mode memory }
  1569. {$ifndef fpc}
  1570. GlobalDosFree(word(Ptr and $ffff));
  1571. {$else fpc}
  1572. If not Global_Dos_Free(word(Ptr and $ffff)) then
  1573. RunError(216);
  1574. {$endif fpc}
  1575. if word(regs.eax) <> $004F then
  1576. begin
  1577. _GraphResult := grError;
  1578. exit;
  1579. end
  1580. else
  1581. begin
  1582. RedValue := Integer(pal.Red);
  1583. GreenValue := Integer(pal.Green);
  1584. BlueValue := Integer(pal.Blue);
  1585. end;
  1586. end
  1587. else
  1588. GetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1589. end;
  1590. {$ELSE}
  1591. Procedure SetVESARGBPalette(ColorNum, RedValue, GreenValue,
  1592. BlueValue : Integer); far;
  1593. var
  1594. FunctionNr : byte; { use blankbit or normal RAMDAC programming? }
  1595. pal: ^palrec;
  1596. Error : boolean; { VBE call error }
  1597. begin
  1598. if DirectColor then
  1599. Begin
  1600. _GraphResult := grError;
  1601. exit;
  1602. end;
  1603. Error := FALSE;
  1604. new(pal);
  1605. if not assigned(pal) then RunError(203);
  1606. pal^.align := 0;
  1607. pal^.red := byte(RedValue);
  1608. pal^.green := byte(GreenValue);
  1609. pal^.blue := byte(BlueValue);
  1610. { use the set/get palette function }
  1611. if VESAInfo.Version >= $0200 then
  1612. Begin
  1613. { check if blanking bit must be set when programming }
  1614. { the RAMDAC. }
  1615. if (VESAInfo.caps and attrSnowCheck) <> 0 then
  1616. FunctionNr := $80
  1617. else
  1618. FunctionNr := $00;
  1619. asm
  1620. mov ax, 4F09h { Set/Get Palette data }
  1621. mov bl, [FunctionNr] { Set palette data }
  1622. mov cx, 01h { update one palette reg. }
  1623. mov dx, [ColorNum] { register number to update }
  1624. les di, [pal] { get palette address }
  1625. int 10h
  1626. cmp ax, 004Fh { check if success }
  1627. jz @noerror
  1628. mov [Error], TRUE
  1629. @noerror:
  1630. end;
  1631. if not Error then
  1632. Dispose(pal)
  1633. else
  1634. begin
  1635. _GraphResult := grError;
  1636. exit;
  1637. end;
  1638. end
  1639. else
  1640. { assume it's fully VGA compatible palette-wise. }
  1641. Begin
  1642. SetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1643. end;
  1644. end;
  1645. Procedure GetVESARGBPalette(ColorNum: integer; Var RedValue, GreenValue,
  1646. BlueValue : integer); far;
  1647. var
  1648. Error: boolean;
  1649. pal: ^palrec;
  1650. begin
  1651. if DirectColor then
  1652. Begin
  1653. _GraphResult := grError;
  1654. exit;
  1655. end;
  1656. Error := FALSE;
  1657. new(pal);
  1658. if not assigned(pal) then RunError(203);
  1659. FillChar(pal^, sizeof(palrec), #0);
  1660. { use the set/get palette function }
  1661. if VESAInfo.Version >= $0200 then
  1662. Begin
  1663. asm
  1664. mov ax, 4F09h { Set/Get Palette data }
  1665. mov bl, 01h { Set palette data }
  1666. mov cx, 01h { update one palette reg. }
  1667. mov dx, [ColorNum] { register number to update }
  1668. les di, [pal] { get palette address }
  1669. int 10h
  1670. cmp ax, 004Fh { check if success }
  1671. jz @noerror
  1672. mov [Error], TRUE
  1673. @noerror:
  1674. end;
  1675. if not Error then
  1676. begin
  1677. RedValue := Integer(pal^.Red);
  1678. GreenValue := Integer(pal^.Green);
  1679. BlueValue := Integer(pal^.Blue);
  1680. Dispose(pal);
  1681. end
  1682. else
  1683. begin
  1684. _GraphResult := grError;
  1685. exit;
  1686. end;
  1687. end
  1688. else
  1689. GetVGARGBPalette(ColorNum, RedValue, GreenValue, BlueValue);
  1690. end;
  1691. {$ENDIF}
  1692. function SetupLinear(var ModeInfo: TVESAModeInfo;mode : word) : boolean;
  1693. begin
  1694. {$ifndef FPC}
  1695. { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
  1696. SetUpLinear:=false;
  1697. {$else FPC}
  1698. case mode of
  1699. m320x200x32k,
  1700. m320x200x64k,
  1701. m640x480x32k,
  1702. m640x480x64k,
  1703. m800x600x32k,
  1704. m800x600x64k,
  1705. m1024x768x32k,
  1706. m1024x768x64k,
  1707. m1280x1024x32k,
  1708. m1280x1024x64k :
  1709. begin
  1710. DirectPutPixel:=@DirectPutPixVESA32kor64kLinear;
  1711. PutPixel:=@PutPixVESA32kor64kLinear;
  1712. GetPixel:=@GetPixVESA32kor64kLinear;
  1713. { linear mode for lines not yet implemented PM }
  1714. HLine:=@HLineDefault;
  1715. VLine:=@VLineDefault;
  1716. end;
  1717. m640x400x256,
  1718. m640x480x256,
  1719. m800x600x256,
  1720. m1024x768x256,
  1721. m1280x1024x256:
  1722. begin
  1723. DirectPutPixel:=@DirectPutPixVESA256Linear;
  1724. PutPixel:=@PutPixVESA256Linear;
  1725. GetPixel:=@GetPixVESA256Linear;
  1726. { linear mode for lines not yet implemented PM }
  1727. HLine:=@HLineDefault;
  1728. VLine:=@VLineDefault;
  1729. end;
  1730. else
  1731. begin
  1732. SetUpLinear:=false;
  1733. exit;
  1734. end;
  1735. end;
  1736. FrameBufferLinearAddress:=Get_linear_addr(VESAModeInfo.PhysAddress and $FFFF0000,
  1737. VESAInfo.TotalMem shl 16);
  1738. if int31error<>0 then
  1739. writeln(stderr,'Unable to get linear address for ',hexstr(VESAModeInfo.PhysAddress,8));
  1740. set_segment_base_address(WinWriteSeg,FrameBufferLinearAddress);
  1741. set_segment_limit(WinWriteSeg,(VESAInfo.TotalMem shl 16)-1);
  1742. set_segment_base_address(WinReadSeg,FrameBufferLinearAddress);
  1743. set_segment_limit(WinReadSeg,(VESAInfo.TotalMem shl 16)-1);
  1744. InLinear:=true;
  1745. SetUpLinear:=true;
  1746. { WinSize:=(VGAInfo.TotalMem shl 16);
  1747. WinLoMask:=(VGAInfo.TotalMem shl 16)-1;
  1748. WinShift:=15;
  1749. Temp:=VGAInfo.TotalMem;
  1750. while Temp>0 do
  1751. begin
  1752. inc(WinShift);
  1753. Temp:=Temp shr 1;
  1754. end; }
  1755. {$endif FPC}
  1756. end;
  1757. procedure SetupWindows(var ModeInfo: TVESAModeInfo);
  1758. begin
  1759. InLinear:=false;
  1760. { now we check the windowing scheme ...}
  1761. if (ModeInfo.WinAAttr and WinSupported) <> 0 then
  1762. { is this window supported ... }
  1763. begin
  1764. { now check if the window is R/W }
  1765. if (ModeInfo.WinAAttr and WinReadable) <> 0 then
  1766. begin
  1767. ReadWindow := 0;
  1768. WinReadSeg := ModeInfo.WinASeg;
  1769. end;
  1770. if (ModeInfo.WinAAttr and WinWritable) <> 0 then
  1771. begin
  1772. WriteWindow := 0;
  1773. WinWriteSeg := ModeInfo.WinASeg;
  1774. end;
  1775. end;
  1776. if (ModeInfo.WinBAttr and WinSupported) <> 0 then
  1777. { is this window supported ... }
  1778. begin
  1779. { OPTIMIZATION ... }
  1780. { if window A supports both read/write, then we try to optimize }
  1781. { everything, by using a different window for Read and/or write.}
  1782. if (WinReadSeg <> 0) and (WinWriteSeg <> 0) then
  1783. begin
  1784. { check if winB supports read }
  1785. if (ModeInfo.WinBAttr and winReadable) <> 0 then
  1786. begin
  1787. WinReadSeg := ModeInfo.WinBSeg;
  1788. ReadWindow := 1;
  1789. end
  1790. else
  1791. { check if WinB supports write }
  1792. if (ModeInfo.WinBAttr and WinWritable) <> 0 then
  1793. begin
  1794. WinWriteSeg := ModeInfo.WinBSeg;
  1795. WriteWindow := 1;
  1796. end;
  1797. end
  1798. else
  1799. { Window A only supported Read OR Write, no we have to make }
  1800. { sure that window B supports the other mode. }
  1801. if (WinReadSeg = 0) and (WinWriteSeg<>0) then
  1802. begin
  1803. if (ModeInfo.WinBAttr and WinReadable <> 0) then
  1804. begin
  1805. ReadWindow := 1;
  1806. WinReadSeg := ModeInfo.WinBSeg;
  1807. end
  1808. else
  1809. { impossible, this VESA mode is WRITE only! }
  1810. begin
  1811. WriteLn('Invalid VESA Window attribute.');
  1812. Halt(255);
  1813. end;
  1814. end
  1815. else
  1816. if (winWriteSeg = 0) and (WinReadSeg<>0) then
  1817. begin
  1818. if (ModeInfo.WinBAttr and WinWritable) <> 0 then
  1819. begin
  1820. WriteWindow := 1;
  1821. WinWriteSeg := ModeInfo.WinBSeg;
  1822. end
  1823. else
  1824. { impossible, this VESA mode is READ only! }
  1825. begin
  1826. WriteLn('Invalid VESA Window attribute.');
  1827. Halt(255);
  1828. end;
  1829. end
  1830. else
  1831. if (winReadSeg = 0) and (winWriteSeg = 0) then
  1832. { no read/write in this mode! }
  1833. begin
  1834. WriteLn('Invalid VESA Window attribute.');
  1835. Halt(255);
  1836. end;
  1837. end;
  1838. { if both windows are not supported, then we can assume }
  1839. { that there is ONE single NON relocatable window. }
  1840. if (WinWriteSeg = 0) and (WinReadSeg = 0) then
  1841. begin
  1842. WinWriteSeg := ModeInfo.WinASeg;
  1843. WinReadSeg := ModeInfo.WinASeg;
  1844. end;
  1845. { 16-bit Protected mode checking code... }
  1846. { change segment values to protected mode }
  1847. { selectors. }
  1848. if WinReadSeg = $A000 then
  1849. WinReadSeg := SegA000
  1850. else
  1851. if WinReadSeg = $B000 then
  1852. WinReadSeg := SegB000
  1853. else
  1854. if WinReadSeg = $B800 then
  1855. WinReadSeg := SegB800
  1856. else
  1857. begin
  1858. WriteLn('Invalid segment address.');
  1859. Halt(255);
  1860. end;
  1861. if WinWriteSeg = $A000 then
  1862. WinWriteSeg := SegA000
  1863. else
  1864. if WinWriteSeg = $B000 then
  1865. WinWriteSeg := SegB000
  1866. else
  1867. if WinWriteSeg = $B800 then
  1868. WinWriteSeg := SegB800
  1869. else
  1870. begin
  1871. WriteLn('Invalid segment address.');
  1872. Halt(255);
  1873. end;
  1874. end;
  1875. function setVESAMode(mode:word):boolean;
  1876. var i:word;
  1877. begin
  1878. { Init mode information, for compatibility with VBE < 1.1 }
  1879. FillChar(VESAModeInfo, sizeof(TVESAModeInfo), #0);
  1880. { get the video mode information }
  1881. if getVESAModeInfo(VESAmodeinfo, mode) then
  1882. begin
  1883. { checks if the hardware supports the video mode. }
  1884. if (VESAModeInfo.attr and modeAvail) = 0 then
  1885. begin
  1886. SetVESAmode := FALSE;
  1887. _GraphResult := grError;
  1888. exit;
  1889. end;
  1890. SetVESAMode := TRUE;
  1891. BankShift := 0;
  1892. while (64 shr BankShift) <> VESAModeInfo.WinGranularity do
  1893. Inc(BankShift);
  1894. CurrentWriteBank := -1;
  1895. CurrentReadBank := -1;
  1896. BytesPerLine := VESAModeInfo.BytesPerScanLine;
  1897. { These are the window adresses ... }
  1898. WinWriteSeg := 0; { This is the segment to use for writes }
  1899. WinReadSeg := 0; { This is the segment to use for reads }
  1900. ReadWindow := 0;
  1901. WriteWindow := 0;
  1902. { VBE 2.0 and higher supports >= non VGA linear buffer types...}
  1903. { this is backward compatible. }
  1904. if ((VESAModeInfo.Attr and ModeNoWindowed) <> 0) and
  1905. ((VESAModeInfo.Attr and ModeLinearBuffer) <> 0) then
  1906. begin
  1907. if not SetupLinear(VESAModeInfo,mode) then
  1908. SetUpWindows(VESAModeInfo);
  1909. end
  1910. else
  1911. { if linear and windowed is supported, then use windowed }
  1912. { method. }
  1913. SetUpWindows(VESAModeInfo);
  1914. {$ifdef logging}
  1915. LogLn('Entering vesa mode '+strf(mode));
  1916. LogLn('Read segment: $'+hexstr(winreadseg,4));
  1917. LogLn('Write segment: $'+hexstr(winwriteseg,4));
  1918. LogLn('Window granularity: '+strf(VESAModeInfo.WinGranularity)+'kb');
  1919. LogLn('Window size: '+strf(VESAModeInfo.winSize)+'kb');
  1920. LogLn('Bytes per line: '+strf(bytesperline));
  1921. {$endif logging}
  1922. asm
  1923. mov ax,4F02h
  1924. mov bx,mode
  1925. {$ifdef fpc}
  1926. push ebp
  1927. {$endif fpc}
  1928. int 10h
  1929. {$ifdef fpc}
  1930. pop ebp
  1931. {$endif fpc}
  1932. sub ax,004Fh
  1933. cmp ax,1
  1934. sbb al,al
  1935. {$ifndef ver0_99_12}
  1936. mov @RESULT,al
  1937. {$endif ver0_99_12}
  1938. end;
  1939. end;
  1940. end;
  1941. (*
  1942. function getVESAMode:word;assembler;
  1943. asm {return -1 if error}
  1944. mov ax,4F03h
  1945. {$ifdef fpc}
  1946. push ebp
  1947. {$endif fpc}
  1948. int 10h
  1949. {$ifdef fpc}
  1950. pop ebp
  1951. {$endif fpc}
  1952. cmp ax,004Fh
  1953. je @@OK
  1954. mov ax,-1
  1955. jmp @@X
  1956. @@OK:
  1957. mov ax,bx
  1958. @@X:
  1959. end;
  1960. *)
  1961. {************************************************************************}
  1962. {* VESA Modes inits *}
  1963. {************************************************************************}
  1964. {$IFDEF DPMI}
  1965. {******************************************************** }
  1966. { Function GetMaxScanLines() }
  1967. {-------------------------------------------------------- }
  1968. { This routine returns the maximum number of scan lines }
  1969. { possible for this mode. This is done using the Get }
  1970. { Scan Line length VBE function. }
  1971. {******************************************************** }
  1972. function GetMaxScanLines: word;
  1973. var
  1974. regs : TDPMIRegisters;
  1975. begin
  1976. FillChar(regs, sizeof(regs), #0);
  1977. { play it safe, call the real mode int, the 32-bit entry point }
  1978. { may not be defined as stated in VBE v3.0 }
  1979. regs.eax := $4f06; {_ setup function }
  1980. regs.ebx := $0001; { get scan line length }
  1981. RealIntr($10, regs);
  1982. GetMaxScanLines := (regs.edx and $0000ffff);
  1983. end;
  1984. {$ELSE}
  1985. function GetMaxScanLines: word; assembler;
  1986. asm
  1987. mov ax, 4f06h
  1988. mov bx, 0001h
  1989. int 10h
  1990. mov ax, dx
  1991. end;
  1992. {$ENDIF}
  1993. procedure Init1280x1024x64k; {$ifndef fpc}far;{$endif fpc}
  1994. begin
  1995. SetVesaMode(m1280x1024x64k);
  1996. { Get maximum number of scanlines for page flipping }
  1997. ScanLines := GetMaxScanLines;
  1998. end;
  1999. procedure Init1280x1024x32k; {$ifndef fpc}far;{$endif fpc}
  2000. begin
  2001. SetVESAMode(m1280x1024x32k);
  2002. { Get maximum number of scanlines for page flipping }
  2003. ScanLines := GetMaxScanLines;
  2004. end;
  2005. procedure Init1280x1024x256; {$ifndef fpc}far;{$endif fpc}
  2006. begin
  2007. SetVESAMode(m1280x1024x256);
  2008. { Get maximum number of scanlines for page flipping }
  2009. ScanLines := GetMaxScanLines;
  2010. end;
  2011. procedure Init1280x1024x16; {$ifndef fpc}far;{$endif fpc}
  2012. begin
  2013. SetVESAMode(m1280x1024x16);
  2014. { Get maximum number of scanlines for page flipping }
  2015. ScanLines := GetMaxScanLines;
  2016. end;
  2017. procedure Init1024x768x64k; {$ifndef fpc}far;{$endif fpc}
  2018. begin
  2019. SetVESAMode(m1024x768x64k);
  2020. { Get maximum number of scanlines for page flipping }
  2021. ScanLines := GetMaxScanLines;
  2022. end;
  2023. procedure Init640x480x32k; {$ifndef fpc}far;{$endif fpc}
  2024. begin
  2025. SetVESAMode(m640x480x32k);
  2026. { Get maximum number of scanlines for page flipping }
  2027. ScanLines := GetMaxScanLines;
  2028. end;
  2029. procedure Init1024x768x256; {$ifndef fpc}far;{$endif fpc}
  2030. begin
  2031. SetVESAMode(m1024x768x256);
  2032. { Get maximum number of scanlines for page flipping }
  2033. ScanLines := GetMaxScanLines;
  2034. end;
  2035. procedure Init1024x768x16; {$ifndef fpc}far;{$endif fpc}
  2036. begin
  2037. SetVESAMode(m1024x768x16);
  2038. { Get maximum number of scanlines for page flipping }
  2039. ScanLines := GetMaxScanLines;
  2040. end;
  2041. procedure Init800x600x64k; {$ifndef fpc}far;{$endif fpc}
  2042. begin
  2043. SetVESAMode(m800x600x64k);
  2044. { Get maximum number of scanlines for page flipping }
  2045. ScanLines := GetMaxScanLines;
  2046. end;
  2047. procedure Init800x600x32k; {$ifndef fpc}far;{$endif fpc}
  2048. begin
  2049. SetVESAMode(m800x600x32k);
  2050. { Get maximum number of scanlines for page flipping }
  2051. ScanLines := GetMaxScanLines;
  2052. end;
  2053. procedure Init800x600x256; {$ifndef fpc}far;{$endif fpc}
  2054. begin
  2055. SetVESAMode(m800x600x256);
  2056. { Get maximum number of scanlines for page flipping }
  2057. ScanLines := GetMaxScanLines;
  2058. end;
  2059. procedure Init800x600x16; {$ifndef fpc}far;{$endif fpc}
  2060. begin
  2061. SetVesaMode(m800x600x16);
  2062. { Get maximum number of scanlines for page flipping }
  2063. ScanLines := GetMaxScanLines;
  2064. end;
  2065. procedure Init640x480x64k; {$ifndef fpc}far;{$endif fpc}
  2066. begin
  2067. SetVESAMode(m640x480x64k);
  2068. { Get maximum number of scanlines for page flipping }
  2069. ScanLines := GetMaxScanLines;
  2070. end;
  2071. procedure Init640x480x256; {$ifndef fpc}far;{$endif fpc}
  2072. begin
  2073. SetVESAMode(m640x480x256);
  2074. { Get maximum number of scanlines for page flipping }
  2075. ScanLines := GetMaxScanLines;
  2076. end;
  2077. procedure Init640x400x256; {$ifndef fpc}far;{$endif fpc}
  2078. begin
  2079. SetVESAMode(m640x400x256);
  2080. { Get maximum number of scanlines for page flipping }
  2081. ScanLines := GetMaxScanLines;
  2082. end;
  2083. procedure Init320x200x64k; {$ifndef fpc}far;{$endif fpc}
  2084. begin
  2085. SetVESAMode(m320x200x64k);
  2086. { Get maximum number of scanlines for page flipping }
  2087. ScanLines := GetMaxScanLines;
  2088. end;
  2089. procedure Init320x200x32k; {$ifndef fpc}far;{$endif fpc}
  2090. begin
  2091. SetVESAMode(m320x200x32k);
  2092. { Get maximum number of scanlines for page flipping }
  2093. ScanLines := GetMaxScanLines;
  2094. end;
  2095. {$IFDEF DPMI}
  2096. Procedure SaveStateVESA; {$ifndef fpc}far;{$endif fpc}
  2097. var
  2098. PtrLong: longint;
  2099. regs: TDPMIRegisters;
  2100. begin
  2101. SaveSupported := FALSE;
  2102. SavePtr := nil;
  2103. {$ifdef logging}
  2104. LogLn('Get the video mode...');
  2105. {$endif logging}
  2106. { Get the video mode }
  2107. asm
  2108. mov ah,0fh
  2109. {$ifdef fpc}
  2110. push ebp
  2111. {$endif fpc}
  2112. int 10h
  2113. {$ifdef fpc}
  2114. pop ebp
  2115. {$endif fpc}
  2116. mov [VideoMode], al
  2117. end;
  2118. {$ifdef logging}
  2119. LogLn('Prepare to save VESA video state');
  2120. {$endif logging}
  2121. { Prepare to save video state...}
  2122. asm
  2123. mov ax, 4F04h { get buffer size to save state }
  2124. mov dx, 00h
  2125. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2126. {$ifdef fpc}
  2127. push ebp
  2128. {$endif fpc}
  2129. int 10h
  2130. {$ifdef fpc}
  2131. pop ebp
  2132. {$endif fpc}
  2133. mov [StateSize], bx
  2134. cmp al,04fh
  2135. jnz @notok
  2136. mov [SaveSupported],TRUE
  2137. @notok:
  2138. end;
  2139. regs.eax := $4f04;
  2140. regs.edx := $0000;
  2141. regs.ecx := $000F;
  2142. RealIntr($10, regs);
  2143. StateSize := word(regs.ebx);
  2144. if byte(regs.eax) = $4f then
  2145. SaveSupported := TRUE;
  2146. if SaveSupported then
  2147. begin
  2148. {$ifdef logging}
  2149. LogLn('allocating VESA save buffer of '+strf(64*StateSize));
  2150. {$endif logging}
  2151. {$ifndef fpc}
  2152. PtrLong:=GlobalDosAlloc(64*StateSize); { values returned in 64-byte blocks }
  2153. {$else fpc}
  2154. PtrLong:=Global_Dos_Alloc(64*StateSize); { values returned in 64-byte blocks }
  2155. {$endif fpc}
  2156. if PtrLong = 0 then
  2157. RunError(203);
  2158. SavePtr := pointer(longint(PtrLong and $0000ffff) shl 16);
  2159. {$ifndef fpc}
  2160. { In FPC mode, we can't do anything with this (no far pointers) }
  2161. { However, we still need to keep it to be able to free the }
  2162. { memory afterwards. Since this data is not accessed in PM code, }
  2163. { there's no need to save it in a seperate buffer (JM) }
  2164. if not assigned(SavePtr) then
  2165. RunError(203);
  2166. {$endif fpc}
  2167. RealStateSeg := word(PtrLong shr 16);
  2168. FillChar(regs, sizeof(regs), #0);
  2169. { call the real mode interrupt ... }
  2170. regs.eax := $4F04; { save the state buffer }
  2171. regs.ecx := $0F; { Save DAC / Data areas / Hardware states }
  2172. regs.edx := $01; { save state }
  2173. regs.es := RealStateSeg;
  2174. regs.ebx := 0;
  2175. RealIntr($10,regs);
  2176. FillChar(regs, sizeof(regs), #0);
  2177. { restore state, according to Ralph Brown Interrupt list }
  2178. { some BIOS corrupt the hardware after a save... }
  2179. regs.eax := $4F04; { restore the state buffer }
  2180. regs.ecx := $0F; { rest DAC / Data areas / Hardware states }
  2181. regs.edx := $02;
  2182. regs.es := RealStateSeg;
  2183. regs.ebx := 0;
  2184. RealIntr($10,regs);
  2185. end;
  2186. end;
  2187. procedure RestoreStateVESA; {$ifndef fpc}far;{$endif fpc}
  2188. var
  2189. regs:TDPMIRegisters;
  2190. begin
  2191. { go back to the old video mode...}
  2192. asm
  2193. mov ah,00
  2194. mov al,[VideoMode]
  2195. {$ifdef fpc}
  2196. push ebp
  2197. {$endif fpc}
  2198. int 10h
  2199. {$ifdef fpc}
  2200. pop ebp
  2201. {$endif fpc}
  2202. end;
  2203. { then restore all state information }
  2204. {$ifndef fpc}
  2205. if assigned(SavePtr) and (SaveSupported=TRUE) then
  2206. {$else fpc}
  2207. { No far pointer support, so it's possible that that assigned(SavePtr) }
  2208. { would return false under FPC. Just check if it's different from nil. }
  2209. if (SavePtr <> nil) and (SaveSupported=TRUE) then
  2210. {$endif fpc}
  2211. begin
  2212. FillChar(regs, sizeof(regs), #0);
  2213. { restore state, according to Ralph Brown Interrupt list }
  2214. { some BIOS corrupt the hardware after a save... }
  2215. regs.eax := $4F04; { restore the state buffer }
  2216. regs.ecx := $0F; { rest DAC / Data areas / Hardware states }
  2217. regs.edx := $02; { restore state }
  2218. regs.es := RealStateSeg;
  2219. regs.ebx := 0;
  2220. RealIntr($10,regs);
  2221. {$ifndef fpc}
  2222. if GlobalDosFree(longint(SavePtr) shr 16)<>0 then
  2223. {$else fpc}
  2224. if Not(Global_Dos_Free(longint(SavePtr) shr 16)) then
  2225. {$endif fpc}
  2226. RunError(216);
  2227. SavePtr := nil;
  2228. end;
  2229. end;
  2230. {$ELSE}
  2231. {**************************************************************}
  2232. {* Real mode routines *}
  2233. {**************************************************************}
  2234. Procedure SaveStateVESA; far;
  2235. begin
  2236. SavePtr := nil;
  2237. SaveSupported := FALSE;
  2238. { Get the video mode }
  2239. asm
  2240. mov ah,0fh
  2241. int 10h
  2242. mov [VideoMode], al
  2243. end;
  2244. { Prepare to save video state...}
  2245. asm
  2246. mov ax, 4f04h { get buffer size to save state }
  2247. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2248. mov dx, 00h
  2249. int 10h
  2250. mov [StateSize], bx
  2251. cmp al,04fh
  2252. jnz @notok
  2253. mov [SaveSupported],TRUE
  2254. @notok:
  2255. end;
  2256. if SaveSupported then
  2257. Begin
  2258. GetMem(SavePtr, 64*StateSize); { values returned in 64-byte blocks }
  2259. if not assigned(SavePtr) then
  2260. RunError(203);
  2261. asm
  2262. mov ax, 4F04h { save the state buffer }
  2263. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2264. mov dx, 01h
  2265. mov es, WORD PTR [SavePtr+2]
  2266. mov bx, WORD PTR [SavePtr]
  2267. int 10h
  2268. end;
  2269. { restore state, according to Ralph Brown Interrupt list }
  2270. { some BIOS corrupt the hardware after a save... }
  2271. asm
  2272. mov ax, 4F04h { save the state buffer }
  2273. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2274. mov dx, 02h
  2275. mov es, WORD PTR [SavePtr+2]
  2276. mov bx, WORD PTR [SavePtr]
  2277. int 10h
  2278. end;
  2279. end;
  2280. end;
  2281. procedure RestoreStateVESA; far;
  2282. begin
  2283. { go back to the old video mode...}
  2284. asm
  2285. mov ah,00
  2286. mov al,[VideoMode]
  2287. int 10h
  2288. end;
  2289. { then restore all state information }
  2290. if assigned(SavePtr) and (SaveSupported=TRUE) then
  2291. begin
  2292. { restore state, according to Ralph Brown Interrupt list }
  2293. asm
  2294. mov ax, 4F04h { save the state buffer }
  2295. mov cx, 00001111b { Save DAC / Data areas / Hardware states }
  2296. mov dx, 02h { restore state }
  2297. mov es, WORD PTR [SavePtr+2]
  2298. mov bx, WORD PTR [SavePtr]
  2299. int 10h
  2300. end;
  2301. FreeMem(SavePtr, 64*StateSize);
  2302. SavePtr := nil;
  2303. end;
  2304. end;
  2305. {$ENDIF DPMI}
  2306. {************************************************************************}
  2307. {* VESA Page flipping routines *}
  2308. {************************************************************************}
  2309. { Note: These routines, according to the VBE3 specification, will NOT }
  2310. { work with the 24 bpp modes, because of the alignment. }
  2311. {************************************************************************}
  2312. {******************************************************** }
  2313. { Procedure SetVisualVESA() }
  2314. {-------------------------------------------------------- }
  2315. { This routine changes the page which will be displayed }
  2316. { on the screen, since the method has changed somewhat }
  2317. { between VBE versions , we will use the old method where }
  2318. { the new pixel offset is used to display different pages }
  2319. {******************************************************** }
  2320. procedure SetVisualVESA(page: word); {$ifndef fpc}far;{$endif fpc}
  2321. var
  2322. newStartVisible : word;
  2323. begin
  2324. if page > HardwarePages then exit;
  2325. newStartVisible := (MaxY+1)*page;
  2326. if newStartVisible > ScanLines then exit;
  2327. asm
  2328. mov ax, 4f07h
  2329. mov bx, 0000h { set display start }
  2330. mov cx, 0000h { pixel zero ! }
  2331. mov dx, [NewStartVisible] { new scanline }
  2332. {$ifdef fpc}
  2333. push ebp
  2334. {$endif}
  2335. int 10h
  2336. {$ifdef fpc}
  2337. pop ebp
  2338. {$endif}
  2339. end;
  2340. end;
  2341. procedure SetActiveVESA(page: word); {$ifndef fpc}far;{$endif fpc}
  2342. begin
  2343. { video offset is in pixels under VESA VBE! }
  2344. { This value is reset after a mode set to page ZERO = YOffset = 0 ) }
  2345. YOffset := (MaxY+1)*page;
  2346. end;
  2347. (*
  2348. $Log$
  2349. Revision 1.18 2000-01-07 16:41:32 daniel
  2350. * copyright 2000
  2351. Revision 1.17 2000/01/07 16:32:24 daniel
  2352. * copyright 2000 added
  2353. Revision 1.16 2000/01/06 15:19:42 jonas
  2354. * fixed bug in getscanlinevesa256 and hlinevesa256 for short lines (<8 pixels)
  2355. Revision 1.15 2000/01/02 18:51:05 jonas
  2356. * again small fix to patternline-, hline- and getscanlinevesa256
  2357. Revision 1.14 1999/12/29 12:15:41 jonas
  2358. * fixed small bug in hlinevesa256, getscanlinevesa25 and patternlinevesa256
  2359. * small speed-up in the above procedures
  2360. Revision 1.13 1999/12/27 12:10:57 jonas
  2361. * fixed VESA palrec structure
  2362. Revision 1.12 1999/12/26 10:36:00 jonas
  2363. * finished patternlineVESA256 and enabled it
  2364. * folded (direct)put/getpixVESA32k and 64k into one procedure since
  2365. they were exactly the same code
  2366. Revision 1.11 1999/12/25 22:31:09 jonas
  2367. + patternlineVESA256, not yet used because I'm not yet sure it's
  2368. already working 100%
  2369. * changed {$ifdef logging} to {$ifdef logging2} for vlineVESA256 and
  2370. hlineVESA256 (they're used a lot a working properly afaik)
  2371. Revision 1.10 1999/12/21 17:42:17 jonas
  2372. * changed vesa.inc so it doesn't try to use linear modes anymore (doesn't work
  2373. yet!!)
  2374. * fixed mode detection so the low modenumber of a driver doesn't have to be zero
  2375. anymore (so VESA autodetection now works)
  2376. Revision 1.9 1999/12/12 13:34:20 jonas
  2377. * putimage now performs the lipping itself and uses directputpixel
  2378. (note: this REQUIRES or/and/notput support in directputpixel,
  2379. this is not yet the case in the assembler versions!)
  2380. * YOffset addition moved in hlinevesa256 and vlinevesa256
  2381. because it uses still putpixel afterwards
  2382. Revision 1.8 1999/12/11 23:41:39 jonas
  2383. * changed definition of getscanlineproc to "getscanline(x1,x2,y:
  2384. integer; var data);" so it can be used by getimage too
  2385. * changed getimage so it uses getscanline
  2386. * changed floodfill, getscanline16 and definitions in Linux
  2387. include files so they use this new format
  2388. + getscanlineVESA256 for 256 color VESA modes (banked)
  2389. Revision 1.7 1999/12/10 12:52:54 pierre
  2390. * some LinearFrameBuffer code, not finished
  2391. Revision 1.6 1999/12/09 02:06:00 carl
  2392. + page flipping for all VESA modes.
  2393. (important note: The VESAModeInfo structure returns the MAXIMUM
  2394. number of image pages, and not the actual available number of
  2395. pages (cf. VBE 3.0 specification), that is the reason why
  2396. SetVisualPage() has so much checking).
  2397. Revision 1.5 1999/12/02 22:34:14 pierre
  2398. * avoid FPC problem in array of char comp
  2399. Revision 1.4 1999/11/30 02:25:15 carl
  2400. * GetPixVESA16 bugfix with read segment.
  2401. Revision 1.3 1999/11/28 12:18:39 jonas
  2402. + all available mode numbers are logged if you compile the unit with
  2403. -dlogging
  2404. Revision 1.2 1999/11/27 21:48:01 jonas
  2405. * fixed VlineVESA256 and re-enabled it in graph.inc
  2406. * added procedure detectgraph to interface of graph unit
  2407. Revision 1.1 1999/11/08 11:15:21 peter
  2408. * move graph.inc to the target dir
  2409. Revision 1.21 1999/11/03 20:23:01 florian
  2410. + first release of win32 gui support
  2411. Revision 1.20 1999/10/24 15:50:23 carl
  2412. * Bugfix in TP mode SaveStateVESA
  2413. Revision 1.19 1999/10/24 03:37:15 carl
  2414. + GetPixVESA16 (not tested yet...)
  2415. Revision 1.18 1999/09/28 13:56:31 jonas
  2416. * reordered some local variables (first 4 byte vars, then 2 byte vars
  2417. etc)
  2418. * font data is now disposed in exitproc, exitproc is now called
  2419. GraphExitProc (was CleanModes) and resides in graph.pp instead of in
  2420. modes.inc
  2421. Revision 1.17 1999/09/27 23:34:42 peter
  2422. * new graph unit is default for go32v2
  2423. * removed warnings/notes
  2424. Revision 1.16 1999/09/26 13:31:07 jonas
  2425. * changed name of modeinfo variable to vesamodeinfo and fixed
  2426. associated errors (fillchar(modeinfo,sizeof(tmodeinfo),#0) instead
  2427. of sizeof(TVesamodeinfo) etc)
  2428. * changed several sizeof(type) to sizeof(varname) to avoid similar
  2429. errors in the future
  2430. Revision 1.15 1999/09/24 22:52:39 jonas
  2431. * optimized patternline a bit (always use hline when possible)
  2432. * isgraphmode stuff cleanup
  2433. * vesainfo.modelist now gets disposed in cleanmode instead of in
  2434. closegraph (required moving of some declarations from vesa.inc to
  2435. new vesah.inc)
  2436. * queryadapter gets no longer called from initgraph (is called from
  2437. initialization of graph unit)
  2438. * bugfix for notput in 32k and 64k vesa modes
  2439. * a div replaced by / in fillpoly
  2440. Revision 1.14 1999/09/23 14:00:42 jonas
  2441. * -dlogging no longer required to fuction correctly
  2442. * some typo's fixed
  2443. Revision 1.13 1999/09/20 09:34:30 florian
  2444. * conflicts solved
  2445. Revision 1.12 1999/09/18 22:21:11 jonas
  2446. + hlinevesa256 and vlinevesa256
  2447. + support for not/xor/or/andput in vesamodes with 32k/64k colors
  2448. * lots of changes to avoid warnings under FPC
  2449. Revision 1.11 1999/09/15 11:40:30 jonas
  2450. * fixed PutPixVESA256
  2451. Revision 1.10 1999/09/11 19:43:02 jonas
  2452. * FloodFill: did not take into account current viewport settings
  2453. * GetScanLine: only get line inside viewport, data outside of it
  2454. is not used anyway
  2455. * InternalEllipseDefault: fix for when xradius or yradius = 0 and
  2456. increase xradius and yradius always by one (TP does this too)
  2457. * fixed conlict in vesa.inc from last update
  2458. * some conditionals to avoid range check and overflow errors in
  2459. places where it doesn't matter
  2460. Revision 1.9 1999/08/01 14:51:07 jonas
  2461. * removed and/or/xorput support from vesaputpix256 (not in TP either)
  2462. * added notput support to directputpix256
  2463. Revision 1.8 1999/07/18 15:07:21 jonas
  2464. + xor-, and- and orput support for VESA256 modes
  2465. * compile with -dlogging if you wnt some info to be logged to grlog.txt
  2466. Revision 1.7 1999/07/14 15:21:49 jonas
  2467. * fixed initialization of bankshift var ('64 shr banshift' instead of shl)
  2468. Revision 1.6 1999/07/14 13:17:29 jonas
  2469. * bugfix in getmodeinfo (SizeOf(TModeInfo) -> SizeOf(TVESAModeInfo))
  2470. * as the result of the above bugfix, the graph unit doesn't crash
  2471. anymore under FPC if compiler with -dsupportVESA, but it doesn't
  2472. work yet either...
  2473. Revision 1.5 1999/07/12 13:28:33 jonas
  2474. * forgot log tag in previous commit
  2475. *)