OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [nanox/] [mazenx.c] - Rev 1782

Compare with Previous | Blame | View Log

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"
#include "maze.h"
 
GR_WINDOW_ID wid;
GR_GC_ID gc;
GR_COORD x, y, h, w;
 
 /*
 * Print utility
 *      __print(const char *fmt, ...)
 */
void _print(const char *fmt, ...)
{
  va_list args;
  va_start(args, fmt);
  __asm__ __volatile__ ("  l.addi\tr3,%0,0\n \
                           l.addi\tr4,%1,0\n \
                           l.nop 3": : "r" (fmt), "r"  (args));
}
 
void event_handler (GR_EVENT *event)
{
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  switch (event->type)
    {
#if 0
    case GR_EVENT_TYPE_EXPOSURE:
      {
        char tmp[40];
        sprintf (tmp, "x = %i, y = %i, h = %i, w = %i", x, y, h, w);
        GrText (wid, gc, 50, 50, tmp, -1, GR_TFASCII);
      }
      break;
    case GR_EVENT_TYPE_UPDATE:
      {
        GR_WINDOW_INFO wi;
        GR_EVENT_UPDATE *upd = (GR_EVENT_UPDATE *) event;
        GrGetWindowInfo (wid, &wi);
        GrGetWindowInfo (wi.parent, &wi);
        x = upd->x + wi.x;
        y = upd->y + wi.y;
        h = upd->height;
        w = upd->width;
        printf ("x = %i, y = %i, h = %i, w = %i\n", x, y, h, w);
        /*GrResizeWindow(wid, WINDOW_WIDTH, WINDOW_HEIGHT);*/
      }
      break;
#endif
    case GR_EVENT_TYPE_CLOSE_REQ:
      GrClose();
      exit (0);
    }
}
 
int main (void)
{
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  if (GrOpen() < 0)
    {
      fprintf (stderr, "GrOpen failed");
      exit (1);
    }
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  gc = GrNewGC();
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  GrSetGCUseBackground (gc, GR_FALSE);
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  GrSetGCForeground (gc, RED);
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  wid = GrNewWindowEx (GR_WM_PROPS_APPFRAME |
                       GR_WM_PROPS_CAPTION |
                       GR_WM_PROPS_CLOSEBOX |
                       /*GR_WM_PROP_NORESIZE |
                       GR_WM_PROP_NOICONISE |
                       GR_WM_PROP_NOWINMENU |
                       GR_WM_PROP_ONTOP |*/
                       GR_WM_PROPS_NOAUTORESIZE,
                       "Maze",
                       GR_ROOT_WINDOW_ID,
                       50, 50, WINDOW_WIDTH, WINDOW_HEIGHT, WHITE);
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  GrSelectEvents (wid, GR_EVENT_MASK_EXPOSURE |
                       GR_EVENT_MASK_UPDATE |
		       GR_EVENT_MASK_TIMEOUT |
                       GR_EVENT_MASK_CLOSE_REQ);
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  GrMapWindow (wid);
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  init_maze ();
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  while (1) {
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
    GR_EVENT event;
    GrGetNextEventTimeout(&event, 1L); /* 500L */
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
    if (event.type == GR_EVENT_TYPE_TIMEOUT) do_clock ();
    else event_handler(&event);
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
  }
  return 0;
}
 
void wait_sync ()
{
}
 
 
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.