IMPORTANTE LEER CHANGELOG - SDK MODIFICADO - indexado dinámico r00lz! :)

This commit is contained in:
Gabriel Lorenzo 2002-09-24 00:47:12 +00:00
parent 129b448c38
commit 042fcd7297
31 changed files with 307 additions and 204 deletions

View file

@ -1,3 +1,28 @@
24/9/2002
---------
* ¡¡Añadido indexado de variables dinámico!! (¿contento Rise?) :D
+------------------------------+
| LEER ESTO CON MUCHA ATENCIÓN |
+------------------------------+
1) Compilad la documentación (doc/html/makedokNT.bat) y leed bien el
varindex-howto.html. Las macros a que hace referencia se encuentran en
varindex.h (para el stub) y export.h (para las dll's), por si quereis
verlas.
2) NO INCLUYÁIS VARINDEX.H EN LAS DLL's, sólamente export.h
Ya tenéis acceso a cualquier variable, tabla o estructura de cualquier dll
desde cualquier otra dll. Falta hacer un sistema de dependencias, rara vez
se va a dar el caso de que una dll dependa de otra (a excepción de la
graphics o la edivstd), pero vendrá muy bien de todas formas y aseguraremos
la robustez de ediv, especialmente de cara a dll's hechas por usuarios.
Al compilar, ediv (compilado como Debug) guarda en varindex.out la tabla
de variables sin comprimir, que podeis comparar con la lista que muestra
el stub en stdout al arrancar, por si hay que comprobar errores. (Er_Makina)
* Naturalmente ha sido necesario adaptar el stub y todas las dlls. De paso he
aprovechado para cambiar alguna cosilla por ahí para quitar warnings (uf
la graphics tiene cada warnings mas peligrosos.. variables sin inicializar..
de to) :P (Er_Makina)
9/9/2002
--------
* Le he añadido icono al stub, y también he hecho un programa (iconchanger)

View file

@ -86,6 +86,8 @@ sdk
+diferencias_compiladores
+estructura_dll
+export_h
+varindex
++varindex-howto
explicacion_source
+compilador_ediv
++ediv_c

View file

@ -11,3 +11,6 @@
"en cualquiera de los documentos que\nse incluyen en este proyecto, por favor "
"comun&iacute;quenoslo a <a href=\"mailto:bugs@edivcentral.com\">bugs@edivcentral.com</a>. "
"Gracias.<br>\n&copy; Copyleft Sion Entertainment, 2000-2002</font>\n</body>\n</html>\n"
<%code%> "<!-- POR HACER: Resaltado de sintaxis --><p><table border=\"0\" cellpadding=\"10\" "
"width=\"80%\" align=\"center\"><tr><td nowrap><pre>"
<%/code%> "</pre></td></tr></table></p>"

View file

@ -268,4 +268,6 @@ http://www.cs.ukc.ac.uk/people/staff/rej/gc.html
screen_color(int color)
rellena el fondo con un color
Incluir Psycle (tracker musical) en el IDE: http://sourceforge.net/projects/psycle/
Incluir Psycle (tracker musical) en el IDE: http://sourceforge.net/projects/psycle/
punteros a estructuras genericos (que no haga falta indicarle a qué tipo de estructura apuntan)

View file

@ -1,6 +1,6 @@
#include <export.h>
#include "../../shared/varindex.h"
//#include "../../shared/varindex.h"
#include "dinmem.h"

View file

@ -153,9 +153,6 @@
<File
RelativePath="..\export.h">
</File>
<File
RelativePath="..\..\shared\varindex.h">
</File>
</Filter>
<Filter
Name="Resource Files"

Binary file not shown.

View file

@ -24,7 +24,7 @@
*/
#include <export.h>
#include "../../shared/varindex.h"
//#include "../../shared/varindex.h"
#include "main.h"
@ -168,7 +168,8 @@ int eDiv_GetId(FUNCTION_PARAMS)
last_proc = i ;
id1 = fp->procs_s[ fp->proc_orden[ i ] ].id ;
//Si el proceso se corresponde con el type
if ( fp->mem[ id1 + fp->varindex[ _res_process_type ] ] == a )
// if ( fp->mem[ id1 + fp->varindex[ _res_process_type ] ] == a )
if ( reserved("process_type",id1) == a )
{
return ( fp->procs_s[ fp->proc_orden[ i ] ].id ) ;
}

View file

@ -148,9 +148,6 @@
<File
RelativePath="..\export.h">
</File>
<File
RelativePath="..\..\shared\varindex.h">
</File>
</Filter>
<Filter
Name="Resource Files"

View file

@ -41,6 +41,28 @@ extern "C" {
typedef enum { FALSE, TRUE } bool;
#endif
///// VARINDEX /////
typedef enum { v_global, v_reserved, v_local } tipo_t;
typedef struct {
unsigned char hash;
tipo_t tipo;
char* nombre;
int offset;
} varindex_t;
#define global(nombre) fp->mem[fp->GetVarOffset(v_global,nombre)]
#define reserved(nombre,id) fp->mem[(id)+fp->GetVarOffset(v_reserved,nombre)]
#define local(nombre,id) fp->mem[(id)+fp->GetVarOffset(v_local,nombre)]
#define globalptr(nombre) fp->GetVarOffset(v_global,nombre)
#define reservedptr(nombre) fp->GetVarOffset(v_reserved,nombre)
#define localptr(nombre) fp->GetVarOffset(v_local,nombre)
///// FIN DE VARINDEX /////
#include <SDL/SDL.h>
// Funciones de exportación de datos
@ -69,6 +91,9 @@ typedef int (TYPEOF_Dibuja)(SDL_Surface *, SDL_Rect, SDL_Rect, int, int);
typedef void (TYPEOF_Runtime_Error)(int, ...);
typedef void (TYPEOF_Critical_Error)(int, ...);
// Obtiene offset de variable indexada dinámicamente
typedef int (TYPEOF_GetVarOffset)(tipo_t tipo,char* nombre);
// estilo BO2K, sólo para "defaultear" las funciones como NULL
/*extern TYPEOF_EDIV_Export *EDIV_Export;
extern TYPEOF_EDIV_Export_Const *EDIV_Export_Const;
@ -233,6 +258,7 @@ struct _fun_params{
TYPEOF_Call_Entrypoint *Call_Entrypoint ;
TYPEOF_Runtime_Error *Runtime_Error ;
TYPEOF_Critical_Error *Critical_Error ;
TYPEOF_GetVarOffset *GetVarOffset ;
} ;
@ -273,75 +299,6 @@ void first_load(FUNCTION_PARAMS) ;
//////////////////////////////
//// VARIABLES INDEXADAS ////
// copio y pasteo brutalmente, no pongo #include para que el export.h sea independiente
/*
#define var(a) mem[varindex[a]]
//////////////////////////////
/// GLOBALES ///
//////////////////////////////
#define _glo_timer 0
#define _glo_max_process_time 1
#define _glo_argc 2
#define _glo_argv 3
//////////////////////////////
/// LOCALES ///
//////////////////////////////
// Estructura reserved
#define _res_process_id 4
#define _res_id_scan 5
#define _res_process_type 6
#define _res_type_scan 7
#define _res_status 8
#define _res_parameters 9
#define _res_param_offset 10
#define _res_program_index 11
#define _res_stack_pointer 12
#define _res_is_executed 13
#define _res_is_painted 14
#define _res_m8_object 15
#define _res_old_ctype 16
#define _res_frame_percent 17
#define _res_box_x0 18
#define _res_box_y0 19
#define _res_box_x1 20
#define _res_box_y1 21
#define _res_f_count 22
#define _res_caller_id 23
// Jerarquía de procesos
#define _loc_father 24
#define _loc_son 25
#define _loc_smallbro 26
#define _loc_bigbro 27
// Variables locales varias
#define _loc_priority 28
#define _loc_ctype 29
#define _loc_x 30
#define _loc_y 31
#define _loc_z 32
#define _loc_graph 33
#define _loc_size 34
#define _loc_angle 35
#define _loc_region 36
#define _loc_file 37
#define _loc_xgraph 38
#define _loc_height 39
#define _loc_cnumber 40
#define _loc_resolution 41
#define _loc_flags 42
#define _loc_transparency 43
*/
#ifdef __cplusplus
}
#endif

View file

@ -1,7 +1,7 @@
#include <stdio.h>
#include <export.h>
#include "../../shared/varindex.h"
//#include "../../shared/varindex.h"
#include "file.h"
@ -93,7 +93,7 @@ int eDiv_Fread(FUNCTION_PARAMS)
int eDiv_Ftell(FUNCTION_PARAMS)
{
int handle ;
int handle=getparm();
if ( !existe[handle] )
return -1 ;
@ -126,7 +126,7 @@ int eDiv_Flush(FUNCTION_PARAMS)
int eDiv_Fclose(FUNCTION_PARAMS)
{
int handle, num ;
int handle=getparm(), num ;
if ( handle == 0 )
if ( ( num = _fcloseall() ) == EOF )

View file

@ -153,9 +153,6 @@
<File
RelativePath="file.h">
</File>
<File
RelativePath="..\..\shared\varindex.h">
</File>
</Filter>
<Filter
Name="Resource Files"

View file

@ -11,7 +11,7 @@
#include "export.h"
#include <SDL/SDL.h>
#include "graphics.h"
#include "varindex.h"
//#include "varindex.h"
#define FUNCTION_PARAMS2 struct _fun_params *fp
@ -430,21 +430,21 @@ int eDIV_COLLISION(FUNCTION_PARAMS)
if ( a < 4000000 )
{
id1 = fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id ;
g1 = fp->mem[ id1 + fp->varindex[_loc_graph] ] ;
f1 = fp->mem[ id1 + fp->varindex[_loc_file] ] ;
g1 = local("graph",id1) ;
f1 = local("file",id1) ;
if ( files[f1].existe == 0 || files[f1].mapa[g1].existe == 0 )
return -1 ;
r1.x = fp->mem[ id1 + fp->varindex[_loc_x] ] ;
r1.y = fp->mem[ id1 + fp->varindex[_loc_y] ] ;
r1.x = local("x",id1) ;
r1.y = local("y",id1) ;
r1.w = files[f1].mapa[g1].Surface->w ;
r1.h = files[f1].mapa[g1].Surface->h ;
id2 = a ;
g2 = fp->mem[ id2 + fp->varindex[_loc_graph] ] ;
g2 = local("graph",id2) ;
if ( files[f2].existe == 0 || files[f2].mapa[g2].existe == 0 )
return -1 ;
f2 = fp->mem[ id2 + fp->varindex[_loc_file] ] ;
r2.x = fp->mem[ id2 + fp->varindex[_loc_x] ] ;
r2.y = fp->mem[ id2 + fp->varindex[_loc_y] ] ;
f2 = local("file",id2) ;
r2.x = local("x",id2) ;
r2.y = local("y",id2) ;
r2.w = files[f2].mapa[g2].Surface->w ;
r2.h = files[f2].mapa[g1].Surface->h ;
//Colision barata :P
@ -458,23 +458,23 @@ int eDIV_COLLISION(FUNCTION_PARAMS)
{
id1 = fp->procs_s[ fp->proc_orden[ i ] ].id ;
//Si el proceso se corresponde con el type
if ( fp->mem[ id1 + fp->varindex[ _res_process_type ] ] == a )
if ( reserved("process_type",id1) == a )
{
g1 = fp->mem[ id1 + fp->varindex[_loc_graph] ] ;
f1 = fp->mem[ id1 + fp->varindex[_loc_file] ] ;
g1 = local("graph",id1) ;
f1 = local("file",id1) ;
if ( files[f1].existe == 0 || files[f1].mapa[g1].existe == 0 )
return -1 ;
r1.x = fp->mem[ id1 + fp->varindex[_loc_x] ] ;
r1.y = fp->mem[ id1 + fp->varindex[_loc_y] ] ;
r1.x = local("x",id1) ;
r1.y = local("y",id1) ;
r1.w = files[f1].mapa[g1].Surface->w ;
r1.h = files[f1].mapa[g1].Surface->h ;
id2 = a ;
g2 = fp->mem[ id2 + fp->varindex[_loc_graph] ] ;
g2 = local("graph",id2) ;
if ( files[f2].existe == 0 || files[f2].mapa[g2].existe == 0 )
return -1 ;
f2 = fp->mem[ id2 + fp->varindex[_loc_file] ] ;
r2.x = fp->mem[ id2 + fp->varindex[_loc_x] ] ;
r2.y = fp->mem[ id2 + fp->varindex[_loc_y] ] ;
f2 = local("file",id2) ;
r2.x = local("x",id2) ;
r2.y = local("y",id2) ;
r2.w = files[f2].mapa[g2].Surface->w ;
r2.h = files[f2].mapa[g1].Surface->h ;
//Colision barata :P
@ -546,11 +546,11 @@ int eDIV_ADVANCE(FUNCTION_PARAMS)
int a , id1 , x , y , angulo ;
a = getparm() ;
id1 = fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id ;
angulo = fp->mem[ id1 + fp->varindex[ _loc_angle ] ] ;
angulo = local("angle",id1) ;
x = (int) ((double)a * cos( (angulo/1000) * PIOVER180 )) ;
y = (int) ((double)a * sin( (angulo/1000) * PIOVER180 )) ;
fp->mem[ id1 + fp->varindex[ _loc_x ] ] += x;
fp->mem[ id1 + fp->varindex[ _loc_y ] ] += y ;
local("x",id1) += x;
local("y",id1) += y ;
return 1 ;
}
@ -564,8 +564,8 @@ int eDIV_XADVANCE(FUNCTION_PARAMS)
angulo = a ;
x = (int) ((double)b * cos( (angulo/1000) * PIOVER180 )) ;
y = (int) ((double)b * sin( (angulo/1000) * PIOVER180 )) ;
fp->mem[ id1 + fp->varindex[ _loc_x ] ] += x ;
fp->mem[ id1 + fp->varindex[ _loc_y ] ] += y ;
local("x",id1) += x ;
local("y",id1) += y ;
return 1 ;
}
@ -933,14 +933,14 @@ int eDIV_OUT_REGION(FUNCTION_PARAMS2)
r = getparm() ;
id = getparm() ;
f = fp->mem[ id + fp->varindex[_loc_file] ] ;
g = fp->mem[ id + fp->varindex[_loc_graph] ] ;
f = local("file",id) ;
g = local("graph",id) ;
if ( !files[f].existe || !files[f].mapa[g].existe )
return -1 ;
x = fp->mem[ id + fp->varindex[_loc_x] ] ;
y = fp->mem[ id + fp->varindex[_loc_y] ] ;
x = local("x",id) ;
y = local("y",id) ;
if ( x < fp->regions[r].x + fp->regions[r].w && x + files[f].mapa[g].Surface->w > fp->regions[r].x &&
y < fp->regions[r].y + fp->regions[r].h && y + files[f].mapa[g].Surface->h > fp->regions[r].y )
@ -1035,7 +1035,7 @@ int eDIV_MOVE_DRAW(FUNCTION_PARAMS2)
SDL_SetAlpha( draws[id].Surface , SDL_SRCALPHA | SDL_RLEACCEL , 17 * (o) ) ;
else
if ( o == 15 )
SDL_SetAlpha( draws[id].Surface , NULL , 255 ) ;
SDL_SetAlpha( draws[id].Surface , 0 , 255 ) ;
return 1 ;
}
@ -1089,6 +1089,8 @@ int eDIV_LOAD_FPG(FUNCTION_PARAMS2)
//Uint8 r,g,b;
SDL_Color p[256];
// TODO: quitar printf's y exit's y poner fp->Runtime_Error()
archivo = getstrparm() ;
printf("LOAD_FPG %s\n",archivo);
@ -1106,6 +1108,8 @@ int eDIV_LOAD_FPG(FUNCTION_PARAMS2)
fread(&cabecera,1,sizeof(FPGHEADER),f);
// TODO: optimizar esto ligeramente (comprobar primero los bytes comunes y luego
// leer "pg","16","24","32")
if(strcmp(cabecera.header,"fpg\x1A\x0D\x0A")) {
if(strcmp(cabecera.header,"f16\x1A\x0D\x0A")) {
if(strcmp(cabecera.header,"f24\x1A\x0D\x0A")) {
@ -1230,10 +1234,11 @@ int eDIV_GET_REAL_POINT(FUNCTION_PARAMS2)
dy = getparm() ;
dx = getparm() ;
n = getparm() ;
f = fp->mem[ fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id + fp->varindex[_loc_file] ] ;
g = fp->mem[ fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id + fp->varindex[_loc_graph] ] ;
x = fp->mem[ fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id + fp->varindex[_loc_x] ] ;
y = fp->mem[ fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id + fp->varindex[_loc_y] ] ;
id = fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id;
f = local("file",id) ;
g = local("graph",id) ;
x = local("x",id) ;
y = local("y",id) ;
if ( !files[f].existe || !files[f].mapa[g].existe )
return -1 ;
@ -1312,7 +1317,7 @@ void frame(FUNCTION_PARAMS2 )
SDL_BlitSurface( fondo , NULL , screen , NULL ) ;
// Draws
z = fp->mem[ fp->varindex[_glo_draw_z] ] ;
z = global("draw_z");
for ( i = 0 ; i <= last_draw ; i++ )
{
if ( draws[i].existe )
@ -1341,12 +1346,12 @@ void frame(FUNCTION_PARAMS2 )
for ( i = 0 ; i < *fp->num_procs ; i++ )
{
id = fp->procs_s[ fp->proc_orden[i] ].id ;
f = fp->mem[ id + fp->varindex[_loc_file] ];
g = fp->mem[ id + fp->varindex[_loc_graph] ];
r = fp->mem[ id + fp->varindex[_loc_region] ] ;
z = fp->mem[ id + fp->varindex[_loc_z] ] ;
dstrect.x = fp->mem[ id + fp->varindex[_loc_x] ] ;
dstrect.y = fp->mem[ id + fp->varindex[_loc_y] ] ;
f = local("file",id);
g = local("graph",id);
r = local("region",id);
z = local("z",id);
dstrect.x = local("x",id);
dstrect.y = local("y",id);
dstrect.w = 0 ;
dstrect.h = 0 ;
if ( files[f].mapa[g].existe )
@ -1357,10 +1362,10 @@ void frame(FUNCTION_PARAMS2 )
srcrect.h = files[f].mapa[g].Surface->h ;
dstrect.x -= files[f].mapa[g].cpoint[0].x ;
dstrect.y -= files[f].mapa[g].cpoint[0].y ;
if ( fp->mem[ id + fp->varindex[_loc_flags] ] & 4 )
if ( local("flags",id) & 4 )
//SDL_SetAlpha(files[f].mapa[g].Surface, SDL_SRCALPHA , fp->mem[ id + fp->varindex[_loc_transparency] ] ) ;
if ( fp->mem[ id + fp->varindex[_loc_flags] ] & 8 ) {
trans = 255 - fp->mem[ id + fp->varindex[_loc_transparency] ] ;
if ( local("flags",id) & 8 ) {
trans = 255 - local("transparency",id);
if(trans<0) trans=0; else if(trans>255) trans=255;
}
else

View file

@ -291,7 +291,7 @@ int eDiv_Key(FUNCTION_PARAMS)
}
//*************************** ENTRYPOINTS **********************************************
void first_load()
void first_load(FUNCTION_PARAMS)
{
int i ;
SDL_Init( SDL_INIT_EVENTTHREAD ) ;
@ -501,7 +501,7 @@ void first_load()
}
void frame(int mem[], int * varindex, struct _procs_s *procs_s)
void frame(FUNCTION_PARAMS)
{
int numkeys ;

View file

@ -153,9 +153,6 @@
<File
RelativePath="main.h">
</File>
<File
RelativePath="..\..\shared\varindex.h">
</File>
</Filter>
<Filter
Name="Resource Files"

View file

@ -24,8 +24,7 @@
*/
#include <stdio.h>
#include <export.h>
#include <math.h>
#include <varindex.h>
#include "math.h"
#include "main.h"
@ -192,10 +191,10 @@ int eDiv_GetAngle(FUNCTION_PARAMS)
int a = getparm() ;
id1 = fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id ;
id2 = a ;
x1 = fp->mem[ id1 + fp->varindex[ _loc_x ] ] ;
y1 = fp->mem[ id1 + fp->varindex[ _loc_y ] ] ;
x2 = fp->mem[ id2 + fp->varindex[ _loc_x ] ] ;
y2 = fp->mem[ id2 + fp->varindex[ _loc_y ] ] ;
x1 = local("x",id1) ;
y1 = local("y",id1) ;
x2 = local("x",id2) ;
y2 = local("y",id2) ;
if ( (x2-x1) != 0 )
{
a = atan( (double)((y2-y1) / (x2-x1)) ) / PIOVER180 ;
@ -218,10 +217,10 @@ int eDiv_GetDist(FUNCTION_PARAMS)
int a = getparm() ;
id1 = fp->procs_s[ fp->proc_orden[*fp->proceso_actual] ].id ;
id2 = a ;
x1 = fp->mem[ id1 + fp->varindex[ _loc_x ] ] ;
y1 = fp->mem[ id1 + fp->varindex[ _loc_y ] ] ;
x2 = fp->mem[ id2 + fp->varindex[ _loc_x ] ] ;
y2 = fp->mem[ id2 + fp->varindex[ _loc_y ] ] ;
x1 = local("x",id1) ;
y1 = local("y",id1) ;
x2 = local("x",id2) ;
y2 = local("y",id2) ;
a = sqrt( pow( x2-x1 , 2 ) + pow( y2-y1 , 2 ) ) ;
return a ;
}

View file

@ -2,7 +2,7 @@
#include <SDL/SDL.h>
#include <export.h>
#include "../../shared/varindex.h"
//#include "../../shared/varindex.h"
#include "scroll.h"

View file

@ -122,9 +122,6 @@
<File
RelativePath="scroll.h">
</File>
<File
RelativePath="..\..\shared\varindex.h">
</File>
</Filter>
<Filter
Name="Resource Files"

View file

@ -2,7 +2,7 @@
#include <SDL/SDL.h>
#include <export.h>
#include "../../shared/varindex.h"
//#include "../../shared/varindex.h"
#include "../../shared/edivfont.h"
#include "text.h"
@ -200,7 +200,7 @@ int eDiv_WriteInt(FUNCTION_PARAMS)
fichero = fopen("wrin.txt" , "w+") ;
fprintf( fichero , "valor: %i\n" , fp->varindex[_glo_fps] ) ;
fprintf( fichero , "valor: %i\n" , global("fps") ) ;
fclose(fichero) ;
_itoa( fp->mem[ textos[i].offset_var ] , texto2 , 10 ) ;

View file

@ -156,9 +156,6 @@
<File
RelativePath="text.h">
</File>
<File
RelativePath="..\..\shared\varindex.h">
</File>
</Filter>
<Filter
Name="Resource Files"

View file

@ -132,7 +132,8 @@ void compila()
unsigned long m;
byte * q, * p;
int start_lin, start_dbg;
int* varptr, nvars; // variables indexadas
byte* varptr; // variables indexadas
FILE* fvar;
ultima_linea=prog;
acceso_remoto=0; parametros=0; linea=1;
@ -258,6 +259,8 @@ void compila()
// de dlopen y demas y haciendonos una pekeña lib (esto es mas aconsejable)
// +32 = El exe lleva incluido el PAK
// +64 = Compilado en modo debug
// +128 = Igual que en DIV2, el programa invoca al trazador nada más ejecutarse (se
// ha usado la orden "trazar programa" en el IDE)
// +512 = ignore_errors, igual que en DIV2
mem[0]=0;
@ -288,7 +291,37 @@ void compila()
// renombra temp.dj! al nombre del exe
rename("temp.dj!",outfilename);
// ordenamos varindex
ordena_varindex();
// escribimos en un temporal todo el indice de variables
fvar=tmpfile();
for(n=0;n<num_indexed_vars;n++) {
fputc(varindex[n].hash,fvar);
fwrite(varindex[n].nombre,1,strlen(varindex[n].nombre)+1,fvar);
fwrite(&varindex[n].offset,1,4,fvar);
fputc(varindex[n].tipo,fvar);
}
// liberamos varindex
for(n=0;n<num_indexed_vars;n++)
free(varindex[n].nombre);
free(varindex);
// lo pasamos todo del temporal a la memoria
l=ftell(fvar);
fseek(fvar,0,SEEK_SET);
varptr=(byte*)e_malloc(l);
fread(varptr,1,l,fvar);
fclose(fvar);
#ifdef _DEBUG
if(fvar=fopen("varindex.out","wb")) {
fwrite(varptr,1,l,fvar);
fclose(fvar);
}
#endif
if ((f=fopen(outfilename,"ab"))!=NULL) {
p=(byte*)e_malloc((imem+iloc)*4);
m=(imem+iloc)*4+1024;
@ -303,14 +336,16 @@ void compila()
fwrite(&m,1,sizeof(unsigned long),f);
fwrite(q,1,m,f);
free(q); free(p);
get_varptr(&varptr,&nvars); // indice de variables
m=nvars*8;
//get_varptr(&varptr,&nvars); // indice de variables
m=l*2;
q=(byte*)e_malloc(m);
if(!compress(q,&m,(byte*)varptr,nvars*4)) { // nºvariables,longitud_datos_comp,datos_comp...
fwrite(&nvars,1,4,f);
if(!compress(q,&m,varptr,l)) { // nºvariables,longitud_datos_descomp,longitud_datos_comp,datos_comp...
fwrite(&num_indexed_vars,1,4,f);
fwrite(&l,1,4,f);
fwrite(&m,1,sizeof(unsigned long),f);
fwrite(q,1,m,f);
free(q);
free(varptr);
if(debug) { // formato de ejecutable de debug
printf(translate(32));
start_lin=ftell(f);
@ -324,27 +359,31 @@ void compila()
fclose(f);
} else {
free(q);
free(varptr);
fclose(f);
errormem();
}
} else {
free(q); free(p);
free(varptr);
fclose(f);
errormem();
}
} else {
if (p!=NULL) free(p);
if (q!=NULL) free(q);
free(varptr);
fclose(f);
errormem();
}
}
else {
free(varptr);
printf(translate(33));
exit(1);
}
#ifdef __linux__
#ifndef _WIN32
chmod(outfilename,493); // -rwxr-xr-x
#endif

View file

@ -190,7 +190,7 @@ int EDIV_Export_Global(char* cadena, int valor)
return 0;
}
indexa_variable(global,cadena,imem);
indexa_variable(v_global,cadena,imem);
(*ob).tipo=tvglo;
(*ob).vglo.offset=imem;
@ -228,7 +228,7 @@ int EDIV_Export_Global_Tab(char* cadena, int numregs)
return 0;
}
indexa_variable(global,cadena,imem);
indexa_variable(v_global,cadena,imem);
(*ob).tipo=ttglo;
(*ob).tglo.offset=imem;
@ -274,6 +274,8 @@ int EDIV_Export_Global_Struct(char* cadena, int numregs)
return 0;
}
indexa_variable(v_global,cadena,imem);
decl_struct=1;
(*ob).tipo=tsglo;
@ -326,7 +328,7 @@ int EDIV_Export_Member_Int(char* cadena, int valor)
}
else { // int miembro de struct local
if(struct_reserved)
indexa_variable(reserved,cadena,iloc);
indexa_variable(v_reserved,cadena,iloc);
(*ob2).tipo=tvloc;
(*ob2).vloc.offset=len++;
loc[iloc]=valor;
@ -455,7 +457,7 @@ int EDIV_Export_Member_Tab(char* cadena, int numregs)
}
else { // array miembro de struct local
if(struct_reserved)
indexa_variable(reserved,cadena,iloc);
indexa_variable(v_reserved,cadena,iloc);
(*ob2).tipo=ttloc;
(*ob2).tloc.offset=len;
(*ob2).tloc.len1=numregs;
@ -548,7 +550,7 @@ int EDIV_Export_Local(char* cadena, int valor)
return 0;
}
indexa_variable(local,cadena,iloc);
indexa_variable(v_local,cadena,iloc);
(*ob).tipo=tvloc;
(*ob).vloc.offset=iloc;
@ -586,7 +588,7 @@ int EDIV_Export_Local_Tab(char* cadena, int numregs)
return 0;
}
indexa_variable(local,cadena,iloc);
indexa_variable(v_local,cadena,iloc);
(*ob).tipo=ttloc;
(*ob).tloc.offset=iloc;
@ -633,8 +635,12 @@ int EDIV_Export_Local_Struct(char* cadena, int numregs)
}
decl_struct=1;
if(!strcmp(cadena,"reserved"))
if(!strcmp(cadena,"reserved")) {
struct_reserved=1;
}
else {
indexa_variable(v_local,cadena,iloc);
}
(*ob).tipo=tsloc;
(*ob).sloc.offset=iloc;

View file

@ -22,11 +22,14 @@
# include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "shared.h"
#include "varindex.h"
#include "main.h"
/*
struct _vars {
tipo_t tipo;
char* nombre;
@ -84,6 +87,7 @@ struct _vars {
byte hash[NUM_INDEXED_VARS];
static int varptr[NUM_INDEXED_VARS];
*/
int res_pos=0, loc_pos=0;
@ -92,10 +96,14 @@ byte index_inicializado=0;
void inicializa_index()
{
int i;
byte *c, h;
// int i;
// byte *c, h;
memset(varptr,0,NUM_INDEXED_VARS*4);
num_indexed_vars=0;
varindex=NULL;
index_inicializado=1;
/* memset(varptr,0,NUM_INDEXED_VARS*4);
for(i=0;i<NUM_INDEXED_VARS;i++) {
h=0;
@ -108,13 +116,13 @@ void inicializa_index()
loc_pos=i;
}
index_inicializado=1;
return;
return;*/
}
void indexa_variable(tipo_t tipo, char* nombre, int ptr)
{
int i;
// int i;
byte *c, h=0;
if(!index_inicializado) return;
@ -123,11 +131,28 @@ void indexa_variable(tipo_t tipo, char* nombre, int ptr)
h=((byte)(h<<1)+(h>>7))^*c;
#ifdef DEBUG_DLL
printf("-- Indexando %s \"%s\" (hash: %d) ptr=%d... ",
tipo==global?"global":tipo==reserved?"reserved":"local",
printf("-- Indexando %s \"%s\" (hash: %d) ptr=%d\n",
tipo==v_global?"global":tipo==v_reserved?"reserved":"local",
nombre,h,ptr);
#endif
if(varindex) {
varindex=(varindex_t*)realloc(varindex,sizeof(varindex_t)*(num_indexed_vars+1));
}
else {
varindex=(varindex_t*)e_malloc(sizeof(varindex_t)*(num_indexed_vars+1));
}
varindex[num_indexed_vars].hash=h;
varindex[num_indexed_vars].tipo=tipo;
varindex[num_indexed_vars].offset=ptr;
varindex[num_indexed_vars].nombre=strdup(nombre);
num_indexed_vars++;
/* #ifdef DEBUG_DLL
printf("id asignado: %d\n",num_indexed_vars);
#endif
i=(tipo==reserved)?res_pos:((tipo==local)?loc_pos:0);
for(;i<NUM_INDEXED_VARS && vars[i].tipo==tipo;i++) {
if(h==hash[i]) if(!strcmp(nombre,vars[i].nombre)) break;
@ -144,13 +169,24 @@ void indexa_variable(tipo_t tipo, char* nombre, int ptr)
printf("id=%d encontrado!! :D\n",i);
#endif
varptr[i]=ptr;
varptr[i]=ptr;*/
return;
}
void get_varptr(int** ptr, int* nptr)
int varindex_compara(const void* a, const void* b)
{
const varindex_t *aa=(const varindex_t*)a, *bb=(const varindex_t*)b;
return aa->hash-bb->hash;
}
void ordena_varindex()
{
qsort(varindex,num_indexed_vars,sizeof(varindex_t),varindex_compara);
}
/*void get_varptr(int** ptr, int* nptr)
{
*ptr=varptr;
*nptr=NUM_INDEXED_VARS;
}
*/

View file

@ -27,6 +27,7 @@
#include <SDL/SDL.h>
#include "main.h"
#include "varindex.h"
#define MAX_EXTERN_FUNCS 0xFFFF // ¿Demasiado?
#define MAX_EXTFUNC_PARMS 0xFF
@ -84,6 +85,9 @@ typedef int (TYPEOF_Dibuja)(SDL_Surface *, SDL_Rect , SDL_Rect , int , int ) ;
typedef void (TYPEOF_Runtime_Error)(int, ...);
typedef void (TYPEOF_Critical_Error)(int, ...);
// Obtiene offset de variable indexada dinámicamente
typedef int (TYPEOF_GetVarOffset)(tipo_t tipo,char* nombre);
/////////////
// ENTRY-POINTS
///////////
@ -253,6 +257,7 @@ struct _fun_params{
TYPEOF_Call_Entrypoint *Call_Entrypoint ;
TYPEOF_Runtime_Error *Runtime_Error ;
TYPEOF_Critical_Error *Critical_Error ;
TYPEOF_GetVarOffset *GetVarOffset ;
} fp ;

View file

@ -21,20 +21,38 @@
#ifndef __VARINDEX_H
#define __VARINDEX_H
typedef enum { global, reserved, local } tipo_t;
typedef enum { v_global, v_reserved, v_local } tipo_t;
/// PROTOTIPOS ///
// compilador
void inicializa_index();
void indexa_variable(tipo_t tipo, char* nombre, int ptr);
void get_varptr(int** ptr, int* nptr);
//void get_varptr(int** ptr, int* nptr);
void ordena_varindex();
// stub
int GetVarOffset(tipo_t tipo, char* nombre);
int num_indexed_vars;
int *varindex;
#define var(a) mem[varindex[a]]
typedef struct {
unsigned char hash;
tipo_t tipo;
char* nombre;
int offset;
} varindex_t;
varindex_t* varindex;
//#define var(a) mem[varindex[a]]
#define global(nombre) mem[GetVarOffset(v_global,nombre)]
#define reserved(nombre,id) mem[(id)+GetVarOffset(v_reserved,nombre)]
#define local(nombre,id) mem[(id)+GetVarOffset(v_local,nombre)]
#define globalptr(nombre) GetVarOffset(v_global,nombre)
#define reservedptr(nombre) GetVarOffset(v_reserved,nombre)
#define localptr(nombre) GetVarOffset(v_local,nombre)
/*
//////////////////////////////
@ -102,7 +120,7 @@ int *varindex;
#define _glo_fps 45
*/
enum {
/*enum {
//////////////////////////////
/// GLOBALES ///
@ -171,6 +189,6 @@ enum {
___last // por si acaso
};
};*/
#endif // __VARINDEX_H

View file

@ -83,6 +83,7 @@ int ini_interprete()
fp.existe.dibuja = 0 ;
fp.Runtime_Error=error;
fp.Critical_Error=critical_error;
fp.GetVarOffset=GetVarOffset;
return 1 ;
@ -301,19 +302,19 @@ int proceso( int num )
retcode = 1 ;
break ;
case lcbp://30
mem[procs_s[num_proc].id+var(_res_parameters)]=mem[imem++];
mem[procs_s[num_proc].id+var(_res_param_offset)]=sp-mem[procs_s[num_proc].id+var(_res_parameters)]+1;
reserved("parameters",procs_s[num_proc].id)=mem[imem++];
reserved("param_offset",procs_s[num_proc].id)=sp-reserved("parameters",procs_s[num_proc].id)+1;
/**/procs_s[num_proc].num_params = mem[ imem-1 ] ;
break;
case lcpa://31 POR HACER #-#
mem[pila[sp--]]=pila[mem[procs_s[num_proc].id+var(_res_param_offset)]++];
mem[pila[sp--]]=pila[reserved("param_offset",procs_s[num_proc].id)++];
break;
case ltyp://32
procs_s[num_proc].id = mem[2] + ( num_proc * iloc_len ) ;
if ( procs_s[num_proc].tipo != 0 )
critical_error(3); // redefinición del tipo de proceso
procs_s[num_proc].tipo = mem[ imem++ ] ;
mem[ procs_s[num_proc].id + varindex[_res_process_type] ] = procs_s[num_proc].tipo ;
reserved("process_type",procs_s[num_proc].id) = procs_s[num_proc].tipo ;
inicio_privadas=mem[6];
break ;
case lpri://33 POR HACER

View file

@ -85,7 +85,7 @@ int* lin;
void error(int num, ...); // Mensaje de error no crítico (trazable)
void critical_error(int num, ...); // Mensaje de error crítico
void stub_quit(); // Salir del stub
void stub_quit(void); // Salir del stub
void* e_malloc(size_t size); // identico a malloc pero con errormsg utomático
#endif /* __MAIN_H */

View file

@ -57,6 +57,7 @@ int main(int argc, char* argv[])
FILE *file_tiempo ;
byte * ptr;
unsigned long len,len_descomp;
byte* vartemp;
#ifdef DBG
int start_lin;
int linsize;
@ -160,27 +161,40 @@ int main(int argc, char* argv[])
//assert(0);
read(f,&num_indexed_vars,4);
read(f,&len_descomp,4);
read(f,&len,4);
len_descomp=num_indexed_vars*4;
ptr=(byte*)e_malloc(len);
read(f,ptr,len);
varindex=(int*)e_malloc(len_descomp);
if(uncompress((byte*)varindex,&len_descomp,ptr,len)) {
vartemp=(byte*)e_malloc(len_descomp);
if(uncompress(vartemp,&len_descomp,ptr,len)) {
free(ptr);
free(varindex);
free(vartemp);
close(f);
critical_error(1); // error leyendo el código del programa
}
// assert(0) ;
for(len=0;len<num_indexed_vars;len++)
fprintf(stdout, "%d: %d\n",len,varindex[len]);
varindex=(varindex_t*)e_malloc(num_indexed_vars*sizeof(varindex_t));
ptr=vartemp;
for(i=0;i<num_indexed_vars;i++) {
varindex[i].hash=*ptr++;
varindex[i].nombre=strdup(ptr);
while(*ptr!=0) ptr++;
ptr++;
varindex[i].offset=*(int*)ptr; ptr+=4;
varindex[i].tipo=*ptr++;
#ifdef _DEBUG
fprintf(stdout, "hash: %d, nombre: %s, offset: %d, tipo: %s\n",
varindex[i].hash,varindex[i].nombre,varindex[i].offset,
varindex[i].tipo==v_global?"global":varindex[i].tipo==v_reserved?"reserved":"local");
#endif
}
free(vartemp);
dimem=long_header;
diloc=0;
//assert(0);
/// DEBUG ///
#ifdef DBG
lseek(f,-12,SEEK_END);
@ -207,11 +221,6 @@ int main(int argc, char* argv[])
close(f);
// AKI HAY KE LLAMAR A LAS RUTINAS K INICIALIZAN TODO Y LLAMAR AL INTERPRETE
// - Inicializar SDL
@ -238,7 +247,7 @@ int main(int argc, char* argv[])
atexit(SDL_Quit);
atexit(stub_quit);
// SE PONE EL MODO GRAFICO 320x200 MODO VENTANA
// Ya se hara el modo full screen
@ -304,10 +313,10 @@ int main(int argc, char* argv[])
tiempo[ tiempo_i ] = SDL_GetTicks() ;
if ( tiempo_i == 99 )
fp.mem[ fp.varindex[_glo_fps] ] = 100000 / (tiempo[99] - tiempo[0]) ;
global("fps") = 100000 / (tiempo[99] - tiempo[0]) ;
else
if ( tiempo[tiempo_i] - tiempo[tiempo_i+1] != 0 )
fp.mem[ fp.varindex[_glo_fps] ] = 100000 / (tiempo[tiempo_i] - tiempo[tiempo_i+1] ) ;
global("fps") = 100000 / (tiempo[tiempo_i] - tiempo[tiempo_i+1] ) ;
@ -334,9 +343,13 @@ int main(int argc, char* argv[])
}
void stub_quit()
void stub_quit(void)
{
exit(0) ;
int i;
for(i=0;i<num_indexed_vars;i++)
free(varindex[i].nombre);
free(varindex);
SDL_Quit();
}

View file

@ -161,6 +161,9 @@
<File
RelativePath="..\..\ediv\expresion.h">
</File>
<File
RelativePath="..\..\shared\extern.h">
</File>
<File
RelativePath="..\..\ediv\listados.h">
</File>
@ -176,6 +179,9 @@
<File
RelativePath="..\..\ediv\parser.h">
</File>
<File
RelativePath="..\..\shared\varindex.h">
</File>
</Filter>
<Filter
Name="Resource Files"

Binary file not shown.

View file

@ -237,6 +237,9 @@ makelib.bat win32.dbg
<File
RelativePath="..\..\stub\stub.c">
</File>
<File
RelativePath="..\..\stub\varindex.c">
</File>
</Filter>
<Filter
Name="Header Files"