First commit 14/08/1997
This commit is contained in:
commit
4eeaecd819
BIN
AVENTURA.EXE
Normal file
BIN
AVENTURA.EXE
Normal file
Binary file not shown.
BIN
AVENTURA.PRJ
Normal file
BIN
AVENTURA.PRJ
Normal file
Binary file not shown.
553
AVNTR_MM.CPP
Normal file
553
AVNTR_MM.CPP
Normal file
@ -0,0 +1,553 @@
|
||||
/**************************************************************************\
|
||||
|* *|
|
||||
|* AVNTR_MM *|
|
||||
|* *|
|
||||
|* Descripci¢n: *|
|
||||
|* M¢dulo principal de la aventura, y hasta el momento el *|
|
||||
|* £nico. *|
|
||||
|* *|
|
||||
|* 1er Proyecto com£n entre Oscar y JD. ( 1§ de muchos ) *|
|
||||
|* *|
|
||||
|* Fecha: 12-06-97 00.58 / 01.34 *|
|
||||
|* 10-07-97 13:05 / 14:07 *|
|
||||
|* *|
|
||||
\**************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#include <dos.h>
|
||||
#include <mem.h>
|
||||
#include <alloc.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "..\modex\modex.h"
|
||||
|
||||
|
||||
#include <conio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define OK 0
|
||||
#define ERROR 1
|
||||
|
||||
#define CURSOR_NORMAL 1
|
||||
|
||||
|
||||
char raton;
|
||||
void Error(int code);
|
||||
void Inicializa_Raton(int x1, int y1, int x2, int y2);
|
||||
#define MEMORIA 1
|
||||
|
||||
|
||||
class VirtualVGA
|
||||
{
|
||||
private:
|
||||
long size, Planos, uPlano;
|
||||
|
||||
char huge *memVGA;
|
||||
|
||||
public:
|
||||
long cX, cY;
|
||||
|
||||
VirtualVGA( long X, long Y );
|
||||
~VirtualVGA() { delete[] memVGA; };
|
||||
void copiaImagen( long offset, char huge *src, long size );
|
||||
long Size( void ){ return size; };
|
||||
void VGA(void);
|
||||
|
||||
char huge *memVirtual(void) { return memVGA; };
|
||||
};
|
||||
|
||||
VirtualVGA::VirtualVGA( long X, long Y )
|
||||
{
|
||||
|
||||
cY = Y; cX = X;
|
||||
|
||||
size = sizeof( char ) * Y * X;
|
||||
if ( ( memVGA = new char huge[size] ) == NULL )
|
||||
Error( MEMORIA );
|
||||
|
||||
// Calculamos el n§ de planos cortados que existen y el tama¤o del £ltimo
|
||||
Planos = size / 0xFFFF;
|
||||
uPlano = size % 0xFFFF;
|
||||
|
||||
};
|
||||
|
||||
void VirtualVGA::copiaImagen( long offset, char huge *src, long size )
|
||||
{
|
||||
char huge *dst;
|
||||
// offset indica el comienzo dentro del bloque destino
|
||||
// src puntero
|
||||
|
||||
dst = memVGA + offset;
|
||||
while ( size-- ) *(dst++) = *(src++);
|
||||
|
||||
// _fmemcpy( dst, scr, size );
|
||||
}
|
||||
|
||||
void VirtualVGA::VGA(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
// for ( i=0; i<Planos; i++ )
|
||||
draw_bitmap( (char far *)(memVGA + 0*0 ), 0, 0, cX, 150 );
|
||||
draw_bitmap( (char far *)(memVGA +(150*360)), 0, 150, cX, 150 );
|
||||
draw_bitmap( (char far *)(memVGA +(300*360)), 0, 300, 360, 100 );
|
||||
};
|
||||
|
||||
void set_video_mode ( char mode )
|
||||
{
|
||||
asm {
|
||||
mov AH, 0
|
||||
mov AL, mode
|
||||
int 0x10
|
||||
}
|
||||
};
|
||||
|
||||
void ControlPrincipal(void);
|
||||
|
||||
int CargaPaleta(char *file );
|
||||
void CargaCursor( VirtualVGA **CursorN, VirtualVGA **CursorP, char TipoCursor );
|
||||
void LiberaCursor( VirtualVGA **CursorN, VirtualVGA **CursorP );
|
||||
void copiaBitmap( char huge *src, int cX, int cY, int wX, int wY, char huge *tgt );
|
||||
|
||||
void GetBitmap( char far *BitMapSRC, char far *TRG, int X, int Y, int Xw1, int Yw1, int Xw2 );
|
||||
char far *CargaImagen( char *file, char huge *VGA, int cX, int cY );
|
||||
|
||||
long i = 0;
|
||||
|
||||
int main( void )
|
||||
{
|
||||
clock_t Start;
|
||||
|
||||
if (set_vga_modex( Mode_360x400, 360, 400, 1) == 0) Error(0x00);
|
||||
|
||||
Inicializa_Raton( 0, 0, 360-32, 400 );
|
||||
// ancho del cursor ---------^
|
||||
|
||||
Start = clock();
|
||||
ControlPrincipal();
|
||||
Start = ( clock() - Start ) / CLK_TCK;
|
||||
|
||||
set_video_mode (3);
|
||||
|
||||
printf( "\n%ld segundos %ld planos y %ld planos por segundo\n", (long)Start, (long)i, (long)(i/Start) );
|
||||
|
||||
|
||||
fflush( stdin );
|
||||
return OK;
|
||||
}
|
||||
|
||||
void GetBitmap( char far *BitMapSRC, char far *TRG, int X, int Y, int Xw1, int Yw1, int Xw2 )
|
||||
{
|
||||
int x, y;
|
||||
|
||||
for ( x = 0; x < Xw1; x++ )
|
||||
for ( y = 0; y < Yw1; y++ )
|
||||
*( TRG + x + y*Xw1 ) = *( BitMapSRC + X+x + (Y+y)*Xw2 );
|
||||
}
|
||||
|
||||
|
||||
void ControlPrincipal(void)
|
||||
{
|
||||
int oX, oY;
|
||||
int X_Mouse, Y_Mouse;
|
||||
union REGS io;
|
||||
io.x.ax = 3;
|
||||
char pCanim, nCanim;
|
||||
|
||||
pCanim = 0;
|
||||
nCanim = 1;
|
||||
|
||||
VirtualVGA *CursorN, *CursorP;
|
||||
CursorN = CursorP = NULL;
|
||||
CargaCursor( &CursorN, &CursorP, CURSOR_NORMAL );
|
||||
|
||||
// Cuadro de Mandos
|
||||
VirtualVGA cuadroMandos( 360, 100 );
|
||||
CargaImagen( "control.pcx", cuadroMandos.memVirtual(), cuadroMandos.cX, cuadroMandos.cY );
|
||||
// Dibujo del cuadro de mandos
|
||||
draw_bitmap( (char far *)cuadroMandos.memVirtual(), 0, 300, cuadroMandos.cX, cuadroMandos.cY );
|
||||
// CargaMuestraControles( cuadroMandos );
|
||||
|
||||
// VGA virtual, ( imprescindible volcarla )
|
||||
VirtualVGA VGAvirtual( 360, 400 );
|
||||
VirtualVGA FondoAvntr( 360, 300 );
|
||||
CargaImagen( "boceto.pcx", FondoAvntr.memVirtual(), FondoAvntr.cX, FondoAvntr.cY );
|
||||
|
||||
CargaPaleta( "boceto.pcx" );
|
||||
|
||||
oX = oY = 0;
|
||||
|
||||
do {
|
||||
|
||||
// 1§ Rellenamos la virtual con los datos OK!
|
||||
/**//**/ /**//**/ /**//**/ /**//**/ /**//**/
|
||||
VGAvirtual.copiaImagen( 0, FondoAvntr.memVirtual(), FondoAvntr.Size() );
|
||||
/*
|
||||
copiaBitmap( FondoAvntr.memVGA, 0, 0, FondoAvntr.cX, FondoAvntr.cY, VGAvirtual.memVGA );
|
||||
copiaBitmap( cuadroMandos.memVGA, 0, 300, cuadroMandos.cX, cuadroMandos.cY, VGAvirtual.memVGA );
|
||||
*/
|
||||
|
||||
// 2§ Mostramos los £ltimos objetos de primer plano:
|
||||
// ÚÄÄÄÄÄ¿ VGAvirtual
|
||||
// ³ 1 ÚÄÁÄÄÄ¿ Objetos de 1er plano
|
||||
// ÀÄÄÄ´ 2 ³
|
||||
// ÀÄÄÄÄÄÙ
|
||||
// Mostramos y controlamos el rat¢n ( redibujo de los controles y procesamiento de todo )
|
||||
{
|
||||
/*
|
||||
if ( ( Y_Mouse + CursorP[ 0 ].cY ) >= 300 )
|
||||
draw_bitmap( (char far *)cuadroMandos.memVGA, 0, 300, cuadroMandos.cX, cuadroMandos.cY );
|
||||
*/
|
||||
int86(0x33, &io, &io); // lee posici¢n y estados del bot¢n
|
||||
X_Mouse = io.x.cx;
|
||||
Y_Mouse = io.x.dx;
|
||||
|
||||
// Comprueba el tablero de control
|
||||
// CompruebaMandos( X_Mouse, Y_Mouse, &cuadroMandos );
|
||||
// Comprueba el resto de posibilidades ( el juego en s¡ )
|
||||
|
||||
// ¨ Se Puls¢ Un BOTON ?
|
||||
// B.Izquierdo B. Derecho
|
||||
if ( (io.x.bx & 1) != 0 || ( (io.x.bx >> 1) & 1 ) != 0 )
|
||||
{
|
||||
// copiaBitmap( CursorP[ pCanim ].memVirtual(), X_Mouse, Y_Mouse, CursorP[ pCanim ].cX, CursorP[ pCanim ].cY, VGAvirtual.memVirtual() );
|
||||
copiaBitmap( CursorP[ pCanim ].memVirtual(), X_Mouse, Y_Mouse, 32, 32, VGAvirtual.memVirtual() );
|
||||
// tdraw_bitmap( CursorP[ pCanim ].memVGA, X_Mouse, Y_Mouse, CursorP[ pCanim ].cX, CursorP[ pCanim ].cY );
|
||||
} else {
|
||||
// copiaBitmap( CursorN[ pCanim ].memVirtual(), X_Mouse, Y_Mouse, CursorN[ pCanim ].cX, CursorN[ pCanim ].cY, VGAvirtual.memVirtual() );
|
||||
copiaBitmap( CursorN[ pCanim ].memVirtual(), X_Mouse, Y_Mouse, 32, 32, VGAvirtual.memVirtual() );
|
||||
// tdraw_bitmap( CursorN[ pCanim ].memVGA, X_Mouse, Y_Mouse, CursorN[ pCanim ].cX, CursorN[ pCanim ].cY );
|
||||
}
|
||||
|
||||
// Copiamos la virtual a la real...
|
||||
// Partido por la mierda de la segmentaci¢n de la memoria
|
||||
VGAvirtual.VGA();
|
||||
}
|
||||
|
||||
i++;
|
||||
} while ( !kbhit() );
|
||||
|
||||
LiberaCursor( &CursorN, &CursorP );
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
|* *|
|
||||
|* 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
|
||||
set_dac_register ( index, (getc(fp) >> 2), (getc(fp) >> 2), (getc(fp) >> 2) );
|
||||
} // end for index
|
||||
|
||||
}
|
||||
|
||||
fclose( fp );
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
|* *|
|
||||
|* MuestraImagen *|
|
||||
|* *|
|
||||
|* Descripci¢n: *|
|
||||
|* Descomprime y copia a la pagina indicada un PCX *|
|
||||
|* *|
|
||||
|* Entradas: nombre de la imagen *|
|
||||
|* pagina *|
|
||||
|* color_invisible ( -1 si ninguno ) *|
|
||||
|* *|
|
||||
|* *|
|
||||
|* Salidas: OK Todo ha ido bien *|
|
||||
|* ERROR Algo va mal *|
|
||||
|* *|
|
||||
\**************************************************************************/
|
||||
int MuestraImagen( char *file, int page, int col_Inv )
|
||||
{
|
||||
int curr_page;
|
||||
FILE *fp;
|
||||
int alto, ancho, contador;
|
||||
unsigned char byte;
|
||||
|
||||
|
||||
if ( (fp = fopen( file,"rb")) != NULL )
|
||||
{
|
||||
|
||||
curr_page = get_active_page();
|
||||
set_active_page(page);
|
||||
|
||||
// Saltamos la cabecera
|
||||
fseek( fp, 128, SEEK_SET );
|
||||
|
||||
for(alto=0; alto<240; alto++)
|
||||
{
|
||||
for(ancho=0; ancho<360; )
|
||||
{
|
||||
byte=getc(fp);
|
||||
if(byte<=0xC0)
|
||||
{
|
||||
if ( col_Inv < 0 || byte != col_Inv ) set_point (ancho, alto, byte);
|
||||
ancho++;
|
||||
}
|
||||
else
|
||||
{
|
||||
contador=byte&0x3F; byte=getc(fp);
|
||||
for(; contador>0; contador--)
|
||||
{
|
||||
if ( col_Inv < 0 || byte != col_Inv ) set_point (ancho, alto, byte);
|
||||
ancho++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
} else return ERROR;
|
||||
|
||||
set_active_page(curr_page);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
char far *CargaImagen( char *file, char huge *VGA, int cX, int cY )
|
||||
{
|
||||
int curr_page;
|
||||
FILE *fp;
|
||||
long alto, ancho, contador;
|
||||
unsigned char byte;
|
||||
|
||||
if ( (fp = fopen( file,"rb")) != NULL )
|
||||
{
|
||||
|
||||
// Saltamos la cabecera
|
||||
fseek( fp, 128, SEEK_SET );
|
||||
|
||||
for(alto=0; alto<cY; alto++)
|
||||
{
|
||||
for(ancho=0; ancho<cX; )
|
||||
{
|
||||
byte=getc(fp);
|
||||
if(byte<=0xC0)
|
||||
{
|
||||
*VGA = byte; VGA++;
|
||||
// set_point( ancho, alto, *(emptyVGA.memVGA + alto*emptyVGA.cX + ancho) );
|
||||
ancho++;
|
||||
}
|
||||
else
|
||||
{
|
||||
contador=byte&0x3F; byte=getc(fp);
|
||||
for(; contador>0; contador--)
|
||||
{
|
||||
*VGA = byte; VGA ++;
|
||||
// set_point( ancho, alto, *(emptyVGA.memVGA + alto*emptyVGA.cX + ancho) );
|
||||
ancho++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
} else return NULL;
|
||||
|
||||
return VGA;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************\
|
||||
|* *|
|
||||
|* Error *|
|
||||
|* *|
|
||||
|* Descripci¢n: *|
|
||||
|* Aborta anormalmente el programa, mostrando un mensaje de *|
|
||||
|* de error. *|
|
||||
|* *|
|
||||
|* Entradas: Codigo del mensaje de error a mostrar *|
|
||||
|* Salidas: (ninguna) *|
|
||||
|* *|
|
||||
\**************************************************************************/
|
||||
void Error(int code)
|
||||
{
|
||||
set_video_mode (3);
|
||||
switch( code )
|
||||
{
|
||||
case MEMORIA:
|
||||
printf( "Ni un byte libre para mi!\n");
|
||||
break;
|
||||
|
||||
}
|
||||
exit(code);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// los par metros son las cotas para el raton
|
||||
void Inicializa_Raton(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
|
||||
// Por defecto el raton aparecer en las coordenadas ( 50, 50 )
|
||||
int px = 50, py = 50;
|
||||
|
||||
// Pero si Y_ y X_ tienen unas coordenadas el raton se posiciona alli.
|
||||
/*
|
||||
if ( Y_Mouse != -1 && X_Mouse != -1 )
|
||||
{
|
||||
px = X_Mouse; py = Y_Mouse;
|
||||
}
|
||||
*/
|
||||
union REGS ent, sal;
|
||||
long dir;
|
||||
|
||||
ent.x.ax = 0;
|
||||
int86(0x33, &ent, &sal); /* averigua si hay rat¢n conectado */
|
||||
|
||||
raton = sal.x.ax; /* indica a la variable global el estado
|
||||
del raton */
|
||||
|
||||
if(raton!=0) {
|
||||
|
||||
ent.x.ax = 15;
|
||||
ent.x.cx = 5;
|
||||
ent.x.dx = 11;
|
||||
int86(0x33, &ent, &sal); /* fija la raz¢n mickey/pixel */
|
||||
|
||||
ent.x.ax = 7;
|
||||
ent.x.cx = x1;
|
||||
ent.x.dx = x2;
|
||||
int86(0x33, &ent, &sal); /* fija la posici¢n m x. y m¡n. horizontal */
|
||||
|
||||
ent.x.ax = 8;
|
||||
ent.x.cx = y1;
|
||||
ent.x.dx = y2;
|
||||
int86(0x33, &ent, &sal); /* fija la posici¢n m x. y m¡n. vertical */
|
||||
|
||||
ent.x.ax = 4;
|
||||
ent.x.cx = px;
|
||||
ent.x.dx = py;
|
||||
int86(0x33, &ent, &sal); /* fija la posici¢n del rat¢n */
|
||||
|
||||
ent.x.ax = 2; // Como sabes hacer esto, no sirve para nada
|
||||
int86(0x33, &ent, &ent); // por que el raton no se puede mostrar y por
|
||||
// deducion, tan poco ocultar.
|
||||
// Pero " Por si el modo no es SVGA ", lo ocultamos
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void LiberaCursor( VirtualVGA **CursorN, VirtualVGA **CursorP )
|
||||
{
|
||||
/*
|
||||
int i;
|
||||
|
||||
if ( (*CursorP) != NULL )
|
||||
{
|
||||
for ( i=0; i<10; i++ )
|
||||
EliminaVirtual( &((*CursorP)[i]) );
|
||||
|
||||
free( (*CursorP) );
|
||||
}
|
||||
|
||||
if ( (*CursorN) != NULL )
|
||||
{
|
||||
for ( i=0; i<10; i++ )
|
||||
EliminaVirtual( &((*CursorN)[i]) );
|
||||
|
||||
free( (*CursorN) );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void CargaCursor( VirtualVGA **CursorN, VirtualVGA **CursorP, char TipoCursor )
|
||||
{
|
||||
/*
|
||||
int i;
|
||||
|
||||
// El cursor presionado solo se carga una vez ( siempre es el mismo )
|
||||
if ( (*CursorP) == NULL )
|
||||
{
|
||||
// cargamos el cursor animado ( presionado ) :: 10 animaciones ::
|
||||
if ( ( (*CursorP) = (VirtualVGA *)malloc( sizeof(VirtualVGA)*10 ) ) == NULL )
|
||||
Error( 0x00 );
|
||||
|
||||
for ( i=0; i<10; i++ )
|
||||
{
|
||||
// CURSOR PRESIONADO: 32x32
|
||||
(*CursorP)[i].cX = 32; (*CursorP)[i].cY = 32;
|
||||
CreaVirtual( &((*CursorP)[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( (*CursorN) == NULL )
|
||||
{
|
||||
// cargamos el cursor animado ( liberado ) :: 10 animaciones ::
|
||||
if ( ( (*CursorN) = (VirtualVGA *)malloc( sizeof(VirtualVGA)*10 ) ) == NULL )
|
||||
Error( 0x00 );
|
||||
|
||||
for ( i=0; i<10; i++ )
|
||||
{
|
||||
// CURSOR PRESIONADO: 32x32
|
||||
(*CursorN)[i].cX = 32; (*CursorN)[i].cY = 32;
|
||||
CreaVirtual( &((*CursorN)[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
switch( TipoCursor )
|
||||
{
|
||||
case CURSOR_NORMAL:
|
||||
default:
|
||||
for ( i=0; i<10; i++ )
|
||||
{
|
||||
// CURSOR PRESIONADO: 32x32
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void copiaBitmap( char huge *src, int cX, int cY, int wX, int wY, char huge *tgt )
|
||||
{
|
||||
long i; char c;
|
||||
long offY;
|
||||
|
||||
wY = (cY + wY); wY = wY >= 400 ? 400 : wY;
|
||||
wX = (cX + wX); wX = wX >= 360 ? 360 : wX;
|
||||
|
||||
for ( ; cY < wY; cY++ )
|
||||
{
|
||||
offY = (long)cY*360;
|
||||
for ( i = cX; i < wX; i++ )
|
||||
if ( ( c = *(src++) ) != 0 )
|
||||
*(tgt + offY + i ) = c;
|
||||
}
|
||||
}
|
BIN
BOCETO.PCX
Normal file
BIN
BOCETO.PCX
Normal file
Binary file not shown.
BIN
CONTROL.PCX
Normal file
BIN
CONTROL.PCX
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user