The Mouse Language I've always been fascinated by "small" languages. My favorites are PILOT, TINY-c and Mouse. Mouse was designed by Peter Grogono around 1975. His book, "Mouse, a language for Microcomputers", 1983, Petrocelli Books, Inc. contains two interpreters. One is written in Pascal, the other uses CP/M and Z-80 macro assembler. Mouse programs execute quickly. The Z-80 interpreter is very small ( 2k ). The source code is under 40k and is well commented. Mouse supports many features usually associated with much higher level languages, like recursion, pointers, arrays, local and global variables and even macros (subroutines). This article will explain the language thru several examples. When you have finished it, you should have a feeling for its potential (and its limitations). Mouse programs are fun to write. They are easier to write than to read (like Forth). Mouse isn't as powerful as Forth (or as complicated). It, like Forth, is a stack-oriented language. Here's a section of code from a program called Z80.MSE. This program draws a picture of Z80 Mouse on a screen. It's a lot of fun to watch it when it runs! Get ready. Hold on tight. This is your first look (probably) at Mouse. It's tricky. $H ~ Draws a horizontal line 3% units long ~ from left to right ~ starting from row 1%, column 2% 2% c : ~ c holds moving column number 3% w : ~ w keeps track of when to stop drawing ( w. ^ #Q,1%,c.; ~ while not done, plot, w. 1 - w : ~ decrement w and c. 1 + c : ~ increment column number ) @ Tildes (~) signal a comment in Mouse. The code above is an example of a macro or subprogram. $H is its name. In the "main" program you would have code like #H,18,33,3; and this would end up being interpreted to mean "draw a line (on a terminal's screen) which starts at row 18, column 33 and goes horizontally across the screen 3 units." Similar macros to draw vertical lines and of course to plot individual points supply you with tools to make line drawings. The Horizontal line drawing macro $H assigns the local variable c the value of the second number passed to it ( 2% c : ), and then proceeds to loop while a work variable ( w ) is still positive, plotting appropriately positioned characters. This is done by calling another macro, Q. In the code above, we see #Q,1%,c.; . This sends the Q routine the row ( 1% ) and the moving column's value ( c. ). Loops are delimited by open and closed parentheses. Expressions within loops and on the left hand side of the symbol ^ are tested for positivity and if the test fails, the loop is exited. The code w. 1 - w : decrements the value of the work variable w . In BASIC, w = w - 1 . Everything, almost, in Mouse, is a single character wide! Most instructions are one character, reminiscent of PILOT, except much more powerful. The usage of a calculation stack is illustrated by the assignment statement w. 1 - w : . "Reverse Polish" or "post-fix" arithmetic is used. Mouse is a good language to use if you don't have much room to play with. The code is incredibly compact. Risking the chance that I might lose you, and hoping I don't, here are the details which explain how this "decrement w" code works. Skip over the next paragraph on your first pass of this article if you wish. It puts the address of w on the stack, then "dereferences" this address ( . ), replacing the top of the stack with the value at that address, then pushes this value and places a 1 on the top of the stack. The top two values are then popped off the stack, subtracted, and their difference is pushed on the top of the stack. w's address is pushed on top of this difference and the colon ( : ) pops the top two elements off the stack and stores the value of the second at the address specified by the value of the first. Continuing, the macro Q refers to yet another "word", P . P's code is machine dependent. This version of P works on terminals which emulate a Lear-Siegler ADM 3A. The KayPro II for example. Here's the code. $Q ~ Shorthand ! #P,1%,2%; G. !' @ $P ~ Position cursor at row 1%, column 2% 27 !' "=" 1% 1 - 32 + !' 2% 1 - 32 + !' @ The 27 !' "=" sends ESC ape = to the screen and the rest tells the screen what row and column to position the cursor at. In BASIC it would be PRINT CHR$(27) + "=" + CHR$(31 + r) + CHR$(31 + c); . Once positioned, the phrase G. !' prints the contents of the global graphics variable G . This can be assigned different values during the course of the picture drawing. For example, Z80.MSE draws the figure shown below. MM MMM M M MMM Z80 Mouse M MMM MMMM M MM MM (8/3/86) MM MM MM M MM MM MM MM MM MM MM M M MM M M ZZZZZZZZZZ 88888 00 M M ZZ 88 88 00 00 MM MM ZZ 8 8 00 00 MM M M M ZZ 88 88 00 00 M M ZZ 88 88 0 0 M M ZZ 88 88 00 00 M M ZZ 8 8 00 00 M M ZZ 88 88 00 00 MMM MMM M ZZ 88 88 00 MMMM MMMMMMMM ZZZZZZZZZZZZZZZZZZZZZ 88888888888000000000000M MMMM L + L The code in the "main" program looks like this. 'Z G : ~ Establish plotting graphic #Z; ~ Draw the Z '8 G : ~ New graphic #E; ~ Draw the 8 etc. The Z macro reads $Z ~ Holds the data for the letter Z #H,10,3,10; #H,11,9,2; #H,12,8,2; ... etc. When I wrote this program, I forgot to put the needed semicolon ( ; ) at the end of the macro calls. I uncovered this bug by using the important trace feature of Mouse. Placing a { anywhere in your code will permit you to single step thru the program. At each step, you are shown a window on the code being executed. This is an invaluable debugging tool. Mouse can handle only 26 variables. Bear in mind, however, that Mouse supports 26 local variables in each of the (up to 26) macros. So you've got 26 times 26 or 676 variables. Their names can't be terribly mnemonic, suffering from the 1 character wide characteristic of everything in Mouse. But 26 variables, (A..Z), isn't really that restrictive for moderate sized applications. I wrote a program in Mouse which solves a general 3 equation 3 unknown system of linear equations. I used all but 6 of the 26 variables by the time I got done ! Here's a complete Mouse program which prints out an ASCII (American Standard Code for Information Interchange) table. "!!" " " "ASCII Table" "!!!" 32 c : ( 128 c. - ^ c. ! " " #H,c.; " " c. !' " " c. 1 + c : "!!" ) "!!" $H ~ Print hexidecimal form of decimal number 1% w : w. 16 / 9 > [w. 16 / 10 - 'A + !'] 10 w. 16 / > [w. 16 / '0 + !'] w. 16 \ 9 > [w. 16 \ 10 - 'A + !'] 10 w. 16 \ > [w. 16 \ '0 + !'] @ Here are the first few lines of the table. ASCII Table 32 20 33 21 ! 34 22 " 35 23 # 36 24 $ 37 25 % 38 26 & ... The routine which prints the hex form of a decimal number uses the modulus operator ( \ ) of Mouse. This is also the first example of the if statement ( [ ] ). Similar to the loop construct, an expression is evaluated and, if positive, the conditional code bracketed with [ and ] gets executed. In conclusion, Mouse is worth learning. I hope this article helps to make it better known. We all owe Peter Grogono our thanks for creating this gem of a language! Lee R. Bradley Mouse House Software 24 East Cedar Street Newington, CT 06111 (203) 666-3139, (203) 665-1100 (RBBS/RCP/M) If you are interested in downloading MOUSE.LBR, a LiBRary file which contains the Z-80 interpreter (source included) as well as full documentation and many sample Mouse programs, it is available on the Computer Language Magazine BBS (415) 957-9370 as well as my own PBBS/RCP/M in Connecticut (203) 665-1100).