×

Search this site

For your Information. When using the search box on this page you will be directed to an external search engine (freefind.com) which may contain adverts not affiliated to MisterSpectrum.com. If you do not wish to continue please click on the 'X' in the right hand corner of this pop-up.



A summary of YS MegaBasic keywords.


YS MegaBasic



Overview

YS MegaBasic (or sometimes just MegaBasic) is a ZX Spectrum BASIC interpreter extension. It was coded by author Mike Leaman and published by Sportscene Specialist Press through Your Spectrum magazine in 1984. It was available through mail order at a price of £9.95. Thirty five new keywords were added to the Spectrum vocabulary as well as the ability to produce 64 column text, define procedures, create windows and produce enhanced sound effects.

The MegaBasic extension required 19K leaving 22K for user programs.



Commands

Keyword

Meaning

Comments

AUTO_


AUTO_m,n

Result : Produce a line number every time the user presses 'ENTER' in immediate mode.

m is the line number to start at.
n is the increment.
To stop the computer producing line numbers, press the equals (‘=’) key in Extended mode and then press 'ENTER'

BACKUP


BACKUP  (no operands)

Result : Makes a duplicate copy of a tape file.

May crash computer if file is greater than 20Kbytes in length.

DELETE_


DELETE_m,n

Result : Deletes a block of program lines, where m is the first line number of the block and n the last.

If a>b then error message 'B Integer out of range' occurs.

EDIT_


EDIT_m

Result : Display line m in the input line and activate the line editor.

Equivelant of:

LIST n then :

BREAK key (if listing is more than one page)

CAPS SHIFT and 1 (EDIT)

SPEED_


SPEED_m

Result : Controls the speed of program execution when the trace function is active. Any number up to a maximum of 254 makes the
execution progressively more slow.



SPEED_0

Result : Makes the program execute at full speed.



SPEED_255

Result : Will stop after every statement and wait for the user to press a key.

See also TRON

TRON


TRON  (no operands)

Result : Displays the current line number in the bottom left hand corner of the screen

See also SPEED_, TROFF.

TROFF


TROFF  (no operands)

Result : Stops line number display at bottom of screen.

See also SPEED_, TRON.


Statements

Keyword

Meaning

Comments

BRANCH_


BRANCH_m

Result : A subroutine at line m is called at the end of every program line. The subroutine is terminated by ENDPROC_.

If n is zero, then YS Mega Basic acts as normal at the end of each line.

BROFF


BROFF

Result : Disables 'BREAK' key.

'BREAK' key will still function during input or output operations.

See also BRON.

BRON


BRON

Result : Re-enables 'BREAK' key after BROFF.

See also BROFF.

CALL_


CALL_m[,n1,...,nk]

Result : Calls a machine code routine at address m. The address may be followed by a number of numeric expressions.

The expressions n1 to nk are evaluated and the result pushed on to the machine stack; the last expression will be the stack’s top value.

The machine code routine removes all values from the stack and should be terminated by a Z80 ‘RET’ instruction.

CHANGE_


CHANGE_m,n

Result : Changes attributes, the mask (m) is negated with each attribute byte; the data (n) is then ORed with each attribute byte.

See also FADE_, INVERT, SWAP_.

CLW_


CLW_[m,]option

Result : Clear a window. The first number (m) is that of the window to be cleared; where only one number is supplied then the current window is used.

Options

CLW_m,0 - Clears a window as normal using the current permanent colours.

CLW_m,1 - Clears a window as normal using the current permanent colours, but clears with INK instead of PAPER.

CLW_m,2 - Inverts the contents of the window This option changes INK to PAPER and PAPER to INK.

CLW_m,3 - Clears the attributes only. This option allows the user to change thecolours of a window, without destroying its contents.

See also WINDOW_.

CURRENT_


CURRENT_m

Result : Window m becomes the ‘current’ window — all subsequent PRINT statements will now use window m.

See also WINDOW_.

DEFG_


DEFG_α$,m1,...,m8

Result : Define user defined graphic character α$ using m1 to m8 to store 8 bit pattern rows.

Replaces POKE USR α$+row,m.

DOKE_


DOKE_m,n

Result : Place a 16 bit integer (n) into the memory location specified (m). The 16 bit integer will be spread across two memory location as two 8 bit values.

DOKE_ is the equivelant of:

POKE a,b-256*INT(b/256)

POKE a+1,INT(b/256)

DOWN_


DOWN_x,y,α$

Result : Prints a string (α$) downwards in the current window starting at position x,y.

If a string goes off the bottom of a window then it wraps around to the top.

EXAMINE


EXAMINE  (no operands)

Result : Displays the type, name, length and start of any files found on tape.

To escape, use the Break key in the normal way.

FADE_


FADE_m

Result : Decrements each byte in the attributes file unless it’s already equal to m.

The process is repeated until all bytes have achieved that value.

See also CHANGE_, INVERT, SWAP_.

FONT_


FONT_m

Result : Selects the character set m.

Has no effect in Mode 1 (which uses its own special character set).

FX_


FX_m,n

Result : Controls choice of windows for particular tasks.

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 frontpanel.

See also WINDOW_.

GET_


GET_0,address,y,x,depth,width

Result : Store a portion of the screen in memory starting at address

y is the line number of the top lefthand corner of the area to be saved

x is the column number of the top lefthand corner of the area to be saved

depth is the depth of area to be saved (measured in rows of eight pixels, one standard size character square)

width is the width of the area to be saved (in groups of eight pixels).

GET_ uses the same coordinate system as ATTR and SCREEN$. Their coordinates are absolute, and not relative to the top lefthand side of the current window — as with PRINT AT.

GET_ stores the display file information in memory followed by the attribute information.

Use the CLEAR command to reserve a specific piece of memory for storing screen information.

The number of bytes taken by one screen area can be found with the equation: 9*width*depth.

INVERT


INVERT  (no operands)

Result : Whole screen attributes are inverted changing INK to PAPER and PAPER to INK.

See also CHANGE_, FADE_, SWAP_.

KEY_


KEY_m,s$

Result : Defines a user defined key

m is the number of the key to be defined

s$ is the string of characters to be assigned to the key.

Too place an 'ENTER' after the key definition add CHR$ 13 to the end of a$.

MODE_


MODE_[m,]n

Result : Size of the characters for screen output are altered according to n.

The MODE_ statement can be followed by one or two numbers.

If two numbers are supplied then the first (m) specifies the window to be used and the second (n) selects the character sizes (between 1 and 4).
See also CLW_.

MON


MON  (no operands)

Result : Calls up the front-panel (monitor) display.

Allows the user to alter and examine the memory and registers of the Z80. To return to YS MegaBasic, press the 'SPACE' bar.

MTASK_


MTASK_m

Result : A YS MegaBasic program is executed from two different places at once

The program to be run is run from two separate places at once.

The first part continues after the MTASK_ statement and the second starts at line m.

Once multitasking has been activated, the computer executes a line alternately from each part of the program.
If n=0 then multitasking is disabled.

See also BRANCH_.

PAN_


PAN_m,n

Result : Scrolls the current window sideways pixel by pixel.

m determins whether ink (m=0) or paper (m=1) should fill edge.

n is the number of pixels to pan. If n is positive the panning is left-to-right. If negative panning is right-to-left.

This statement only scrolls the display file — the attributes are left alone.

See also PANW_, SCROLL_, SCROLLW_.

PANW_


PANW_m,n

Result : Scrolls the current window sideways pixel by pixel with wraparound.

m determins whether ink (m=0) or paper (m=1) should fill edge.

n is the number of pixels to pan. If n is positive the panning is left-to-right. If negative panning is right-to-left.

This statement only scrolls the display file — the attributes are left alone.

See also PAN_, SCROLL_, SCROLLW_.

PCLEAR


PCLEAR  (no operands)

Result : Clears the PROCedures/REPEAT-UNTIL stack.

Should be executed at the beginning of every program involving the use of procedures or REPEAT-UNTIL loops.

See also REPEAT, UNTIL_.

PLAY_


PLAY_ note,length,start,steps,change

Result : Produces a sound effect.

note produces pure notes (note=0) or white noise (note=1)
length is the length of each step
start is the start frequency
steps is the number of steps
change is the change of frequency alter each step

Not to be confused with the 128K PLAY statement.

POP_


POP_m

Result : A value (m) is removed from the PROCedure/REPEAT-UNTIL stack.

The manual is unclear exactly how POP_ operates.

If POP_ is executed when the stack is already empty, a 'PROC stack underflow' error will occur.

See also PUSH_, REPEAT, UNTIL_.

PRINTER_


PRINTER_m

Result : Screen output is diverted to a peripheral, such as a printer.

This statement 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.

The PRINTER_ statement should be used when communicating with a printer instead of CLEAR #, OPEN # 2, CLOSE # 2, all of which may crash the computer if used whilst running MegaBasic according to the manual.

PUSH_


PUSH_m

Result : Places a number on the PROCedure/REPEAT-UNTIL stack.

The PUSH_ statement is followed by two numeric expressions — the statement number (m) followed by the line number (n).

The manual is unclear exactly how PUSH_ operates.

If PUSH_ is executed when the stack is fill, a 'PROC stack overflow' error will occur.

See also PUSH_, REPEAT, UNTIL_.

PUT_


PUT_m,address,y,x,depth,width

Result : Recall from memory a portion of the screen starting at address

m is how the stored image is going to be displayed on screen.

if m=0 the screen is overwritten by memory.
if m=1 the screen is ORed with memory.
if m=2 the screen is XORed with memory.
if m=4 the screen is overwritten by memory but the current attributes are used instead of stored attributes.
if m=5 the screen is ORed by memory but the current attributes are used instead of stored attributes.
if m=6 the screen is XORed by memory but the current attributes are used instead of stored attributes.

y is the line number of the top lefthand corner of the area to be recalled

x is the column number of the top lefthand corner of the area to be recalled

depth is the depth of area to be recalled (measured in rows of eight pixels, one standard size character square)

width is the width of the area to be recalled (in groups of eight pixels).

PUT_ uses the same coordinate system as ATTR and SCREEN$. Their coordinates are absolute, and not relative to the top lefthand side of the current window — as with PRINT AT.

PUT_ recalls the display file information in memory followed by the attribute information.

The number of bytes taken by one screen area can be found with the equation: 9*width*depth.

See also GET_, SPUT_.

RESTART_


RESTART_m

Result : On error go to line m.



RESTART_OFF

Result : Disables error trapping.



Information is stored in the following locations in memory:

Address 59873/4 The line at which the error occurred.
Address 59875 The statement within the line where the error occurred.
Address 59862 The code of the error that’s occurred.

RESTART_ will not trap either Interface 1 or new YS MegaBasic errors.

SCROLL_


SCROLL_m,n

Result : Scrolls the current window up or down pixel by pixel.

m determins whether ink (m=0) or paper (m=1) should fill edge.

n is the number of pixels to scroll. If n is positive the scrolling is left-to-right. If negative scrolling is right-to-left.

This statement only scrolls the display file — the attributes are left alone.

See also PAN_, PANW_, SCROLLW_.

SCROLLW_


SCROLLW_m,n

Result : Scrolls the current window up or down pixel by pixel with wraparound.

m determins whether ink (m=0) or paper (m=1) should fill edge.

n is the number of pixels to scroll. If n is positive the scrolling is left-to-right. If negative scrolling is right-to-left.

This statement only scrolls the display file — the attributes are left alone.

See also PAN_, PANW_, SCROLLW_.

SOFF


SOFF  (no operands)

Result : Disables the Interupt Sound Generator.

See also SON, SOUND__, SREP_.

SON


SON  (no operands)

Result : Enables the Interupt Sound Generator.

See also SOFF, SOUND__, SREP_.

SOUND_


SOUND_m,α,β,γ,δ

Result : Manipulates the sound buffer.

m clears the sound buffer before replacing it with something new (m=0) or adds sound on to the end of the sound buffer (m=1)
α plays a pure sound (α=0) or white noise (α=1)
β is the value to be added to the frequency after each step
γ is the number of steps in sequence
δ is the number of times the sequence is to be repeated.

See also SOFF, SON, SREP_.

SPRINT_


SPRINT_x,y,m,n,α$

Result : Prints a string on the screen using characters of a predetermined size.

x and y mark the pixel position of the first character to be printed
m 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
α$ is the string of characters to be printed.

If the string goes off the edge of the screen then it will wrap around and reappear on the lefthand side.

.

SPROFF_


SPROFF_m

Result : Turns off sprite operation.

m is number of sprite to be deactivated.

An error in the YS MegaBasic manual 'THE NEW COMMANDS' list states that SPROFF_ has two parameters.

See also SPRON_.

SPRON_


SPRON_m,n

Result : Turns on sprite operation.

m is number of sprite to be activated.
n is how the sprite is plotted on screen.

if n=1 then a logical OR is performed between then sprite pixels and the screen pixels.

if n=2 then a logical XOR is performed between the sprite pixels and the screen pixels.

See also SPROFF_.

SPUT_


SPUT_address,y,x,β,α,depth,width

Result : Recall from memory a portion of the screen starting at address, magnifiying by β and α.

y is the line number of the top lefthand corner of the area to be recalled

x is the column number of the top lefthand corner of the area to be recalled

β is the number of times the block should be magnified in the y direction

α is the number of times the block should be magnified in the x direction

depth is the depth of area to be recalled (measured in rows of eight pixels, one standard size character square)

width is the width of the area to be recalled (in groups of eight pixels).

SPUT_ uses the same coordinate system as ATTR and SCREEN$. Their coordinates are absolute, and not relative to the top lefthand side of the current window — as with PRINT AT.

SPUT_ always uses the current attributes when placing a block on the screen, it therefore doesn’t use the attributes stored in memory with the display file information.

The number of bytes taken by one screen area can be found with the equation: 9*width*depth.

See also GET_, PUT_.

SREP_


SREP_m

Result : If m is zero, then the data stored in the sound buffer will only be played once.
If m is one. the sound buffer’s contents will be repeated forever.

See also SOFF, SON, SOUND_.

STIPPLE_


STIPPLE_m

Result : Defines a pattern of dots to produce a shading effect to characters in MODE_4.

m indicates the pattern required. Values for m 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 display of blank spaces.

See also MODE_.

SWAP_


SWAP_m,n

Result : Swap first the new attribute (m) and second the old (n). The attribute file is searched and if an old attribute is found then it’s replaced by the new.

See also CHANGE_, FADE_.

VDU_


VDU_m1[,...mk]

Result : Display a character with the ASCII code of m1. More than one character may be displayed from m1 to mk.

Equivelant to PRINT CHR$ m;

See also CHR$.

WINDOW_


WINDOW_y,x,depth,width

Result : Create a window of depth and width pointed to by CURRENT_ at position y,x.

See also CLW_, CURRENT_.


Structured Statements

Keyword

Meaning

Comments

@...ENDPROC_


@procedure[_v1,...,vk]

statements

ENDPROC_procedure

Result : Defines a procedure. Optional variables (v1 to vk) may be passed to the procedure. Procedure is exited via ENDPROC_procedure


See also PCLEAR.

REPEAT...UNTIL_


REPEAT

statements

UNTIL_e

Result : Sets up and executes the REPEAT loop and performs statements. UNTIL closes the loop and exits if e is true.


See also PCLEAR, POP_, PUSH_.


Functions

Keyword

Meaning

Comments

CHR$


CHR$ m

Returns : Single character from position m in the character set.

A number of new control characters have been included in the MegaBasic character set:

CHR$ 7 - Inverts the character at the cursor position.
CHR$ 14 - Select the mode of the current window.
CHR$ 24 - Select the window 0 for output.
CHR$ 25 - Select the window 1 for output.
CHR$ 26 - Select the window 2 for output.
CHR$ 27 - Select the window 3 for output.
CHR$ 28 - Select the window 4 for output.
CHR$ 29 - Select the window 5 for output.
CHR$ 30 - Select the window 6 for output.
CHR$ 31 - Select the window 7 for output.
MegaBasic CHR$ works in the same way as the standard ZX Spectrum CHR$ with the exceptions of codes 7, 14, 24 to 31.

On a standard Spectrum CHR$ 7 translates to EDIT (and can be captured with INKEY$ as CAPS-SHIFT & 1); CHR$ 14 translates to a number in a program listing; CHR$ 24 to 31 are not used.





Nomenclature

This list uses the same letters to represent variables, expressions and sequences etc. as the ZX Spectrum BASIC manual.

α,β represents a single letter
v represents a variable
x,y,z represents numerical expressions
m,n represents numerical expressions rounded to the nearest integer
b represents a 16 bit binary number
e represents an expression
f represents a string valued expression
s represents a sequence of statement separated by colons :
c represents a sequence of colour items, each terminated by commas , or semi-colons ; A colour item has the form of a PAPER, INK, FLASH, BRIGHT, INVERSE or OVER statement.

Items in italics are parameters in explanatory word form.

A short note on brackets. Where curved brackets '(' or ')' are shown they are mandatory, this includes the ZX Spectrum 'two parameter' functions and user defined functions.
Where square brackets '[' or ']' are shown the statement, parameter or value inside the bracket is optional.

References

Your Spectrum Software MEGABASIC, Sportscene Specialist Press (publisher)
"COVER STORY - MEGABASIC", Your Spectrum No.8, October 1984, p.50

External Links

Your Spectrum MEGABASIC Manual at World of Spectrum


Last revision : 07/12/2023