BBK Monitor

by: Bryan Schappel and Barry Kolbe

Publication date: February 1987

Many microcomputers have a built-in monitor which the user can call up to examine memory, disassemble memory, or even write simple machine code. This is available on the Atari only as a cartridge. So, one must switch back and forth between the BASIC cartridge and some assembler cartridge. Until now, that is. Enter the BBK Monitor (we'll call it BBK, for brevity). This is a 100 percent machine language monitor, residing "permanently" in memory ($2000-$30AE).

To load BBK from Atari DOS 2.0s, go to DOS and type:

     L[RETURN]
     BBKMON.COM[RETURN]

BBK will load and run automatically.

To load BBK with OS/A+, go to the command processor and type:

     BBKMON [RETURN]

Again, BBK will load and run automatically.

Monitor functions.
BBK performs the following general functions: assembly, disassembly, disk management, number base conversions and memory dumping.

To get BBK up and running, you have two choices; to use it with or without a cartridge.

Without a cartridge.
Insert a disk with a copy of BBKMON.COM on it into drive 1 and power up your computer. When you get to DOS, follow the loading instructions described above to load BBK. The message BBK MONITOR will appear on a green screen with a > for a prompt.

With a cartridge.
Hoot up your computer and exit to DOS. When you get to DOS, load BBK. The program will load and initialize itself, then return control to the cartridge.

To enter the monitor, type DOS and hit RETURN. The BBK MONITOR message will appear on a green screen.

Monitor commands.
(1) Assemble.
To enter this mode, type A$nnnn, where $nnnn is a hexadecimal address of one to four hexadecimal digits. All assembly must be done in hex. This is a mini-assembler. That means no labels. All assembly is done directly to memory.

Since the assembler actually stores opcodes and arguments in memory, this brings up the problem of finding free RAM. For example, the following program is "poked" into memory at $4000:

     A$4000 [RETURN]
$4000: PLA $4001: LDA#$4 $4003: STA $600 $4006: RTS $4007: [RETURN]

This results in memory locations $4000-$4006 being filled with these numbers (represented in hex):

     $4000: 68 (PLA)
     $4001: A9 (LDA#)
     $4882: 04 ($04)
     $4003: 8D (STA)
     $4004: 00 Low byte of $0600
     $4005: 06 High byte of $0600
     $4006: 60 (RTS)

Obviously, a BASIC program residing from $30AF to $5000 would be somewhat flawed after typing in the above program!

So where is there free memory? Well, we left you page 6 ($600-$6FF). We also left you free use of $CB-$CE, for indirect addressing. The monitor occupies $2000-$30AE. Without the BASIC cartridge, you have from $30AF to the bottom of screen memory—see Figure 1, below.


ROM


BASIC CART


Screen memory


Free RAM


Runtime stack


BASIC Program


BBK Monitor


DOS


Page 6


OS Usage

$FFFF


$C000


$A000


Varies


Varies ($90,91)


Varies


$30AF


$2000


$0600


$0000



Figure 1. — Memory map.

With the BASIC language in operation, but no BASIC program in memory, you have from $30AF to the bottom of screen memory. Be warned, though: BASIC will use $30AF-$31AF as a buffer for tokenizing lines! We would recommend starting at $3200.

With a BASIC program in memory, the situation is more complicated. The bottom of the BASIC program will he at $30AF, and the top can be found by determining the contents of MEMTOP, $90,91 (144,145 in decimal). Use the memory dump to do this. For example, type: M$90 and RETURN. The result might look like this:

     $0090: 30 54 A3 42 61 84

Then, $5430 would be the current top of the BASIC program. Above the BASIC program is the runtime stack. This is where BASIC keeps track of line numbers for GOSUBs and FOR-NEXT loops. MEMTOP changes from program to program, and also changes while the program is running. Any place between MEMTOP and screen memory is suitable for assembling. We would stay 1 or 2K above MEMTOP, just to be safe.

You can also use the memory dump or disassembly functions to find a block of free memory. To leave the assembler mode, just hit RETURN.

Some error checking is performed. For example, typing AND 3 results in an error; AND $3 would be accepted; PHA $3200 is taken as PHA, ignoring the $3200; and STA #$23 is taken as STA $23.

All branch instructions are checked for legal ranges.

(2) Disassemble.
Type D$nnnn,[P] to disassemble memory at $nnnn. For example, D$A000,P will disassemble the cartridge to the printer. Press any key to pause. Hit RETURN to exit at any time, even while paused. All disassembly is in hex. Disassembler format:

     $A000: LDA $A023,Y   B9 23 A0
     Addr   Mnemonics     Op Lo Hi bytes

(3) Number base conversions.
Type ?ddd or ?$nnn to convert from decimal to hex or hex to decimal.

(4) Change memory.
Type C$nnnn<mm,mm,mm,... to change a range of memory addresses. The mms are hex numbers. A maximum of 40 bytes (including the End-Of-Line or EOL) are allowed for input. This allows about ten locations to be changed per input line.

(5) Exit to cartridge.
Type Q and RETURN. The monitor's still resident, how-ever. Type DOS to re-enter the monitor; entering the monitor will not destroy your BASIC code.

(6) Exit to DOS.
Type X and RETURN. Doing this removes BBK, loads DUP. SYS and, most likely, will erase your BASIC code.

(7) Disk functions.
(a) F,n. Gives the directory for drive number n.

(b) L>D:filespec. Locks specified file. Wild cards are allowed.

(c) U>D:tilespec. Unlocks file(s).

(d) E>D:filespec. Erases file. Be sure you want to do this; you're not asked if you're sure.

(e) A>D:filespec1 ,filespec2. Renames first file with the second name.

(f) S>D:filespec,start,end. Saves a single-stage binary file, from start to end. Note that start and end must be of the form $nnnn.

(g) B>D:filespec, Loads any binary file into memory, if the file is not binary ($FF headers) the message Not a binary file is displayed. If it is a binary file, then the message Loading at $nnnn is displayed.

(8) Memory dump.
Type M$nnnn. Each generated line has this format:

     $nnnn: 00 00 00 00 00 00 ......
     Addr      Hex bytes      ATASCII

First is the address of the line; next, the values of the contents in that memory (in hex); then the ATASCII characters for that memory. The only exception is $9B (EOL). This is replaced by $1B or ESCAPE. We use CIO to print all these characters, by placing a nonzero in location 766 before printing. After the print, store a 0 in 766 to let special control characters perform their normal functions.

Pressing any key will pause the screen. Press any key to resume screen scrolling. Hitting RETURN or BREAK will abort this function.

Technical notes.
BBK resides in the low memory from $2000-$30AE. It is "protected" from erasure by the SYSTEM RESET process. We use a variable called WHICH? to determine if RESET was pressed while using BASIC or BBK. So, if you press RESET in BBK, you're returned to BBK. Likewise, from BASIC you're returned to BASIC.

BBK takes up little more than 4K, leaving around 27K in which to program.

Originally, we designed BBK to reside just below RAMTOP, with screen memory below BBK. Even though we lowered RAMTOP 16 pages, SYSTEM RESET (depending upon screen size) wiped out up to 123 bytes of our program. We moved our program up 128 bytes (it wasn't 4K at that time: fine... right?) No. For some reason, SYSTEM RESET cleared out 960 bytes [one graphics 0 screen size) below old RAMTOP. At this point, we threw up our hands in despair!

The main reason for putting BBK in high memory was so we could go to DOS to perform binary saves and loads. Well, we tried. So we lengthened BBK by doing our own binary saves and loads, and adding a memory dump.

We hope you find this program useful at some time. It's come in handy once in a while for us. Happy programming.


Barry Kolbe is a mathematics teacher in Madison, WI. He uses the Atari to demonstrate graphing in his classroom. His former student, Bryan Schappel, is studying Computer Science at the University of Wisconsin.

© 2008 Bryan P. Schappel • Valid XHTML Transitional • Valid CSS