/*****************************************************************************
;  :Module.	wincpu.c
;  :Author.	Bert Jahn
;  :Address.	Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
;  :Version.	$Id: wincpu.c 0.6 2002/02/19 21:15:21 wepl Exp wepl $
;  :History.	18.07.98 started
;		03.03.00 bubble help added to all fields
;			 some cleanup
;		28.03.00 more cleanup
;  :Copyright.	All Rights Reserved
;  :Language.	C
;  :Translator.	GCC
****************************************************************************/

#include <libraries/mui.h>
#include <exec/execbase.h>

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

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

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

extern APTR			app,win;
extern struct whddump_header	*header;
extern struct whddump_cpu	*cpu;
extern const char		*StringHexAccept;
extern struct Library		*MUIMasterBase;

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

APTR win_cpu = NULL;

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

void make_win_cpu(void) {
	ULONG open;
	APTR
		regmsp=0,
		regcaar=0,
		regcacr=0,
		regpcr=0,
		regbuscr=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:",
		*sfc_h="Source Function Code",
		*dfc_h="Destination Function Code",
		*vbr_h="Vector Base Register",
		*msp_h="Master Stack Pointer",
		*caar_h="Cache Address Register",
		*cacr_h="Cache Control Register",
		*tc_h="Translation Control (MMU)",
		*crp_h="CPU Root Pointer (MMU)",
		*srp_h="Supervisor Root Pointer (MMU)",
		*urp_h="User Root Pointer (MMU)",
		*mmusr_h="MMU Status Register",
		*tt0_h="Transparent Translation 0",
		*tt1_h="Transparent Translation 1",
		*dtt0_h="Data Transparent Translation 0",
		*dtt1_h="Data Transparent Translation 1",
		*itt0_h="Instruction Transparent Translation 0",
		*itt1_h="Instruction Transparent Translation 1",
		*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',' '),
				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',' '),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68010", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Register(sfc,sfc_h,cpu->wdc_sfc),
						Register(dfc,dfc_h,cpu->wdc_dfc),
						Register(vbr,vbr_h,cpu->wdc_vbr),
						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',' '),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68020", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Register(sfc,sfc_h,cpu->wdc_sfc),
						Register(dfc,dfc_h,cpu->wdc_dfc),
						Register(vbr,vbr_h,cpu->wdc_vbr),
						RegisterC(regmsp,msp,msp_h,cpu->wdc_msp,8),
						RegisterC(regcaar,caar,caar_h,cpu->wdc_caar,8),
						RegisterC(regcacr,cacr,cacr_h,cpu->wdc_cacr,8),
						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',' '),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68030", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Register(sfc,sfc_h,cpu->wdc_sfc),
						Register(dfc,dfc_h,cpu->wdc_dfc),
						Register(vbr,vbr_h,cpu->wdc_vbr),
						RegisterC(regmsp,msp,msp_h,cpu->wdc_msp,8),
						RegisterC(regcaar,caar,caar_h,cpu->wdc_caar,8),
						RegisterC(regcacr,cacr,cacr_h,cpu->wdc_cacr,8),
						Register(tc,tc_h,cpu->wdc_tc),
						Register64(crp,crp_h,cpu->wdc_crp[0],cpu->wdc_crp[1]),
						Register64(srp,srp_h,cpu->wdc_srp[0],cpu->wdc_srp[1]),
						Register(mmusr,mmusr_h,cpu->wdc_mmusr),
						Register(tt0,tt0_h,cpu->wdc_tt0),
						Register(tt1,tt1_h,cpu->wdc_tt1),
						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',' '),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68040", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Register(sfc,sfc_h,cpu->wdc_sfc),
						Register(dfc,dfc_h,cpu->wdc_dfc),
						Register(vbr,vbr_h,cpu->wdc_vbr),
						RegisterC(regmsp,msp,msp_h,cpu->wdc_msp,8),
						RegisterC(regcacr,cacr,cacr_h,cpu->wdc_cacr,8),
						Register(tc,tc_h,cpu->wdc_tc),
						Register(srp,srp_h,cpu->wdc_srp[0]),
						Register(urp,urp_h,cpu->wdc_urp),
						Register(mmusr,mmusr_h,cpu->wdc_mmusr),
						Register(dtt0,dtt0_h,cpu->wdc_dtt0),
						Register(dtt1,dtt1_h,cpu->wdc_dtt1),
						Register(itt0,itt0_h,cpu->wdc_itt0),
						Register(itt1,itt1_h,cpu->wdc_itt1),
						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',' '),
				WindowContents, VGroup,
					Child, TextObject, GroupFrame, MUIA_Text_Contents, "\33cMC68060", End,
					Child, HGroup, MUIA_Group_Columns, 2,
						Register(sfc,sfc_h,cpu->wdc_sfc),
						Register(dfc,dfc_h,cpu->wdc_dfc),
						Register(vbr,vbr_h,cpu->wdc_vbr),
						RegisterC(regcacr,cacr,cacr_h,cpu->wdc_cacr,8),
						RegisterC(regpcr,"PCR:","Processor Configuration Register",cpu->wdc_pcr,8),
						RegisterC(regbuscr,"BUSCR:","Bus Control Register",cpu->wdc_buscr,8),
						Register(tc,tc_h,cpu->wdc_tc),
						Register(srp,srp_h,cpu->wdc_srp[0]),
						Register(urp,urp_h,cpu->wdc_urp),
						Register(dtt0,dtt0_h,cpu->wdc_dtt0),
						Register(dtt1,dtt1_h,cpu->wdc_dtt1),
						Register(itt0,itt0_h,cpu->wdc_itt0),
						Register(itt1,itt1_h,cpu->wdc_itt1),
						End,
					End,
				End;
			break;
		}
		if (win_cpu) {
			DoMethod(app,OM_ADDMEMBER,win_cpu);
			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.");
		}
	}
}

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

