===============================================================================
Date: 11-15-95 Time: 09:22p Number: 1412
From: andrew clarke Refer:
To: Elliot Tobin Board ID: FIX Reply:
Subject: Hey! 132: fido.en.c_ec Status: Public
-------------------------------------------------------------------------------
> Does anybod have some code on fading in and out?
/*
fadethng.c; fade da VGA screen in and out.
Copyright (c) 1995 by Andrew Clarke. Based on code by Mike Jabour.
Released to the public domain.
*/
#include
#include
unsigned char pal[256][3];
void set_mcga(void)
{
_asm {
mov ax,0x0013
int 0x10
}
}
void set_text(void)
{
_asm {
mov ax,0x0003
int 0x10
}
}
void wait_retrace(void)
{
_asm {
mov dx,0x03da
}
l1:
_asm {
in al,dx
and al,0x08
jnz l1
}
l2:
_asm {
in al,dx
and al,0x08
jz l2
}
}
void get_pal(unsigned char color_no, unsigned char *r, unsigned char *g,
unsigned char *b)
{
outp(0x03c7, color_no);
*r = (unsigned char) inp(0x3c9);
*g = (unsigned char) inp(0x3c9);
*b = (unsigned char) inp(0x3c9);
}
void set_pal(unsigned char color_no, unsigned char r, unsigned char g, unsigned
char b)
{
outp(0x03c8, color_no);
outp(0x3c9, r);
outp(0x3c9, g);
outp(0x3c9, b);
}
void fade_up(void)
{
unsigned char i, j, tmp[3];
for(i = 1; i < 64; i++) {
wait_retrace();
for(j = 0; j < 255; j++) {
get_pal(j, &tmp[0], &tmp[1], &tmp[2]);
if (tmp[0] < pal[j][0])
tmp[0]++;
if (tmp[1] < pal[j][1])
tmp[1]++;
if (tmp[2] < pal[j][2])
tmp[2]++;
set_pal(j, tmp[0], tmp[1], tmp[2]);
}
}
}
void fade_down(void)
{
unsigned char i, j, tmp[3];
for(i = 1; i < 64; i++) {
wait_retrace();
for(j = 0; j < 255; j++) {
get_pal(j, &tmp[0], &tmp[1], &tmp[2]);
if (tmp[0])
tmp[0]--;
if (tmp[1])
tmp[1]--;
if (tmp[2])
tmp[2]--;
set_pal(j, tmp[0], tmp[1], tmp[2]);
}
}
}
void save_palette(void)
{
unsigned char i, j;
for(i = 1; i < 64; i++) {
wait_retrace();
for(j = 0; j < 255; j++) {
get_pal(j, &pal[j][0], &pal[j][1], &pal[j][2]);
}
}
}
int main(void)
{
save_palette();
fade_down();
getch();
fade_up();
return 0;
}
--- Msgedsq/2 3.20
* Origin: Blizzard of Ozz, Melbourne, Australia (3:635/727.4@fidonet)
===============================================================================