console.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. {$MACRO ON}
  2. {$DEFINE DEFAULT_WIDTH:=320}
  3. {$DEFINE DEFAULT_HEIGHT:=200}
  4. {$DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF)}
  5. Constructor TextFX2Console.Create;
  6. Var
  7. I : Integer;
  8. Begin
  9. m_160x100buffer := Nil;
  10. m_primary := Nil;
  11. m_keyboard := Nil;
  12. m_copy := Nil;
  13. m_default_format := Nil;
  14. m_open := False;
  15. m_locked := False;
  16. FillChar(m_modes, SizeOf(m_modes), 0);
  17. m_title[0] := #0;
  18. m_information[0] := #0;
  19. m_default_width := DEFAULT_WIDTH;
  20. m_default_height := DEFAULT_HEIGHT;
  21. m_default_format := DEFAULT_FORMAT;
  22. For I := Low(m_modes) To High(m_modes) Do
  23. m_modes[I] := TPTCMode.Create;
  24. calcpal := @calcpal_colorbase;
  25. use_charset := @charset_b7asc;
  26. build_colormap(0);
  27. m_copy := TPTCCopy.Create;
  28. configure('ptc.cfg');
  29. End;
  30. Destructor TextFX2Console.Destroy;
  31. Var
  32. I : Integer;
  33. Begin
  34. close;
  35. If m_160x100buffer <> Nil Then
  36. m_160x100buffer.Destroy;
  37. If m_primary <> Nil Then
  38. m_primary.Destroy;
  39. For I := Low(m_modes) To High(m_modes) Do
  40. If m_modes[I] <> Nil Then
  41. m_modes[I].Destroy;
  42. If m_keyboard <> Nil Then
  43. m_keyboard.Destroy;
  44. If m_copy <> Nil Then
  45. m_copy.Destroy;
  46. If m_default_format <> Nil Then
  47. m_default_format.Destroy;
  48. dispose_colormap;
  49. Inherited Destroy;
  50. End;
  51. Procedure TextFX2Console.configure(Const _file : String);
  52. Var
  53. F : Text;
  54. S : String;
  55. Begin
  56. ASSign(F, _file);
  57. Try
  58. Reset(F);
  59. Except
  60. Exit;
  61. End;
  62. Try
  63. While Not EoF(F) Do
  64. Begin
  65. Readln(F, S);
  66. option(S);
  67. End;
  68. Finally
  69. CloseFile(F);
  70. End;
  71. End;
  72. Function TextFX2Console.option(Const _option : String) : Boolean;
  73. Begin
  74. {...}
  75. option := True;
  76. If _option = 'charset_b8ibm' Then
  77. Begin
  78. use_charset := @charset_b8ibm;
  79. Exit;
  80. End;
  81. If _option = 'charset_b7asc' Then
  82. Begin
  83. use_charset := @charset_b7asc;
  84. Exit;
  85. End;
  86. If _option = 'charset_b7sml' Then
  87. Begin
  88. use_charset := @charset_b7sml;
  89. Exit;
  90. End;
  91. If _option = 'charset_b8gry' Then
  92. Begin
  93. use_charset := @charset_b8gry;
  94. Exit;
  95. End;
  96. If _option = 'charset_b7nws' Then
  97. Begin
  98. use_charset := @charset_b7nws;
  99. Exit;
  100. End;
  101. If _option = 'calcpal_colorbase' Then
  102. Begin
  103. calcpal := @calcpal_colorbase;
  104. build_colormap(0);
  105. Exit;
  106. End;
  107. If _option = 'calcpal_lightbase' Then
  108. Begin
  109. calcpal := @calcpal_lightbase;
  110. build_colormap(0);
  111. Exit;
  112. End;
  113. If _option = 'calcpal_lightbase_g' Then
  114. Begin
  115. calcpal := @calcpal_lightbase_g;
  116. build_colormap(0);
  117. Exit;
  118. End;
  119. option := m_copy.option(_option);
  120. End;
  121. Function TextFX2Console.modes : PPTCMode;
  122. Begin
  123. {todo...}
  124. modes := @m_modes;
  125. End;
  126. Procedure TextFX2Console.open(Const _title : String; _pages : Integer); Overload;
  127. Begin
  128. open(_title, m_default_format, _pages);
  129. End;
  130. Procedure TextFX2Console.open(Const _title : String; Const _format : TPTCFormat;
  131. _pages : Integer); Overload;
  132. Begin
  133. open(_title, m_default_width, m_default_height, _format, _pages);
  134. End;
  135. Procedure TextFX2Console.open(Const _title : String; _width, _height : Integer;
  136. Const _format : TPTCFormat; _pages : Integer); Overload;
  137. Var
  138. m : TPTCMode;
  139. Begin
  140. m := TPTCMode.Create(_width, _height, _format);
  141. open(_title, m, _pages);
  142. m.Destroy;
  143. End;
  144. Procedure TextFX2Console.open(Const _title : String; Const _mode : TPTCMode;
  145. _pages : Integer); Overload;
  146. Var
  147. _width, _height : Integer;
  148. _format : TPTCFormat;
  149. Begin
  150. If Not _mode.valid Then
  151. Raise TPTCError.Create('invalid mode');
  152. _width := _mode.width;
  153. _height := _mode.height;
  154. _format := _mode.format;
  155. internal_pre_open_setup(_title);
  156. internal_open_fullscreen_start;
  157. internal_open_fullscreen(_width, _height, _format);
  158. internal_open_fullscreen_finish(_pages);
  159. internal_post_open_setup;
  160. End;
  161. Procedure TextFX2Console.close;
  162. Begin
  163. If m_open Then
  164. Begin
  165. If m_locked Then
  166. Raise TPTCError.Create('console is still locked');
  167. {flush all key presses}
  168. While KeyPressed Do ReadKey;
  169. internal_close;
  170. m_open := False;
  171. End;
  172. End;
  173. Procedure TextFX2Console.flush;
  174. Begin
  175. check_open;
  176. check_unlocked;
  177. End;
  178. Procedure TextFX2Console.finish;
  179. Begin
  180. check_open;
  181. check_unlocked;
  182. End;
  183. Procedure TextFX2Console.update;
  184. Var
  185. framebuffer : PInteger;
  186. Begin
  187. check_open;
  188. check_unlocked;
  189. { m_primary.clear;}
  190. m_primary.copy(m_160x100buffer);
  191. framebuffer := m_160x100buffer.lock;
  192. vrc;
  193. dump_160x(0, 50, framebuffer);
  194. m_160x100buffer.unlock;
  195. End;
  196. Procedure TextFX2Console.update(Const _area : TPTCArea);
  197. Begin
  198. update;
  199. End;
  200. Procedure TextFX2Console.internal_ReadKey(k : TPTCKey);
  201. Begin
  202. check_open;
  203. m_keyboard.internal_ReadKey(k);
  204. End;
  205. Function TextFX2Console.internal_PeekKey(k : TPTCKey) : Boolean;
  206. Begin
  207. check_open;
  208. Result := m_keyboard.internal_PeekKey(k);
  209. End;
  210. Procedure TextFX2Console.copy(Var surface : TPTCBaseSurface);
  211. Var
  212. pixels : Pointer;
  213. Begin
  214. check_open;
  215. check_unlocked;
  216. pixels := lock;
  217. Try
  218. surface.load(pixels, width, height, pitch, format, palette);
  219. unlock;
  220. Except
  221. On error : TPTCError Do
  222. Begin
  223. unlock;
  224. Raise TPTCError.Create('failed to copy console to surface', error);
  225. End;
  226. End;
  227. End;
  228. Procedure TextFX2Console.copy(Var surface : TPTCBaseSurface;
  229. Const source, destination : TPTCArea);
  230. Begin
  231. End;
  232. Function TextFX2Console.lock : Pointer;
  233. Var
  234. pixels : Pointer;
  235. Begin
  236. check_open;
  237. If m_locked Then
  238. Raise TPTCError.Create('console is already locked');
  239. pixels := m_primary.lock;
  240. m_locked := True;
  241. lock := pixels;
  242. End;
  243. Procedure TextFX2Console.unlock;
  244. Begin
  245. check_open;
  246. If Not m_locked Then
  247. Raise TPTCError.Create('console is not locked');
  248. m_primary.unlock;
  249. m_locked := False;
  250. End;
  251. Procedure TextFX2Console.load(Const pixels : Pointer;
  252. _width, _height, _pitch : Integer;
  253. Const _format : TPTCFormat;
  254. Const _palette : TPTCPalette);
  255. Var
  256. Area_ : TPTCArea;
  257. console_pixels : Pointer;
  258. c, a : TPTCArea;
  259. Begin
  260. c := clip; a := area;
  261. If (c.left = a.left) And
  262. (c.top = a.top) And
  263. (c.right = a.right) And
  264. (c.bottom = a.bottom) Then
  265. Begin
  266. check_open;
  267. check_unlocked;
  268. console_pixels := lock;
  269. Try
  270. m_copy.request(_format, format);
  271. m_copy.palette(_palette, palette);
  272. m_copy.copy(pixels, 0, 0, _width, _height, _pitch, console_pixels, 0, 0,
  273. width, height, pitch);
  274. unlock;
  275. Except
  276. On error : TPTCError Do
  277. Begin
  278. unlock;
  279. Raise TPTCError.Create('failed to load pixels to console', error);
  280. End;
  281. End;
  282. End
  283. Else
  284. Begin
  285. Area_ := TPTCArea.Create(0, 0, width, height);
  286. load(pixels, _width, _height, _pitch, _format, _palette, Area_, area);
  287. Area_.Destroy;
  288. End;
  289. End;
  290. Procedure TextFX2Console.load(Const pixels : Pointer;
  291. _width, _height, _pitch : Integer;
  292. Const _format : TPTCFormat;
  293. Const _palette : TPTCPalette;
  294. Const source, destination : TPTCArea);
  295. Var
  296. console_pixels : Pointer;
  297. clipped_source, clipped_destination : TPTCArea;
  298. tmp : TPTCArea;
  299. Begin
  300. check_open;
  301. check_unlocked;
  302. console_pixels := lock;
  303. clipped_source := TPTCArea.Create;
  304. clipped_destination := TPTCArea.Create;
  305. Try
  306. tmp := TPTCArea.Create(0, 0, _width, _height);
  307. TPTCClipper.clip(source, tmp, clipped_source, destination, clip, clipped_destination);
  308. tmp.Destroy;
  309. m_copy.request(_format, format);
  310. m_copy.palette(_palette, palette);
  311. m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
  312. console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
  313. unlock;
  314. Except
  315. On error:TPTCError Do
  316. Begin
  317. clipped_source.Destroy;
  318. clipped_destination.Destroy;
  319. unlock;
  320. Raise TPTCError.Create('failed to load pixels to console area', error);
  321. End;
  322. End;
  323. clipped_source.Destroy;
  324. clipped_destination.Destroy;
  325. End;
  326. Procedure TextFX2Console.save(pixels : Pointer;
  327. _width, _height, _pitch : Integer;
  328. Const _format : TPTCFormat;
  329. Const _palette : TPTCPalette);
  330. Var
  331. Area_ : TPTCArea;
  332. console_pixels : Pointer;
  333. c, a : TPTCArea;
  334. Begin
  335. c := clip; a := area;
  336. If (c.left = a.left) And
  337. (c.top = a.top) And
  338. (c.right = a.right) And
  339. (c.bottom = a.bottom) Then
  340. Begin
  341. check_open;
  342. check_unlocked;
  343. console_pixels := lock;
  344. Try
  345. m_copy.request(format, _format);
  346. m_copy.palette(palette, _palette);
  347. m_copy.copy(console_pixels, 0, 0, width, height, pitch, pixels, 0, 0,
  348. _width, _height, _pitch);
  349. unlock;
  350. Except
  351. On error : TPTCError Do
  352. Begin
  353. unlock;
  354. Raise TPTCError.Create('failed to save console pixels', error);
  355. End;
  356. End;
  357. End
  358. Else
  359. Begin
  360. Area_ := TPTCArea.Create(0, 0, width, height);
  361. save(pixels, _width, _height, _pitch, _format, _palette, area, Area_);
  362. Area_.Destroy;
  363. End;
  364. End;
  365. Procedure TextFX2Console.save(pixels : Pointer;
  366. _width, _height, _pitch : Integer;
  367. Const _format : TPTCFormat;
  368. Const _palette : TPTCPalette;
  369. Const source, destination : TPTCArea);
  370. Var
  371. console_pixels : Pointer;
  372. clipped_source, clipped_destination : TPTCArea;
  373. tmp : TPTCArea;
  374. Begin
  375. check_open;
  376. check_unlocked;
  377. console_pixels := lock;
  378. clipped_source := TPTCArea.Create;
  379. clipped_destination := TPTCArea.Create;
  380. Try
  381. tmp := TPTCArea.Create(0, 0, _width, _height);
  382. TPTCClipper.clip(source, clip, clipped_source, destination, tmp, clipped_destination);
  383. tmp.Destroy;
  384. m_copy.request(format, _format);
  385. m_copy.palette(palette, _palette);
  386. m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
  387. pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
  388. unlock;
  389. Except
  390. On error:TPTCError Do
  391. Begin
  392. clipped_source.Destroy;
  393. clipped_destination.Destroy;
  394. unlock;
  395. Raise TPTCError.Create('failed to save console area pixels', error);
  396. End;
  397. End;
  398. clipped_source.Destroy;
  399. clipped_destination.Destroy;
  400. End;
  401. Procedure TextFX2Console.clear;
  402. Begin
  403. End;
  404. Procedure TextFX2Console.clear(Const color : TPTCColor);
  405. Begin
  406. End;
  407. Procedure TextFX2Console.clear(Const color : TPTCColor;
  408. Const _area : TPTCArea);
  409. Begin
  410. End;
  411. Procedure TextFX2Console.palette(Const _palette : TPTCPalette);
  412. Begin
  413. check_open;
  414. m_primary.palette(_palette);
  415. End;
  416. Function TextFX2Console.palette : TPTCPalette;
  417. Begin
  418. check_open;
  419. palette := m_primary.palette;
  420. End;
  421. Procedure TextFX2Console.clip(Const _area : TPTCArea);
  422. Begin
  423. check_open;
  424. m_primary.clip(_area);
  425. End;
  426. Function TextFX2Console.width : Integer;
  427. Begin
  428. check_open;
  429. width := m_primary.width;
  430. End;
  431. Function TextFX2Console.height : Integer;
  432. Begin
  433. check_open;
  434. height := m_primary.height;
  435. End;
  436. Function TextFX2Console.pitch : Integer;
  437. Begin
  438. check_open;
  439. pitch := m_primary.pitch;
  440. End;
  441. Function TextFX2Console.pages : Integer;
  442. Begin
  443. check_open;
  444. pages := 2;{m_primary.pages;}
  445. End;
  446. Function TextFX2Console.area : TPTCArea;
  447. Begin
  448. check_open;
  449. area := m_primary.area;
  450. End;
  451. Function TextFX2Console.clip : TPTCArea;
  452. Begin
  453. check_open;
  454. clip := m_primary.clip;
  455. End;
  456. Function TextFX2Console.format : TPTCFormat;
  457. Begin
  458. check_open;
  459. format := m_primary.format;
  460. End;
  461. Function TextFX2Console.name : String;
  462. Begin
  463. End;
  464. Function TextFX2Console.title : String;
  465. Begin
  466. End;
  467. Function TextFX2Console.information : String;
  468. Begin
  469. End;
  470. Procedure TextFX2Console.internal_pre_open_setup(Const _title : String);
  471. Begin
  472. End;
  473. Procedure TextFX2Console.internal_open_fullscreen_start;
  474. Var
  475. f : TPTCFormat;
  476. Begin
  477. f := TPTCFormat.Create(32, $0000FF, $00FF00, $FF0000);
  478. m_160x100buffer := TPTCSurface.Create(160, 100, f);
  479. f.Destroy;
  480. set80x50;
  481. End;
  482. Procedure TextFX2Console.internal_open_fullscreen(_width, _height : Integer; Const _format : TPTCFormat);
  483. Begin
  484. m_primary := TPTCSurface.Create(_width, _height, _format);
  485. End;
  486. Procedure TextFX2Console.internal_open_fullscreen_finish(_pages : Integer);
  487. Begin
  488. End;
  489. Procedure TextFX2Console.internal_post_open_setup;
  490. Begin
  491. If m_keyboard <> Nil Then
  492. m_keyboard.Destroy;
  493. m_keyboard := TDosKeyboard.Create;
  494. { create win32 keyboard
  495. m_keyboard = new DosKeyboard();//m_window->handle(),m_window->thread(),false);}
  496. { temporary platform dependent information fudge }
  497. {sprintf(m_information,"dos version x.xx.x\nvesa version x.xx\nvesa driver name xxxxx\ndisplay driver vendor xxxxx\ncertified driver? x\n");}
  498. { set open flag }
  499. m_open := True;
  500. End;
  501. Procedure TextFX2Console.internal_reset;
  502. Begin
  503. If m_primary <> Nil Then
  504. m_primary.Destroy;
  505. { m_keyboard.Destroy;}
  506. m_primary := Nil;
  507. { m_keyboard := Nil;}
  508. End;
  509. Procedure TextFX2Console.internal_close;
  510. Begin
  511. If m_primary <> Nil Then
  512. m_primary.Destroy;
  513. m_primary := Nil;
  514. If m_160x100buffer <> Nil Then
  515. m_160x100buffer.Destroy;
  516. m_160x100buffer := Nil;
  517. set80x25;
  518. { m_keyboard.Destroy;
  519. m_keyboard := Nil;}
  520. End;
  521. Procedure TextFX2Console.check_open;
  522. Begin
  523. {$IFDEF DEBUG}
  524. If Not m_open Then
  525. Raise TPTCError.Create('console is not open');
  526. {$ENDIF}
  527. End;
  528. Procedure TextFX2Console.check_unlocked;
  529. Begin
  530. {$IFDEF DEBUG}
  531. If m_locked Then
  532. Raise TPTCError.Create('console is not unlocked');
  533. {$ENDIF}
  534. End;