home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <math.h>
- #include "fixed.h"
- #include "trg.h"
-
- /**********************************************************************/
- /* I'm sorry about the comments, but I've no time to comment it. */
- /**********************************************************************/
-
- #define WALL_HEIGHT 64
- #define VIEWER_HEIGHT 32
- #define VIEWER_DISTANCE 128
- #define WINDOW_LEFT 0
- #define WINDOW_RIGHT 320
- #define WINDOW_TOP 10
- #define WINDOW_BOTTOM 170
- #define WINDOW_HEIGHT 160
- #define WINDOW_CENTER 90
-
- /* global variables to do it more easy */
- int xdist,ydist;
- fixed x2,y2;
-
- /* function that calculate the slope */
- fixed inclinacion(int radians);
-
- /* function that calculate the distance */
- int dist(int grados,fixed y,fixed py)
- {
- asm(" movl 8(%ebp),%eax # EAX=grados(deegres)
- movl 8(%ebp),%ebx # EBX=grados(deegres)
- sarl $10,%eax # EAX=grados/1024 (to see which cuadrant)
- movl 12(%ebp),%ecx # ECX=y
- andl $3,%eax # lets see which one
- testl %eax,%eax # is 0
- jz CASO1
- cmpl $2,%eax # is 2
- jz CASO1
- CASO2:
- sall $10,%eax # multiplico los (radianes*1024)
- subl 16(%ebp),%ecx # ECX=y-py;
- subl %eax,%ebx # EBX=grados-(cuadrante<<10)
- xorl %edx,%edx # elimino lo que pudiera haber en EDX
- movl %ecx,%eax # EAX=numerador
- movl _sin_table(,%ebx,4),%ecx # ECX=denominador
- call _fixdiv2
- sarl $16,%eax
- cmpl $0,%eax
- jl NEGATIVO
- jmp RETORNO
- CASO1:
- sall $10,%eax # multiplico los (radianes*1024)
- subl 16(%ebp),%ecx # ECX=y-py;
- subl %eax,%ebx # EBX=grados-(cuadrante<<10)
- xorl %edx,%edx # elimino lo que pudiera haber en EDX
- movl %ecx,%eax # EAX=numerador
- movl _cos_table(,%ebx,4),%ecx # ECX=denominador
- call _fixdiv2
- sarl $16,%eax
- cmpl $0,%eax
- jl NEGATIVO
- jmp RETORNO
- NEGATIVO:
- negl %eax
- RETORNO:
- ");
- }
-
- void draw_game(int *map_game,unsigned char *vgascr,fixed px,fixed py,int v_angle,unsigned char *data[])
- {
- int desp;
- int grid_x,grid_y;
- fixed xcross_x,xcross_y;
- fixed ycross_x,ycross_y;
- int xmaze,ymaze;
- int distance;
- int column;
- int radians;
- int column_angle;
- fixed x,y;
- fixed pendiente;
- int altura,fondo,tope;
- int tmap;
- char car;
- int cual;
-
- for(column=WINDOW_LEFT;column<WINDOW_RIGHT;column++){
-
- column_angle=FIXED_TO_INT(fixmul(tabla_atan[column],FLOAT_TO_FIXED(652.229)));
-
- if(column_angle<0)
- column_angle+=NUM_GRAD;
- if(column_angle>=NUM_GRAD)
- column_angle-=NUM_GRAD;
-
- radians=v_angle+column_angle;
-
- if(radians>=NUM_GRAD)
- radians-=NUM_GRAD;
- if(radians<0)
- radians+=NUM_GRAD;
-
- /**************************************************************************/
- /* HASTA AQUI CALCULO LOS ANGULOS DE VISUALIZACION DEL JUGADOR DENTRO DEL */
- /* JUEGO. */
- /**************************************************************************/
-
- x=px; /* POSICION DONDE ESTA SITUADO EL JUGADOR */
- y=py; /* DENTRO DEL JUEGO */
-
- asm("subl $8,%esp"); /* guardo espacio en la pila para las variables
- X2 e Y2 de retorno */
- pendiente=inclinacion(radians);
-
- asm("movl (%esp),%eax
- movl 4(%esp),%ebx
- movl %eax,_x2
- movl %ebx,_y2
- addl $8,%esp
- NO_FIN:
- incl %ecx
- movl _x2,%eax # EAX=xdiff=x2
- movl _y2,%ebx # EBX=ydiff=y2
- movl -56(%ebp),%ecx # ECX=x
- movl -60(%ebp),%edx # EDX=y
- sarl $16,%ecx # ECX=x>>16;
- sarl $16,%edx # EDX=y>>16;
- andl $0xffffffc0,%ecx # ECX=x>>16&0xffc0;
- andl $0xffffffc0,%edx # EDX=y>>16&0xffc0;
- X2_FCERO:
- cmpl $0,%eax # es xdiff?
- jle MENOR_1 # menor o igual que 0
- decl %ecx # no pues lo decremento en una unidad
- jmp Y2_FCERO # vamos a ver ydiff
- MENOR_1:
- addl $64,%ecx # si es menor pues lo incremento en 64
- Y2_FCERO:
- cmpl $0,%ebx # es ydiff?
- jle MENOR_2 # menor o igual a cero
- decl %edx # no pues lo decremento en una unidad
- jmp FINAL_IFS
- MENOR_2:
- addl $64,%edx # si pues lo incremento 64 unidades
- FINAL_IFS:
- sall $16,%ecx # lo paso a FIXED (grid_x)
- sall $16,%edx # lo paso a FIXED (grid_y)
-
- movl %ecx,-24(%ebp) # guardo el grid_x en ycross_x
- movl %edx,-20(%ebp) # guardo el grid_y en xcross_y
- movl %ecx,%edx # EDX=grid_x
- movl -64(%ebp),%eax # EAX=pendiente
- subl -56(%ebp),%edx # le resto x a grid_x
- call _fixmul2
-
- addl -60(%ebp),%eax # EAX=pendiente*(grid_x-x)+y;
- movl -64(%ebp),%ecx # ECX=pendiente
- movl %eax,-28(%ebp) # guardo ycross_y;
- movl -20(%ebp),%eax # EAX=xcross_y
- subl -60(%ebp),%eax # EAX=xcross_y-y;
- call _fixdiv2
-
- addl -56(%ebp),%eax # EAX=(xcross_y-y)/pendiente+x
- pushl -60(%ebp) # paso la x como ultimo parametro
- movl %eax,-16(%ebp) # salvo el resultado en xcross_x
- pushl -28(%ebp) # paso la ycross_y como segundo parametro
- pushl -48(%ebp) # paso los radianes como primer parametro
- call _dist
- addl $12,%esp # calculo la distancia y elimino lo que queda en la pila
- movl %eax,_ydist
-
- pushl -60(%ebp)
- pushl -20(%ebp)
- pushl -48(%ebp)
- call _dist
- movl %eax,_xdist #calculo la distancia
- movl _ydist,%ebx
- addl $12,%esp
- cmpl %eax,%ebx
- jle YMENORX
- YMAYORX:
- movl -16(%ebp),%eax # EAX=xcross_x
- movl -20(%ebp),%ebx # EBX=xcross_y
- movl %eax,-56(%ebp) # x=xcross_x
- movl %ebx,-60(%ebp) # y=xcross_y
- sarl $22,%ebx
- sarl $22,%eax
- sall $5,%ebx
- addl %eax,%ebx
- movl -56(%ebp),%edx
- sall $2,%ebx
- sarl $16,%edx
- addl 8(%ebp),%ebx
- movl (%ebx),%eax # EAX= cual
- andl $0x0000003f,%edx
- testl %eax,%eax
- jz NO_FIN
- movl %edx,-80(%ebp)
- jmp FIN_BUC
- YMENORX:
- movl -24(%ebp),%eax
- movl -28(%ebp),%ebx
- movl %eax,-56(%ebp)
- movl %ebx,-60(%ebp)
- sarl $22,%ebx
- sarl $22,%eax
- sall $5,%ebx
- addl %eax,%ebx
- movl -60(%ebp),%edx
- sall $2,%ebx
- sarl $16,%edx
- addl 8(%ebp),%ebx
- movl (%ebx),%eax # EAX= cual
- andl $0x0000003f,%edx
- testl %eax,%eax
- jz NO_FIN
- movl %edx,-80(%ebp)
- FIN_BUC:
- movl %eax,-88(%ebp) # guardo el bitmap a mapear
- pushl 20(%ebp) # paso PY
- pushl -60(%ebp) # paso Y
- pushl -48(%ebp) # paso RADIANES
- call _dist
- addl $12,%esp
- movl %eax,-40(%ebp)
- movl -52(%ebp),%ebx
- sall $16,%eax
- movl _cos_table(,%ebx,4),%edx
- call _fixmul2
-
- sarl $16,%eax # paso el resultado a ENTERO
- cmpl $0,%eax # miro si el resultado es positivo
- jge MOVER
- negl %eax # le calculo el ABS
- MOVER:
- testl %eax,%eax
- jnz AL_FINAL # si era 0 le pongo un 1 para evitar errores
- incl %eax
- AL_FINAL:
- xorl %edx,%edx
- movl %eax,%ecx # ECX=EAX=distance
- movl $2048,%eax # EAX=VIEWER_DIST * WALL_HEIGHT
- idivl %ecx
-
- movl %eax,-68(%ebp) # EAX= (VIEWER_DIST * WALL_HEIGHT) / distance =altura
- xorl %edx,%edx # EDX= 0
- movl $1024,%eax # EAX= (VIEWER_DIST * VIEWER_HEIGHT)
- idivl %ecx # ECX= distance
-
- addl $90,%eax # EAX= ((VIEWER_DIST * VIEWER_HEIGHT)/distance)+VIEWPORT_CENTER
-
- movl -68(%ebp),%ebx # EBX= altura
- movl %eax,-72(%ebp) # guardo bottom
- subl %ebx,%eax # EAX= bottom-altura= top
-
- # REALIZO LOS CLIPPINS PERTINENTES
-
- cmpl $10,%eax
- jge NADA_TOPE
- addl %eax,-68(%ebp)
- movl $10,%eax
- subl $10,-68(%ebp)
- NADA_TOPE:
- movl -68(%ebp),%ecx
- movl %eax,-76(%ebp)
- addl %ecx,%eax # EAX=altura+tope
- cmpl $170,%eax # es mayor que 170
- jle NADA_TOPE_ALTURA
- subl -72(%ebp),%ecx
- addl $170,%ecx
- movl %ecx,-68(%ebp)
- NADA_TOPE_ALTURA:
- movl -76(%ebp),%ebx # EBX=top
- movl -76(%ebp),%ecx # ECX=top
- sall $8,%ebx
- sall $6,%ecx
- addl -44(%ebp),%ebx
- addl %ecx,%ebx
-
-
- movl -68(%ebp),%ecx # ECX= altura
- movl %ebx,-4(%ebp) # guardo el desp
- sall $16,%ecx # convierto la altura a FIXED
-
- movl $0x00400000,%eax # EAX=WALL_HEIGHT
- call _fixdiv2 # divido para obtener el factor de correccion
-
- movl -88(%ebp),%edx # obtengo el valor del bitmap que tengo que mapear
- movl 12(%ebp),%edi # obtengo la direccion de la pantalla virtual
- decl %edx # calculo que indice para leer el bitmap correcto
- movl 28(%ebp),%esi # obtengo la lista de texturas para las paredes
- sall $2,%edx # multiplico por 4 porque son punteros de 32 bits
-
- addl %ebx,%edi # calculo la primera posicion destino (pantalla-virtual)
- addl %edx,%esi # hago igual con el bitmap de la textura
- movl -68(%ebp),%ecx # leo la altura
- movl (%esi),%esi # en ESI tendre el bitmap de la textura a mapear
-
-
- movl -80(%ebp),%ebx # leo tmap en EBX
- xorl %edx,%edx
- addl %ebx,%esi
- xorl %ebx,%ebx
-
- # BUCLE QUE SE ENCARGA DE HACER EL TEXTURE MAPPING
-
- bucler_sin:
- incl %ecx
- movb (%esi,%edx,1),%dl
- addl %eax,%ebx
- movb %dl,(,%edi,)
- movl %ebx,%edx
- addl $320,%edi
- sarl $16,%edx
- decl %ecx
- sall $6,%edx
- loop bucler_sin
- fin_bucler:
- ");
-
- }
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-