langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,46 @@
let codes = [
'a', ".-"; 'b', "-..."; 'c', "-.-.";
'd', "-.."; 'e', "."; 'f', "..-.";
'g', "--."; 'h', "...."; 'i', "..";
'j', ".---"; 'k', "-.-"; 'l', ".-..";
'm', "--"; 'n', "-."; 'o', "---";
'p', ".--."; 'q', "--.-"; 'r', ".-.";
's', "..."; 't', "-"; 'u', "..-";
'v', "...-"; 'w', ".--"; 'x', "-..-";
'y', "-.--"; 'z', "--.."; '0', "-----";
'1', ".----"; '2', "..---"; '3', "...--";
'4', "....-"; '5', "....."; '6', "-....";
'7', "--..."; '8', "---.."; '9', "----.";
]
let oc = open_out "/dev/dsp"
let bip u =
for i = 0 to pred u do
let j = sin(0.6 *. (float i)) in
let k = ((j +. 1.0) /. 2.0) *. 127.0 in
output_byte oc (truncate k)
done
let gap u =
for i = 0 to pred u do
output_byte oc 0
done
let morse =
let u = 1000 in (* length of one unit *)
let u2 = u * 2 in
let u3 = u * 3 in
let u6 = u * 6 in
String.iter (function
| ' ' -> gap u6
| 'a'..'z' | 'A'..'Z' | '0'..'9' as c ->
let s = List.assoc c codes in
String.iter (function
'.' -> bip u; gap u
| '-' -> bip u3; gap u
| _ -> assert false
) s; gap u2
| _ -> prerr_endline "unknown char")
let () = morse "rosettacode morse"

View file

@ -0,0 +1,15 @@
sleep(ms)={
while((ms-=gettime()) > 0,);
};
dot()=print1(Strchr([7]));sleep(250);
dash()=print1(Strchr([7]));sleep(10);print1(Strchr([7]));sleep(10);print1(Strchr([7]));sleep(250);
Morse(s)={
s=Vec(s);
for(i=1,#s,
if(s[i] == ".", dot(),
if(s[i] == "-", dash(), sleep(250))
)
)
};
Morse("...---...")

View file

@ -0,0 +1,51 @@
/* Sound Morse code via the PC buzzer. June 2011 */
MORSE: procedure options (main);
declare (i, j) fixed binary;
declare buzz character (1) static initial ('07'x);
declare text character (100) varying,
c character (1);
declare alphabet character (36) static initial (
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
declare morse_character character(5) varying;
declare morse_codes(36) character(5) varying static initial (
/* Letters A-Z */
'.-', '-...', '-.-.', '-..', '.',
'..-.', '--.', '....', '..', '.---',
'-.-', '.-..', '--', '-.', '---',
'--.-', '--.-', '.-.', '...', '-',
'..-', '...-', '.--', '-..-', '-.--',
'--..',
/* Digits 0-9 */
'-----', '.----', '..---', '...--', '....-',
'.....', '-....', '--...', '---..', '----.' );
put skip list ('Please type the text to be transmitted:');
get edit (text) (L);
do i = 1 to length (text);
c = substr(text, i, 1);
j = index(alphabet, uppercase(c));
if j > 0 then
do;
morse_character = morse_codes(j);
put skip list (morse_character); /* Display the Morse. */
call send_morse (morse_character);
end;
end;
send_morse: procedure (morse_character);
declare morse_character character(*) varying;
declare i fixed binary;
do i = 1 to length(morse_character);
if substr(morse_character, 1, 1) = '-' then
put skip edit (buzz, ' ', buzz) (a(1), A, skip, a(1));
else
put skip edit (buzz, ' ') (a(1));
delay (1000); /* Delay one period. */
end;
delay (1000);
/* Making a delay of 2 periods after each English letter. */
end send_morse;
END MORSE;

View file

@ -0,0 +1,64 @@
my %m = ' ', '_ _ ',
<
! ---.
" .-..-.
$ ...-..-
' .----.
( -.--.
) -.--.-
+ .-.-.
, --..--
- -....-
. .-.-.-
/ -..-.
: ---...
; -.-.-.
= -...-
? ..--..
@ .--.-.
[ -.--.
] -.--.-
_ ..--.-
0 -----
1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.---
R .-.
S ...
T -
U ..-
V ...-
W .--
X -..-
Y -.--
Z --..
>.map: -> $c, $m is copy {
$m.=subst(rx/'-'/, 'BGAAACK!!! ', :g);
$m.=subst(rx/'.'/, 'buck ', :g);
$c => $m ~ '_ ';
}
say prompt("Gimme a string: ").uc.comb.map: { %m{$_} // "<scratch> " }

View file

@ -0,0 +1,129 @@
#BaseTime =50
#Frequence=1250
#Short = #BaseTime
#Long =3* #BaseTime
#Intergap = #BaseTime
#LetterGap=3* #BaseTime
#WordGap =7* #BaseTime
Declare.s TextToMorse(Text$)
Declare.i PlayMorse(Text$)
Text$ =InputRequester("Morse coder","Enter text to send","Hello RosettaWorld!")
Text$ =TextToMorse(Text$)
If Not (InitSound() And PlayMorse(Text$))
Text$=ReplaceString(Text$, ",","")
MessageRequester("Morse EnCoded",Text$)
EndIf
;-
Procedure PlayMorse(Code$) ;- Beep() is normally only Ok on Windows_x86
CompilerIf #PB_Compiler_Processor=#PB_Processor_x86 And #PB_Compiler_OS=#PB_OS_Windows
Protected i, sign
For i=1 To Len(Code$)
sign=Asc(Mid(Code$,i,1))
Select sign
Case '.': Beep_(#Frequence,#Short): Delay(#Intergap)
Case '-': Beep_(#Frequence,#Long) : Delay(#Intergap)
Case ',': Delay(#LetterGap)
Case ' ': Delay(#WordGap)
EndSelect
Next
ProcedureReturn 1
CompilerElse
ProcedureReturn 0
CompilerEndIf
EndProcedure
Procedure.s TextToMorse(InString$)
Protected *p.Character=@InString$, CurrStr$, i=1
Protected.s s1, s2, result
Repeat
If Not *p\c: Break: EndIf
CurrStr$=UCase(PeekS(*p,1))
*p+StringByteLength(">")
Restore MorseCode
Repeat
Read.s s1
If s1="Done"
s2+s1+" " ; failed to find this coding
Break
ElseIf Not s1=CurrStr$
Continue
EndIf
Read.s s2
result+s2
If s2<>" "
result+","
EndIf
ForEver
ForEver
ProcedureReturn result
EndProcedure
DataSection
MorseCode:
Data.s "A", ".-"
Data.s "B", "-..."
Data.s "C", "-.-."
Data.s "D", "-.."
Data.s "E", "."
Data.s "F", "..-."
Data.s "G", "--."
Data.s "H", "...."
Data.s "I", ".."
Data.s "J", ".---"
Data.s "K", "-.-"
Data.s "L", ".-.."
Data.s "M", "--"
Data.s "N", "-."
Data.s "O", "---"
Data.s "P", ".--."
Data.s "Q", "--.-"
Data.s "R", ".-."
Data.s "S", "..."
Data.s "T", "-"
Data.s "U", "..-"
Data.s "V", "...-"
Data.s "W", ".--"
Data.s "X", "-..-"
Data.s "Y", "-.--"
Data.s "Z", "--.."
Data.s "Á", "--.-"
Data.s "Ä", ".-.-"
Data.s "É", "..-.."
Data.s "Ñ", "--.--"
Data.s "Ö", "---."
Data.s "Ü", "..--"
Data.s "1", ".----"
Data.s "2", "..---"
Data.s "3", "...--"
Data.s "4", "....-"
Data.s "5", "....."
Data.s "6", "-...."
Data.s "7", "--..."
Data.s "8", "---.."
Data.s "9", "----."
Data.s "0", "-----"
Data.s ",", "--..--"
Data.s ".", ".-.-.-"
Data.s "?", "..--.."
Data.s ";", "-.-.-"
Data.s ":", "---..."
Data.s "/", "-..-."
Data.s "-", "-....-"
Data.s "'", ".----."
Data.s "+", ".-.-."
Data.s "-", "-....-"
Data.s #DOUBLEQUOTE$, ".-..-."
Data.s "@", ".--.-."
Data.s "(", "-.--."
Data.s ")", "-.--.-"
Data.s "_", "..--.-"
Data.s "$", "...-..-"
Data.s "&", ".-..."
Data.s "=", "---..."
Data.s " ", " "
Data.s "Done",""
EndOfMorseCode:
EndDataSection

View file

@ -0,0 +1,33 @@
$$ MODE TUSCRIPT
MODE DATA
$$ BUILD X_TABLE alfabet2moco =*
"!"---."\".-..-."$"...-..-"'".----."
"("-.--.")"-.--.-"+".-.-.","--..--"
"-"-....-".".-.-.-"/"-..-."
"0"-----"1".----"2"..---"3"...--"
"4"....-"5"....."6"-...."7"--..."
"8"---.."9"----."
":"---...";"-.-.-."="-...-"?"..--.."
"@".--.-."
"A".-"B"-..."C"-.-."D"-.."
"E"."F"..-."G"--."H"...."
"I".."J".---"K"-.-"L".-.."
"M"--"N"-."O"---"P".--."
"Q"--.-"R".-."S"..."T"-"
"U"..-"V"...-"W".--"X"-..-"
"Y"-.--"Z"--.."
"["-.--."]"-.--.-"_"..--.-"
$$ BUILD X_TABLE moco2sound =*
" "p2 "
"-"a4 "
"."a2 "
$$ BUILD X_TABLE space2split=": :':"
$$ MODE TUSCRIPT
ASK "Please enter your sentence": mc=""
PRINT "SEE your morsecode !"
mc=EXCHANGE (mc,alfabet2moco)
PRINT mc
PRINT "HEAR your morsecode !"
mc=EXCHANGE (mc,moco2sound)
mc=EXCHANGE (mc,space2split)
BEEP $mc

View file

@ -0,0 +1,42 @@
code ChOut=8, CrLf=9, Sound=39;
string 0; \use zero-terminated strings
proc Morse(Msg); \Output Msg string as audible International Morse code
char Msg;
char C, D;
int Code, Vol;
[Code:= [" ", \space
".-.-..",".-..-.", " ", "...-..-"," ", \!"#$%
"----.", ".----.", "-.--.-", "---..", " ", \&'()*
".-.-.", "--..--", "-....-", ".-.-.-", "-..-.", \+,-./
"-----", ".----", "..---", "...--", "....-", \01234
".....", "-....", "--...", "---..", "----.", \56789
"---...","-.-.-.", " ", "-...-", " ", \:;<=>
"..--..",".--.-.", \?@
".-", "-...", "-.-.", "-..", ".", \ABCDE
"..-.", "--.", "....", "..", ".---", \FGHIJ
"-.-", ".-..", "--", "-.", "---", \KLMNO
".--.", "--.-", ".-.", "...", "-", \PQRST
"..-", "...-", ".--", "-..-", "-.--", \UVWXY
"--.."]; \Z
Sound(0, 1, 1); \sync, for consistent durations
repeat C:= Msg(0); Msg:= Msg+1; \get character from message
ChOut(0, C); \show the character
if C>=^a & C<=^z then C:= C-$20; \convert letters to uppercase
Vol:= 1; \assume volume is on (not space)
if C>=$21 & C<=^Z then D:= Code(C-$20) \convert characters to code
else [D:= Code(0); Vol:= 0]; \space (or unsupported char)
repeat Sound(Vol, if D(0)=^- then 3 else 1, 1190000/600); \600 Hz
Sound(0, 1, 1); \gap between . and -
ChOut(0, D(0)); \show dots and dashes
D:= D+1; \next dot or dash for character
until D(0) = 0; \string terminator
Sound(0, 2, 1); \gap between letters (2+1=3)
ChOut(0, ^ ); \show gap
until Msg(0) = 0; \string terminator
];
[Morse("SOS SOS SOS "); \something easy to recognize
CrLf(0);
Morse("Hello, world!");
]