From: Frank K. <fbk...@co...> - 2003-11-11 06:28:13
|
Jonathan Mitelman wrote: > i need sone help in amorse ocees translator, > fron english to morse code in sound and signals > thanks Haven't you got your homework done *yet*? :) You don't tell us what part it is you need help with. Sounds? I suppose "signals" means a string of dots and dashes? Do you know how to do that part? It would be cool to emulate one of those signal lamps they use on ships - with the venetian blinds? - I suppose they don't use 'em any more... they got radio and stuff... maybe for "extra credit"... Or are you having trouble with the "translating" from ascii to Morse? You don't even tell us what OS. I suppose, obsolete as Morse Code is, probably CP/M would be appropriate :) In another post (Nasm forum?), you (someone... was it you?) mentioned "to run on 8086". I take that to mean dos... That's a horrible restraint! I took that to mean "no AT bios calls", so I used the 18.2/second timer tick for timing. Sounds like crap! Finer resolution would be nice (and it might help if I knew what the timing was *supposed* to be for Morse - I probably knew, once). Could arrange better resolution on an XT - calibrate a timing loop, or something. I didn't bother... I mentioned on the Nasm forum that I'd probably use the ascii code as a "biased" index into an array of addresses of "dot and dash strings". Thinking about the principle that the data ought to be arranged in a way that makes the code easy to write, I decided to not use a "bias" but use a table of all 256 possible ascii codes (actually, only the first 128 are ascii, but Morse includes some accented "international" characters - which I did not implement - I don't even know how to get international characters on my keyboard!). Most of the slots point to a dummy "invalid" string - which prints a '?', and "beeps some silence". Quite a bloated setup, but it seems to work... I just used int 29h for screen output - would be more useful if it output to stdout, I suppose. Then you could re-direct the output to a file, and write another program to read it and translate it back. "Holy Catfish, Captain Midnight! A secret decoder ring!" :) I think I mentioned on the Nasm forum that I've seen a program that outputs a series of "stick figure" cartoons representing a Midshipman waving semaphore flags around. I've got source for it, but it was an entry in an obfuscated C contest, so it isn't much help. Of course I've asked gcc for a ".s" file, and run that through "intel2gas". Not even close to figuring it out yet! I think I'd be better off to start from scratch and "clone" it... if I needed such a thing, that is... :) I should mention that this (Yahoo) mailing list was intended for Nasm developers - not for homework questions. It's pretty much dead now - development has moved to SourceForge, so it doesn't matter, but the "nasm-users" list at SourceForge is a better place to ask "how do I ..." questions about Nasm. I've cc'ed this there - they need the traffic :) Best, Frank P.S. Shall I include that C code too? Why not? I think it's cute. Forget where I found it - saved as "anderson.c" so I assume the author's name is Anderson... ; gets input from stdin, outputs "Morse code"... ; use as "morse<morse.txt" or just "morse" ; ("morse.txt" should end in ESC or EOF ; - or use cntrl-break to quit) ; nasm -f bin -o morse.com morse.asm org 100h cpu 8086 DIT_TIME equ 2 DAH_TIME equ 4 INT_TIME equ 4 SPACE_TIME equ 6 TONE_FREQ equ 2280 section .data morse_table: ; 0 -31 ; first 32 are control characters dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv ; 32 - 47 ; space ! " # $ % & ' dw mc_inv, mc_dot, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_apos ; ( ) * + , - . / dw mc_paren, mc_paren, mc_inv, mc_inv, mc_comma, mc_dash,mc_dot,mc_inv ; 48 - 57 ; numbers dw mc_0, mc_1, mc_2, mc_3, mc_4, mc_5, mc_6, mc_7, mc_8, mc_9 ; 58 - 64 ; : ; < = > ? @ dw mc_colon, mc_semi, mc_inv, mc_inv, mc_inv, mc_querry, mc_inv ; 65 - 90 ; upper case dw mc_A, mc_B, mc_C, mc_D, mc_E, mc_F, mc_G, mc_H, mc_I dw mc_J, mc_K, mc_L, mc_M, mc_N, mc_O, mc_P, mc_Q, mc_R dw mc_S, mc_T, mc_U, mc_V, mc_W, mc_X, mc_Y, mc_Z ; 91 - 96 ; [ \ ] ^ _ ` dw mc_paren, mc_inv, mc_paren, mc_inv, mc_uline, mc_apos ; 97 - 122 ; lower case dw mc_A, mc_B, mc_C, mc_D, mc_E, mc_F, mc_G, mc_H, mc_I dw mc_J, mc_K, mc_L, mc_M, mc_N, mc_O, mc_P, mc_Q, mc_R dw mc_S, mc_T, mc_U, mc_V, mc_W, mc_X, mc_Y, mc_Z ; 123 - 127 ; { | } ~ dw mc_paren, mc_inv, mc_paren, mc_inv ; 128 - 255 dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv dw mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv, mc_inv ; the "strings" mc_A db '.-', 0 mc_B db '-...', 0 mc_C db '-.-.', 0 mc_D db '-..', 0 mc_E db '.', 0 mc_F db '..-.', 0 mc_G db '--.', 0 mc_H db '....', 0 mc_I db '..', 0 mc_J db '.---', 0 mc_K db '-.-', 0 mc_L db '.-..', 0 mc_M db '--', 0 mc_N db '-.', 0 mc_O db '---', 0 mc_P db '.--.', 0 mc_Q db '--.-', 0 mc_R db '.-.', 0 mc_S db '...', 0 mc_T db '-', 0 mc_U db '..-', 0 mc_V db '...-', 0 mc_W db '.--', 0 mc_X db '-..-', 0 mc_Y db '-.--', 0 mc_Z db '--..', 0 mc_1 db '.----', 0 mc_2 db '..---', 0 mc_3 db '...--', 0 mc_4 db '....-', 0 mc_5 db '.....', 0 mc_6 db '-....', 0 mc_7 db '--...', 0 mc_8 db '---..', 0 mc_9 db '----.', 0 mc_0 db '-----', 0 mc_comma db '--..--', 0 ; comma mc_dot db '.-.-.-', 0 ; period mc_querry db '..--..', 0 ; question mark mc_semi db '-.-.-', 0 ; semicolon mc_colon db '---...', 0 ; colon mc_slash db '-..-.', 0 ; slash mc_dash db '-....-', 0 ; dash mc_apos db '.----.', 0 ; apostrophe mc_paren db '-.--.-', 0 ; parenthesis mc_uline db '..--.-', 0 ; underline mc_inv db '?', 0 ; "When in danger or in doubt, ; run in circles, scream and shout" ; internationalization is left as an excercise for the student :) %if 0 mc_Á db '.--.-', 0 ; A with accent mc_Ä db '.-.- ', 0 ; A with two dots mc_É db '..-..', 0 ; E with accent mc_Ñ db '--.--', 0 ; N with tilde mc_Ö db '---.', 0 ; O with two dots mc_Ü db '..--', 0 ; U with two dots %endif section .text ; set up PIT mov al, 10111110b ;.......|------ binary 16-bit counter ;....|||------- square wave generator ;..||---------- r/w bits 0-7, then 8-15 ;||------------ select timer 2 out 43h, al ; set frequncy on timer 2 mov ax, TONE_FREQ ; arbitrary frequency "C" out 42h, al ; low byte mov al, ah out 42h ,al ; high byte next_char: mov ah, 8 ; get stdin int 21h cmp al, 1Bh ; user hit ESC? jz egress cmp al, 1Ah ; eof? jz egress cmp al, 13 jz treat_as_space cmp al, 10 jz treat_as_space ; check for tab, too? cmp al, ' ' jnz not_space treat_as_space: mov al, ' ' ; print a space int 29h mov ax, SPACE_TIME call delay jmp short next_char not_space: xor ah, ah ; clear upper part add ax, ax ; double the index - it's a word array mov si, ax mov si, [morse_table + si] ; now si points to our string getbeep: lodsb ; get char from "morse string" or al, al ; end of string? jnz more_string mov al, ' ' ; print a space int 29h jmp short next_char ; get more input more_string: mov bx, DIT_TIME cmp al, '.' je beepit mov bx, DAH_TIME cmp al, '-' jz beepit cmp al, '?' jnz baddata ; what *is* it then??? int 29h ; an "invalid" character mov ax, SPACE_TIME ; print the "?" and call delay ; output some silence jmp next_char ; if we're here, typo in data! baddata: mov al, 'E' ; panic! int 29h jmp egress beepit: int 29h ; print '.' or '-' in al, 61h ; enable speaker or al, 00000011b ;.......|------- enable speaker on timer 2 gate ;......|-------- enable speaker data out 61h, al mov ax, bx ; leave it on this long call delay in al, 61h ; Turn Speaker OFF and al, 11111100b out 61h, al mov ax, INT_TIME ; pause before next '.' or '-' call delay jmp getbeep ; get next '.' or '-' egress: in al, 61h and al, 0FCh ; Turn Speaker OFF. Please. out 61h, al ret ;------------------ ;------------------ delay: ; for ax 18.2ths of a second push bx push ds xor bx, bx mov ds, bx mov bx, [46Ch] ; bios timer tick add bx, ax linger: cmp [46Ch], bx jnz linger pop ds pop bx ret ;-------------------- And here's the C code for that semaphore thing... And they say asm is hard to read! :) #include <stdio.h> char *T="IeJKLMaYQCE]jbZRskc[SldU^V\\X\\|/_<[<:90!\"$434-./2>]s", K[3][1000],*F,x,A,*M[2],*J,r[4],*g,N,Y,*Q,W,*k,q,D;X(){r [r [r[3]=M[1-(x&1)][*r=W,1],2]=*Q+2,1]=x+1+Y,*g++=((((x& 7) -1)>>1)-1)?*r:r[x>>3],(++x<*r)&&X();}E(){A||X(x=0,g =J ),x=7&(*T>>A*3),J[(x[F]-W-x)^A*7]=Q[x&3]^A*(*M)[2 +( x&1)],g=J+((x[k]-W)^A*7)-A,g[1]=(*M)[*g=M[T+=A ,1 ][x&1],x&1],(A^=1)&&(E(),J+=W);}l(){E(--q&&l () );}B(){*J&&B((D=*J,Q[2]<D&&D<k[1]&&(*g++=1 ), !(D-W&&D-9&&D-10&&D-13)&&(!*r&&(*g++=0) ,* r=1)||64<D&&D<91&&(*r=0,*g++=D-63)||D >= 97&&D<123&&(*r=0,*g++=D-95)||!(D-k[ 3] )&&(*r=0,*g++=12)||D>k[3]&&D<=k[ 1] -1&&(*r=0,*g++=D-47),J++));}j( ){ putchar(A);}b(){(j(A=(*K)[D* W+ r[2]*Y+x]),++x<Y)&&b();}t () {(j((b(D=q[g],x=0),A=W) ), ++q<(*(r+1)<Y?*(r+1): Y) )&&t();}R(){(A=(t( q= 0),'\n'),j(),++r [2 ]<N)&&R();}O() {( j((r[2]=0,R( )) ),r[1]-=q) && O(g-=-q) ;} C(){( J= gets (K [1]))&&C((B(g=K[2]),*r=!(!*r&&(*g++=0)),(*r)[r]=g-K[2],g=K[2 ],r[ 1]&& O()) );;} main (){C ((l( (J=( A=0) [K], A[M] =(F= (k=( M[!A ]=(Q =T+( q=(Y =(W= 32)- (N=4 )))) +N)+ 2)+7 )+7) ),Y= N<<( *r=! -A)) );;} |