home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-19.28-src.tgz / tar.out / fsf / emacs / src / amiga_term.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  13KB  |  530 lines

  1. /* Amiga terminal control routines.
  2.    Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <sys/time.h>
  23. #include "config.h"
  24. #include "termhooks.h"
  25. #include "termchar.h"
  26. #include "termopts.h"
  27. #include "lisp.h"
  28. #include "frame.h"
  29.  
  30. #ifdef USE_PROTOS
  31. #include "protos.h"
  32. #endif
  33.  
  34. #ifdef GENPROTO
  35. extern void *Aframe_raise_lower; /* CHFIXME */
  36. #endif
  37.  
  38. /* internal state */
  39.  
  40. /* nonzero means supposed to write text in standout mode.  */
  41. static int Astandout_requested;
  42.  
  43. static int Astandout_mode;    /* Nonzero when in standout mode.  */
  44.  
  45. static char tens[100] = {
  46.     '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
  47.     '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
  48.     '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
  49.     '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
  50.     '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
  51.     '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
  52.     '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
  53.     '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
  54.     '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
  55.     '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
  56. };
  57.  
  58. static char ones[100] = {
  59.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  60.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  61.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  62.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  63.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  64.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  65.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  66.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  67.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  68.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  69. };
  70.  
  71. #define addnum(str, num) if (num < 100) \
  72.                              { *--str = ones[num]; *--str = tens[num]; } \
  73.                          else do { *--str = '0' + num % 10; num /= 10; } while (num != 0)
  74.  
  75. static Abackground_highlight ();
  76. static Aturn_off_highlight ();
  77.  
  78.  
  79. /* Cursor motion stuff (from cm.c) */
  80. static int curX, curY;
  81.  
  82. /* Move cursor to absolute position, specified origin 0 */
  83.  
  84. static int
  85. Acursor_to (int row, int col)
  86. {
  87.   char buf[32], *pos = buf + 32;
  88.  
  89.   if (curY == row && curX == col)
  90.     return;
  91.  
  92.   curX = col; curY = row;
  93.   *--pos = 'H';
  94.   col = col + 1; row = row + 1;
  95.   addnum(pos, col);
  96.   *--pos = ';';
  97.   addnum(pos, row);
  98.   *--pos = (char) 0x9b;
  99. #ifdef MULTI_FRAME
  100.   CHFIXME check
  101. #endif
  102.   emacs_output(selected_frame, pos, buf + 32 - pos);
  103.   if (pos < buf) abort();
  104. }
  105.  
  106.  
  107. Aring_bell ()
  108. {
  109. #ifdef MULTI_FRAME
  110.   CHFIXME check
  111. #endif
  112.   emacs_output(selected_frame, "\07", 1);
  113. }
  114.  
  115. Aset_terminal_modes ()
  116. {
  117. }
  118.  
  119. Areset_terminal_modes ()
  120. {
  121.   Aturn_off_highlight ();
  122. }
  123.  
  124. int
  125. Aupdate_begin (FRAME_PTR f)
  126. {
  127.   /* Hide cursor */
  128.   emacs_output(f, "\x9b\x30\x20\x70", 4);
  129. }
  130.  
  131. int
  132. Aupdate_end (FRAME_PTR f)
  133. {
  134.   Abackground_highlight ();
  135.   Astandout_requested = 0;
  136.   emacs_output(f, "\x9b\x20\x70", 3); /* Show cursor */
  137. }
  138.  
  139.  
  140. /* Handle highlighting when TN_standout_width (termcap sg) is not specified.
  141.    In these terminals, output is affected by the value of standout
  142.    mode when the output is written.
  143.  
  144.    These functions are called on all terminals, but do nothing
  145.    on terminals whose standout mode does not work that way.  */
  146.  
  147. static Aturn_off_highlight ()
  148. {
  149.   if (Astandout_mode)
  150.     {
  151.       extern int background, foreground;      
  152.       extern int inverse_fill_pen, inverse_text_pen;
  153.       int b = background + 40, f = foreground + 30;
  154.       if(inverse_fill_pen < 8 && inverse_text_pen < 8)
  155.     {
  156.       char buf[32], *pos = buf + 32;
  157.       /* UnDo inverse fill */
  158.       *--pos = '\0';
  159.       *--pos = 'm';
  160.       addnum(pos, b);
  161.       *--pos = ';';
  162.       /* UnDo inverse text */
  163.       addnum(pos, f);
  164.       *--pos = (char) 0x9b;
  165. #ifdef MULTI_FRAME
  166.   CHFIXME check
  167. #endif
  168.       emacs_output(selected_frame, pos, buf + 32 - pos);
  169.     }
  170.       else
  171.     {
  172.       emacs_output(selected_frame, "\x9b""27m", 4);
  173.     }
  174.     }
  175.   Astandout_mode = 0;
  176. }
  177.  
  178. static Aturn_on_highlight ()
  179. {
  180.   if (!Astandout_mode)
  181.     {
  182.       extern int inverse_fill_pen, inverse_text_pen;
  183.       int b = inverse_fill_pen + 40, f = inverse_text_pen + 30;
  184.       if(inverse_fill_pen < 8 && inverse_text_pen < 8)
  185.     {
  186.       char buf[32], *pos = buf + 32;
  187.       /* Do inverse fill */
  188.       *--pos = '\0';
  189.       *--pos = 'm';
  190.       addnum(pos, b);
  191.       *--pos = ';';
  192.  
  193.       /* Do inverse text */
  194.       addnum(pos, f);
  195.       *--pos = (char) 0x9b;
  196. #ifdef MULTI_FRAME
  197.   CHFIXME check
  198. #endif
  199.       emacs_output(selected_frame, pos, buf + 32 - pos);
  200.     }
  201.       else
  202.     {
  203.       emacs_output(selected_frame, "\x9b\x37m", 3);
  204.     }
  205.     }
  206.   Astandout_mode = 1;
  207. }
  208.  
  209. /* Set standout mode to the state it should be in for
  210.    empty space inside windows.  What this is,
  211.    depends on the user option inverse-video.  */
  212.  
  213. static Abackground_highlight ()
  214. {
  215.   if (inverse_video)
  216.     Aturn_on_highlight ();
  217.   else
  218.     Aturn_off_highlight ();
  219. }
  220.  
  221. /* Set standout mode to the mode specified for the text to be output.  */
  222.  
  223. static
  224. Ahighlight_if_desired ()
  225. {
  226.   if (!inverse_video == !Astandout_requested)
  227.     Aturn_off_highlight ();
  228.   else
  229.     Aturn_on_highlight ();
  230. }
  231.  
  232. /* External interface to control of standout mode.
  233.    Call this when about to modify line at position VPOS
  234.    and not change whether it is highlighted.  */
  235.  
  236. Areassert_line_highlight (highlight, vpos)
  237.      int highlight;
  238.      int vpos;
  239. {
  240.   Astandout_requested = highlight;
  241. }
  242.  
  243. /* Call this when about to modify line at position VPOS
  244.    and change whether it is highlighted.  */
  245.  
  246. Achange_line_highlight (new_highlight, vpos, first_unused_hpos)
  247.      int new_highlight, vpos, first_unused_hpos;
  248. {
  249.   Astandout_requested = new_highlight;
  250.  
  251.   cursor_to (vpos, 0);
  252.  
  253.   Abackground_highlight ();
  254.   clear_end_of_line (first_unused_hpos);
  255.   reassert_line_highlight (new_highlight, curY);
  256. }
  257.  
  258. /* Erase operations */
  259.  
  260. /* clear from cursor to end of screen */
  261. Aclear_to_end ()
  262. {
  263.   Abackground_highlight ();
  264. #ifdef MULTI_FRAME
  265.   CHFIXME check
  266. #endif
  267.   emacs_output(selected_frame, "\x9bJ", 2);
  268. }
  269.  
  270. /* Clear entire frame */
  271.  
  272. static int
  273. Aclear_frame (FRAME_PTR f)
  274. {
  275.   Abackground_highlight ();
  276.   emacs_output(f, "\f", 1);
  277.   curX = curY = 0;
  278. }
  279.  
  280. /* Clear to end of line, but do not clear any standout marker.
  281.    Assumes that the cursor is positioned at a character of real text,
  282.    which implies it cannot be before a standout marker
  283.    unless the marker has zero width.
  284.  
  285.    Note that the cursor may be moved.  */
  286.  
  287. Aclear_end_of_line (first_unused_hpos)
  288.      int first_unused_hpos;
  289. {
  290.   if (curX >= first_unused_hpos)
  291.     return;
  292.  
  293.   Abackground_highlight ();
  294. #ifdef MULTI_FRAME
  295.   CHFIXME check
  296. #endif
  297.   emacs_output(selected_frame, "\x9bK", 2);
  298. }
  299.  
  300. static int
  301. Aoutput_glyphs (string, len)
  302.      register GLYPH *string;
  303.      int len;
  304. {
  305.   Ahighlight_if_desired ();
  306.  
  307.   curX += len;
  308.   emacs_output_glyphs(selected_frame, string, len);
  309. }
  310.  
  311. /* If start is zero, insert blanks instead of a string at start */
  312.  
  313. static int
  314. Ainsert_glyphs (start, len)
  315.      register GLYPH *start;
  316.      int len;
  317. {
  318.   char buf[32], *pos = buf + 32;
  319.  
  320.   Ahighlight_if_desired ();
  321.  
  322.   *--pos = '@';
  323.   addnum(pos, len);
  324.   *--pos = (char) 0x9b;
  325. #ifdef MULTI_FRAME
  326.   CHFIXME check
  327. #endif
  328.   emacs_output(selected_frame, pos, buf + 32 - pos);
  329.   if (pos < buf) abort();
  330.   if (start) emacs_output_glyphs(selected_frame, start, len);
  331. }
  332.  
  333. static int
  334. Adelete_glyphs (n)
  335.      register int n;
  336. {
  337.   char buf[32], *pos = buf + 32;
  338.  
  339.   *--pos = 'P';
  340.   addnum(pos, n);
  341.   *--pos = (char) 0x9b;
  342.   emacs_output(selected_frame, pos, buf + 32 - pos);
  343.   if (pos < buf) abort();
  344. }
  345.  
  346. /* Insert N lines at vpos VPOS.  If N is negative, delete -N lines.  */
  347.  
  348. Ains_del_lines (vpos, n)
  349.      int vpos, n;
  350. {
  351.   register int i = n > 0 ? n : -n;
  352.   char buf[32], *pos = buf + 32;
  353.  
  354.   if (n > 0)
  355.     {
  356.       i = n;
  357.       *--pos = 'L';
  358.     }
  359.   else
  360.     {
  361.       i = -n;
  362.       *--pos = 'M';
  363.     }
  364.   if (vpos + i >= FRAME_HEIGHT (selected_frame)) return;
  365.  
  366.   cursor_to (vpos, 0);
  367.   Abackground_highlight ();
  368.   addnum(pos, i);
  369.   *--pos = (char) 0x9b;
  370. #ifdef MULTI_FRAME
  371.   CHFIXME check
  372. #endif
  373.  
  374.   emacs_output(selected_frame, pos, buf + 32 - pos);
  375.   if (pos < buf) abort();
  376. }
  377.  
  378. #if 0 /* CHFIXME */
  379. Acalculate_costs (extra, costvec, ncostvec)
  380.      int extra;
  381.      int *costvec, *ncostvec;
  382. {
  383.   line_ins_del(selected_frame, 2, 40, extra, 0, costvec, ncostvec);
  384. }
  385. #endif
  386.  
  387. Aset_terminal_window (int size)
  388. {
  389. }
  390.  
  391. /* Return the current position of the mouse.
  392.  
  393.    Set *f to the frame the mouse is in, or zero if the mouse is in no
  394.    Emacs frame.  If it is set to zero, all the other arguments are
  395.    garbage.
  396.  
  397.    If the motion started in a scroll bar, set *bar_window to the
  398.    scroll bar's window, *part to the part the mouse is currently over,
  399.    *x to the position of the mouse along the scroll bar, and *y to the
  400.    overall length of the scroll bar.
  401.  
  402.    Otherwise, set *bar_window to Qnil, and *x and *y to the column and
  403.    row of the character cell the mouse is over.
  404.  
  405.    Set *time to the time the mouse was at the returned position.
  406.  
  407.    This should clear mouse_moved until the next motion
  408.    event arrives.  */
  409. extern int mouse_moved;
  410.  
  411. static void
  412. Amouse_position(FRAME_PTR *f,
  413.         Lisp_Object *bar_window,
  414.         enum scroll_bar_part *part,
  415.         Lisp_Object *x, Lisp_Object *y,
  416.         unsigned long *time)
  417. {
  418.     struct timeval tv;
  419.     int an_x, an_y;
  420.  
  421. #ifdef MULTI_FRAME
  422.     CHFIXME
  423. #endif
  424.     get_mouse_char_pos(selected_frame, &an_x, &an_y);
  425.     if(x >= 0 && y >= 0) /* CHFIXME: always report ? */
  426.     {
  427.     *f = selected_frame; /* CHFIXME: ok for MULTI_FRAME ? */
  428.     *bar_window = Qnil;
  429.     *x = make_number (an_x);
  430.     *y = make_number (an_y);
  431.     gettimeofday (&tv, NULL);
  432.     *time = tv.tv_usec;
  433.     }
  434.     else
  435.     {
  436.     *f = NULL;
  437.     }
  438.     mouse_moved = 0;
  439. }
  440. /* Change from withdrawn state to mapped state,
  441.    or deiconify. */
  442.  
  443. void
  444. x_make_frame_visible (FRAME_PTR f)
  445. {
  446.     /* CHFIXME: add deiconify call! */
  447. }
  448.  
  449. amiga_term_init ()
  450. {
  451.   must_write_spaces = FALSE;
  452.   min_padding_speed = 0;
  453.   memory_below_frame = FALSE;     /* we don't remember what scrolls 
  454.                    off the bottom */
  455.   meta_key = 2; /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
  456.            keep 0200 bit in input chars.  0 to ignore the 0200 bit.  */
  457.  
  458.   scroll_region_ok = TRUE; /* CHFIXME: test */         /* we'll scroll partial frames */
  459.   scroll_region_ok = FALSE;         /* we don\'t scroll partial frames */
  460.   line_ins_del_ok = TRUE;        /* CHFIXME: test */
  461.   line_ins_del_ok = FALSE;    /* much cleaner display when FALSE  -ch3/19/93. */
  462.   char_ins_del_ok = FALSE;
  463.   fast_clear_end_of_line = TRUE;
  464.   no_redraw_on_reenter = FALSE;
  465.  
  466.   clear_frame_hook = Aclear_frame;
  467.   clear_end_of_line_hook = Aclear_end_of_line;
  468.   clear_to_end_hook = Aclear_to_end;
  469.   ins_del_lines_hook = Ains_del_lines;
  470.   change_line_highlight_hook = Achange_line_highlight;
  471.  
  472.   insert_glyphs_hook = Ainsert_glyphs;
  473.   write_glyphs_hook = Aoutput_glyphs;
  474.   delete_glyphs_hook = Adelete_glyphs;
  475.  
  476.   ring_bell_hook = Aring_bell;
  477.   reset_terminal_modes_hook = Areset_terminal_modes;
  478.   set_terminal_modes_hook = Aset_terminal_modes;
  479.   update_begin_hook = Aupdate_begin;
  480.   update_end_hook = Aupdate_end;
  481.   set_terminal_window_hook = Aset_terminal_window;
  482.   /* read_socket_hook ? */ /* CHFIXME */
  483.   /* frame_up_to_date_hook */
  484.   cursor_to_hook = Acursor_to;
  485.   reassert_line_highlight_hook = Areassert_line_highlight;
  486.   raw_cursor_to_hook = Acursor_to; /* CHFIXME, correct ? */
  487.   
  488.   mouse_position_hook = Amouse_position;
  489.   /*
  490.   frame_rehighlight_hook = XTframe_rehighlight;
  491.   */
  492. #ifdef GENPROTO
  493.   frame_raise_lower_hook = Aframe_raise_lower;
  494. #endif
  495.   /*
  496.   set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
  497.   */
  498. #ifdef USE_SCROLL_BARS
  499.   condemn_scroll_bars_hook = Acondemn_scroll_bars;
  500.   redeem_scroll_bar_hook = Aredeem_scroll_bar;
  501.   judge_scroll_bars_hook = Ajudge_scroll_bars;
  502. #endif
  503. #if 0
  504. /*  dont_calculate_costs = 1; try to use it CHFIXME */
  505. #else
  506.   dont_calculate_costs = 0;
  507. #endif
  508.  
  509. #if 0 /* CHFIXME */
  510.   calculate_costs_hook = Acalculate_costs;
  511. #endif
  512.   
  513.   /* Get screen size from system, or else from somewhere ...  */
  514.  
  515. #ifdef MULTI_FRAME
  516.   you lose
  517. #endif
  518.   get_frame_size (&FRAME_WIDTH(selected_frame), &FRAME_HEIGHT(selected_frame));
  519.   /* Random defaults to avoid any problems */
  520.   if (FRAME_WIDTH(selected_frame) <= 0) FRAME_WIDTH(selected_frame) = 80;
  521.   if (FRAME_HEIGHT(selected_frame) <= 0) FRAME_HEIGHT(selected_frame) = 23;
  522.  
  523.   init_baud_rate ();
  524.   FRAME_CAN_HAVE_SCROLL_BARS (selected_frame) = 0; /* CHFIXME */
  525.   FRAME_HAS_VERTICAL_SCROLL_BARS (selected_frame) = 0;
  526.  
  527.  
  528.   /* CHFIXME: move init glyphs stuff here ? */
  529. }
  530.