DEMO/DEMO.CPP
2021-09-08 20:55:57 +02:00

907 lines
24 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <dos.h>
#include <mem.h>
#include "demo.h"
#include "..\modex\modex.h"
#define ERROR 1
#define OK 0
char *Pato[3], *BufferV;
int LeePato( char *file, char *dir );
void ReducePato( char *Dest, char *Org, char Magn );
void LeeFuentes(char *file);
void JugadorDyna( int x, int y, char mov );
void BombaDyna( int x, int y, char mov );
void MensajeIntermedio(char *buffer);
void FuenteAmplia( char *Frase, p_Ampliada far *FA );
void FuenteAmplia2( char *Frase, p_Ampliada far *FA );
void PatoSimpsons(void);
char *ptr_char;
int XSinMov[256], YSinMov[256];
int TSin[360+90];
/**************************************************************************\
|* *|
|* CargaPaleta *|
|* *|
|* Descripci¢n: *|
|* Carga la paleta con los colores por defecto *|
|* *|
|* *|
|* Entradas: achivo PCX de donde cargar la paleta *|
|* *|
|* Salidas: OK Todo ha ido bien *|
|* ERROR Algo va mal *|
|* *|
\**************************************************************************/
int CargaPaleta(char *file )
{
int index;
FILE *fp;
if ( (fp=fopen( file, "rb" ) ) == NULL )
return ERROR;
if ( fseek( fp, -768L, SEEK_END ) == 0 )
{
for (index=0; index<256; index++)
{
// get the red component
// get the green component
// get the blue component
// set components
Palette256[index][0] = ( ( getc(fp) >> 2 ) )/* *63 )/255*/;
Palette256[index][1] = ( ( getc(fp) >> 2 ) )/* *63 )/255*/;
Palette256[index][2] = ( ( getc(fp) >> 2 ) )/* *63 )/255*/;
} // end for index
}
setvgapalette256( &Palette256 );
fclose( fp );
return OK;
};
void RellenaTablas(void)
{
float angle;
angle = 0;
while( angle < 256 )
{
XSinMov[angle] = YSinMov[angle] = (int)( sin( (M_PI*angle*1.4)/180.0 ) * 180.0) / M_PI;
YSinMov[angle] = 0;
angle+=1;
};
angle = 0;
while( angle < (360+90) )
{
TSin[angle] = (int)(sin( (M_PI*angle)/180.0 ) * 100 );
angle+=1;
};
}
void Put( int x, int y, char c)
{
if ( x < 0 || x >= 320 ) return;
if ( y < 0 || y >= 200 ) return;
// { Written by Matt Sottile }
asm mov ax,y
asm mov bx,ax
asm shl ax,8
asm shl bx,6
asm add bx,ax
asm add bx,x
asm mov ax,0xa000
asm mov es,ax
asm mov al,c
asm mov es:[bx],al
};
//#define RADIO 255
#define RADIO 255
//#define SALTOS_PROFUNDOS 8
#define SALTOS_PROFUNDOS 8
//#define SALTOS_ANCHOS 7
#define SALTOS_ANCHOS 7
#define BLOQUEO_RADIO 1
#define INCREMENTAL 1
#define PROFUNDIDAD_TUNEL 35
//#define FACTOR_SERPIENTE 0.015F
#define FACTOR_SERPIENTE 0.008594366927F
//#define TODO_BLANCO
//#define TODO_GRIS
int PERFECCION_CIRCULO = 8;
// Circulo con impresi¢n de giro ( MEJORA POR JD )
void Circulo( int x, int y, int radio, int giro, int Color )
{
int angle;
for ( angle = 0; angle < 360; angle+=PERFECCION_CIRCULO )
Put( x + (radio*FACTOR_SERPIENTE*TSin[ (giro + angle)%360 + 90 ]), y + (radio*FACTOR_SERPIENTE*TSin[ (giro+angle)%360 ]), angle >= 0 && angle <= 50 ? (Color-PROFUNDIDAD_TUNEL) : (Color) );
};
// Circulo con impresi¢n de giro ( MEJORA POR JD )
void CirculoB( int x, int y, int radio, int giro )
{
int angle;
for ( angle = 0; angle < 360; angle+=PERFECCION_CIRCULO )
Put( x + (radio*FACTOR_SERPIENTE*TSin[ (giro + angle)%360 + 90 ]), y + (radio*FACTOR_SERPIENTE*TSin[ (giro+angle)%360 ]), 0 );
};
void TunelEstrellas(void)
{
int depth, Color;
static unsigned char ZMov = 0;
static int GiroAngular = 0;
unsigned char Movimiento = ZMov;
static Subidon = 255;
static Velocidad = 0;
// Controles de giro por JD:
// SUAVE ZMov
// DURO Movimiento
int OGiroAngular = GiroAngular;
GiroAngular = ( GiroAngular++ ) % 360;
ZMov ++;
Movimiento = ZMov;
Color = 255-PROFUNDIDAD_TUNEL;
// Color = 255;
Velocidad++;
if ( Velocidad == 5 )
{
Velocidad = 0;
// Subidon --; if ( Subidon < 255-PROFUNDIDAD_TUNEL ) Subidon = 255;
Subidon = (Subidon++)%PROFUNDIDAD_TUNEL;
}
for ( depth=0; depth<SALTOS_ANCHOS*PROFUNDIDAD_TUNEL; depth+=SALTOS_ANCHOS*INCREMENTAL, Movimiento+=SALTOS_PROFUNDOS, Color++ )
// for ( depth=INCREMENTAL*SALTOS_ANCHOS*(PROFUNDIDAD_TUNEL-1); depth>=0; depth-=SALTOS_ANCHOS*INCREMENTAL, Movimiento+=SALTOS_PROFUNDOS, Color-- )
{
/*
OGiroAngular = GiroAngular;
GiroAngular = ( GiroAngular++ ) % 360;
*/
// Borra el anterior
CirculoB( XSinMov[(unsigned char)(Movimiento-1)] + 160, YSinMov[(unsigned char)(Movimiento-1)] + 100, RADIO - depth*BLOQUEO_RADIO, OGiroAngular + 0*Movimiento );
Subidon = (Subidon++)%PROFUNDIDAD_TUNEL;
// Dibuja el nuevo circulo
// Circulo( XSinMov[Movimiento] + 160, YSinMov[Movimiento] + 100, RADIO - depth*BLOQUEO_RADIO, GiroAngular + 0*Movimiento, (Subidon >= Color && Subidon <= Color + 2 ) ? 1: Color );
Circulo( XSinMov[Movimiento] + 160, YSinMov[Movimiento] + 100, RADIO - depth*BLOQUEO_RADIO, GiroAngular + 0*Movimiento, Subidon%6 == 0 || Subidon%6 == 1 ? 1+Subidon : Color);
}
delay(10);
}
typedef struct
{
unsigned char R, G, B;
} ColorValue;
typedef ColorValue VGAPaletteType[256];
void ReadPal( VGAPaletteType K )
{
struct REGPACK outR;
outR.r_ax = 0x1017;
outR.r_bx = 0;
outR.r_cx = 256;
outR.r_es = FP_SEG(K);
outR.r_dx = FP_OFF(K);
while( ( inport(0x03DA) & 0x08 ) == 0x08 ); // {Wait for rescan}
intr( 0x10, &outR );
};
void WritePal( VGAPaletteType K )
{
struct REGPACK outR;
outR.r_ax = 0x1012;
outR.r_bx = 0;
outR.r_cx = 256;
outR.r_es = FP_SEG(K);
outR.r_dx = FP_OFF(K);
// while( ( inport(0x03DA) & 0x08 ) == 0x08 ); // {Wait for rescan}
sync_display();
intr( 0x10, &outR );
};
VGAPaletteType Pal;
void CreaPaleta(void)
{
unsigned char I;
memset( Pal, 0, sizeof(Pal) );
Pal[1].R = 255;
Pal[1].G = 255;
Pal[1].B = 255;
Pal[255].R = 20;
Pal[255].G = 0;
Pal[255].B = 0;
for ( I=254/*MaxColor*/; I > 254-PROFUNDIDAD_TUNEL; I-- )
{
Pal[I] = Pal[I+1];
{
if ( Pal[I].R<63 ) Pal[I].R++;
if ( Pal[I].R<63 ) Pal[I].R++;
if ( (I % 2==0) && (Pal[I].G<53) ) Pal[I].G++;
if ( (I % 2==0) && (Pal[I].B<63) ) Pal[I].B++;
}
}
#ifdef TODO_GRIS
Pal[5].R = 255;
Pal[5].G = 255;
Pal[5].B = 255;
for ( I=5; I < 255; I++ )
{
Pal[I] = Pal[I-1];
{
Pal[I].R--;
Pal[I].G--;
Pal[I].B--;
}
}
#endif
Pal[255-PROFUNDIDAD_TUNEL+1].R = 0;
Pal[255-PROFUNDIDAD_TUNEL+1].G = 0;
Pal[255-PROFUNDIDAD_TUNEL+1].B = 20;
for ( I=/*MaxColor*/255-PROFUNDIDAD_TUNEL; I > 255-2*PROFUNDIDAD_TUNEL; I-- )
{
Pal[I] = Pal[I+1];
{
if ( Pal[I].B<63 ) Pal[I].B++;
if ( Pal[I].B<63 ) Pal[I].B++;
if ( (I % 2==0) && (Pal[I].G<53) ) Pal[I].G++;
if ( (I % 2==0) && (Pal[I].R<63) ) Pal[I].R++;
}
}
#ifdef TODO_BLANCO
memset( Pal, 255, sizeof(Pal) );
Pal[0].R = 0;
Pal[0].G = 0;
Pal[0].B = 0;
#endif
WritePal(Pal);
}
#define Longitud_Despedida (64+13)*8
void DynaFin( char *buffer, char *buffer1 )
{
long i; char mov, acel;
int salida, index, x, y;
p_Ampliada Despedida = { 0, 50, 40, 2, 2, 0, 255, 255 };
setvgapalette256( &PaletteDyn );
// Mostramos el mensaje de despedia.
i = 0;
Despedida.AX = 2;
Despedida.AY = 2;
while ( i < Longitud_Despedida )
{
i++;
FuenteAmplia( buffer, &Despedida );
delay(3);
};
i = 0;
// Despedida.y += 30;
Despedida.AX = 1;
Despedida.AY = 1;
while ( i < (28+24)*8 )
{
i++;
FuenteAmplia( buffer1, &Despedida );
delay(3);
};
delay(2000);
// Acercamiento del mu¤eco, colocaci¢n de la bomba, y alejamiento mu¤eco
mov = 1; acel = 0;
for ( x = 320; x > -30; x -=2 )
{
acel = (acel++) % 2;
if ( acel == 1 )
mov = (mov++) % 3;
if ( x < 160 )
BombaDyna( 160, 150, mov-1 );
JugadorDyna( x, 150, mov-1 );
delay(50);
}
// Explosion de la bomba
// Gradiente rapidisimo hasta el blanco
Palette256[64][0] = 32;
Palette256[64][1] = 32;
Palette256[64][2] = 32;
memset( MK_FP( 0xA000, 0 ), 64, 320*200 );
salida = 0;
for( ; salida == 0; )
{
for (index=100; index>=0; index--)
{
// set components
if( Palette256[index][0]<63 ) Palette256[index][0] ++;
if( Palette256[index][1]<63 ) Palette256[index][1] ++;
if( Palette256[index][2]<63 ) Palette256[index][2] ++;
if( Palette256[index][0]==63 && Palette256[index][1]==63 && Palette256[index][2]==63 )
salida = 1;
else
salida = 0;
} // end for index
setvgapalette256( &Palette256 );
}
delay(2000);
// Gradiente algo mas lento hacia el negro
salida = 0;
for( ; salida == 0; )
{
for (index=0; index<256; index++)
{
// set components
if( Palette256[index][0]>0 ) Palette256[index][0] --;
if( Palette256[index][1]>0 ) Palette256[index][1] --;
if( Palette256[index][2]>0 ) Palette256[index][2] --;
if( Palette256[index][0]==0 && Palette256[index][1]==0 && Palette256[index][2]==0 )
salida = 1;
else
salida = 0;
} // end for index
setvgapalette256( &Palette256 );
delay(50);
}
}
void JugadorDyna( int x, int y, char mov )
{
char x1, y1;
if ( mov < 0 )
{
// Borra el mu¤eco anterior
} else {
// Pinta el nuevo mu¤eco
for ( x1=0; x1 < 23; x1++ )
for ( y1=0; y1 < 23; y1++ )
Put( x+x1, y+y1, DynaMovs[mov][y1][x1] );
}
}
void BombaDyna( int x, int y, char mov )
{
char x1, y1;
if ( mov < 0 )
{
// Borra el mu¤eco anterior
} else {
// Pinta el nuevo mu¤eco
for ( x1=0; x1 < 16; x1++ )
for ( y1=0; y1 < 18; y1++ )
Put( x+x1, y+y1, BombMovs[mov][y1][x1] );
}
}
void CirculoGradiente(void)
{
int x, y;
float angle; int radio;
VGAPaletteType K;
ReadPal( K );
K[x].R =0;
K[x].G =0;
K[x].B =0;
// Intentemos mejorar la paleta
for ( x = 1; x <= 127; x++ )
{
K[x].R = K[x-1].R+1;
K[x].G = K[x-1].G+1;
K[x].B = K[x-1].B+1;
}
for ( x = 127; x < 256; x++ )
{
K[x].R = K[255-x].R;
K[x].G = 0*K[255-x].G;
K[x].B = 0*K[255-x].B;
}
// Calculamos los circulos
for ( radio = 1; radio < 320; radio++ )
for ( angle = 0; angle < 360; angle+=0.1 )
{
x = 160 + (radio*sin( angle * M_PI / 180.0 ));
y = 100 + ((radio/*+20*/)*cos( (angle-15) * M_PI / 180.0 ));
if ( x >= 0 && x < 320 && y >= 0 && y < 200 )
Put( x, y, (radio%(255/*-32*/))/*+32*/ );
}
clock_t start, end;
start = clock();
while( ( ( clock() - start) / CLK_TCK ) < 30 )
{
for ( x = 0; x < 256; x++ )
K[x]=K[ (x+1)%255+1 ];
WritePal( K );
}
};
/*************************************************************************\
|* *|
|* El control es poder, y aqui esta el control de todo el demo... *|
|* *|
|* *|
|* *|
|* *|
|* *|
|* *|
|* *|
|* *|
|* *|
|* *|
\*************************************************************************/
void main(void)
{
int ok;
if ( ( ptr_char = (char *)malloc( 4096*sizeof(char) ) ) == NULL )
return;
LeeFuentes( "demo.fnt" );
RellenaTablas();
// Cambiamos a modo grafico
asm mov ax, 0x13
asm int 0x10
while( kbhit() ) getch();
//°±±²²²ÛÛÛþþ þ þ Tunel de Estrellas (JD) þ þ þþÛÛÛ²²²±±°
PatoSimpsons();
MensajeIntermedio( "Que tal un poco de plasma para tus ojos" );
CirculoGradiente();
MensajeIntermedio( "Waooo, eso ha estado bien, pero esto estar  aun mejor" );
//°±±²²²ÛÛÛþþ þ þ Tunel de Estrellas (JD) þ þ þþÛÛÛ²²²±±°
CreaPaleta(); // ¨ Porque no mejoramos la paleta 16x2 ?
ReadPal(Pal);
clock_t start, end;
start = clock();
while( ( ( clock() - start) / CLK_TCK ) < 30 )
TunelEstrellas();
MensajeIntermedio( "Y por si fuera poco, miraa esto:" );
//°±±²²²ÛÛÛþþ þ þ Mensaje y dyna poniendo una bomba þ þ þþÛÛÛ²²²±±°
DynaFin( " Agradecimiento a todos los que han hecho posible este demo. ", " Jose David Guillen 1997 (c)" );
// Cambiamos a modo texto
asm mov ax, 3
asm int 0x10
/*
gotoxy(1,1);
cprintf( "C:\\>");
sleep(30);
cprintf( "\n\r Que no me he quedao' colgao' tio... " );
cprintf( "\n\r -- Hasta el proximo intro -- " );
cprintf( "\n\r Jos David Guilln 1997 (c) " );
cprintf( "\n\r " );
*/
free ( ptr_char );
}
void MensajeIntermedio(char *buffer)
{
char buffer1[500];
long i, len;
p_Ampliada Despedida = { 0, 50, 40, 1, 1, 0, 200, 200 };
memset( MK_FP( 0xA000, 0 ), 0, 320*200 );
while( kbhit() ) getch();
i = 0;
sprintf( buffer1, " %s", buffer );
len = (strlen( buffer1 ))*8;
while ( i < len )
{
i++;
FuenteAmplia2( buffer1, &Despedida );
delay(3);
};
memset( MK_FP( 0xA000, 0 ), 0, 320*200 );
}
/////ÜÜ/////////////////////////////////////////////////////////////////////////////
////Û/////////////////////////////////////////////////////////////////////////////////
/////ßÜ/////Ü///////////////////////////////////////////////////////////////////////
//////ß///Ü////ß/Ü//////////////////////////////////////////////////////////////////
///////ß/Ü///Ü//////////////////////////////////////////////////////////////////////
////////Ü//ß////ß///////////////////////////////////////////////////////////////////
/////////ß////Ü/////////////////////////////////////////////////////////////////////
///////////ß////////////////////////////////////////////////////////////////////////
#define TAMx 8
#define TAMy 16
void FuenteAmplia( char *Frase, p_Ampliada far *FA )
{
int i, j, k; // Variables de avance
int c_elec; // Color en el momento de imprimir
int PosX, PosY; // Posicion fisica final
char LCaract; // Caracter de linea a tratar
if ( FA->Flen != _fstrlen( Frase ) ) // Reseteamos las variables de control interno
{
// Obtenemos la longitud de la frase. ( En d¡gitos )
FA -> Flen = _fstrlen( Frase );
// Contador de digito actual a cero
FA -> BitByte = 0;
// Posicion dentro de la frase
FA -> currByte = 0;
}
// Avance horizontal de bit's ( avance de digitos )
for ( i = 0; i < ( TAMx * (FA -> ndigitos) ); i++ )
{
k = ( Frase[ ( (i+FA->BitByte)/TAMx + FA -> currByte ) % FA->Flen ] ) << 4;
LCaract = ( (char)0x01 << (7 - (i+FA->BitByte)%TAMx) );
PosX = FA -> x + FA->AX * i; // Posicion f¡sica horizontal
// Avance vertical de bit's
for ( j = 0; j < TAMy; j ++ )
{
PosY = FA -> y + FA->AY * j; // Posicion f¡sica vertical
if ( ptr_char[ k + j ] & LCaract )
c_elec = FA->C2;
else
c_elec = FA->C1;
Put ( PosX, PosY, c_elec );
}
}
// Tenemos en cuenta el avance dentro de la frase
if ( ( FA -> BitByte ++ ) >= 7 )
{
FA -> BitByte = 0; FA -> currByte ++;
if ( FA -> currByte >= FA -> Flen )
FA -> currByte = 0;
}
}
#undef TAMy
#undef TAMx
#define TAMx 8
#define TAMy 16
void FuenteAmplia2( char *Frase, p_Ampliada far *FA )
{
int i, j, k; // Variables de avance
int c_elec; // Color en el momento de imprimir
int PosX, PosY; // Posicion fisica final
char LCaract; // Caracter de linea a tratar
if ( FA->Flen != _fstrlen( Frase ) ) // Reseteamos las variables de control interno
{
// Obtenemos la longitud de la frase. ( En d¡gitos )
FA -> Flen = _fstrlen( Frase );
// Contador de digito actual a cero
FA -> BitByte = 0;
// Posicion dentro de la frase
FA -> currByte = 0;
}
// Avance horizontal de bit's ( avance de digitos )
for ( i = 0; i < ( TAMx * (FA -> ndigitos) ); i++ )
{
k = ( Frase[ ( (i+FA->BitByte)/TAMx + FA -> currByte ) % FA->Flen ] ) << 4;
LCaract = ( (char)0x01 << (7 - (i+FA->BitByte)%TAMx) );
PosX = FA -> x + FA->AX * i; // Posicion f¡sica horizontal
// Avance vertical de bit's
for ( j = 0; j < TAMy; j ++ )
{
PosY = FA -> y + FA->AY * j; // Posicion f¡sica vertical
if ( ptr_char[ k + j ] & LCaract )
c_elec = /*FA->C2*/PosX;
else
c_elec = FA->C1;
Put ( PosX, PosY, c_elec );
}
}
// Tenemos en cuenta el avance dentro de la frase
if ( ( FA -> BitByte ++ ) >= 7 )
{
FA -> BitByte = 0; FA -> currByte ++;
if ( FA -> currByte >= FA -> Flen )
FA -> currByte = 0;
}
}
#undef TAMy
#undef TAMx
/* Setvgapalette256 sets the entire 256 color palette */
/* PalBuf contains RGB values for all 256 colors */
/* R,G,B values range from 0 to 63 */
/* Usage: */
/* DacPalette256 dac256; */
/* */
/* setvgapalette256(&dac256); */
void setvgapalette256(DacPalette256 *PalBuf)
{
struct REGPACK reg;
reg.r_ax = 0x1012;
reg.r_bx = 0;
reg.r_cx = 256;
reg.r_es = FP_SEG(PalBuf);
reg.r_dx = FP_OFF(PalBuf);
// while( ( inport(0x03DA) & 0x08 ) == 0x08 ); // {Wait for rescan}
sync_display();
intr(0x10,&reg);
}
/*************************************************************************\
|* *|
|* LeeFuentes *|
|* *|
|* Descripcion: *|
|* Lee el conjunto de fuentes del archivo especificado *|
|* *|
|* Entradas: puntero al nombre del archivo *|
|* *|
|* Salidas: (ninguna) *|
|* *|
\*************************************************************************/
void LeeFuentes(char *file)
{
FILE *fich;
/* Reservamos 4 Kb. para cargar la fuente en memoria */
/* Abrimos el fichero de la fuente */
if ((fich=fopen(file,"rb"))==NULL) {
printf("\a\nArchivo %s no encontrado.\n",file);
exit(1);
}
fseek(fich, SEEK_SET, 0); /* Nos colocamos al principio del fichero */
fread(ptr_char,1,4096,fich); /* Cargamos en memoria 4096 bytes del fichero */
fclose(fich); /* Cerramos el fichero */
}
#define RESP_X 151
#define RESP_Y 141
void PatoSimpsons(void)
{
FILE *handle;
char *Buffer2;
int byteRot;
int x, y, mov, i, ok;
// Pido memoria para los tres patos 151x141
if ( ( Pato[0] = (char *)malloc( sizeof(char)*155*145 ) ) == NULL ||
( Pato[1] = (char *)malloc( sizeof(char)*155*145 ) ) == NULL ||
( Pato[2] = (char *)malloc( sizeof(char)*155*145 ) ) == NULL ||
( Buffer2 = (char *)malloc( sizeof(char)*320*200 ) ) == NULL ||
( BufferV = (char *)malloc( sizeof(char)*320*200 ) ) == NULL
) {
printf( "\a" );
return;
}
// Buffer2 = (char *)MK_FP( 0xA000, 0 );
// Inicializamos la paleta
CargaPaleta( "Pat0.pcx" );
// Leemos los patos
LeePato( "Pat0.pcx", Pato[0] );
// Muestra el primer pato mientras acabamos los c lculos
for ( x = 0; x < RESP_X; x ++ )
for ( y = 0; y < RESP_Y; y ++ )
Put( x+85, y+50, Pato[0][x + RESP_X*y] );
LeePato( "Pat1.pcx", Pato[1] );
LeePato( "Pat2.pcx", Pato[2] );
i = 0;
while ( i < 5*6 )
{
i++;
mov = (mov++) % 6;
for ( x = 0; x < RESP_X; x ++ )
for ( y = 0; y < RESP_Y; y ++ )
Put( x+85, y+50, Pato[ mov > 3 ? (6 - mov) : (mov-1) ][x + RESP_X*y] );
delay( 100 );
}
// Tatatam tam
sync_display(); memset( MK_FP( 0xA000, 0 ), 255, 320*200 ); delay( 50 ); sync_display(); memset( MK_FP( 0xA000, 0 ), 0, 320*200 ); delay( 50 );
sync_display(); memset( MK_FP( 0xA000, 0 ), 255, 320*200 ); delay( 50 ); sync_display(); memset( MK_FP( 0xA000, 0 ), 0, 320*200 ); delay( 150 );
sync_display(); memset( MK_FP( 0xA000, 0 ), 255, 320*200 ); delay( 50 ); sync_display(); memset( MK_FP( 0xA000, 0 ), 0, 320*200 );
// Patos reduciendoce:
i = 1; ok = 0; byteRot = 0;
int inc = 1, fVel = 0;
float CosAngle, SinAngle;
int xc, yc;
clock_t start, end;
start = clock();
while( ( ( clock() - start) / CLK_TCK ) < 30 )
{
fVel = (fVel++)%3;
if ( fVel==1 )
{
i += inc; if ( i > 6 ) inc = -1; else if ( i < 2 ) inc = 1;
}
ReducePato( BufferV, Pato[ mov > 3 ? (6 - mov) : (mov-1) ], i );
mov = (mov++) % 6;
/*
Que tal una peque¤a rotaci¢n:
*/
byteRot = (byteRot+=8) % 360;
CosAngle = TSin[ byteRot + 90 ] / 100.0;
SinAngle = TSin[ byteRot ] / 100.0;
for ( x = 0; x < 320; x++ )
// for ( y = 0; y < 200; y++ )
for ( y = 0; y < 200; y++ )
{
xc = x - 160;
yc = y - 100;
yc = xc * SinAngle + yc * CosAngle + 100;
if ( yc >= 0 && yc < 200 )
{
xc = xc * CosAngle - ( y - 100 ) * SinAngle + 160;
if ( xc >= 0 && xc < 320 )
{
Buffer2[ x + 320*y ] = BufferV[ xc + 320 * yc ];
} else Buffer2[ x + 320*y ] = 0;
} else Buffer2[ x + 320*y ] = 0;
}
sync_display(); memcpy( MK_FP( 0xA000, 0 ), Buffer2, 320*200 );
delay( 100 );
};
free( Pato[0] );
free( Pato[1] );
free( Pato[2] );
free( BufferV );
// free( Buffer2 );
}
void ReducePato( char *Dest, char *Org, char Magn )
{
int x, y;
int xR, yR;
// Escalamos el primer pato y despues...
for ( x = 0, xR = 0; x < RESP_X; x +=Magn, xR++ )
for ( y = 0, yR = 0; y < RESP_Y; y +=Magn, yR++ )
Dest[xR + yR*320] = Org[x + y*RESP_X];
// Copiamos en el destino tantos patos reducidos como podamos
// como la ovejita Dolly, pero con patos: a clonar se ha dicho...
for ( x = 0; x < 320; x++ )
for ( y = 0; y < 200; y++ )
// for ( y = 0; y < 320; y++ )
Dest[x + y*320] = Dest[ (x%xR) + (y%yR)*320 ];
}
int LeePato( char *file, char *dir )
{
int alto, ancho, contador;
unsigned char byte;
FILE *fp;
if ( (fp = fopen( file,"rb")) != NULL )
{
// Saltamos la cabecera
fseek( fp, 128, SEEK_SET );
for(alto=0; alto<RESP_Y; alto++)
{
for(ancho=0; ancho< (RESP_X+1); )
{
byte=getc(fp);
if(byte<=0xC0)
{
// set_point (ancho, alto, byte);
// ProcesaPunto( ancho, alto, byte );
dir[ancho + alto*RESP_X] = byte;
ancho++;
} else {
contador=byte&0x3F; byte=getc(fp);
for(; contador>0; contador--)
{
// set_point (ancho, alto, byte);
// ProcesaPunto( ancho, alto, byte );
dir[ancho + alto*RESP_X] = byte;
ancho++;
}
}
}
}
fclose(fp);
} else return ERROR;
return OK;
}