Author : Grant Smith
Page : << Previous 2 Next >>
Returns: None
Registers destroyed: AX, SP, BP, SI, DI
As seen from our SetMCGA example, you would write this by doing the following:
[PASCAL]
Procedure INTPutpixel (X,Y : Integer; Col : Byte);
BEGIN
asm
mov ah,0Ch
mov al,[col]
mov cx,[x]
mov dx,[y]
mov bx,[1]
int 10h
end;
END;
[C++]
void INTPutpixel(int x, int y, unsigned char Col) {
_AH = 0x0C;
_AL = Col;
_CX = x;
_DX = y;
_BX = 0x01;
geninterrupt (0x10);
}
The X would be the X-Coordinate, the Y would be the Y-Coordinate, and the Col
would be the color of the pixel to place. Note that MCGA has 256 colors,
numbered 0 to 255. The startoff pallette is pretty grotty, and I will show
you how to alter it in my next lesson, but for now you will have to hunt for
colors that fit in for what you want to do. Luckily, a byte is 0 to 255
[in C++ syntax, "byte" = "unsigned char"], so that is what we pass to the col
variable. Have a look at the following.
CGA = 4 colours.
4x4 = 16
EGA = 16 colors.
16x16 = 256
VGA = 256 colors.
Therefore an EGA is a CGA squared, and a VGA is an EGA squared ;-)
Anyway, back to reality. Even though the above procedure/function is written
in assembly language, it is slooow. Why? I hear your enquiring minds cry.
The reason is simple : It uses interrupts (It calls INT 10h). Interrupts are
sloooow ... which is okay for getting into MCGA mode, but not for trying
to put down a pixel lickety-split. So, why not try the following ...
[PASCAL]
Procedure MEMPutpixel (X,Y : Integer; Col : Byte);
BEGIN
Mem [VGA:X+(Y*320)]:=Col;
END;
[C++]
void MEMPutpixel (int x, int y, unsigned char Col) {
memset(vga+x+(y*320),Col,1);
}
The Mem/memset command, as we have seen above, allows you to point at a
certain point in memory ... the starting point is a000h, the base of the
VGA's memory, and then we specify how far into this base memory we start.
Think of the monitor this way. It starts in the top left hand corner at
0. As you increase the number, you start to move across the screen to your
right, until you reach 320. At 320, you have gone all the way across the
screen and come back out the left side, one pixel down. This carries on
until you reach 63999, at the bottom right hand side of the screen. This
is how we get the equation X+(Y*320). For every increased Y, we must
increment the number by 320. Once we are at the beginning of the Y line
we want, we add our X by how far out we want to be. This gives us the
exact point in memory that we want to be at, and then we set it equal to
the pixel value we want.
The MEM methood of putpixel is much faster, and it is shown in the sample
program at the end of this lesson. The ASPHYXIA team uses neither putpixel;
we use a DMA-Straight-To-Screen-Kill-Yer-Momma-With-An-Axe type putpixel
which is FAST. We will give it out, but only to those of you who show us
you are serious about coding. If you do do anything, upload it to me,
I will be very interested to see it. Remember : If you do glean anything
from these training sessions, give us a mention in your demos and UPLOAD
YOUR DEMO TO US!
Well, after this is the sample program; have fun with it, UNDERSTAND it,
and next week I will start on fun with the pallette.
See you all later,
- Denthor
[Note: things in brackets have been added by Snowman. The original text
has remained mostly unaltered except for the inclusion of C++ material]
Introduction
Hi there again! This is Grant Smith, AKA Denthor of ASPHYXIA. This is the
second part of my Training Program for new programmers. I have only had a
lukewarm response to my first part of the trainer series ... remember, if
I don't hear from you, I will assume that you are all dead and will stop
writing the series ;-). Also, if you do get in contact with me I will give
you some of our fast assembly routines which will speed up your demos no
end. So go on, leave mail to GRANT SMITH in the main section of the
MailBox BBS, start up a discussion or ask a few questions in this Conference,
leave mail to ASPHYXIA on the ASPHYXIA BBS, leave mail to Denthor on
Connectix, or write to Grant Smith,
P.O.Box 270
Kloof
3640
See, there are many ways you can get in contact with me! Use one of them!
In this part, I will put the Pallette through it's paces. What the hell is
a pallette? How do I find out what it is? How do I set it? How do I stop
the "fuzz" that appears on the screen when I change the pallette? How do
I black out the screen using the pallette? How do I fade in a screen?
How do I fade out a screen? Why are telephone calls so expensive?
Most of these quesions will be answered in this, the second part of my
Trainer Series for Pascal.
What is the Pallette?
A few weeks ago a friend of mine was playing a computer game. In the game
there was a machine with stripes of blue running across it. When the
machine was activated, while half of the the blue stripes stayed the same,
the other half started to change color and glow. He asked me how two stripes
of the same color suddenly become different like that. The answer is simple:
the program was changing the pallette.
As you know from Part 1, there are 256 colors in MCGA mode, numbered 0 to 255.
What you don't know is that each if those colors is made up of different
intensities of Red, Green and Blue, the primary colors (you should have
learned about the primary colors at school). These intensities are numbers
between 0 and 63. The color of bright red would for example be obtained by
setting red intensity to 63, green intensity to 0, and blue intensity to 0.
This means that two colors can look exactly the same, eg you can set color 10
to bright red and color 78 to color bright red. If you draw a picture using
both of those colors, no-one will be able to tell the difference between the
two.. It is only when you again change the pallette of either of them will
they be able to tell the difference.
Also, by changing the whole pallette, you can obtain the "Fade in" and "Fade
out" effects found in many demos and games. Pallette manipulation can become
quite confusing to some people, because colors that look the same are in fact
totally seperate.
How do I read in the pallette value of a color?
This is very easy to do. To read in the pallette value, you enter in the
number of the color you want into port $3c7 [0x03C7], then read in the values
of red, green and blue respectively from port $3c9 [0x03C9]. Simple, huh? Here
is a procedure that does it for you :
[Pascal]
Procedure GetPal(ColorNo : Byte; Var R,G,B : Byte);
{ This reads the values of the Red, Green and Blue values of a certain
color and returns them to you. }
Begin
Port[$3c7] := ColorNo;
R := Port[$3c9];
G := Port[$3c9];
B := Port[$3c9];
End;
[C++]
void GetPal(unsigned char ColorNo, unsigned char &R,
unsigned char &G, unsigned char &B) {
outp (0x03C7,ColorNo); // here is the pallette color I want read
R = inp (0x03C9);
G = inp (0x03C9);
B = inp (0x03C9);
}
How do I set the pallette value of a color?
This is also as easy as 3.1415926535897932385. What you do is you enter
Page : << Previous 2 Next >>