home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 December / Chip_2002-12_cd1.bin / tema / clin / CLIN.EXE / SRC / SRC.RAR / KOD8.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-09-24  |  5.4 KB  |  166 lines

  1. // Code 93
  2. Unit Kod8;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8.   Dialogs, StdCtrls, ExtCtrls,
  9.   U;
  10.  
  11.  procedure HC8(var Co:TMemo);
  12.  procedure S2L8(Co:String; StartStop:Boolean; Crc:Boolean    ; var Raw:String; var RawS:String; var Bits:String);
  13.  
  14.  
  15. implementation
  16.  
  17.  const MaxKod=47;
  18.  var Kody:Array[0..48]of record
  19.        Asc:String;
  20.        Kod:Byte;
  21.        Line:String;
  22.      end;
  23.  
  24.  procedure HC8(var Co:TMemo);
  25.  var I:Word;
  26.  begin
  27.   Co.Clear;
  28.   for I:=0 to MaxKod do
  29.    with Kody[I] do
  30.      begin
  31.        Co.Lines.Add(Hex(Kod)+' '+Asc+' ('+Line+')');
  32.      end;
  33.  end;
  34.  
  35.  procedure S2L8(Co:String; StartStop:Boolean; Crc:Boolean    ; var Raw:String; var RawS:String; var Bits:String);
  36.  var I,J,K:Integer;
  37.      Pom,Pom2:String;
  38.      PomC:Byte;
  39.      E:Integer;
  40.      Ch:Byte;
  41.  begin
  42.    Raw:='';
  43.    RawS:='';
  44.    Bits:='';
  45.    if Length(Co)=0 then Exit;
  46.  //// Vy°a∩ neplatnΘ a zkonvertuj HEX verze
  47.    I:=1;
  48.    while I<=Length(Co) do
  49.    begin
  50.      Co[I]:=UpCase(Co[I]);
  51.      //// Je to $ ?
  52.      if Co[I]='$' then // Je to HEX
  53.         begin
  54.           Pom:='';
  55.           repeat
  56.             Pom:=Pom+Co[I];
  57.             I:=I+1; // Posu≥ o dalÜφ znak
  58.           until (length(Pom)=3) or (I>Length(Co));
  59.           if I<=Length(Co) then I:=I-1;
  60.           Val(Pom,PomC,E);
  61.           if (E=0)and(PomC<=MaxKod) then
  62.           begin
  63.             Raw:=Raw+Chr(PomC);
  64.           end;
  65.         end else
  66.         begin   // Nenφ to HEX
  67.           for J:=0 to MaxKod do
  68.             if Co[I]=Kody[J].Asc then Raw:=Raw+Chr(Kody[J].Kod);
  69.         end;
  70.      I:=I+1;
  71.    end;
  72.  //// Crc a Start/Stop
  73.    if Crc then
  74.    begin
  75.      J:=0;
  76.      for I:=1 to Length(Raw) do
  77.      begin
  78.        J:=J+(Length(Raw)-I+1)*Ord(Raw[I]);
  79.      end;
  80.      Raw:=Raw+Chr(J mod 47);
  81.  
  82.      J:=0;
  83.      for I:=1 to Length(Raw) do
  84.      begin
  85.        J:=J+(Length(Raw)-I+1)*Ord(Raw[I]);
  86.      end;
  87.      Raw:=Raw+Chr(J mod 47);     
  88.    end;
  89.  
  90.    if StartStop then Raw:=#47+Raw+#48;
  91.  //// Na zobrazitelne
  92.       //// +Na bity
  93.  for I:=1 to Length(Raw) do
  94.   begin
  95.     RawS:=RawS+Kody[Ord(Raw[I])].Asc;
  96.     Pom2:=Kody[Ord(Raw[I])].Line;
  97.       Pom:='';
  98.       Ch:=$31; // ZaΦφnßme jedniΦkou
  99.       for J:=1 to Length(Pom2) do
  100.       begin
  101.         for K:=1 to (Ord(Pom2[J])-$30) do // Pozor na 0-x a 1-x v tabulce bit∙ !!!
  102.           begin
  103.             Pom:=Pom+Chr(Ch);
  104.           end;
  105.         Ch:=Ch xor 1;
  106.       end;
  107.      Bits:=Bits+Pom;
  108.   end;
  109.  end;
  110.  
  111. begin
  112.  with Kody[00]do begin Asc:='0';Kod:=0;Line:='131112';end;
  113.  with Kody[01]do begin Asc:='1';Kod:=1;Line:='111213';end;
  114.  with Kody[02]do begin Asc:='2';Kod:=2;Line:='111312';end;
  115.  with Kody[03]do begin Asc:='3';Kod:=3;Line:='111411';end;
  116.  with Kody[04]do begin Asc:='4';Kod:=4;Line:='121113';end;
  117.  with Kody[05]do begin Asc:='5';Kod:=5;Line:='121212';end;
  118.  with Kody[06]do begin Asc:='6';Kod:=6;Line:='121311';end;
  119.  with Kody[07]do begin Asc:='7';Kod:=7;Line:='111114';end;
  120.  with Kody[08]do begin Asc:='8';Kod:=8;Line:='131211';end;
  121.  with Kody[09]do begin Asc:='9';Kod:=9;Line:='141111';end;
  122.  
  123.  with Kody[10]do begin Asc:='A';Kod:=10;Line:='211113';end;
  124.  with Kody[11]do begin Asc:='B';Kod:=11;Line:='211212';end;
  125.  with Kody[12]do begin Asc:='C';Kod:=12;Line:='211311';end;
  126.  with Kody[13]do begin Asc:='D';Kod:=13;Line:='221112';end;
  127.  with Kody[14]do begin Asc:='E';Kod:=14;Line:='221211';end;
  128.  with Kody[15]do begin Asc:='F';Kod:=15;Line:='231111';end;
  129.  with Kody[16]do begin Asc:='G';Kod:=16;Line:='112113';end;
  130.  with Kody[17]do begin Asc:='H';Kod:=17;Line:='112212';end;
  131.  with Kody[18]do begin Asc:='I';Kod:=18;Line:='112311';end;
  132.  with Kody[19]do begin Asc:='J';Kod:=19;Line:='122112';end;
  133.  
  134.  with Kody[20]do begin Asc:='K';Kod:=20;Line:='132111';end;
  135.  with Kody[21]do begin Asc:='L';Kod:=21;Line:='111123';end;
  136.  with Kody[22]do begin Asc:='M';Kod:=22;Line:='111222';end;
  137.  with Kody[23]do begin Asc:='N';Kod:=23;Line:='111321';end;
  138.  with Kody[24]do begin Asc:='O';Kod:=24;Line:='121122';end;
  139.  with Kody[25]do begin Asc:='P';Kod:=25;Line:='131121';end;
  140.  with Kody[26]do begin Asc:='Q';Kod:=26;Line:='212112';end;
  141.  with Kody[27]do begin Asc:='R';Kod:=27;Line:='212211';end;
  142.  with Kody[28]do begin Asc:='S';Kod:=28;Line:='211122';end;
  143.  with Kody[29]do begin Asc:='T';Kod:=29;Line:='211221';end;
  144.  
  145.  with Kody[30]do begin Asc:='U';Kod:=30;Line:='221121';end;
  146.  with Kody[31]do begin Asc:='V';Kod:=31;Line:='222111';end;
  147.  with Kody[32]do begin Asc:='W';Kod:=32;Line:='112122';end;
  148.  with Kody[33]do begin Asc:='X';Kod:=33;Line:='112221';end;
  149.  with Kody[34]do begin Asc:='Y';Kod:=34;Line:='122121';end;
  150.  with Kody[35]do begin Asc:='Z';Kod:=35;Line:='123111';end;
  151.  with Kody[36]do begin Asc:='-';Kod:=36;Line:='121131';end;
  152.  with Kody[37]do begin Asc:='.';Kod:=37;Line:='311112';end;
  153.  with Kody[38]do begin Asc:=' ';Kod:=38;Line:='311211';end;
  154.  with Kody[39]do begin Asc:='$';Kod:=39;Line:='321111';end;
  155.  
  156.  with Kody[40]do begin Asc:='/';Kod:=40;Line:='112131';end;
  157.  with Kody[41]do begin Asc:='+';Kod:=41;Line:='113121';end;
  158.  with Kody[42]do begin Asc:='%';Kod:=42;Line:='211131';end;
  159.  with Kody[43]do begin Asc:='{_$}';Kod:=43;Line:='121221';end;
  160.  with Kody[44]do begin Asc:='{_%}';Kod:=44;Line:='312111';end;
  161.  with Kody[45]do begin Asc:='{_/}';Kod:=45;Line:='311121';end;
  162.  with Kody[46]do begin Asc:='{_+}';Kod:=46;Line:='122211';end;
  163.  with Kody[47]do begin Asc:='{Start}';Kod:=47;Line:='111141';end;
  164.  with Kody[48]do begin Asc:='{Stop}';Kod:=48;Line:='1111411';end;
  165. end.
  166.