console.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. {$MACRO ON}
  2. {$DEFINE DEFAULT_WIDTH:=320}
  3. {$DEFINE DEFAULT_HEIGHT:=200}
  4. {$DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF)}
  5. { $DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF)}
  6. Constructor VESAConsole.Create;
  7. Var
  8. I, J : Integer;
  9. r, g, b, a : DWord;
  10. tmpbpp : Integer;
  11. tmp : TPTCFormat;
  12. Begin
  13. m_modes := Nil;
  14. m_modes_n := Nil;
  15. m_keyboard := Nil;
  16. m_open := False;
  17. m_locked := False;
  18. m_default_format := Nil;
  19. m_palette := Nil;
  20. m_copy := Nil;
  21. m_area := Nil;
  22. m_clip := Nil;
  23. m_title := '';
  24. m_information := '';
  25. m_default_width := DEFAULT_WIDTH;
  26. m_default_height := DEFAULT_HEIGHT;
  27. m_default_format := DEFAULT_FORMAT;
  28. InitVESA;
  29. m_primary := Nil;
  30. m_modes_last := -1;
  31. For I := 0 To NrOfModes Do
  32. With ModeInfo[I].VesaModeInfo Do
  33. If (MemoryModel = 6) And
  34. ((BitsPerPixel = 8) Or
  35. (BitsPerPixel = 15) Or
  36. (BitsPerPixel = 16) Or
  37. (BitsPerPixel = 24) Or
  38. (BitsPerPixel = 32)) Then
  39. Inc(m_modes_last)
  40. Else
  41. If (MemoryModel = 4) And (BitsPerPixel = 8) Then
  42. Inc(m_modes_last, 2);
  43. GetMem(m_modes, (m_modes_last + 2) * SizeOf(TPTCMode));
  44. FillChar(m_modes^, (m_modes_last + 2) * SizeOf(TPTCMode), 0);
  45. GetMem(m_modes_n, (m_modes_last + 1) * SizeOf(Integer));
  46. // Writeln(m_modes_last, ' ', NrOfModes);
  47. m_modes[m_modes_last + 1] := TPTCMode.Create; {mark end of list!}
  48. J := -1;
  49. For I := 0 To NrOfModes Do
  50. With ModeInfo[I].VesaModeInfo Do
  51. If (MemoryModel = 6) And
  52. ((BitsPerPixel = 8) Or
  53. (BitsPerPixel = 15) Or
  54. (BitsPerPixel = 16) Or
  55. (BitsPerPixel = 24) Or
  56. (BitsPerPixel = 32)) Then
  57. Begin
  58. Inc(J);
  59. r := MakeMask(RedMaskSize, RedFieldPosition);
  60. g := MakeMask(GreenMaskSize, GreenFieldPosition);
  61. b := MakeMask(BlueMaskSize, BlueFieldPosition);
  62. {a := MakeMask(RsvdMaskSize, RsvdFieldPosition);}
  63. a := 0;
  64. If BitsPerPixel = 15 Then
  65. tmpbpp := 16
  66. Else
  67. tmpbpp := BitsPerPixel;
  68. tmp := TPTCFormat.Create(tmpbpp, r, g, b, a);
  69. Try
  70. m_modes[J] := TPTCMode.Create(XResolution, YResolution, tmp);
  71. m_modes_n[J] := I;
  72. Finally
  73. tmp.Destroy;
  74. End;
  75. { Inc(m_modes_last)}
  76. End
  77. Else
  78. If (MemoryModel = 4) And (BitsPerPixel = 8) Then
  79. Begin
  80. Inc(J);
  81. tmp := TPTCFormat.Create(8);
  82. Try
  83. m_modes[J] := TPTCMode.Create(XResolution, YResolution, tmp);
  84. m_modes_n[J] := I;
  85. Finally
  86. tmp.Destroy;
  87. End;
  88. Inc(J);
  89. tmp := TPTCFormat.Create(8, $E0, $1C, $03); {RGB 332}
  90. Try
  91. m_modes[J] := TPTCMode.Create(XResolution, YResolution, tmp);
  92. m_modes_n[J] := I;
  93. Finally
  94. tmp.Destroy;
  95. End;
  96. { Inc(m_modes_last, 2);}
  97. End;
  98. m_clip := TPTCArea.Create;
  99. m_area := TPTCArea.Create;
  100. m_copy := TPTCCopy.Create;
  101. m_palette := TPTCPalette.Create;
  102. configure('ptc.cfg');
  103. End;
  104. Destructor VESAConsole.Destroy;
  105. Var
  106. I : Integer;
  107. Begin
  108. close;
  109. If m_modes <> Nil Then
  110. For I := 0 To m_modes_last + 1 Do
  111. If m_modes[I] <> Nil Then
  112. m_modes[I].Destroy;
  113. If m_modes <> Nil Then
  114. FreeMem(m_modes);
  115. If m_modes_n <> Nil Then
  116. FreeMem(m_modes_n);
  117. If m_keyboard <> Nil Then
  118. m_keyboard.Destroy;
  119. If m_copy <> Nil Then
  120. m_copy.Destroy;
  121. If m_default_format <> Nil Then
  122. m_default_format.Destroy;
  123. If m_palette <> Nil Then
  124. m_palette.Destroy;
  125. If m_area <> Nil Then
  126. m_area.Destroy;
  127. If m_clip <> Nil Then
  128. m_clip.Destroy;
  129. Inherited Destroy;
  130. End;
  131. Procedure VESAConsole.configure(Const _file : String);
  132. Var
  133. F : Text;
  134. S : String;
  135. Begin
  136. ASSignFile(F, _file);
  137. {$I-}
  138. Reset(F);
  139. {$I+}
  140. If IOResult <> 0 Then
  141. Exit;
  142. While Not EoF(F) Do
  143. Begin
  144. {$I-}
  145. Readln(F, S);
  146. {$I+}
  147. If IOResult <> 0 Then
  148. Break;
  149. option(S);
  150. End;
  151. CloseFile(F);
  152. End;
  153. Function VESAConsole.option(Const _option : String) : Boolean;
  154. Begin
  155. {...}
  156. option := m_copy.option(_option);
  157. End;
  158. Function VESAConsole.modes : PPTCMode;
  159. Begin
  160. {todo...}
  161. modes := m_modes;
  162. End;
  163. Procedure VESAConsole.open(Const _title : String; _pages : Integer); Overload;
  164. Begin
  165. open(_title, m_default_format, _pages);
  166. End;
  167. Procedure VESAConsole.open(Const _title : String; Const _format : TPTCFormat;
  168. _pages : Integer); Overload;
  169. Begin
  170. open(_title, m_default_width, m_default_height, _format, _pages);
  171. End;
  172. Procedure VESAConsole.open(Const _title : String; _width, _height : Integer;
  173. Const _format : TPTCFormat; _pages : Integer); Overload;
  174. Var
  175. m : TPTCMode;
  176. Begin
  177. m := TPTCMode.Create(_width, _height, _format);
  178. Try
  179. open(_title, m, _pages);
  180. Finally
  181. m.Destroy;
  182. End;
  183. End;
  184. Procedure VESAConsole.open(Const _title : String; Const _mode : TPTCMode;
  185. _pages : Integer); Overload;
  186. Var
  187. { _width, _height : Integer;
  188. _format : TPTCFormat;}
  189. I : Integer;
  190. modefound, bestmodefound : Integer;
  191. x, y, bpp : Integer;
  192. Begin
  193. If Not _mode.valid Then
  194. Raise TPTCError.Create('invalid mode');
  195. modefound := -1;
  196. For I := 0 To m_modes_last Do
  197. If m_modes[I].Equals(_mode) Then
  198. Begin
  199. modefound := I;
  200. Break;
  201. End;
  202. { If modefound = -1 Then
  203. Raise TPTCError.Create('mode not found >:)');}
  204. bestmodefound := -1;
  205. If (modefound = -1) And (_mode.format.direct) Then
  206. Begin
  207. x := 100000000;
  208. y := x;
  209. bpp := -1;
  210. For I := 0 To m_modes_last Do
  211. If (m_modes[i].width >= _mode.width) And
  212. (m_modes[i].height >= _mode.height) And
  213. (m_modes[i].width <= x) And
  214. (m_modes[i].height <= y) And
  215. (((m_modes[i].format.bits >= bpp) And
  216. (bpp < _mode.format.bits)) Or
  217. ((m_modes[i].format.bits < bpp) And
  218. (m_modes[i].format.bits >= _mode.format.bits) And
  219. (bpp > _mode.format.bits))) Then
  220. Begin
  221. bestmodefound := I;
  222. x := m_modes[i].width;
  223. y := m_modes[i].height;
  224. bpp := m_modes[i].format.bits;
  225. End;
  226. { If m_modes[I].bpp >= Then
  227. Begin
  228. modefound := I;
  229. Break;
  230. End;}
  231. End;
  232. If (modefound = -1) And (_mode.format.indexed) Then
  233. Begin
  234. x := 100000000;
  235. y := x;
  236. bpp := -1;
  237. For I := 0 To m_modes_last Do
  238. If (m_modes[i].width >= _mode.width) And
  239. (m_modes[i].height >= _mode.height) And
  240. (m_modes[i].width <= x) And
  241. (m_modes[i].height <= y) { And
  242. (((m_modes[i].format.bits >= bpp) And
  243. (bpp < _mode.format.bits)) Or
  244. ((m_modes[i].format.bits < bpp) And
  245. (m_modes[i].format.bits >= _mode.format.bits) And
  246. (bpp > _mode.format.bits)))} Then
  247. Begin
  248. If (m_modes[i].width <> x) Or (m_modes[i].height <> y) Then
  249. bpp := -1;
  250. If m_modes[i].format.indexed Or
  251. (m_modes[i].format.bits > bpp) Then
  252. Begin
  253. bestmodefound := I;
  254. x := m_modes[i].width;
  255. y := m_modes[i].height;
  256. bpp := m_modes[i].format.bits;
  257. If m_modes[i].format.indexed Then
  258. bpp := 1000;
  259. End;
  260. End;
  261. { If m_modes[I].bpp >= Then
  262. Begin
  263. modefound := I;
  264. Break;
  265. End;}
  266. End;
  267. If bestmodefound <> -1 Then
  268. modefound := bestmodefound;
  269. // Writeln('mf', modefound);
  270. // Readln;
  271. If modefound = -1 Then
  272. Raise TPTCError.Create('mode not found >:)');
  273. { _width := _mode.width;
  274. _height := _mode.height;
  275. _format := _mode.format;}
  276. { m_CurrentMode := modefound;}
  277. { m_VESACurrentMode := m_modes_n[modefound];}
  278. internal_pre_open_setup(_title);
  279. internal_open_fullscreen_start;
  280. internal_open_fullscreen(modefound{m_CurrentMode});
  281. internal_open_fullscreen_finish(_pages);
  282. internal_post_open_setup;
  283. End;
  284. Procedure VESAConsole.close;
  285. Begin
  286. If m_open Then
  287. Begin
  288. If m_locked Then
  289. Raise TPTCError.Create('console is still locked');
  290. {flush all key presses}
  291. While KeyPressed Do ReadKey;
  292. internal_close;
  293. m_open := False;
  294. End;
  295. End;
  296. Procedure VESAConsole.flush;
  297. Begin
  298. check_open;
  299. check_unlocked;
  300. End;
  301. Procedure VESAConsole.finish;
  302. Begin
  303. check_open;
  304. check_unlocked;
  305. End;
  306. Procedure VESAConsole.update;
  307. Var
  308. framebuffer : PInteger;
  309. Begin
  310. check_open;
  311. check_unlocked;
  312. WriteToVideoMemory(m_primary, 0, m_pitch * m_height);
  313. { m_primary.clear;}
  314. { m_primary.copy(m_160x100buffer);
  315. framebuffer := m_160x100buffer.lock;
  316. dump_160x(0, 50, framebuffer);
  317. m_160x100buffer.unlock;}
  318. End;
  319. Procedure VESAConsole.update(Const _area : TPTCArea);
  320. Begin
  321. update;
  322. End;
  323. Procedure VESAConsole.internal_ReadKey(k : TPTCKey);
  324. Begin
  325. check_open;
  326. m_keyboard.internal_ReadKey(k);
  327. End;
  328. Function VESAConsole.internal_PeekKey(k : TPTCKey) : Boolean;
  329. Begin
  330. check_open;
  331. Result := m_keyboard.internal_PeekKey(k);
  332. End;
  333. Procedure VESAConsole.copy(Var surface : TPTCBaseSurface);
  334. Var
  335. pixels : Pointer;
  336. Begin
  337. check_open;
  338. check_unlocked;
  339. pixels := lock;
  340. Try
  341. surface.load(pixels, width, height, pitch, format, palette);
  342. unlock;
  343. Except
  344. On error : TPTCError Do
  345. Begin
  346. unlock;
  347. Raise TPTCError.Create('failed to copy console to surface', error);
  348. End;
  349. End;
  350. End;
  351. Procedure VESAConsole.copy(Var surface : TPTCBaseSurface;
  352. Const source, destination : TPTCArea);
  353. Var
  354. pixels : Pointer;
  355. Begin
  356. check_open;
  357. check_unlocked;
  358. pixels := lock;
  359. Try
  360. surface.load(pixels, width, height, pitch, format, palette, source, destination);
  361. unlock;
  362. Except
  363. On error : TPTCError Do
  364. Begin
  365. unlock;
  366. Raise TPTCError.Create('failed to copy console to surface', error);
  367. End;
  368. End;
  369. End;
  370. Function VESAConsole.lock : Pointer;
  371. Var
  372. pixels : Pointer;
  373. Begin
  374. check_open;
  375. If m_locked Then
  376. Raise TPTCError.Create('console is already locked');
  377. { pixels := m_primary.lock;}
  378. pixels := m_primary;
  379. m_locked := True;
  380. lock := pixels;
  381. End;
  382. Procedure VESAConsole.unlock;
  383. Begin
  384. check_open;
  385. If Not m_locked Then
  386. Raise TPTCError.Create('console is not locked');
  387. { m_primary.unlock;}
  388. m_locked := False;
  389. End;
  390. Procedure VESAConsole.load(Const pixels : Pointer;
  391. _width, _height, _pitch : Integer;
  392. Const _format : TPTCFormat;
  393. Const _palette : TPTCPalette);
  394. Var
  395. Area_ : TPTCArea;
  396. console_pixels : Pointer;
  397. Begin
  398. check_open;
  399. check_unlocked;
  400. If clip.Equals(area) Then
  401. Begin
  402. console_pixels := lock;
  403. Try
  404. Try
  405. m_copy.request(_format, format);
  406. m_copy.palette(_palette, palette);
  407. m_copy.copy(pixels, 0, 0, _width, _height, _pitch, console_pixels, 0, 0,
  408. width, height, pitch);
  409. Except
  410. On error : TPTCError Do
  411. Begin
  412. Raise TPTCError.Create('failed to load pixels to console', error);
  413. End;
  414. End;
  415. Finally
  416. unlock;
  417. End;
  418. End
  419. Else
  420. Begin
  421. Area_ := TPTCArea.Create(0, 0, width, height);
  422. Try
  423. load(pixels, _width, _height, _pitch, _format, _palette, Area_, area);
  424. Finally
  425. Area_.Destroy;
  426. End;
  427. End;
  428. End;
  429. Procedure VESAConsole.load(Const pixels : Pointer;
  430. _width, _height, _pitch : Integer;
  431. Const _format : TPTCFormat;
  432. Const _palette : TPTCPalette;
  433. Const source, destination : TPTCArea);
  434. Var
  435. console_pixels : Pointer;
  436. clipped_source, clipped_destination : TPTCArea;
  437. tmp : TPTCArea;
  438. Begin
  439. check_open;
  440. check_unlocked;
  441. clipped_destination := Nil;
  442. clipped_source := TPTCArea.Create;
  443. Try
  444. clipped_destination := TPTCArea.Create;
  445. console_pixels := lock;
  446. Try
  447. Try
  448. tmp := TPTCArea.Create(0, 0, _width, _height);
  449. Try
  450. TPTCClipper.clip(source, tmp, clipped_source, destination, clip, clipped_destination);
  451. Finally
  452. tmp.Destroy;
  453. End;
  454. m_copy.request(_format, format);
  455. m_copy.palette(_palette, palette);
  456. m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
  457. console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
  458. Except
  459. On error:TPTCError Do
  460. Begin
  461. Raise TPTCError.Create('failed to load pixels to console area', error);
  462. End;
  463. End;
  464. Finally
  465. unlock;
  466. End;
  467. Finally
  468. clipped_source.Destroy;
  469. If clipped_destination <> Nil Then
  470. clipped_destination.Destroy;
  471. End;
  472. End;
  473. Procedure VESAConsole.save(pixels : Pointer;
  474. _width, _height, _pitch : Integer;
  475. Const _format : TPTCFormat;
  476. Const _palette : TPTCPalette);
  477. Var
  478. Area_ : TPTCArea;
  479. console_pixels : Pointer;
  480. Begin
  481. check_open;
  482. check_unlocked;
  483. If clip.Equals(area) Then
  484. Begin
  485. console_pixels := lock;
  486. Try
  487. Try
  488. m_copy.request(format, _format);
  489. m_copy.palette(palette, _palette);
  490. m_copy.copy(console_pixels, 0, 0, width, height, pitch, pixels, 0, 0,
  491. _width, _height, _pitch);
  492. Except
  493. On error : TPTCError Do
  494. Begin
  495. Raise TPTCError.Create('failed to save console pixels', error);
  496. End;
  497. End;
  498. Finally
  499. unlock;
  500. End;
  501. End
  502. Else
  503. Begin
  504. Area_ := TPTCArea.Create(0, 0, width, height);
  505. Try
  506. save(pixels, _width, _height, _pitch, _format, _palette, area, Area_);
  507. Finally
  508. Area_.Destroy;
  509. End;
  510. End;
  511. End;
  512. Procedure VESAConsole.save(pixels : Pointer;
  513. _width, _height, _pitch : Integer;
  514. Const _format : TPTCFormat;
  515. Const _palette : TPTCPalette;
  516. Const source, destination : TPTCArea);
  517. Var
  518. console_pixels : Pointer;
  519. clipped_source, clipped_destination : TPTCArea;
  520. tmp : TPTCArea;
  521. Begin
  522. check_open;
  523. check_unlocked;
  524. clipped_destination := Nil;
  525. clipped_source := TPTCArea.Create;
  526. Try
  527. clipped_destination := TPTCArea.Create;
  528. console_pixels := lock;
  529. Try
  530. Try
  531. tmp := TPTCArea.Create(0, 0, _width, _height);
  532. Try
  533. TPTCClipper.clip(source, clip, clipped_source, destination, tmp, clipped_destination);
  534. Finally
  535. tmp.Destroy;
  536. End;
  537. m_copy.request(format, _format);
  538. m_copy.palette(palette, _palette);
  539. m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
  540. pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
  541. Except
  542. On error:TPTCError Do
  543. Begin
  544. Raise TPTCError.Create('failed to save console area pixels', error);
  545. End;
  546. End;
  547. Finally
  548. unlock;
  549. End;
  550. Finally
  551. clipped_source.Destroy;
  552. If clipped_destination <> Nil Then
  553. clipped_destination.Destroy;
  554. End;
  555. End;
  556. Procedure VESAConsole.clear;
  557. Var
  558. tmp : TPTCColor;
  559. Begin
  560. check_open;
  561. check_unlocked;
  562. If format.direct Then
  563. tmp := TPTCColor.Create(0, 0, 0, 0)
  564. Else
  565. tmp := TPTCColor.Create(0);
  566. Try
  567. clear(tmp);
  568. Finally
  569. tmp.Destroy;
  570. End;
  571. End;
  572. Procedure VESAConsole.clear(Const color : TPTCColor);
  573. Var
  574. tmp : TPTCArea;
  575. Begin
  576. check_open;
  577. check_unlocked;
  578. tmp := TPTCArea.Create;
  579. Try
  580. clear(color, tmp);
  581. Finally
  582. tmp.Destroy;
  583. End;
  584. End;
  585. Procedure VESAConsole.clear(Const color : TPTCColor;
  586. Const _area : TPTCArea);
  587. Begin
  588. check_open;
  589. check_unlocked;
  590. {...}
  591. End;
  592. Procedure VESAConsole.palette(Const _palette : TPTCPalette);
  593. Begin
  594. check_open;
  595. { m_primary.palette(_palette);}
  596. If format.indexed Then
  597. Begin
  598. m_palette.load(_palette.data);
  599. SetPalette(_palette.data, 0, 256);
  600. End;
  601. End;
  602. Function VESAConsole.palette : TPTCPalette;
  603. Begin
  604. check_open;
  605. palette := m_palette;
  606. { palette := m_primary.palette;}
  607. End;
  608. Procedure VESAConsole.clip(Const _area : TPTCArea);
  609. Var
  610. tmp : TPTCArea;
  611. Begin
  612. check_open;
  613. tmp := TPTCClipper.clip(_area, m_area);
  614. Try
  615. m_clip.Assign(tmp);
  616. Finally
  617. tmp.Destroy;
  618. End;
  619. End;
  620. Function VESAConsole.width : Integer;
  621. Begin
  622. check_open;
  623. width := m_width;
  624. End;
  625. Function VESAConsole.height : Integer;
  626. Begin
  627. check_open;
  628. height := m_height;
  629. End;
  630. Function VESAConsole.pitch : Integer;
  631. Begin
  632. check_open;
  633. pitch := m_pitch;
  634. End;
  635. Function VESAConsole.pages : Integer;
  636. Begin
  637. check_open;
  638. pages := 2;{m_primary.pages;}
  639. End;
  640. Function VESAConsole.area : TPTCArea;
  641. Begin
  642. check_open;
  643. area := m_area;
  644. { area := m_primary.area;}
  645. End;
  646. Function VESAConsole.clip : TPTCArea;
  647. Begin
  648. check_open;
  649. clip := m_clip;
  650. { clip := m_primary.clip;}
  651. End;
  652. Function VESAConsole.format : TPTCFormat;
  653. Begin
  654. check_open;
  655. format := m_modes[m_CurrentMode].format;
  656. { format := m_primary.format;}
  657. End;
  658. Function VESAConsole.name : String;
  659. Begin
  660. name := 'VESA';
  661. End;
  662. Function VESAConsole.title : String;
  663. Begin
  664. title := m_title;
  665. End;
  666. Function VESAConsole.information : String;
  667. Begin
  668. information := m_information;
  669. End;
  670. Procedure VESAConsole.internal_pre_open_setup(Const _title : String);
  671. Begin
  672. internal_close;
  673. m_title := _title;
  674. End;
  675. Procedure VESAConsole.internal_open_fullscreen_start;
  676. {Var
  677. f : TPTCFormat;}
  678. Begin
  679. { f := TPTCFormat.Create(32, $0000FF, $00FF00, $FF0000);}
  680. { m_160x100buffer := TPTCSurface.Create(160, 100, f);}
  681. { f.Destroy;}
  682. { set80x50;}
  683. End;
  684. Procedure VESAConsole.internal_open_fullscreen(ModeNr : Integer);
  685. Var
  686. tmp : TPTCFormat;
  687. tmpa : TPTCArea;
  688. I : Integer;
  689. plt : Array[0..255] Of Packed Record
  690. B, G, R, A : Byte;
  691. End;
  692. Begin
  693. m_CurrentMode := ModeNr;
  694. m_VESACurrentMode := m_modes_n[ModeNr];
  695. SetVESAMode(m_VESACurrentMode);
  696. tmp := TPTCFormat.Create(8, $E0, $1C, $03);
  697. If m_modes[m_CurrentMode].m_format.Equals(tmp) Then
  698. Begin
  699. For I := 0 To 255 Do
  700. With plt[I] Do
  701. Begin
  702. Case I Shr 5 Of
  703. 0 : R := 0;
  704. 1 : R := 36;
  705. 2 : R := 73;
  706. 3 : R := 109;
  707. 4 : R := 146;
  708. 5 : R := 182;
  709. 6 : R := 219;
  710. 7 : R := 255;
  711. End;
  712. Case (I Shr 2) And 7 Of
  713. 0 : G := 0;
  714. 1 : G := 36;
  715. 2 : G := 73;
  716. 3 : G := 109;
  717. 4 : G := 146;
  718. 5 : G := 182;
  719. 6 : G := 219;
  720. 7 : G := 255;
  721. End;
  722. Case I And 3 Of
  723. 0 : B := 0;
  724. 1 : B := 85;
  725. 2 : B := 170;
  726. 3 : B := 255;
  727. End;
  728. A := 0;
  729. End;
  730. SetPalette(@plt, 0, 256);
  731. End;
  732. tmp.Destroy;
  733. { m_primary := TPTCSurface.Create(_width, _height, _format);}
  734. With ModeInfo[m_VESACurrentMode].VesaModeInfo Do
  735. Begin
  736. m_width := XResolution;
  737. m_height := YResolution;
  738. m_pitch := BytesPerScanline;
  739. End;
  740. tmpa := TPTCArea.Create(0, 0, width, height);
  741. Try
  742. m_area.ASSign(tmpa);
  743. m_clip.ASSign(tmpa);
  744. Finally
  745. tmpa.Destroy;
  746. End;
  747. End;
  748. Procedure VESAConsole.internal_open_fullscreen_finish(_pages : Integer);
  749. Begin
  750. m_primary := GetMem(m_height * m_pitch);
  751. End;
  752. Procedure VESAConsole.internal_post_open_setup;
  753. Begin
  754. If m_keyboard <> Nil Then
  755. m_keyboard.Destroy;
  756. m_keyboard := TDosKeyboard.Create;
  757. { temporary platform dependent information fudge }
  758. m_information := 'dos version x.xx.x'+#13+#10+'vesa version x.xx'+#13+#10+'vesa driver name xxxxx'+#13+#10+'display driver vendor xxxxx'+#13+#10+'certified driver? x'+#13+#10;
  759. { set open flag }
  760. m_open := True;
  761. End;
  762. Procedure VESAConsole.internal_reset;
  763. Begin
  764. If m_keyboard <> Nil Then
  765. Begin
  766. m_keyboard.Destroy;
  767. m_keyboard := Nil;
  768. End;
  769. End;
  770. Procedure VESAConsole.internal_close;
  771. Begin
  772. If m_primary <> Nil Then
  773. Begin
  774. FreeMem(m_primary);
  775. m_primary := Nil;
  776. End;
  777. If m_keyboard <> Nil Then
  778. Begin
  779. m_keyboard.Destroy;
  780. m_keyboard := Nil;
  781. End;
  782. RestoreTextMode;
  783. End;
  784. Procedure VESAConsole.check_open;
  785. Begin
  786. {$IFDEF DEBUG}
  787. If Not m_open Then
  788. Raise TPTCError.Create('console is not open');
  789. {$ELSE}
  790. {$ENDIF}
  791. End;
  792. Procedure VESAConsole.check_unlocked;
  793. Begin
  794. {$IFDEF DEBUG}
  795. If m_locked Then
  796. Raise TPTCError.Create('console is not unlocked');
  797. {$ELSE}
  798. {$ENDIF}
  799. End;