68HC11 
MS Windows Based Simulator
Details
Program Name
6811sim.exe
Author
David Jones
Dept. Computer Systems Engineering
RMIT, Melbourne Australia
Version
2.1a
Date
9 October 1994
Purpose
  To interactively show the 68HC11 functions instruction set
  To simulate the 68HC11 CPU by running 68HC11 source code
  To simulate hardware directly interfaced to the 68HC11
  (Future) To simulate 68HC11 hardware units
Context
  Runs on an IBM compatible PC
  Runs under MS Windows V3.1+
  Requires certain files to be installed in windows\system:
vbrun300.dll, grid.vbx, cmdialog.vbx, commdlg.dll 
(Note this assumes the updated version of grid.vbx, not the version supplied with Visual 
		Basic for Windows V3 Standard).
Installation
At RMIT:
Get the file 6811sim.zip
  City : In s:\ds207\simulate.win\
  Bundoora: In h:\simulate.win\
At home
  Place in a new subdirectory
  pkunzip -d 6811sim
  Copy the files in the system directory to your windows\system directory
  Copy the file 6811sim.exe to your windows directory
  Add 6811sim.exe to a folder in the usual way or choose file run
  Clean up : You may now delete the unzip subdirectory.
Starting
At RMIT
City:
Run windows 
Double click on the 6811sim icon in the DS207 folder
OR: 	Choose file-run-browse
		Move to s:\ds207\simulate.win
		Choose 6811sim.exe
Remember to set your directory to f:\ when saving and loading.
Bundoora
Install the microprocessor control code on H drive
Exit microprocessor control
Run windows
Choose file-run-browse
Move to h:\simulate.win
Choose 6811sim.exe
At home.
If installed to an icon in a folder, double click on that icon
Otherwise choose file-run-browse and choose 6811sim.exe (assuming that you have 
moved it to \windows.)
Modes
Interactive Mode
This is the normal mode.  In this mode individual instructions are initiated by clicking 
their buttons.  Once an instruction is completed and all consequential events are completed, 
the program waits for another button to be completed.  This mode is useful for examining 
the function of specific 68HC11 CPU instructions, including their actions upon and with 
registers and memory as well as the different addressing modes for obtaining instruction 
operands.
In interactive mode, instructions are recorded for replay in the Run mode.  These 
instruction sequences can be saved to a file for reload at a later stage.
Certain instruction, although recorded in this mode, have no affect.  These are the 
branching instructions as well as pseudo instruction that are recognised at run time 
(START, STOP).


Run Mode
In this mode, instruction that have been recorded in interactive mode are replayed in the 
same order.  Branches can also occur in this mode to affect loops and selection.  An 
instruction list can be replayed by choosing the required run option from the Run menu.
Instructions can be run from
  The first instruction
  The currently selected instruction
  The first START pseudo instruction
Replay stops whenever:
  The end of the instruction list is reached
  A STOP pseudo instruction is reached.  These act as breakpoints.
  The required number of instructions have been stepped through when in step mode.
  Run-Abort menu option is chosen.
Note the menus can be accessed whilst an instruction sequence is running.  Note also 
that there are also hot keys for many of the menu options.  Eg F8 to run from the start.  
Run-Abort is Cntrl-Shift-F8.
By default instructions run as fast as the PC will run them.  By setting an animation time 
(in 1/10ths of a second) the time for each instruction can be controlled.  This is set by the 
Run-Animate menu option.
Program Elements
Main window
This performs like a 68HC11 CPU.  Certain of its RAM addresses communicate directly 
with the other two elements.  In a future version of  this program, elements will be added to 
simulate the 68HC11 IO hardware units.
LEDS
When a byte is written to this window (Address $1f3) , the byte's bit pattern is displayed 
using eight simulated LEDS (light emitting diodes), MSB on left.  It can be exposed and 
hidden under program control by writing to RAM addresses $1F4 and $1F5 respectively.
Keypad and seven segments
This is a simulated matrix keypad and 4 digit seven segment displays as memory mapped 
IO (written to/read from by writing to/reading from RAM addresses)  Pop up address is 
$1F6 and hide address i $1F7.
Keypad
This window contains a simulated telephone 4x3 keypad.  Its columns, as inputs can be 
set or cleared.  Its rows, as outputs, are normally hi.  When a key is pressed it passes the 
state of its row to its corresponding column.  In this way the keypad can be scanned to 
decode the key pressed.  The row's outputs can be collectively read at RAM address $1F2 
(Bits 0 to 3) whereas bits 4,5 and 6 of RAM address $1F0 are the columns.
Eg $1F2 normally reads as $0f, ie no keys pressed.
Eg Writing $30 (25 + 24 : set bits 4 & 5, bit 6 clear) to $1F0 will make the keypad 
column headed by key 1 go lo, leaving the other two columns hi.
Keys toggle when pressed.  That is when first pressed, the button is on and when 
pressed again it becomes inactive.  When on the button reduces in size.
Decoding the keypad
Look at the "Simulated HW" document  Examine the keypad matrix.  Note that the 
columns are input and the rows are output.  The rows and columns show their states in 
their corresponding checkboxes.
-The rows are pulled hi when not pressed, hence their output is normally  $0f as 
evidenced by $0f normally showing in the DataOut box (Bottom Left).  If a key is pressed 
then its row goes lo iff its corresponding column is  lo.  
-Columns can be set or cleared by writing to the Latch box (bottom left).
 Bits 4,5 and 6 of this input are the columns.
-Note that only one key can be pressed at a time, and that they toggle.  
 ie One press they are on until a second press.  
-If another key is pressed whilst one is toggled down then the current key
 toggles up but the other key then gets the focus.
Seven segment displays
There are also 4 seven segment digit displays.  They have a common input with a bit 
latch for each digit to activate the loading of the input data into a specific digit.  The data is 
coded as one bit for each segment, segment a being LSB upto segment g being bit 6.  Bit 7 
is unused.
Writing to the seven segment displays
Look at the "Simulated HW" document.  Examine the 7 segments part of it.  Note that 
data is displayed by writing it to the DataIn box(bottom right) and then latching the 
required bit of Latch.  
- This can be done with a mouse by typing say $EF! to DataIn (click on it  first), note 
the !, and then clicking the checkbox of the required digit from lo to hi. $EF will display 8. 
- Note that the data is latched into a digit using a postive edge on its Latch bit.  Its bit 
must first be lo then be made hi.
The Latch bits for the 7 segment digits are bits 0 to 3 of Latch.  Hence writing 2n to 
Latch, where N= 0..3 will set the latch bit corresponding to digit 0..3.  Writing 0 to Latch 
will clear all latch bits.  This is necessary when latching so as to set up the postive edge.  
Writing a one to a latch bit when it is already set will not affect a latch action.  Note also 
that when latching, by leaving its 4..6 at zero the columns of the keypad remain lo.

The seven segments of the digits are bitwise connected to DataIn thus:

 aaa
f   b  MSB:   _ gfedcba   :LSB
f   b
 ggg          _ means that bit7 of DataIn is not connected
e   c
e   c
 ddd


Main window
 
  This window acts as the central processing unit.  This has Mnemonic buttons (top right), 
registers (in centre), target-source register selection option box: Register (top left), 
operand addressing mode option box: Addr Mod (middle left), all of which are based upon 
the 68HC11 CPU instruction and register set.  Its internal RAM ( <$200) is also displayed 
(middle bottom).  
  Its has individual buttons for 68HC11 UC mnemonics and a number of pseudo operations.  
In interactive mode pressing a button will affect its operation with the current register 
contents.  Flags and memory locations get updated.  There is also a status bar at the bottom 
of the main window that displays system messages, command "mouse-overs" and can be 
written to use the pseudo operations OUTA/B.
  Each instruction so pressed gets recorded in the Instruction list box (bottom right).  This 
list can be replayed completely or partially.  Playback mode can be single an multiple 
stepped, breakpointed and animated.  The list can also be edited.
  The direction of rotation and shift instructions is selected using the Rot option box 
(middle)
  Labels can be defined as pseudo instructions which then can be used as branch and jump 
instructions.  Equates pseudo instructions can also be defined for use as instruction 
operands.  Once defined  their use or non use is predicated by the Use Labels option check 
box.  The address labels for branches are displayed in the bottom left of the Main window 
whereas the equates are displayed between that list and the RAM display.  Note that equate 
labels are limited to 6 characters whilst address labels can be significantly longer.
  The menus allow for file handling, choosing between overlaid branch instructions, selecting 
run mode, selecting the instruction list entry mode and for showing/hiding of the simulated 
hardware.  The Instruction List can be saved to file and reloaded.
  Note that each instruction contains embedded information to facilitate speedier execution 
with simulation which is saved and reloaded.  This information is written in fields to the 
right of the visible part in the instruction list and as such is in the comment field as far as an 
assembler is concerned.  Therefore code created in the 6811sim can be assembled (subject 
to a small amount of editing) but code created elsewhere cannot be loaded into the 
simulator as it does not have the embedded information.
Mnemonic buttons
These are an overlaid set of instructions.  The overlays switch as the target/source 
register is changed.  That is the instructions are in context for the chosen register.  For 
example ldaa, ldab, ldx etc are overlaid (only one is visible at a time).
Buttons display the mnemonic (or pseudo operation name) of the instruction that is 
executed when that button is pressed.  Passing the mouse over a button causes an 
explanation of it to appear is the status bar.  When pressed, the mnemonic and any operand 
are recorded in the instruction list.  This list can optionally be displayed (Menu:Instruction-
Show)
To run a mnemonic
  Select the relevant register (if required)
  Select the operand addressing mode (if required)
  Select Use Labels if desired for operands/branches
  Press the button of  the mnemonic
  Enter any operand information if prompted
  or choose a label for a branch instruction (if Use labels selected)
  or choose an equates for an operand (if Use Labels selected)

In run mode the buttons may be hidden.  Choose Menu:Run-Hide buttons on run.  When 
chosen, the Instruction List expands to the full height of the Main window.
Registers
Values can be directly entered into a register by typing in the hex or binary window for 
it.  Note though that the value does not take affect until enter is pressed.  The current 
register, the last one operated upon by instructions, is highlighted in red.  The A and B 
registers also have their corresponding ASCII character displayed.
The Condition flag names are displayed above their bits in the CCR.  The C flag is also 
displayed next to the A and B registers to aid the understanding of shift and rotate 
instructions.  The logical combinations of flags, as used separately by the signed and 
unsigned, are also generated as >, = <.  For example if US < is displayed then BLO and 
BLS branches would occur.


Instructions
(See the Visual Basic code at the end of this document)
All except the more obscure 68HC11 instruction have been allocated a button.  Most 
have been implemented but some have not.  Those not implemented show a not 
implemented yet message.  Nothing is recorded for these
The branch and jump instructions are only recorded when pressed in interactive mode.  
The branches only have an affect when in run mode.
The flags have correctly interpreted for most instructions, although the V flag is not yet 
implemented for some instructions.  The flags for the critical addition, subtraction and 
compare instructions have been fully interpreted though.
If the IMM mode is checked for shifts/rotates then these operate with the A or B 
register if selected. Direct mode is available for the rotates although this is not a valid 
addressing mode for these instructions.  These two points are also true for instructions such 
as NEG COM CLR DEC and INC.  The D register rotates have not been implemented yet.
Data tables
Data tables can be setup using the ORG and FCB pseudo commands.  Firstly set up the 
address of the table with an ORG statement.  Then follow it with an FCB command for 
each byte of the table.  FCB can only contain one byte.  To access the table load the index 
register with the address specified in the ORG statement.  To use a label for a table define 
its address as an equates and use the equates label.  Note that an address label has no 
connection with data addresses and the ORG statement has no association with program 
addresses in the 6811sim program.
See the Branch-button-locations section below for showing the FCB button.
Comments
Comments can be inserted but have no affect.  When prompted, enter comment without 
the * as this is automatically inserted.  Note that comments are lined based and cannot be 
postpended to instructions.
Editing code
The default entry mode is to add instructions at the end of the instruction list, when a 
button is pressed.  To notify code two other entry modes are possible.  Instructions can be 
overwritten and instructions can be inserted.  The entry mode can be selected from 
Menu:Instruction-Append/Insert/Append options.  Note that an instruction must be 
completely rewritten.
Instructions can be deleted by selecting it and pressing D
Note that Address Labels and equates cannot be deleted (except when all instructions 
are cleared).  This is to maintain some internal consistency.
All of the instructions can be deleted by pressing C or Menu:File-New.
Branch instructions
When address labels are used as targets of branch and jump instructions, they are 
simulated by jumping the instruction pointer to that instruction.  No check is made for the 
size of the branch.  The simplest way to record branches is to use address labels.
Branch targets can be recorded directly.  When labels are not used, when a branch 
button is pressed, a request is made to select are target instruction.  For branches the 
relative offset in terms of instruction lines, is calculated and recorded.  If code is inserted 
inside of such a branch than the branch instruction must be re-entered so as to affect a 
recalculation of the branch offset.  Similarly when labels are not used, when a jump button 
(JMP, JSR) is pressed, the instruction line number of the chosen target is recorded.  If the 
target instruction line number is changed (through a lower line number insertion or 
deletion)  then the branch must be re-entered.
The most commonly used branch instructions BRA and BNE are always displayed  as 
are JSR, JMP and BSR.  The other branch instructions are overlaid in groups of four with 
the direct bit manipulation instructions.  Choose which group you want in the 
Menu:Mnemonics-Branches submenu.
Branch button locations
The Branches Minus-Plus group of button overlay has the BEQ button as well as three 
further overlaid pseudo instructions: OUTA/OUTB/FCB.  When this overlay is chosen, the 
fourth button is OUTA if register A is chosen, OUTB if register B is chosen or FCB 
otherwise.  Hence to show the FCB button choose, say register X and the Minus-Plus 
branches.

