gameunit.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. {
  2. $Id$
  3. A simple unit with some common used routines for FPCGames (FpcTris and
  4. SameGame)
  5. Contains
  6. - Highscore routines "developped" for FPCTris, but now also used by SameGame
  7. - "Dummy" mouse routines which either shell to API units or to MSMouse.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. UNIT GameUnit;
  15. INTERFACE
  16. {MouseAPI defined : unit unes API mouse units, which requires that package,
  17. but also works under Linux
  18. MouseAPI undef : RTL unit MsMouse. API not required, but doesn't work under
  19. Linux }
  20. {$ifdef Unix}
  21. {$define MouseAPI}
  22. {$endif}
  23. {$ifdef win32}
  24. {$define MouseAPI}
  25. {$define UseGraphics} {Mandatory}
  26. {$endif}
  27. {$IFDEF Ver70}
  28. {$define MouseAPI}
  29. {$G+}
  30. {$endif}
  31. {$IFDEF Ver60}
  32. {$define MouseAPI}
  33. {$G+}
  34. {$endif}
  35. {$IFDEF Ver55}
  36. {$define MouseAPI}
  37. {$G+}
  38. {$endif}
  39. {$ifdef UseGraphics}
  40. {$ifdef Win32}
  41. {$define Win32Graph}
  42. {$endif}
  43. {$endif}
  44. CONST LineDistY=13;
  45. TYPE CHARSET=SET OF CHAR;
  46. {---- Unified Mouse procedures. ---- }
  47. FUNCTION MousePresent : BOOLEAN;
  48. PROCEDURE HideMouse;
  49. PROCEDURE ShowMouse;
  50. PROCEDURE GetMouseState(VAR MX,MY,MState : LONGINT);
  51. PROCEDURE DoneMouse;
  52. PROCEDURE InitMouse;
  53. PROCEDURE SetMousePosition(X,Y:LONGINT);
  54. Const LButton = 1; {left button}
  55. RButton = 2; {right button}
  56. MButton = 4; {middle button}
  57. {---- Standard Highscore procedures ----}
  58. TYPE HighScoreType = Packed RECORD
  59. Name : String[15];
  60. Score: LONGINT;
  61. END;
  62. HighScoreArr = ARRAY[0..9] OF HighScoreType;
  63. VAR HighScore : HighScoreArr;
  64. ScorePath : String;
  65. HighX,HighY : LONGINT;
  66. Negative : BOOLEAN; { Negative=true-> better scores are lower}
  67. PROCEDURE LoadHighScore(FileName:STRING);
  68. PROCEDURE SaveHighScore;
  69. PROCEDURE ShowHighScore;
  70. FUNCTION SlipInScore(Score:LONGINT):LONGINT;
  71. {---- Keyboard routines ----}
  72. CONST {Constants for GetKey}
  73. ArrU = $04800; ArrL = $04B00; ArrR = $04D00; BS = $08; (* Backspace *)
  74. ArrD = $05000; CR = $0D; ESC = $1B; KDelete= $05300;
  75. KInsert= $05200; Home = $04700; KEnd = $04F00; CtrlY = $19;
  76. CtrlT = $14;
  77. CONST FieldSpace : CHAR = #177;
  78. AlfaBeta : CHARSET= [' '..'z'];
  79. FUNCTION GetKey:LONGINT;
  80. {Generic string input routine}
  81. {$IFDEF UseGraphics}
  82. FUNCTION GrInputStr(VAR S:String;X,Y,Len,dX,dY:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
  83. {$ELSE}
  84. FUNCTION InputStr(VAR S:String;X,Y,Len:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
  85. {$ENDIF}
  86. {---- Misc ----}
  87. PROCEDURE SetDefaultColor; {Restore the attribs saved on startup}
  88. {BP compability}
  89. {$IFNDEF FPC}
  90. PROCEDURE SetCursorSize(CurDat:WORD);
  91. FUNCTION GetCursorSize:WORD;
  92. PROCEDURE CursorOn;
  93. PROCEDURE CursorOff;
  94. {Non Go32 but not existant in BP}
  95. PROCEDURE FillWord(VAR Data;Count,Value:WORD);
  96. PROCEDURE dosmemfillword(Segx,xofs,Count,Value:WORD);
  97. PROCEDURE dosmemput(Segx,xofs:WORD;VAR Data;Count:WORD);
  98. PROCEDURE dosmemget(Segx,xofs:WORD;VAR Data;Count:WORD);
  99. FUNCTION inportb(portx : word) : byte;
  100. PROCEDURE outportb(portx : word;data : byte);
  101. FUNCTION inportw(portx : word) : word;
  102. PROCEDURE outportw(portx : word;data : word);
  103. FUNCTION inportl(portx : word) : longint;
  104. PROCEDURE outportl(portx : word;data : longint);
  105. {$ENDIF}
  106. IMPLEMENTATION
  107. Uses
  108. {$ifdef Win32Graph}
  109. WinMouse,
  110. {$undef MouseApi}
  111. {$else}
  112. {$IFDEF MouseAPI}
  113. Mouse,
  114. {$ELSE}
  115. MSMouse,
  116. {$ENDIF}
  117. {$endif}
  118. {$ifdef UseGraphics}
  119. Graph,
  120. {$endif}
  121. {$ifdef Win32Graph}
  122. WinCrt,
  123. {$else}
  124. Crt,
  125. {$endif}
  126. Dos;
  127. VAR DefColor : BYTE; {Backup of startup colors}
  128. CONST
  129. {The initial names. If people feel they are missing, I first checked the Alias,
  130. and then filled with names of the FPC-Devel list, and arranged them alfabetically}
  131. InitNames : ARRAY[0..9] OF String[12] = ('Carl','Daniel','Florian','Jonas','John','Marco','Michael (3x)',
  132. 'Peter','Pierre','Thomas' );
  133. FUNCTION MousePresent : BOOLEAN;
  134. BEGIN
  135. {$IFDEF MouseAPI}
  136. MousePresent:=DetectMouse<>0;
  137. {$ELSE}
  138. MousePresent:=MouseFound;
  139. {$ENDIF}
  140. END;
  141. PROCEDURE ShowMouse;
  142. BEGIN
  143. {$ifdef Win32Graph}
  144. WinMouse.ShowMouse;
  145. {$else}
  146. {$IFDEF MouseAPI}
  147. Mouse.ShowMouse;
  148. {$ELSE}
  149. MsMouse.ShowMouse;
  150. {$ENDIF}
  151. {$endif}
  152. END;
  153. PROCEDURE HideMouse;
  154. BEGIN
  155. {$ifdef Win32Graph}
  156. WinMouse.HideMouse;
  157. {$else}
  158. {$IFDEF MouseAPI}
  159. Mouse.HideMouse;
  160. {$ELSE}
  161. MsMouse.HideMouse;
  162. {$ENDIF}
  163. {$endif}
  164. END;
  165. PROCEDURE InitMouse;
  166. BEGIN
  167. {$ifdef Win32Graph}
  168. WinMouse.InitMouse;
  169. {$else}
  170. {$IFDEF MouseAPI}
  171. Mouse.InitMouse;
  172. {$ELSE}
  173. MsMouse.InitMouse;
  174. {$ENDIF}
  175. {$endif}
  176. END;
  177. PROCEDURE DoneMouse;
  178. BEGIN
  179. {$ifdef Win32Graph}
  180. {$else}
  181. {$IFDEF MouseAPI}
  182. Mouse.DoneMouse;
  183. {$ENDIF}
  184. {$endif}
  185. END;
  186. PROCEDURE GetMouseState(VAR MX,MY,MState : LONGINT);
  187. {$IFDEF MouseAPI}
  188. VAR MouseEvent : TMouseEvent;
  189. {$ENDIF}
  190. BEGIN
  191. {$IFDEF MouseAPI}
  192. GetMouseEvent(MouseEvent);
  193. MX:=MouseEvent.X SHL 3;
  194. MY:=MouseEvent.Y SHL 3;
  195. MState:=MouseEvent.Buttons;
  196. {$ELSE}
  197. {$ifdef Win32Graph}
  198. WinMouse.GetMouseState(MX,MY,MState);
  199. {$else}
  200. MsMouse.GetMouseState(MX,MY,MState);
  201. {$endif}
  202. {$ENDIF}
  203. END;
  204. PROCEDURE SetMousePosition(X,Y:LONGINT);
  205. BEGIN
  206. {$ifndef Win32Graph}
  207. {$IFDEF MouseAPI}
  208. SetMouseXY(x,y);
  209. {$ELSE}
  210. SetMousePos(X,Y);
  211. {$endif}
  212. {$ENDIF}
  213. END;
  214. Procedure LoadHighScore(FileName:STRING);
  215. var
  216. F: File;
  217. I : LONGINT;
  218. OFileMode : LONGINT;
  219. BEGIN
  220. {$I-}
  221. Assign(F, FileName);
  222. OFileMode:=FileMode;
  223. FileMode := 0; {Set file access to read only }
  224. Reset(F);
  225. Close(F);
  226. {$I+}
  227. IF IOResult=0 THEN
  228. ScorePath:=FileName
  229. ELSE
  230. ScorePath:=FSearch(FileName,GetEnv('PATH'));
  231. IF ScorePath='' THEN
  232. BEGIN
  233. FOR I:=0 TO 9 DO
  234. BEGIN
  235. HighScore[I].Name:=InitNames[I];
  236. If Negative Then
  237. HighScore[I].Score:=-100*(10-I)
  238. Else
  239. HighScore[I].Score:=(I+1)*750;
  240. END;
  241. ScorePath:=FileName;
  242. END
  243. ELSE
  244. BEGIN
  245. Assign(F,ScorePath);
  246. Reset(F,1);
  247. BlockRead(F,HighScore,SIZEOF(HighScoreArr));
  248. Close(F);
  249. END;
  250. FileMode:=OFileMode;
  251. END;
  252. Procedure SaveHighScore;
  253. var
  254. F: File;
  255. BEGIN
  256. Assign(F,ScorePath);
  257. Rewrite(F,1);
  258. BlockWrite(F,HighScore,SIZEOF(HighScoreArr));
  259. Close(F);
  260. END;
  261. FUNCTION SlipInScore(Score:LONGINT):LONGINT;
  262. VAR I,J : LONGINT;
  263. BEGIN
  264. IF Negative THEN
  265. Score:=-Score;
  266. I:=0;
  267. WHILE (Score>HighScore[I].Score) AND (I<10) DO
  268. INC(I);
  269. IF I<>0 THEN
  270. BEGIN
  271. IF I>1 THEN
  272. FOR J:=0 TO I-2 DO
  273. HighScore[J]:=HighScore[J+1];
  274. HighScore[I-1].Score:=Score;
  275. HighScore[I-1].Name:='';
  276. END;
  277. SlipInScore:=I;
  278. END;
  279. {$IFDEF UseGraphics}
  280. PROCEDURE ShowHighScore;
  281. VAR I : LONGINT;
  282. S : String;
  283. BEGIN
  284. SetFillStyle(SolidFill,0); {Clear part of playfield}
  285. Bar(HighX,HighY, 638, HighY+20+18*LineDistY);
  286. FOR I:=0 TO 9 DO
  287. BEGIN
  288. OutTextXY(HighX,HighY+(9-I)*LineDistY,HighScore[I].Name);
  289. IF Negative THEN
  290. Str((-HighScore[I].Score):5,S)
  291. ELSE
  292. Str(HighScore[I].Score:5,S);
  293. OutTextXY(HighX+150,HighY+(9-I)*LineDistY,S);
  294. END;
  295. END;
  296. {$ELSE}
  297. PROCEDURE ShowHighScore;
  298. VAR I : LONGINT;
  299. {HighX=40 HighY=9}
  300. BEGIN
  301. GotoXY(HighX+5,9); Write('The Highscores');
  302. FOR I:=0 TO 9 DO
  303. BEGIN
  304. GotoXY(HighX,HighY+11-I);
  305. Write(HighScore[I].Name,' ':(13-Length(HighScore[I].Name)),' ');
  306. IF NOT Negative THEN { Negative=true-> better scores are lower}
  307. Write(HighScore[I].Score:5)
  308. ELSE
  309. Write(-HighScore[I].Score:5)
  310. END;
  311. END;
  312. {$ENDIF}
  313. FUNCTION GetKey:LONGINT;
  314. VAR InKey: LONGINT;
  315. BEGIN
  316. InKey:=ORD(ReadKey);
  317. IF InKey=0 THEN InKey:=ORD(ReadKey) SHL 8;
  318. GetKey:=InKey;
  319. END;
  320. {$IFNDEF UseGraphics}
  321. FUNCTION InputStr(VAR S:String;X,Y,Len:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
  322. {
  323. Input a string from keyboard, in a nice way,
  324. allowed characters are in CHARSET CharAllow, but several editting
  325. keys are always allowed, see CASE loop.
  326. Parameters:
  327. X,Y Coordinates field
  328. Len Length field
  329. TextIn S already filled?}
  330. VAR
  331. InGev : LONGINT; { No. of chars inputted }
  332. Posi : LONGINT; { Cursorposition}
  333. Ins : BOOLEAN; { Insert yes/no}
  334. Key : LONGINT; { Last key as ELib.GetKey
  335. code <255 if normal key,
  336. >256 if special/function
  337. key. See keys.inc}
  338. Uitg : String; {The inputted string}
  339. Full : BOOLEAN; { Is the string full? }
  340. EndVal : WORD;
  341. PROCEDURE ReWr; { Rewrite the field, using Uitg}
  342. VAR I : LONGINT; { Temporary variabele }
  343. BEGIN
  344. IF Length(Uitg)>Len THEN
  345. Uitg[0]:=CHR(Len);
  346. IF Length(Uitg)>0 THEN
  347. FOR I:= 1 TO Length(Uitg) DO
  348. BEGIN
  349. GotoXY(X+I-1,Y);
  350. IF Uitg[I]=CHR(32) THEN
  351. Write(FieldSpace)
  352. ELSE
  353. Write(Uitg[I]);
  354. END;
  355. IF Len<>Length(Uitg) THEN
  356. BEGIN
  357. GotoXY(X+Length(Uitg),Y);
  358. FOR I:= Length(Uitg) TO Len-1 DO
  359. Write(FieldSpace);
  360. END;
  361. END;
  362. PROCEDURE DoCursor; { Put Cursor in/out insert-mode }
  363. BEGIN
  364. {$IFNDEF Unix}
  365. { IF Ins THEN
  366. SetCursorSize($11E)
  367. ELSE
  368. SetCursorSize($71E); }
  369. {$ENDIF}
  370. END;
  371. BEGIN
  372. { Init }
  373. InGev :=0; { 0 chars untill now }
  374. Posi :=1; { Cursorposition 0 }
  375. Ins :=TRUE; { Insert according to parameters }
  376. DoCursor; { Set cursor accordingly }
  377. Key :=0;
  378. { put ±±± padded field on screen }
  379. FillChar(Uitg,Len+1,FieldSpace);
  380. Uitg[0]:=CHR(Len);
  381. ReWr;
  382. GotoXY(X,Y);
  383. FillChar(Uitg,Len,32);
  384. UitG[0]:=#0;
  385. IF TextIn THEN
  386. BEGIN
  387. Uitg:=S;
  388. Posi:=Length(Uitg)+1; { Put a predefined }
  389. ReWr; { String on screen if specified }
  390. END;
  391. EndVal:=0;
  392. WHILE EndVal=0 DO
  393. BEGIN
  394. Full:=FALSE;
  395. IF ((Posi)>=Len) THEN
  396. BEGIN
  397. Full:=TRUE;
  398. Posi:=Len;
  399. END;
  400. GotoXY(X+Posi-1,Y);
  401. {$IFNDEF Unix}
  402. {$IFDEF FPC}
  403. {$ifndef Win32Graph}
  404. CursorOn;
  405. {$endif}
  406. {$ENDIF}
  407. DoCursor;
  408. {$ENDIF}
  409. Key:=GetKey;
  410. {$IFNDEF Unix}
  411. {$IFDEF FPC}
  412. {$ifndef Win32Graph}
  413. CursorOff;
  414. {$endif}
  415. {$ENDIF}
  416. {$ENDIF}
  417. CASE Key OF
  418. CR : BEGIN
  419. EndVal:=1;
  420. S:=UitG;
  421. END;
  422. ESC : EndVal:=2;
  423. BS : IF Posi>1 THEN { BackSpace }
  424. BEGIN
  425. DEC(Posi);
  426. Delete(Uitg,Posi,1);
  427. DEC(InGev);
  428. ReWr;
  429. END;
  430. KDelete : BEGIN
  431. Delete(Uitg,Posi,1);
  432. DEC(InGev);
  433. ReWr;
  434. END;
  435. ArrR : IF (NOT Full) AND ((Posi-1)<InGev) THEN
  436. BEGIN
  437. INC (Posi);
  438. GotoXY(X+Posi-1,Y);
  439. END;
  440. KInsert : BEGIN
  441. Ins:= NOT Ins;
  442. DoCursor;
  443. END;
  444. ArrL : IF (NOT (Posi=1)) THEN
  445. BEGIN
  446. DEC (Posi);
  447. GotoXY(X+Posi-1,Y);
  448. END;
  449. Home : Posi:=1;
  450. KEnd : Posi:=InGev-1;
  451. CtrlY : BEGIN
  452. Delete(Uitg,Posi,Length(Uitg)-Posi);
  453. ReWr;
  454. END;
  455. CtrlT : BEGIN
  456. Uitg[0]:=#0; Posi:=1; ReWr;
  457. END;
  458. END; {Case}
  459. IF EndVal=0 THEN
  460. BEGIN
  461. IF (CHR(Key) IN CharAllow) THEN
  462. BEGIN
  463. IF Posi>Len THEN
  464. Posi:=Len;
  465. IF (Ins=FALSE) OR Full THEN
  466. BEGIN
  467. IF (ORD(Uitg[0])<Posi) THEN
  468. Uitg[0]:=CHR(Posi);
  469. Uitg[Posi]:=CHR(Key);
  470. END
  471. ELSE
  472. BEGIN
  473. Insert(CHR(Key),Uitg,Posi);
  474. END;
  475. ReWr;
  476. INC(Posi);
  477. END;
  478. END;
  479. InGev:=Length(Uitg);
  480. END;
  481. InputStr:=Endval=1;
  482. END;
  483. {$ENDIF}
  484. {$IFDEF UseGraphics}
  485. FUNCTION GrInputStr(VAR S:String;X,Y,Len,dX,dY:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
  486. {As the (older) textversion except:
  487. - oX,oY are in pixels.
  488. - dX,dY are the dimensions of the font.
  489. - Len is still characters ( length in pixels/dX)
  490. }
  491. VAR
  492. InGev : LONGINT; { No. of chars inputted }
  493. Posi : LONGINT; { Cursorposition}
  494. Ins : BOOLEAN; { Insert yes/no}
  495. Key : LONGINT; { Last key as ELib.GetKey
  496. code <255 if normal key,
  497. >256 if special/function
  498. key. See keys.inc}
  499. Uitg : String; {The inputted string}
  500. Full : BOOLEAN; { Is the string full? }
  501. EndVal : WORD;
  502. PROCEDURE ReWr; { Rewrite the field, using Uitg}
  503. VAR I : LONGINT; { Temporary variabele }
  504. S : String;
  505. BEGIN
  506. FillChar(S[1],Len,FieldSpace);
  507. S:=Uitg;
  508. IF Length(Uitg)>Len THEN
  509. SetLength(Uitg,Len);
  510. SetLength(S,Len);
  511. IF Length(S)>0 THEN
  512. BEGIN
  513. FOR I:= 1 TO Length(S) DO
  514. IF S[I]=CHR(32) THEN
  515. S[I]:=FieldSpace;
  516. SetFillStyle(SolidFill,0);
  517. Bar(X,Y,X+Len*Dx+5,Y+Dy+1);
  518. OutTextXY(X,Y,S);
  519. END;
  520. END;
  521. PROCEDURE DoCursor; { Put Cursor in/out insert-mode }
  522. BEGIN
  523. {$IFNDEF Unix}
  524. { IF Ins THEN
  525. SetCursorSize($11E)
  526. ELSE
  527. SetCursorSize($71E); }
  528. {$ENDIF}
  529. END;
  530. BEGIN
  531. { Init }
  532. InGev :=0; { 0 chars untill now }
  533. Posi :=1; { Cursorposition 0 }
  534. Ins :=TRUE; { Insert according to parameters }
  535. DoCursor; { Set cursor accordingly }
  536. Key :=0;
  537. // SetFillStyle(SolidFill,0);
  538. // Bar(X,Y,X+Len*Dx+5,Y+Dy+1);
  539. { put ±±± padded field on screen }
  540. FillChar(Uitg,Len+1,FieldSpace);
  541. Uitg[0]:=CHR(Len);
  542. ReWr;
  543. // GotoXY(X,Y);
  544. FillChar(Uitg,Len,32);
  545. SetLength(UitG,0);
  546. IF TextIn THEN
  547. BEGIN
  548. Uitg:=S;
  549. Posi:=Length(Uitg)+1; { Put a predefined }
  550. ReWr; { String on screen if specified }
  551. END;
  552. EndVal:=0;
  553. WHILE EndVal=0 DO
  554. BEGIN
  555. Full:=FALSE;
  556. IF ((Posi)>=Len) THEN
  557. BEGIN
  558. Full:=TRUE;
  559. Posi:=Len;
  560. END;
  561. {$IFNDEF Unix}
  562. {$IFDEF FPC}
  563. {$ifndef Win32Graph}
  564. CursorOn;
  565. {$endif}
  566. {$ENDIF}
  567. DoCursor;
  568. {$ENDIF}
  569. Key:=GetKey;
  570. {$IFNDEF Unix}
  571. {$IFDEF FPC}
  572. {$ifndef Win32Graph}
  573. CursorOff;
  574. {$endif}
  575. {$ENDIF}
  576. {$ENDIF}
  577. CASE Key OF
  578. CR : BEGIN
  579. EndVal:=1;
  580. S:=UitG;
  581. END;
  582. ESC : EndVal:=2;
  583. BS : IF Posi>1 THEN { BackSpace }
  584. BEGIN
  585. DEC(Posi);
  586. Delete(Uitg,Posi,1);
  587. DEC(InGev);
  588. ReWr;
  589. END;
  590. KDelete : BEGIN
  591. Delete(Uitg,Posi,1);
  592. DEC(InGev);
  593. ReWr;
  594. END;
  595. ArrR : IF (NOT Full) AND ((Posi-1)<InGev) THEN
  596. BEGIN
  597. INC (Posi);
  598. // GotoXY(X+Posi-1,Y);
  599. END;
  600. KInsert : BEGIN
  601. Ins:= NOT Ins;
  602. DoCursor;
  603. END;
  604. ArrL : IF (NOT (Posi=1)) THEN
  605. BEGIN
  606. DEC (Posi);
  607. END;
  608. Home : Posi:=1;
  609. KEnd : Posi:=InGev-1;
  610. CtrlY : BEGIN
  611. Delete(Uitg,Posi,Length(Uitg)-Posi);
  612. ReWr;
  613. END;
  614. CtrlT : BEGIN
  615. Uitg[0]:=#0; Posi:=1; ReWr;
  616. END;
  617. END; {Case}
  618. IF EndVal=0 THEN
  619. BEGIN
  620. IF (CHR(Key) IN CharAllow) THEN
  621. BEGIN
  622. IF Posi>Len THEN
  623. Posi:=Len;
  624. IF (Ins=FALSE) OR Full THEN
  625. BEGIN
  626. IF (Length(Uitg)<Posi) THEN
  627. SetLength(UitG,Posi);
  628. Uitg[Posi]:=CHR(Key);
  629. END
  630. ELSE
  631. Insert(CHR(Key),Uitg,Posi);
  632. ReWr;
  633. INC(Posi);
  634. END;
  635. END;
  636. InGev:=Length(Uitg);
  637. END;
  638. GrInputStr:=Endval=1;
  639. END;
  640. {$ENDIF}
  641. PROCEDURE SetDefaultColor;
  642. BEGIN
  643. {$ifndef UseGraphics}
  644. TextColor(DefColor AND 15);
  645. TextBackground(DefColor SHR 4);
  646. {$endif}
  647. END;
  648. {$IFNDEF FPC}
  649. PROCEDURE SetCursorSize(CurDat:WORD);ASSEMBLER;
  650. ASM
  651. mov ah,1
  652. mov cx,CurDat
  653. int $10
  654. END;
  655. {The two procedures below are standard (and os-independant) in FPC's Crt}
  656. PROCEDURE CursorOn;
  657. BEGIN
  658. SetCursorSize($090A);
  659. END;
  660. PROCEDURE CursorOff;
  661. BEGIN
  662. SetCursorSize($FFFF);
  663. END;
  664. PROCEDURE dosmemfillword(Segx,xofs,Count,Value:WORD); ASSEMBLER;
  665. {VAR A:WORD;
  666. BEGIN
  667. FOR A :=0 TO Count-1 DO
  668. MemW[Seg:xofs+2*A]:=Value;
  669. END;
  670. }
  671. ASM
  672. mov ax,segx
  673. mov es,ax
  674. mov di,xofs
  675. mov cx,count
  676. mov ax,value
  677. rep
  678. stosw
  679. end;
  680. {TYPE VetteArray=ARRAY[0..9999] OF BYTE;}
  681. PROCEDURE dosmemput(Segx,xofs:WORD;VAR Data;Count:WORD); assembler;
  682. {VAR A:WORD;
  683. L:^VetteArray;
  684. BEGIN
  685. L:=@Data;
  686. FOR A :=0 TO Count-1 DO
  687. Mem[Segx:xofs+A]:=L^[A];
  688. END;
  689. }
  690. asm
  691. lds si,Data
  692. mov ax,segx
  693. mov es,ax
  694. mov di,xofs
  695. mov cx,count
  696. rep
  697. movsw
  698. end;
  699. PROCEDURE dosmemget(Segx,xofs:WORD;VAR Data;Count:WORD); ASSEMBLER;
  700. {VAR A:WORD;
  701. L:^VetteArray;
  702. BEGIN
  703. L:=@Data;
  704. FOR A :=0 TO Count-1 DO
  705. L^[A]:=Mem[Segx:xofs+A];
  706. END;
  707. }
  708. asm
  709. les di,Data
  710. mov ax,segx
  711. mov ds,ax
  712. mov si,xofs
  713. mov cx,count
  714. rep
  715. movsw
  716. end;
  717. PROCEDURE FillWord(VAR Data;Count,Value:WORD); ASSEMBLER;
  718. {VAR A :WORD;
  719. L:^VetteArray;
  720. BEGIN
  721. L:=@Data;
  722. FOR A:=0 TO Count-1 DO
  723. Begin
  724. L^[2*A]:=Value AND 255;
  725. L^[2*A+1]:=Value shr 8;
  726. END;
  727. END;}
  728. asm
  729. les di,Data
  730. mov cx,count
  731. mov ax,Value
  732. rep
  733. movsw
  734. end;
  735. FUNCTION GetCursorSize:WORD;ASSEMBLER;
  736. ASM
  737. mov ah,3
  738. xor bh,bh
  739. int $10
  740. mov ax,cx
  741. END;
  742. FUNCTION inportb(portx : word) : byte;
  743. BEGIN
  744. Inportb:=Port[PortX];
  745. END;
  746. PROCEDURE outportb(portx : word;data : byte);
  747. BEGIN
  748. Port[portx]:=Data;
  749. END;
  750. FUNCTION inportw(portx : word) : word;
  751. BEGIN
  752. Inportw:=Portw[PortX];
  753. END;
  754. PROCEDURE outportw(portx : word;data : word);
  755. BEGIN
  756. PortW[portx]:=Data;
  757. END;
  758. FUNCTION inportl(portx : word) : longint; ASSEMBLER;
  759. ASM
  760. mov dx,portx { load port address }
  761. db $66; in ax,dx { in eax,dx }
  762. db $66; mov dx,ax { mov edx, eax }
  763. db $66; shr dx,16 { shr edx, 16 }
  764. { return: ax=low word, dx=hi word }
  765. END;
  766. PROCEDURE outportl(portx : word;data : longint); ASSEMBLER;
  767. ASM
  768. { we cant use the 32 bit operand prefix for loading the longint -
  769. therefore we have to do that in two chunks }
  770. mov dx, portx
  771. db $66; mov ax, Word(Data) { mov eax, Data }
  772. db $66; out dx,ax { out dx, eax }
  773. END;
  774. {$ENDIF}
  775. BEGIN
  776. {$ifndef Win32Graph}
  777. DefColor:=TextAttr; { Save the current attributes, to restore}
  778. {$endif}
  779. Negative:=FALSE; { Negative=true-> better scores are lower}
  780. END.
  781. {
  782. $Log$
  783. Revision 1.8 2002-09-07 15:06:35 peter
  784. * old logs removed and tabs fixed
  785. Revision 1.7 2002/06/02 17:34:21 marco
  786. * Renamefest
  787. Revision 1.6 2002/06/02 09:49:17 marco
  788. * Renamefest
  789. Revision 1.5 2002/02/25 12:23:05 marco
  790. * Fixes for Quad Win32 GUI mode
  791. Revision 1.4 2002/02/22 21:40:09 carl
  792. * fix compilation problem
  793. }