home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / h / hp11 / Amiga_Code / c / arc_events < prev    next >
Encoding:
Text File  |  1992-05-07  |  6.1 KB  |  239 lines

  1. /* Title:   ->  $.!hp11.amiga.c.arc_events
  2.  *
  3.  */
  4.  
  5. #define TRACE 1
  6.  
  7. #include "wimp.h"
  8. #include "wimpt.h"
  9. #include "win.h"
  10. #include "event.h"
  11. #include "menu.h"
  12. #include "template.h"
  13. #include "dbox.h"
  14. #include "werr.h"
  15. #include "flex.h"
  16. #include "trace.h"
  17.  
  18. #include "types.h"
  19. #include "hp11.h"
  20. #include "ami_amiga.h"
  21. #include "ins.h"
  22.  
  23. #include <math.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27.  
  28. /*---------------------------------------------------------------------------*/
  29. /*================                 CONSTANTS                   ==============*/
  30. /*---------------------------------------------------------------------------*/
  31. /* Menu items */
  32. #define hp11_menu_info     1
  33. #define hp11_menu_load     2
  34. #define hp11_menu_quit     3
  35.  
  36. #define hp11_popup_radix   1
  37. #define hp11_popup_speed   2
  38. #define hp11_popup_stack   3
  39. #define hp11_popup_save    4
  40.  
  41. /* Info box field for the version string */
  42. #define hp11_info_field    4
  43.  
  44.  
  45. /******************************** GLOBAL DATA *******************************/
  46. struct Regs hp11r;
  47. int running, fast, error, skip;
  48. int PC, retStack[MAXSTACK], retCnt;
  49. int Flags;
  50.  
  51. int quit, on = TRUE; /* Set to false to quit */
  52.  
  53. extern wimp_w  hp11_win_handle;
  54. extern dbox    hp11_dbox_handle;
  55. extern dbox    hp11_stack_dbox_handle;
  56. extern BOOL    hp11_window_open;
  57.  
  58. /* Application version */
  59. static char *hp11_Version_String = "0.3 (10 March 1990)";
  60.  
  61. /* The top of the menu tree */
  62. static menu hp11_menu;
  63.  
  64. static BOOL hp11_show_stack  = FALSE;
  65.  
  66. /****************************** EVENT HANDLERS *******************************/
  67. BOOL hp11_dbox_raw_handler(dbox hp11_d, void *ev, void *handle)
  68.   {                                        
  69.   wimp_eventstr *event;
  70.  
  71.   event = (wimp_eventstr *)ev;
  72.   if (running)
  73.     {                                      
  74.     if(event->e == wimp_ENULL)
  75.       {
  76.       /* respond to idle event by running one cycle of program */
  77.       if (!fast) WaitSync(2L); /* Slow calculator down to make it 
  78.                                 more realistic (wait 2/50 s) */
  79.       ExecIns(Prog[PC]); /* Exec current ins */
  80.       if (error || overflow) 
  81.         {
  82.         running = FALSE;            /* An error occured, halt */
  83.         } 
  84.       else
  85.         { 
  86.         if (skip) PC++; /* A conditional instruction asked for the next
  87.                            instruction to be skipped */
  88.         PC++;
  89.         while (PC > lastIns)  /* There is an implicit return at the 
  90.           {                      end of the program */  
  91.           RTN();
  92.           PC++;
  93.           }
  94.         }
  95.       return (TRUE);
  96.       } 
  97.     /* this point would be reached by trying a file transfer while running */
  98.     }  
  99.   else
  100.     return (FALSE);    /* this will later include file transfer actions */
  101.   }
  102.  
  103. void hp11_dbox_handler(dbox hp11_d, void *handle)
  104.   {
  105.   WORD code;
  106.   enum KeyTypes type;
  107.   dbox_field i;
  108.   handle = handle;  /* stops compiler warning about non-use of handle */
  109.  
  110.   /* respond to each type of calculator key click (reference by key-code) */
  111.   i = dbox_get(hp11_d);
  112.   if (i < 36) code = (WORD)(i-1);
  113.  
  114.   error = FALSE; overflow = FALSE;
  115.  
  116.   if (running)                   /* Run mode */
  117.     {
  118. /*      running = FALSE; */             /* User pressed a key */
  119. /*      win_claim_idle_events(-1); */   /* release idle event trapping */
  120.                                         /* Should wait for him to release it */
  121.     }
  122.   else  /* normal mode operation */
  123.     {
  124.     type = ReadKey(&code);
  125.     switch (type)                       /* Read an instruction/action */
  126.       {
  127.       case Action:
  128.         ExecAction(code);               /* Execute corresponding action */
  129.         break;
  130.       case Instruction:
  131.         ExecIns(code);                  /* Interpret instruction */
  132.         break;
  133.       }
  134.     }
  135.   Disp();
  136.   }
  137.  
  138. /*--- Display the program info box - called from the menu processor. ---*/
  139. static void hp11_info_about_program(void)
  140. {
  141.   dbox  d;  /* Dialogue box handle */
  142.  
  143.   /* Create the dialogue box */
  144.   if (d = dbox_new("ProgInfo"), d != NULL)
  145.   {
  146.     /* Fill in the version number */
  147.     dbox_setfield(d, hp11_info_field, hp11_Version_String);
  148.  
  149.     /* Show the dialogue box */
  150.     dbox_show(d);
  151.  
  152.     /* Keep it on the screen as long as needed */
  153.     dbox_fillin(d);
  154.  
  155.     /* Dispose of the dialogue box */
  156.     dbox_dispose(&d);
  157.   }
  158. }
  159.  
  160. /*--- Event handler for the menu. ---*/
  161. static void hp11_menuproc(void *handle, char *hit)
  162. {
  163.   handle = handle; /* We don't need handle: this stops compiler warning */
  164.  
  165.   /* Find which menu item was hit and take action as appropriate */
  166.   switch (hit[0])
  167.   {
  168.     case hp11_menu_info:
  169.       hp11_info_about_program();
  170.       break;
  171.  
  172.     case hp11_menu_load:
  173.       break;
  174.  
  175.     case hp11_menu_quit:
  176.       /* Exit from the program. The wimp gets rid of the window and icon */
  177.       exit(0);
  178.   }
  179. }
  180.  
  181. /*--- Event handler for the pop-up menu. ---*/
  182. static void hp11_popup_proc(void *handle, char *hit)
  183. {
  184.   handle = handle; /* We don't need handle: this stops compiler warning */
  185.  
  186.   /* Find which menu item was hit and take action as appropriate */
  187.   switch (hit[0])
  188.   {
  189.     case hp11_popup_radix:
  190.       break;
  191.  
  192.     case hp11_popup_speed:
  193.       break;
  194.  
  195.     case hp11_popup_stack:
  196.       if (hp11_show_stack)
  197.         {
  198.         menu_setflags(hp11_menu, hp11_popup_stack, 0, 0);
  199.         hp11_show_stack = FALSE;
  200.         dbox_hide(hp11_stack_dbox_handle);
  201.         }
  202.       else
  203.         {
  204.         menu_setflags(hp11_menu, hp11_popup_stack, 1, 0);
  205.         hp11_show_stack = TRUE;
  206.         dbox_showstatic(hp11_stack_dbox_handle);
  207.         }
  208.       break;
  209.  
  210.     case hp11_popup_save:
  211.       break;
  212.  
  213.   }
  214. }
  215.  
  216.  
  217. /*--- Event handler called on a left click on the icon. ---*/
  218. static void hp11_iconclick(wimp_i icon)
  219.   {
  220. /*  BOOL hp11_dbox_raw_handler(dbox, void*, void*); */
  221.   void hp11_dbox_handler(dbox, void*);
  222.  
  223.   icon = icon; /* We don't need the handle: this stops compiler warning */
  224.  
  225.   /* Open the window - only one allowed */
  226.   if (!hp11_window_open)
  227.     {
  228.     dbox_showstatic(hp11_dbox_handle);
  229. /*    dbox_raweventhandler(hp11_dbox_handle, hp11_dbox_raw_handler, 0);  */
  230.     dbox_eventhandler(hp11_dbox_handle, hp11_dbox_handler, &hp11_win_handle);
  231.     hp11_window_open = TRUE;
  232.     if (hp11_show_stack)
  233.       {
  234.       dbox_showstatic(hp11_stack_dbox_handle);
  235.       }
  236.     }
  237.   }
  238.  
  239.