A SuperPET Monitor You Can Bank On
Gary L. Ratliff
How to add and easily relocate Micromon to the SuperPET. When this powerful monitor is paired ivith that powerful computer — you can explore the languages, the operating system, and maybe construct a 6809 disassembler.
Have you acquired the SuperPET computer and found that resident monitors lack several features found in extended monitors such as Supermon and Micromon? (Both of these monitors were made available to COMPUTE! readers: Supermon, December 1981 and Micromon, January 1982.) Have you considered adding additional memory or buying one of the newer Commodore units with the 6508 or 6509 chips? Since both these devices can use bank switching to extend the address range to several megabytes, it's likely that you will soon need a monitor which adds bank switching to an already powerful set of commands.
Or, have you wished to add a user feature to one of these monitors and wondered how it was done? If so, then the methods which I've used to add a Bank command to Micromon Plus will be of interest to you. We will examine more closely the structure of the command and jump tables so that any code which you may wish to add to the monitor will also be easy to relocate with the T and N commands of Micromon.
The first step necessary for the addition of a command to Micromon Plus which will allow bank switching is that you have correct versions of Micromon and Plus which have not been run. When Micromon Plus is executed, several changes are made to the Micromon portion of the code which make relocating the code difficult. [After the code first appeared in the January 1982 issue of COMPUTE!, several readers found relocating the code difficult. Consequently, several comments and suggestions appeared in the "CAPUTE!" section of later issues (April 1982 and June 1982).] If you are entering this on a SuperPET, be certain to make the changes for converting the code for the 8032 screen format to your correct version of Micromon. The assumed starting point is Micromon located at $6000-$6FFF and the Plus code at $5B00-$5FFF.
The first features of the Plus code which we shall examine are the commands and jump vectors. This segment of code is found at $5F15-$5F39. Note that the jump vectors for the @ command and the > command are both to $5CD8. The first change is to add a shifted B command by locating the $3E in the line starting at $5F15 and changing it to $C2. Now you can test this by issuing a shifted B command.
If you don't get the disk status, you have made an error and should correct it before entering further code. Next, change the second occurrence of the pattern D8 5C to 4A 5F. The code of the bank command will be assembled starting at $5F4A. If you wish to enter your own command into this monitor, you would follow a similar procedure.
The commands are obtained by the command search and dispatch routine found at $5B69 to $5B86. The commands start at $5F15; the jump vectors start at $5F22. If the value of the X register becomes negative, it signals that the command was not found and an error message is printed.
The design of the command is the next step. My idea of the B command was to print out the present bank setting on B <return>. Change the bank setting on entering any hex value from 0 to F, then print out the altered status. Any character other than spaces between the B and the parameter would be an error; the error message (?) should be printed to show this fact.
Note: if after the break a simple G command is issued, Micromon Plus with a BANK command added will perform a cold start. The code for adding the bank command is found in Program 1. You may enter it directly with the command: A 5F4A JSR $6006 etc. Just enter the listed code until you reach the end of the bank code at $5F8D. (If you make any entry errors, use the D command to correct the assembled code.)
Easy Relocation
A text message is easily printed by loading the Y and A registers with the address of the string followed by JSR STROUT. This was the first approach; however, the two-byte immediate instructions will not relocate properly when the finished code is moved. A careful study of the Micromon Plus code reveals that if the address is contained in a pointer, it will change automatically with the N command word option and make it easy for the user to relocate the code to any desired address. If your own routine is to use ROM-based routines which require setting up certain registers, then a similar analysis will reveal whether you need to reserve some memory as pointers to your code.
Micromon is designed to work for both Upgrade and 4.0 operating systems so look up both routines and code accordingly. SuperPET is available only for 4.0 operating systems, yet the code will operate on Upgrade BASIC which has a bank-switched RAM board (the hidden RAM feature of the 8032 excepted).
Next, the text message and the hexadecimal data need to be moved to safe ("hidden") memory. This is the purpose of the initialization code presented in Program 2. Again, just use the A command of Micromon Plus to assemble the code starting at $5AD7.
The final step is to enter the text and data. Using the M command, change the contents of locations $5F15-$5F45 and $5F90-$5FF0 to read exactly like those presented in the text of the article. This change will also enter your pointers, which will allow easy relocation of the code. Before saving the code, load the correct version of Micromon. As I mentioned, running the Plus portion will alter the Micromon code and make relocation difficult. When all these changes have been made correctly, you are ready to save the finished product. Now save the finished product by entering: S "0FILENAME",08,5AD7,7000.
You are now ready to test the operation of the bank command. Since this was written to overcome some of the shortcomings of the resident monitors present in the SuperPET, flip your machine to the 6809 setting and load in the development system. This step will fill your 64K bank switched RAM and give you something to explore. Now flip back to the 6502 side and load in Bankplus or whatever you called it when you saved the program.
Enter a SYS(1024) to get the monitor and then a command of: G 5AD7. Since this is an assembler, linker, and editor, let's try to find the instruction set text for 6809 opcodes. Enter the command: B0 followed by M 9000 9FFF to examine bank zero.
Examine Both 6502 And 6809
What? Something passed by which you wanted to see! You now have the power of Micromon Plus to examine not only the 6502 side, but also the 6809 side of your SuperPET. Before working with the 6809 monitor, you would have had to reissue the command and hope to narrow down on the target. Now, to catch that segment you missed, just hit the cursor keys and scroll up or down through memory.
Did you want to hunt through memory for the 6809 equivalent of the JSR and RTS statements to more closely zero in on the code to be translated later by the 6809 translate instruction? (While you're at it, if you turn on the printer you'll have the results of your search as hardcopy.) Want a printed hex dump of the APL in the SuperPET? Since this is larger than the 64K, you now know why the code for BANK switching must be easy to relocate. For those who are becoming impatient, the opcode data table will be found in bank six at locations $9660-$9A70.
The next step is instructions to move the code. I am certain that SuperPET owners will want to explore not only the languages, but also the operating system itself. To do this we will want to relocate Micromon to start at $7000 and the Bankplus addition to run from $0AD7-0FFF. This will allow us to move a copy of the 6809 operating system from $A000-FFFF to the freed space from $1000-6FFF. The goal is achieved by writing a simple 6809 move routine. The trick is to power-up with the switch in program mode, and then, once the code has been moved, change the registers to automatically switch to the 6502 mode. Be certain that you know how to control the diagnostic sense pin, or you will completely wipe out your freshly moved code. You'll notice that the stack pointer is messed up. Don't try to correct it: just get the code to the disk as a file.
Step-by-step
The following instructions will achieve this relocation of the code:
- T 6000 6FFF 7000
(first move Micromon) - N 7000 7FFF 1000 6000 6FFF
(relocate the code) - N 7FB0 7FFF 1000 6000 6FFFW
(relocate the words) - T 5AD7 5FFF 0AD7
(move Plus and additions) - N 0 AD7 0FFF B000 5000 5FFF
(relocate Plus) - N 0F4A 0F8F B000 5000 5FFF
(relocate Bank) - N 0AD7 0FFF 1000 6000 6FFF
(correct any Micromon calls from Plus) - N 0D4A 0F8F 1000 6000 6FFF
(correct any Micromon calls from Bank)
5F15 50 C4 49 CD 40 C2 DA 4A CB CC 5E 55 59 BE 5B 89PDIM@BZJKLˆUY>[. 5F25 5B 6B 5C 16 5C D8 5C 4A 5F 27 5E 3A 5E 62 5E 69[k\.\X\J_'ˆ : ˆb" ˆ i 5F35 5E 77 5E 82 5E D2 5E 69 5B 00 5B B0 5F D7 5A 31ˆwˆ.ˆRˆi[;. [0_WZ1 5F45 30 32 31 38 31 20 06 60 C9 20 D0 03 20 17 6C C902181 .’I P. .1IFigure 1: Command/Jump Vectors
5F90 0D 2E 20 42 41 4E 4B 20 3D 20 30 2E 0D 2E 00 00.. BANK = 0..... 5FA0 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 460123456789ABCDEF 5FB0 93 4D 49 43 52 4F 4D 4F 4E 20 50 4C 55 53 0D 42.MICROMON PLUS.B 5FC0 59 3A 20 42 2E 20 53 45 49 4C 45 52 0D 11 42 41Y: B. SEILER..BA 5FD0 4E 4B 20 43 4F 44 45 20 41 44 44 45 44 0D 42 59NK CODE ADDED.BY 5FE0 3A 20 47 2E 20 52 41 54 4C 49 46 46 0D 0D 00 00: G. RATLIFF.... 5FF0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00................Figure 2: Text String Area
9. N 0F22 0F47 B000 5000 5FFFW (correct the word tables)
At this point you can run the code and issue a load command to recall the file of the 6809 operating system. Save the whole thing, and with one very powerful monitor you can examine the 6502 ROM, the relocated code of the 6809 side of the SuperPET, and any of the languages which load into the bank-switched RAM space. Furthermore, you can also load and save segments of 6809 code. (A feature omitted from the 6809 monitor.) Not only this, but you can also determine where the 6809 programs load with the J "1 FILENAME" command of Plus and alter this location with the Y command to load the short program "loader" into the bank-switched RAM space.
Program 1:
Add the Bank Command
5F4A 20 06 60 JSR $6006 5F4D C9 20 CMP #$20 5F4F D0 03 BNE $5F54 5F51 20 17 6C JSR $6C17 5F54 C9 0D CMP #$0D 5F56 F0 14 BEQ $5F6C 5F58 A2 0F LDX #$0F 5F5A DD E0 87 CMP $87E0, X 5F5D F0 06 BEQ $5F65 5F5F CA DEX 5F60 10 F8 BPL $5F5A 5F62 4C 8E 60 JMP $608E 5F65 8A TXA 5F66 8D DF 87 STA $87DF 5F69 8D FC EF STA $EFFC 5F6C AE DF 87 LDX $87DF 5F6F BD E0 87 LDA $87E0, X 5F72 8D DA 87 STA $87DA 5F75 A0 87 LDY #$87 5F77 A9 D0 LDA #$D0 5F79 AE 00 C0 LDX $C000 5F7C E0 40 CPX #$40 5F7E F0 06 BEQ $5F86 5F80 20 1D BB JSR $BB1D 5F83 4C 89 5F JMP $5F89 5F86 20 1C CA JSR $CA1C 5F89 00 BRK 5F8A 20 60 6C JSR $6C60 5F8D 6C 3E 5F JMP ($5F3E)
I would like to learn how the disassembler works. The biggest headache in writing a disassembler in BASIC is getting the data statements correct. Since these are easily copied in from the source code used in the development system, I think the disassembler from Micromon could be converted to translate the 6809 opcodes and also print them in a correct format. How about it? Is anyone game for writing a 6809 disassembler routine in 6502? Would such a product be called a cross disassembler? You can now bank switch; let's translate too.
Program 2:
Initialization of Bank Command
5AD7 AC 41 5F LDY $5F41 5ADA AD 40 5F LDA $5F40 5ADD AE 00 C0 LDX $C000 5AE0 E0 40 CPX #$40 5AE2 F0 06 BEQ $5AEA 5AE4 20 1D BB JSR $BB1D 5AE7 4C ED 5A JMP $5AED 5AEA 20 1C CA JSR $CA1C 5AED A2 1F LDX #$1F 5AEF BD 90 5F LDA $5F90, X 5AF2 9D D0 87 STA $87D0, X 5AF5 CA DEX 5AF6 10 F7 BPL $5AEF 5AF8 A9 00 LDA #$00 5AFA 8D DF 87 STA $87DF 5AFD 8D FC EF STA $EFFC