Before continuing to talk about the other functions of graphics, I would like to apologize to the readers for an error or rather an oversight in the last episode.
On the last part of the CIRCLE command, to be precise on its syntax:
Syntax: CIRCLE [STEP] (X,Y), radius [,Color][, Start, End][,Relationship]
This is the correct one. I forgot to enter the X and Y coordinates.
PAINT
The PAINT function colors a drawing. But there are rules to respect. It must be a closed figure. Even just a pixel gap between one point and another,
it will color the entire screen or everything that is not the same color. All points in the area must have the same color. The point where you start coloring must be inside the enclosed area. To make it clearer, let's use the rhombus program created in the last lesson:
10 SCREEN 2: COLOR 1,15,15: CLS
20 LINE (50,50)-(75,75),6: LINE -(50,100),6
30 LINE -(25,75),6: LINE -(50,50),6
40 PAINT(75,75),6
50 GOTO 50
After drawing the four lines that form the rhombus, with the PAINT function I gave the coordinates of the point to be colored within the area, using the same color as the aforementioned ones. If we try to change the color of one of the lines
or the color of the PAINT, it will color the entire screen.
The correct syntax is: PAINT(HorizontalCoordinate,VerticalCoordinate),[Color code]. If we omit the color code it will take the foreground one.
DRAW
DRAW is a powerful command for drawing images, or rather, more than a command, it is a real language within Basic that uses its own instructions. It is called GML (Graphic Macro Language), it is a little faster than other Basic instructions and has
a different use than the others. The instructions are placed inside quotes or we can also put them in an alphanumeric variable. For example; Let's draw the round done above with the LINE function:
DRAW “BM50,50F25G25H25E25″ or A$=”BM50,50F25G25H25E25”: DRAW A$. Below I insert the table with all the instructions used by DRAW with relative explanation, where n will be the number of pixels to draw.
Education Meaning
A Draws n pixels upwards
Dn Draws n pixels down
Ln Draws n pixels to the left
Rn Draws n pixels to the right
En Draws n pixels upward diagonally to the right
Fn Draws n pixels down diagonally to the right
Gn Draws n pixels down diagonally to the left
Hn Draws n pixels up diagonally to the left
Mx,y Positions itself at the specified point located in x,y
B Executes the instruction without drawing
N Returns to the previous point after execution
Cc Assigns the color to the drawing, where c must be from 0 to 15
Ar Rotates the image 90°. r must be 0 to 3
Ss Plays the image using a scale of s/4
Xstring Executes instructions inside a string or string variable
The first eight are easy to understand. Unfortunately, we encounter the sore point when drawing the diagonals, the line will always have an angle of 45°, if we want to have a different angle we must use the LINE function. The M instruction allows us to indicate the starting point of the drawing, otherwise it would start drawing from the last positioning of the graphic cursor. We can also use it with variables, just add an equal before and a semicolon at the end.
X=50: Y=50: DRAW “M=X;,=Y;R50F25”. This instruction is like the PSET, in fact you will always see a point where it was placed. To overcome this, we can use the B instruction: DRAW “BM50,50”, we can also use it if we want to draw a line without making it visible: DRAW “BM50,50R50BF25”. If, however, we want to return to the starting point after drawing a segment, just put N in front of the instruction: DRAW “BM50,50NR50”. By doing this we have returned the graphic cursor, after having drawn the straight line on the right, to its initial position; 50.50. If we don't use the C (Color) instruction, it will use the default one, i.e. the one for the foreground, otherwise every time we want to change color just put it first: DRAW “BM50,50C15R50C1F25”. The line going to the right will be white (15), the diagonal one will be black (1). Instruction A, as we said, rotates the image 90° to the right. A=0 is the initial position, so it is unnecessary to use it, but I will tell you later why it is important. A1=90°, A2=180°and A3=270°, if we use a number greater than 3 the MSX will report an error message. If we used the A instruction in our drawing with DRAW, everything we do afterwards with DRAW will be drawn with the last rotation used, so it is preferable to bring it to the real position after each rotation, using A0, unless we want to draw everything from different angles. The S instruction enlarges or decreases the drawn image: by default it is 4, since it reproduces at a scale of 4.
S1 will be a quarter of the image, S2 half, S3 three quarters, S4 four quarters i.e. the real image. After that the image becomes larger; S5 larger than 1/4, S8 will be doubled and so on. An important thing; if an enlarged image
goes beyond the edges of the screen, the MSX will not crop the image but will draw on the last row or column. We cannot use negative or decimal values.
What I said for instruction A also applies to S, that is, once used it will always draw with the last scale reported. The X instruction is used to insert a string into the DRAW instructions. In a string of instructions just put To conclude, I only used uppercase letters inside the DRAW, but we can also use lowercase letters or even mix them, the result does not change.
How to insert character strings in graphical mode As I said in one of the previous lessons, in graphical mode it is not possible to use functions for writing on the screen, such as PRINT, LOCATE etc.
This is because when the MSX works in graphics mode, it uses a separate chip, the TM9918A from Texas Instruments. But we can get around this shortcoming of our MSX by opening the graphics screen device. I won't explain in detail how it works, but you just need to know that to open this device called GRP, you use the OPEN command. Since we will have to write on the graphic screen, the peripheral will be open in output, i.e. in output. In summary: OPEN “GRP:” FOR
OUTPUT AS #1. #1 is the port number we will use, since by default we can only use 1, moreover zero is a reserved number of the MSX, so we are obliged to write the aforementioned. After opening the device we can print on the screen using the PRINT function with the port number: PRINT #1,
“Now I can write graphically.” Mandatory are the pound sign after the PRINT and the comma before inserting the string or variable. To close the device, use the CLOSE #1 command, or just CLOSE. Used without arguments it closes all open devices, but since it's only one, we won't have any problems.
Let's take an example with a program:
10 SCREEN 2: COLOR 1,15,13: CLS
20 OPEN “GRP:” FOR OUTPUT AS #1
30 DRAW “BM10,50C6E15R50F15D30L80U30”: PAINT(30,70),6
40 DRAW”BM10,100″:PRINT #1,”Drawing of a trapezoid”
50 GOTO 50
Line 10 I have activated the graphics and color mode
Line 20 Open device for writing on the graphics screen
Line 30 Drawn and colored a trapezoid
Line 40 DRAW used to position the string print. I could also use PSET(10,100), and finally print the sentence using PRINT with the device number.
Line 50 As you already know, it blocks the program at line 50
If we use PRINT # without having opened the device with OPEN, the MSX will report an error message.
We'll talk again after the Epiphany.
Thank you and Happy Holidays to everyone.


0 Comments