Salutare !
Tocmai am recuperat ce am scris acum mai bine de 10 ani, de pe un HDD cu interfata ISA pe 8 biti, dar sa lasam detaliile tehnice:
sursa:
MORSE.PAS
uses crt;
const debug:boolean=true;
var
semnal:word;
punct:word;
linie:word;
pauza:word;
pauza_litera:word;
pauza_cuvint:word;
cod:array[1..50] of record c:char; s:string[6]; end;
n_cod:byte;
vit:word;
procedure gen_punct;
begin
sound(semnal);
delay(punct);
nosound;
delay(pauza);
end;
procedure gen_linie;
begin
sound(semnal);
delay(linie);
nosound;
delay(pauza);
end;
procedure gen_char(c:char);
var i,j:byte;
begin
for i:=1 to 50 do begin
if c=cod[i].c then begin
j:=1;
repeat
case cod[i].s[j] of
'.':gen_punct;
'-':gen_linie;
end;
inc(j);
until j>byte(cod[i].s[0]);
delay(pauza_litera);
exit;
end;
end;
writeln;
writeln('Eroare: nu stiu sa generez "',c,'".');{}
end;
procedure load_cfg;
const k:real=38.43;
var f:text;
i,j:byte; s:string;
p,l,pz,pl,pc,v:real;
s_p,s_l,s_z:word;
l_med:real; {lungime medie cod morse}
begin
assign(f,'morse.cfg');
reset(f);
read(f,semnal); readln(f);
read(f,p); punct:=round(k*p*18.2); readln(f);
read(f,l); l:=p*l; linie:=round(k*l*18.2); readln(f);
read(f,pz);pz:=p*pz; pauza:=round(k*pz*18.2); readln(f);
read(f,pl);pl:=p*pl; pauza_litera:=round(k*pl*18.2); readln(f);
read(f,pc);pc:=p*pc; pauza_cuvint:=round(k*pc*18.2); readln(f);
readln(f);
i:=1; l_med:=0;
repeat
read(f,cod[i].c); readln(f,s); delete(s,1,1); cod[i].s:=s;
inc(i); l_med:=l_med+byte(s[0]);
until (eof(f)) or (i>50);
n_cod:=i-1;
l_med:=l_med/n_cod; {calculat media}
for j:=i to 50 do cod[j].c:=#0;
close(f);
s_p:=0;s_l:=0;s_z:=0;
for i:=1 to 50 do begin
for j:=1 to byte(cod[i].s[0]) do begin
case cod[i].s[j] of
'.':inc(s_p);
'-':inc(s_l);
end;
end;
end;
s_z:=s_p+s_l;
v:=60/((p+l*(s_l/s_p)+2*pz)*l_med/3.4 + pl + pc/4);
vit:=round(v);
if debug then begin
writeln('Lungime medie cod: ',l_med:2:2);
writeln('Numar "." si "-" : ',s_p,' ',s_l);
writeln('Lungime punct: ',p:1:3,' secunde.');
writeln('Lungime linie: ',l:1:3,' secunde.');
end;
end;
procedure init;
begin
clrscr;
writeln('Generator de cod morse. 1.1 (c) 1997 by EmiSoft');
writeln;
load_cfg;
writeln('Viteza curenta: ',vit,' caractere pe minut.');
writeln;
end;
procedure run;
var f:text; c:char;
fn:string;
begin
fn:=paramstr(1);
if fn='' then begin
writeln('Error: Must use "MORSE file_to_play"');
halt;
end;
assign(f,fn);
reset(f);
repeat
read(f,c);
case c of
' ':begin write(' '); delay(pauza_cuvint);end;
#13,#10:begin writeln; read(f,c);delay(pauza_cuvint);end;
else begin write(c); gen_char(upcase(c)); end;
end;
if keypressed then if (readkey=#27) then begin
close(f);
exit;
end;
until eof(f);
close(f);
end;
procedure done;
var c:char;
begin
writeln(#13#10,'End.');
{c:=readkey;{}
end;
begin
init;
run;
done;
end.
MORSE.CFG
700 = Semnal (Hz)
0.07 = Punct (secunde)
3.0 * Punct = Linie
1.0 * Punct = Pauza (intre semnale)
3.0 * Punct = Pauza_litera
5.5 * Punct = Pauza_cuvint
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
S ...
T -
U ..-
V ...-
W .--
Y -.--
X -..-
Z --..
. ......
, .-.-.-
! --..--
? ..--..
= -...-
/ -..-.
1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
0 -----
Observatie: Pe PC-uri la zi, punctul nu poate fi 0.07 secunde, asta era valabil pe ce am programat eu.
Cine doreste tot programul, sa dea un PM.