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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [nanox/] [mazenx.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 770 simons
#include <stdio.h>
2
#include <stdarg.h>
3
#include <stdlib.h>
4
#define MWINCLUDECOLORS
5
#include "nano-X.h"
6
#include "maze.h"
7
 
8
GR_WINDOW_ID wid;
9
GR_GC_ID gc;
10
GR_COORD x, y, h, w;
11
 
12
 /*
13
 * Print utility
14
 *      __print(const char *fmt, ...)
15
 */
16
void _print(const char *fmt, ...)
17
{
18
  va_list args;
19
  va_start(args, fmt);
20
  __asm__ __volatile__ ("  l.addi\tr3,%0,0\n \
21
                           l.addi\tr4,%1,0\n \
22
                           l.nop 3": : "r" (fmt), "r"  (args));
23
}
24
 
25
void event_handler (GR_EVENT *event)
26
{
27
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
28
  switch (event->type)
29
    {
30
#if 0
31
    case GR_EVENT_TYPE_EXPOSURE:
32
      {
33
        char tmp[40];
34
        sprintf (tmp, "x = %i, y = %i, h = %i, w = %i", x, y, h, w);
35
        GrText (wid, gc, 50, 50, tmp, -1, GR_TFASCII);
36
      }
37
      break;
38
    case GR_EVENT_TYPE_UPDATE:
39
      {
40
        GR_WINDOW_INFO wi;
41
        GR_EVENT_UPDATE *upd = (GR_EVENT_UPDATE *) event;
42
        GrGetWindowInfo (wid, &wi);
43
        GrGetWindowInfo (wi.parent, &wi);
44
        x = upd->x + wi.x;
45
        y = upd->y + wi.y;
46
        h = upd->height;
47
        w = upd->width;
48
        printf ("x = %i, y = %i, h = %i, w = %i\n", x, y, h, w);
49
        /*GrResizeWindow(wid, WINDOW_WIDTH, WINDOW_HEIGHT);*/
50
      }
51
      break;
52
#endif
53
    case GR_EVENT_TYPE_CLOSE_REQ:
54
      GrClose();
55
      exit (0);
56
    }
57
}
58
 
59
int main (void)
60
{
61
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
62
  if (GrOpen() < 0)
63
    {
64
      fprintf (stderr, "GrOpen failed");
65
      exit (1);
66
    }
67
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
68
  gc = GrNewGC();
69
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
70
  GrSetGCUseBackground (gc, GR_FALSE);
71
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
72
  GrSetGCForeground (gc, RED);
73
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
74
  wid = GrNewWindowEx (GR_WM_PROPS_APPFRAME |
75
                       GR_WM_PROPS_CAPTION |
76
                       GR_WM_PROPS_CLOSEBOX |
77
                       /*GR_WM_PROP_NORESIZE |
78
                       GR_WM_PROP_NOICONISE |
79
                       GR_WM_PROP_NOWINMENU |
80
                       GR_WM_PROP_ONTOP |*/
81
                       GR_WM_PROPS_NOAUTORESIZE,
82
                       "Maze",
83
                       GR_ROOT_WINDOW_ID,
84
                       50, 50, WINDOW_WIDTH, WINDOW_HEIGHT, WHITE);
85
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
86
  GrSelectEvents (wid, GR_EVENT_MASK_EXPOSURE |
87
                       GR_EVENT_MASK_UPDATE |
88
                       GR_EVENT_MASK_TIMEOUT |
89
                       GR_EVENT_MASK_CLOSE_REQ);
90
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
91
  GrMapWindow (wid);
92
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
93
  init_maze ();
94
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
95
  while (1) {
96
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
97
    GR_EVENT event;
98
    GrGetNextEventTimeout(&event, 1L); /* 500L */
99
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
100
    if (event.type == GR_EVENT_TYPE_TIMEOUT) do_clock ();
101
    else event_handler(&event);
102
_print("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
103
  }
104
  return 0;
105
}
106
 
107
void wait_sync ()
108
{
109
}
110
 
111
 

powered by: WebSVN 2.1.0

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