;       SCCSID = @(#)debrcmd.asm	6.1 90/11/17
;      SCCSID = @(#)debrcmd.asm	13.6 90/05/23
PAGE	,132
NAME	DEBRCMD
TITLE	DEBRCMD - debugger modified and display registers commands
.286p

;***	DEBRCMD.ASM - debugger modified and display registers commands
;
;	This file contains the routines to display and modify the
;	debuggee's registers and flags.
;
;

.xlist
	include debseg.inc
	include debmac.inc
	include debequ.inc
	include debinit.inc
	include debdesc.inc
	include debprt.inc
.list

DataSegmentStart

Extern DebData,		WORD
Extern RegSA,		WORD
Extern pRegSA,		WORD
Extern DisAddr,		WORD
Extern opbuf,		BYTE
Extern fRegDisp,	BYTE
Extern pTXT,		WORD
Extern fTraceCount,	BYTE

;
;	Global register message strings
;

Extern AXmsg,	WORD
Extern EAXmsg,	WORD
Extern BXmsg,	WORD
Extern EBXmsg,	WORD
Extern CXmsg,	WORD
Extern ECXmsg,	WORD
Extern DXmsg,	WORD
Extern EDXmsg,	WORD
Extern SPmsg,	WORD
Extern ESPmsg,	WORD
Extern BPmsg,	WORD
Extern EBPmsg,	WORD
Extern SImsg,	WORD
Extern ESImsg,	WORD
Extern DImsg,	WORD
Extern EDImsg,	WORD
Extern CSmsg,	WORD
Extern DSmsg,	WORD
Extern ESmsg,	WORD
Extern SSmsg,	WORD
Extern IPmsg,	WORD
Extern EIPmsg,	WORD
Extern Fmsg,	WORD
Extern EFmsg,	WORD
Extern TRmsg,	WORD
Extern LDTRmsg, WORD
Extern IOPLmsg, WORD
Extern MSWmsg,	WORD
Extern GDTRmsg, WORD
Extern IDTRmsg, WORD
Extern GDTBmsg, WORD
Extern GDTLmsg, WORD
Extern IDTBmsg, WORD
Extern IDTLmsg, WORD
Extern CR0msg,	WORD
Extern CR2msg,	WORD
Extern CR3msg,	WORD
Extern CR4msg,	WORD		; 148688
Extern FSmsg,	WORD
Extern GSmsg,	WORD
Extern DR0msg,	WORD
Extern DR1msg,	WORD
Extern DR2msg,	WORD
Extern DR3msg,	WORD
Extern TR6msg,	WORD
Extern TR7msg,	WORD
Extern DR6msg,	WORD
Extern DR7msg,	WORD

Static PCmsg,	STRING, "PC"

;
;  Flag strings.
;

Static NTfmsg,	STRING,	"NT"
Static OVfmsg,	STRING,	"OV"
Static DNfmsg,	STRING,	"DN"
Static EIfmsg,	STRING,	"EI"
Static NGfmsg,	STRING,	"NG"
Static ZRfmsg,	STRING,	"ZR"
Static ACfmsg,	STRING,	"AC"
Static PEfmsg,	STRING,	"PE"
Static CYfmsg,	STRING,	"CY"
Static NVfmsg,	STRING,	"NV"
Static UPfmsg,	STRING,	"UP"
Static DIfmsg,	STRING,	"DI"
Static PLfmsg,	STRING,	"PL"
Static NZfmsg,	STRING,	"NZ"
Static NAfmsg,	STRING,	"NA"
Static POfmsg,	STRING,	"PO"
Static NCfmsg,	STRING,	"NC"
Static RFfmsg,	STRING,	"RF"
Static VMfmsg,	STRING,	"VM"
Static Min2msg,	STRING,	"--"

;
; MSW flag strings
;

Static PMfmsg,	STRING, "PM"
Static MPfmsg,	STRING, "MP"
Static EMfmsg,	STRING, "EM"
Static TSfmsg,	STRING, "TS"
Static Blankmsg,STRING, " "

;
; CR0 flag strings
;

Static PGfmsg,	STRING, "PG"
Static ETfmsg,	STRING, "ET"

;
;	Tables and strings for DR0-3 R/W and Len messages
;	  Note: Rmsg and Wmsg also used by TR6 print routine
;

Static RWmsgTbl, LABEL, WORD
	dw	dataOFFSET Emsg			; 0
	dw	dataOFFSET Wmsg			; 1
	dw	dataOFFSET Undmsg		; 2
	dw	dataOFFSET Rmsg			; 3

Static LnmsgTbl, LABEL, WORD
	dw	dataOFFSET Onemsg		; 0
	dw	dataOFFSET Twomsg		; 1
	dw	dataOFFSET Undmsg		; 2
	dw	dataOFFSET Fourmsg		; 3

Static Onemsg,		STRING,	"1"
Static Emsg,		STRING,	"E"
Static Twomsg,		STRING,	"2"
Static Rmsg,		STRING,	"R"
Static Undmsg,		STRING,	"U"
Static Fourmsg,		STRING,	"4"
Static Wmsg,		STRING,	"W"
Static Gfmsg,		STRING,	"G"
Static Minfmsg,		STRING,	"-"
Static Lfmsg,		STRING,	"L"
Static Bfmsg,		STRING,	"B"

;
;	TR6 flag field strings
;

Static Veqmsg,		STRING,	" V="
Static Deqmsg,		STRING,	" D="
Static Ueqmsg,		STRING,	" U="
Static Weqmsg,		STRING,	" W="
Static Ceqmsg,		STRING,	" C="

;
;	TR7 flag field strings
;

Static HTeqmsg,		STRING,	" HT="
Static RPeqmsg,		STRING,	" REP="

;
;	DR6 flag strings
;

Static BTfmsg,		STRING,	"BT"
Static BSfmsg,		STRING,	"BS"
Static BDfmsg,		STRING,	"BD"

;
;	DR7 flag strings
;

Static GEfmsg,		STRING,	"GE"
Static LEfmsg,		STRING,	"LE"

;
;	286 environment register display
;

Static	PrtRegs, LABEL, BYTE

	OutMsglc	AXmsg
	OutWordHexPtr	AXsav
	OutBlanks	2

	OutMsglc	BXmsg
	OutWordHexPtr	BXsav
	OutBlanks	2

	OutMsglc	CXmsg
	OutWordHexPtr	CXsav
	OutBlanks	2

	OutMsglc	DXmsg
	OutWordHexPtr	DXsav
	OutBlanks	2

	OutMsglc	SPmsg
	OutWordHexPtr	SPsav
	OutBlanks	2

	OutMsglc	BPmsg
	OutWordHexPtr	BPsav
	OutBlanks	2

	OutMsglc	SImsg
	OutWordHexPtr	SIsav
	OutBlanks	2

	OutMsglc	DImsg
	OutWordHexPtr	DIsav
	OutCrLf

	OutMsglc	IPmsg
	OutWordHexPtr	IPsav
	OutBlanks	2

	OutMsglc	CSmsg
	OutWordHexPtr	CSsav
	OutBlanks	2

	OutMsglc	DSmsg
	OutWordHexPtr	DSsav
	OutBlanks	2

	OutMsglc	ESmsg
	OutWordHexPtr	ESsav
	OutBlanks	2

	OutMsglc	SSmsg
	OutWordHexPtr	SSsav
	OutBlanks	2

	CallOp		PrtFlags, Fsav
	OutCrLf
	EndOp

Static	PrtRegs2, LABEL, BYTE

	OutMsglc	GDTRmsg
	Out24HexPtr	GDTsav.DTRBaseLow
	OutBlank
	OutWordHexPtr	GDTsav.DTRLimit
	OutBlanks	2

	OutMsglc	IDTRmsg
	Out24HexPtr	IDTsav.DTRBaseLow
	OutBlank
	OutWordHexPtr	IDTsav.DTRLimit
	OutBlanks	2

	OutMsglc	TRmsg
	OutWordHexPtr	TRsav
	OutBlanks	2

	OutMsglc	LDTRmsg
	OutWordHexPtr	LDTsav
	OutBlank

	OutMsglc	IOPLmsg
	OutBitFHexPtr	Fsav, 12, 2
	OutBlank

	CallOp		PrtMSW, MSWsav
	OutCrLf
	EndOp

;
;	Displays the terse registers dump
;

Static	PrtERegs, LABEL, BYTE

	OutMsglc	EAXmsg
	OutDwordHexPtr	EAXsav
	OutBlank

	OutMsglc	EBXmsg
	OutDwordHexPtr	EBXsav
	OutBlank

	OutMsglc	ECXmsg
	OutDwordHexPtr	ECXsav
	OutBlank

	OutMsglc	EDXmsg
	OutDwordHexPtr	EDXsav
	OutBlank

	OutMsglc	ESImsg
	OutDwordHexPtr	ESIsav
	OutBlank

	OutMsglc	EDImsg
	OutDwordHexPtr	EDIsav
	OutCrLf

	OutMsglc	EIPmsg
	OutDwordHexPtr	EIPsav
	OutBlank

	OutMsglc	ESPmsg
	OutDwordHexPtr	ESPsav
	OutBlank

	OutMsglc	EBPmsg
	OutDwordHexPtr	EBPsav
	OutBlank

	OutMsglc	IOPLmsg
	OutBitFHexPtr	Fsav, 12, 2
	OutBlank

	CallOp		PrtRFVM, EFsav		; Prints only RF/VM flags
	OutBlank
	CallOp		PrtFlags, Fsav
	OutCrLf

	OutMsglc	CSmsg
	OutWordHexPtr	CSsav
	OutBlank

	OutMsglc	SSmsg
	OutWordHexPtr	SSsav
	OutBlank

	OutMsglc	DSmsg
	OutWordHexPtr	DSsav
	OutBlank

	OutMsglc	ESmsg
	OutWordHexPtr	ESsav
	OutBlank

	OutMsglc	FSmsg
	OutWordHexPtr	FSsav
	OutBlank

	OutMsglc	GSmsg
	OutWordHexPtr	GSsav
	OutBlanks	2

	OutMsglc	CR2msg
	OutDwordHexPtr	CR2sav
	OutBlanks	2

	OutMsglc	CR3msg
	OutDwordHexPtr	CR3sav
	OutCrLf

	EndOp

;
;	Displays the non-terse registers
;

Static	PrtERegs2, LABEL, BYTE
	OutMsglc	GDTRmsg
	OutDwordHexPtr	GDTsav.DTRBaseLow
	OutBlank
	OutWordHexPtr	GDTsav.DTRLimit
	OutBlanks	2

	OutMsglc	IDTRmsg
	OutDwordHexPtr	IDTsav.DTRBaseLow
	OutBlank
	OutWordHexPtr	IDTsav.DTRLimit
	OutBlanks	2

	OutMsglc	TRmsg
	OutWordHexPtr	TRsav
	OutBlank

	OutMsglc	LDTRmsg
	OutWordHexPtr	LDTsav
	OutBlank

	CallOp		PrtCR0				; Print CR0 flags
	OutCrLf

	OutMsglc	DR0msg
	OutDwordHexPtr	DR0sav
	OutBlank
	CallOp		PrtDR0b, DR7sav			; DR7 flags (dr0)
	OutBlanks	2

	OutMsglc	DR1msg
	OutDwordHexPtr	DR1sav
	OutBlank
	CallOp		PrtDR1b, DR7sav			; DR7 flags (dr1)
	OutBlanks	2

	OutMsglc	DR2msg
	OutDwordHexPtr	DR2sav
	OutBlank
	CallOp		PrtDR2b, DR7sav			; DR7 flags (dr2)
	OutBlanks	2

	OutMsglc	DR3msg
	OutDwordHexPtr	DR3sav
	OutBlank
	CallOp		PrtDR3b, DR7sav			; DR7 flags (dr3)
	OutCrLf

	OutMsglc	TR6msg
	CallOp		PrtTR6, TR6sav			; Print TR6 flags
	OutBlanks	2

	OutMsglc	TR7msg
	CallOp		PrtTR7, TR7sav			; Print TR7 flags
	OutBlanks	2

	OutMsglc	DR6msg
	CallOp		PrtDR6, DR6sav			; Print DR6 flags
	OutBlanks	2

	OutMsglc	DR7msg
	CallOp		PrtDR7, DR7sav
	OutCrLf

	EndOp

;
;	Change registers opcode programs
;


ChangeRegs	label	byte

	InSwitchStr
	SwitchEntry	AXmsg,	ChgRegAX
	SwitchEntry	EAXmsg,	ChgRegEAX
	SwitchEntry	BXmsg,	ChgRegBX
	SwitchEntry	EBXmsg,	ChgRegEBX
	SwitchEntry	CXmsg,	ChgRegCX
	SwitchEntry	ECXmsg,	ChgRegECX
	SwitchEntry	DXmsg,	ChgRegDX
	SwitchEntry	EDXmsg,	ChgRegEDX
	SwitchEntry	SPmsg,	ChgRegSP
	SwitchEntry	ESPmsg,	ChgRegESP
	SwitchEntry	BPmsg,	ChgRegBP
	SwitchEntry	EBPmsg,	ChgRegEBP
	SwitchEntry	SImsg,	ChgRegSI
	SwitchEntry	ESImsg,	ChgRegESI
	SwitchEntry	DImsg,	ChgRegDI
	SwitchEntry	EDImsg,	ChgRegEDI
	SwitchEntry	IPmsg,	ChgRegIP
	SwitchEntry	EIPmsg,	ChgRegEIP
	SwitchEntry	PCmsg,	ChgRegIP
	SwitchEntry	CSmsg,	ChgRegCS
	SwitchEntry	DSmsg,	ChgRegDS
	SwitchEntry	ESmsg,	ChgRegES
	SwitchEntry	SSmsg,	ChgRegSS
	SwitchEntry	TRmsg,	ChgRegTR
	SwitchEntry	LDTRmsg, ChgRegLDTR
	SwitchEntry	Fmsg,	ChgRegFlags
	SwitchEntry	EFmsg,	ChgRegEFlags
	SwitchEntry	MSWmsg, ChgRegMSW
	SwitchEntry	CR0msg, ChgRegCR0
	SwitchEntry	IOPLmsg, ChgRegIOPL
	SwitchEntry	GDTBmsg, ChgRegGDTB
	SwitchEntry	GDTLmsg, ChgRegGDTL
	SwitchEntry	IDTBmsg, ChgRegIDTB
	SwitchEntry	IDTLmsg, ChgRegIDTL
	SwitchEntry	CR2msg,	ChgRegCR2
	SwitchEntry	CR3msg,	ChgRegCR3
	SwitchEntry	CR4msg,	ChgRegCR4		; 148688
	SwitchEntry	FSmsg,	ChgRegFS
	SwitchEntry	GSmsg,	ChgRegGS
	SwitchEntry	DR0msg,	ChgRegDR0
	SwitchEntry	DR1msg,	ChgRegDR1
	SwitchEntry	DR2msg,	ChgRegDR2
	SwitchEntry	DR3msg,	ChgRegDR3
	SwitchEntry	TR6msg,	ChgRegTR6
	SwitchEntry	TR7msg,	ChgRegTR7
	SwitchEntry	DR6msg,	ChgRegDR6
	SwitchEntry	DR7msg,	ChgRegDR7
	SwitchEnd	ChgRegErr

ChgRegAX	label	byte
	CallOp	ChgReg, <dataOFFSET AXmsg, AXsav>
	EndOp

ChgRegEAX	label	byte
	CallOp	ChgEReg, <dataOFFSET EAXmsg, EAXsav>
	EndOp

ChgRegBX	label	byte
	CallOp	ChgReg, <dataOFFSET BXmsg, BXsav>
	EndOp

ChgRegEBX	label	byte
	CallOp	ChgEReg, <dataOFFSET EBXmsg, EBXsav>
	EndOp

ChgRegCX	label	byte
	CallOp	ChgReg, <dataOFFSET CXmsg, CXsav>
	EndOp

ChgRegECX	label	byte
	CallOp	ChgEReg, <dataOFFSET ECXmsg, ECXsav>
	EndOp

ChgRegDX	label	byte
	CallOp	ChgReg, <dataOFFSET DXmsg, DXsav>
	EndOp

ChgRegEDX	label	byte
	CallOp	ChgEReg, <dataOFFSET EDXmsg, EDXsav>
	EndOp

ChgRegSP	label	byte
	CallOp	ChgReg, <dataOFFSET SPmsg, SPsav>
	EndOp

ChgRegESP	label	byte
	CallOp	ChgEReg, <dataOFFSET ESPmsg, ESPsav>
	EndOp

ChgRegBP	label	byte
	CallOp	ChgReg, <dataOFFSET BPmsg, BPsav>
	EndOp

ChgRegEBP	label	byte
	CallOp	ChgEReg, <dataOFFSET EBPmsg, EBPsav>
	EndOp

ChgRegSI	label	byte
	CallOp	ChgReg, <dataOFFSET SImsg, SIsav>
	EndOp

ChgRegESI	label	byte
	CallOp	ChgEReg, <dataOFFSET ESImsg, ESIsav>
	EndOp

ChgRegDI	label	byte
	CallOp	ChgReg, <dataOFFSET DImsg, DIsav>
	EndOp

ChgRegEDI	label	byte
	CallOp	ChgEReg, <dataOFFSET EDImsg, EDIsav>
	EndOp

ChgRegIP	label	byte
	CallOp	ChgReg, <dataOFFSET IPmsg, IPsav>
	EndOp

ChgRegEIP	label	byte
	CallOp	ChgEReg, <dataOFFSET EIPmsg, EIPsav>
	EndOp

ChgRegCS	label	byte
	CallOp	ChgReg, <dataOFFSET CSmsg, CSsav>
	EndOp

ChgRegDS	label	byte
	CallOp	ChgReg, <dataOFFSET DSmsg, DSsav>
	EndOp

ChgRegES	label	byte
	CallOp	ChgReg, <dataOFFSET ESmsg, ESsav>
	EndOp

ChgRegSS	label	byte
	CallOp	ChgReg, <dataOFFSET SSmsg, SSsav>
	EndOp

ChgRegTR	label	byte
	CallOp	ChgReg, <dataOFFSET TRmsg, TRsav>
	EndOp

ChgRegLDTR	label	byte
	CallOp	ChgReg, <dataOFFSET LDTRmsg, LDTsav>
	EndOp

ChgRegFlags	label	byte
	CallOp	ChgFlags, Fsav
	EndOp

ChgRegEFlags	label	byte
	CallOp	ChgEFlags, EFsav
	EndOp

ChgRegMSW	label	byte
	CallOp	ChgMSW, MSWsav
	EndOp

ChgRegCR0	label	byte
	CallOp	ChgCR0, CR0sav
	EndOp

ChgRegIOPL	label	byte
	CallOp	ChgIOPL, Fsav
	EndOp

ChgRegGDTB	label	byte
	CallOp	Chg2432Reg, <dataOFFSET GDTBmsg, GDTsav.DTRBaseLow>
	EndOp

ChgRegGDTL	label	byte
	CallOp	ChgReg, <dataOFFSET GDTLmsg, GDTsav.DTRLimit>
	EndOp

ChgRegIDTB	label	byte
	CallOp	Chg2432Reg, <dataOFFSET IDTBmsg, IDTsav.DTRBaseLow>
	EndOp

ChgRegIDTL	label	byte
	CallOp	ChgReg, <dataOFFSET IDTLmsg, IDTsav.DTRLimit>
	EndOp

ChgRegCR2	label	byte
	CallOp	ChgEReg, <dataOFFSET CR2msg, CR2sav>
	EndOp

ChgRegCR3	label	byte
	CallOp	ChgEReg, <dataOFFSET CR3msg, CR3sav>
	EndOp

ChgRegCR4	label	byte					; 148688
	CallOp	ChgEReg, <dataOFFSET CR4msg, CR4sav>		; 148688
	EndOp							; 148688

ChgRegFS	label	byte
	CallOp	ChgReg, <dataOFFSET FSmsg, FSsav>
	EndOp

ChgRegGS	label	byte
	CallOp	ChgReg, <dataOFFSET GSmsg, GSsav>
	EndOp

ChgRegDR0	label	byte
	CallOp	ChgEReg, <dataOFFSET DR0msg, DR0sav>
	EndOp

ChgRegDR1	label	byte
	CallOp	ChgEReg, <dataOFFSET DR1msg, DR1sav>
	EndOp

ChgRegDR2	label	byte
	CallOp	ChgEReg, <dataOFFSET DR2msg, DR2sav>
	EndOp

ChgRegDR3	label	byte
	CallOp	ChgEReg, <dataOFFSET DR3msg, DR3sav>
	EndOp

ChgRegTR6	label	byte
	CallOp	ChgEReg, <dataOFFSET TR6msg, TR6sav>
	EndOp

ChgRegTR7	label	byte
	CallOp	ChgEReg, <dataOFFSET TR7msg, TR7sav>
	EndOp

ChgRegDR6	label	byte
	CallOp	ChgEReg, <dataOFFSET DR6msg, DR6sav>
	EndOp

ChgRegDR7	label	byte
	CallOp	ChgEReg, <dataOFFSET DR7msg, DR7sav>
	EndOp

ChgRegErr	label	byte
	OutStr	"Bad Register Error"
	OutCrLf
	EndOp

;
;	Displays and changes the 386 flags.
;

FlagOffst	equ	0

Static	ChgEFlags, LABEL, BYTE
	JumpIfInCharEQ	"=", cfg2
	JumpIfEOL	cef1
	JumpOp		cfg2

cef1	label	byte
	OutMsgIfBitSetArglc	RFVMoffst, 16, RFfmsg
	OutMsgIfBitClrArglc	RFVMoffst, 16, Min2msg
	OutChar "("
	OutMsglc		RFfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	RFVMoffst, 17, VMfmsg
	OutMsgIfBitClrArglc	RFVMoffst, 17, Min2msg
	OutChar "("
	OutMsglc		VMfmsg
	OutChar ")"
	OutBlank
	JumpOp		cfg1

;
;	Displays and changes the 286 or 386 flags.
;

FlagOffst	equ	0

Static	ChgFlags, LABEL, BYTE
	JumpIfEnv386	ChgEFlags
	JumpIfInCharEQ	"=", cfg2
	JumpIfEOL	cfg1
	JumpOp		cfg2

cfg1	label	byte
	OutMsgIfBitSetArglc	FlagOffst, 14, NTfmsg
	OutMsgIfBitClrArglc	FlagOffst, 14, Min2msg
	OutChar "("
	OutMsglc		NTfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 11, OVfmsg
	OutMsgIfBitClrArglc	FlagOffst, 11, NVfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 11, NVfmsg
	OutMsgIfBitClrArglc	FlagOffst, 11, OVfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 10, DNfmsg
	OutMsgIfBitClrArglc	FlagOffst, 10, UPfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 10, UPfmsg
	OutMsgIfBitClrArglc	FlagOffst, 10, DNfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 9, EIfmsg
	OutMsgIfBitClrArglc	FlagOffst, 9, DIfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 9, DIfmsg
	OutMsgIfBitClrArglc	FlagOffst, 9, EIfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 7, NGfmsg
	OutMsgIfBitClrArglc	FlagOffst, 7, PLfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 7, PLfmsg
	OutMsgIfBitClrArglc	FlagOffst, 7, NGfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 6, ZRfmsg
	OutMsgIfBitClrArglc	FlagOffst, 6, NZfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 6, NZfmsg
	OutMsgIfBitClrArglc	FlagOffst, 6, ZRfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 4, ACfmsg
	OutMsgIfBitClrArglc	FlagOffst, 4, NAfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 4, NAfmsg
	OutMsgIfBitClrArglc	FlagOffst, 4, ACfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 2, PEfmsg
	OutMsgIfBitClrArglc	FlagOffst, 2, POfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 2, POfmsg
	OutMsgIfBitClrArglc	FlagOffst, 2, PEfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 0, CYfmsg
	OutMsgIfBitClrArglc	FlagOffst, 0, NCfmsg
	OutChar "("
	OutMsgIfBitSetArglc	FlagOffst, 0, NCfmsg
	OutMsgIfBitClrArglc	FlagOffst, 0, CYfmsg
	OutChar ")"

	OutCrLf
	OutChar		":"
	GetInBuf				; get a line from console
cfg2	label	byte
	JumpIfEOL	ChgFlagEnd
	InSwitchStr				; switch on flag name
	SwitchEntry	RFfmsg,	ChgFlagRF
	SwitchEntry	VMfmsg,	ChgFlagVM
	SwitchEntry	NTfmsg,	ChgFlagNT
	SwitchEntry	OVfmsg,	ChgFlagOV
	SwitchEntry	DNfmsg,	ChgFlagDN
	SwitchEntry	EIfmsg,	ChgFlagEI
	SwitchEntry	NGfmsg,	ChgFlagNG
	SwitchEntry	ZRfmsg,	ChgFlagZR
	SwitchEntry	ACfmsg,	ChgFlagAC
	SwitchEntry	PEfmsg,	ChgFlagPE
	SwitchEntry	CYfmsg,	ChgFlagCY
	SwitchEntry	NVfmsg,	ChgFlagNV
	SwitchEntry	UPfmsg,	ChgFlagUP
	SwitchEntry	DIfmsg,	ChgFlagDI
	SwitchEntry	PLfmsg,	ChgFlagPL
	SwitchEntry	NZfmsg,	ChgFlagNZ
	SwitchEntry	NAfmsg,	ChgFlagNA
	SwitchEntry	POfmsg,	ChgFlagPO
	SwitchEntry	NCfmsg,	ChgFlagNC
	SwitchEnd	ChgFlagErr

ChgFlagRF	label	byte
	ToggleBitArg	FlagOffst, 16
	JumpOp		cfg2

ChgFlagVM	label	byte
	ToggleBitArg	FlagOffst, 17
	JumpOp		cfg2

ChgFlagNT	label	byte
	ToggleBitArg	FlagOffst, 14
	JumpOp		cfg2

ChgFlagOV	label	byte
	SetBitArg	FlagOffst, 11
	JumpOp		cfg2

ChgFlagDN	label	byte
	SetBitArg	FlagOffst, 10
	JumpOp		cfg2

ChgFlagEI	label	byte
	SetBitArg	FlagOffst, 9
	JumpOp		cfg2

ChgFlagNG	label	byte
	SetBitArg	FlagOffst, 7
	JumpOp		cfg2

ChgFlagZR	label	byte
	SetBitArg	FlagOffst, 6
	JumpOp		cfg2

ChgFlagAC	label	byte
	SetBitArg	FlagOffst, 4
	JumpOp		cfg2

ChgFlagPE	label	byte
	SetBitArg	FlagOffst, 2
	JumpOp		cfg2

ChgFlagCY	label	byte
	SetBitArg	FlagOffst, 0
	JumpOp		cfg2

ChgFlagNV	label	byte
	ClearBitArg	FlagOffst, 11
	JumpOp		cfg2

ChgFlagUP	label	byte
	ClearBitArg	FlagOffst, 10
	JumpOp		cfg2

ChgFlagDI	label	byte
	ClearBitArg	FlagOffst, 9
	JumpOp		cfg2

ChgFlagPL	label	byte
	ClearBitArg	FlagOffst, 7
	JumpOp		cfg2

ChgFlagNZ	label	byte
	ClearBitArg	FlagOffst, 6
	JumpOp		cfg2

ChgFlagNA	label	byte
	ClearBitArg	FlagOffst, 4
	JumpOp		cfg2

ChgFlagPO	label	byte
	ClearBitArg	FlagOffst, 2
	JumpOp		cfg2

ChgFlagNC	label	byte
	ClearBitArg	FlagOffst, 0
	JumpOp		cfg2

;
;	Changes the CR0 register.
;

CR0offst	equ	0

Static	ChgCR0,	LABEL, BYTE
	JumpIfInCharEQ	"=", crc2
	JumpIfEOL	crc1
	JumpOp		crc2

crc1	label	byte
	OutMsglc		CR0msg
	OutMsgIfBitSetArglc	CR0offst, 31, PGfmsg
	OutMsgIfBitClrArglc	CR0offst, 31, Min2msg
	OutChar "("
	OutMsglc		PGfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	CR0offst, 4, ETfmsg
	OutMsgIfBitClrArglc	CR0offst, 4, Min2msg
	OutChar "("
	OutMsglc		ETfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	CR0offst, 3, TSfmsg
	OutMsgIfBitClrArglc	CR0offst, 3, Min2msg
	OutChar "("
	OutMsglc		TSfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	CR0offst, 2, EMfmsg
	OutMsgIfBitClrArglc	CR0offst, 2, Min2msg
	OutChar "("
	OutMsglc		EMfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	CR0offst, 1, MPfmsg
	OutMsgIfBitClrArglc	CR0offst, 1, Min2msg
	OutChar "("
	OutMsglc		MPfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	CR0offst, 0, PMfmsg
	OutMsgIfBitClrArglc	CR0offst, 0, Min2msg
	OutChar "("
	OutMsglc		PMfmsg
	OutChar ")"

	OutCrLf
	OutChar		":"
	GetInBuf				; get a line from console
crc2	label	byte
	JumpIfEOL	ChgFlagEnd
	InSwitchStr				; switch on CR0 flag name
	SwitchEntry	PGfmsg,	ChgFlPG
	SwitchEntry	ETfmsg,	ChgFlET
	SwitchEntry	TSfmsg,	ChgFlTS
	SwitchEntry	EMfmsg,	ChgFlEM
	SwitchEntry	MPfmsg,	ChgFlMP
	SwitchEntry	PMfmsg,	ChgFlPM
	SwitchEnd	ChgFlagErr

ChgFlPG	label	byte
	ToggleBitArg	CR0offst, 31
	JumpOp		crc2

ChgFlET	label	byte
	ToggleBitArg	CR0offst, 4
	JumpOp		crc2

ChgFlTS	label	byte
	ToggleBitArg	CR0offst, 3
	JumpOp		crc2

ChgFlEM	label	byte
	ToggleBitArg	CR0offst, 2
	JumpOp		crc2

ChgFlMP	label	byte
	ToggleBitArg	CR0offst, 1
	JumpOp		crc2

ChgFlPM	label	byte
	ToggleBitArg	CR0offst, 0
	JumpOp		crc2

;
;	Changes a MSW word.
;

MSWoffst	equ	0

Static	ChgMSW, LABEL, BYTE
	JumpIfInCharEQ	"=", crm2
	JumpIfEOL	crm1
	JumpOp		crm2

crm1	label	byte
	OutMsglc		MSWmsg

	OutMsgIfBitSetArglc	MSWoffst,  3, TSfmsg
	OutMsgIfBitClrArglc	MSWoffst,  3, Min2msg
	OutChar "("
	OutMsglc		TSfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	MSWoffst,  2, EMfmsg
	OutMsgIfBitClrArglc	MSWoffst,  2, Min2msg
	OutChar "("
	OutMsglc		EMfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	MSWoffst,  1, MPfmsg
	OutMsgIfBitClrArglc	MSWoffst,  1, Min2msg
	OutChar "("
	OutMsglc		MPfmsg
	OutChar ")"
	OutBlank

	OutMsgIfBitSetArglc	MSWoffst,  0, PMfmsg
	OutMsgIfBitClrArglc	MSWoffst,  0, Min2msg
	OutChar "("
	OutMsglc		PMfmsg
	OutChar ")"

	OutCrLf
	OutChar		":"
	GetInBuf				; get a line from console
crm2	label	byte
	JumpIfEOL	ChgFlagEnd
	InSwitchStr				; switch on msw flag name
	SwitchEntry	PMfmsg, ChgFlagPM
	SwitchEntry	MPfmsg, ChgFlagMP
	SwitchEntry	EMfmsg, ChgFlagEM
	SwitchEntry	TSfmsg, ChgFlagTS
	SwitchEnd	ChgFlagErr

ChgFlagPM	label	byte
	ToggleBitArg	MSWoffst, 0
	JumpOp		crm2

ChgFlagMP	label	byte
	ToggleBitArg	MSWoffst, 1
	JumpOp		crm2

ChgFlagEM	label	byte
	ToggleBitArg	MSWoffst, 2
	JumpOp		crm2

ChgFlagTS	label	byte
	ToggleBitArg	MSWoffst, 3
	JumpOp		crm2

ChgFlagErr	label	byte
	OutStr		"Bad Flag Error"
	OutCrLf

ChgFlagEnd	label	byte
	EndOp		1

;
;	Change the IOPL field in the flag word.
;

IOPLoffst	equ	0

Static	ChgIOPL, LABEL, BYTE
	JumpIfInCharEQ	"=", cio2
	JumpIfEOL	cio1
	JumpOp		cio2

cio1	label	byte
	OutMsglc	IOPLmsg			; print iopl field
	OutBitFHexArg	IOPLoffst, 12, 2	;
	OutCrLf
	OutChar		":"
	GetInBuf
cio2	label	byte
	InBitFArg	IOPLoffst, 12, 2d
	EndOp		1

;
;	Change register opcode subroutine
;

MsgAdr		equ	1
RegOffst	equ	0

Static	ChgReg, LABEL, BYTE
	JumpIfInCharEQ	"=", crg2
	JumpIfEOL	crg1
	JumpOp		crg2

crg1	label	byte
	OutMsgArglc	MsgAdr			; print register's contents
	OutWordHexArg	RegOffst		;
	OutCrLf
	OutChar		":"
	GetInBuf				; get a line from console
crg2	label	byte
	InWordArg	RegOffst		; get a word from input buffer
	EndOp		2

;
;	Change extended register opcode subroutine
;

MsgAdr		equ	1
RegOffst	equ	0

Static	Chg2432Reg, LABEL, BYTE
	JumpIfEnv286	Chg24Reg

Static	ChgEReg, LABEL, BYTE
	JumpIfInCharEQ	"=", cer2
	JumpIfEOL	cer1
	JumpOp		cer2

cer1	label	byte
	OutMsgArglc	MsgAdr			; print register's contents
	OutDwordHexArg	RegOffst		;
	OutCrLf
	OutChar		":"
	GetInBuf				; get a line from console
cer2	label	byte
	InDwordArg	RegOffst		; get a word from input buffer
	EndOp		2

;
;	Change 24 bit register opcode subroutine
;

MsgAdr		equ	1
RegOffst	equ	0

Static	Chg24Reg, LABEL, BYTE
	JumpIfInCharEQ	"=", c24r2
	JumpIfEOL	c24r1
	JumpOp		c24r2

c24r1	label	byte
	OutMsgArglc	MsgAdr			; print register's contents
	Out24HexArg	RegOffst		;
	OutCrLf
	OutChar		":"
	GetInBuf				; get a line from console
c24r2	label	byte
	In24bitArg	RegOffst		; get a word from input buffer
	EndOp		2

;
;	Print MSW flags OpInterpret opcode subroutine.
;

MSWoffst	equ	0

Global	PrtMSW, LABEL, BYTE
	OutMsglc		MSWmsg
	OutMsgIfBitSetArglc	MSWoffst,  3, TSfmsg
	OutMsgIfBitSetArglc	MSWoffst,  3, Blankmsg
	OutMsgIfBitSetArglc	MSWoffst,  2, EMfmsg
	OutMsgIfBitSetArglc	MSWoffst,  2, Blankmsg
	OutMsgIfBitSetArglc	MSWoffst,  1, MPfmsg
	OutMsgIfBitSetArglc	MSWoffst,  1, Blankmsg
	OutMsgIfBitSetArglc	MSWoffst,  0, PMfmsg
	EndOp			1

;
;	Print flags OpInterpret opcode subroutine format list.
;

FlagOffst	equ	0

Global	PrtFlags, LABEL, BYTE
	OutMsgIfBitSetArglc	FlagOffst, 14, NTfmsg
	OutMsgIfBitClrArglc	FlagOffst, 14, Min2msg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 11, OVfmsg
	OutMsgIfBitClrArglc	FlagOffst, 11, NVfmsg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 10, DNfmsg
	OutMsgIfBitClrArglc	FlagOffst, 10, UPfmsg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 9, EIfmsg
	OutMsgIfBitClrArglc	FlagOffst, 9, DIfmsg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 7, NGfmsg
	OutMsgIfBitClrArglc	FlagOffst, 7, PLfmsg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 6, ZRfmsg
	OutMsgIfBitClrArglc	FlagOffst, 6, NZfmsg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 4, ACfmsg
	OutMsgIfBitClrArglc	FlagOffst, 4, NAfmsg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 2, PEfmsg
	OutMsgIfBitClrArglc	FlagOffst, 2, POfmsg
	OutBlank

	OutMsgIfBitSetArglc	FlagOffst, 0, CYfmsg
	OutMsgIfBitClrArglc	FlagOffst, 0, NCfmsg
	EndOp		1

;
;	Print RFVM flags OpInterpret opcode subroutine.
;

RFVMoffst	equ	0

Global	PrtRFVM, LABEL, BYTE
	OutMsgIfBitSetArglc	RFVMoffst, 16, RFfmsg
	OutMsgIfBitClrArglc	RFVMoffst, 16, Min2msg
	OutBlank
	OutMsgIfBitSetArglc	RFVMoffst, 17, VMfmsg
	OutMsgIfBitClrArglc	RFVMoffst, 17, Min2msg
	EndOp			1

;
;	Print CR0 flags OpInterpret opcode subroutine.
;

Static	PrtCR0, LABEL, BYTE
	OutMsglc		CR0msg
	OutMsgIfBitSetlc	CR0sav, 31, PGfmsg
	OutMsgIfBitClrlc	CR0sav, 31, Min2msg
	OutBlank
	OutMsgIfBitSetlc	CR0sav, 4, ETfmsg
	OutMsgIfBitClrlc	CR0sav, 4, Min2msg
	OutBlank
	OutMsgIfBitSetlc	CR0sav,	3, TSfmsg
	OutMsgIfBitClrlc	CR0sav,	3, Min2msg
	OutBlank
	OutMsgIfBitSetlc	CR0sav,	2, EMfmsg
	OutMsgIfBitClrlc	CR0sav,	2, Min2msg
	OutBlank
	OutMsgIfBitSetlc	CR0sav,	1, MPfmsg
	OutMsgIfBitClrlc	CR0sav,	1, Min2msg
	OutBlank
	OutMsgIfBitSetlc	CR0sav,	0, PMfmsg
	OutMsgIfBitClrlc	CR0sav,	0, Min2msg
	EndOp			0

;
;	Print DR7 fields for DR0-3 OpInterpret opcode subroutine.
;

DR7offst	equ	0

Static	PrtDR0b, LABEL, BYTE
	OutMsgIfBitSetArglc	DR7offst, 1, Gfmsg
	OutMsgIfBitClrArglc	DR7offst, 1, Minfmsg
	OutMsgIfBitSetArglc	DR7offst, 0, Lfmsg
	OutMsgIfBitClrArglc	DR7offst, 0, Minfmsg
	OutMsgBitFlc		DR7sav.HighWord, 0, 2, RWmsgTbl
	OutMsgBitFlc		DR7sav.HighWord, 2, 2, LnmsgTbl
	OutMsgIfBitSetlc	DR6sav, 0, Bfmsg
	OutMsgIfBitClrlc	DR6sav, 0, Minfmsg
	EndOp			1

Static	PrtDR1b, LABEL, BYTE
	OutMsgIfBitSetArglc	DR7offst, 3, Gfmsg
	OutMsgIfBitClrArglc	DR7offst, 3, Minfmsg
	OutMsgIfBitSetArglc	DR7offst, 2, Lfmsg
	OutMsgIfBitClrArglc	DR7offst, 2, Minfmsg
	OutMsgBitFlc		DR7sav.HighWord, 4, 2, RWmsgTbl
	OutMsgBitFlc		DR7sav.HighWord, 6, 2, LnmsgTbl
	OutMsgIfBitSetlc	DR6sav, 1, Bfmsg
	OutMsgIfBitClrlc	DR6sav, 1, Minfmsg
	EndOp			1

Static	PrtDR2b, LABEL, BYTE
	OutMsgIfBitSetArglc	DR7offst, 5, Gfmsg
	OutMsgIfBitClrArglc	DR7offst, 5, Minfmsg
	OutMsgIfBitSetArglc	DR7offst, 4, Lfmsg
	OutMsgIfBitClrArglc	DR7offst, 4, Minfmsg
	OutMsgBitFlc		DR7sav.HighWord, 8, 2, RWmsgTbl
	OutMsgBitFlc		DR7sav.HighWord, 10, 2, LnmsgTbl
	OutMsgIfBitSetlc	DR6sav, 2, Bfmsg
	OutMsgIfBitClrlc	DR6sav, 2, Minfmsg
	EndOp			1

Static	PrtDR3b, LABEL, BYTE
	OutMsgIfBitSetArglc	DR7offst, 7, Gfmsg
	OutMsgIfBitClrArglc	DR7offst, 7, Minfmsg
	OutMsgIfBitSetArglc	DR7offst, 6, Lfmsg
	OutMsgIfBitClrArglc	DR7offst, 6, Minfmsg
	OutMsgBitFlc		DR7sav.HighWord, 12, 2, RWmsgTbl
	OutMsgBitFlc		DR7sav.HighWord, 14, 2, LnmsgTbl
	OutMsgIfBitSetlc	DR6sav, 3, Bfmsg
	OutMsgIfBitClrlc	DR6sav, 3, Minfmsg
	EndOp			1

;
;	Print TR6 and flags OpInterpret opcode subroutine.
;

TR6offst	equ	0

Static	PrtTR6, LABEL, BYTE
	OutBitFHexArg		TR6offst, 12, 20, 5
	OutMsglc		Veqmsg
	OutBitFHexArg		TR6offst, 11, 1
	OutMsglc		Deqmsg
	OutBitFHexArg		TR6offst, 10, 1
	OutBitFHexArg		TR6offst, 9, 1
	OutMsglc		Ueqmsg
	OutBitFHexArg		TR6offst, 8, 1
	OutBitFHexArg		TR6offst, 7, 1
	OutMsglc		Weqmsg
	OutBitFHexArg		TR6offst, 6, 1
	OutBitFHexArg		TR6offst, 5, 1
	OutMsglc		Ceqmsg
	OutMsgIfBitSetArglc	TR6offst, 1, Rmsg
	OutMsgIfBitClrArglc	TR6offst, 1, Wmsg
	EndOp			1

;
;	Print TR7 and flags OpInterpret opcode subroutine.
;

TR7offst	equ	0

Static	PrtTR7, LABEL, BYTE
	OutBitFHexArg		TR7offst, 12, 20, 5
	OutMsglc		HTeqmsg
	OutBitFHexArg		TR7offst, 4, 1
	OutMsglc		RPeqmsg
	OutBitFHexArg		TR7offst, 2, 2
	EndOp			1

;
;	Print DR6 flags OpInterpret opcode subroutine.
;

DR6offst	equ	0

Static	PrtDR6, LABEL, BYTE
	OutMsgIfBitSetArglc	DR6offst, 15, BTfmsg
	OutMsgIfBitClrArglc	DR6offst, 15, Min2msg
	OutBlank
	OutMsgIfBitSetArglc	DR6offst, 14, BSfmsg
	OutMsgIfBitClrArglc	DR6offst, 14, Min2msg
	OutBlank
	OutMsgIfBitSetArglc	DR6offst, 13, BDfmsg
	OutMsgIfBitClrArglc	DR6offst, 13, Min2msg
	EndOp			1

;
;	Print DR7 flags OpInterpret opcode subroutine.
;

DR7offst	equ	0

Static	PrtDR7, LABEL, BYTE
	OutMsgIfBitSetArglc	DR7offst, 9, GEfmsg
	OutMsgIfBitClrArglc	DR7offst, 9, Min2msg
	OutBlank
	OutMsgIfBitSetArglc	DR7offst, 8, LEfmsg
	OutMsgIfBitClrArglc	DR7offst, 8, Min2msg
	EndOp			1

DataSegmentEnd

CodeSegmentStart

Extern	CmdBreak,	NEAR


;***	reg
;
;	Perform register dump if no parameters or set register if a
;	register designation is a parameter.
;
;	Entry:	NONE
;
;	Exit:	NONE
;
;	Uses:	ALL
;

DefProc reg, NEAR, PUBLIC
	Pcall	ScanP
	jnz	short reg1
	Pcall	SetDefaults
	mov	[pRegSA],dataOFFSET RegSA
	Pcall	DispReg
	jmp	short regx

reg1:	mov	si,pTXT
	cmp	byte ptr [si],'T'
	jne	reg2
	cmp	byte ptr [si+1],0
	jne	reg2
	Pcall	SkipB
	xor	DebData.InitFlag,INIT_NOREGTERSE
	jmp	short regx

reg2:	mov	si,dataOFFSET ChangeRegs
	mov	di,dataOFFSET RegSA
	Pcall	OpInterpret
regx:
EndProc


;***	DispReg
;
;	Pcall	DispReg
;
;	Display registers.
;
;	ENTRY:	[pRegSA] points to RegSA_Frame to be used.
;
;	EXIT:	NONE
;
;	USES:	AX, BX, CX, DX, SI, DI, Flags
;

DefProc DispReg, NEAR, PUBLIC

;	Print the fault message and error code (if any).

	Pcall	PrintTrapMsg

;	Print anything only if enabled to do so.

	cmp	fTraceCount,0
	je	short prg0			; Normal reg dump
	jmp	short prg5			; No display

;	Print the register save area only if we are enabled to do so

prg0:	cmp	fRegDisp,0
	je	short prg3

	mov	di,[pRegSA]
	mov	si,dataOFFSET PrtRegs		; assume 16 bit regs
	test	DebData.InitFlag,INIT_ENV386
	jz	short prg1
	mov	si,dataOFFSET PrtERegs		; dump 32 bit regs
prg1:	Pcall	OpInterpret

	test	DebData.InitFlag,INIT_NOREGTERSE; if 0, dump terse register set
	jz	prg3

	mov	si,dataOFFSET PrtRegs2		; assume 16 bit regs
	test	DebData.InitFlag,INIT_ENV386
	jz	short prg2
	mov	si,dataOFFSET PrtERegs2		; dump full register set
prg2:	Pcall	OpInterpret

;	Print the current cs:ip disassembled

prg3:	Pcall	disasln
	or	ax,ax				; Any bytes disassembled?
	jz	short prg4			;  no, skip ahead
	Ccall	decodeop, <dataOFFSET opbuf>	; Decode operands into buffer

prg4:	mov	dx,dataOFFSET opbuf
	Pcall	rprbuf				; Print disassembled instrs
	Pcall	crlf
	mov	bx,[pRegSA]
	add	bx,CSIPsav
	Pcall	CopyAddr, <bx, dataOFFSET DisAddr>
prg5:

EndProc

CodeSegmentEnd

	end
