Your Spectrum
YS MegaBasic manual - Graphics
Home YS MegaBasic Contents

GRAPHICS

CHANGE AND SWAP

YS MegaBasic includes a number of commands which allow the user to directly manipulate the attributes file. 'CHANGE_' is a new command that permits alteration of certain parts of each attribute byte, while still leaving the others intact. The command word is followed by two numeric expressions, representing the 'mask' and the data. The mask, which is used to show the bits in each attribute byte that are to be changed is best thought of in its binary form - if a bit in the mask is one, then the corresponding bit in the attribute byte is to be changed. The data shows the changes to be made. This procedure is accomplished by the following steps:
11.b

CHANGE_1 The mask is negated - all ones are turned to zeros and all zeros are turned to ones.
CHANGE_2 Each byte in the attributes file is ANDed with the negated mask.
CHANGE_3 Each attribute byte is ORed with the data byte.
The 'SWAP_' command allows one attribute to be swapped for another. It's followed by two numeric expressions, first the new attribute and second the old. The attribute file is searched and if an 'old' attribute is found then it's replaced by the 'new'.

FADE

The 'FADE_' command can produce some very spectacular effects. Enter and run this short program:

  10 FOR A=0 TO 703
  20 POKE 22528+A, PEEK A
  30 NEXT A
  40 FADE_0


The first three lines just fill the attributes file with random characters ... the last line is the important one!
  The command 'FADE_' is followed by a single numeric expression. The attribute file is searched and any bytes that are equal to this expression are left alone; any that aren't are decremented. This process continues until every byte in the attributes file is equal to the numeric expression.

INVERT

The 'INVERT' command is very simple in that all it does is to invert the whole screen. It scans through each byte in the display file and negates each bit, causing INK to turn to PAPER and PAPER to INK.

DEFG

The way in which user-defined graphics are defined on the standard Spectrum is very cumbersome ... so YS MegaBasic provides the 'DEFG_' command. This requires a single string expression, followed by eight numeric expressions separated by commas. The string shows which graphic is to be defined ('a' to 'u') and the eight numeric expressions show the shape the graphic is to take - the first number being the top row of the character and the last, the bottom.
12

GET AND PUT

It's now possible to store a portion of the screen in memory and then put it back on the screen in a different position. The two commands which accomplish this amazing feat are 'GET_' and 'PUT_'. 'GET_' saves the screen to memory, and 'PUT_' outputs the memory's contents onto the screen. 'GET_' takes the form:

  GET_0,a,y,x,d,w

Where: 'a' is the address at which to start storing the screen information; 'y' is the line number of the top left-hand corner of the area to be saved; 'x' is the column number of the top left-hand corner of the area to be saved; 'd' is the depth of area to be saved (measured in rows of eight pixels, one standard size character square); and 'w' is the width of the area to be saved (again in groups of eight pixels).
  'PUT_' and 'GET_' use the same co-ordinate system as 'ATTR' and 'SCREEN$'. Their co-ordinates are absolute, and not relative to the top left- hand side of the current window - as with 'PRINT AT'.
  The 'GET_' command 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. You can work out the number of bytes taken by one screen area using the equation:

  9*w*d

The 'PUT_' command is the direct opposite of 'GET_' and takes the form:

  PUT_f,a,y,x,d,w

Where: 'f' shows the way the stored information is to be put back on to the screen:
f=0 Screen is overwritten by memory.
f=1 Screen is ORed with memory.
f=2 Screen is XORed with memory.
f=4 Same as 'f=0' but the current attributes are used instead of stored attributes.
f=5 Same as 'f=1' but the current attributes are used.
f=6 Same as 'f=2' but the current attributes are used.
Variables 'a', 'y', 'x', 'd' and 'w' are the same as those defined for the 'GET_' command.
13

SPUT

'SPUT_' is a variation on the 'PUT_' command in that you can not only put information back on to the screen, but you can also enlarge it. 'SPUT_' takes the form:

  SPUT_a,x,y,b,c,w,d

Where: 'a' is the address in memory of the start of the block; 'x' and 'y' are the pixel co-ordinates of the top left-hand corner of where the block is to be plotted ('SPUT_' uses the same co-ordinate system as 'SPRINT_'); 'b' is the number of times the block should be magnified in the x direction; 'c' is the number of times the block should be magnified in the y direction; 'w' is the width of the block in groups of eight pixels (as with 'GET_'); and 'd' is the depth of the block in pixels; the value should be eight times that used by 'GET_' and 'PUT_'.
  '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.
14.a