Unlike most other microcomputers, microtan 65 has been designed from the
start with a small system in mind, therefore expansion of microtan 65 is a
concept, not an after thought. We hope that this manual will be the first of
many, as each Tangerine product is supplied with thorough and useful
documentation, an absolute necessity with anything related to computers. The
first chapter of this manual provides an introduction to microprocessors and the
binary number system, it is by no means complete as this subject requires a
complete book to be dedicated to it. Chapter two gives contructional notes for
the kit version but purchasers of ready built microtan 65's are still advised to
read it as it contains relevant information. Chapters three and four describe
the microtan 65 and the microtan system respectively. The 6502 microprocessor is
described in sufficient detail in chapter five which also contains complete
tables of all of the 6502 machine code instructions.
CHAPTER 3: The Microtan 65
The microtan 65 is an exceptional microcomputer kit and the purpose of this section is to describe its design. It was considered that the majority of microkit users would initially benefit from a machine that was very easy to use rather than one that has parallel I/O, but was very awkward to use. Therefore microtan 65 is supplied with a VDU on-board, and because of this the ability to use an alphanumeric keyboard is an immediate asset. The 6502 microprocessor was chosen mainly for its very simple yet elegant hardware structure. Of course, as most readers will know, the 6502 also has a very powerful instruction set and addressing modes.
A fully expanded microtan 65 contains the 6502 microprocessor, 1K rom containing TANBUG, 1K RAM which is used for display memory and user program, keyboard interface, VDU logic and tri-state address buffers. The basic block diagram of the microtan 65 is shown below.
The most important aspect of the design is that the address multiplexer is switching at the processor clock rate. This can be done with the 6502 as memory accesses will only occur on one phase of the clock i.e. when 02 is high. WHen 02 is low the memory is not selected. During this time the VDU logic reads the display memory, one location at a time and decodes memory contents as alphanumeric or graphics characters. You will also notice when using microtan 65 that the display is free from annoying speckles, spots and flashes. This is because there is no conflict of access to display memory between processor and display refresh logic. In fact you can run a program that actually resides in display memory and it will run at full speed without upsetting the display ! The address and data bus timing is shown below to illustrate this.
Memory mapped display: Pages 2 and 3 of the address space (see chapter on the 6502) are used as the display memory, that is from hex location 200 to hex 3FF. Location 200 is the top left hand corner character position. Location 201 is the second character position in the top row and so on. The diagram below illustrates this more clearly.
To write a particular character into a character cell in the display the user must write the ASCII code, or whatever, for that character in the correct memory location. For example, if it was required to write the character "W" in the bottom row third column then the ASCII code 57 (for W) should be placed in memory loaction 3E2. If you use TANBUG's memory modify command M to load characters into the display remember that the display scrolls automatically and the character may be output onto a different row than intended.
Memory mapping of the microtan 65 is controlled on-board by three wire links, when used without the TANEX exapansion board. As there is only 1K RAM, 1K ROM and 6 I/O locations on the microtan 65 each of the three are allowed to repeat through defined areas of the 64K address space to simplify design. The address map is represented diagramatically below.
As can be seen the address space is divided into only three blocks and therefore only two bits of the address bus are necessary to control this map. The two bits used for memory mapping are the most significant address bits A15 and A14. Three links are used to wire in this address map on the microtan 65. When TANEX is used however, all memory mapping is controlled on the TANEX board and not on the microtan 65. To modify the microtan 65 it is only necessary to cut these three links.
RAM and ROM hardware is of really no consequence to the user but a knowledge
of the on-board I/O ports is useful. There are six peripheral ports used on the
microtan 65 cpu board and these control graphics on and off, keyboard read and
write, keyboard interrupt flag clear and delayed non-maskable interrupt (used
for single instruction and breakpoints). Each one of these will be taken in
CHAPTER 6 : TANBUG
TANBUG will only operate in the memory map of the microtan system, it is not
a general purpose 6502 software and has been specifically written for microtan.
Locations F7F7, F7F8 and F7F9 are reserved for a jump to an expansion monitor
ROM which is positioned on the expansion board, more about this later.
TANBUG conatins coding to automatically identify whether the keypad or full ASCII keyboard is connected to the keyboard socket. This coding is executed every time a reset is issued, and thereafter a sequence of code particular to the keyboard type in use is executed. Reset must therefore always be issued after changing the keyboard type.
When using an ASCII encoded alphanumeric keyboard monitor commands are typed in as shown in this chapter. There is however, no reset key on an ASCII keyboard, one must be fitted as shown in the chapter describing assembly of the microtan kit. TANBUG drives this type of keyboard in the interrupt mode.
The keypad is used somewhat differently, its layout being shown below.
TANBUG interrogates the keypad for a depressed key, then translates the matrix encoded signal into an ASCII character which it puts up on the visual display just as if the equivalent key were depressed on an ASCII encoded keyboard. Because of the limited number of keys it has been necessary to incorporate a shift function on the keypad. So, to obtain the character P for example, the user presses and releases SHIFT, then depresses and releases P. The SHIFT key contains a self cancelling facility - if the user presses SHIFT twice in succession the pending shift operation is cancelled. So as an example, using the two keys SHIFT and 8 the operations SHIFT P yields P on the display. SHIFT SHIFT P yields 8 on the display. Other special purpose keys on the keypad are RST, which issues a reset to the microtan, and DEL which deletes the last character typed. Repeated deletes erase characters back to the beginning of the line.
From now on in this chapter the microtan will be treated as having one type of keyboard only, since all functions required can be derived by depressing the appropriate key or keys on whatever is used - keyboard or keypad.
Having described some of the background to TANBUG it is now possible to describe the commands and syntax of TANBUG i.e. how to use it. An example is shown later on. All numerical values of address, data and monitor command arguments are in hexadecimal. The symbol <CR> means on depression of the carriage return key, <SP> the space key or bar, <ESC> the escape key (ALT on some keyboards) and <LF> line feed. In all examples, text to be typed by the user will be underlined, while TANBUG responses will not. indicates the cursor. <ADDR> means a hexadecimal address, <ARG> means hexadecimal data and <TERM> means one of terminators <CR>, <SP>, <ESC> or <LF>.
All commands are of the form
where <COMMAND> is one of the mnemonic commands and <ARG> is a hexadecimal argument applicable to the command being used. The required argument is defined for each command. It should be noted at an early stage that the longest argument will contain 4 hexadecimal characters. If more are typed all but the last 4 are ignored. As an example consider the memory modify command M12340078 <CR>. In this case location 0078 will be modified or examined as all but the last 4 characters are ignored.
<TERM> is one of the terminating characters <CR>, <SP>, <LF> or <ESC>. In fact TANBUG accepts any of the "control" characters (HEX code 0-20) as terminator. TANBUG will reply with a ? if an illegal command is encountered.
Starting the monitor TANBUG:
Press the RST key on the keypad or the reset key or button connected to the
microtan. TANBUG will scroll the display and respond with
Memory modify/examine command M:
The M command allows the user to enter and modify programs by changing the RAM locations to the desired values. The command also allows the user to inspect ROM locations, modify registers etc. To open a location type the following
TANBUG then replies with the current contents of that location. For example
to examine the contents of RAM location 100 type M100<CR>
assuming the current contents of the location were 0E.
There are now several options open to the user. If any terminator is typed the location is closed and not altered and the cursor moves to the next line scrolling up the display by one row. If however, a value is typed followed by one of the terminators <CR>, <LF> or <ESC> the location is modified and then closed. For example using <CR>
location 100 will now contain FF. If however <SP> is typed, the location is re-opened and unmodified.
This facility is useful if an erroneous value has been typed. The terminators
<LF> and <ESC> modify the current location being examined, then opens the next
and previous locations respectively
and using <ESC>
Using <LF> makes for very easy program entry, it only being necessary to type the initial address of the program followed by its data and <LF>, the responding to the cursor prompt for subsequent data words.
NOTE that locations 1FE and 1FF should not be modified. These are the stack locations which contain the monitor return addresses. If they are corrupted TANBUG will almost certainly "crash" and it will be necessary to issue a reset in order to recover.
List command L:
The list command allows the user to list out sections of memory onto the display. It is possible to display the contents of a maximum of one hundred and twenty consecutive memory locations simultaneously. To list a series of location type
where <ADDR> is the address of the first location to be printed and <NUMBER>
is the number of lines of eight consecutive locations to be printed. TANBUG
pauses briefly between each line to allow the user to scan them. For example, to
list the first 16 locations of TANBUG (which resides at FC00-FFFF) type
If zero line are requested (i.e. <NUMBER> = 0) then 256 lines will be given.
Go command G:
Having entered a program using the M command and verified it using the L command the user can use the G command to start running his own program. The command is of the format G <ADDR><TERM>. For example, to start a program whose first instruction is at location 100 type G100<CR>. When the user program is started the cursor disappears. On a return to the monitor it re-appears.
The G command automatically sets up two of the microprocessors internal registers
The contents of the other four internal registers, namely the status word (PSW), index X (IX), index Y (IY) and accumulator (A), are taken from the monitor pseudo registers (described next). Thus the user can either set up the pseudo registers before typing the G command, or use instructions within his/her program to manipulate them directly.
Register modify/examine command R:
Locations 15 to 1B within the RAM reserved for TANBUG are the user pseudo registers. The user can set these locations prior to issuing a G command. The values are then transferred to the micro-processors internal registers immediately before the user program is started. The pseudo register locations are also used by the monitor to save the user internal register values when a breakpoint is encountered. These values are then transferred back into the microprocessor when a P command is issued, so that to all intents and purposes the user program appears to be uninterrupted.
The R command allows the user to modify these registers in conjunction with the M command. To modify/examine registers type R<CR> and the following display will appear (location 15 containing 00 say)
Now proceed as for the M command.
Naturally the M command could be used to modify/examine location 15 without
using the R command - the R command merely saving the user the need to remember
and type in the start location of the pseudo registers. Pseudo registers
locations are as follows.
Two typical instances of the use of the R command are:-
Note that when modifying registers in case (b) care must be taken if PCL, PCH or SP are modified, since the proceed command P uses these to determine the address of the next instructions to be executed (PCL, PCH) and the user stack pointer (SP).
Single instruction mode S:
Single instruction mode is a very powerful debugging aid. When set TANBUG executes the user program one instruction at a time, re-entering the monitor between each instruction and printing out the status of all of the microprocessor's internal registers as they were after the last instruction executed in the user program. The S command is used in conjunction with the proceed command P and the normal mode command N. Examples are given in the description of the P command.
Normal mode command N:
The N command is the complement of the S command and is used to cancel the S command so that the microprocessor executes the user program in the normal manner without returning to the monitor between each instruction. Reset automatically sets the normal mode of operation.
Proceed command P:
The P command is used to instruct TANBUG to execute the next instruction in the user program when in single instruction mode. Pseudo register contents are transferred into the microprocessors internal registers and the next instruction in the users program is executed. The monitor is then re-entered. P may also be used with an argument thus P <NUMBER><CR> where NUMBER is less than or equal to FF. In this case the program executes the specified number of instructions before returning to the monitor.
Each time the monitor is re-entered after execution of an instruction or instructions, the status of the microprocessor internal registers as they were in the user program are printed across the screen in the following order:
Note that these are in the same order as the pseudo registers described earlier.
Whenever the user program is entered, the cursor is removed from the display. Whenever the monitor is entered, the cursor returns to the display as a user prompt. While in the monitor between user instructions, any monitor command can be typed. A program must always be started by the G command, then P used if in single instruction mode. A P command used before a G command is issued is likely to cause a program "crash" and should not be attempted.
As an example consider the simple program which repeatedly adds 1 to the
Set the single instruction mode and start the program. The user may wish to initially set the accumulator to 00 by using the M command.
TANBUG then responds with the characters shown above.
Since the cursor has re-appeared, TANBUG is ready for any monitor command. For example, registers or memory locations can be modified, or the program may be re-started from scratch by typing G100<CR> again. If the user wishes to continue then type P<CR>. The resulting display is
Since the instruction at location 102 was "Jump to 100", the status print out shows that this has indeed occurred. Registers, since they were not modified by any program instruction, remain unchanged. To proceed further type P<CR> again.
The add instruction has been executed again, so the accumulator has incremented by 1 to become 2. Now typing P4 <CR> gives a display.
TANBUG allowed execution of 4 instructions before again returning to the monitor. The 4 instructions were 2 add instructions and 2 jump instructions thus giving the accumulator the value 4.
By typing N<CR> then P<CR> removes the single instruction mode and causes the program to proceed. It now does not return to the monitor but continues to race around this small program loop continually adding and jumping back. There is no way to exit from this trivial program except by a microprocessor reset or, if using an alphanumeric keyboard, by typing ESC.
It can be seen that the S and P commands are particularly useful when tracing a program which contains instructions that transfer program control e.g. jumps, branches and subroutines, since these commands allow the user to interrogate the order of execution of his/her program.
Breakpoint command B:
A breakpoint is a complementary debugging aid to single instruction mode. Instead of stepping singly through all instructions in a program, the breakpoint facility allows the user to specify the address at which he requires the monitor to be re-entered from his/her program. As an example, consider a long program in which a fault is suspected to exist near the end. It would be very tedious and time consuming to single step through the program to the problem area. A breakpoint can be set just previous to where the fault is suspected to exist and the program started with the G command. Normal execution occurs until the breakpoint is reached, then the monitor is re-entered with the same status print-out as for single instruction mode. Any monitor commands can then be used and the program continued.
The format of the breakpoint command is
where <ADDR> is the address of any instruction OPCODE (but not argument), <NUMBER> is any number from 0-7 defining one of 8 breakpoints. B <CR> removes all breakpoints. As an example consider the following program
Firstly set index X, index Y and the accumulator to 00 using the R command. To set breakpoint 0 at the jump instruction and start the program type B104,0<CR>. The display will then be
The jump instruction was reached and the breakpoint re-directed control back to TANBUG. If it were required, single instruction mode could be set for further debugging. However, assume that we wish to execute the loop again by typing P<CR>.
The proceed command P has gone once through the breakpoint and then re-entered the monitor. If P<NUMBER><CR> was typed it would have proceeded through the breakpoint <NUMBER> times.
Up to 8 breakpoints can be set at 8 different locations. The B <CR> command removes all breakpoints. A single breakpoint can be removed by setting its address to 0. For example, imagine a breakpoint is set as follows; B102,2, and it is subsequently wished to remove it but leave any others unaltered; type B0,2<CR> to remove it.
Caution. The breakpoint system works by replacing the users instruction with a special instruction (BRK) whose opcode is 00. Replacement is carried out when G or P is typed. On return to the monitor the original opcode is replaced. It is therefore possible to corrupt the user program under some circumstances. The following points should therefore be observed:
The status of breakpoints may be inspected by using the M command to examine the breakpoint status table. This is located in RAM locations 20-2F and are as follows:
For example, typing M20<CR> followed by <LF> gives
This indicates that breakpoint 0 is set to location 100 by taking the contents of location 20 as PCL and of location 21 as PCH. If the breakpoint is set at location 0 then this particular breakpoint is disabled.
Offset command O:
The offset command O is a program writing aid. It calculates branch offsets for the user for incorporation as arguments in branch instructions. Consider the example:-
To calculate the number to enter into location 121 is quite tedious without a facility such as the O command. It is used with the following format.
and in this case it would be necessary to type O120,100<CR>. The display would be
DE is the number that should be entered into location 121 such that if the BNE instruction is true the program counter will jump to the label LOOP.
Note that the maximum branch range is 7F forwards and backwards. If the range is exceeded a ? is displayed.
Copy command C:
The copy command allows copying of the contents of one block of memory to another. Its format is
Suppose it is required to copy the block of data in locations FC00-FD00 into a block starting at location 200. This may be achieved by typing CFC00,FD00,200<CR>. The display will be
As 200 is the starting address of the display memory the user will notice that the top half of the screen has been over written with all sorts of weird and wonderful characters. What this example has done is to take the first 256 bytes of TANBUG and copy them into the top half of the display. The display then scrolled having the top 7 rows filled with these characters.
Breakpoints and the ESC key
If an alphanumeric keyboard is being used, depression of the ESC key (ALT on some keyboards) will cause a re-entry into the monitor from the user program. This is possible because the alphanumeric keyboard is interrupt driven. For example, if the trivial program
has been started by typing the G command the program continues to loop around continuously with no exit path to the monitor, except by issuing a reset. Instead of a reset the user can press the ESC key, TANBUG responding thus
Using the ESC key has caused a breakpoint to be executed and the monitor invoked. The register print-out above is only typical, the value of each beaing that when the ESC was depressed. Any monitor command may now be typed, for example P causes the user program to proceed once again.
The ESC facility is most useful in debugging where the user program gets into
an unforseen loop where breakpoints have not been set. It enables the user to
rejoin the monitor withour using reset and losing the breakpoints that have been
Certain input/output subroutines are available to the
TANBUG uses the bottom line of the display for all text
Subroutine POLLKB is used to interrogate the keyboard for a
1) C LI enable interrupts
This subroutine causes the display to scroll up one line by out-
This subroutine is called to output a character held in the
Since 30 is the ASCII code for the character "Oll and 31 is the
Subroutine HEXPNT takes a binary value from the accumulator and
PHA save A on stack
This code will display the contents of the accumulator as two
Notes: Address of subroutine HEXPNT is FFOB. Register IY is
This subroutine reads hex characters from the bottom line of the
enabling a sixteen bit word to be assembled. It is useful for
JSR OUTPCR scrol 1 display
In this example the subroutine is used in the following way:
is 0013 and HXPKH is 0014. Registers IX, IY and A are all
TANBUG uses both the maskable and non-maskable interrupts.
The maskable interrupt
When TANBUG is initialised by a reset, certain RAM locations are
routine after executing its own code.
A number of things should be noted when using interrupts:
The non-maskable interrupt
The non-maskable interrupt vector is accessed in the same way as
It will be noted that TANBUG displays a question mark whenever
When an error occurs the following sequence of events is
With TANEX present, a special link is incorporated to return
There are two methods of returning to the monitor from
EXAMPLE OF TANBUG's USE
The following, simple example program clears the screen by
The first step in writing a program is to produce a flowchart
step is to look up and write the op-codes and arguments for each
The flowchart and program listing now follows.
Example program listing
0050 00 00 VDUIND: 0 ;
Program entry is performed using the M command. For the
Once the program is entered the branch offsets are
The program will now run if it has been entered
Having got the program working it is now possible to introduce
instruction BNE DECIT; instead of location 73 containing FD
is displayed. Control is now back in
Note that when using an alphanumeric keyboard, debugging is
TABLE OF HEX ASCII CODES
Note that the codes 00 - 1F produce special symbols when
TABLE OF HEX ASCII CODES (CONTINUED)
20 Space 40 @ 60
Om NULL: 00
;reserved for bpt use
;start of main program init.
FCOO A2FF START: LDX #FF
;set stack pointer
;clear breakpoint store as their
values will be
FC06 2OB7FF JSR BPTCLR
now use table to initiate
FCOC A20E LDX #E
FC35 DOF5 BNE TBMS