vesa.inc 93 KB

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