 #include <X11/Xlib.h> // Every Xlib program must include this
 #include <assert.h>   // To test return values the lazy way
 #include <unistd.h>

 #define NIL (0)       // A name for the void pointer

 Window w;
 GC gc;
 XEvent e;
 int blackColor,whiteColor,k;
 Display *dpy;





 int putpixel(int i,int j,int k)
 {
  if(j > YREF + YLIM)
	return(0);
  XSetForeground(dpy, gc, whiteColor/k );
  XDrawPoint(dpy,w,gc,i,j);
  XFlush(dpy);
  return(0);
 }   



 int initgraph(int *ptra, int *ptrb, char *cptr)
 {
  dpy = XOpenDisplay(NIL);
  assert(dpy);
  blackColor = BlackPixel(dpy, DefaultScreen(dpy));
  whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
  w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
  400, 200, 0, blackColor, blackColor);
  XSelectInput(dpy, w, StructureNotifyMask);
  XMapWindow(dpy, w);  
  gc = XCreateGC(dpy, w, 0, NIL);
  XSetForeground(dpy, gc, whiteColor);
  XSetBackground(dpy, gc, whiteColor);
  for(;;) {
	XNextEvent(dpy, &e);
	if (e.type == MapNotify)	break;
  }       
  draw_sheet();
  return(0);
 }

 int draw_sheet(void)
 {
  int x,y;
  int flag;
  for(x = XREF;x <= XREF + XLIM;x++) {
	putpix(x, YREF + 1, 3);
	if(x <= YLIM)
		putpix(XREF, YREF - x + XREF, 3);
	flag = (x - XREF) % 0x10;
	if( flag < 4 ) {
		for(y = YREF + 1;y < YREF + 10;y++) {
			if(x < 160)
				putpix(XREF - y + YREF, YREF - x + XREF, 3);
			putpix(x, y, 3);
		}
	}
  }
  return(0);
 }



 int putpix(int i,int j,int k)
 {
  k = 2;
  XSetForeground(dpy, gc, whiteColor/k );
  XDrawPoint(dpy,w,gc,i,j);
  XFlush(dpy);
  return(0);
 }   



 int closegraph(void)
 {
  system("clear;echo Thanks for using the simulator");
  return(0);
 } 

