Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. unit main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.   ExtCtrls, Buttons, StdCtrls;
  10.  
  11. type
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Bevel1: TBevel;
  15.     Bevel2: TBevel;
  16.     ButtonHelp: TButton;
  17.     ButtonDef: TButton;
  18.     ButtonOpen: TButton;
  19.     ButtonSave: TButton;
  20.     ButtonFWPath: TButton;
  21.     ButtonExit: TButton;
  22.     OpenDialog1: TOpenDialog;
  23.     SaveDialog1: TSaveDialog;
  24.     procedure ButtonDefClick(Sender: TObject);
  25.     procedure ButtonExitClick(Sender: TObject);
  26.     procedure ButtonFWPathClick(Sender: TObject);
  27.     procedure ButtonSaveClick(Sender: TObject);
  28.     procedure ButtonHelpClick(Sender: TObject);
  29.     procedure ButtonOpenClick(Sender: TObject);
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  32.       Shift: TShiftState; X, Y: Integer);
  33.     procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
  34.       Shift: TShiftState; X, Y: Integer);
  35.     procedure FormPaint(Sender: TObject);
  36.     procedure FormResize(Sender: TObject);
  37.   private
  38.     { private declarations }
  39.   public
  40.     { public declarations }
  41.   end;
  42.  
  43. var
  44.   Form1:TForm1;
  45.  
  46. implementation
  47.  
  48. {$R *.lfm}
  49.  
  50. { TForm1 }
  51.  
  52. type
  53.   key_rcrd = record
  54.    x1, y1, x2, y2, cd   :byte;
  55.    n1, n2               :string;
  56.   end;
  57.  
  58. const
  59.   pckeys: array[0..124] of key_rcrd = (
  60.     (x1: 3;y1: 9;x2: 7;y2:13;cd:$ff; n1:'Esc';   n2:''),
  61.     (x1:11;y1: 9;x2:15;y2:13;cd:$05; n1:'F1';    n2:''),
  62.     (x1:15;y1: 9;x2:19;y2:13;cd:$06; n1:'F2';    n2:''),
  63.     (x1:19;y1: 9;x2:23;y2:13;cd:$04; n1:'F3';    n2:''),
  64.     (x1:23;y1: 9;x2:27;y2:13;cd:$0c; n1:'F4';    n2:''),
  65.     (x1:29;y1: 9;x2:33;y2:13;cd:$03; n1:'F5';    n2:''),
  66.     (x1:33;y1: 9;x2:37;y2:13;cd:$0b; n1:'F6';    n2:''),
  67.     (x1:37;y1: 9;x2:41;y2:13;cd:$7f; n1:'F7';    n2:''),
  68.     (x1:41;y1: 9;x2:45;y2:13;cd:$0a; n1:'F8';    n2:''),
  69.     (x1:47;y1: 9;x2:51;y2:13;cd:$01; n1:'F9';    n2:''),
  70.     (x1:51;y1: 9;x2:55;y2:13;cd:$09; n1:'F10';   n2:''),
  71.     (x1:55;y1: 9;x2:59;y2:13;cd:$78; n1:'F11';   n2:''),
  72.     (x1:59;y1: 9;x2:63;y2:13;cd:$ff; n1:'F12';   n2:''),
  73.     (x1:65;y1: 9;x2:69;y2:13;cd:$ff; n1:'PrtScr';n2:'SysRq'),
  74.     (x1:69;y1: 9;x2:73;y2:13;cd:$ff; n1:'Scroll';n2:'Lock'),
  75.     (x1:73;y1: 9;x2:77;y2:13;cd:$ff; n1:'Pause'; n2:'Break'),
  76.  
  77.     (x1: 3;y1:15;x2: 7;y2:19;cd:$0e; n1:'~';     n2:'`'),
  78.     (x1: 7;y1:15;x2:11;y2:19;cd:$16; n1:'!';     n2:'1'),
  79.     (x1:11;y1:15;x2:15;y2:19;cd:$1e; n1:'@';     n2:'2'),
  80.     (x1:15;y1:15;x2:19;y2:19;cd:$26; n1:'#';     n2:'3'),
  81.     (x1:19;y1:15;x2:23;y2:19;cd:$25; n1:'$';     n2:'4'),
  82.     (x1:23;y1:15;x2:27;y2:19;cd:$2e; n1:'%';     n2:'5'),
  83.     (x1:27;y1:15;x2:31;y2:19;cd:$36; n1:'^';     n2:'6'),
  84.     (x1:31;y1:15;x2:35;y2:19;cd:$3d; n1:'&';     n2:'7'),
  85.     (x1:35;y1:15;x2:39;y2:19;cd:$3e; n1:'*';     n2:'8'),
  86.     (x1:39;y1:15;x2:43;y2:19;cd:$46; n1:'(';     n2:'9'),
  87.     (x1:43;y1:15;x2:47;y2:19;cd:$45; n1:')';     n2:'0'),
  88.     (x1:47;y1:15;x2:51;y2:19;cd:$4e; n1:'_';     n2:'-'),
  89.     (x1:51;y1:15;x2:55;y2:19;cd:$55; n1:'+';     n2:'='),
  90.     (x1:55;y1:15;x2:59;y2:19;cd:$5d; n1:'|';     n2:'\'),
  91.     (x1:59;y1:15;x2:63;y2:19;cd:$66; n1:'BkSp';  n2:''),
  92.     (x1:65;y1:15;x2:69;y2:19;cd:$f0; n1:'Insert';n2:''),
  93.     (x1:69;y1:15;x2:73;y2:19;cd:$ec; n1:'Home';  n2:''),
  94.     (x1:73;y1:15;x2:77;y2:19;cd:$fd; n1:'Page';  n2:'Up'),
  95.     (x1:79;y1:15;x2:83;y2:19;cd:$ff; n1:'Num';   n2:'Lock'),
  96.     (x1:83;y1:15;x2:87;y2:19;cd:$ca; n1:'/';     n2:''),
  97.     (x1:87;y1:15;x2:91;y2:19;cd:$7c; n1:'*';     n2:''),
  98.     (x1:91;y1:15;x2:95;y2:19;cd:$7b; n1:'-';     n2:''),
  99.  
  100.     (x1: 3;y1:19;x2: 9;y2:23;cd:$0d; n1:'Tab';   n2:''),
  101.     (x1: 9;y1:19;x2:13;y2:23;cd:$15; n1:'Q';     n2:''),
  102.     (x1:13;y1:19;x2:17;y2:23;cd:$1d; n1:'W';     n2:''),
  103.     (x1:17;y1:19;x2:21;y2:23;cd:$24; n1:'E';     n2:''),
  104.     (x1:21;y1:19;x2:25;y2:23;cd:$2d; n1:'R';     n2:''),
  105.     (x1:25;y1:19;x2:29;y2:23;cd:$2c; n1:'T';     n2:''),
  106.     (x1:29;y1:19;x2:33;y2:23;cd:$35; n1:'Y';     n2:''),
  107.     (x1:33;y1:19;x2:37;y2:23;cd:$3c; n1:'U';     n2:''),
  108.     (x1:37;y1:19;x2:41;y2:23;cd:$43; n1:'I';     n2:''),
  109.     (x1:41;y1:19;x2:45;y2:23;cd:$44; n1:'O';     n2:''),
  110.     (x1:45;y1:19;x2:49;y2:23;cd:$4d; n1:'P';     n2:''),
  111.     (x1:49;y1:19;x2:53;y2:23;cd:$54; n1:'[';     n2:'{'),
  112.     (x1:53;y1:19;x2:57;y2:23;cd:$5b; n1:']';     n2:'}'),
  113.     (x1:65;y1:19;x2:69;y2:23;cd:$f1; n1:'Delete';n2:''),
  114.     (x1:69;y1:19;x2:73;y2:23;cd:$e9; n1:'End';   n2:''),
  115.     (x1:73;y1:19;x2:77;y2:23;cd:$fa; n1:'Page';  n2:'Down'),
  116.     (x1:79;y1:19;x2:83;y2:23;cd:$6c; n1:'7';     n2:'Home'),
  117.     (x1:83;y1:19;x2:87;y2:23;cd:$75; n1:'8';     n2:'Up'),
  118.     (x1:87;y1:19;x2:91;y2:23;cd:$7d; n1:'9';     n2:'PgUp'),
  119.  
  120.     (x1: 3;y1:23;x2:10;y2:27;cd:$58; n1:'Caps';  n2:'Lock'),
  121.     (x1:10;y1:23;x2:14;y2:27;cd:$1c; n1:'A';     n2:''),
  122.     (x1:14;y1:23;x2:18;y2:27;cd:$1b; n1:'S';     n2:''),
  123.     (x1:18;y1:23;x2:22;y2:27;cd:$23; n1:'D';     n2:''),
  124.     (x1:22;y1:23;x2:26;y2:27;cd:$2b; n1:'F';     n2:''),
  125.     (x1:26;y1:23;x2:30;y2:27;cd:$34; n1:'G';     n2:''),
  126.     (x1:30;y1:23;x2:34;y2:27;cd:$33; n1:'H';     n2:''),
  127.     (x1:34;y1:23;x2:38;y2:27;cd:$3b; n1:'J';     n2:''),
  128.     (x1:38;y1:23;x2:42;y2:27;cd:$42; n1:'K';     n2:''),
  129.     (x1:42;y1:23;x2:46;y2:27;cd:$4b; n1:'L';     n2:''),
  130.     (x1:46;y1:23;x2:50;y2:27;cd:$4c; n1:':';     n2:';'),
  131.     (x1:50;y1:23;x2:54;y2:27;cd:$52; n1:#$22;    n2:#$27),
  132.     (x1:54;y1:19;x2:63;y2:27;cd:$5a; n1:'';      n2:'Enter'),
  133.     (x1:79;y1:23;x2:83;y2:27;cd:$6b; n1:'4';     n2:'Left'),
  134.     (x1:83;y1:23;x2:87;y2:27;cd:$73; n1:'5';     n2:''),
  135.     (x1:87;y1:23;x2:91;y2:27;cd:$74; n1:'6';     n2:'Right'),
  136.     (x1:91;y1:19;x2:95;y2:27;cd:$79; n1:'+';     n2:''),
  137.  
  138.     (x1: 3;y1:27;x2:12;y2:31;cd:$12; n1:'Shift'; n2:''),
  139.     (x1:12;y1:27;x2:16;y2:31;cd:$1a; n1:'Z';     n2:''),
  140.     (x1:16;y1:27;x2:20;y2:31;cd:$22; n1:'X';     n2:''),
  141.     (x1:20;y1:27;x2:24;y2:31;cd:$21; n1:'C';     n2:''),
  142.     (x1:24;y1:27;x2:28;y2:31;cd:$2a; n1:'V';     n2:''),
  143.     (x1:28;y1:27;x2:32;y2:31;cd:$32; n1:'B';     n2:''),
  144.     (x1:32;y1:27;x2:36;y2:31;cd:$31; n1:'N';     n2:''),
  145.     (x1:36;y1:27;x2:40;y2:31;cd:$3a; n1:'M';     n2:''),
  146.     (x1:40;y1:27;x2:44;y2:31;cd:$41; n1:'<';     n2:','),
  147.     (x1:44;y1:27;x2:48;y2:31;cd:$49; n1:'>';     n2:'.'),
  148.     (x1:48;y1:27;x2:52;y2:31;cd:$4a; n1:'?';     n2:'/'),
  149.     (x1:52;y1:27;x2:63;y2:31;cd:$59; n1:'Shift'; n2:''),
  150.     (x1:69;y1:27;x2:73;y2:31;cd:$f5; n1:'Up';    n2:''),
  151.     (x1:79;y1:27;x2:83;y2:31;cd:$69; n1:'1';     n2:'End'),
  152.     (x1:83;y1:27;x2:87;y2:31;cd:$72; n1:'2';     n2:'Down'),
  153.     (x1:87;y1:27;x2:91;y2:31;cd:$7a; n1:'3';     n2:'PgDn'),
  154.  
  155.     (x1: 3;y1:31;x2: 9;y2:35;cd:$14; n1:'Ctrl';  n2:''),
  156.     (x1: 9;y1:31;x2:14;y2:35;cd:$9f; n1:'Win';   n2:''),
  157.     (x1:14;y1:31;x2:19;y2:35;cd:$11; n1:'Alt';   n2:''),
  158.     (x1:19;y1:31;x2:42;y2:35;cd:$29; n1:'Space'; n2:''),
  159.     (x1:42;y1:31;x2:47;y2:35;cd:$91; n1:'Alt Gr';n2:''),
  160.     (x1:47;y1:31;x2:52;y2:35;cd:$a7; n1:'Win';   n2:''),
  161.     (x1:52;y1:31;x2:57;y2:35;cd:$af; n1:'Context'; n2:'Menu'),
  162.     (x1:57;y1:31;x2:63;y2:35;cd:$94; n1:'Ctrl';  n2:''),
  163.     (x1:65;y1:31;x2:69;y2:35;cd:$eb; n1:'Left';  n2:''),
  164.     (x1:69;y1:31;x2:73;y2:35;cd:$f2; n1:'Down';  n2:''),
  165.     (x1:73;y1:31;x2:77;y2:35;cd:$f4; n1:'Right'; n2:''),
  166.     (x1:79;y1:31;x2:87;y2:35;cd:$70; n1:'0';     n2:'Ins'),
  167.     (x1:87;y1:31;x2:91;y2:35;cd:$71; n1:'.';     n2:'Del'),
  168.     (x1:91;y1:27;x2:95;y2:35;cd:$da; n1:'Enter'; n2:''),
  169.  
  170.     (x1: 5;y1: 3;x2: 9;y2: 7;cd:$c0; n1:'My';    n2:'Comp'),
  171.     (x1: 9;y1: 3;x2:13;y2: 7;cd:$ab; n1:'Calc';  n2:''),
  172.     (x1:13;y1: 3;x2:17;y2: 7;cd:$d0; n1:'Media'; n2:''),
  173.     (x1:17;y1: 3;x2:21;y2: 7;cd:$95; n1:'Prev';  n2:'Track'),
  174.     (x1:21;y1: 3;x2:25;y2: 7;cd:$b4; n1:'Play';  n2:'Pause'),
  175.     (x1:25;y1: 3;x2:29;y2: 7;cd:$bb; n1:'Stop';  n2:''),
  176.     (x1:29;y1: 3;x2:33;y2: 7;cd:$cd; n1:'Next';  n2:'Track'),
  177.     (x1:33;y1: 3;x2:37;y2: 7;cd:$b2; n1:'Vol';   n2:'Up'),
  178.     (x1:37;y1: 3;x2:41;y2: 7;cd:$a1; n1:'Vol';   n2:'Down'),
  179.     (x1:41;y1: 3;x2:45;y2: 7;cd:$a3; n1:'Mute';  n2:''),
  180.     (x1:45;y1: 3;x2:49;y2: 7;cd:$c8; n1:'E-Mail';n2:''),
  181.     (x1:49;y1: 3;x2:53;y2: 7;cd:$b8; n1:'WWW';   n2:'Back'),
  182.     (x1:53;y1: 3;x2:57;y2: 7;cd:$b0; n1:'WWW';   n2:'Frwrd'),
  183.     (x1:57;y1: 3;x2:61;y2: 7;cd:$a0; n1:'WWW';   n2:'Rfrsh'),
  184.     (x1:61;y1: 3;x2:65;y2: 7;cd:$a8; n1:'WWW';   n2:'Stop'),
  185.     (x1:65;y1: 3;x2:69;y2: 7;cd:$ba; n1:'WWW';   n2:'Home'),
  186.     (x1:69;y1: 3;x2:73;y2: 7;cd:$90; n1:'WWW';   n2:'Search'),
  187.     (x1:73;y1: 3;x2:77;y2: 7;cd:$98; n1:'WWW';   n2:'Favor'),
  188.     (x1:81;y1: 3;x2:85;y2: 7;cd:$b7; n1:'Power'; n2:''),
  189.     (x1:85;y1: 3;x2:89;y2: 7;cd:$bf; n1:'Sleep'; n2:''),
  190.     (x1:89;y1: 3;x2:93;y2: 7;cd:$de; n1:'Wake';  n2:'')
  191.   );
  192.  
  193.   zxkeys: array[0..41] of key_rcrd = (
  194.     (x1:27;y1:39;x2:31;y2:43;cd: 4; n1:'1'; n2:''),
  195.     (x1:31;y1:39;x2:35;y2:43;cd:12; n1:'2'; n2:''),
  196.     (x1:35;y1:39;x2:39;y2:43;cd:20; n1:'3'; n2:''),
  197.     (x1:39;y1:39;x2:43;y2:43;cd:28; n1:'4'; n2:''),
  198.     (x1:43;y1:39;x2:47;y2:43;cd:36; n1:'5'; n2:''),
  199.     (x1:47;y1:39;x2:51;y2:43;cd:35; n1:'6'; n2:''),
  200.     (x1:51;y1:39;x2:55;y2:43;cd:27; n1:'7'; n2:''),
  201.     (x1:55;y1:39;x2:59;y2:43;cd:19; n1:'8'; n2:''),
  202.     (x1:59;y1:39;x2:63;y2:43;cd:11; n1:'9'; n2:''),
  203.     (x1:63;y1:39;x2:67;y2:43;cd: 3; n1:'0'; n2:''),
  204.  
  205.     (x1:29;y1:43;x2:33;y2:47;cd: 5; n1:'Q'; n2:''),
  206.     (x1:33;y1:43;x2:37;y2:47;cd:13; n1:'W'; n2:''),
  207.     (x1:37;y1:43;x2:41;y2:47;cd:21; n1:'E'; n2:''),
  208.     (x1:41;y1:43;x2:45;y2:47;cd:29; n1:'R'; n2:''),
  209.     (x1:45;y1:43;x2:49;y2:47;cd:37; n1:'T'; n2:''),
  210.     (x1:49;y1:43;x2:53;y2:47;cd:34; n1:'Y'; n2:''),
  211.     (x1:53;y1:43;x2:57;y2:47;cd:26; n1:'U'; n2:''),
  212.     (x1:57;y1:43;x2:61;y2:47;cd:18; n1:'I'; n2:''),
  213.     (x1:61;y1:43;x2:65;y2:47;cd:10; n1:'O'; n2:''),
  214.     (x1:65;y1:43;x2:69;y2:47;cd: 2; n1:'P'; n2:''),
  215.  
  216.     (x1:30;y1:47;x2:34;y2:51;cd: 6; n1:'A'; n2:''),
  217.     (x1:34;y1:47;x2:38;y2:51;cd:14; n1:'S'; n2:''),
  218.     (x1:38;y1:47;x2:42;y2:51;cd:22; n1:'D'; n2:''),
  219.     (x1:42;y1:47;x2:46;y2:51;cd:30; n1:'F'; n2:''),
  220.     (x1:46;y1:47;x2:50;y2:51;cd:38; n1:'G'; n2:''),
  221.     (x1:50;y1:47;x2:54;y2:51;cd:33; n1:'H'; n2:''),
  222.     (x1:54;y1:47;x2:58;y2:51;cd:25; n1:'J'; n2:''),
  223.     (x1:58;y1:47;x2:62;y2:51;cd:17; n1:'K'; n2:''),
  224.     (x1:62;y1:47;x2:66;y2:51;cd: 9; n1:'L'; n2:''),
  225.     (x1:66;y1:47;x2:70;y2:51;cd: 1; n1:'Enter'; n2:''),
  226.  
  227.     (x1:27;y1:51;x2:32;y2:55;cd: 7; n1:'Caps'; n2:'Shift'),
  228.     (x1:32;y1:51;x2:36;y2:55;cd:15; n1:'Z'; n2:''),
  229.     (x1:36;y1:51;x2:40;y2:55;cd:23; n1:'X'; n2:''),
  230.     (x1:40;y1:51;x2:44;y2:55;cd:31; n1:'C'; n2:''),
  231.     (x1:44;y1:51;x2:48;y2:55;cd:39; n1:'V'; n2:''),
  232.     (x1:48;y1:51;x2:52;y2:55;cd:32; n1:'B'; n2:''),
  233.     (x1:52;y1:51;x2:56;y2:55;cd:24; n1:'N'; n2:''),
  234.     (x1:56;y1:51;x2:60;y2:55;cd:16; n1:'M'; n2:''),
  235.     (x1:60;y1:51;x2:64;y2:55;cd: 8; n1:'Symb'; n2:'Shift'),
  236.     (x1:64;y1:51;x2:70;y2:55;cd: 0; n1:'Space'; n2:''),
  237.  
  238.     (x1:17;y1:39;x2:23;y2:43;cd:127;n1:'Not'; n2:'mapped'),
  239.     (x1:74;y1:39;x2:80;y2:43;cd:127;n1:'Not'; n2:'mapped')
  240.   );
  241.  
  242.   defkbmap:array [0..511] of byte=(
  243.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  244.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$07,$00,$07,$04,$7F,$7F,
  245.     $7F,$7F,$7F,$7F,$07,$7F,$7F,$7F,$7F,$7F,$05,$7F,$04,$7F,$7F,$7F,
  246.     $7F,$7F,$7F,$7F,$0F,$7F,$0E,$7F,$06,$7F,$0D,$7F,$0C,$7F,$7F,$7F,
  247.     $7F,$7F,$1F,$7F,$17,$7F,$16,$7F,$15,$7F,$1C,$7F,$14,$7F,$7F,$7F,
  248.     $7F,$7F,$00,$7F,$27,$7F,$1E,$7F,$25,$7F,$1D,$7F,$24,$7F,$7F,$7F,
  249.     $7F,$7F,$18,$7F,$20,$7F,$21,$7F,$26,$7F,$22,$7F,$23,$7F,$7F,$7F,
  250.     $7F,$7F,$7F,$7F,$10,$7F,$19,$7F,$1A,$7F,$1B,$7F,$13,$7F,$7F,$7F,
  251.     $7F,$7F,$08,$18,$11,$7F,$12,$7F,$0A,$7F,$03,$7F,$0B,$7F,$7F,$7F,
  252.     $7F,$7F,$08,$10,$08,$1F,$09,$7F,$08,$0F,$02,$7F,$08,$19,$7F,$7F,
  253.     $7F,$7F,$7F,$7F,$08,$02,$7F,$7F,$08,$13,$08,$11,$7F,$7F,$7F,$7F,
  254.     $07,$0C,$08,$7F,$01,$7F,$08,$0B,$7F,$7F,$08,$07,$7F,$7F,$7F,$7F,
  255.     $7F,$7F,$08,$07,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$07,$03,$7F,$7F,
  256.     $7F,$7F,$04,$7F,$7F,$7F,$1C,$7F,$1B,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  257.     $03,$7F,$08,$10,$0C,$7F,$24,$7F,$23,$7F,$13,$7F,$7A,$7F,$7F,$7F,
  258.     $7F,$7F,$08,$11,$14,$7F,$08,$19,$08,$20,$0B,$7F,$7F,$7F,$7F,$7F,
  259.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  260.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  261.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  262.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  263.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  264.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  265.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  266.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  267.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  268.     $7F,$7F,$7F,$7F,$08,$27,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  269.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  270.     $7F,$7F,$7F,$7F,$01,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  271.     $7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,$7F,
  272.     $7F,$7F,$08,$15,$7F,$7F,$07,$24,$08,$05,$7F,$7F,$7F,$7F,$7F,$7F,
  273.     $08,$0D,$07,$0B,$07,$23,$7F,$7F,$07,$13,$07,$1B,$7A,$7F,$7F,$7F,
  274.     $7F,$7F,$7F,$7F,$07,$1C,$7F,$7F,$7F,$7F,$07,$14,$7F,$7F,$7F,$7F
  275.    );
  276.  
  277. var
  278.   hidbmp                :TBitmap;
  279.   scale, x0, y0         :integer;
  280.   kbmap                 :array [0..511] of byte;
  281.   pckey_selected        :byte;
  282.   was_mousedown         :boolean;
  283.  
  284. function CRC16_XModem( pb:PByte; count:integer ):word;
  285. const
  286.   tbl16:array [0..255] of word=(
  287.     $0000,$1021,$2042,$3063,$4084,$50a5,$60c6,$70e7,
  288.     $8108,$9129,$a14a,$b16b,$c18c,$d1ad,$e1ce,$f1ef,
  289.     $1231,$0210,$3273,$2252,$52b5,$4294,$72f7,$62d6,
  290.     $9339,$8318,$b37b,$a35a,$d3bd,$c39c,$f3ff,$e3de,
  291.     $2462,$3443,$0420,$1401,$64e6,$74c7,$44a4,$5485,
  292.     $a56a,$b54b,$8528,$9509,$e5ee,$f5cf,$c5ac,$d58d,
  293.     $3653,$2672,$1611,$0630,$76d7,$66f6,$5695,$46b4,
  294.     $b75b,$a77a,$9719,$8738,$f7df,$e7fe,$d79d,$c7bc,
  295.     $48c4,$58e5,$6886,$78a7,$0840,$1861,$2802,$3823,
  296.     $c9cc,$d9ed,$e98e,$f9af,$8948,$9969,$a90a,$b92b,
  297.     $5af5,$4ad4,$7ab7,$6a96,$1a71,$0a50,$3a33,$2a12,
  298.     $dbfd,$cbdc,$fbbf,$eb9e,$9b79,$8b58,$bb3b,$ab1a,
  299.     $6ca6,$7c87,$4ce4,$5cc5,$2c22,$3c03,$0c60,$1c41,
  300.     $edae,$fd8f,$cdec,$ddcd,$ad2a,$bd0b,$8d68,$9d49,
  301.     $7e97,$6eb6,$5ed5,$4ef4,$3e13,$2e32,$1e51,$0e70,
  302.     $ff9f,$efbe,$dfdd,$cffc,$bf1b,$af3a,$9f59,$8f78,
  303.     $9188,$81a9,$b1ca,$a1eb,$d10c,$c12d,$f14e,$e16f,
  304.     $1080,$00a1,$30c2,$20e3,$5004,$4025,$7046,$6067,
  305.     $83b9,$9398,$a3fb,$b3da,$c33d,$d31c,$e37f,$f35e,
  306.     $02b1,$1290,$22f3,$32d2,$4235,$5214,$6277,$7256,
  307.     $b5ea,$a5cb,$95a8,$8589,$f56e,$e54f,$d52c,$c50d,
  308.     $34e2,$24c3,$14a0,$0481,$7466,$6447,$5424,$4405,
  309.     $a7db,$b7fa,$8799,$97b8,$e75f,$f77e,$c71d,$d73c,
  310.     $26d3,$36f2,$0691,$16b0,$6657,$7676,$4615,$5634,
  311.     $d94c,$c96d,$f90e,$e92f,$99c8,$89e9,$b98a,$a9ab,
  312.     $5844,$4865,$7806,$6827,$18c0,$08e1,$3882,$28a3,
  313.     $cb7d,$db5c,$eb3f,$fb1e,$8bf9,$9bd8,$abbb,$bb9a,
  314.     $4a75,$5a54,$6a37,$7a16,$0af1,$1ad0,$2ab3,$3a92,
  315.     $fd2e,$ed0f,$dd6c,$cd4d,$bdaa,$ad8b,$9de8,$8dc9,
  316.     $7c26,$6c07,$5c64,$4c45,$3ca2,$2c83,$1ce0,$0cc1,
  317.     $ef1f,$ff3e,$cf5d,$df7c,$af9b,$bfba,$8fd9,$9ff8,
  318.     $6e17,$7e36,$4e55,$5e74,$2e93,$3eb2,$0ed1,$1ef0
  319.   );
  320. var
  321.   i     :integer;
  322.   crc   :word;
  323. begin
  324.   crc:=0;
  325.   for i:=1 to count do
  326.   begin
  327.     crc:=tbl16[hi(crc) xor pb^] xor word(crc shl 8);
  328.     inc(pb);
  329.   end;
  330.   result:=crc;
  331. end;
  332.  
  333. function fw_version_str( pb:pbyte ):string;
  334. var
  335.   name, beta            :string;
  336.   w                     :word;
  337.   day, mouth, year      :byte;
  338. begin
  339.   name:='';
  340.   for w:=0 to 11 do
  341.   begin
  342.    if pb^<>0 then name:=name+chr(pb^);
  343.    inc(pb);
  344.   end;
  345.   w:=pb^;
  346.   inc(pb);
  347.   w:=w or (pb^ shl 8);
  348.   day:=w and $1f;
  349.   mouth:=(w shr 5) and $0f;
  350.   year:=(w shr 9) and $3f;
  351.   if (w and $8000)<>0 then beta:='' else beta:=' beta';
  352.   result:=Format('%s %.2u.%.2u.20%.2u%s',[name,day,mouth,year,beta]);
  353. end;
  354.  
  355. procedure recalc_and_rebuild;
  356. var
  357.   i, kb, sx, sy,
  358.   kx1, ky1, kx2, ky2    :integer;
  359.   zk1, zk2              :byte;
  360. begin
  361.   sx:=Form1.Width div 98;
  362.   sy:=Form1.Bevel1.Top div 58;
  363.   if sx<sy then scale:=sx else scale:=sy;
  364.   kb:=scale div 3;
  365.  
  366.   x0:=(Form1.Width-scale*98) div 2;
  367.   y0:=(Form1.Bevel1.Top-scale*58) div 2;
  368.  
  369.   Form1.Bevel2.Top:=y0+37*scale;
  370.  
  371.   hidbmp.Canvas.Brush.Color:=clBtnFace;
  372.   hidbmp.Canvas.FillRect(0,0,Form1.Width,Form1.Height);
  373.  
  374.   hidbmp.Canvas.Pen.Color:=clBlack;
  375.   hidbmp.Canvas.Brush.Color:=$d0d0d0;
  376.   hidbmp.Canvas.Font.Size:=(scale*7) div 8;
  377.  
  378.   for i:=124 downto 0 do
  379.   begin
  380.     if pckey_selected=pckeys[i].cd then
  381.       hidbmp.Canvas.Brush.Color:=$80d0ff
  382.     else
  383.       hidbmp.Canvas.Brush.Color:=$d0d0d0;
  384.     if pckeys[i].cd=$ff then
  385.       hidbmp.Canvas.Font.Color:=$808080
  386.     else
  387.       hidbmp.Canvas.Font.Color:=$000000;
  388.     kx1:=x0+pckeys[i].x1*scale;
  389.     ky1:=y0+pckeys[i].y1*scale;
  390.     kx2:=x0+1+pckeys[i].x2*scale;
  391.     ky2:=y0+1+pckeys[i].y2*scale;
  392.     hidbmp.Canvas.Rectangle(kx1,ky1,kx2,ky2);
  393.     inc(kx1,kb);
  394.     inc(ky1,kb);
  395.     dec(kx2,kb);
  396.     dec(ky2,kb);
  397.     if (pckeys[i].n1<>'') then
  398.     begin
  399.       hidbmp.Canvas.TextRect(rect(kx1,ky1,kx2,ky2),
  400.                              kx1,ky1,pckeys[i].n1);
  401.     end;
  402.     if (pckeys[i].n2<>'') then
  403.     begin
  404.       ky1:=((ky1+ky2) div 2)+kb;
  405.       hidbmp.Canvas.TextRect(rect(kx1,ky1,kx2,ky2),
  406.                              kx1,ky1,pckeys[i].n2);
  407.     end;
  408.   end;
  409.  
  410.   hidbmp.Canvas.Font.Color:=$000000;
  411.   zk1:=kbmap[pckey_selected*2];
  412.   zk2:=kbmap[pckey_selected*2+1];
  413.   for i:=41 downto 0 do
  414.   begin
  415.     if zk1=zxkeys[i].cd then
  416.       hidbmp.Canvas.Brush.Color:=$80d0ff
  417.     else if (zk2<>$7f) and (zk2=zxkeys[i].cd) then
  418.       hidbmp.Canvas.Brush.Color:=$80f0ff
  419.     else
  420.       hidbmp.Canvas.Brush.Color:=$d0d0d0;
  421.     kx1:=x0+zxkeys[i].x1*scale;
  422.     ky1:=y0+zxkeys[i].y1*scale;
  423.     kx2:=x0+1+zxkeys[i].x2*scale;
  424.     ky2:=y0+1+zxkeys[i].y2*scale;
  425.     hidbmp.Canvas.Rectangle(kx1,ky1,kx2,ky2);
  426.     inc(kx1,kb);
  427.     inc(ky1,kb);
  428.     dec(kx2,kb);
  429.     dec(ky2,kb);
  430.     if (zxkeys[i].n1<>'') then
  431.     begin
  432.       hidbmp.Canvas.TextRect(rect(kx1,ky1,kx2,ky2),
  433.                              kx1,ky1,zxkeys[i].n1);
  434.     end;
  435.     if (zxkeys[i].n2<>'') then
  436.     begin
  437.       ky1:=((ky1+ky2) div 2)+kb;
  438.       hidbmp.Canvas.TextRect(rect(kx1,ky1,kx2,ky2),
  439.                              kx1,ky1,zxkeys[i].n2);
  440.     end;
  441.   end;
  442.  
  443. end;
  444.  
  445.  
  446. procedure TForm1.FormCreate(Sender: TObject);
  447. begin
  448.   Form1.DoubleBuffered:=true;
  449.   pckey_selected:=$29;
  450.   was_mousedown:=false;
  451.   Move(defkbmap,kbmap,512);
  452.   hidbmp:=TBitmap.Create;
  453.   hidbmp.Width:=1920;
  454.   hidbmp.Height:=1080;
  455.   hidbmp.Canvas.Brush.Style:=bsSolid;
  456.   //hidbmp.Canvas.Font.Name:='Arial';
  457.   recalc_and_rebuild;
  458. end;
  459.  
  460. procedure TForm1.FormResize(Sender: TObject);
  461. begin
  462.   recalc_and_rebuild;
  463. end;
  464.  
  465. procedure TForm1.FormPaint(Sender: TObject);
  466. begin
  467.   Form1.Canvas.Draw(0,0,hidbmp);
  468. end;
  469.  
  470. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  471.   Shift: TShiftState; X, Y: Integer);
  472. begin
  473.   was_mousedown:=true;
  474. end;
  475.  
  476. procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  477.   Shift: TShiftState; X, Y: Integer);
  478. var
  479.   i, kx, ky  :integer;
  480. begin
  481.   if was_mousedown then
  482.   begin
  483.     kx:=(X-x0) div scale;
  484.     ky:=(Y-y0) div scale;
  485.     if Button=mbLeft then
  486.     begin
  487.       for i:=0 to 125 do
  488.       begin
  489.         if (kx>=pckeys[i].x1) and (ky>=pckeys[i].y1) and
  490.            (kx< pckeys[i].x2) and (ky< pckeys[i].y2) then
  491.         begin
  492.           if pckeys[i].cd<>$ff then
  493.           begin
  494.             if pckey_selected<>pckeys[i].cd then
  495.             begin
  496.               pckey_selected:=pckeys[i].cd;
  497.               recalc_and_rebuild;
  498.               Form1.Repaint;
  499.             end;
  500.             break;
  501.           end;
  502.         end;
  503.       end;
  504.     end;
  505.     if (Button=mbLeft) or (Button=mbRight) then
  506.     begin
  507.       for i:=0 to 41 do
  508.       begin
  509.         if (kx>=zxkeys[i].x1) and (ky>=zxkeys[i].y1) and
  510.            (kx< zxkeys[i].x2) and (ky< zxkeys[i].y2) then
  511.         begin
  512.           if Button=mbRight then
  513.           begin
  514.             if (kbmap[pckey_selected*2]<>$7f) and
  515.                (kbmap[pckey_selected*2]<>zxkeys[i].cd) and
  516.                (kbmap[pckey_selected*2+1]<>zxkeys[i].cd) then
  517.             begin
  518.               kbmap[pckey_selected*2+1]:=zxkeys[i].cd;
  519.               recalc_and_rebuild;
  520.               Form1.Repaint;
  521.             end;
  522.           end
  523.           else if kbmap[pckey_selected*2]<>zxkeys[i].cd then
  524.           begin
  525.             kbmap[pckey_selected*2]:=zxkeys[i].cd;
  526.             kbmap[pckey_selected*2+1]:=$7f;
  527.             recalc_and_rebuild;
  528.             Form1.Repaint;
  529.           end;
  530.         end;
  531.       end;
  532.     end;
  533.   end;
  534.   was_mousedown:=false;
  535. end;
  536.  
  537. procedure TForm1.ButtonExitClick(Sender: TObject);
  538. begin
  539.   Form1.Close;
  540. end;
  541.  
  542. procedure TForm1.ButtonDefClick(Sender: TObject);
  543. begin
  544.   if MessageDlg('Reset keyboard map to default?',
  545.                 mtConfirmation,[mbYes,mbNo],0)=mrYes then
  546.   begin
  547.     Move(defkbmap,kbmap,512);
  548.     recalc_and_rebuild;
  549.     Form1.Repaint;
  550.   end;
  551. end;
  552.  
  553. procedure TForm1.ButtonSaveClick(Sender: TObject);
  554. var
  555.   f1  :file;
  556. begin
  557.   SaveDialog1.FileName:='';
  558.   if SaveDialog1.Execute then
  559.   begin
  560.     assignfile(f1,SaveDialog1.FileName);
  561.     rewrite(f1,512);
  562.     BlockWrite(f1,kbmap,1);
  563.     CloseFile(f1);
  564.   end;
  565. end;
  566.  
  567. procedure TForm1.ButtonOpenClick(Sender: TObject);
  568. var
  569.   i64  :int64;
  570.   f1  :file;
  571. begin
  572.   OpenDialog1.FileName:='';
  573.   if OpenDialog1.Execute then
  574.   begin
  575.     if FileSize(OpenDialog1.FileName)=512 then
  576.     begin
  577.       AssignFile(f1,OpenDialog1.FileName);
  578.       Reset(f1,512);
  579.       BlockRead(f1,kbmap,1,i64);
  580.       CloseFile(f1);
  581.       recalc_and_rebuild;
  582.       Form1.Repaint;
  583.     end
  584.     else
  585.       MessageDlg('The file must be exactly 512 bytes long.',mtError,[mbOk],0);
  586.   end;
  587. end;
  588.  
  589. procedure TForm1.ButtonFWPathClick(Sender: TObject);
  590. const
  591.   singature:array [0..5] of byte=($5a,$58,$45,$56,$4f,$1a);
  592. var
  593.   buff  :array [0..127103] of byte;
  594.   eeprom  :array [0..4095] of byte;
  595.   fsz, i64  :int64;
  596.   i, j, n, adr1, adr2  :integer;
  597.   w  :word;
  598.   b  :byte;
  599.   f1  :file;
  600. begin
  601.   OpenDialog1.FileName:='zxevo_fw.bin';
  602.   if OpenDialog1.Execute then
  603.   begin
  604.     fsz:=FileSize(OpenDialog1.FileName);
  605.     if fsz<768 then
  606.       MessageDlg('Hmm... This a very short file.',mtError,[mbOk],0)
  607.     else if fsz>127104 then
  608.       MessageDlg('Hmm... This a very long file.',mtError,[mbOk],0)
  609.     else
  610.     begin
  611.       AssignFile(f1,OpenDialog1.FileName);
  612.       Reset(f1,1);
  613.       BlockRead(f1,buff,fsz,i64);
  614.       CloseFile(f1);
  615.       if CompareByte(buff,singature,6)<>0 then
  616.         MessageDlg('The file is not ZX-Evo firmware.',mtError,[mbOk],0)
  617.       else if CRC16_XModem(buff,128)<>$0000 then
  618.         MessageDlg('The file is damaged!',mtError,[mbOk],0)
  619.       else
  620.       begin
  621.         FillDWord(eeprom,1024,$ffffffff);
  622.         //
  623.         adr1:=$0080;
  624.         for i:=$40 to $7b do
  625.         begin
  626.           b:=buff[i];
  627.           for j:=1 to 8 do
  628.           begin
  629.             if (b and 1)<>0 then inc(adr1,$0100);
  630.             b:=b shr 1;
  631.           end;
  632.         end;
  633.         //
  634.         i:=0;
  635.         adr2:=adr1;
  636.         w:=buff[$7c] or (buff[$7d] shl 8);
  637.         for j:=1 to 16 do
  638.         begin
  639.           if (w and 1)<>0 then
  640.             for n:=1 to $0100 do
  641.             begin
  642.               eeprom[i]:=buff[adr2];
  643.               inc(i);
  644.               inc(adr2);
  645.             end
  646.           else
  647.             inc(i,$0100);
  648.           w:=w shr 1;
  649.         end;
  650.         Move(kbmap,eeprom,512);
  651.         eeprom[0]:=$4b;
  652.         eeprom[1]:=$42;
  653.         //
  654.         w:=0;
  655.         i:=0;
  656.         adr2:=adr1;
  657.         for j:=1 to 16 do
  658.         begin
  659.           w:=w shr 1;
  660.           b:=$ff;
  661.           for n:=0 to $00ff do  b:=b and eeprom[i+n];
  662.           if b<>$ff then
  663.           begin
  664.             for n:=0 to $00ff do
  665.             begin
  666.               buff[adr2]:=eeprom[i];
  667.               inc(i);
  668.               inc(adr2);
  669.             end;
  670.             w:=w or $8000;
  671.           end
  672.           else
  673.             inc(i,$0100);
  674.         end;
  675.         buff[$7c]:=byte(w and $ff);
  676.         buff[$7d]:=byte((w shr 8) and $ff);
  677.         w:=CRC16_XModem(buff,126);
  678.         buff[$7e]:=byte((w shr 8) and $ff);
  679.         buff[$7f]:=byte(w and $ff);
  680.         //
  681.         RenameFile(OpenDialog1.FileName,OpenDialog1.FileName+'.bak');
  682.         //AssignFile(f1,OpenDialog1.FileName);
  683.         ReWrite(f1,1);
  684.         BlockWrite(f1,buff,adr2);
  685.         CloseFile(f1);
  686.         MessageDlg('ZX-Evo firmware'#13#10+fw_version_str(@buff[adr1-16])+
  687.                    #13#10'patched successfully.',
  688.                    mtInformation,[mbOk],0)
  689.       end;
  690.     end;
  691.   end;
  692. end;
  693.  
  694. procedure TForm1.ButtonHelpClick(Sender: TObject);
  695. begin
  696.   MessageDlg('Meanwhile no help, no setting.',mtInformation,[mbOk],0)
  697. end;
  698.  
  699. end.
  700.  
  701.