Your Spectrum
YS MegaBasic manual - Screen Output
Home YS MegaBasic Contents

SCREEN OUTPUT

WINDOWS

The size and shape of characters and the way in which they can be output are factors that have been greatly improved by YS MegaBasic. It's now possible, for instance, to confine output to a particular area of the screen; this area can be of any size and, as you'll have seen when loading, it can even cover the whole screen. These areas are referred to as 'windows', each window having a number You can have up to ten windows on the MegaSpectrum - numbered zero to nine - and all can be utilised in your programs (although, as mentioned earlier, windows zero to three are already being used by the system).
  When you run your program, all PRINT statements use window two automatically. However, it's possible to switch to another window using the command 'CURRENT_'. The command word is followed by a single numeric expression - the number of the window to be used for all subsequent output. If the expression results in a value greater than nine then you'll get the "Illegal window" error message up on-screen. It's also possible using 'CURRENT_' to manipulate three windows at once, switching between each in turn.
  As mentioned earlier, a window can be any size and take up any position on the screen. The 'WINDOW_' command is used to define the size and position of the current window and it takes the form:

  WINDOW_y,x,d,w

Where: 'y' (the line position of the top left-hand corner of window 'y') can be from zero to 23; 'x' (the column position of the top left corner of window 'x') can be from zero to 63; 'd' is the depth of the window in character lines; and 'w' is the width of the window in character columns. As YS MegaBasic incorporates 64-column characters the screen can now be thought of as being 64 character columns across and 24 character lines down.
  The standard Spectrum functions ATTR and SCREEN$ still use
6.b

the old co-ordinate system, but PRINT AT uses the new system. Also, the PRINT AT co-ordinates are relative to the top left-hand corner of the current window, whereas ATTR and SCREEN$ use absolute screen co-ordinates.
  Thus, if 'y+d' is greater than 24 or 'x+w' is more than 64, you'll get the error message "Window too large"; if the values of 'd' or 'w' are less than zero, you can expect the "Window too small" error message. After a 'WINDOW_' command has been executed the print position is reset to the top left-hand corner of the window.

CLS AND CLW

The standard command CLS is used to clear the whole screen - which isn't much use if you just want to clear a single window. Therefore, a new command 'CLW_' is provided to perform this task. The command word is followed by one or two numbers. If two are supplied, then the first is the number of the window to be cleared and the second shows what type of 'clear' is required; if only one number is supplied then the current window is used. There are four different types of action available from the 'CLW_' command (where 'n' is the window number):
CLW_n,0 Clears a window as normal using the current permanent colours.
CLW_n,1 Clears a window as normal using the current permanent colours, but clears with INK instead of PAPER.
CLW_n,2 Inverts the contents of the window. This option changes INK to PAPER and PAPER to INK.
CLW_n,3 Clears the attributes only. This option allows the user to change the colours of a window, without destroying its contents.
In all cases the print position is reset to the top left-hand corner of the window.
  The 'CLW_' command always uses the current permanent attributes. So, for example, if the command 'CLW_0,0' was executed and window three was the current window, then window zero would be cleared using the attributes of window three.

PAN AND SCROLL

It's possible, pixel by pixel, to scroll the current window up, down, left and right using the commands' PAN_' and 'SCROLL_'. 'PAN_' scrolls a window sideways and 'SCROLL_' scrolls it vertically. Both commands must be followed by two numbers. The first indicates whether the edge
7

of the window should be filled with INK or PAPER; if it's a one then the edge is filled with INK - if zero, it'll be PAPER. The second number shows in what direction and by how many pixels, the window should be scrolled. With 'PAN_' if the second number is positive then the window is scrolled left to right - if negative, right to left. With 'SCROLL_' if the number is positive the window is scrolled upwards - if negative, it goes downwards.
  It's also possible to make the contents of a window wrap around. This is done using 'PANW_' and 'SCROLLW_'. These two commands are followed by a single number specifying the direction and number of pixels to be scrolled - as with 'PAN_' and 'SCROLL_'. 'PAN_', 'PANW ', 'SCROLL_' and 'SCROLLW_' only affect the display file.
  The 'FX_' command is used to control the way the YS MegaBasic system operates, and a number of 'FX' calls have been set aside to control choice of windows for particular tasks. The 'FX_' command is followed by two numbers, the first being the call required and the second providing any data which the call in question may need. The 'FX_' calls relating to windows are:
FX 0,n Sets the window used for user input and error messages.
FX 1,n Sets the window used for automatic listings.
FX 2,n Sets the window used for user output.
FX 3,n Sets the window used by the front-panel.
Try typing in some example commands to test the theory. For example, 'FX_0,5' will cause the system to use window five to display user input and error messages. And, if you've ever wanted a display like that of the Sinclair QL, then enter and run this short program:

  10 BORDER 0
  20 CURRENT_0: WINDOW_0,0,15,32
  30 PAPER 2: INK 7: CLW_0
  40 CURRENT_1: WINDOW_0,32,22,32
  50 PAPER 1: INK 7: CLW_0
  60 CURRENT_2: WINDOW_15,0,7,32
  70 PAPER 7: INK 1: CLW_0


You can stop any window scrolling at any time, by pressing the 'M' key.

MODE

Characters can now be printed on the screen in four different sizes - using the 'MODE_' command:
8

MODE_n,1 Calls up the 64 column character set where each character is four by eight pixels. This size doubles the maximum horizontal character resolution.
MODE_n,2 Calls up the standard size character set where each character is eight by eight pixels. These are the characters you'll find on the standard Spectrum.
MODE_n,3 Calls up the double height character set where each character is eight by 16 pixels.
MODE_n,4 Calls up the double height / double width character set, where each character is 16 by 16 pixels. This character size allows you to make use of 'stipples'.
The 'MODE_' command can be followed by one or two numbers, in the same way as 'CLW_'; if two numbers are supplied then the first again specifies the window to be used and the second (between one and four) selects the character sizes. Each window can have its own mode and different sized characters can be mixed in the same window.
  When utilising Mode 4, it's possible to introduce a feature called 'stippling', which allows characters to appear shaded. Remember that the characters of Mode 4 are four times the standard size and, as a result, each pixel in the character takes up four pixels on-screen. Thus, using stipples, it's possible to define the pattern of the four dots and to produce a shading effect. The type of pattern used is defined by the command 'STIPPLE_'. The command word is followed by a single numeric expression that indicates the pattern required. Values for the numeric expression should fall between zero and 15, the higher the value the darker the shading; a value of 15 produces solid characters, whereas zero results in the 'printing' of blank spaces.

FONT

The MegaSpectrum has three character sets, as compared to the standard Spectrum's one. Selection of the character set is effected by 'FONT_', and this command requires a single numeric expression to define whichever one has been chosen. Here's what you get when you use the expression with values between zero and two:
FONT_0 Calls up the standard Spectrum character set we all know and love.
FONT_1 Calls up a character set similar to that used on the BBC Micro and Acorn Electron.
FONT_2 Calls up a character set similar to that used on the Amstrad CPC 464.
9

The 'FONT_' command alters the character set used for all printing; it doesn't just refer to the current window.
  The two new character sets are stored in RAM and thus can be altered by the user if so desired. Each character uses up eight bytes to define its shape (in much the same way as a user-defined graphic). The RAM character sets store the characters from CHR$32 up to CHR$127, the pseudo-BBC Micro character set starts at address 48000, and the pseudo-Amstrad character set starts at address 45000.
  If 'a$' is the character to be defined, then the start of the eight bytes for that character is given by:

  S+8*(CODE a$-32)

Where 'S' is the start of the required character set.

CHR$, VDU AND DOWN

The Spectrum's character set consists of printable characters, and others which affect the way characters are printed - called 'control' characters. A number of new control characters have been included in the MegaSpectrum's character set:
CHR$1-4 Select the mode of the current window.
CHR$7 Inverts the character at the cursor position.
CHR$24-31 Select the window used for output; CHR$24 selects window zero whereas CHR$31 selects window seven.
There's also a new command called 'VDU_' that's directly equivalent to PRINT CHR$. Let's look at some examples:

  VDU_2

This makes all subsequent output appear as standard size characters, whereas the following prints out 'AB':

  VDU_65,66

Strings of characters can be printed down the screen with the 'DOWN_' command. The command takes the form:

  DOWN_y,x,a$

Where: 'y' is the line on which the first character is to be printed; 'x' is the column at which the first character is to be printed; and 'a$' is the string to be printed. If the string runs off the bottom of the window then it wraps around and re-appears at the top.
10

SPRINT AND PRINTER

Moving on to the 'SPRINT_' command' it's now possible to print characters on-screen in any size required. The command takes the form:

  SPRINT_x,y,a,b,a$

Where: 'x' and 'y' mark the pixel position of the first character to be printed; 'a' is the number of times the characters are to be magnified in the x direction; 'b' is the number of times the characters are to be magnified in the y direction; and 'a$' is the string of characters to be printed. If the string goes off the edge of the screen then it'll wrap around and re-appear on the left-hand side. ('SPRINT_' and other YS MegaBasic commands take the screen origin to be the top left-hand corner of the screen, rather than the bottom left.)
  The 'PRINTER_' command is provided to allow screen output to be diverted to a peripheral, such as a printer. This command is followed by a single numeric expression. If the result of that expression is zero the output will go to the screen; if the result is other than zero, then a user supplied routine will be called every time a character is output to the screen. The address of this machine code routine should be stored in the two bytes starting at address 59934. The character to be printed is supplied in the accumulator and the routine is terminated by a 'RET' instruction.
  It's most important that the following commands should notbe used when operating YS MegaBasic: 'CLEAR #', 'OPEN #2'and 'CLOSE #2' - othenwise a system crash will result.
11.a