Sunday, February 12, 2023

Exploring the Z80-MBC2 Soup to Nuts Chapter 7: FabGL AnsiTerminal & Microsoft BASIC

It's high time to explore the capabilities of the Z80-MBC2. By pairing it with the LILYGO TTGO VGA32 module, we have created a formidable 128K computer that can run CP/M with a variety of programming languages, including BASIC, PASCAL, C, and Assembly. This setup offers multiple video resolutions and up to 64 colors, as well as sprite support.

To get started, Microsoft BASIC (MBASIC-80), is readily available on the A> disk of the CP/M3 disk set. Interestingly, there are actually two variations of the BASIC interpreter to choose from.

MBASIC-80 V5.21 released in 1980. MBASIC-85 V5.29 released in 1985.

I tend to use slightly newer 85 version.

These were released when Bill Gates was still a programmer at Microsoft.

 

Also included in the same disk image is a copy the classic Star Trek game.

Star Trek is a classic example of what you can achieve with MBASIC and holds historical significance as a widely-circulated game during the early days of personal computing. To try it out for yourself, simply type "MBASIC TREKINST.BAS" at the A> prompt.

The TREKINST.BAS program provides instructions on how to play the game, where you assume the role of the captain of the USS ENTERPRISE and defend the Federation against the Klingons.

While the game was designed for early, single-color VT-100 terminals, our Z80-MBC2 computer with the VGA32 Module has much greater video capabilities. To make the most of this, I've enhanced the FabGL Ansi Terminal software to allow for control over screen resolution and font selection directly from the Z80-MBC2. Additionally, a 320x200 64-color video mode option is available.

You can download this tweaked version of Ansi Terminal from my GITHUB.

    https://github.com/eightbitswide/FabGL-AnsiTerminal-Mods-

This GITHUB package is a complete fork of Fabrizio Di Vittorio's FabGL project, with the majority of the modifications being made to the Ansi Terminal software. I have also incorporated the classic Commodore PETSCII font style into the VGA8X8 font.

It is assumed going forward that you have this version of the Ansi Terminal software installed on your VGA32 Module. Simply connect a PS2 keyboard, press F12, and you will have the ability to choose your options via a PS2 mouse or by using the TAB key to navigate between selections.

 

Choose your desired Resolution and Font setting and press F10 to apply it. Personally, I prefer the 512x354, 64-color option for most of my programming on the Z80-MBC2, which provides an ANSI/VT100 terminal with a screen size of 64x45 characters. Be sure to also check out the "Terminal Type" options, as Ansi Terminal can emulate various types of terminals, including Osborne, Kaypro, Hazeline, and ADM. If you need to make any changes to your terminal settings later on, simply press F12 and make your selections. Additionally, you can reset the screen without affecting the Z80-MBC2 by pressing CTRL+ESC from the same menu.

With this in place, let's take advantage of a few of those new graphics commands:

In the first example, you might have noticed that when Star Trek ran, the game cleared the screen, homed the cursor then welcomed us to the same with a moving ASCII art version of the USS Enterprise.   This was accomplished using VT-100 commands.

For example, if I want to clear the screen I would send [ESC]+[2J  to the terminal.  In BASIC this would look like:

10 PRINT CHR$(27)+"[2J";

Next if I want to home the cursor in the top left of the screen, I would send [ESC]+[H to the terminal.   Our BASIC program would get an additional line 20.

20 PRINT CHR$(27)+"[H";

Running the BASIC program with these two VT-100 commands will both clear the screen and home the cursor.   A complete list of VT-100 commands can be found on this website.  Ansi Terminal supports most of these commands.  This gives it the ability to be compatible with programs like Word Star.

Our terminal also supports some "non-standard" ESC commands as well.   Consider this: ESC "_GRECT" X1 ";" Y1 ";" X2 ";" Y2 "$"  This special graphics command will tell Ansi Terminal to draw a rectangle on the screen.   At the following line to your BASIC program:

30 PRINT CHR$(27)+"_GRECT10;10;150;150$";

With a single line of code we told the terminal to draw a box with the top left corner located at 10,10 and the bottom right corner located at 150,150.

In addition to the _GRECT command there are also _GPEN, _GLINE, _GPIXEL, _GELLIPSE as well as a variety of other non-standard ESC commands we can send our terminal.

A complete list of these commands can be found at the FabGL Specific Terminal Sequences page.


By utilizing these commands and some mathematical calculations, we can unlock a variety of intriguing graphics capabilities right away.

In the March 1981 issue of Compute Magazine, there was an advertisement for a  memory add-on for the Commodore PET computer. A demonstration program was included at the bottom of the advertisement.

Thanks to Tom Lake and John Galt (Altair-Duino: Google Groups) a version of this BASIC program has been adapted for use with those FabGL non-standard terminal sequences.

This TLHAT1.BAS program takes advantage of the _GPEN and _GPIXEL commands to draw what looks like a Fedora hat pixel, by pixel.

Let's review:

Ansi Terminal is capable of:

 

Let's see what those additional tweaks do:

Fedora Hat demo

Consider the following BASIC program:

  • 10 PRINT CHR$(27)+"_#320x200x64$"
  • 20 PRINT CHR$(27)+"_#LCD 8x14$"
  • 30 PRINT CHR$(27)+"_#APPLYSETTINGS$"
  • 40 FOR X = 1 TO 3000 : NEXT X
  • 50 PRINT "HELLO WORLD";

This simple BASIC program adjusts the resolution and font, applies the changes to the terminal, waits for the screen to update, and finally displays the message "HELLO WORLD" using an LCD font.

All of the available resolution and font options are listed on the GITHUB readme for FabGL-Ansiterminal-Mods.

Remember if you need to switch your terminal back to your preferred settings, press F12, make your changes, then F10 to save and reset.

A disk image containing a number of BASIC demos can be downloaded and extracted to your Z80-MBC2 SD card.  It replaces the normally empty P:> disk (file:D2N15.DSK) in CP/M3.  Launch P:>MBASIC85 {filename.bas}.  These demos are best viewed at 640x480x16.

These BASIC demos are intended to get you started in experimenting with the extended graphics commands.  If you come up with some additional ideas, please post them in the comments section.

 

Basic Sphere Demo


16 color Mandelbrot Demo

Fedora Hat Demo drawn in random pixel colors



 


1 comment:

tfurrows said...

Greetings! Trying to reach out from gopherspace and radio space. This is KF7MIX, user tfurrows, Joe. My email is on QRZ, I'd like to chat about your recent gopher post on amateur radio. Reach out if you get this!