Your Spectrum
Issue 9, November 1984 - MegaBasic Tutorial, part 1
Home Contents KwikPik

The YS MegaBasic manual is on the Spot's Pourri page.

THE COMPLETE
M E G A B A S I C
TUTORIAL - PART 1
Your Spectrum presents the first in a series of tutorials on the amazing new language for the ZX Spectrum - YS MegaBasic. Mike Leaman details two of its most outstanding features - windows, and the manipulation of character sets.
MegaBasic logo
Once you've got hold of your very own copy of YS MegaBasic (And that won't be long now! Ed.), the features that are going to grab your attention first of all are going to be the use of windows on-screen and the ease with which you can manipulate the different character sizes. So without further ado, let's take a look at the screen output and the commands you'll need to be au fait with before you get down to some serious Mega-programming.

FRAMING WINDOWS

A 'window' is an area of the screen to which you can output any characters. This area can be specified to be any size and in any position on-screen. Users can have any number of windows active at any one time, but the normal limit is 10 without involving the use of special memory-saving techniques which I'll detail once you've had a chance to play with YS MegaBasic yourself.
If windows are positioned on-screen such that they overlap, you'll find that printing to one window will obliterate whatever's in the other window. For this reason, it's best to plan out exactly what screen layout you're after before you commit yourself. You'll also find that characters scrolled off the top of a window are lost - an indication that the window techniques offered by YS MegaBasic are not quite the system you'd expect to find in computers like the Apple Mackintosh ... but then, there's a slight difference in the price of the Spectrum compared to the Mac!
The normal Spectrum can be thought of as having a single window of a fixed size, and associated with this window are the following features - the PAPER colour, the INK colour, the BRIGHT state, the FLASH state, the INVERSE state and the OVER state. However, with YS MegaBasic, the Spectrum can make use of up to 20 user-definable windows,
each having the following features attributed to them - the character size, the PAPER colour, the INK colour, the BRIGHT state and the FLASH state. The current character set or FONT, the INVERSE state and the OVER state can be said to be features of all 10 windows and so are referred to as 'global' features. It must be noted that the FONT state only has effect when normal and double- height characters are selected; half-width characters use a special predefined character set.

A SIGN OF CHARACTER

Moving on to the character sets themselves, the Spectrum screen under YS MegaBasic can be thought of as having 64 columns and 24 lines. This feature allows half-width characters to be used on-screen; half-width characters can be printed in any column of the screen, whereas normal and double-height characters can only be printed at column
SCROLLING WINDOWS DEMO
10 Selects window 4.

30 Selects window 5.
40 Defines the size and position of window 5, and clears it with white PAPER and blue INK.

60 Defines the size and position of window 6, and clears it with white PAPER and blue INK.

84 Selects window 4.

95 Plots a sine wave.

110 Scrolls window 5 down one pixel.

130 The 'NEXT' part of the loop, creating the movement on-screen.
 10 CURRENT_4
 20 WINDOW_6,0,10,64: PAPER 6: INK 1: CLW_0
 30 CURRENT_5
 40 WINDOW_0,12,6,40: PAPER 7: INK 1: CLW_0
 45 MODE_3: PRINT AT 0,10;"MEGA-BASIC"
 50 CURRENT_6
 60 WINDOW_16,12,6,40: PAPER 7: INK 1: CLW_0
 70 MODE_3: PRINT AT 4,10;"MEGA-BASIC";
 80 FOR A=0 TO 255
 84 CURRENT_4
 90 PLOT 255,88-35*SIN (A/128*PI)
 95 PLOT 255,88+35*SIN (A/128*PI)
100 PAN_0,-1
110 CURRENT_5: SCROLLW_-1
120 CURRENT_6: SCROLLW_1
130 NEXT A: GO TO 80
	
20 Defines the size and position of window 4, and clears it with yellow PAPER and blue INK.

45 Prints the message 'MEGABASIC' using double-height characters.
50 Selects window 6.

70 Prints the message 'MEGABASIC' using double-height characters.
80 Sets up a FOR ... NEXT loop (see line 130).

90 Plots a cosine wave.

100 Scrolls window 4 one pixell to the left.

120 Scrolls window 6 up one pixel.
This demonstration creates a central window (window 4) containing a sine and cosine wave moving from right to left. In the top and bottom windows (windows 5 and 6 repsectively) the word 'MEGABASIC' scrolls down and up the screen.

THE COMPLETE
M E G A B A S I C
TUTORIAL - PART 1


positions which have an even number. It must also be noted that although the character resolution has been improved, the colour resolution has not.
The character sets for FONTs 1 and 2 are stored in RAM allowing users to redefine them at will for whatever requirements you may have. Also, characters 128 to 143 are also stored in RAM (the normal Spectrum character set). Thus, it's now possible using the normal method of constructing Spectrum user- definable graphics to obtain up to 229 UDGs - just think of the graphics you'll be able to include in your own Mega-programs!

IN COMMANDS

Before you take a look at the listing I've prepared to illustrate these aspects of YS MegaBasic, have a look through the detailed explanation of each of the commands associated with the creation of windows and the manipulation of the different character sets.
Note that when you're looking through the tables of commands that 'n' denotes a numeric expression and '$' represents a string expression; and expressions shown in brackets are optional. When you're using YS MegaBasic commands which require numeric or string expressions, there's no restriction to the complexity of the expression and all standard ZX Basic functions can be used alongside the new ones.

THE YS MEGABASIC TOKEN


MegaBasic logo

YOU CANNOT BE SERIOUS ...


64-COLUMN TEXT?
THREE CHARACTER SIZES?
QL-STYLE WINDOWS?
TWO CHARACTER FONTS?
SPRITES GALORE?
SINGLE LETTER ENTRY?
NAMED PROCEDURES?

... ON A SPECTRUM!!??


Well, if you've read this far you've probably guessed that we're very serious! It's all possible - on a 48K Spectrum, with or without microdrives. All you need is a copy of YS MegaBasic ... the inexpensive miracle on cassette. Next month, we'll be providing you with a coupon to send off, pricing details of the package and instructions for what to do with this token (especially if you want to be one of the first to transform your computer into a Mega-Spectrum). Be there next month ... and prepare yourself for the unimaginable - the one and only YS MegaBasic!
YS MEGABASIC WINDOW COMMANDS
COMMAND COMMENT
CLW_(n),n This command enables the user to clear a window in a number of different ways. The numeric expression will usually be in the range '0' to '3'; any other number will be taken by the MegaSpectrum to be a '3'. Action taken by CLW depends very much on the value of the numeric expression, as shown below:
(0) - The window is cleared, just as the CLS command on the standard Spectrum;
(1) - The window is cleared with INK instead of PAPER;
(2) - The window is inverted, ie, the INK is turned to PAPER and the PAPER is turned to INK;
(3) - Only the attributes are cleared. This final option allows you to change the colour of a window without clearing the contents of the window.
CURRENT_n This allows the user to select which window is used for output. The variable, n, can be any value between zero and nine; any value outside these limits will result in an 'illegal window' error.
DOWN_n,n,$ This command prints a string downwards in the current window. The two numeric expressions give the co-ordinates from which the string should be printed.
FX_n,n This is a general command enabling the user to control the way in which the YS MegaBasic system operates. FX calls values of '0', '1', '2' and '3', allowing users the option of which windows are used for specific tasks by the system. For example, FX_0,n selects which window is used for command input, FX_1,n decides the window used for automatic listings, FX_2,n selects the window used as the default program output window and FX_3,n decides the window used by the Front Panel. Using each of these FX calls, it's possible to use the same window for all four functions!
PAN_n,n This command's used to scroll the current window to the left or right, pixel-by-pixel. The first expression defines whether the window is filled with INK or PAPER, and the second controls which direction and by how many pixels the window should be scrolled.
PANW_n This is similar to PAN, except that the window's contents wrap around; that is, what comes off one side of the window automatically appears at the other side.
SCROLL_n,n This command is similar to PAN, except for the fact that the window is scrolled up and down instead of left and right.
SCROLLW_n Again, the equivalent to PANW, except that it controls up and down scrolling instead of movement left and right.
WINDOW_n,n,n,n This command defines the size and position of the current window. When the command is executed, the position of the cursor is reset to the top left corner of the window. The first two numerical expressions define the position of the window - first the Y co-ordinate, then the X co-ordinate. The second two expressions define the depth and width of the window respectively; if either of these two expressions are zero, you'll get a 'window too small' error. If the Y co-ordinate plus the depth give a window greater than 24 lines, or the X co-ordinate and the width give a window greater than 64 columns, a 'window too large' error will be produced.
YS MEGABASIC CHARACTER COMMANDS
COMMAND COMMENT
FONT_n This command selects the character set used for screen output. FONT_O gives you the standard ZX Basic character set, and FONT_1 and FONT_2 select between the two RAM character sets. If you use a value of 'n' that's greater than two, then FONT_2 is assumed.
MODE_(n),n The MODE command enables the character size to be used for printing. If two expressions are specified, the first value denotes the window whose character size is to be defined and the second expression is the character size to be selected. If you use only one expression, it's assumed that any alteration is carried out on the current window. The value of 'n' should be '1', '2' or '3'; any other value given will mean that no characters are printed - quite useful if you want to switch off a particular window.
PRINT CHR$ Character sizes can also be defined in a PRINT statement by use of control codes. Character sizes '1', '2' and '3' are now used to select the character size for the current window, ie, PRINT CHR$; "MEGABASIC" would print the message 'MEGABASIC' using double-height characters.
The above tables detail the commands associated with the construction of windows and the manipulation of character sets.

. . STOP PRESS . . . STOP PRESS . . . STOP PRESS . . . STOP PRESS . .
Being given a deadline for a piece of software that's taken me over a year to produce, I couldn't resist adding a few final touches to make it last just that bit longer in the marketplace ... and also to make it more user-friendly!
You may have noticed in this month's tutorial a brief mention of the Front Panel. Well, to explain that a little, the Front Panel allows the user to get to the heart of the Spectrum - the Z80 processor itself. Thus, you can easily alter the contents of the registers and alter the way the Spectrum operates.
Entering the Front Panel using the command MON' (or pressing the Space and 'F' key together) produces a display showing the current piece of memory in yellow and the registers in cyan. At the bottom of the display is a green cursor which the user can use to enter bytes into memory by typing their values in hexadecimal. Each time a value is entered, the current memory location is advanced by one or, if a change isn't needed, you can just press Enter. Stepping back through memory is just as easy using the minus key.
As well as entering bytes into memory, users can also make use of other features using the single-letter commands shown below. If you make a mistake, not to worry, any command can be aborted simply by pressing the Space key.

Note that in the table on the right, the variable 'n' represents a hexadecimal number.
MEGABASIC FRONT PANEL COMMANDS
COMMAND COMMENT
In,n,n Fills a block of memory with a certain value.
Jn Calls a machine code routine at the address specified by the user.
Ln,n,n Moves a block of memory from one location to another.
Mn Sets the current memory location to the address specified by the user.
P Advances the current register pointer.
Rn Enters a value into the current register.
S Sets a 'break-point' at the current memory location. (A 'break-point' is a piece of machine code which transfers control to the Front Panel; so if you set a break-point at a certain address, when the processor reaches that address the Front Panel will appear.)
Un Recovers the break-point. This command restores the machine code which was over-written by the break-point code.
Home Contents KwikPik