/*****************************************************************************
;  :Module.		wincpu.c
;  :Author.		Bert Jahn
;  :EMail.		jah@fh-zwickau.de
;  :Address.	Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
;  :Version.	$Id: wincpu.c 0.1 1998/08/06 23:13:50 jah Exp $
;  :History.	18.07.98 started
;  :Copyright.	All Rights Reserved
;  :Language.	C
;  :Tabsize.	4
;  :Translator.	SAS 6.58
****************************************************************************/

#include <exec/execbase.h>

#include <clib/alib_protos.h>
#include <clib/muimaster_protos.h>

#include <pragmas/muimaster_pragmas.h>

#include "whddump.h"
#include "WHDLoadGCI.h"

/****************************************************************************/

extern APTR						app,win;
extern APTR						regmsp,regcacr,regpcr,regbuscr;
extern struct whddump_header	*header;
extern struct whddump_cpu		*cpu;
extern struct NewMenu			MenuData1[];
extern const char				*StringHexAccept;
extern struct Library			*MUIMasterBase;

/****************************************************************************/

APTR win_cpu = NULL;

/****************************************************************************/

void make_win_cpu(void) {
	ULONG open;
	APTR strip_cpu;
	APTR
		regsfc=0,regdfc=0,regvbr=0,regcaar=0,regtt0=0,regtt1=0,regdtt0=0,regdtt1=0,
		regitt0=0,regitt1=0,regcrp=0,regsrp=0,regurp=0,regtc=0,regmmusr=0;
	const char
		sfc[]="SFC:",dfc[]="DFC:",vbr[]="VBR:",msp[]="MSP:",caar[]="CAAR:",cacr[]="CACR:",tc[]="TC:",crp[]="CRP:",srp[]="SRP:",
		urp[]="URP:",mmusr[]="MMUSR:",tt0[]="TT0:",tt1[]="TT1:",dtt0[]="DTT0:",dtt1[]="DTT1:",itt0[]="ITT0:",itt1[]="ITT1:";
	static const char t_morecpu[]="More CPU";

	if (win_cpu) {
		get(win_cpu,MUIA_Window_Open,&open);
		if (open)	set(win_cpu,MUIA_Window_Open,FALSE);
		else		set(win_cpu,MUIA_Window_Open,TRUE);
	} else {
		switch ((header->wdh_CPU)&(AFF_68010|AFF_68020|AFF_68030|AFF_68040|AFF_68060)) {
		case 0:
			win_cpu = WindowObject,
				MUIA_Window_Title, t_morecpu,
				MUIA_Window_ID   , MAKE_ID('C','P','U',' '),
				MUIA_Window_Menustrip, strip_cpu = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
				WindowContents,
					TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68000", End,
				End;
			break;
		case AFF_68010:
			win_cpu = WindowObject,
				MUIA_Window_Title, t_morecpu,
				MUIA_Window_ID   , MAKE_ID('C','P','U',' '),
				MUIA_Window_Menustrip, strip_cpu = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68010", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Child, Label2(sfc),		Child, regsfc = TextObject, StringFrame, End,
						Child, Label2(dfc),		Child, regdfc = TextObject, StringFrame, End,
						Child, Label2(vbr),		Child, regvbr = TextObject, StringFrame, End,
						End,
					End,
				End;
			break;
		case AFF_68010|AFF_68020:
			win_cpu = WindowObject,
				MUIA_Window_Title, t_morecpu,
				MUIA_Window_ID   , MAKE_ID('C','P','U',' '),
				MUIA_Window_Menustrip, strip_cpu = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68020", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Child, Label2(sfc),		Child, regsfc = TextObject, StringFrame, End,
						Child, Label2(dfc),		Child, regdfc = TextObject, StringFrame, End,
						Child, Label2(vbr),		Child, regvbr = TextObject, StringFrame, End,
						Child, Label2(msp),		Child, regmsp = StringHex8,
						Child, Label2(cacr),	Child, regcacr = StringHex8,
						Child, Label2(cacr),	Child, regcacr = TextObject, StringFrame, End,
						End,
					End,
				End;
			break;
		case AFF_68010|AFF_68020|AFF_68030:
			win_cpu = WindowObject,
				MUIA_Window_Title, t_morecpu,
				MUIA_Window_ID   , MAKE_ID('C','P','U',' '),
				MUIA_Window_Menustrip, strip_cpu = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68030", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Child, Label2(sfc),		Child, regsfc = TextObject, StringFrame, End,
						Child, Label2(dfc),		Child, regdfc = TextObject, StringFrame, End,
						Child, Label2(vbr),		Child, regvbr = TextObject, StringFrame, End,
						Child, Label2(msp),		Child, regmsp = StringHex8,
						Child, Label2(caar),	Child, regcaar = TextObject, StringFrame, End,
						Child, Label2(cacr),	Child, regcacr = StringHex8,
						Child, Label2(tc),		Child, regtc = TextObject, StringFrame, End,
						Child, Label2(crp),		Child, regcrp = TextObject, StringFrame, End,
						Child, Label2(srp),		Child, regsrp = TextObject, StringFrame, End,
						Child, Label2(mmusr),	Child, regmmusr = TextObject, StringFrame, End,
						Child, Label2(tt0),		Child, regtt0 = TextObject, StringFrame, End,
						Child, Label2(tt1),		Child, regtt1 = TextObject, StringFrame, End,
						End,
					End,
				End;
			break;
		case AFF_68010|AFF_68020|AFF_68030|AFF_68040:
			win_cpu = WindowObject,
				MUIA_Window_Title, t_morecpu,
				MUIA_Window_ID   , MAKE_ID('C','P','U',' '),
				MUIA_Window_Menustrip, strip_cpu = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68040", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Child, Label2(sfc),		Child, regsfc = TextObject, StringFrame, End,
						Child, Label2(dfc),		Child, regdfc = TextObject, StringFrame, End,
						Child, Label2(vbr),		Child, regvbr = TextObject, StringFrame, End,
						Child, Label2(msp),		Child, regmsp = StringHex8,
						Child, Label2(cacr),	Child, regcacr = StringHex8,
						Child, Label2(tc),		Child, regtc = TextObject, StringFrame, End,
						Child, Label2(srp),		Child, regsrp = TextObject, StringFrame, End,
						Child, Label2(urp),		Child, regurp = TextObject, StringFrame, End,
						Child, Label2(mmusr),	Child, regmmusr = TextObject, StringFrame, End,
						Child, Label2(dtt0),	Child, regdtt0 = TextObject, StringFrame, End,
						Child, Label2(dtt1),	Child, regdtt1 = TextObject, StringFrame, End,
						Child, Label2(itt0),	Child, regitt0 = TextObject, StringFrame, End,
						Child, Label2(itt1),	Child, regitt1 = TextObject, StringFrame, End,
						End,
					End,
				End;
			break;
		case AFF_68010|AFF_68020|AFF_68030|AFF_68040|AFF_68060:
			win_cpu = WindowObject,
				MUIA_Window_Title, t_morecpu,
				MUIA_Window_ID   , MAKE_ID('C','P','U',' '),
				MUIA_Window_Menustrip, strip_cpu = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68060", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Child, Label2(sfc),		Child, regsfc = TextObject, StringFrame, MUIA_ShortHelp, "Source Function Code", End,
						Child, Label2(dfc),		Child, regdfc = TextObject, StringFrame, End,
						Child, Label2(vbr),		Child, regvbr = TextObject, StringFrame, End,
						Child, Label2(cacr),	Child, regcacr = StringHex8,
						Child, Label2("PCR:"),	Child, regpcr = StringHex8,
						Child, Label2("BUSCR:"),Child, regbuscr = StringHex8,
						Child, Label2(tc),		Child, regtc = TextObject, StringFrame, End,
						Child, Label2(srp),		Child, regsrp = TextObject, StringFrame, End,
						Child, Label2(urp),		Child, regurp = TextObject, StringFrame, End,
						Child, Label2(dtt0),	Child, regdtt0 = TextObject, StringFrame, End,
						Child, Label2(dtt1),	Child, regdtt1 = TextObject, StringFrame, End,
						Child, Label2(itt0),	Child, regitt0 = TextObject, StringFrame, End,
						Child, Label2(itt1),	Child, regitt1 = TextObject, StringFrame, End,
						End,
					End,
				End;
			break;
		}
		if (win_cpu) {
			DoMethod(app,OM_ADDMEMBER,win_cpu);
			if (regsfc) sethex1t(regsfc,cpu->wdc_sfc);
			if (regdfc) sethex1t(regdfc,cpu->wdc_dfc);
			if (regvbr) sethex8t(regvbr,cpu->wdc_vbr);
			if (regmsp) sethex8(regmsp,cpu->wdc_msp);
			if (regcaar) sethex8(regcaar,cpu->wdc_caar);
			if (regcacr) sethex8(regcacr,cpu->wdc_cacr);
			if (regpcr) sethex8(regpcr,cpu->wdc_pcr);
			if (regbuscr) sethex8(regbuscr,cpu->wdc_buscr);
			if (regtc) sethex8t(regtc,cpu->wdc_tc);
			if (regcrp) sethex16t(regcrp,cpu->wdc_crp[0],cpu->wdc_crp[1]);
			switch ((header->wdh_CPU)&(AFF_68010|AFF_68020|AFF_68030|AFF_68040|AFF_68060)) {
			case AFF_68010|AFF_68020|AFF_68030:
				sethex16t(regsrp,cpu->wdc_srp[0],cpu->wdc_srp[1]);
				break;
			case AFF_68010|AFF_68020|AFF_68030|AFF_68040:
			case AFF_68010|AFF_68020|AFF_68030|AFF_68040|AFF_68060:
				sethex8t(regsrp,cpu->wdc_srp[0]);
				break;
			}
			if (regurp) sethex8t(regurp,cpu->wdc_urp);
			if (regmmusr) sethex8t(regmmusr,cpu->wdc_mmusr);
			if (regtt0) sethex8t(regtt0,cpu->wdc_tt0);
			if (regtt1) sethex8t(regtt1,cpu->wdc_tt1);
			if (regdtt0) sethex8t(regdtt0,cpu->wdc_dtt0);
			if (regdtt1) sethex8t(regdtt1,cpu->wdc_dtt1);
			if (regitt0) sethex8t(regitt0,cpu->wdc_itt0);
			if (regitt1) sethex8t(regitt1,cpu->wdc_itt1);
			DoMethod(win_cpu,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MAIN_MORECPU);
			set(win_cpu,MUIA_Window_Open,TRUE);
		} else {
			MUI_Request(app,win,0,NULL,"Ok","Couldn't open CPU window.");
		}
	}
}

/****************************************************************************/

