home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / textutil / microemacs / Source / c / RiscOSwimp < prev    next >
Encoding:
Text File  |  1991-09-14  |  27.8 KB  |  997 lines

  1. /*
  2.  *       riscoswimp.c:   RISC OS windowed front end for uEmacs (and others)
  3.  */
  4.  
  5. #include "kernel.h"
  6.  
  7. #include <stdio.h>
  8. #include "estruct.h"
  9. #include "edef.h"
  10.  
  11. #if RISCOSWIMP
  12.  
  13. #include "wimp.h" 
  14. #include "wimpt.h" 
  15. #include "win.h"
  16. #include "event.h"
  17. #include "res.h"
  18. #include "menu.h"
  19. #include "template.h"
  20. #include "dbox.h"
  21. #include "werr.h"
  22. #include "baricon.h"
  23. #include "xferrecv.h"
  24. #include "msgs.h"
  25. #include "saveas.h"
  26.  
  27. #define NROW            64      /* Screen size.                         */
  28. #define NCOL            192     /* Edit if you want to.                 */
  29. #define NPAUSE          750     /* # times thru update to pause         */
  30. #define MARGIN          8       /* size of minimim margin and           */
  31. #define SCRSIZ          64      /* scroll size for extended lines       */
  32. #define BEL             0x07    /* BEL character.                       */
  33. #define ESC             0x1B    /* ESC character.                       */
  34.  
  35. #define INBUFSIZE       16      /* Cyclic buffer for input              */ 
  36.                                 /* Must be a power of two               */
  37.  
  38. extern  int     risc_osgetc(void);              /* forward references   */
  39. extern  int     risc_osputc(int);
  40. extern  int     risc_osflush(void);
  41. extern  int     risc_osmove(int, int);
  42. extern  int     risc_oseeol(void);
  43. extern  int     risc_oseeop(void);
  44. extern  int     risc_osbeep(void);
  45. extern  int     risc_osopen(void);
  46. extern  int     risc_osrev(int);
  47. extern  int     risc_oscres();
  48. extern  int     risc_osclose(void);
  49. extern  int     risc_oskopen(void);
  50. extern  int     risc_oskclose(void);
  51.  
  52. #if              COLOR
  53. extern  int     risc_osfcol();
  54. extern  int     risc_osbcol();
  55.  
  56. int      cfcolor = -1;           /* current forground color */
  57. int      cbcolor = -1;           /* current background color */
  58. #endif
  59.  
  60. TERM    term    = {
  61.         NROW-1,
  62.         NROW-1,
  63.         NCOL,
  64.         NCOL,
  65.         MARGIN,
  66.         SCRSIZ,
  67.         NPAUSE,
  68.         risc_osopen,
  69.         risc_osclose,
  70.         risc_oskopen,
  71.         risc_oskclose,
  72.         risc_osgetc,
  73.         risc_osputc,
  74.         risc_osflush,
  75.         risc_osmove,
  76.         risc_oseeol,
  77.         risc_oseeop,
  78.         risc_osbeep,
  79.         risc_osrev,
  80.         risc_oscres
  81. #if     COLOR
  82.         , risc_osfcol,
  83.         risc_osbcol
  84. #endif
  85. };
  86.  
  87. #define vdu(x) _kernel_oswrch(x)
  88.  
  89. static BOOL     win_displayed;
  90. static int      ue_xpos, ue_ypos;
  91. static char     sb[NROW][NCOL];
  92. static char     attribs[NROW][NCOL];
  93. static char     attrib_byte;
  94. static int      use_colour;
  95. static wimp_w   uemacs_window;
  96. static menu     uemacs_menu, uemacs_icon_menu;
  97. static char     inbuffer[INBUFSIZE];
  98. static int      in_next, in_last;
  99.  
  100. BOOL need_to_redraw;
  101. static wimp_box rb, rb_blank = {NCOL, NROW, -1, -1};
  102.  
  103. static void in_init(void)
  104. {
  105.         in_next = in_last = INBUFSIZE;
  106. }
  107.  
  108. static int in_any(void)
  109. {
  110.         return (in_next != in_last);
  111. }
  112.  
  113. static void in_push(char c)
  114. {
  115.         in_last &= (INBUFSIZE -1);
  116.         inbuffer[in_last++]=c;
  117. }
  118.  
  119. static void in_push_spec(int c)
  120. {
  121.         in_last &= (INBUFSIZE -1);
  122.         inbuffer[in_last++]=0;
  123.         in_last &= (INBUFSIZE -1);
  124.         inbuffer[in_last++]=(c >> 8);
  125.         in_last &= (INBUFSIZE -1);
  126.         inbuffer[in_last++]=(c & 0xff);
  127. }
  128.  
  129. static void in_push_nop(void)
  130. {
  131.     in_push_spec(ALTD | SHFT | SPEC | CTLX | META | CTRL | 'N');
  132. }
  133.  
  134. static void in_push_mouse(int m, int x, int y, char t)
  135. {
  136.         in_last &= (INBUFSIZE -1);
  137.         inbuffer[in_last++]=0;
  138.         in_last &= (INBUFSIZE -1);
  139.         inbuffer[in_last++]=(m | MOUS) >> 8;
  140.         in_last &= (INBUFSIZE -1);
  141.         inbuffer[in_last++]=x;
  142.         in_last &= (INBUFSIZE -1);
  143.         inbuffer[in_last++]=y;
  144.         in_last &= (INBUFSIZE -1);
  145.         inbuffer[in_last++]=t;
  146. }
  147.  
  148. static char in_pull(void)
  149. {
  150.         in_next &= (INBUFSIZE -1);
  151.         return (inbuffer[in_next++]);
  152. }
  153.  
  154. static void uemacs_set_pointer(char *name, int x, int y)
  155. {
  156.         os_regset r;
  157.  
  158.         r.r[0] = 36 + 256;
  159.         r.r[2] = (int) name;
  160.         r.r[3] = 2;
  161.         r.r[4] = x;
  162.         r.r[5] = y;
  163.         r.r[6] = 0;
  164.         r.r[7] = 0;
  165.         wimpt_noerr(wimp_spriteop_full(&r));
  166. }
  167.  
  168. static void place_caret(BOOL force)
  169. {
  170.         wimp_caretstr   car;
  171.  
  172.         wimp_get_caret_pos(&car);
  173.         if (force || car.w == uemacs_window)
  174.         {
  175.                 car.w = uemacs_window;
  176.                 car.i = -1;
  177.                 car.x = ue_xpos << 4;
  178.                 car.y = -(ue_ypos+1)<< 5;
  179.                 car.height = 1<<24 | 32;
  180.                 car.index = -1; 
  181.  
  182.                 wimp_set_caret_pos(&car);
  183.         }
  184. }               
  185.  
  186. static void uemacs_force_redraw(void)
  187. {
  188.         wimp_redrawstr r;       
  189.  
  190.         r.w = uemacs_window;
  191.         r.box.x0 = rb.x0 << 4;
  192.         r.box.x1 = (rb.x1 + 1) << 4;
  193.         r.box.y1 = -(rb.y0 << 5);
  194.         r.box.y0 = -((rb.y1 +1) << 5);
  195.  
  196.         wimp_force_redraw(&r);
  197.  
  198.         rb = rb_blank;
  199.         need_to_redraw = FALSE;
  200. }
  201.  
  202.  
  203. static BOOL uemacs_create_window(char *name, wimp_w *handle)
  204. {
  205.         wimp_wind *window;
  206.  
  207.         window = template_syshandle(name);
  208.         if (window == 0)
  209.                 return FALSE;
  210.  
  211.         use_colour = (3 << 4) | window->colours[wimp_WCWKAREAFORE] ^
  212.                                 window->colours[wimp_WCWKAREABACK] ;
  213.  
  214.         return (wimpt_complain(wimp_create_wind(window, handle)) == 0);
  215. }
  216.  
  217. static void uemacs_open_window(wimp_openstr *o)
  218. {
  219.         wimp_redrawstr r;
  220.         int ox,oy;
  221.  
  222.         o->x = 0;
  223.         o->y = 0;
  224.  
  225.         wimpt_noerr(wimp_open_wind(o));
  226.                         
  227.         oy = term.t_mrow;
  228.         ox = term.t_mcol;
  229.  
  230.         if (oy != (term.t_mrow = ((o->box.y1 - o->box.y0) >> 5)-1))
  231.                 newsize(TRUE, term.t_mrow +1);
  232.         if (ox != (term.t_mcol = ((o->box.x1 - o->box.x0) >> 4)))
  233.                 newwidth(TRUE, term.t_mcol);
  234.                 
  235.         if (term.t_mrow != oy || term.t_mcol != ox)
  236.         {
  237.                 update(TRUE);
  238.  
  239.                 r.w = -1;
  240.                 r.box = o->box;
  241.                 wimp_force_redraw(&r);
  242.         }
  243. }
  244.  
  245. static void raise_window(void)
  246. {
  247.         wimp_wstate     state;
  248.         wimp_caretstr r;
  249.  
  250.         if (wimpt_complain(wimp_get_wind_state(uemacs_window, &state)) == 0)
  251.         {
  252.                 state.o.behind = -1;     /* Make sure window is opened in front */
  253.                 wimpt_complain(wimp_open_wind(&state.o));
  254.         }
  255.  
  256.         r.w = uemacs_window;
  257.         r.i = -1;
  258.         r.x = ue_xpos << 4;
  259.         r.y = -(ue_ypos+1)<< 5;
  260.         r.height = 1<<24 | 32;
  261.         r.index = -1; 
  262.  
  263.         wimp_set_caret_pos(&r);
  264. }
  265.  
  266. static void uemacs_redraw_window(wimp_w handle)
  267. {
  268.         int             more;
  269.         wimp_redrawstr  r;
  270.         int             ox,oy;
  271.  
  272.         r.w = handle;
  273.         wimpt_noerr(wimp_redraw_wind(&r, &more));
  274.                                                                  
  275.         ox = r.box.x0 - r.scx;
  276.         oy = r.box.y1 - r.scy;
  277.  
  278.         while (more)
  279.         {                                                       
  280.                 int top, left, right, bottom;
  281.                 int i,j;
  282.                                         
  283.                 top =           r.g.y1 + 1 - oy;        
  284.                 left =          r.g.x0 - ox;
  285.                 right =         r.g.x1 - ox;
  286.                 bottom =        r.g.y0 + 1 - oy;
  287.  
  288.                 top = (-top) >> 5;
  289.                 left = left >> 4;
  290.                 right = right >> 4;
  291.                 bottom = (-bottom) >> 5;
  292.  
  293.                 wimp_setcolour(use_colour);
  294.  
  295.                 for(j = top; j<= bottom; j++)
  296.                 {
  297.                         int revs = -1, last = 0;
  298.                         
  299.                         bbc_move(ox + (left << 4), oy-1-(j<<5) );
  300.                         for(i = left; i <= right; i++)
  301.                         { 
  302.                                 vdu(sb[j][i]);
  303.                                 if (attribs[j][i] != last)
  304.                                 {
  305.                                         if (revs == -1)
  306.                                         {
  307.                                                 revs = i;
  308.                                         }
  309.                                         else
  310.                                         {
  311.                                                 bbc_rectanglefill(ox+(revs<<4), oy-((j+1) <<5),
  312.                                                                 ((i - revs)<<4)-1, 31 );
  313.                                                 revs = -1;
  314.                                         }
  315.                                         bbc_move(ox +((i+1) << 4) , oy-((j+1) << 5) + 31 );
  316.                                         last = attribs[j][i];
  317.                                 } 
  318.                         }
  319.                         if (last)
  320.                         {
  321.                                 bbc_rectanglefill(ox+(revs<<4), oy-((j+1) <<5),
  322.                                                 ((i - revs)<<4)-1, 31 );
  323.                         }
  324.                 }
  325.  
  326.                 wimp_get_rectangle(&r, &more);
  327.         }
  328.  
  329.         place_caret(FALSE);
  330.  
  331. }
  332.  
  333. static wimp_bbits last_button;
  334.  
  335. static void uemacs_drag_event(wimp_box *b)
  336. {
  337.         wimp_wstate s;
  338.         int at_x, at_y;
  339.  
  340.         wimpt_noerr(wimp_get_wind_state(uemacs_window, &s));
  341.         
  342.         at_x = (b->x0 - s.o.box.x0) >> 4;
  343.         at_y = (s.o.box.y1 -1 - b->y0) >> 5;
  344.  
  345.         in_push_mouse(0, at_x, at_y, (last_button & wimp_BDRAGLEFT) ? 'b' : 'f');
  346.         uemacs_set_pointer("ptr_write",4,4);
  347. }
  348.  
  349. static void uemacs_mouse_event(wimp_eventdata *d)
  350. {
  351.         wimp_wstate s;
  352.         int at_x, at_y;                                                  
  353.  
  354.         wimpt_noerr(wimp_get_wind_state(uemacs_window, &s));
  355.  
  356.         at_x = (d->but.m.x - s.o.box.x0) >> 4;
  357.         at_y = (s.o.box.y1 -1 - d->but.m.y) >> 5;
  358.  
  359.         place_caret(TRUE);
  360.  
  361.         if (d->but.m.bbits & (wimp_BDRAGRIGHT | wimp_BDRAGLEFT))
  362.         {
  363.                 wimp_dragstr ds;
  364.  
  365.                 ds.window = uemacs_window;
  366.                 ds.type = wimp_USER_HIDDEN;
  367.                 ds.box.x0 = ds.box.x1 = d->but.m.x;
  368.                 ds.box.y0 = ds.box.y1 = d->but.m.y;
  369.                 ds.parent = s.o.box;
  370.  
  371.                 wimp_drag_box(&ds);
  372.  
  373.                 if (d->but.m.bbits & wimp_BDRAGLEFT)
  374.                         uemacs_set_pointer("ptr_hand",12,8);
  375.  
  376.                 last_button = d->but.m.bbits;
  377.  
  378.                 in_push_mouse(0, at_x, at_y, (d->but.m.bbits & wimp_BDRAGLEFT) ? 'a' : 'e');
  379.         }
  380.         else
  381.         {
  382.                 if (d->but.m.bbits == last_button >> 4)
  383.                 {
  384.                         last_button = 0;
  385.                 }
  386.                 else
  387.                 {
  388.                         in_push_mouse(0, at_x, at_y, (d->but.m.bbits & wimp_BLEFT) ? 'a' : 'e');
  389.                         in_push_mouse(0, at_x, at_y, (d->but.m.bbits & wimp_BLEFT) ? 'b' : 'f');
  390.                 }
  391.         }
  392. }
  393.  
  394. static void uemacs_key_pressed(int c)
  395. {
  396.         static had_escape = 0;
  397.  
  398.         /* Keys between 100 and 180 and f12 keys get filtered out */
  399.         if ((c >= 0x100 && c < 0x180) || (c >= 0x1c0 && ((c & 0xf) == 0xc)))
  400.                 wimp_processkey(c);
  401.         else
  402.         {
  403.                 if (0)                           /* c = ESC ????? */
  404.                 {                                                       
  405.                         if (had_escape)
  406.                         {
  407.                                 in_push_spec(ALTD | ESC);
  408.                                 had_escape = 0;
  409.                         }
  410.                         else
  411.                         {
  412.                                 had_escape = 1;
  413.                         }
  414.                 }
  415.                 else
  416.                 {
  417.                         if (c < 0x100)
  418.                         {
  419.                                 if (had_escape)
  420.                                 {
  421.                                         if (c >= 0x20)
  422.                                         {
  423.                                                 in_push_spec(ALTD | (c & 0xff));
  424.                                         }
  425.                                         else
  426.                                         {
  427.                                                 in_push_spec(ALTD | CTRL | '@' | c);
  428.                                         }
  429.                                 }
  430.                                 else
  431.                                 {
  432.                                     if (c == 0)
  433.                                     {
  434.                                         in_push(0);
  435.                                         in_push(0);
  436.                                         in_push(0);
  437.                                     }
  438.                                     else
  439.                                     {
  440.                                         in_push(c & 0xff);
  441.                                     }
  442.                                 }
  443.                         }
  444.                         else
  445.                         {
  446.                                 int base_key = c & 0xCF;
  447.                                 int shft = (c & 0x10 ? SHFT : 0);
  448.                                 int ctrl = (c & 0x20 ? CTRL : 0);
  449.                                 int alt = (had_escape ? ALTD : 0);
  450.  
  451.                                 if (base_key >= 0x81    && base_key <= 0x89)
  452.                                         in_push_spec(SPEC | shft | ctrl | base_key - 0x81 + '1');
  453.                                 else
  454.                                 {       
  455. #define asc (shft | ctrl | alt)
  456.                                         switch (base_key)
  457.                                         {
  458.                                         case 0x80:      /* F0 (Print) */
  459.                                                 in_push_spec(SPEC | asc | '`');
  460.                                                 break;
  461.  
  462.                                         case 0x8A:      /* Tab */
  463.                                                 if (asc == 0)
  464.                                                         in_push ('\t');
  465.                                                 else if (!ctrl)
  466.                                                         in_push_spec (alt | shft | CTRL | 'I');
  467.                                                 else
  468.                                                         in_push_spec (SPEC | asc | 'T');
  469.                                                         break;
  470.  
  471.                                         case 0x8B:      /* Copy */
  472.                                                 in_push_spec (SPEC | asc | '>');
  473.                                                 break;
  474.  
  475.                                         case 0x8C:      /* Cursor Left */
  476.                                                 in_push_spec (SPEC | asc | 'B');
  477.                                                 break;
  478.  
  479.                                         case 0x8D:      /* Cursor Right */
  480.                                                 in_push_spec (SPEC | asc | 'F');
  481.                                                 break;
  482.  
  483.                                         case 0x8E:      /* Cursor Down */
  484.                                                 in_push_spec (SPEC | asc | 'N');
  485.                                                 break;
  486.  
  487.                                         case 0x8F:      /* Cursor Up */
  488.                                                 in_push_spec (SPEC | asc | 'P');
  489.                                                 break;
  490.  
  491.                                         case 0xCA:      /* F10 */
  492.                                                 in_push_spec(SPEC | asc | '0');
  493.                                                 break;
  494.  
  495.                                         case 0xCB:      /* F11 */
  496.                                                 in_push_spec(SPEC | asc | '-');
  497.                                                 break;
  498.  
  499.                                         case 0xCC:      /* F12 */
  500.                                                 in_push_spec(SPEC | asc | '=');
  501.                                                 break;
  502.  
  503.                                         case 0xCD:      /* Insert */
  504.                                                 in_push_spec (SPEC | asc | 'C');
  505.                                                 break;
  506.                                         }
  507.                                 }
  508.                         }
  509.                 }
  510.         }
  511. }
  512.  
  513. static void uemacs_scroll_event(int y)
  514. {
  515.         switch (y)
  516.         {
  517.                 case -2:
  518.                         in_push_spec(SPEC | 'W');
  519.                         break;
  520.                 case -1:
  521.                         in_push_spec(SPEC | 'X');
  522.                         break;
  523.                 case 1:
  524.                         in_push_spec(SPEC | 'Y');
  525.                         break;
  526.                 case 2:
  527.                         in_push_spec(SPEC | 'Z');
  528.                         break;
  529.         }
  530. }                                               
  531.  
  532. static void uemacs_clickproc(wimp_i i)
  533. {
  534.         i=i;
  535.  
  536.         raise_window();
  537. }
  538.  
  539. static void uemacs_iconbar_loader(void)
  540. {
  541.         char *filename;
  542.         
  543.         xferrecv_checkinsert(&filename);
  544.  
  545.         getfile(filename, TRUE);
  546.  
  547.         raise_window();
  548.         
  549.         update(TRUE);
  550.                 
  551.         xferrecv_insertfileok();
  552. }
  553.  
  554. static void uemacs_window_loader(void)
  555. {
  556.         char *filename;
  557.         
  558.         xferrecv_checkinsert(&filename);
  559.  
  560.         ifile(filename);
  561.  
  562.         raise_window();
  563.  
  564.     update(TRUE);
  565.                 
  566.         xferrecv_insertfileok();
  567. }
  568.  
  569. static BOOL uemacs_saveproc(char *fname, void *handle)
  570. {
  571.         int s;
  572.  
  573.         handle = handle;
  574.                 
  575.         if ((s=writeout(fname, "w")) == TRUE)
  576.         {
  577.                 strcpy(curbp->b_fname, fname);
  578.                 curbp->b_flag &= ~BFCHG;
  579.                 /* Update mode lines.   */
  580.                 upmode();
  581.                 update(TRUE);
  582.         }
  583.                 
  584.         return s;
  585. }
  586.  
  587. static void uemacs_event_handler(wimp_eventstr *e, void *handle)
  588. {
  589.         handle = handle; /* We don't need handle: this stops compiler warning */
  590.  
  591.         /* Deal with event */
  592.         switch (e->e)
  593.         {
  594.                 case wimp_EREDRAW:
  595.                         uemacs_redraw_window(e->data.o.w);
  596.                         break;
  597.  
  598.                 case wimp_EOPEN:
  599.                         uemacs_open_window(&e->data.o);
  600.                         break;
  601.  
  602.                 case wimp_ECLOSE:
  603.                         wimp_close_wind(e->data.o.w);
  604.                         win_displayed = FALSE;
  605.                         break;
  606.  
  607.                 case wimp_EPTRLEAVE:
  608.                         os_swi2(6,106,1);  /* Select pointer 1 */
  609.                         break;
  610.  
  611.                 case wimp_EPTRENTER:
  612.                         uemacs_set_pointer("ptr_write",4,4);
  613.                         break;
  614.  
  615.                 case wimp_EBUT:
  616.                     if (e->data.but.m.w < 0)
  617.                     {
  618.                         uemacs_clickproc(e->data.but.m.i);
  619.                     }
  620.                     else
  621.                     {                        
  622.                             uemacs_mouse_event(&e->data);
  623.                         }
  624.                         break;
  625.  
  626.                 case wimp_EUSERDRAG:
  627.                         uemacs_drag_event(&e->data.dragbox);
  628.                         break;
  629.  
  630.                 case wimp_EKEY:
  631.                         uemacs_key_pressed(e->data.key.chcode);
  632.                         break;
  633.  
  634.                 case wimp_ESCROLL:
  635.                         uemacs_scroll_event(e->data.scroll.y);
  636.                         break;
  637.                         
  638.                 case wimp_ESEND:
  639.                 case wimp_ESENDWANTACK:
  640.                 {
  641.                         switch (e->data.msg.hdr.action)
  642.                         {
  643.                                 case wimp_MDATAOPEN:
  644.                                         if (e->data.msg.data.dataopen.type == 0xfff)
  645.                                                 uemacs_iconbar_loader();
  646.                                         break;
  647.                                 case wimp_MDATALOAD:
  648.                                         if (e->data.msg.data.dataload.w == uemacs_window)
  649.                                         {
  650.                                                 uemacs_window_loader();
  651.                                         }
  652.                                         else
  653.                                         {
  654.                                                 uemacs_iconbar_loader();
  655.                                         }
  656.                                         break;
  657.                                 case wimp_MPREQUIT:
  658.                                         break;
  659.                                 default:
  660.                                         break;
  661.                         }
  662.                 }
  663.                 
  664.                 default:         /* Ignore any other event */
  665.                         break;
  666.         }
  667. }
  668.  
  669. int risc_osflush()
  670. {
  671.         return 0;
  672. }
  673.  
  674. int risc_osmove(int row, int col)
  675. {
  676.         ue_xpos=col;
  677.         ue_ypos=row;
  678.         
  679.         place_caret(FALSE); 
  680.  
  681.         if (need_to_redraw)
  682.         {
  683.                 /* If the move is to a line not next to the rb, redraw now */
  684.                 if ((row < rb.y0-1) || (row > rb.y1+1))
  685.                         uemacs_force_redraw();
  686.         }
  687.  
  688.         return 0;
  689. }
  690.  
  691. int risc_oseeol(void)
  692. {
  693.         int i;
  694.         for(i=ue_xpos; i<NCOL; i++)
  695.         {
  696.                 sb[ue_ypos][i]=32;
  697.                 attribs[ue_ypos][i]=attrib_byte;
  698.         }
  699.         
  700.         if (rb.x0 > ue_xpos)
  701.                 rb.x0 = ue_xpos;
  702.         if (rb.y0 > ue_ypos)
  703.                 rb.y0 = ue_ypos;
  704.         if (rb.y1 < ue_ypos)
  705.                 rb.y1 = ue_ypos;
  706.         rb.x1 = NCOL-1;
  707.  
  708.         need_to_redraw=TRUE;
  709.  
  710.         return 0;
  711. }
  712.  
  713. int risc_oseeop(void)
  714. {
  715.         int i,j;
  716.         risc_oseeol();
  717.         for(j=ue_ypos+1; j<NROW; j++)
  718.                 for(i=0; i<NCOL; i++)
  719.                 {
  720.                         sb[j][i]=32;
  721.                         attribs[j][i]=attrib_byte;
  722.                 }
  723.  
  724.         rb.x0 = 0;
  725.         rb.y1 = NROW-1;
  726.  
  727.         return 0;
  728. }
  729.  
  730. int risc_osrev(int state) 
  731. {
  732.         if (state)
  733.                 attrib_byte = 1;
  734.         else
  735.                 attrib_byte = 0;
  736.  
  737.         return 0;
  738. }
  739.  
  740. int risc_oscres(char *newres)
  741. {
  742.         return 0;
  743. }
  744.  
  745. int spal(int a)
  746. {
  747.         return 0;
  748. }
  749.  
  750. int risc_osbeep(void)
  751. {
  752.         vdu(BEL);
  753.         return 0;
  754. }
  755.  
  756. static void uemacs_program_info(void)
  757. {
  758.         dbox    d;
  759.  
  760.         if (d = dbox_new("ProgInfo"), d != NULL)
  761.         {
  762.                 dbox_setfield(d, 4, "0.80 ("__DATE__")" );
  763.                 dbox_setfield(d, 1, PROGNAME" "VERSION );
  764.  
  765.                 dbox_show(d);
  766.  
  767.                 dbox_fillin(d);
  768.  
  769.                 dbox_dispose(&d);
  770.         }
  771. }
  772.  
  773. static void save_buffer(void)
  774. {
  775. #if     EXTINFO
  776.         int type = (curbp->b_os.load >> 8) & 0xfff;
  777. #else
  778. #if     FTYPE
  779.         int type = curbp->b_type;
  780. #else
  781.         int type = 0xfff;
  782. #endif  /* FTYPE */
  783. #endif  /* EXTINFO */
  784.         saveas(type, curbp->b_fname, 1, uemacs_saveproc, 0, 0, 0);
  785. }
  786.  
  787. static void uemacs_barmenuproc(void *handle, char *hit)
  788. {
  789.         handle = handle;
  790.         
  791.         switch(hit[0])
  792.         {
  793.                 case 1:
  794.                         uemacs_program_info();
  795.                         break;
  796.                 case 2:
  797.                         raise_window();
  798.                         break;
  799.                 case 3:
  800.                         quit(FALSE, 0);
  801.                         break;
  802.         }
  803.         in_push_nop();
  804. }
  805.                                                  
  806. static void uemacs_menuproc(void *handle, char *hit)
  807. {
  808.         handle = handle;
  809.         
  810.         switch(hit[0])
  811.         {
  812.                 case 1:
  813.                         save_buffer();
  814.                         break;
  815.                 case 2:
  816.                         raise_window();
  817.                         break;
  818.                 case 3:
  819.                         quit(FALSE, 0);
  820.                         break;
  821.         }
  822.         in_push_nop();
  823. }
  824.                                                  
  825. int risc_osopen(void)
  826. {
  827.         wimp_wstate     state;
  828.  
  829.         wimpt_init(PROGNAME);
  830.         res_init("uEmacs");
  831.         template_init();         
  832.         msgs_init();
  833.  
  834.         baricon("!uemacs", 1, uemacs_clickproc);
  835.         win_register_event_handler(win_ICONBAR, uemacs_event_handler, 0);
  836.         win_claim_unknown_events(win_ICONBAR);
  837.  
  838.         uemacs_icon_menu = menu_new("uEmacs", msgs_lookup("barmenu"));
  839.         event_attachmenu(win_ICONBAR, uemacs_icon_menu, uemacs_barmenuproc, 0); 
  840.  
  841.         uemacs_create_window("MainWindow", &uemacs_window);
  842.         win_register_event_handler(uemacs_window, uemacs_event_handler, 0);
  843.         win_claim_idle_events(uemacs_window);
  844.         event_setmask(event_getmask() & (~wimp_EMNULL));
  845.  
  846.         uemacs_menu = menu_new("uEmacs", msgs_lookup("mainmenu"));
  847.         event_attachmenu(uemacs_window, uemacs_menu, uemacs_menuproc, 0);
  848.  
  849.         if (wimpt_complain(wimp_get_wind_state(uemacs_window, &state)) == 0)
  850.                 {
  851.  
  852.                         term.t_nrow = ((state.o.box.y1 - state.o.box.y0) >> 5)-1;
  853.                         term.t_ncol = ((state.o.box.x1 - state.o.box.x0) >> 4);
  854.  
  855.                         state.o.behind = -1;            /* Make sure window is opened in front */
  856.                         wimpt_complain(wimp_open_wind(&state.o));
  857.                         win_activeinc();
  858.                         win_displayed = TRUE;
  859.                 }
  860.         attrib_byte = 0;
  861.         risc_osmove(0,0);
  862.         risc_oseeop();
  863.         place_caret(TRUE);
  864.  
  865.         rb = rb_blank;
  866.  
  867.         return 0;
  868. }
  869.  
  870. int risc_osclose(void)
  871. {
  872.         os_swi2(6,106,1);  /* reset pointer to number 1 */
  873.         return 0;
  874. }
  875.  
  876. int risc_oskopen(void)
  877. {
  878.         return 0;
  879. }
  880.  
  881. int risc_oskclose(void)
  882. {
  883.         return 0;
  884. }
  885.  
  886. int risc_osgetc()
  887. {
  888.         while (!in_any())
  889.         {
  890.                 if (need_to_redraw)
  891.                         uemacs_force_redraw();
  892.                 event_process();
  893.         }
  894.  
  895.         return in_pull();
  896. }
  897.  
  898. #if     TYPEAH
  899. int typahead(void)
  900. {
  901. #if 0
  902.         if (need_to_redraw || !in_any())
  903.         {
  904.                 if (need_to_redraw)
  905.                         uemacs_force_redraw();
  906.                 event_process();
  907.         }
  908. #else
  909.         if (!in_any())
  910.                 event_process();
  911. #endif
  912.         return in_any();
  913. }
  914. #endif  /* TYPEAH */
  915.  
  916. int risc_osputc(int c)
  917. {
  918.         if (c < 0x20)
  919.         {
  920.                 switch (c) {
  921.                         case 8:
  922.                                 if (ue_xpos != 0)
  923.                                         ue_xpos--;
  924.                                 break;
  925.                         case 9:
  926.                                 if (ue_xpos != NCOL-1)
  927.                                         ue_xpos++;
  928.                                 break;
  929.                         case 10:
  930.                                 if (ue_ypos != NROW-1)
  931.                                         ue_ypos++;
  932.                                 break;
  933.                         case 11:
  934.                                 if (ue_ypos != 0)
  935.                                         ue_ypos--;
  936.                                 break;
  937.                         case 12:
  938.                                 ue_xpos = ue_ypos = 0;
  939.                                 risc_oseeop();
  940.                                 break;
  941.                         case 30:
  942.                                 ue_xpos = ue_ypos =0;
  943.                                 break;
  944.                         default:
  945.                                 break;
  946.                 }
  947.         }
  948.         else
  949.         { 
  950.                 if (c == 0x7f)
  951.                 {
  952.                         sb[ue_ypos][--ue_xpos] = 32;
  953.                 }
  954.          
  955.                 if (rb.x0 > ue_xpos)
  956.                         rb.x0 = ue_xpos;
  957.                 if (rb.x1 < ue_xpos)
  958.                         rb.x1 = ue_xpos;
  959.                 if (rb.y0 > ue_ypos)
  960.                         rb.y0 = ue_ypos;
  961.                 if (rb.y1 < ue_ypos)
  962.                         rb.y1 = ue_ypos;
  963.  
  964.                 
  965.                 attribs[ue_ypos][ue_xpos]=attrib_byte;
  966.                 
  967.  
  968.                 if (c != 127)
  969.                 {
  970.                         sb[ue_ypos][ue_xpos++] = c;
  971.                 }
  972.  
  973.                 need_to_redraw = TRUE;
  974.         }
  975.  
  976.         return 0;
  977. }
  978.  
  979. #if      FLABEL
  980. fnclabel(f, n)                  /* label a function key */
  981. int f,n;                        /* default flag, numeric argument [unused] */
  982. {
  983.         /* on machines with no function keys...don't bother */
  984.         return(TRUE);
  985.  
  986.  
  987.  
  988. #endif
  989.  
  990. #else
  991. void risc_oshello(void)
  992. {
  993. }
  994.  
  995. #endif
  996.