MORSE.C
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:4k
源码类别:

操作系统开发

开发平台:

DOS

  1. #include <stdio.h>
  2. #include <rtos.h>
  3. #include <mem.h>
  4. #include <dos.h>
  5. #include <ctype.h>
  6. #include "morse.h"
  7. morse_type codes[] = {
  8.     { 'A',      {1,0,1,1,1,0,0,0,0,9}},                  /* A */
  9.     { 'B',      {1,1,1,0,1,0,1,0,1,0,0,0,0,9}},
  10.     { 'C',      {1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,9}},
  11.     { 'D',      {1,1,1,0,1,0,1,0,0,0,0,9}},
  12.     { 'E',      {1,0,0,0,0,9}},
  13.     { 'F',      {1,0,1,0,1,1,1,0,1,0,0,0,0,9}},
  14.     { 'G',      {1,1,1,0,1,1,1,0,1,0,0,0,0,9}},
  15.     { 'H',      {1,0,1,0,1,0,1,0,0,0,0,9}},
  16.     { 'I',      {1,0,1,0,0,0,0,9}},
  17.     { 'J',      {1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},
  18.     { 'K',      {1,1,1,0,1,0,1,1,1,0,0,0,0,9}},
  19.     { 'L',      {1,0,1,1,1,0,1,0,1,0,0,0,0,9}},
  20.     { 'M',      {1,1,1,0,1,1,1,0,0,0,0,9}},
  21.     { 'N',      {1,1,1,0,1,0,0,0,0,9}},
  22.     { 'O',      {1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},
  23.     { 'P',      {1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,9}},
  24.     { 'Q',      {1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,9}},
  25.     { 'R',      {1,0,1,1,1,0,1,0,0,0,0,9}},
  26.     { 'S',      {1,0,1,0,1,0,0,0,0,9}},
  27.     { 'T',      {1,1,1,0,0,0,0,9}},
  28.     { 'U',      {1,0,1,0,1,1,1,0,0,0,0,9}},
  29.     { 'V',      {1,0,1,0,1,0,1,1,1,0,0,0,0,9}},
  30.     { 'W',      {1,0,1,1,1,0,1,1,1,0,0,0,0,9}},
  31.     { 'X',      {1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,9}},
  32.     { 'Y',      {1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},
  33.     { 'Z',      {1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,9}},      /* Z */
  34.     { '0',      {1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},      /* 0 */
  35.     { '1',      {1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},          /* 1 */
  36.     { '2',      {1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},              /* 2 */
  37.     { '3',      {1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},                  /* 3 */
  38.     { '4',      {1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,9}},                      /* 4 */
  39.     { '5',      {1,0,1,0,1,0,1,0,1,0,0,0,0,9}},                          /* 5 */
  40.     { '6',      {1,1,1,0,1,0,1,0,1,0,1,0,0,0,0,9}},                      /* 6 */
  41.     { '7',      {1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,9}},                  /* 7 */
  42.     { '8',      {1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,9}},              /* 8 */
  43.     { '9',      {1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,9}},          /* 9 */
  44.     { ' ',      {0,0,0,0,9}},                                        /* space */
  45.     { '.',      {1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,9}},        /* . */
  46.     { ',',      {1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,9}},    /* , */
  47.     { '?',      {1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,9}},            /* ? */
  48.     { ':',      {1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,9}},        /* : */
  49.     { ';',      {1,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,9}},        /* ; */
  50.     { '(',      {1,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,9}},    /* ( */
  51.     { '/',      {1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,9}},                /* / */
  52.     { '_',      {1,1,1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,9}},                /* - */
  53.     { ')',      {1,0,1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,9}},              /* ) AR */
  54.     { '!',      {1,0,1,1,1,0,1,0,1,0,1,0,0,0,0,9}},                  /* ! AS */
  55.     { '=',      {1,1,1,0,1,0,1,0,0,0,1,0,0,0,0,9}},                  /* = DE */
  56.     { '|',      {1,0,1,0,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,9}},          /* | SK */
  57.     { '%',      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9}},        /* % pause */
  58.     { '*',      {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9}},        /* * tone */
  59.       0, {0} };
  60. morse_type* ascii_to_morse( char ch )
  61. {
  62.     morse_type *p;
  63.     for ( p = codes ; p->m_ch != 0 ; p++ )
  64.         if ( p->m_ch == ch ) return( p );
  65.     return( NULL );
  66. }
  67. morse_type* codes_to_morse( BYTE *b, int len )
  68. {
  69.     morse_type *p;
  70.     for ( p = codes ; p->m_ch != 0 ; p++ )
  71.         if ( memcmp( p->m_code, b, len ) == 0 ) return( p );
  72.     return( NULL );
  73. }