procedure clean_up_display;
var start, finish : integer;
begin
   if (xkbd <= 1) AND (ykbd = out_start_line) then exit;
   start := (80*(yout - 1) + xout) - 1;
   finish := (80*(ykbd - 1) + xkbd) - 1;
   while start <= finish do
   begin
     if (start > lead_attr) then
     case vid_type of
       0 : mono_screen[start].a := xmt_attrib;
       1 : color_screen[start].a := xmt_attrib;
     end;
     start := start + 2;
   end;
end;

procedure del_char;
begin
  if (inp_ptr <> out_ptr) then
  begin
    if xkbd > 1 then
    begin
      inp_ptr := inp_ptr - 1;
      if (inp_ptr < 0 ) then inp_ptr := buf_size;
      xkbd := xkbd - 1;
      gotoxy(xkbd,ykbd);
      transmit_color;
      write(' '^H);
    end;
  end;
end;

procedure add_char(ch : char);
begin
  inp_ptr := (inp_ptr + 1) AND buf_size;
  kbd_buffer[inp_ptr] := ch;
  gotoxy(xkbd,ykbd);
  case state  of
    transmit  : transmit_color;
    receive   : aux_color;
  end;
  if ch = #$0D
  then begin
         write(#31);
         xkbd := 1;
         ykbd := ykbd + 1;
       end
  else begin
         case ch of
           #07 : case mode of
                   CW    : write(' ');
                   RTTY  : write(#254);
                   ASCII : write(#254);
                 end;
           else  write(ch);
         end;
         xkbd := xkbd + 1;
         if xkbd > scrn_width then
         begin
           xkbd := 1;
           ykbd := ykbd + 1;
         end;
       end;
  if ykbd > out_end_line then
    begin
      transmit_color;
      window(1,out_start_line,80,out_end_line);
      gotoxy(1,1); DelLine;
      window(1,1,80,25);
      ykbd := ykbd - 1;
      yout := yout - 1;
    end;
  gotoxy(xkbd,ykbd);
end;

procedure RYs;
var   i : integer;
     RY : string[72];
begin
  RY := 'RYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRYRY';
  add_char(#13);
  for i := 1 to length(RY) do
    add_char(RY[i]);
  add_char(#13);
end;

procedure xmt_msg( nbr : integer);
var  index : integer;
     size  : integer;
begin
  index := 1;
  size := ord(msg[nbr][0])+1;
  while (index < size) do
    begin
      add_char(msg[nbr][index]);
      index := index + 1;
    end;
end;

procedure add_msg;
var nbr, size, index : integer;
    ch : char;
begin
  prompt_color;
  gotoxy(20,aux_line); write('Select Msg (0..9) ...');
  repeat
    ch := readkey;
  until (ch in [#0,'0'..'9']);
  if ch = #0 then
  begin
    ch := readkey;
    gotoxy(20,aux_line); aux_color; ClrEol;
    exit;
  end;
  xmt_msg(ord(ch) - $30);
  gotoxy(20,aux_line); aux_color; ClrEol;
end;
