/* ------------------------------------------------------------------------ */
/*                                  demo.c                                  */
/*                       main demo of the SST toolkit                       */
/* ------------------------------------------------------------------------ */
#include <stdio.h>
#include <string.h>
#include <mem.h>
#include <stdlib.h>
#include <conio.h>
#include <alloc.h>

#include "sstvid.h"
#include "sstwin.h"
#define MAXWINS    1024


void wcolour(WINDOW *wnd,int a, int fg, int bg, int i);
void wtitle(WINDOW *wnd, char *s, int j);
void wborder(WINDOW *wnd);
void wshow(WINDOW *wnd);
void wwrite(WINDOW *wnd, unsigned int ram);
void main(void);

/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
void wcolour(WINDOW *wnd,int a, int fg, int bg, int i)

{
    Wsetcolour(wnd, a, fg, bg, i);
}

/* ------------------------------------------------------------------------ */
/*    */
/* ------------------------------------------------------------------------ */
void wtitle(WINDOW *wnd, char *s, int j)

{
  Wsettitle(wnd,s,j);
}

/* ------------------------------------------------------------------------ */
/*    */
/* ------------------------------------------------------------------------ */
void wborder(WINDOW *wnd)

{
   Wsetborder(wnd,BRD_SINGLE);
}

/* ------------------------------------------------------------------------ */
/*    */
/* ------------------------------------------------------------------------ */
void wshow(WINDOW *wnd)

{
    Wshow(wnd);
}

/* ------------------------------------------------------------------------ */
/*    */
/* ------------------------------------------------------------------------ */
void wwrite(WINDOW *wnd, unsigned int ram)

{
  Wprintf(wnd,"Core  = %u bytes\n",ram);
}

/* ------------------------------------------------------------------------ */
void main(void)
{
    int ctr = 0, l;
    unsigned int ram, wsize;
    unsigned int maxused;
    char s[13];
    WINDOW **wnd;

    for (l = 0 ; l < MAXWINS ; l++) {
	  ram = (unsigned) coreleft();
	  sprintf(s,"[Win %3d]",l);
	  wnd[l] = Westablish(0, 0, 25, 80);
	  if (ram < 8192)
		break;
	  wshow(wnd[l]);   /* show window first */
	  wcolour(wnd[l], WIN_ALL, CYAN, BLUE, BRIGHT);
	  wtitle(wnd[l],s,JUST_L);
	  wborder(wnd[l]);
	  wwrite(wnd[l],ram);
	  wsize = (unsigned)coreleft();
	  wsize = ram - wsize;
	  ctr++;
	  wsize = ram - (unsigned)coreleft();
    }
    Wdelete(wnd[l]);
    while(l--) {
	Wdelete(wnd[l]);
    }
  fprintf(stdout,"\nMaximum windows opened, limited by HEAP.\n");
  fprintf(stdout,"Memory allocated by window    = %d\n",wsize);
  fprintf(stdout,"Total Windows opened          = %d\n",ctr);
}



