Files
SPIRAL/ESPIRAL.C
2021-09-08 21:41:03 +02:00

331 lines
7.6 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.

#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <alloc.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
char far *VidRam = MK_FP( 0xA000, 0);
typedef struct
{
int x, y;
char ndigitos;
char AX, AY;
unsigned char C1, C2, C3;
} p_graphics;
char Reverse = 0;
void Letras_en_espiral( char *Frase, p_graphics *FA );
void writepixel( int x, int y, char color );
void asigna_modo_video(char modo); /* asigna el modo de v¡deo indicado */
void LeeFuentes(char *file);
char *ptr_char;
double grad, pi;
double ia=3; /*incremento  ngulo*/
double ir=0.3; /*incremento radio*/
int key;
void main( int argc, char *argv[] )
{
clock_t tiempo;
char up_down = 1;
char Texto[255];
/* .. */
p_graphics Text1 = { 0, 84, 48, 1, 1, 0, 15, 15 };
pi = 4.0*atan(1.0);
grad = pi/180.0;
if( argc != 2 )
strcpy( Texto, "<-- ESPIRAL --><-- ESPIRAL --><-- ESPIRAL --><-- ESPIRAL --><-- ESPIRAL -->" );
else
strcpy( Texto, argv[2] );
if( argc != 3 ) LeeFuentes("comix.fnt"); else LeeFuentes(argv[2]);
/* Load Mod, and begin to play... */
/* While Sound up, J&D down and up until BOOM!! */
/* When 2nd BOOM!! will sound, J&D was join and change VidMode */
asigna_modo_video(0x13);
/* Swap to graphic mode and show TextSpiral while background is flicking */
/*
tiempo = clock() / CLK_TCK;
while( ( (clock()/CLK_TCK) - tiempo) <= 15 && !kbhit())
Letras_en_espiral( Texto, &Text1 );
*/
ia += 30;
while( 1 )
{
delay(50);
if ( kbhit() )
{
if( (key=getch()) == 27 ) break;
else
{
/* memset( VidRam, 0, 64000);*/
Text1.C1 = 255;
Letras_en_espiral( Texto, &Text1 );
Text1.C1 = 0;
switch( key )
{
case 'r':
case 'R':
Reverse = !Reverse;
break;
case 'a':
case 'A':
ia += 0.5;
break;
case 's':
case 'S':
ia -=0.5;
break;
case 'z':
case 'Z':
ir +=0.5;
break;
case 'x':
case 'X':
ir -=0.5;
break;
}
}
}
Text1.C1 = 255;
Letras_en_espiral( Texto, &Text1 );
Text1.C1 = 0;
/* ia 3 __ -3.5 */
if ( up_down==1 ) ia -= 0.1;
else ia += 0.1;
if ( ia <= -3.5 ) up_down = 0;
if ( ia >= 3 ) up_down = 1;
/* Letras_en_espiral( "abcdefghijklmn¤opqrstuvwxyz ABCDEFGHIJKLMN¥OPQRSTU... 0123456789", &Text1 );*/
Letras_en_espiral( Texto, &Text1 );
}
asigna_modo_video(0x3);
printf("La fuente utilizada fue: %s\n", argv[2]);
getch();
free(ptr_char);
}
void Letras_en_espiral( char *Frase, p_graphics *FA )
{
static char vez_ptr = 0;
static char FraseBit[110][16];
static char Frase1[100];
static unsigned int Flen;
static char Flen1;
static char RLen;
char cont;
int i;
char j, j1;
char c_elec;
char bit_s;
char *Frase_seg;
char FrBit_tmp[16];
unsigned seg, off;
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
double r; /*radio*/
/* double ia; */ /*incremento  ngulo*/
/* double ir;*/ /*incremento radio*/
double s,c; /*seno y coseno actuales <2>*/
double ca; /*coseno anterior*/
double isin,icos; /*incremento seno y coseno*/
int x,y;
/*
ia = 3;
ir = 0.3;
*/
isin = sin(ia*grad);
icos = cos(ia*grad);
r = 0.0; /*parte del centro*/
s = sin(0.0); /*con  ngulo 0 grados*/
c = cos(0.0);
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
Frase_seg = Frase1;
if ( !vez_ptr )
{
vez_ptr = 1;
/* Now, we going to get 8x8 Font dir. */
/*
asm mov AH, 0x11
asm mov AL, 0x30
asm mov BH, 0x03
asm int 0x10
asm mov seg, ES
asm mov off, BP
*/
}
if ( strcmp( Frase1, Frase ) != 0 )
{
strncpy( Frase1, Frase, 99 );
Frase1[99] = '\0';
j = i = strlen( Frase );
Flen = i * 8;
cont = 0;
if ( i < FA -> ndigitos )
i += FA -> ndigitos - i;
else
i += 5;
Flen1 = i;
/* // Almacenamos en la Frase a Bit's la FRASE A BIT'S */
while( cont <= i )
{
/* // Descomponemos cada caracter en un patron de BIT's */
if ( (cont - j) > 0 )
{
FraseBit[cont][0] = 0x00; FraseBit[cont][1] = 0x00;
FraseBit[cont][2] = 0x00; FraseBit[cont][3] = 0x00;
FraseBit[cont][4] = 0x00; FraseBit[cont][5] = 0x00;
FraseBit[cont][6] = 0x00; FraseBit[cont][7] = 0x00;
} else {
for( j1=0; j1<16; j1++)
FraseBit[cont][j1]= ptr_char[ ( *Frase_seg ) * 16 + j1 ];
}
cont++;
Frase_seg++;
}
} else {
/*
// Rotamos la frase
// Almacenamos el 1er bit que vamos a perder...
*/
for ( j1=0; j1<16; j1++ )
FrBit_tmp[j1] = 0x01 & ( FraseBit[0][j1] >> 7 );
for ( j=0; j<Flen1; j++ )
{
for ( j1=0; j1<16; j1++ )
FraseBit[j][j1] = FraseBit[j][j1] << 1;
for ( j1=0; j1<16; j1++ )
FraseBit[j][j1] = ( FraseBit[j][j1] & 0xFE ) | (0x01 & (FraseBit[j+1][j1] >> 7 ) );
}
for ( j1=0; j1<16; j1++ )
FraseBit[Flen1-1][j1] = ( FraseBit[Flen1-1][j1] & 0xFE ) | FrBit_tmp[j1];
}
/*// ndigitos --> m x. = 40*/
for ( i=0; i < FA->ndigitos; i ++ )
{
for ( j=0, j1=0; j1<8; j+=2*FA->AX, j1++ )
{
/*
// Analizamos el patron de BIT's y lo imprimimos
// FraseBit[cont][0]
// ^ ^----- N£mero de byte del digito ( 8x8 )
// |_________ N£mero de digito alfa-numerico
*/
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
if( r < 250 )
{
ca = c;
c = c*icos-s*isin;
s = s*icos+ca*isin;
x = 160+(int)(floor(r*c*1.2+0.5));
y = 100+(int)(floor(r*s+0.5));
r += ir;
}
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
for ( bit_s = 0; bit_s < 16; bit_s++ )
{
if ( FraseBit[i][bit_s] & ( (char)0x01 << (7-j1) ) ) c_elec = FA->C2; else c_elec = FA->C1;
/* writepixel( ( FA->x + j + i*8*2*FA->AX ), ( FA->y + 2*bit_s*FA->AY ), c_elec );*/
if( !Reverse )
{
if ( c_elec == FA->C2 ) c_elec = r;
} else {
if ( c_elec == FA->C1 ) c_elec = r;
else
c_elec = FA->C1;
}
if ( FA->C1==255 ) c_elec=0;
/* writepixel( x,y+bit_s*2, c_elec ); */writepixel( x, y+bit_s*2, c_elec );
}
}
}
}
void writepixel( int x, int y, char color )
{
if ( x>=0 && x<320 && y>=0 && y<200 )
*(VidRam + (x + y*320) ) = color;
}
void asigna_modo_video(char modo) /* asigna el modo de v¡deo indicado */
{ /* en la variable "modo" */
union REGS ent, sal;
ent.h.al = modo;
ent.h.ah = 0;
int86(16, &ent, &sal); /* funci¢n para asignar el modo de video */
}
void LeeFuentes(char *file)
{
FILE *fich;
/* Reservamos 4 Kb. para cargar la fuente en memoria */
if((ptr_char=(char *)malloc(4096))==NULL) {
printf("­­ No hay suficiente memoria !!\n");
exit (1);
}
/* Abrimos el fichero de la fuente */
if ((fich=fopen(file,"rb"))==NULL) {
printf("\a\nArchivo %s no encontrado.\n",file);
free(ptr_char);
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 */
}