/*
 *
 * debug86  Version 0.0  28NOV83
 *
 * This is the "debug" subtree for the 8086 family
 *
 */

/*
 * TNIX/Unix/VMS Version
 * Keyshell Version Number 1
 */

/*
 * Include files used by the pre-processor.
 */

#include <breakpoint>
#include <memcmds>
#include <portcmds>
#include <loadsave>

debug
{
>
>\kstatus\e - Shows the emulator environment.
>
>\krun pgrm\e - Runs your program.
>
>\kmemory\e - Modifies and/or accesses memory.
>
>\kregisters\e - Modifies and/or accesses register contents.
>
>\kload/save\e - Loads or saves your program.

		msg (^);
		f1;status; {
			>
			>\kregisters\e - Show register contents.
			>
			>\kmode\e - Shows current emulation mode (0, 1 or 2).
			>
			>\kmemory\e - Shows memory partitioning, emulator and program loaded.
			>
			>\kbreaks\e - Shows emulator breakpoints programmed.
			>
			>\kall\e - Show all of the above.
			msg (^);
			f1;registers; msg (^Displaying register contents...),
#if (_micro == _8086uP)
				cmd (^ds),
#else
#ifdef _UNIX
				cmd (^ds -l|more),
#else
#ifdef _VMS
				cmd (^ds "-l"),
#else
				cmd (^ds -l),
#endif
#endif
#endif
				exec, msg (^), cmd (^);
			f2;mode; msg (^Displaying emulation mode...),
				cmd (^em), exec, msg (^), cmd (^);
			f3;memory; msg (^Displaying memory status...),
#ifdef _UNIX
				cmd (^al; map; stat), exec,
#else
#ifdef _VMS
				cmd (^icom al), exec,
#else
				cmd (^al), exec,
#endif
				cmd (^map), exec,
				cmd (^stat), exec,
#endif
					msg (^), cmd (^);
			f4;breaks; msg (^Displaying breakpoints set...),
#ifdef _UNIX
				cmd (^tra; bk), exec,
#else
				cmd (^tra), exec,
				cmd (^bk), exec,
#endif
					msg (^), cmd (^);
			f5;all; msg (^Displaying emulator status...),
#ifdef _UNIX
#if (_micro == _8086uP)
				cmd (^em; ds; al; map; tra; bk), exec,
#else
				cmd (^em; ds -l; al; map; tra; bk), exec,
#endif
#else
				cmd (^em), exec,
#if (_micro == _8086uP)
				cmd (^ds), exec,
#else
#ifdef _VMS
				cmd (^ds "-l"),
#else
				cmd (^ds -l),
#endif
					exec,
#endif
#ifdef _VMS
				cmd (^icom al), exec,
#else
				cmd (^al), exec,
#endif
				cmd (^map), exec,
				cmd (^tra), exec,
				cmd (^bk), exec,
#endif
				msg (^), cmd (^);
			f8;done; cmd (^), msg (^), break;
		};
		f2;run pgrm; {
			>
			>\kgo @ pc\e - Runs your program starting at the current pc.
			>
			>\kgo @ addr\e - Runs your program starting at the specified address.
			>
			>\kstep\e - Single steps through your program.
			>
			>\ktrace\e - Turns program trace on or off.
			>
			>\kbreaks\e - Sets or clears program breakpoints.
			>
			>\kreset\e - Resets the emulator.
			f1;go @ pc;
				msg (^Hit Control-C to stop!),
				cmd (^g), exec,
				msg (^), cmd(^);
			f2;go @ addr;  {
>
> \kabsolute\e
> The environment of the 8540 operates on absolute values.  An example would
> be a symbol for an address.    Since the 8086 does not operate on absolute
> values but a combination of CS and IP,  an IP must be created from a  cur-
> rent CS value.  The special symbol CSX takes the current CS and multiplies
> it by 16.    This value may then be subtracted out of the symbol to create
> an IP.  This value is placed in the IP when the emulator is started.
>
> \krelative\e
> The 8086 is always started by using the current CS value and placing a new
> value in the IP if necessary, thus the term relative.  The value following
> the "Go" command must be a value of, 0 <= value <= 65535 or limits of  the
> IP register.
>
				f1;absolute; {
>
> This must be an absolute value containing both CS and IP information.
>
					cmd (^g ),
#ifdef _VMS
						cmd ("),
#endif
						msg (^Go at what address? %p),
						cmd (-csx),
#ifdef _VMS
						cmd ("),
#endif
						msg (^Hit Control-C to stop!),
						exec,
						msg (^), break (2);
					f1;; hist;
					f2;; hist;
					f3;; hist;
					f4;; hist;
					f5;; hist;
					f6;; hist;
					f7;manual; man (g);
					f8;done; msg (^), cmd (^), break (2);
				};
				f2;relative; {
>
> This must be a relative value containing only IP information.
>
					cmd (^g ),
						msg (^Go at what address? %p),
						msg (^Hit Control-C to stop!), exec,
						msg (^), break (2);
					f1;; hist;
					f2;; hist;
					f3;; hist;
					f4;; hist;
					f5;; hist;
					f6;; hist;
					f7;manual; man (g);
					f8;done; msg (^), cmd (^), break (2);
				};
				f7;manual; man (g);
				f8;done; msg (^), cmd (^), break;
			};
			f3; step; msg (^Executing program line...),
#if (_micro == _8086uP)
				cmd (^tra all -s ; g), exec,
#else
				cmd (^tra all -ls; g), exec,
#endif
				cmd (^tra off), exec, msg (^);
			f4;trace; {
				>
				>\kshow tra\e - Show trace status.
				>
				>\kon\e - Turns on program tracing.
				>
				>\koff\e - Disables program tracing.
				f1;show tra; msg (^Displaying trace status...),
					cmd (^tra), exec, msg (^), cmd (^);
				f2;on;
#if (_micro == _8086uP)
				cmd (^tra all),
#else
				cmd (^tra -l all),
#endif
					exec, msg (^), cmd (^), break;
				f3;off; cmd (^tra off), exec,
					msg (^), cmd(^), break;
				f7;manual; man (tra);
				f8;done; msg (^), cmd (^), break;
			};
			f5;breaks; [breakpoint];
			f6;reset; cmd (^reset), exec, msg (^);
			f8;done; msg (^), cmd (^), break;
		};
		f3;memory; { 
			>
			>\kdump\e - Shows memory contents over a specified address range.
			>
			>\kfill\e - Fills memory with a specified pattern.
			>
			>\kpatch\e - Changes contents of memory.
			>
			>\kdisassem\e - Disassembles program over a specified address range.
			>
			>\ki/o read\e - Reads the specified I/O port.
			>
			>\ki/o write\e - Writes a value to a specified I/O port.
			f1;dump; [dump];
			f2;fill; [fillmem];
			f3;patch; [patch];
			f4;disassem; [disassemble];
			f5;i/o read; [rdport];
			f6;i/o write; [wrtport];
			f8;done; msg (^), cmd (^), break;
		};
		f4;registers; {
			>
			>\kshow reg\e - Shows the register contents.
			>
			>\kset 8086\e - Allows you to change the 8086 register contents.
			>
#if (_micro == _8087uP)
			>\kset 8087\e - Allows you to change the 8087 register contents and display format.
			>
#endif
			>\kreset\e - Resets the emulator.
			f1;show reg; msg (^Displaying register contents...),
#ifdef _UNIX
				cmd (^ds -l|more),
#else
				cmd (^ds -l),
#endif
				exec, msg (^), cmd (^);
			f2;set 8086; {
>
> Valid Registers are:
>
>   \mah\n..High-order byte of register A \mcx\n..Register C
>   \mal\n..Low-order byte of register A  \mdh\n..High-order byte of register D
>   \max\n..Register A                    \mdi\n..Destination index register
>   \mbh\n..High-order byte of register B \mdl\n..Low-order byte of register D
>   \mbl\n..Low-order byte of register B  \mds\n..Data segment register
>   \mbp\n..Base pointer register         \mdx\n..Register D
>   \mbx\n..Register B                    \mes\n..Extra segment register
>   \mch\n..High-order byte of register C \msi\n..Source index register
>   \mcl\n..Low-order byte of register C  \msp\n..Stack pointer register
>   \mcs\n..Code segment register         \mss\n..Stack segment register
>
> Flags may be set also:
>
>   \mflags\n.Flags register
>   \maf\n....Auxiliary carry flag        \mpf\n....Parity flag
>   \mcf\n....Carry flag                  \msf\n....Sign flag
>   \mdf\n....Direction flag              \mtf\n....Trap flag
>   \mof\n....Overflow flag               \mzf\n....Zero flag
>
				cmd (^s ), msg (^Register name: %p), next;
				f1;; hist;
				f2;; hist;
				f3;; hist;
				f4;; hist;
				f5;; hist;
				f6;; hist;
				f7;manual; man (s);
				f8;done; msg (^), cmd (^), break;
			}, {
>
> Any valid expression or symbol.
>
				cmd (=), msg ( value: %p), exec,
					msg (^), cmd (^), back;
				f1;; hist;
				f2;; hist;
				f3;; hist;
				f4;; hist;
				f5;; hist;
				f6;; hist;
				f7;manual; man (s);
				f8;done; msg (^), cmd (^), break;
			};
#if (_micro == _8087uP)
			f3;set 8087; {
>
>\kshow sndp\e - Displays the current settings for justify, format and datatype.
>
>\kjustify\e - Justifies the stack registers for status and trace displays.
>
>\kformat\e - Sets formats for the stack registers for status and trace displays.
>            Also sets input formats for using the set 8087 command.
>
>\kdatatype\e - Sets datatype for the stack registers for status and trace displays.
>            Also sets input datatype for using the set 8087 command.
>
>\kregister\e - Sets the registers of the 8087.
>
				f1;show sndp; msg (^Displaying sndp justify, format and datatype settings...),
					cmd (^8540 sndp), exec, msg (^), cmd (^);
				f2;justify; {
>
>\kleft\e - Left justifies both the lsb and column of each displayed
>            stack register.
>\kright\e - Right justifies both the lsb and column of each displayed 
>            stack register.
>
>
					cmd (^8540 sndp j=),
					msg (^justify stack registers and the lsb left or right: %% ) ;
					f1; left; msg (^), cmd (l), exec,
						msg (^), cmd (^), break;
					f2; right; msg (^), cmd (r), exec,
						msg (^), cmd (^), break;
					f7;manual; man (sndp);
					f8;done; msg (^), cmd (^), break;
				};
				f3;format; {
>
>\khex\e - Stack registers may be altered or displayed in hex.
>\kdecimal\e - Stack registers may be altered or displayed in decimal.
>
					cmd (^8540 sndp f=),
					msg (^format of the stack registers may be hex or decimal: %% );
					f1; hex; msg (^), cmd (h), exec,
						msg (^), cmd (^), break;
					f2; decimal; msg (^), cmd (de), exec,
						msg (^), cmd (^), break;
					f7;manual; man (sndp);
					f8;done; msg (^), cmd (^), break;
				};
				f4;datatype; {
>
> Stack registers may be displayed in one of seven datatypes.
>
>                               Approximate Range in Decimal
>\kword int\e - Word integer       -32,786 <=  X  <= +32,767
>\kshort int\e - Short integer         -2e9 <=  X  <= +2e9
>\klong int\e - Long integer         -9e18 <=  X  <= +9e18
>\kpack dec\e - Packed decimal    -99...99 <=  X  <= +99...99(18 digits)
>\kshort rl\e - Short real        8.43e-37 <= |X| <= 3.37e38
>\klong rl\e - Long real        4.19e-307 <= |X| <= 1.67e308
>\ktemp rl\e - Temporary real   3.4e-4932 <= |X| <= 1.2e4932
>
					cmd (^8540 sndp da=),
					msg (^datatype may be one of seven types: %% );
					f1; word int; msg (^), cmd (wi), exec, 
						msg (^), cmd (^), break;
					f2; short int; msg (^), cmd (si), exec, 
						msg (^), cmd (^), break;
					f3; long int; msg (^), cmd (li), exec, 
						msg (^), cmd (^), break;
					f4; pack dec; msg (^), cmd (pd), exec, 
						msg (^), cmd (^), break;
					f5; short rl; msg (^), cmd (sr), exec, 
						msg (^), cmd (^), break;
					f6; long rl; msg (^), cmd (lr), exec, 
						msg (^), cmd (^), break;
					f7; temp rl; msg (^), cmd (tr), exec, 
						msg (^), cmd (^), break;
					f8;done; msg (^), cmd (^), break;
				};
				f5;register; {
>
> The control word controls several processing options available to the 8087.
> The word or individual bits may altered.
>  \mcw\n...Control Word
>  \mdm\n...Denormalized operand mask        \mpc\n...Precision control
>  \mic\n...Infinity control                 \mpm\n...Precision mask
>  \miem\n..Interrupt enable mask            \mrc\n...Rounding control
>  \mim\n...Invalid operation mask           \mum\n...Underflow mask
>  \mom\n...Overflow mask                    \mzm\n...Zero-divide mask
> The status word reflects the overall condition of the 8087.
> The word or individual bits may altered.
>  \msw\n...Status Word
>  \mb\n....Busy flag                         \moe\n...Overflow exception flag
>  \mcc\n...Condition code                    \mpe\n...Precision exception flag
>  \mde\n...Denormalized exception flag       \mst\n...Stack top pointer
>  \mie\n...Invalid operation exception flag  \mue\n...Underflow exception flag
>  \mir\n...Interrupt request                 \mze\n...Zero-divide exception flag
>  \mip\n...Instruction address pointer, used in exception handling
>  \mopc\n..Instruction opcode, used in exception handling
>  \moprp\n.Operand address pointer, used in exception handling
>  \mtw\n...Shows how each stack register is being used.
>  \mst\[0-7\]\n..Stack registers 0 through 7
>
					cmd (^8540 sndp ),
					msg (^Register name: %p), next;
					f1;; hist;
					f2;; hist;
					f3;; hist;
					f4;; hist;
					f5;; hist;
					f6;; hist;
					f7;manual; man (sndp);
					f8;done; msg (^), cmd (^), break;
				}, {
>
> Any valid expression or symbol may be used except for the stack registers.
> Stack registers must have a format consistent with their datatype.
> For decimal integers:
>   \[+/-\]digit\(s\)
>
> For decimal floating point values:
>   \[+/-\]digit\(s\).digit\(s\)\[E/e\]\[+/-\]digit\(s\)
>
> For hexadecimal values:
>   \[+/-\]hexdigit\(s\)
>
>   Word integer has maximum length of 4 digits.
>   Short integer has maximum length of 8 digits.
>   Long integer has maximum length of 16 digits.
>   Pack decimal has maximum length of 20 digits.
>   Short real \umust have a length\n of 8 digits.
>   Long real \umust have a length\n of 16 digits.
>   Temporary real \umust have a length\n of 20 digits.
>
					cmd (=), msg ( value: %p), exec,
					msg (^), cmd (^), back;
					f1;; hist;
					f2;; hist;
					f3;; hist;
					f4;; hist;
					f5;; hist;
					f6;; hist;
					f7;manual; man (sndp);
					f8;done; msg (^), cmd (^), break;
				};
				f7;manual; man (sndp);
				f8;done; msg (^), cmd (^), break;
			};
			f4;reset; msg (^), cmd (^reset), exec;
#else
			f3;reset; msg (^), cmd (^reset), exec;
#endif
			f8;done; msg (^), cmd (^), break;
		};
		f5;load/save; [loadsave];
		f8;done; msg (^), cmd (^), break;
}
