home *** CD-ROM | disk | FTP | other *** search
- /* Title: -> $.!hp11.amiga.c.arc_events
- *
- */
-
- #define TRACE 1
-
- #include "wimp.h"
- #include "wimpt.h"
- #include "win.h"
- #include "event.h"
- #include "menu.h"
- #include "template.h"
- #include "dbox.h"
- #include "werr.h"
- #include "flex.h"
- #include "trace.h"
-
- #include "types.h"
- #include "hp11.h"
- #include "ami_amiga.h"
- #include "ins.h"
-
- #include <math.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- /*---------------------------------------------------------------------------*/
- /*================ CONSTANTS ==============*/
- /*---------------------------------------------------------------------------*/
- /* Menu items */
- #define hp11_menu_info 1
- #define hp11_menu_load 2
- #define hp11_menu_quit 3
-
- #define hp11_popup_radix 1
- #define hp11_popup_speed 2
- #define hp11_popup_stack 3
- #define hp11_popup_save 4
-
- /* Info box field for the version string */
- #define hp11_info_field 4
-
-
- /******************************** GLOBAL DATA *******************************/
- struct Regs hp11r;
- int running, fast, error, skip;
- int PC, retStack[MAXSTACK], retCnt;
- int Flags;
-
- int quit, on = TRUE; /* Set to false to quit */
-
- extern wimp_w hp11_win_handle;
- extern dbox hp11_dbox_handle;
- extern dbox hp11_stack_dbox_handle;
- extern BOOL hp11_window_open;
-
- /* Application version */
- static char *hp11_Version_String = "0.3 (10 March 1990)";
-
- /* The top of the menu tree */
- static menu hp11_menu;
-
- static BOOL hp11_show_stack = FALSE;
-
- /****************************** EVENT HANDLERS *******************************/
- BOOL hp11_dbox_raw_handler(dbox hp11_d, void *ev, void *handle)
- {
- wimp_eventstr *event;
-
- event = (wimp_eventstr *)ev;
- if (running)
- {
- if(event->e == wimp_ENULL)
- {
- /* respond to idle event by running one cycle of program */
- if (!fast) WaitSync(2L); /* Slow calculator down to make it
- more realistic (wait 2/50 s) */
- ExecIns(Prog[PC]); /* Exec current ins */
- if (error || overflow)
- {
- running = FALSE; /* An error occured, halt */
- }
- else
- {
- if (skip) PC++; /* A conditional instruction asked for the next
- instruction to be skipped */
- PC++;
- while (PC > lastIns) /* There is an implicit return at the
- { end of the program */
- RTN();
- PC++;
- }
- }
- return (TRUE);
- }
- /* this point would be reached by trying a file transfer while running */
- }
- else
- return (FALSE); /* this will later include file transfer actions */
- }
-
- void hp11_dbox_handler(dbox hp11_d, void *handle)
- {
- WORD code;
- enum KeyTypes type;
- dbox_field i;
- handle = handle; /* stops compiler warning about non-use of handle */
-
- /* respond to each type of calculator key click (reference by key-code) */
- i = dbox_get(hp11_d);
- if (i < 36) code = (WORD)(i-1);
-
- error = FALSE; overflow = FALSE;
-
- if (running) /* Run mode */
- {
- /* running = FALSE; */ /* User pressed a key */
- /* win_claim_idle_events(-1); */ /* release idle event trapping */
- /* Should wait for him to release it */
- }
- else /* normal mode operation */
- {
- type = ReadKey(&code);
- switch (type) /* Read an instruction/action */
- {
- case Action:
- ExecAction(code); /* Execute corresponding action */
- break;
- case Instruction:
- ExecIns(code); /* Interpret instruction */
- break;
- }
- }
- Disp();
- }
-
- /*--- Display the program info box - called from the menu processor. ---*/
- static void hp11_info_about_program(void)
- {
- dbox d; /* Dialogue box handle */
-
- /* Create the dialogue box */
- if (d = dbox_new("ProgInfo"), d != NULL)
- {
- /* Fill in the version number */
- dbox_setfield(d, hp11_info_field, hp11_Version_String);
-
- /* Show the dialogue box */
- dbox_show(d);
-
- /* Keep it on the screen as long as needed */
- dbox_fillin(d);
-
- /* Dispose of the dialogue box */
- dbox_dispose(&d);
- }
- }
-
- /*--- Event handler for the menu. ---*/
- static void hp11_menuproc(void *handle, char *hit)
- {
- handle = handle; /* We don't need handle: this stops compiler warning */
-
- /* Find which menu item was hit and take action as appropriate */
- switch (hit[0])
- {
- case hp11_menu_info:
- hp11_info_about_program();
- break;
-
- case hp11_menu_load:
- break;
-
- case hp11_menu_quit:
- /* Exit from the program. The wimp gets rid of the window and icon */
- exit(0);
- }
- }
-
- /*--- Event handler for the pop-up menu. ---*/
- static void hp11_popup_proc(void *handle, char *hit)
- {
- handle = handle; /* We don't need handle: this stops compiler warning */
-
- /* Find which menu item was hit and take action as appropriate */
- switch (hit[0])
- {
- case hp11_popup_radix:
- break;
-
- case hp11_popup_speed:
- break;
-
- case hp11_popup_stack:
- if (hp11_show_stack)
- {
- menu_setflags(hp11_menu, hp11_popup_stack, 0, 0);
- hp11_show_stack = FALSE;
- dbox_hide(hp11_stack_dbox_handle);
- }
- else
- {
- menu_setflags(hp11_menu, hp11_popup_stack, 1, 0);
- hp11_show_stack = TRUE;
- dbox_showstatic(hp11_stack_dbox_handle);
- }
- break;
-
- case hp11_popup_save:
- break;
-
- }
- }
-
-
- /*--- Event handler called on a left click on the icon. ---*/
- static void hp11_iconclick(wimp_i icon)
- {
- /* BOOL hp11_dbox_raw_handler(dbox, void*, void*); */
- void hp11_dbox_handler(dbox, void*);
-
- icon = icon; /* We don't need the handle: this stops compiler warning */
-
- /* Open the window - only one allowed */
- if (!hp11_window_open)
- {
- dbox_showstatic(hp11_dbox_handle);
- /* dbox_raweventhandler(hp11_dbox_handle, hp11_dbox_raw_handler, 0); */
- dbox_eventhandler(hp11_dbox_handle, hp11_dbox_handler, &hp11_win_handle);
- hp11_window_open = TRUE;
- if (hp11_show_stack)
- {
- dbox_showstatic(hp11_stack_dbox_handle);
- }
- }
- }
-
-