/*
 *	Perlin Production Co. Ltd. September 1993 (c).
 *			GRAB4.C
 */

#include "stdio.h"
#include "wios.h"
#include "conio.h"
#include "grab.h"

#define	SELECTOR	(& selw)
#define SOPT_NUM	5
#define	PANELS		(& selp)
#define INFO		(& iset)
#define	BYE		(& bwin)
#define	SAV_MODE	(& smod)

int	select_panels()
{
	WINDOW	selw,selp;
	char	*sopt[SOPT_NUM];
	char	*popt[NPANELS];
	int 	i;
	char	code,choice;
	int	ivalue,sav_form;

	cls();
	for (i=0 ; i < NPANELS ; i++) p_enabled[i]=TRUE;

	sopt[0]=" Enable panel ";
	sopt[1]=" Disable panel ";
	sopt[2]=" sprite Format ";
	sopt[3]=" Save sprite ";
	sopt[4]=" eXit to CP/M ";
	popt[0]="8000H - 9FFFH";
	popt[1]="A000H - BFFFH";
	popt[2]="C000H - DFFFH";
	popt[3]="E000H - FFFFH";

	defs_wn(0,0,MAXX,3,D_BORD,SELECTOR);
	sw_shadow(NO_SHADOW,SELECTOR);
	sw_fill(SHADOW3,SELECTOR);
	sw_margin(1,1,SELECTOR);
	sm_options("EDFSX",sopt,SELECTOR,0);

	defs_wn(20,6,21,6,D_BORD,PANELS);
	sw_margin(3,3,PANELS);
	sm_options("8ACE",popt,PANELS,0);

	current_setting(sav_form=AS_BITMAP);
	set_wn(SELECTOR);
	while((code=menu_bar(SELECTOR)) != 3)
	{
		switch (code)
		{
		case 0:
			sw_name("Enable PANEL",PANELS);
			set_wn(PANELS);
			choice=menu(PANELS);
			if (choice >=0) p_enabled[choice]=TRUE;
			unset_wn(PANELS,BLANK,NORM_VID);
			break;
		case 1:
			sw_name("Disable PANEL",PANELS);
			set_wn(PANELS);
			choice=menu(PANELS);
			if (choice >=0) p_enabled[choice]=FALSE;
			unset_wn(PANELS,BLANK,NORM_VID);
			break;
		case 2:
			ivalue=save_format();
			if (ivalue > 0) sav_form=ivalue;
			break;
		case 4: bye_bye();
		}
		current_setting(sav_form);
	}
	return (sav_form);	
}



int	save_format()
{
	WINDOW	smod;
	char	*sfopt[5],*hotkeys;
	int	choice;

	sfopt[0]="Main    menu";
	sfopt[1]="Bitmap table";
	sfopt[2]="Pixel  array";
	sfopt[3]="Sprite bytes";
	sfopt[4]="Word  bitmap";

	hotkeys = evenHght ? "MBPSW" : "MBPS";

	defs_wn(40,3,21,strlen(hotkeys)+2,D_BORD,SAV_MODE);
	sw_name("Sprite format: ",SAV_MODE);
	sm_options(hotkeys,sfopt,SAV_MODE,0);
	set_wn(SAV_MODE);
	choice=menu(SAV_MODE);
	unset_wn(SAV_MODE,BLANK,NORM_VID);
	return(choice);
}


pnl_stat(_caption,_wnd)
char	*_caption;
WINDOW	*_wnd;
{
	int	i,pos;

	sw_name(_caption,_wnd);
 	set_wn(_wnd);
 	mv_csr(0,1,_wnd);
 	w_puts(
	"8000-9FFF:         A000-BFFF:         C000-DFFF:         E000-FFFF:",
	_wnd);
	pos=10;
	for (i=0 ; i < NPANELS ; ++i)
	{
		mv_csr(pos,1,_wnd);
		w_puts( ((p_enabled[i] !=0) ? "ENABLED":"DISABLED"),_wnd);
		pos += 19;
 	}
}


current_setting(mode)
int	mode;
{
	WINDOW	iset;

	def_wn(0,19,MAXX,23,S_BORD,INFO);
	sw_shadow(NO_SHADOW,INFO);
	switch(mode)
	{
	case AS_BITMAP:
	 pnl_stat("Panel status for BITMAP save mode:",INFO);
	 break;
	case AS_SPRITE:
	 pnl_stat("Panel status for SPRITE save mode:",INFO);
	 break;
	case AS_WBITMAP:
	 pnl_stat("Panel status for WORD BITMAP save mode:",INFO);
	 break; 
	case AS_PIXELS:
	 sw_name("Panels status for PIXEL_ARRAY save mode:",INFO);
	 set_wn(INFO);
	 w_puts(
"All panels are ENABLED in this mode.Any byte of the output sprite will\n",
	 INFO);
	 w_puts(
"contain information about 2 video pixels: 4 higher bits - even pixel.\n",
	 INFO);
	 w_puts(
"Switch to a BITMAP save mode in a sprite FORMAT menu to cut some panels.",
	 INFO);
	 break;
	}
}
