|★ APPLICATIONS ★ CREATION GRAPHIQUE ★ PCG DESIGNER ★|
|Pcg Designer|The Amstrad User)||Applications Creation Graphique|
We have received many character redefining programs in the past but most of them were the same so did not get published.
This one is different, in that the output is saved to disc as a Basic program to be later incorporated into a main program.
Have you ever played a game, such as Roland In Time, and taken a close look at some of the animated characters that move around the screen at great speed. These, as you might already know, are achieved by re-defining a character from the ASCII code to make it appear as something different.
When I redefine a character, I find it is easier to draw up a few eight by eight squares on graph paper. The reason the square is eight by eight is because each character is built up of 64 tiny squares called pixels. The pixel lengths vary depending on which Mode you are in at the time. For example in Mode 0 the pixels are twice the length as they are in Mode 1, and in Mode 2 they are half the size as they are in Mode 1. This gives the effect of 'fat' letters in Mode 0, 'square' letters in Mode 1 and 'skinny' letters in Mode 2.
After ruling up your squares you can start to draw in your picture. Take a look at Fig 1.1 and you will notice I have already drawn a picture of a tractor, which appears at the start of the program accompanying this article.
As you can see some squares are filled and some are not, this is because the filled squares are the ones I want to be able to see and display and the ones left blank will show nothing.
So how do we go about making our pretty picture show up on the screen? To answer this question you must be familiar with the use of binary numbers. Now this all sounds very complicated but is very easy when you know how. The method has been explained in previous issues of The Amstrad User, but it will do no harm to take another look.
Unlike our daily decimal number system (1 to 9), binary numbers consist of just two numbers, these are "0" and "1".
How can we use binary numbers to re-define characters ? This is a very simple process but to accomplish it you have to understand the structure as shown in the following table:
As you can see it is a typical 8*8 grid except it has a few numbers up the top. It also has a few filled squares on each line. For each line across, a string of binary numbers (1's and 0's) are used to identify which squares are filled (the l's) and which are not (the 0's). The position of the l's determines the value they take from the top of the grid. So, to turn a binary number into a decimal number it is important that you know the eight values on the top row of the grid. As they never change, it is easy to remember.
Let me give you an example. We'll take the binary number 10110011 and turn it into a decimal number. There are two ways we can tackle this problem, we can either use the computer to work it out or solve it mathematically.
Using the computer type the following:
PRINT &X10110011 (ENTER)
The screen should look like this:
To solve this problem mathematically we first have to break the number up into eight separate numbers: 1,0,1,1,00,1,1.
By referring back to the grid we can see that if the first number from the right is a "1" it is equivalent to the value 128, if it was a "0" it would have a value of zero. Added onto this number is the value of the next number which happens to be a zero. If this number was a "1" it would have the value of 64. Can you see the pattern that is being used? After adding all the eight values you will come up with the value 179. This means that the number 179 is equal to the binary number of 10110011.
This sti'J doesn't explain how binary numbers can be used to redefine characters. Take another look at the tractor in Fig 1.1. again. The middle three 8*8 grids are the same as in Fig 1.3.
In the first square what is the binary number for the top line? If your answer came out to be 00000001 then you were correct. Next look at the other numbers in turn and write down their decimal equivalent.
When you have finished you should have a list of eight numbers looking like this:
If you take a close look at the above set of binary numbers, espacially the 1's, they form similar pattern to the picture in the first square in the second row. By changing these binary numbers into decimal numbers the computer will know what the shape will look like, and to do this we use the SYMBOL command.
When using the symbol command we do net worry about using the binary numbers but we use their decimal equivalent. Page 79 chapter 3 in the Instruction Manual tells you what each parameter in the symbol command docs, so when using the command it should look like this:
SYMBOL 65,1,0,63,127,96,127, 125,79 (enter)
NOTE: In this example, the number 65 means character 65, which is the letter A.
When you execute the above line you would have re-defined that letter. Press the key marked A and try it, but remember it must be an upper case A.
This is all very fine so how does P.C.G. Designer help me? P.C.G. Designer is a utility that redefines characters for the user.
It takes the eight binary numbers from each square and converts them to decimal and then saves them to disc as a basic program.
Lets have a look at the program and see how it works. The main part of the program starts at line 180. You may have noticed two input statements in the previous two lines.They collect information from the user to tell the computer how many times to go through the loop.
In the main program the following variables are used:
All the binary to decimal conversions are done in line 300 and is a lit lie too complicated to explain in this article.
To use the program simply answer the questions at the start arid then enter in your binary numbers, the program will do the rest.
The basic program creatcd is called SPRITE.BAS and is kept under the string of DISCNAMES which is defined in line 640. Make sure if you re-run the program, that your original SPRITE.BAS does not get overwritten (unless you want it to), by saving it under another name.
I hope you enjoy using P.C.G. Designer. It should take a lot of the hard work out of designing characters.
Note: This program was written fur the CPC664/CPC6128 but can be run on the CPC464 (with disc drive attached)-providing the 'FRAME' command in line 1400 is rephced with "CALL &BD19"