diff --git a/dlls/src/dinmem/dinmem.c b/dlls/src/dinmem/dinmem.c new file mode 100644 index 0000000..8f2a0e9 --- /dev/null +++ b/dlls/src/dinmem/dinmem.c @@ -0,0 +1,47 @@ + +#include +#include "dinmem.h" + + +/* + * POR HACER: eDIV debe controlar todas las peticiones de memoria dinámica + * es decir, si hacemos un free() donde no debemos, debe producirse un + * fp->Runtime_Error + */ +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + + FUNCTION("malloc",1,eDiv_Malloc) ; + FUNCTION("free",1,eDiv_Free) ; + return TRUE ; +} + +int eDiv_Malloc(FUNCTION_PARAMS) +{ + int longitud ; + int *puntero ; + longitud = getparm() ; + + puntero = calloc(longitud,4) ; + if ( puntero == NULL ) { + fp->Runtime_Error(100); /* no hay memoria suficiente */ + return 0 ; + } + else + return ( puntero - fp->mem ) ; +} + +int eDiv_Free(FUNCTION_PARAMS) +{ + int offset ; + int *puntero ; + offset = getparm() ; + puntero = &fp->mem[offset] ; + free( puntero ) ; + + return 1 ; +} + + + + diff --git a/dlls/src/dinmem/dinmem.def b/dlls/src/dinmem/dinmem.def new file mode 100644 index 0000000..d0ed5e2 --- /dev/null +++ b/dlls/src/dinmem/dinmem.def @@ -0,0 +1,3 @@ +LIBRARY dinmem +EXPORTS + ExportaFuncs diff --git a/dlls/src/dinmem/dinmem.h b/dlls/src/dinmem/dinmem.h new file mode 100644 index 0000000..0e010cb --- /dev/null +++ b/dlls/src/dinmem/dinmem.h @@ -0,0 +1,7 @@ +#ifndef __EDIV_DINMEM_H_ +#define __EDIV_DINMEM_H_ + +int eDiv_Malloc(FUNCTION_PARAMS) ; +int eDiv_Free(FUNCTION_PARAMS) ; + +#endif diff --git a/dlls/src/dinmem/win32/dinmem.sln b/dlls/src/dinmem/win32/dinmem.sln new file mode 100644 index 0000000..46259ad --- /dev/null +++ b/dlls/src/dinmem/win32/dinmem.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dinmem", "dinmem.vcproj", "{2FD59E33-AB54-47EC-A3E5-3619A3921ABF}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Debug.ActiveCfg = Debug|Win32 + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Debug.Build.0 = Debug|Win32 + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Release.ActiveCfg = Release|Win32 + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/dinmem/win32/dinmem.vcproj b/dlls/src/dinmem/win32/dinmem.vcproj new file mode 100644 index 0000000..b799139 --- /dev/null +++ b/dlls/src/dinmem/win32/dinmem.vcproj @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/edivstd/edivstd.c b/dlls/src/edivstd/edivstd.c new file mode 100644 index 0000000..7280761 --- /dev/null +++ b/dlls/src/edivstd/edivstd.c @@ -0,0 +1,356 @@ +/* + * eDiv Compiler + * Copyleft (C) 2000-2002 Sion Entertainment + * http://www.sion-e.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + *EDIVSTD.DLL + * Esta librería contiene los datos más básicos que puede requerir un programa + * DIV, tal como las opciones de compilación, estructura reserved, etc. + */ + +#ifdef _WIN32 + #include + #include + unsigned int tiempo; + unsigned int ultimo_tiempo; +#else + #error ¡adapta las rutinas de timer a Linux! +#endif + +#include + +#include "export.h" +#include "edivstd.h" + +int last_type ; +int last_proc ; + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + + /* CONSTANTES PREDEFINIDAS */ + + /* Opciones de compilación */ + CONST("_max_process",0); + CONST("_extended_conditions",1); + CONST("_simple_conditions",2); + CONST("_case_sensitive",3); + CONST("_ignore_errors",4); + CONST("_free_sintax",5); + CONST("_no_check",6); + CONST("_no_strfix",7); + CONST("_no_optimization",8); + CONST("_no_range_check",9); + CONST("_no_id_check",10); + CONST("_no_null_check",11); + + /* Indicadores de ventanas (cnumber) */ + CONST("c_0",1); + CONST("c_1",2); + CONST("c_2",4); + CONST("c_3",8); + CONST("c_4",16); + CONST("c_5",32); + CONST("c_6",64); + CONST("c_7",128); + CONST("c_8",256); + CONST("c_9",512); + + /* True y false */ + CONST("true",1); + CONST("false",0); + + /* Rango de INT */ + CONST("max_int",2147483647); + CONST("min_int",-2147483648); + + /* Señales entre procesos */ + CONST("s_kill",0); + CONST("s_wakeup",1); + CONST("s_sleep",2); + CONST("s_freeze",3); + CONST("s_kill_tree",100); + CONST("s_wakeup_tree",101); + CONST("s_sleep_tree",102); + CONST("s_freeze_tree",103); + + + /* DATOS GLOBALES PREDEFINIDOS */ + + /* Contadores de tiempo */ + GLOBAL_ARRAY("timer",9); + + /* Tiempo máximo de ejecución para un proceso */ + GLOBAL("max_process_time",500); + + /* Argumentos de línea de comando */ + GLOBAL("argc",0); + GLOBAL_ARRAY("argv",9); + + + /* DATOS LOCALES PREDEFINIDOS */ + + /* Estructura reserved - POR HACER: ¿preservar compatibilidad con DIV? -> si + * pero ¿Qué hacer con distance_1 y distance_2 (sinónimos de m8_object y old_ctype, + * respectivamente)? ya nos toparemos con ellas cuando hagamos el modo7. + */ + + LOCAL_STRUCT("reserved",0); + _INT("process_id",0); + _INT("id_scan",0); + _INT("process_type",0); /* usado por VisualDIV ;) */ + _INT("type_scan",0); + _INT("status",2); + _INT("parameters",0); + _INT("param_offset",0); + _INT("program_index",0); + _INT("stack_pointer",0); + _INT("is_executed",0); + _INT("is_painted",0); + _INT("m8_object",-1); /* usado por VPE en DIV2 */ + _INT("old_ctype",0); + _INT("frame_percent",0); + _INT("box_x0",0); + _INT("box_y0",0); + _INT("box_x1",0); + _INT("box_y1",0); + _INT("f_count",0); + _INT("caller_id",0); + END_STRUCT; + + /* Jerarquía de procesos */ + LOCAL("father",0); + LOCAL("son",0); + LOCAL("smallbro",0); + LOCAL("bigbro",0); + + /* Variables locales varias */ + LOCAL("priority",0); + LOCAL("ctype",0); + LOCAL("x",0); + LOCAL("y",0); + LOCAL("z",0); + LOCAL("graph",0); + LOCAL("size",0); + LOCAL("angle",0); + LOCAL("region",0); + LOCAL("file",0); + LOCAL("xgraph",0); + LOCAL("height",1); + LOCAL("cnumber",0); + LOCAL("resolution",0); + LOCAL("flags",0); + LOCAL("transparency",128) ; + + FUNCTION("exit",2,eDIV_Exit); + FUNCTION("get_id",1,eDiv_GetId) ; + FUNCTION("define_region",5,eDiv_DefineRegion) ; + FUNCTION("signal",2,eDIV_Signal); + FUNCTION("let_me_alone",0,eDIV_Let_Me_Alone); + + ENTRYPOINT( first_load ) ; + ENTRYPOINT(frame); + + /* + * POR HACER: funciones signal, system, ignore_error... + */ + + return TRUE; +} + +int eDIV_Exit(FUNCTION_PARAMS) +{ + int codigo=getparm(); + char* mensaje=getstrparm(); + + /* + * FIXME: ¿Qué hacemos con el mensaje? ¿Lo mostramos en un msgbox si no es ""? + */ + if(*mensaje) { + #ifdef _WIN32 + MessageBox(0,mensaje,fp->nombre_program,0); + #else + fprintf(stdout,"%s\n",mensaje); + #endif + } + #ifdef _DEBUG + printf("dbg:\texit(): código de retorno: %d\n",codigo); + #endif + fp->Stub_Quit(codigo); + + /* Por si acaso :P */ + return codigo; +} + +int eDiv_GetId(FUNCTION_PARAMS) +{ + int i ,id1 ; + int a = getparm() ; + int* last_type=&reserved("type_scan",fp->procs_s[fp->proc_orden[*fp->proceso_actual]].id); + int* last_proc=&reserved("id_scan",fp->procs_s[fp->proc_orden[*fp->proceso_actual]].id); + + if ( *last_type == a ) + i = *last_proc+1 ; + else { + i = 0 ; + *last_type = a ; + } + for ( ; i < *fp->num_procs ; i++ ) + { + *last_proc = i ; + id1 = fp->procs_s[ fp->proc_orden[ i ] ].id ; + /* Si el proceso se corresponde con el type */ + if ( reserved("process_type",id1) == a ) + { + return ( fp->procs_s[ fp->proc_orden[ i ] ].id ) ; + } + } + *last_type = 0 ; + return 0 ; +} + +int eDiv_DefineRegion(FUNCTION_PARAMS) +{ + int n , x , y , w , h ; + h = getparm() ; + w = getparm() ; + y = getparm() ; + x = getparm() ; + n = getparm() ; + + if ( n > 31 || n < 1 ) { + fp->Runtime_Error(108); /* nº de región inválido */ + return 0; + } + + regions[n].x = x ; + regions[n].y = y ; + regions[n].w = w ; + regions[n].h = h ; + + + return 1 ; +} + +void signal_tree(int proc, int signal, FUNCTION_PARAMS) +{ + int id2; + if(id2=local("son",proc)) { + signal_tree(id2,signal,fp); + reserved("status",id2)=signal; + } + while(local("bigbro",id2)) { + proc=local("bigbro",id2); + reserved("status",id2)=signal; + } +} + +int eDIV_Signal(FUNCTION_PARAMS) +{ + int signal=getparm(); + int proc=getparm(); + char tree=FALSE; + + if(signal>=100) { + signal-=100; + tree=TRUE; + } + + signal++; + + /* Si se le pasa un ID */ + if(procimem_max) + { + reserved("status",proc)=signal; + if(tree && (proc=reserved("son",proc))) + signal_tree(proc,signal,fp); + } + /* Si se le pasa un type */ + else { + int i,p; + for(i=0;i<*fp->num_procs;i++) { + if(fp->procs_s[fp->proc_orden[i]].tipo==proc) { + reserved("status",fp->procs_s[fp->proc_orden[i]].id)=signal; + if(tree && (p=reserved("son",fp->procs_s[fp->proc_orden[i]].id))) + signal_tree(fp->procs_s[fp->proc_orden[i]].id,signal,fp); + } + } + } + return 0; +} + +int eDIV_Let_Me_Alone(FUNCTION_PARAMS) +{ + int i; + int _status=reservedptr("status"); + + for(i=0;i<*fp->num_procs;i++) { + if(i!=*fp->proceso_actual) { + fp->mem[fp->procs_s[fp->proc_orden[i]].id+_status]=1; /* s_kill */ + } + } + return 0; +} + + + +/* + * Entrypoints + */ +void first_load(FUNCTION_PARAMS) +{ + int i ; + + #ifdef _WIN32 + struct timeb tiempob; + ftime(&tiempob); + ultimo_tiempo=tiempob.time*100+tiempob.millitm/10; + #endif + + for ( i = 0 ; i < 32 ; i++ ) + { + regions[i].x = 0 ; + regions[i].y = 0 ; + regions[i].w = 0 ; + regions[i].h = 0 ; + } + + + fp->regions = regions ; + fp->existe.regions = 1 ; + +} + +void frame(FUNCTION_PARAMS) +{ + int i; + int timer; + #ifdef _WIN32 + struct timeb tiempob; + ftime(&tiempob); + tiempo=tiempob.time*100+tiempob.millitm/10; + timer=globalptr("timer"); + for(i=0;i<10;i++) + fp->mem[timer+i]+=tiempo-ultimo_tiempo; + ultimo_tiempo=tiempo; + #endif +} + + + diff --git a/dlls/src/edivstd/edivstd.def b/dlls/src/edivstd/edivstd.def new file mode 100644 index 0000000..8c7cce4 --- /dev/null +++ b/dlls/src/edivstd/edivstd.def @@ -0,0 +1,3 @@ +LIBRARY edivstd +EXPORTS + ExportaFuncs diff --git a/dlls/src/edivstd/edivstd.h b/dlls/src/edivstd/edivstd.h new file mode 100644 index 0000000..f1fc680 --- /dev/null +++ b/dlls/src/edivstd/edivstd.h @@ -0,0 +1,13 @@ +#ifndef __EDIV_EDIVSTD_H_ +#define __EDIV_EDIVSTD_H_ + +struct _regions regions[32] ; + +/* Prototipos */ +int eDIV_Exit(FUNCTION_PARAMS); +int eDiv_GetId(FUNCTION_PARAMS) ; +int eDiv_DefineRegion(FUNCTION_PARAMS) ; +int eDIV_Signal(FUNCTION_PARAMS); +int eDIV_Let_Me_Alone(FUNCTION_PARAMS); + +#endif \ No newline at end of file diff --git a/dlls/src/edivstd/win32/edivstd.sln b/dlls/src/edivstd/win32/edivstd.sln new file mode 100644 index 0000000..83abe2e --- /dev/null +++ b/dlls/src/edivstd/win32/edivstd.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "edivstd", "edivstd.vcproj", "{92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Debug.ActiveCfg = Debug|Win32 + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Debug.Build.0 = Debug|Win32 + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Release.ActiveCfg = Release|Win32 + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/edivstd/win32/edivstd.vcproj b/dlls/src/edivstd/win32/edivstd.vcproj new file mode 100644 index 0000000..4362934 --- /dev/null +++ b/dlls/src/edivstd/win32/edivstd.vcproj @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/file/file.c b/dlls/src/file/file.c new file mode 100644 index 0000000..5e9c142 --- /dev/null +++ b/dlls/src/file/file.c @@ -0,0 +1,174 @@ + +#include +#include + +#include +#include "file.h" + + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + + CONST("seek_cur",SEEK_CUR) ; + CONST("seek_set",SEEK_SET) ; + CONST("seek_end",SEEK_END) ; + + GLOBAL("unit_size",4); + + FUNCTION("fopen",2,eDiv_Fopen) ; + FUNCTION("fwrite",3,eDiv_Fwrite) ; + FUNCTION("fread",3,eDiv_Fread) ; + FUNCTION("ftell",1,eDiv_Ftell) ; + FUNCTION("fseek",3,eDiv_Fseek) ; + FUNCTION("flush",0,eDiv_Flush) ; + FUNCTION("fclose",1,eDiv_Fclose) ; + return TRUE ; + +} + +FILE *fichero[0xFF] ; +int existe[0xFF] ; + +/* + * POR HACER: + * Los handles deben ser IMPARES + */ + +int eDiv_Fopen(FUNCTION_PARAMS) +{ + int i ; + char *filename ; + char modo[128]; + + strcpy(modo,getstrparm()); + filename = getstrparm() ; + + for (i=0;iRuntime_Error(166); /* modo de acceso al archivo no válido */ + return 0; + } + strcat(modo,"b"); + + for ( i = 1 ; i < 0xFF ; i++ ) + if ( existe[i] == 0 ) + break ; + if ( i == 0xFF ) { + fp->Runtime_Error(169); /* demasiados archivos abiertos */ + return 0 ; + } + + fichero[i] = fopen( filename, modo ) ; + if ( fichero[i] == NULL ) { + if(errno==EMFILE) + fp->Runtime_Error(169); /* demasiados archivos abiertos */ + return 0 ; + } + + existe[i] = 1 ; + return i; +} + +int eDiv_Fwrite(FUNCTION_PARAMS) +{ + int offset , longitud , handle ; + int escrito ; + handle = getparm() ; + longitud = getparm() ; + offset = getparm() ; + + if ( !existe[handle] ) { + fp->Runtime_Error(170); /* handle no válido */ + return 0; + } + + escrito = fwrite( &fp->mem[ offset ] , global("unit_size") , longitud , fichero[handle] ) ; + + if ( escrito == longitud ) + return 1 ; + else + return 0 ; +} + +int eDiv_Fread(FUNCTION_PARAMS) +{ + int offset, longitud , handle ; + int leido ; + handle = getparm() ; + longitud = getparm() ; + offset = getparm() ; + + if ( !existe[handle] ) + return 0 ; + + leido = fread( &fp->mem[ offset ] , global("unit_size") , longitud , fichero[handle] ) ; + + if ( leido == longitud ) + return 1 ; + else + return 0 ; +} + +int eDiv_Ftell(FUNCTION_PARAMS) +{ + int handle=getparm(); + + if ( !existe[handle] ) { + fp->Runtime_Error(170); /* handle no válido */ + return -1 ; /* En caso de error, DIV2 devuelve handle, pero no me parece muy correcto... */ + } + + return (int)ftell( fichero[handle] ) ; +} + +int eDiv_Fseek(FUNCTION_PARAMS) +{ + int handle , posicion, modo ; + modo = getparm() ; + posicion = getparm()*global("unit_size") ; + handle = getparm() ; + + if ( !existe[handle] ) { + fp->Runtime_Error(170); /* handle no válido */ + return -1 ; /* ocurre lo mismo que con ftell... */ + } + + if ( fseek( fichero[handle] , posicion , modo ) == 0 ) + return 0 ; + else + return -1 ; + +} + + +int eDiv_Flush(FUNCTION_PARAMS) +{ + return flushall() ; /* flushall()-numfiles */ +} + +int eDiv_Fclose(FUNCTION_PARAMS) +{ + int handle=getparm(), num ; + + if ( handle == 0 ) + if ( ( num = fcloseall() ) == EOF ) + return 0 ; + else + return num ; + else + if ( !existe[handle] ) { + fp->Runtime_Error(170); + return 0 ; + } + else + if ( ( num = fclose( fichero[handle] ) ) == EOF ) + return 0 ; + else + return num ; +} + + + + + diff --git a/dlls/src/file/file.def b/dlls/src/file/file.def new file mode 100644 index 0000000..6972183 --- /dev/null +++ b/dlls/src/file/file.def @@ -0,0 +1,3 @@ +LIBRARY file +EXPORTS + ExportaFuncs diff --git a/dlls/src/file/file.h b/dlls/src/file/file.h new file mode 100644 index 0000000..0def7f0 --- /dev/null +++ b/dlls/src/file/file.h @@ -0,0 +1,12 @@ +#ifndef __EDIV_FILE_H_ +#define __EDIV_FILE_H_ + +int eDiv_Fopen(FUNCTION_PARAMS) ; +int eDiv_Fwrite(FUNCTION_PARAMS) ; +int eDiv_Fread(FUNCTION_PARAMS) ; +int eDiv_Ftell(FUNCTION_PARAMS) ; +int eDiv_Fseek(FUNCTION_PARAMS) ; +int eDiv_Flush(FUNCTION_PARAMS) ; +int eDiv_Fclose(FUNCTION_PARAMS) ; + +#endif diff --git a/dlls/src/file/win32/file.sln b/dlls/src/file/win32/file.sln new file mode 100644 index 0000000..1c650a8 --- /dev/null +++ b/dlls/src/file/win32/file.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "file", "file.vcproj", "{EA869297-5AC6-4603-BB86-9962207DB25F}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {EA869297-5AC6-4603-BB86-9962207DB25F}.Debug.ActiveCfg = Debug|Win32 + {EA869297-5AC6-4603-BB86-9962207DB25F}.Debug.Build.0 = Debug|Win32 + {EA869297-5AC6-4603-BB86-9962207DB25F}.Release.ActiveCfg = Release|Win32 + {EA869297-5AC6-4603-BB86-9962207DB25F}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/file/win32/file.vcproj b/dlls/src/file/win32/file.vcproj new file mode 100644 index 0000000..0563201 --- /dev/null +++ b/dlls/src/file/win32/file.vcproj @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/graphics/SDL_rotozoom.c b/dlls/src/graphics/SDL_rotozoom.c new file mode 100644 index 0000000..415835a --- /dev/null +++ b/dlls/src/graphics/SDL_rotozoom.c @@ -0,0 +1,901 @@ +/* + + SDL_rotozoom.c + + Copyright (C) A. Schiffler, July 2001 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifdef WIN32 +#include +#endif + +#include +#include + +#include "SDL_rotozoom.h" + +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) + +/* + + 32bit Zoomer with optional anti-aliasing by bilinear interpolation. + + Zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface. + +*/ + +int +zoomSurfaceRGBA (SDL_Surface * src, SDL_Surface * dst, int smooth) +{ + int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy, ex, ey, t1, t2, sstep; + tColorRGBA *c00, *c01, *c10, *c11; + tColorRGBA *sp, *csp, *dp; + int sgap, dgap, orderRGBA; + + /* Variable setup */ + if (smooth) + { + /* For interpolation: assume source dimension is one pixel */ + /* smaller to avoid overflow on right and bottom edge. */ + sx = (int) (65536.0 * (float) (src->w - 1) / (float) dst->w); + sy = (int) (65536.0 * (float) (src->h - 1) / (float) dst->h); + } + else + { + sx = (int) (65536.0 * (float) src->w / (float) dst->w); + sy = (int) (65536.0 * (float) src->h / (float) dst->h); + } + + /* Allocate memory for row increments */ + if ((sax = (int *) malloc ((dst->w + 1) * sizeof (Uint32))) == NULL) + { + return (-1); + } + if ((say = (int *) malloc ((dst->h + 1) * sizeof (Uint32))) == NULL) + { + free (sax); + return (-1); + } + + /* Precalculate row increments */ + csx = 0; + csax = sax; + for (x = 0; x <= dst->w; x++) + { + *csax = csx; + csax++; + csx &= 0xffff; + csx += sx; + } + csy = 0; + csay = say; + for (y = 0; y <= dst->h; y++) + { + *csay = csy; + csay++; + csy &= 0xffff; + csy += sy; + } + + /* Pointer setup */ + sp = csp = (tColorRGBA *) src->pixels; + dp = (tColorRGBA *) dst->pixels; + sgap = src->pitch - src->w * 4; + dgap = dst->pitch - dst->w * 4; + orderRGBA = (src->format->Rmask == 0x000000ff); + + /* Switch between interpolating and non-interpolating code */ + if (smooth) + { + + /* Interpolating Zoom */ + + /* Scan destination */ + csay = say; + for (y = 0; y < dst->h; y++) + { + /* Setup color source pointers */ + c00 = csp; + c01 = csp; + c01++; + c10 = (tColorRGBA *) ((Uint8 *) csp + src->pitch); + c11 = c10; + c11++; + csax = sax; + for (x = 0; x < dst->w; x++) + { + /* ABGR ordering */ + /* Interpolate colors */ + ex = (*csax & 0xffff); + ey = (*csay & 0xffff); + t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff; + t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff; + dp->r = (((t2 - t1) * ey) >> 16) + t1; + t1 = ((((c01->g - c00->g) * ex) >> 16) + c00->g) & 0xff; + t2 = ((((c11->g - c10->g) * ex) >> 16) + c10->g) & 0xff; + dp->g = (((t2 - t1) * ey) >> 16) + t1; + t1 = ((((c01->b - c00->b) * ex) >> 16) + c00->b) & 0xff; + t2 = ((((c11->b - c10->b) * ex) >> 16) + c10->b) & 0xff; + dp->b = (((t2 - t1) * ey) >> 16) + t1; + t1 = ((((c01->a - c00->a) * ex) >> 16) + c00->a) & 0xff; + t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff; + dp->a = (((t2 - t1) * ey) >> 16) + t1; + /* Advance source pointers */ + csax++; + sstep = (*csax >> 16); + c00 += sstep; + c01 += sstep; + c10 += sstep; + c11 += sstep; + /* Advance destination pointer */ + dp++; + } + /* Advance source pointer */ + csay++; + csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch); + /* Advance destination pointers */ + dp = (tColorRGBA *) ((Uint8 *) dp + dgap); + } + + } + else + { + + /* Non-Interpolating Zoom */ + + csay = say; + for (y = 0; y < dst->h; y++) + { + sp = csp; + csax = sax; + for (x = 0; x < dst->w; x++) + { + /* Draw */ + *dp = *sp; + /* Advance source pointers */ + csax++; + sp += (*csax >> 16); + /* Advance destination pointer */ + dp++; + } + /* Advance source pointer */ + csay++; + csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch); + /* Advance destination pointers */ + dp = (tColorRGBA *) ((Uint8 *) dp + dgap); + } + + } + + /* Remove temp arrays */ + free (sax); + free (say); + + return (0); +} + +/* + + 8bit Zoomer without smoothing. + + Zoomes 8bit palette/Y 'src' surface to 'dst' surface. + +*/ + +int +zoomSurfaceY (SDL_Surface * src, SDL_Surface * dst) +{ + Uint32 x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; + Uint8 *sp, *dp, *csp; + int dgap; + + /* Variable setup */ + sx = (Uint32) (65536.0 * (float) src->w / (float) dst->w); + sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h); + + /* Allocate memory for row increments */ + if ((sax = (Uint32 *) malloc (dst->w * sizeof (Uint32))) == NULL) + { + return (-1); + } + if ((say = (Uint32 *) malloc (dst->h * sizeof (Uint32))) == NULL) + { + if (sax != NULL) + { + free (sax); + } + return (-1); + } + + /* Precalculate row increments */ + csx = 0; + csax = sax; + for (x = 0; x < dst->w; x++) + { + csx += sx; + *csax = (csx >> 16); + csx &= 0xffff; + csax++; + } + csy = 0; + csay = say; + for (y = 0; y < dst->h; y++) + { + csy += sy; + *csay = (csy >> 16); + csy &= 0xffff; + csay++; + } + + csx = 0; + csax = sax; + for (x = 0; x < dst->w; x++) + { + csx += (*csax); + csax++; + } + csy = 0; + csay = say; + for (y = 0; y < dst->h; y++) + { + csy += (*csay); + csay++; + } + + /* Pointer setup */ + sp = csp = (Uint8 *) src->pixels; + dp = (Uint8 *) dst->pixels; + dgap = dst->pitch - dst->w; + + /* Draw */ + csay = say; + for (y = 0; y < dst->h; y++) + { + csax = sax; + sp = csp; + for (x = 0; x < dst->w; x++) + { + /* Draw */ + *dp = *sp; + /* Advance source pointers */ + sp += (*csax); + csax++; + /* Advance destination pointer */ + dp++; + } + /* Advance source pointer (for row) */ + csp += ((*csay) * src->pitch); + csay++; + /* Advance destination pointers */ + dp += dgap; + } + + /* Remove temp arrays */ + free (sax); + free (say); + + return (0); +} + +/* + + 32bit Rotozoomer with optional anti-aliasing by bilinear interpolation. + + Rotates and zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface. + +*/ + +void +transformSurfaceRGBA (SDL_Surface * src, SDL_Surface * dst, int cx, int cy, + int isin, int icos, int smooth) +{ + int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh; + tColorRGBA c00, c01, c10, c11; + tColorRGBA *pc, *sp; + int gap, orderRGBA; + + + xd = ((src->w - dst->w) << 15); + yd = ((src->h - dst->h) << 15); + ax = (cx << 16) - (icos * cx); + ay = (cy << 16) - (isin * cx); + sw = src->w - 1; + sh = src->h - 1; + pc = dst->pixels; + gap = dst->pitch - dst->w * 4; + orderRGBA = (src->format->Rmask == 0x000000ff); + + + if (smooth) + { + for (y = 0; y < dst->h; y++) + { + dy = cy - y; + sdx = (ax + (isin * dy)) + xd; + sdy = (ay - (icos * dy)) + yd; + for (x = 0; x < dst->w; x++) + { + dx = (sdx >> 16); + dy = (sdy >> 16); + if ((dx >= -1) && (dy >= -1) && (dx < src->w) && (dy < src->h)) + { + if ((dx >= 0) && (dy >= 0) && (dx < sw) && (dy < sh)) + { + sp = + (tColorRGBA *) ((Uint8 *) src->pixels + + src->pitch * dy); + sp += dx; + c00 = *sp; + sp += 1; + c01 = *sp; + sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); + sp -= 1; + c10 = *sp; + sp += 1; + c11 = *sp; + } + else if ((dx == sw) && (dy == sh)) + { + sp = + (tColorRGBA *) ((Uint8 *) src->pixels + + src->pitch * dy); + sp += dx; + c00 = *sp; + c01 = *pc; + c10 = *pc; + c11 = *pc; + } + else if ((dx == -1) && (dy == -1)) + { + sp = (tColorRGBA *) (src->pixels); + c00 = *pc; + c01 = *pc; + c10 = *pc; + c11 = *sp; + } + else if ((dx == -1) && (dy == sh)) + { + sp = (tColorRGBA *) (src->pixels); + sp = + (tColorRGBA *) ((Uint8 *) src->pixels + + src->pitch * dy); + c00 = *pc; + c01 = *sp; + c10 = *pc; + c11 = *pc; + } + else if ((dx == sw) && (dy == -1)) + { + sp = (tColorRGBA *) (src->pixels); + sp += dx; + c00 = *pc; + c01 = *pc; + c10 = *sp; + c11 = *pc; + } + else if (dx == -1) + { + sp = + (tColorRGBA *) ((Uint8 *) src->pixels + + src->pitch * dy); + c00 = *pc; + c01 = *sp; + c10 = *pc; + sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); + c11 = *sp; + } + else if (dy == -1) + { + sp = (tColorRGBA *) (src->pixels); + sp += dx; + c00 = *pc; + c01 = *pc; + c10 = *sp; + sp += 1; + c11 = *sp; + } + else if (dx == sw) + { + sp = + (tColorRGBA *) ((Uint8 *) src->pixels + + src->pitch * dy); + sp += dx; + c00 = *sp; + c01 = *pc; + sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); + c10 = *sp; + c11 = *pc; + } + else if (dy == sh) + { + sp = + (tColorRGBA *) ((Uint8 *) src->pixels + + src->pitch * dy); + sp += dx; + c00 = *sp; + sp += 1; + c01 = *sp; + c10 = *pc; + c11 = *pc; + } + ex = (sdx & 0xffff); + ey = (sdy & 0xffff); + t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff; + t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff; + pc->r = (((t2 - t1) * ey) >> 16) + t1; + t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff; + t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff; + pc->g = (((t2 - t1) * ey) >> 16) + t1; + t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff; + t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff; + pc->b = (((t2 - t1) * ey) >> 16) + t1; + t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff; + t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff; + pc->a = (((t2 - t1) * ey) >> 16) + t1; + + } + sdx += icos; + sdy += isin; + pc++; + } + pc = (tColorRGBA *) ((Uint8 *) pc + gap); + } + } + else + { + + + for (y = 0; y < dst->h; y++) + { + + dy = cy - y; + sdx = (ax + (isin * dy)) + xd; + sdy = (ay - (icos * dy)) + yd; + for (x = 0; x < dst->w; x++) + { + + dx = (short) (sdx >> 16); + dy = (short) (sdy >> 16); + if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) + { + sp = + (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); + sp += dx; + *pc = *sp; + } + sdx += icos; + sdy += isin; + pc++; + } + pc = (tColorRGBA *) ((Uint8 *) pc + gap); + } + } +} + +/* + + 8bit Rotozoomer without smoothing + + Rotates and zoomes 8bit palette/Y 'src' surface to 'dst' surface. + +*/ + +void +transformSurfaceY (SDL_Surface * src, SDL_Surface * dst, int cx, int cy, + int isin, int icos) +{ + int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay, sw, sh; + tColorY *pc, *sp; + int gap; + + /* Variable setup */ + xd = ((src->w - dst->w) << 15); + yd = ((src->h - dst->h) << 15); + ax = (cx << 16) - (icos * cx); + ay = (cy << 16) - (isin * cx); + sw = src->w - 1; + sh = src->h - 1; + pc = dst->pixels; + gap = dst->pitch - dst->w; + /* Clear surface to colorkey */ + memset (pc, (unsigned char) (src->format->colorkey & 0xff), + dst->pitch * dst->h); + /* Iterate through destination surface */ + for (y = 0; y < dst->h; y++) + { + dy = cy - y; + sdx = (ax + (isin * dy)) + xd; + sdy = (ay - (icos * dy)) + yd; + for (x = 0; x < dst->w; x++) + { + dx = (short) (sdx >> 16); + dy = (short) (sdy >> 16); + if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) + { + sp = (tColorY *) (src->pixels); + sp += (src->pitch * dy + dx); + *pc = *sp; + } + sdx += icos; + sdy += isin; + pc++; + } + pc += gap; + } +} + +/* + + rotozoomSurface() + + Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 + then the destination 32bit surface is anti-aliased. If the surface is not 8bit + or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. + +*/ + +/*XPUT/* Sanity check */ +/* Determine if source surface is 32bit or 8bit */ +/* New source surface is 32bit with a defined RGBA ordering */ +/* Sanity check zoom factor */ +/* Check if we have a rotozoom or just a zoom */ +/* Angle!=0: full rotozoom * +//* ----------------------- */ +/* Calculate target factors from sin/cos and zoom +*/ +/* Determine destination width and height by rotating a centered source box */ +/* Alloc space to completely contain the rotated surface */ +/* Target surface is 32bit with source RGBA/ABGR ordering */ +/* Lock source surface */ +/* Check which kind of surface we have */ +/* Call the 32bit transformation routine to do the rotation (using alpha) */ + +#define VALUE_LIMIT 0.001 + +SDL_Surface * +rotozoomSurface (SDL_Surface * src, double angle, double zoom, int smooth) +{ + SDL_Surface *rz_src; + SDL_Surface *rz_dst; + double zoominv; + double radangle, sanglezoom, canglezoom, sanglezoominv, canglezoominv; + int dstwidthhalf, dstwidth, dstheighthalf, dstheight; + double x, y, cx, cy, sx, sy; + int is32bit; + int i, src_converted; + + + if (src == NULL) + return (NULL); + + + is32bit = (src->format->BitsPerPixel == 32); + if ((is32bit) || (src->format->BitsPerPixel == 8)) + { + + rz_src = src; + src_converted = 0; + } + else + { + + rz_src = + SDL_CreateRGBSurface (SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, + 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface (src, NULL, rz_src, NULL); + src_converted = 1; + is32bit = 1; + } + + + if (zoom < VALUE_LIMIT) + { + zoom = VALUE_LIMIT; + } + zoominv = 65536.0 / zoom; + + + if (fabs (angle) > VALUE_LIMIT) + { + + radangle = angle * (M_PI / 180.0); + sanglezoom = sanglezoominv = sin (radangle); + canglezoom = canglezoominv = cos (radangle); + sanglezoom *= zoom; + canglezoom *= zoom; + sanglezoominv *= zoominv; + canglezoominv *= zoominv; + + x = rz_src->w / 2; + y = rz_src->h / 2; + cx = canglezoom * x; + cy = canglezoom * y; + sx = sanglezoom * x; + sy = sanglezoom * y; + dstwidthhalf = src->w; + dstheighthalf = src->h; + /*dstwidthhalf =MAX ((int) + ceil (MAX + (MAX + (MAX (fabs (cx + sy), fabs (cx - sy)), fabs (-cx + sy)), + fabs (-cx - sy))), 1); + dstheighthalf = MAX ((int) ceil (MAX (MAX (MAX (fabs (sx + cy), fabs (sx - cy)), fabs (-sx + cy)),fabs (-sx - cy))), 1); + */ + dstwidth = 2 * dstwidthhalf; + dstheight = 2 * dstheighthalf; + + rz_dst = NULL; + if (is32bit) + { + + rz_dst = + SDL_CreateRGBSurface (SDL_SWSURFACE, dstwidth, dstheight, 32, + rz_src->format->Rmask, + rz_src->format->Gmask, + rz_src->format->Bmask, + rz_src->format->Amask); + } + else + { + + rz_dst = + SDL_CreateRGBSurface (SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, + 0, 0); + } + + + SDL_LockSurface (rz_src); + + if (is32bit) + { + + transformSurfaceRGBA (rz_src, rz_dst, dstwidthhalf, dstheighthalf, + (int) (sanglezoominv), + (int) (canglezoominv), smooth); + + SDL_SetAlpha (rz_dst, SDL_SRCALPHA, 255); + } + else + { + + for (i = 0; i < rz_src->format->palette->ncolors; i++) + { + rz_dst->format->palette->colors[i] = + rz_src->format->palette->colors[i]; + } + rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; + + transformSurfaceY (rz_src, rz_dst, dstwidthhalf, dstheighthalf, + (int) (sanglezoominv), (int) (canglezoominv)); + SDL_SetColorKey (rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, + rz_src->format->colorkey); + } + + SDL_UnlockSurface (rz_src); + + } + else + { + + dstwidth = (int) ((double) rz_src->w * zoom); + dstheight = (int) ((double) rz_src->h * zoom); + if (dstwidth < 1) + { + dstwidth = 1; + } + if (dstheight < 1) + { + dstheight = 1; + } + + + rz_dst = NULL; + if (is32bit) + { + + rz_dst = + SDL_CreateRGBSurface (SDL_SWSURFACE, dstwidth, dstheight, 32, + rz_src->format->Rmask, + rz_src->format->Gmask, + rz_src->format->Bmask, + rz_src->format->Amask); + } + else + { + + rz_dst = + SDL_CreateRGBSurface (SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, + 0, 0); + } + + + SDL_LockSurface (rz_src); + + if (is32bit) + { + + zoomSurfaceRGBA (rz_src, rz_dst, smooth); + + SDL_SetAlpha (rz_dst, SDL_SRCALPHA, 255); + } + else + { + + for (i = 0; i < rz_src->format->palette->ncolors; i++) + { + rz_dst->format->palette->colors[i] = + rz_src->format->palette->colors[i]; + } + rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; + + zoomSurfaceY (rz_src, rz_dst); + SDL_SetColorKey (rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, + rz_src->format->colorkey); + } + + SDL_UnlockSurface (rz_src); + } + + + if (src_converted) + { + SDL_FreeSurface (rz_src); + } + + + return (rz_dst); +} + +/* + + zoomSurface() + + Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 + then the destination 32bit surface is anti-aliased. If the surface is not 8bit + or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. + +*/ + +#define VALUE_LIMIT 0.001 + +SDL_Surface * +zoomSurface (SDL_Surface * src, double zoomx, double zoomy, int smooth) +{ + SDL_Surface *rz_src; + SDL_Surface *rz_dst; + int dstwidth, dstheight; + int is32bit; + int i, src_converted; + + + if (src == NULL) + return (NULL); + + + + is32bit = (src->format->BitsPerPixel == 32); + + if ((is32bit) || (src->format->BitsPerPixel == 8)) + { + + rz_src = src; + src_converted = 0; + } + else + { + + rz_src = + SDL_CreateRGBSurface (SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, + 0x0000ff00, 0x00ff0000, 0xff000000); + SDL_BlitSurface (src, NULL, rz_src, NULL); + src_converted = 1; + is32bit = 1; + } + + + if (zoomx < VALUE_LIMIT) + { + zoomx = VALUE_LIMIT; + } + if (zoomy < VALUE_LIMIT) + { + zoomy = VALUE_LIMIT; + } + + dstwidth = (int) ((double) rz_src->w * zoomx); + dstheight = (int) ((double) rz_src->h * zoomy); + if (dstwidth < 1) + { + dstwidth = 1; + } + if (dstheight < 1) + { + dstheight = 1; + } + + + rz_dst = NULL; + if (is32bit) + { + + rz_dst = + SDL_CreateRGBSurface (SDL_SWSURFACE, dstwidth, dstheight, 32, + rz_src->format->Rmask, rz_src->format->Gmask, + rz_src->format->Bmask, rz_src->format->Amask); + } + else + { + + rz_dst = + SDL_CreateRGBSurface (SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, + 0); + } + + + SDL_LockSurface (rz_src); + + if (is32bit) + { + + zoomSurfaceRGBA (rz_src, rz_dst, smooth); + SDL_SetAlpha (rz_dst, SDL_SRCALPHA, 255); + } + else + { + + for (i = 0; i < rz_src->format->palette->ncolors; i++) + { + rz_dst->format->palette->colors[i] = + rz_src->format->palette->colors[i]; + } + rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; + + zoomSurfaceY (rz_src, rz_dst); + SDL_SetColorKey (rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, + rz_src->format->colorkey); + } + + SDL_UnlockSurface (rz_src); + + + if (src_converted) + { + SDL_FreeSurface (rz_src); + } + + return (rz_dst); +} + +#ifdef NORL_WIN32 + /* For DLL building under VC6 */ +BOOL APIENTRY +DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} +#endif diff --git a/dlls/src/graphics/SDL_rotozoom.h b/dlls/src/graphics/SDL_rotozoom.h new file mode 100644 index 0000000..773d496 --- /dev/null +++ b/dlls/src/graphics/SDL_rotozoom.h @@ -0,0 +1,77 @@ +#ifndef _SDL_rotozoom_h +#define _SDL_rotozoom_h + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#ifndef M_PI +#define M_PI 3.141592654 +#endif +#include + + +/* ---- Defines */ + +#define SMOOTHING_OFF 0 +#define SMOOTHING_ON 1 + +/* ---- Structures */ + + typedef struct tColorRGBA + { + Uint8 r; + Uint8 g; + Uint8 b; + Uint8 a; + } + tColorRGBA; + + typedef struct tColorY + { + Uint8 y; + } + tColorY; + + +/* ---- Prototypes */ + +/* + + rotozoomSurface() + + Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 + then the destination 32bit surface is anti-aliased. If the surface is not 8bit + or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. + +*/ + + SDL_Surface *rotozoomSurface (SDL_Surface * src, double angle, double zoom, + int smooth); + + +/* + + zoomSurface() + + Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 + then the destination 32bit surface is anti-aliased. If the surface is not 8bit + or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. + +*/ + + SDL_Surface *zoomSurface (SDL_Surface * src, double zoomx, double zoomy, + int smooth); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +}; +#endif + +#endif /* _SDL_rotozoom_h */ diff --git a/dlls/src/graphics/graphics.c b/dlls/src/graphics/graphics.c new file mode 100644 index 0000000..aabc04b --- /dev/null +++ b/dlls/src/graphics/graphics.c @@ -0,0 +1,1501 @@ +#include +#include +#include +#include +#include + +#ifndef WIN32 + #include +#endif + +#include + +#include +#include "graphics.h" +#include "SDL_rotozoom.h" + +#define ERR_CANNOTOPENFPG 105 +#define ERR_INVALIDFPGHEADER 106 +#define ERR_INVALIDMAPCODE 110 + +#define Miedzy(x,a,b) (((x) >= (a)) && ((x) <= (b))) + + + +#define FUNCTION_PARAMS2 struct _fun_params *fp + +#define MAX_DRAWS 1024 + + +struct _files files[ 0xFF ] ; + +SDL_Surface *Mapa[0xFFF] ; +SDL_Surface *fondo ; +struct _file file0[0xFFF] ; +int last_map[0xFF] ; +int color_transparente ; +int define_region ; + +typedef struct { + unsigned char r,g,b; + } pal_t; + +typedef struct _FPGHEADER8{ + char header[8]; + pal_t palette[256]; + /* char palette[768]; */ + char colorbars[576]; +}FPGHEADER8; + +typedef struct _FPGHEADER{ + char header[8]; + /* pal_t palette[256]; */ + /* char palette[768]; */ + /* char colorbars[576]; */ +}FPGHEADER; + +typedef struct _FPGMAPINFO{ + int code; + int lenght; + char description[32]; + char filename[12]; + int wide; + int height; + int number_of_points; +}FPGMAPINFO; + + +char *graphic; /* wide*height */ + + +struct{ + int existe ; + int region ; + int x , y ; + int t , c ; /* requerido para move_draw() */ + SDL_Surface *Surface ; +} draws[MAX_DRAWS] ; + +int last_draw ; + +struct _blits { + SDL_Surface *src ; + SDL_Rect srcrect ; + SDL_Surface *dst ; + SDL_Rect dstrect ; + int z ; + int trans ; +} blits[0xFFFF] , *orden[0xFFFF]; + +int last_blit ; + +int gamma[3] ; + +int smooth=0; /* Smooth para el ZOOM */ + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + + CONST("m320x200",320200); + CONST("m320x240",320240); + CONST("m320x400",320400); + CONST("m360x240",360240); + CONST("m360x360",360360); + CONST("m376x282",376282); + CONST("m400x300",400300); + CONST("m512x384",512384); + CONST("m640x400",640400); + CONST("m640x480",640480); + CONST("m800x600",800600); + CONST("m960x720",960720); + CONST("m1024x768",1024768); + CONST("m1152x864",1152864); + CONST("m1280x960",1280960); + CONST("m1280x1024",12801024); + CONST("m1600x1200",16001200); + CONST("m1900x1600",19001600); + + CONST("partial_dump",0); + CONST("complete_dump",1); + + CONST("no_restore",-1); + CONST("partial_restore",0); + CONST("complete_restore",1); + + CONST("g_wide",0); + CONST("g_height",1); + CONST("g_x_center",2); + CONST("g_y_center",3); + + CONST("all_drawing",-1); + + + GLOBAL_STRUCT("video_modes",31); + _INT("wide",0); + _INT("height",0); + _INT("bpp",0); /* NUEVO */ + _INT("mode",0); + END_STRUCT; + + GLOBAL("dump_type",1); + GLOBAL("restore_type",1); + GLOBAL("fading",0); + GLOBAL("fps",0); + GLOBAL("num_video_modes",0); + GLOBAL("vsync",0); + GLOBAL("draw_z",-255); + GLOBAL("smooth",smooth); /* > Atención una nueva variable que indica si se activa o no el SMOOTH al ZOOMEAR. */ + + FUNCTION("load_bmp",1,eDIV_LOAD_BMP) ; + FUNCTION("collision",1,eDIV_COLLISION) ; + FUNCTION("set_transparent_color",1,eDIV_SET_TRANSPARENT_COLOR) ; + FUNCTION("get_transparent_color",0,eDIV_GET_TRANSPARENT_COLOR) ; + FUNCTION("rgb",3,eDIV_RGB) ; + FUNCTION("advance",1,eDIV_ADVANCE) ; + FUNCTION("xadvance",2,eDIV_XADVANCE) ; + FUNCTION("map_block_copy",9,eDIV_MAP_BLOCK_COPY) ; + FUNCTION("map_get_pixel",4,eDIV_MAP_GET_PIXEL) ; + FUNCTION("map_put",5,eDIV_MAP_PUT); + FUNCTION("map_put_pixel",5,eDIV_MAP_PUT_PIXEL); + FUNCTION("put",4,eDIV_PUT); + FUNCTION("put_pixel",3,eDIV_PUT_PIXEL); + FUNCTION("put_screen",2,eDIV_PUT_SCREEN); + FUNCTION("clear_screen",0,eDIV_CLEAR_SCREEN); + FUNCTION("get_pixel",2,eDIV_GET_PIXEL); + FUNCTION("new_map",5,eDIV_NEW_MAP) ; + FUNCTION("screen_copy",7,eDIV_SCREEN_COPY) ; + FUNCTION("out_region",2,eDIV_OUT_REGION) ; + FUNCTION("draw",8,eDIV_DRAW) ; + FUNCTION("move_draw",7,eDIV_MOVE_DRAW) ; + FUNCTION("delete_draw",1,eDIV_DELETE_DRAW) ; + FUNCTION("load_fpg",1,eDIV_LOAD_FPG) ; + FUNCTION("get_point",5,eDIV_GET_POINT) ; + FUNCTION("get_real_point",3,eDIV_GET_REAL_POINT) ; + FUNCTION("graphic_info",3,eDIV_GRAPHIC_INFO) ; + FUNCTION("fade",4,eDIV_FADE) ; + FUNCTION("xput",6,eDIV_XPUT); + FUNCTION("get_rgb",4,eDIV_GET_RGB); + + ENTRYPOINT( frame ) ; + ENTRYPOINT( first_load ) ; + + + + return TRUE; +} + +/* + * int IntersectionRR(int rc1left,int rc1top,int rc1right,int rc1bottom,int rc2left,int rc2top,int rc2right,int rc2bottom) + * Comprueba si hay colisión entre dos regiones rectangulares. + * + * Devuelve: + * 0 - No hay colisión + * 1 - Hay colisión + */ +int IntersectionRR(int rc1left,int rc1top,int rc1right,int rc1bottom,int rc2left,int rc2top,int rc2right,int rc2bottom) +{ + return ((Miedzy(rc1left,rc2left,rc2right) || Miedzy(rc1right,rc2left,rc2right) || + Miedzy(rc2left,rc1left,rc1right) || Miedzy(rc2right,rc1left,rc1right)) && + (Miedzy(rc1top,rc2top,rc2bottom) || Miedzy(rc1bottom,rc2top,rc2bottom) || + Miedzy(rc2top,rc1top,rc1bottom) || Miedzy(rc2bottom,rc1top,rc1bottom))); +} + +/* + * A continuación las funciones que queremos exportar. Para una mayor + * sencillez las hemos puesto en este mismo archivo, aunque puede ser + * aconsejable ponerlas en archivos aparte. + */ +int eDIV_COLLISION(FUNCTION_PARAMS) +{ + int g1 , g2 ; + int f1 , f2 ; + int id1, id2 ; + int a, i ; + SDL_Rect r1 , r2 ; + int _status=reservedptr("status"); + a = getparm() ; + + id1 = fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id ; + + g1 = local("graph",id1) ; + f1 = local("file",id1) ; + if ( files[f1].existe == 0 || files[f1].mapa[g1].existe == 0 ) + return 0; + + /* Si se le pasa un ID */ + if (aimem_max) + { + if(a==id1 || (fp->mem[id1+_status]!=2 && fp->mem[id1+_status]!=4)) + return 0; + 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 = local("graph",id2) ; + f2 = local("file",id2); + if ( files[f2].existe == 0 || files[f2].mapa[g2].existe == 0 ) + return 0; + 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 */ + if(IntersectionRR(r1.x,r1.y,r1.x+r1.w-1,r1.x+r1.h-1,r2.x,r2.y,r2.x+r2.w-1,r2.y+r2.h-1)) + return id2; + } + else { + int* type_scan=&reserved("type_scan",id1); + int* id_scan=&reserved("id_scan",id1); + /* Si se le pasa un type */ + + if(*type_scan!=a) { + *id_scan=0; + *type_scan=a; + } + + for ( i = *id_scan+1 ; i < *fp->num_procs ; i++ ) + { + id2 = fp->procs_s[ fp->proc_orden[ i ] ].id; + if(id2==id1 || (fp->mem[id1+_status]!=2 && fp->mem[id1+_status]!=4)) + continue; + + /* Si el proceso se corresponde con el type */ + if ( reserved("process_type",id2) == a ) + { + + 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 ; + g2 = local("graph",id2) ; + f2 = local("file",id2) ; + if ( files[f2].existe == 0 || files[f2].mapa[g2].existe == 0 ) + continue; + 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 */ + if(IntersectionRR(r1.x,r1.y,r1.x+r1.w-1,r1.x+r1.h-1,r2.x,r2.y,r2.x+r2.w-1,r2.y+r2.h-1)) { + *id_scan=i; + + return id2; + } + } + } + *type_scan=0; + } + + return 0 ; +} + +/*****************************************************************/ +/* */ +/* eDIV_LOAD_BMP(filename); */ +/* */ +/* Carga un BMP donde 'filename' es el fichero a cargar. */ +/* */ +/* Retorna: El numero de Mapa. */ +/* -1 : Si no se ha podido cargar el mapa. */ +/* */ +/*****************************************************************/ +int eDIV_LOAD_BMP(FUNCTION_PARAMS) +{ + int i ; + const char *filename=getstrparm(); /* Fichero a cargar */ + for ( i = 1000 ; i < files[0].num ; i++ ) + { + if ( files[0].mapa[i].existe == 0 ) + { + files[0].mapa[i].Surface = SDL_LoadBMP( filename ) ; + if(files[0].mapa[i].Surface == NULL) + fp->Runtime_Error(143); /* "No se pudo cargar el mapa, archivo no encontrado." */ + files[0].mapa[i].existe = 1 ; + files[0].mapa[i].cpoint[0].x = (int)files[0].mapa[i].Surface->w / 2 ; + files[0].mapa[i].cpoint[0].y = (int)files[0].mapa[i].Surface->h / 2 ; + SDL_SetColorKey( files[0].mapa[i].Surface , SDL_SRCCOLORKEY | SDL_RLEACCEL , color_transparente ) ; + if ( i > last_map[0] ) + last_map[0] = i ; + return i ; + } + } + return -1 ; +} + +/*****************************************************************/ +/* */ +/* eDIV_SET_TRANSPARENT_COLOR(a); */ +/* */ +/* Coloca cual es el color transparente donde 'a' es el color. */ +/* */ +/* Retorna: El antiguo color transparente. */ +/* */ +/*****************************************************************/ + +int eDIV_SET_TRANSPARENT_COLOR(FUNCTION_PARAMS) +{ + int b , i; + int a = getparm() ; + b = color_transparente ; + color_transparente = a ; + for ( i = 1 ; i <= last_map[0] ; i++ ) + { + if ( files[0].mapa[i].existe ) + SDL_SetColorKey( files[0].mapa[i].Surface , SDL_SRCCOLORKEY | SDL_RLEACCEL , color_transparente ) ; + } + return b ; +} + +/*****************************************************************/ +/* */ +/* eDIV_GET_TRANSPARENT_COLOR(); */ +/* */ +/* Retorna: El color transparente. */ +/* */ +/*****************************************************************/ + +int eDIV_GET_TRANSPARENT_COLOR(FUNCTION_PARAMS) +{ + return color_transparente ; +} + +/*****************************************************************/ +/* */ +/* eDIV_RGB(r,g,b); */ +/* */ +/* Crea un color a partir de los 3 colores basicos. . */ +/* */ +/* r=Rojo (Red) g=Verde (Green) b=Blue (Azul) */ +/* */ +/* Retorna: El color generado. */ +/* */ +/*****************************************************************/ + +int eDIV_RGB(FUNCTION_PARAMS) +{ + int r,g,b ; + b = getparm() ; + g = getparm() ; + r = getparm() ; + + return ( b + g*256 + r*65536 ) ; +} + +/*****************************************************************/ +/* */ +/* eDIV_GET_RGB(color, offset r, offset g, offset b); */ +/* */ +/* Obtiene las componentes RGB de un color dado. */ +/* */ +/* r=Rojo (Red) g=Verde (Green) b=Blue (Azul) */ +/* */ +/* Retorna: 1 */ +/* */ +/*****************************************************************/ +int eDIV_GET_RGB(FUNCTION_PARAMS) +{ + unsigned int color,roff,goff,boff; + unsigned char r,g,b; + boff=getparm(); + goff=getparm(); + roff=getparm(); + color=getparm(); + SDL_GetRGB(color,fp->screen->format,&r,&g,&b); + if(roff) fp->mem[roff]=(int)r; + if(goff) fp->mem[goff]=(int)g; + if(boff) fp->mem[boff]=(int)b; + return 1; +} + +/*****************************************************************/ +/* */ +/* eDIV_ADVANCE(a); */ +/* */ +/* Avanza 'a' unidades segun el angulo del proceso. . */ +/* */ +/* Retorna: 1. */ +/* */ +/*****************************************************************/ + +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 = local("angle",id1) ; + x = (int) ((double)a * cos( (angulo/1000) * PIOVER180 )) ; + y = (int) ((double)a * sin( (angulo/1000) * PIOVER180 )) ; + local("x",id1) += x; + local("y",id1) += y ; + return 1 ; +} + +/*****************************************************************/ +/* */ +/* eDIV_XADVANCE(angle,b) */ +/* */ +/* Avanza 'b' unidades segun el angulo 'angle' . . */ +/* */ +/* Retorna: 1 */ +/* */ +/*****************************************************************/ + +int eDIV_XADVANCE(FUNCTION_PARAMS) +{ + int a , b , id1 , x , y , angulo ; + b = getparm() ; + a = getparm() ; + id1 = fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id ; + angulo = a ; + x = (int) ((double)b * cos( (angulo/1000) * PIOVER180 )) ; + y = (int) ((double)b * sin( (angulo/1000) * PIOVER180 )) ; + local("x",id1) += x ; + local("y",id1) += y ; + return 1 ; +} + +int eDIV_MAP_BLOCK_COPY(FUNCTION_PARAMS) +{ + int f , g2 , x2 , y2 , g1 , x1 , y1 , w , h ; + SDL_Rect srcrect , dstrect ; + h = getparm() ; + w = getparm() ; + y1 = getparm() ; + x1 = getparm() ; + g1 = getparm() ; + y2 = getparm() ; + x2 = getparm() ; + g2 = getparm() ; + f = getparm() ; + + srcrect.x = x1 ; + srcrect.y = y1 ; + srcrect.w = w ; + srcrect.h = h ; + + dstrect.x = x2 ; + dstrect.y = y2 ; + dstrect.w = srcrect.w ; + dstrect.h = srcrect.h ; + + if ( !files[f].existe || !files[f].mapa[g1].existe || !files[f].mapa[g2].existe ) + return -1 ; + + SDL_BlitSurface( files[f].mapa[g1].Surface , &srcrect , files[f].mapa[g2].Surface , &dstrect ) ; + return 1 ; + +} + +/*****************************************************************/ +/* */ +/* eDIV_MAP_GET_PIXEL(y,x,g,f); */ +/* */ +/* Coje el color de un pixel, de un mapa. Coordenadas, x e y */ +/* */ +/* del mapa 'g' del fichero 'f'. */ +/* */ +/* Retorna: El color del pixel. */ +/* */ +/*****************************************************************/ + +int eDIV_MAP_GET_PIXEL(FUNCTION_PARAMS) +{ + int f , g , x , y , bpp ; + Uint8 *p ; + y = getparm() ; + x = getparm() ; + g = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + if ( x > files[f].mapa[g].Surface->w || y > files[f].mapa[g].Surface->h || x < 0 || y < 0 ) + return -2 ; + + bpp = files[f].mapa[g].Surface->format->BytesPerPixel; + p = (Uint8 *)files[f].mapa[g].Surface->pixels + y * files[f].mapa[g].Surface->pitch + x * bpp; + + switch(bpp) { + case 1: + return *p; + case 2: + return *(Uint16 *)p; + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + return p[0] << 16 | p[1] << 8 | p[2]; + }else + { + return p[0] | p[1] << 8 | p[2] << 16; + } + case 4: + return *(Uint32 *)p; + } + + return 0; +} + +int eDIV_MAP_PUT(FUNCTION_PARAMS) +{ + int f , g2 , g1 , x , y ; + SDL_Rect dstrect ; + y = getparm() ; + x = getparm() ; + g1 = getparm() ; + g2 = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g1].existe || !files[f].mapa[g2].existe ) + return -1 ; + + dstrect.x = x ; + dstrect.y = y ; + dstrect.w = 0 ; /* Se ignora */ + dstrect.h = 0 ; /* Se ignora */ + + SDL_BlitSurface( files[f].mapa[g1].Surface , NULL , files[f].mapa[g2].Surface , &dstrect ) ; + return 1 ; + +} + +int eDIV_MAP_PUT_PIXEL(FUNCTION_PARAMS) +{ + int f , g , x , y , c , bpp ; + Uint8 *p ; + + + c = getparm() ; + y = getparm() ; + x = getparm() ; + g = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[0].mapa[g].existe ) + return -1 ; + + if ( x > files[f].mapa[g].Surface->w || y > files[f].mapa[g].Surface->h || x < 0 || y < 0 ) + return -2 ; + + if ( SDL_MUSTLOCK( files[f].mapa[g].Surface ) ) { + if ( SDL_LockSurface( files[f].mapa[g].Surface ) < 0 ) { + return -3; + } + } + + + bpp = files[f].mapa[g].Surface->format->BytesPerPixel ; + p = (Uint8 *)files[f].mapa[g].Surface->pixels + y * files[f].mapa[g].Surface->pitch + x * bpp ; + + switch(bpp) { + + case 1: + *p = c; + break; + + case 2: + *(Uint16 *)p = c; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (c >> 16) & 0xff; + p[1] = (c >> 8) & 0xff; + p[2] = c & 0xff; + } else { + p[0] = c & 0xff; + p[1] = (c >> 8) & 0xff; + p[2] = (c >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = c; + break; + } + + if ( SDL_MUSTLOCK( files[f].mapa[g].Surface ) ) { + SDL_UnlockSurface( files[f].mapa[g].Surface ); + } + + + return 1 ; +} + + +int eDIV_PUT(FUNCTION_PARAMS) +{ + int f , g , x , y ; + SDL_Rect dstrect ; + + y = getparm() ; + x = getparm() ; + g = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + dstrect.x = x - files[f].mapa[g].cpoint[0].x ; + dstrect.y = y - files[f].mapa[g].cpoint[0].y ; + dstrect.w = 0 ; /* Se ignora */ + dstrect.h = 0 ; /* Se ignora */ + + SDL_BlitSurface( files[f].mapa[g].Surface , NULL , fondo , &dstrect ) ; + + return 1 ; + +} + +/*****************************************************************/ +/* */ +/* eDIV_XPUT(f,g,x,y,angle,zoom); */ +/* */ +/* Coloca un MAPA 'g' del fichero 'f' en x e y con un angulo */ +/* angle y un tamaño zoom/100; */ +/* */ +/* Retorna: 1: Si se ha colocado correctamente */ +/* -1: Si el mapa no existe. */ +/*****************************************************************/ + +int eDIV_XPUT(FUNCTION_PARAMS) +{ + int f , g , x , y ; + double zoom,angle; + SDL_Surface *map; + SDL_Rect dstrect ; + + zoom = getparm(); + angle = getparm(); + y = getparm() ; + x = getparm() ; + g = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + dstrect.x = x - files[f].mapa[g].cpoint[0].x ; + dstrect.y = y - files[f].mapa[g].cpoint[0].y ; + dstrect.w = 0 ; /* Se ignora */ + dstrect.h = 0 ; /* Se ignora */ + + map=xput(files[f].mapa[g].Surface,zoom,angle); + + SDL_BlitSurface(map , NULL , fondo , &dstrect ) ; + SDL_FreeSurface (map); + + return 1 ; + +} + + + + +int eDIV_PUT_SCREEN(FUNCTION_PARAMS) +{ + int f , g ; + + g = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + SDL_BlitSurface( files[f].mapa[g].Surface , NULL , fondo , NULL ) ; + + return 1 ; + +} + +int eDIV_PUT_PIXEL(FUNCTION_PARAMS) +{ + int x , y , c , bpp ; + Uint8 *p ; + + + c = getparm() ; + y = getparm() ; + x = getparm() ; + + if ( x > fondo->w || y > fondo->h || x < 0 || y < 0 ) + return -1 ; + + if ( SDL_MUSTLOCK(fondo) ) { + if ( SDL_LockSurface(fondo) < 0 ) { + return -2; + } + } + + + bpp = fondo->format->BytesPerPixel ; + p = (Uint8 *)fondo->pixels + y * fondo->pitch + x * bpp ; + + switch(bpp) { + + case 1: + *p = c; + break; + + case 2: + *(Uint16 *)p = c; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (c >> 16) & 0xff; + p[1] = (c >> 8) & 0xff; + p[2] = c & 0xff; + } else { + p[0] = c & 0xff; + p[1] = (c >> 8) & 0xff; + p[2] = (c >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = c; + break; + } + + if ( SDL_MUSTLOCK(fondo) ) { + SDL_UnlockSurface(fondo); + } + + + return 1 ; +} + + + +int eDIV_CLEAR_SCREEN(FUNCTION_PARAMS) +{ + SDL_FillRect( fondo , NULL , 0 ) ; + + return 1; +} + + +int eDIV_GET_PIXEL(FUNCTION_PARAMS) +{ + int x , y , bpp; + Uint8 *p ; + y = getparm() ; + x = getparm() ; + + if ( x > fondo->w || y > fondo->h || x < 0 || y < 0 ) + return -1 ; + + bpp = fondo->format->BytesPerPixel; + p = (Uint8 *)fondo->pixels + y * fondo->pitch + x * bpp; + + switch(bpp) { + case 1: + return *p; + case 2: + return *(Uint16 *)p; + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + return p[0] << 16 | p[1] << 8 | p[2]; + }else + { + return p[0] | p[1] << 8 | p[2] << 16; + } + case 4: + return *(Uint32 *)p; + } + + return 0; +} + + +int eDIV_NEW_MAP(FUNCTION_PARAMS) +{ + int i ; + int w , h , cx , cy , c ; + c = getparm() ; + cy = getparm() ; + cx = getparm() ; + h = getparm() ; + w = getparm() ; + + for ( i = 1000 ; i < files[0].num ; i++ ) + { + if ( !files[0].mapa[i].existe ) + { + files[0].mapa[i].Surface = SDL_CreateRGBSurface( SDL_HWSURFACE , w , h , screen->format->BitsPerPixel , 0xFF0000 , 0x00FF00 , 0x0000FF , 0x000000 ) ; + files[0].mapa[i].existe = 1 ; + files[0].mapa[i].cpoint[0].x = cx ; + files[0].mapa[i].cpoint[0].y = cy ; + SDL_FillRect( files[0].mapa[i].Surface , NULL , c ) ; + SDL_SetColorKey( files[0].mapa[i].Surface , SDL_SRCCOLORKEY | SDL_RLEACCEL , color_transparente ) ; + if ( i > last_map[0] ) + last_map[0] = i ; + return i ; + } + } + return -1 ; +} + + +int eDIV_SCREEN_COPY(FUNCTION_PARAMS) +{ + SDL_Rect srcrect , dstrect ; + int r, f, g , x, y , w , h ; + h = getparm() ; + w = getparm() ; + y = getparm() ; + x = getparm() ; + g = getparm() ; + f = getparm() ; + r = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + srcrect.x = 0 ; + srcrect.y = 0 ; + srcrect.w = w ; + srcrect.h = h ; + + dstrect.x = x ; + dstrect.y = y ; + dstrect.w = 0 ; + dstrect.h = 0 ; + + SDL_BlitSurface( screen, &srcrect , files[f].mapa[g].Surface , &dstrect ) ; + return 1 ; +} + +int eDIV_OUT_REGION(FUNCTION_PARAMS2) +{ + int id , r ; + int f, g , x , y ; + r = getparm() ; + id = getparm() ; + + f = local("file",id) ; + g = local("graph",id) ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + 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 ) + return 0 ; + else + return 1 ; +} + +int eDIV_DRAW(FUNCTION_PARAMS2) +{ + int i ; + int t , c , o , r , x0, y0 , x1 , y1 ; + SDL_Rect dstrect ; + y1 = getparm() ; + x1 = getparm() ; + y0 = getparm() ; + x0 = getparm() ; + r = getparm() ; + o = getparm() ; + c = getparm() ; + t = getparm() ; + + for ( i = 0 ; i < 1024 ; i++ ) + { + if ( draws[i].existe == 0 ) + { + draws[i].Surface = SDL_CreateRGBSurface( SDL_HWSURFACE , x1 - x0 , y1 - y0 , screen->format->BitsPerPixel , 0xFF0000 , 0x00FF00 , 0x0000FF , 0x000000 ) ; + switch ( t ) + { + case 3: + dstrect.x = 0 ; + dstrect.y = 0 ; + dstrect.w = x1 - x0 ; + dstrect.h = y1 - y0 ; + SDL_FillRect( draws[i].Surface , &dstrect , c ) ; + break ; + } + draws[i].region = r ; + draws[i].x = x0 ; + draws[i].y = y0 ; + draws[i].t = t ; + draws[i].c = c ; + if ( o < 15 && o > -1 ) + SDL_SetAlpha( draws[i].Surface , SDL_SRCALPHA | SDL_RLEACCEL , 17 * (o) ) ; + draws[i].existe = 1 ; + if ( i > last_draw ) + last_draw = i ; + return i ; + } + } + return -1 ; +} + +int eDIV_MOVE_DRAW(FUNCTION_PARAMS2) +{ + SDL_Rect dstrect ; + int id , c , o , x0 , y0 , x1 , y1 ; + y1 = getparm() ; + x1 = getparm() ; + y0 = getparm() ; + x0 = getparm() ; + o = getparm() ; + c = getparm() ; + id = getparm() ; + + if ( !draws[id].existe ) + return -1 ; + + if ( x1 - x0 != draws[id].Surface->w || y1 - y0 != draws[id].Surface->h || c != draws[id].c ) + { + if ( x1 - x0 != draws[id].Surface->w || y1 - y0 != draws[id].Surface->h ) + { + SDL_FreeSurface( draws[id].Surface ) ; + draws[id].Surface = SDL_CreateRGBSurface( SDL_HWSURFACE , x1 - x0 , y1 - y0 , screen->format->BitsPerPixel , 0xFF0000 , 0x00FF00 , 0x0000FF , 0x000000 ) ; + } + switch ( draws[id].t ) + { + case 3: + dstrect.x = 0 ; + dstrect.y = 0 ; + dstrect.w = x1 - x0 ; + dstrect.h = y1 - y0 ; + SDL_FillRect( draws[id].Surface , &dstrect , c ) ; + break ; + } + } + + draws[id].x = x0 ; + draws[id].y = y0 ; + draws[id].c = c ; + if ( o < 15 && o > -1 ) + SDL_SetAlpha( draws[id].Surface , SDL_SRCALPHA | SDL_RLEACCEL , 17 * (o) ) ; + else + if ( o == 15 ) + SDL_SetAlpha( draws[id].Surface , 0 , 255 ) ; + + return 1 ; +} + +int eDIV_DELETE_DRAW(FUNCTION_PARAMS2) +{ + int n ; + n = getparm() ; + + if(n==-1) { + for(n=0;n 0 ; last_draw-- ) + { + if ( draws[last_draw].existe ) + break ; + } + return 1 ; + + + +} + + +int eDIV_LOAD_FPG(FUNCTION_PARAMS2) +{ + char * archivo ; + FILE *f; + FPGHEADER8 cabecera8; + FPGHEADER cabecera; + FPGMAPINFO infomapa; + int tamano; + int cont=0,num,i; + int bpp; + + SDL_Color p[256]; + + archivo = getstrparm() ; + + f=fopen(archivo,"rb"); + if(f==NULL) { + fp->Runtime_Error(ERR_CANNOTOPENFPG); + } + + fseek(f,0,SEEK_END); + tamano=ftell(f); + fseek(f,0,SEEK_SET); + + 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")) { + if(strcmp(cabecera.header,"f32\x1A\x0D\x0A")) { + fp->Runtime_Error(ERR_INVALIDFPGHEADER); + } + else { + bpp=32; + } + } + else { + bpp=24; + } + } + else { + bpp=16; + } + } + else { + bpp=8; + fseek(f,0,SEEK_SET); + fread(&cabecera8,1,sizeof(FPGHEADER8),f); + + for(i=0;i<256;i++) { + p[i].r=cabecera8.palette[i].r*4; + p[i].g=cabecera8.palette[i].g*4; + p[i].b=cabecera8.palette[i].b*4; + } + SDL_SetPalette(screen,SDL_LOGPAL|SDL_PHYSPAL,p,0,256); + } + + + + while(ftell(f)999 || num<0) { + fp->Runtime_Error(ERR_INVALIDMAPCODE); + } + if ( files[0].mapa[num].existe == 1 ) + return -1 ; + files[0].mapa[num].existe = 1 ; + + if(infomapa.number_of_points==0) { + files[0].mapa[num].cpoint[0].x = (int) infomapa.wide/2 ; + files[0].mapa[num].cpoint[0].y = (int) infomapa.height/2 ; + } else { + fread(files[0].mapa[num].cpoint,2,2*infomapa.number_of_points,f) ; + } + + graphic = (char*)malloc(infomapa.wide*infomapa.height*bpp/8); + fread(graphic,1,infomapa.wide*infomapa.height*bpp/8,f); + + files[0].mapa[num].Surface = SDL_CreateRGBSurfaceFrom(graphic,infomapa.wide,infomapa.height,bpp,infomapa.wide*bpp/8,0,0,0,0) ; + + cont++; + if(bpp==8) { + SDL_SetPalette(files[0].mapa[num].Surface,SDL_LOGPAL|SDL_PHYSPAL,p,0,256); + } + SDL_SetColorKey(files[0].mapa[num].Surface,SDL_SRCCOLORKEY|SDL_RLEACCEL,0); + } + + fclose(f); + return 0; +} + +int eDIV_GET_POINT(FUNCTION_PARAMS2) +{ + int f , g , n , dx , dy ; + dy = getparm() ; + dx = getparm() ; + n = getparm() ; + g = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + fp->mem[ dx ] = files[f].mapa[g].cpoint[n].x ; + fp->mem[ dy ] = files[f].mapa[g].cpoint[n].y ; + + return 0 ; +} + +int eDIV_GET_REAL_POINT(FUNCTION_PARAMS2) +{ + int f , g , n , dx , dy , x , y , id; + dy = getparm() ; + dx = getparm() ; + n = getparm() ; + 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 ; + + fp->mem[ dx ] = files[f].mapa[g].cpoint[n].x - files[f].mapa[g].cpoint[0].x + x ; + fp->mem[ dy ] = files[f].mapa[g].cpoint[n].y - files[f].mapa[g].cpoint[0].y + y ; + + return 0 ; +} + +int eDIV_GRAPHIC_INFO(FUNCTION_PARAMS2) +{ + int f , g , i ; + i = getparm() ; + g = getparm() ; + f = getparm() ; + + if ( !files[f].existe || !files[f].mapa[g].existe ) + return -1 ; + + switch (i) + { + case 0: + return files[f].mapa[g].Surface->w ; + case 1: + return files[f].mapa[g].Surface->h ; + case 2: + return files[f].mapa[g].cpoint[0].x ; + case 3: + return files[f].mapa[g].cpoint[0].y ; + } + return -1; +} + + +int eDIV_FADE(FUNCTION_PARAMS2) +{ + int r , g , b , v ; + v = getparm() ; + b = getparm() ; + g = getparm() ; + r = getparm() ; + + return SDL_SetGamma( 1.0f , 1.0f , 1.0f ) ; + return 1 ; +} + +/* + * Entrypoints + */ +FILE * fichero ; +FILE * memo ; + +/* + * Función para usar con qsort() para ordenar los blits por su Z + */ +int ordena_por_z(const void* a, const void* b) +{ + struct _blits* aa=(struct _blits*)a; + struct _blits* bb=(struct _blits*)b; + return (aa->z>bb->z)?-1:((aa->zz)?1:0); +} + +void frame(FUNCTION_PARAMS) +{ + static int una_vez = 1 ; + int i , id , f , g , r , z , trans,angle,size,resolution; + SDL_Rect dstrect , srcrect ; + + fichero = fopen( "draw.txt" , "w" ) ; + + if ( define_region == 1) + { + + if ( fp->existe.regions == 1 ) + { + define_region = 0 ; + fp->regions[0].x = 0 ; + fp->regions[0].y = 0 ; + fp->regions[0].w = 320 ; + fp->regions[0].h = 200 ; + } + } + + SDL_BlitSurface( fondo , NULL , screen , NULL ) ; + + /* + * Draws + */ + z = global("draw_z"); + smooth = global("smooth"); + for ( i = 0 ; i <= last_draw ; i++ ) + { + if ( draws[i].existe ) + { + if ( draws[i].x + draws[i].Surface->w >= fp->regions[0].x && draws[i].x < fp->regions[0].x + fp->regions[0].w && + draws[i].y + draws[i].Surface->h >= fp->regions[0].y && draws[i].y < fp->regions[0].y + fp->regions[0].h ) + { + if ( draws[i].x >= fp->regions[0].x && draws[i].x + draws[i].Surface->w < fp->regions[0].x + fp->regions[0].w && + draws[i].y >= fp->regions[0].y && draws[i].y + draws[i].Surface->h < fp->regions[0].y + fp->regions[0].h ) + { + srcrect.x = 0 ; + srcrect.y = 0 ; + srcrect.w = draws[i].Surface->w ; + srcrect.h = draws[i].Surface->h ; + + dstrect.x = draws[i].x ; + dstrect.y = draws[i].y ; + dstrect.w = 0 ; /* Se ignora */ + dstrect.h = 0 ; /* Se ignora */ + Dibuja( draws[i].Surface , srcrect , dstrect , z , draws[i].t,100,0) ; + } + } + } + } + + /* + * Procesos + */ + for ( i = 0 ; i < *fp->num_procs ; i++ ) + { + int _status=reservedptr("status"); + id = fp->procs_s[ fp->proc_orden[i] ].id ; + + if(fp->mem[id+_status]!=2 && fp->mem[id+_status]!=4) + continue; + + f = local("file",id); + g = local("graph",id); + r = local("region",id); + z = local("z",id); + size = local("size",id); + angle = local("angle",id); + dstrect.x = local("x",id); + dstrect.y = local("y",id); + resolution = local("resolution",id); + if(resolution!=0) + { + dstrect.x = dstrect.x / resolution; + dstrect.y = dstrect.y / resolution; + } + dstrect.w = 0 ; + dstrect.h = 0 ; + if ( files[f].mapa[g].existe ) + { + srcrect.x = 0 ; + srcrect.y = 0 ; + srcrect.w = files[f].mapa[g].Surface->w ; + 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 ( local("flags",id) & 4 ) + if ( local("flags",id) & 8 ) { + trans = 255 - local("transparency",id); + if(trans<0) trans=0; else if(trans>255) trans=255; + } + else + trans = 128 ; + else + trans = SDL_ALPHA_OPAQUE ; + if ( r == 0 ) + Dibuja( files[f].mapa[g].Surface , srcrect , dstrect , z , trans , size , angle) ; + else if ( define_region == 0 ) + { + if ( dstrect.x >= fp->regions[r].x && dstrect.x + files[f].mapa[g].Surface->w <= fp->regions[r].x + fp->regions[r].w && + dstrect.y >= fp->regions[r].y && dstrect.y + files[f].mapa[g].Surface->h <= fp->regions[r].y + fp->regions[r].h ) + { + + Dibuja( files[f].mapa[g].Surface , srcrect , dstrect , z , trans , size , angle) ; + }else + { + if ( dstrect.x < fp->regions[r].x + fp->regions[r].w && dstrect.x + files[f].mapa[g].Surface->w > fp->regions[r].x && + dstrect.y < fp->regions[r].y + fp->regions[r].h && dstrect.y + files[f].mapa[g].Surface->h > fp->regions[r].y ) + { + srcrect.x = 0 ; + srcrect.y = 0 ; + srcrect.w = files[f].mapa[g].Surface->w ; + srcrect.h = files[f].mapa[g].Surface->h ; + + if ( dstrect.x < fp->regions[r].x ) + { + srcrect.x = fp->regions[r].x - dstrect.x ; + srcrect.w -= fp->regions[r].x - dstrect.x ; + dstrect.x = fp->regions[r].x ; + } + if ( dstrect.y < fp->regions[r].y ) + { + srcrect.y = fp->regions[r].y - dstrect.y ; + srcrect.h -= fp->regions[r].y - dstrect.y ; + dstrect.y = fp->regions[r].y ; + } + if ( dstrect.x + srcrect.w > fp->regions[r].x + fp->regions[r].w ) + { + srcrect.w -= dstrect.x + srcrect.w - fp->regions[r].x - fp->regions[r].w ; + } + if ( dstrect.y + srcrect.h > fp->regions[r].y + fp->regions[r].h ) + { + srcrect.h -= dstrect.y + srcrect.h - fp->regions[r].y - fp->regions[r].h ; + } + + + Dibuja( files[f].mapa[g].Surface , srcrect , dstrect , z , trans , size , angle) ; + } + } + } + } + } + /* + * Volcamos la pila de bliteos + */ + qsort(blits,last_blit+1,sizeof(struct _blits),ordena_por_z); + + for ( i = 0 ; i <= last_blit ; i++ ) + { + SDL_BlitSurface( blits[i].src , &blits[i].srcrect , screen , &blits[i].dstrect ) ; + SDL_FreeSurface (blits[i].src); + } + last_blit = -1 ; + + SDL_Flip(screen) ; + fp->screen=screen; + fclose(fichero); + +} + +void first_load(FUNCTION_PARAMS2) +{ + Uint32 rmask , gmask , bmask , amask ; + int i ; + + fp->Dibuja = Dibuja ; + fp->files = files ; + fp->existe.dibuja = 1 ; + + + + for ( i = 0 ; i < 0xFF ; i++ ) + last_map[i] = 0 ; + color_transparente = 0 ; + + /* + * TODO: Añadir comprobacion de errores en los 2 if siguientes (Daijo) + */ + if (SDL_Init(SDL_INIT_VIDEO)) ; + if ( screen == NULL ) ; + + + screen = SDL_SetVideoMode(320, 200, 24, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL); + rmask = 0x00ff0000; + gmask = 0x0000ff00; + bmask = 0x000000ff; + amask = 0x00000000; + fondo = SDL_CreateRGBSurface( SDL_HWSURFACE , 320 , 200 , 24 , rmask , gmask , bmask , amask ) ; + + for ( i = 0 ; i < 0xFF ; i++ ) + { + files[i].existe = 0 ; + } + files[0].existe = 1 ; + files[0].num = 0xFFF ; + files[0].mapa = file0 ; + + for ( i = 0 ; i < 0xFFF ; i++ ) + { + files[0].mapa[i].existe = 0 ; + } + + last_blit = -1 ; + + gamma[0] = 128 ; + gamma[1] = 128 ; + gamma[2] = 128 ; + + define_region = 1 ; + + SDL_WM_SetCaption(fp->nombre_program, NULL); + SDL_ShowCursor(0); +} + + + + +/* + * Funciones Internas de la DLL + */ + +/* + * Dibuja + * Se encarga de meter un registro en la pila de bliteos, segun su z + * Esta funcion no se encarga de discernir si esta dentro o fuera de la region o pantalla, + * eso se debe calcular antes y pasarle la informacion resultante a Dibuja + */ + +int Dibuja(SDL_Surface *src , SDL_Rect srcrect , SDL_Rect dstrect , int z , int trans,int size,int angle) +{ + float zoom; + double angulo; + register int i , j ; + + last_blit++ ; + + + if (size==0) + size=100; + if (size>100) + size=100; + + zoom=size*0.01; + + angulo=angle/1000; + + blits[last_blit].src =xput(src, zoom,angulo); + + /* + * Pequeño hack para arreglar transparency + * Debería limpiarse y revisarse un poco :P + */ + if(blits[last_blit].src->flags & SDL_SRCALPHA) { + for(i=0;ih*blits[last_blit].src->w*blits[last_blit].src->format->BytesPerPixel;i+=blits[last_blit].src->format->BytesPerPixel) { + if(*((int*)&((unsigned char*)blits[last_blit].src->pixels)[i])!=color_transparente) + ((unsigned char*)blits[last_blit].src->pixels)[i+3]=trans; + } + } + else { + SDL_SetAlpha(blits[last_blit].src,SDL_SRCALPHA,trans); + } + + blits[last_blit].srcrect.x = srcrect.x ; + blits[last_blit].srcrect.y = srcrect.y ; + blits[last_blit].srcrect.w = blits[last_blit].src->w; + blits[last_blit].srcrect.h = blits[last_blit].src->h; + blits[last_blit].dstrect.x = dstrect.x ; + blits[last_blit].dstrect.y = dstrect.y ; + blits[last_blit].dstrect.w = dstrect.w ; + blits[last_blit].dstrect.h = dstrect.h ; + blits[last_blit].z = z ; + blits[last_blit].trans = trans ; + + return 1 ; +} + +SDL_Surface *xput(SDL_Surface *src,double size,double angle) +{ + + int s; + SDL_Surface *dst; + SDL_Surface *tmp; + + s=smooth; + if(size==1 && angle ==0)s=0; + tmp= zoomSurface (src, size, size,s); + dst=rotozoomSurface (tmp, angle, 1,s); + SDL_FreeSurface (tmp); + + return dst; +} \ No newline at end of file diff --git a/dlls/src/graphics/graphics.def b/dlls/src/graphics/graphics.def new file mode 100644 index 0000000..544fd3d --- /dev/null +++ b/dlls/src/graphics/graphics.def @@ -0,0 +1,3 @@ +LIBRARY graphics +EXPORTS + ExportaFuncs diff --git a/dlls/src/graphics/graphics.h b/dlls/src/graphics/graphics.h new file mode 100644 index 0000000..53669bd --- /dev/null +++ b/dlls/src/graphics/graphics.h @@ -0,0 +1,44 @@ +#ifndef __EDIV_GRAPHICS_H_ +#define __EDIV_GRAPHICS_H_ + +#include + +#define PIOVER180 0.017453292519943295769236907684886 + +SDL_Surface *screen; +SDL_Surface *prueba; + +int eDIV_LOAD_BMP(FUNCTION_PARAMS); +int eDIV_COLLISION(FUNCTION_PARAMS); +int eDIV_SET_TRANSPARENT_COLOR(FUNCTION_PARAMS); +int eDIV_GET_TRANSPARENT_COLOR(FUNCTION_PARAMS); +int eDIV_RGB(FUNCTION_PARAMS); +int eDIV_GET_RGB(FUNCTION_PARAMS); +int eDIV_ADVANCE(FUNCTION_PARAMS); +int eDIV_XADVANCE(FUNCTION_PARAMS) ; +int eDIV_MAP_BLOCK_COPY(FUNCION_PARMAS) ; +int eDIV_MAP_GET_PIXEL(FUNCION_PARMAS) ; +int eDIV_MAP_PUT(FUNCION_PARMAS) ; +int eDIV_MAP_PUT_PIXEL(FUNCTION_PARAMS); +int eDIV_PUT(FUNCTION_PARAMS); +int eDIV_PUT_PIXEL(FUNCTION_PARAMS); +int eDIV_PUT_SCREEN(FUNCION_PARAMS); +int eDIV_CLEAR_SCREEN(FUNCTION_PARAMS); +int eDIV_GET_PIXEL(FUNCTION_PARAMS); +int eDIV_NEW_MAP(FUNCTION_PARAMS) ; +int eDIV_SCREEN_COPY(FUNCTION_PARAMS) ; +int eDIV_OUT_REGION(FUNCTION_PARAMS) ; +int eDIV_DRAW(FUNCTION_PARAMS) ; +int eDIV_MOVE_DRAW(FUNCTION_PARAMS) ; +int eDIV_DELETE_DRAW(FUNCTION_PARAMS) ; +int eDIV_LOAD_FPG(FUNCTION_PARAMS) ; +int eDIV_GET_POINT(FUNCTION_PARAMS) ; +int eDIV_GET_REAL_POINT(FUNCTION_PARAMS) ; +int eDIV_GRAPHIC_INFO(FUNCTION_PARAMS) ; +int eDIV_FADE(FUNCTION_PARAMS) ; +int eDIV_XPUT(FUNCTION_PARAMS); + +int Dibuja(SDL_Surface *src , SDL_Rect srcrect , SDL_Rect dstrect , int z , int trans,int size,int angle); +SDL_Surface *xput(SDL_Surface *src,double size,double angle); + +#endif \ No newline at end of file diff --git a/dlls/src/graphics/win32/graphics.sln b/dlls/src/graphics/win32/graphics.sln new file mode 100644 index 0000000..98be379 --- /dev/null +++ b/dlls/src/graphics/win32/graphics.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graphics", "graphics.vcproj", "{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.ActiveCfg = Debug|Win32 + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.Build.0 = Debug|Win32 + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.ActiveCfg = Release|Win32 + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/graphics/win32/graphics.vcproj b/dlls/src/graphics/win32/graphics.vcproj new file mode 100644 index 0000000..3ef73aa --- /dev/null +++ b/dlls/src/graphics/win32/graphics.vcproj @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/include/export.h b/dlls/src/include/export.h new file mode 100644 index 0000000..06fd970 --- /dev/null +++ b/dlls/src/include/export.h @@ -0,0 +1,281 @@ + +/* + * eDiv Compiler + * Copyleft (C) 2000-2002 Sion Entertainment + * http://www.sion-e.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Este fichero es la cabecera para las DLL's de eDIV. + * Para saber cómo se utiliza, consulte el eDIV SDK de la documentación de eDIV + * ESTE FICHERO -NO- HA DE SER MODIFICADO PARA CREAR DLLs, TAN SÓLO POR + * DESARROLLADORES DE eDIV. EN CASO DE SER MODIFICADO, SE PERDERÁ LA + * COMPATIBILIDAD CON eDIV Y EL RESTO DE DLLs. + * En caso de encontrar cualquier bug o anomalía en este archivo, por favor + * notifíquelo a Sion Entertainment en bugs@edivcentral.com + */ + +#ifndef __EDIV_EXPORT_H_ +#define __EDIV_EXPORT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* COMPATIBILIDAD WIN <-> LINUX */ + +#ifdef _WIN32 +# include +#else + #ifndef bool + typedef enum { FALSE, TRUE } bool; + #endif +#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 + +/* Funciones de exportación de datos */ +typedef int (TYPEOF_EDIV_Export)(char* cadena, int nparam, void* hfuncion); +typedef int (TYPEOF_EDIV_Export_Const)(char* cadena, int valor); +typedef int (TYPEOF_EDIV_Export_Global)(char* cadena, int valor); +typedef int (TYPEOF_EDIV_Export_Global_Tab)(char* cadena, int numregs); +typedef int (TYPEOF_EDIV_Export_Global_Struct)(char* cadena, int numregs); +typedef int (TYPEOF_EDIV_Export_Member_Int)(char* cadena, int valor); +typedef int (TYPEOF_EDIV_Export_Member_Str)(char* cadena, int tamano); +typedef int (TYPEOF_EDIV_Export_Member_Tab)(char* cadena, int numregs); +typedef int (TYPEOF_EDIV_Export_EndStruct)(); +typedef int (TYPEOF_EDIV_Export_Local)(char* cadena, int valor); +typedef int (TYPEOF_EDIV_Export_Local_Tab)(char* cadena, int numregs); +typedef int (TYPEOF_EDIV_Export_Local_Struct)(char* cadena, int numregs); +typedef int (TYPEOF_EDIV_Export_Entrypoint)(int ep, void* hfuncion); +typedef int (TYPEOF_EDIV_Export_Priority)(int priority); + +/* Call_Entrypoint */ +typedef int (TYPEOF_Call_Entrypoint)(int ep, ...); + +/* Dibuja */ +typedef int (TYPEOF_Dibuja)(SDL_Surface *, SDL_Rect, SDL_Rect, int, int, int, int); + +/* Errores */ +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); + +/* Finaliza el stub (exit) */ +typedef void (TYPEOF_Stub_Quit)(int n); + +/* EXPORTAFUNCS_PARAMS deben usarse como parámetros para ExportaFuncs */ +#define EXPORTAFUNCS_PARAMS \ +TYPEOF_EDIV_Export *EDIV_Export ,\ +TYPEOF_EDIV_Export_Const *EDIV_Export_Const ,\ +TYPEOF_EDIV_Export_Global *EDIV_Export_Global ,\ +TYPEOF_EDIV_Export_Global_Tab *EDIV_Export_Global_Tab ,\ +TYPEOF_EDIV_Export_Global_Struct *EDIV_Export_Global_Struct,\ +TYPEOF_EDIV_Export_Member_Int *EDIV_Export_Member_Int ,\ +TYPEOF_EDIV_Export_Member_Str *EDIV_Export_Member_Str ,\ +TYPEOF_EDIV_Export_Member_Tab *EDIV_Export_Member_Tab ,\ +TYPEOF_EDIV_Export_EndStruct *EDIV_Export_EndStruct ,\ +TYPEOF_EDIV_Export_Local *EDIV_Export_Local ,\ +TYPEOF_EDIV_Export_Local_Tab *EDIV_Export_Local_Tab ,\ +TYPEOF_EDIV_Export_Local_Struct *EDIV_Export_Local_Struct ,\ +TYPEOF_EDIV_Export_Entrypoint *EDIV_Export_Entrypoint ,\ +TYPEOF_EDIV_Export_Priority *EDIV_Export_Priority + + +/* + * ENTRY-POINTS + * + * Estas funciones son llamadas por el STUB en determinados eventos + * (Cuando una DLL hace cierta acción, lo avisa al Stub y el stub se encarga de llamar + * a las correspondientes rutinas de las dll's, ordenadas por prioridad) + */ + +// Constantes para EDIV_Export_Entrypoint + +#define EDIV_set_video_mode 1 /* Al activar un nuevo modo de vídeo */ +#define EDIV_process_palette 2 /* Al cargar una paleta */ +#define EDIV_process_active_palette 3 /* Al modificar la paleta activa (usada en los fades) */ +#define EDIV_process_sound 4 /* Al cargar un efecto sonoro */ +#define EDIV_process_map 5 /* Al cargar un mapa */ +#define EDIV_process_fpg 6 /* Al cargar un FPG */ +#define EDIV_process_fnt 7 /* Al cargar una fuente */ +#define EDIV_background_to_buffer 8 /* Volcar el fondo al buffer */ +#define EDIV_buffer_to_video 9 /* Volcar el buffer a la memoria de video */ +#define EDIV_post_process_scroll 10 /* Tras dibujar una ventana de scroll (sin los sprites) */ +#define EDIV_post_process_m7 11 /* Tras dibujar una ventana de modo7 (sin los sprites) */ +#define EDIV_post_process_m8 12 /* Tras dibujar una ventana de modo8 (sin los sprites) */ +#define EDIV_post_process_buffer 13 /* Tras haber terminado de dibujarlo todo */ +#define EDIV_post_process 14 /* Tras ejecutar el frame de un proceso (cualquier %) */ +#define EDIV_put_sprite 15 /* Dibujar un sprite */ +#define EDIV_ss_init 16 /* Inicio de salvapantallas */ +#define EDIV_ss_frame 17 /* Frame de salvapantallas */ +#define EDIV_ss_end 18 /* Fin de salvapantallas */ +#define EDIV_frame 19 /* En cada frame */ +#define EDIV_trace 20 /* Después de ejecutar cada instrucción de bytecode (solo en debug) */ +#define EDIV_debug 21 /* Invocar al trazador - sentencia debug (solo en debug) */ +#define EDIV_first_load 22 /* Se ejecuta al cargar la DLL en ejecucion */ +#define EDIV_quit 23 /* Llamado por stub_quit() */ + + +/* #defines para que la declaración de datos sea un poco más BASIC... :p */ +#ifdef CONST +# undef CONST +#endif +#define FUNCTION EDIV_Export +#define CONST EDIV_Export_Const +#define GLOBAL EDIV_Export_Global +#define GLOBAL_ARRAY EDIV_Export_Global_Tab +#define GLOBAL_STRUCT EDIV_Export_Global_Struct +#define _INT EDIV_Export_Member_Int +#define _STRING EDIV_Export_Member_Str +#define _ARRAY EDIV_Export_Member_Tab +#define END_STRUCT EDIV_Export_EndStruct() +#define LOCAL EDIV_Export_Local +#define LOCAL_ARRAY EDIV_Export_Local_Tab +#define LOCAL_STRUCT EDIV_Export_Local_Struct +#define ENTRYPOINT(e) EDIV_Export_Entrypoint(EDIV_##e,e) +#define PRIORITY EDIV_Export_Priority + + +/* + * FUNCTION_PARAMS deben usarse como parametros para TODAS las funciones + * ¡ojo! debe ser igual en extern.h + */ +#define FUNCTION_PARAMS struct _fun_params *fp + +struct _procs_s{ + int id ; /* offset de los datos locales del proceso */ + int tipo ; /* tipo de proceso */ + int orden ; /* indice en proc_orden[] */ + int num_params ; /* numero de parametros k coje ( NO SE PARA K SIRVE PERO PARA ALGO ESTARA CBP NO ? ) */ + int imem ; /* Posicion en la k se quedo suspendido el proceso */ + int priority ; /* Priority */ + int frame; /* Frame completado */ + int graph ; +}; + +struct _regions +{ + int x , y , w , h ; +} ; + +struct _existe { + int regions ; + int dibuja ; +} ; +struct _file +{ + SDL_Surface *Surface ; + int existe ; + struct + { + int x , y ; + } cpoint[ 20 ] ; +} ; + +struct _files +{ + int num ; + int existe ; + struct _file *mapa ; +} ; + +struct _fun_params{ + int *pila ; + int *sp ; + int *mem ; + int num_params; + varindex_t *varindex ; + struct _procs_s *procs_s ; + int *num_procs ; + int *proc_orden ; + int *proceso_actual ; + unsigned char* nombre_program; + struct _regions *regions ; + struct _existe existe ; + struct _files *files ; + TYPEOF_Dibuja *Dibuja ; + TYPEOF_Call_Entrypoint *Call_Entrypoint ; + TYPEOF_Runtime_Error *Runtime_Error ; + TYPEOF_Critical_Error *Critical_Error ; + TYPEOF_GetVarOffset *GetVarOffset ; + TYPEOF_Stub_Quit *Stub_Quit ; + int imem_max; + SDL_Surface *screen; +} ; + + +/* Se usa igual que el getparm() de DIV */ +#define getparm() fp->pila[(*fp->sp)--] +#define getstrparm() (char*)&fp->mem[fp->pila[(*fp->sp)--]] + +/* Y esto por si los despistes xD */ +#define retval(a) return (a) + + +/* Prototipos de los entrypoints */ +void set_video_mode(void); +void process_palette(void); +void process_active_palette(void); +void process_sound(char *sound,int lenght); +void process_fpg(char *fpg,int fpg_lenght); +void process_map(char *map,int map_lenght); +void process_fnt(char *fnt,int fnt_lenght); +void background_to_buffer(void); +void buffer_to_video(void); +void post_process_scroll(void); +void post_process_m7(void); +void post_process_m8(void); +void post_process_buffer(void); +void post_process(void); +void put_sprite(unsigned char * si, int x,int y, int an, int al, int xg, int yg, + int ang, int size, int flags); +void ss_init(void); +void ss_frame(void); +void ss_end(void); +void frame(FUNCTION_PARAMS); +void trace(int imem, char* nombreprg, int* lin, void* dbg); +void debug(int imem, char* nombreprg, int* lin, void* dbg); +void first_load(FUNCTION_PARAMS) ; +void quit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __EDIV_EXPORT_H_ */ diff --git a/dlls/src/input/input.c b/dlls/src/input/input.c new file mode 100644 index 0000000..72ef03f --- /dev/null +++ b/dlls/src/input/input.c @@ -0,0 +1,494 @@ +/* + * eDiv Compiler + * Copyleft (C) 2000-2002 Sion Entertainment + * http://www.sion-e.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include +#include "input.h" + +#define _KEY(a) CONST(#a,a) + + +#define _esc 1 +#define _f1 59 +#define _f2 60 +#define _f3 61 +#define _f4 62 +#define _f5 63 +#define _f6 64 +#define _f7 65 +#define _f8 66 +#define _f9 67 +#define _f10 68 +#define _f11 87 +#define _f12 88 +#define _prn_scr 55 /* Impr Pant */ +#define _scroll_lock 70 /* Bloq Despl */ + +#define _wave 41 /* "º" */ +#define _1 2 +#define _2 3 +#define _3 4 +#define _4 5 +#define _5 6 +#define _6 7 +#define _7 8 +#define _8 9 +#define _9 10 +#define _0 11 +#define _minus 12 /* ? */ +#define _plus 13 /* ¿ */ + +#define _backspace 14 +#define _tab 15 +#define _q 16 +#define _w 17 +#define _e 18 +#define _r 19 +#define _t 20 +#define _y 21 +#define _u 22 +#define _i 23 +#define _o 24 +#define _p 25 +#define _l_brachet 26 /* "`" "^" */ +#define _r_brachet 27 /* "+" "*" */ +#define _enter 28 + +#define _caps_lock 58 +#define _a 30 +#define _s 31 +#define _d 32 +#define _f 33 +#define _g 34 +#define _h 35 +#define _j 36 +#define _k 37 +#define _l 38 +#define _semicolon 39 /* Ñ */ +#define _apostrophe 40 /* { */ +#define _backslash 43 /* } */ + +#define _l_shift 42 +#define _z 44 +#define _x 45 +#define _c 46 +#define _v 47 +#define _b 48 +#define _n 49 +#define _m 50 +#define _comma 51 +#define _point 52 +#define _slash 53 /* "-" "_" */ +#define _r_shift 54 + +#define _control 29 +#define _alt 56 +#define _space 57 + +#define _ins 82 +#define _home 71 +#define _pgup 73 +#define _del 83 +#define _end 79 +#define _pgdn 81 + +#define _up 72 +#define _down 80 +#define _left 75 +#define _right 77 + +#define _num_lock 69 +#define _c_backslash 90 +#define _c_asterisk 91 +#define _c_minus 92 +#define _c_home 93 +#define _c_up 94 +#define _c_pgup 95 +#define _c_left 96 +#define _c_center 97 +#define _c_right 98 +#define _c_end 99 +#define _c_down 100 +#define _c_pgdn 101 +#define _c_ins 102 +#define _c_del 103 +#define _c_plus 104 +#define _c_enter 105 + + + +Uint8 *keys ; +Uint8 mbuttons; + +int SDLtoDIV[1024] ; + + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + _KEY(_esc) ; + _KEY(_f1) ; + _KEY(_f2) ; + _KEY(_f3) ; + _KEY(_f4) ; + _KEY(_f5) ; + _KEY(_f6) ; + _KEY(_f7) ; + _KEY(_f8) ; + _KEY(_f9) ; + _KEY(_f10) ; + _KEY(_f11) ; + _KEY(_f12) ; + _KEY(_prn_scr ) ; + _KEY(_scroll_lock ) ; + _KEY(_wave) ; + _KEY(_1) ; + _KEY(_2) ; + _KEY(_3) ; + _KEY(_4) ; + _KEY(_5) ; + _KEY(_6) ; + _KEY(_7) ; + _KEY(_8) ; + _KEY(_9) ; + _KEY(_0) ; + _KEY(_minus) ; + _KEY(_plus) ; + _KEY(_backspace) ; + _KEY(_tab) ; + _KEY(_q) ; + _KEY(_w) ; + _KEY(_e) ; + _KEY(_r) ; + _KEY(_t) ; + _KEY(_y) ; + _KEY(_u) ; + _KEY(_i) ; + _KEY(_o) ; + _KEY(_p) ; + _KEY(_l_brachet) ; + _KEY(_r_brachet) ; + _KEY(_enter) ; + _KEY(_caps_lock ) ; + _KEY(_a) ; + _KEY(_s) ; + _KEY(_d) ; + _KEY(_f) ; + _KEY(_g) ; + _KEY(_h) ; + _KEY(_j) ; + _KEY(_k) ; + _KEY(_l) ; + _KEY(_semicolon) ; + _KEY(_apostrophe) ; + _KEY(_backslash) ; + _KEY(_l_shift) ; + _KEY(_z) ; + _KEY(_x) ; + _KEY(_c) ; + _KEY(_v) ; + _KEY(_b) ; + _KEY(_n) ; + _KEY(_m) ; + _KEY(_comma) ; + _KEY(_point) ; + _KEY(_slash) ; + _KEY(_r_shift) ; + _KEY(_control) ; + _KEY(_alt) ; + _KEY(_space) ; + _KEY(_ins) ; + _KEY(_home) ; + _KEY(_pgup) ; + _KEY(_del) ; + _KEY(_end) ; + _KEY(_pgdn) ; + _KEY(_up) ; + _KEY(_down) ; + _KEY(_left) ; + _KEY(_right) ; + _KEY(_num_lock) ; + _KEY(_c_backslash) ; + _KEY(_c_asterisk) ; + _KEY(_c_minus) ; + _KEY(_c_plus) ; + _KEY(_c_enter) ; + _KEY(_c_home) ; + _KEY(_c_pgup) ; + _KEY(_c_end) ; + _KEY(_c_pgdn) ; + _KEY(_c_up) ; + _KEY(_c_down) ; + _KEY(_c_left) ; + _KEY(_c_right) ; + _KEY(_c_center) ; + _KEY(_c_ins) ; + _KEY(_c_del) ; + + FUNCTION("key",1,eDiv_Key) ; + + GLOBAL_STRUCT("mouse",0); + _INT("x",0); /* Coordenada x */ + _INT("y",0); /* Coordenada y */ + _INT("graph",0); /* Gráfico */ + _INT("file",0); /* FPG */ + _INT("z",-512); /* Profundidad (TODO) */ + _INT("angle",0); /* Ángulo (TODO) */ + _INT("size",100); /* Tamaño (TODO) */ + _INT("flags",0); /* Banderas (TODO) */ + _INT("region",0); /* Región (TODO) */ + _INT("left",0); /* Botón izquierdo */ + _INT("middle",0); /* Botón central o de ruedecilla */ + _INT("right",0); /* Botón derecho */ + _INT("wheelup",0); /* Ruedecilla arriba (NUEVO) */ + _INT("wheeldown",0); /* Ruedecilla abajo (NUEVO) */ + _INT("cursor",0); /* Emulación con teclas de cursor (TODO) */ + _INT("speed",0); /* Velocidad del ratón (TODO) */ + _INT("transparency",0); /* Transparencia (NUEVO) (TODO) */ + END_STRUCT; + + ENTRYPOINT(first_load) ; + ENTRYPOINT(frame) ; + + return TRUE; +} + +int eDiv_Key(FUNCTION_PARAMS) +{ + /* FILE *fichero ; */ + int a ; + + /* fichero = fopen("input.txt" , "a+" ) ; */ + a = getparm() ; + /* fprintf( fichero , "key: %i , keys[30]: %i \n" , a , keys[30] ) ; */ + /* fclose( fichero ) ; */ + + if ( a == _control ) + if ( keys[ SDLK_RCTRL ] ) + return 1 ; + if ( a == _alt ) + if ( keys[ SDLK_RALT ] ) + return 1 ; + + return keys[ SDLtoDIV[a] ] ; +} + +/* + * Entrypoints + */ +void first_load(FUNCTION_PARAMS) +{ + int i ; + SDL_Init( SDL_INIT_EVENTTHREAD ) ; + + for ( i = 0 ; i < 1024 ; i++ ) + { + SDLtoDIV[ i ] = 0 ; + } + + SDLtoDIV[ _esc ] = SDLK_ESCAPE ; + SDLtoDIV[ _1 ] = SDLK_1 ; + SDLtoDIV[ _2 ] = SDLK_2 ; + SDLtoDIV[ _3 ] = SDLK_3 ; + SDLtoDIV[ _4 ] = SDLK_4 ; + SDLtoDIV[ _5 ] = SDLK_5 ; + SDLtoDIV[ _6 ] = SDLK_6 ; + SDLtoDIV[ _7 ] = SDLK_7 ; + SDLtoDIV[ _8 ] = SDLK_8 ; + SDLtoDIV[ _9 ] = SDLK_9 ; + SDLtoDIV[ _0 ] = SDLK_0 ; + SDLtoDIV[ _minus ] = SDLK_MINUS ; + SDLtoDIV[ _plus ] =SDLK_EQUALS ; + SDLtoDIV[ _backspace ] =SDLK_BACKSPACE ; + SDLtoDIV[ _tab ] =SDLK_TAB ; + SDLtoDIV[ _p ] =SDLK_p ; + SDLtoDIV[ _w ] =SDLK_w ; + SDLtoDIV[ _e ] =SDLK_e ; + SDLtoDIV[ _r ] =SDLK_r ; + SDLtoDIV[ _t ] =SDLK_t ; + SDLtoDIV[ _y ] =SDLK_y ; + SDLtoDIV[ _u ] =SDLK_u ; + SDLtoDIV[ _i ] =SDLK_i ; + SDLtoDIV[ _o ] =SDLK_o ; + SDLtoDIV[ _p ] =SDLK_p ; + SDLtoDIV[ _l_brachet ] =SDLK_LEFTBRACKET ; + SDLtoDIV[ _r_brachet ] =SDLK_RIGHTBRACKET ; + SDLtoDIV[ _enter ] =SDLK_RETURN ; + SDLtoDIV[ _control ] =SDLK_LCTRL ; + SDLtoDIV[ _a ] =SDLK_a ; + SDLtoDIV[ _s ] =SDLK_s ; + SDLtoDIV[ _d ] =SDLK_d ; + SDLtoDIV[ _f ] =SDLK_f ; + SDLtoDIV[ _g ] =SDLK_g ; + SDLtoDIV[ _h ] =SDLK_h ; + SDLtoDIV[ _j ] =SDLK_j ; + SDLtoDIV[ _k ] =SDLK_k ; + SDLtoDIV[ _l ] =SDLK_l ; + SDLtoDIV[ _semicolon ] =SDLK_SEMICOLON ; + SDLtoDIV[ _apostrophe ] =SDLK_QUOTE ; + SDLtoDIV[ _wave ] =SDLK_BACKQUOTE ; + SDLtoDIV[ _l_shift ] =SDLK_LSHIFT ; + SDLtoDIV[ _backslash ] =SDLK_BACKSLASH ; + SDLtoDIV[ _z ] =SDLK_z ; + SDLtoDIV[ _x ] =SDLK_x ; + SDLtoDIV[ _c ] =SDLK_c ; + SDLtoDIV[ _v ] =SDLK_v ; + SDLtoDIV[ _b ] =SDLK_b ; + SDLtoDIV[ _n ] =SDLK_n ; + SDLtoDIV[ _m ] =SDLK_m ; + SDLtoDIV[ _comma ] =SDLK_COMMA ; + SDLtoDIV[ _point ] =SDLK_PERIOD ; + SDLtoDIV[ _slash ] =SDLK_SLASH ; + SDLtoDIV[ _r_shift ] =SDLK_RSHIFT ; + SDLtoDIV[ _prn_scr ] =SDLK_SYSREQ ; + SDLtoDIV[ _alt ] =SDLK_LALT ; + SDLtoDIV[ _space ] =SDLK_SPACE ; + SDLtoDIV[ _caps_lock ] =SDLK_CAPSLOCK ; + SDLtoDIV[ _f1 ] =SDLK_F1 ; + SDLtoDIV[ _f2 ] =SDLK_F2 ; + SDLtoDIV[ _f3 ] =SDLK_F3 ; + SDLtoDIV[ _f4 ] =SDLK_F4 ; + SDLtoDIV[ _f5 ] =SDLK_F5 ; + SDLtoDIV[ _f6 ] =SDLK_F6 ; + SDLtoDIV[ _f7 ] =SDLK_F7 ; + SDLtoDIV[ _f8 ] =SDLK_F8 ; + SDLtoDIV[ _f9 ] =SDLK_F9 ; + SDLtoDIV[ _f10 ] =SDLK_F10 ; + SDLtoDIV[ _f11 ] =SDLK_F11 ; + SDLtoDIV[ _f12 ] =SDLK_F12 ; + SDLtoDIV[ _num_lock ] =SDLK_NUMLOCK ; + SDLtoDIV[ _scroll_lock ] =SDLK_SCROLLOCK ; + SDLtoDIV[ _home ] =SDLK_HOME ; + SDLtoDIV[ _up ] =SDLK_UP ; + SDLtoDIV[ _pgup ] =SDLK_PAGEUP ; + SDLtoDIV[ _end ] =SDLK_END ; + SDLtoDIV[ _down ] =SDLK_DOWN ; + SDLtoDIV[ _left ] =SDLK_LEFT ; + SDLtoDIV[ _right ] =SDLK_RIGHT ; + SDLtoDIV[ _pgdn ] =SDLK_PAGEDOWN ; + SDLtoDIV[ _ins ] =SDLK_INSERT ; + SDLtoDIV[ _c_del ] =SDLK_KP_PERIOD ; + SDLtoDIV[ _c_backslash ] =SDLK_KP_DIVIDE ; + SDLtoDIV[ _c_asterisk ] =SDLK_KP_MULTIPLY ; + SDLtoDIV[ _c_minus ] =SDLK_KP_MINUS ; + SDLtoDIV[ _c_plus ] =SDLK_KP_PLUS ; + SDLtoDIV[ _c_enter ] =SDLK_KP_ENTER ; + SDLtoDIV[ _c_ins ] =SDLK_KP0 ; + SDLtoDIV[ _c_end ] =SDLK_KP1 ; + SDLtoDIV[ _c_down ] =SDLK_KP2 ; + SDLtoDIV[ _c_pgdn ] =SDLK_KP3 ; + SDLtoDIV[ _c_left ] =SDLK_KP4 ; + SDLtoDIV[ _c_center ] =SDLK_KP5 ; + SDLtoDIV[ _c_right ] =SDLK_KP6 ; + SDLtoDIV[ _c_home ] =SDLK_KP7 ; + SDLtoDIV[ _c_up ] =SDLK_KP8 ; + SDLtoDIV[ _c_pgup ] =SDLK_KP9 ; +} + +void frame(FUNCTION_PARAMS) +{ + int numkeys ; + int _mouse=globalptr("mouse"); + SDL_Rect srcrect,dstrect; + SDL_Surface* mapamouse; + + SDL_PumpEvents(); + + keys = SDL_GetKeyState(&numkeys ) ; + + /* MOUSE */ + + mbuttons = SDL_GetMouseState(&fp->mem[_mouse],&fp->mem[_mouse+1]); + + /* Ponemos los 5 botones a 0 */ + memset(&fp->mem[_mouse+9],0,5*4); + + if(mbuttons&SDL_BUTTON(1)) + fp->mem[_mouse+9]=1; + + if(mbuttons&SDL_BUTTON(2)) + fp->mem[_mouse+10]=1; + + if(mbuttons&SDL_BUTTON(3)) + fp->mem[_mouse+11]=1; + + if(mbuttons&SDL_BUTTON(4)) /* podria no funcionar ¿necesario sdl_event? */ + fp->mem[_mouse+12]=1; + + if(mbuttons&SDL_BUTTON(5)) /* podria no funcionar ¿necesario sdl_event? */ + fp->mem[_mouse+13]=1; + + /* si mouse.graph!=0 */ + if(fp->mem[_mouse+2]!=0) { + mapamouse=fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].Surface; + srcrect.x=0; + srcrect.y=0; + srcrect.w=mapamouse->w; + srcrect.h=mapamouse->h; + + dstrect.x=fp->mem[_mouse]-fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].cpoint[0].x; + dstrect.y=fp->mem[_mouse+1]-fp->files[fp->mem[_mouse+3]].mapa[fp->mem[_mouse+2]].cpoint[0].y; + dstrect.w=mapamouse->w; + dstrect.h=mapamouse->h; + + /* + * TODO: añadir chequeo de error si no existe file o mapa + */ + fp->Dibuja(mapamouse,srcrect,dstrect,fp->mem[_mouse+4],255,0,0); + } + + /* FIN DE MOUSE */ + + /* FILE* fichero ; */ + /* fichero = fopen( "input.txt" , "w+" ) ; */ + /* for ( i = 0 ; i < 256 ; i++ ) */ + /* keys[i] = 0 ; */ +/* + for ( i = 0 ; i < 256 ; i++ ) + { + if ( event[i].type == SDL_KEYDOWN ) + { + keys[ SDLtoDIV[ event[i].key.keysym.sym ] ] = 1 ; + } + if ( event[i].type == SDL_KEYUP ) + { + keys[ SDLtoDIV[ event[i].key.keysym.sym ] ] = 0 ; + } + }*/ + /* + while(SDL_PollEvent(&tecla)) + { + if(tecla.type == SDL_KEYDOWN) + { + if ( + keys[tecla.key.keysym.sym] = 1 ; + //i=(int)tecla.key.keysym.sym; + } + } + */ +/* for ( i = 0 ; i < 256 ; i++ ) + { + fprintf( fichero , "%i " , keys[i] ) ; + } + fprintf( fichero , "\n" ) ; +*/ + //fclose( fichero ) ; +} \ No newline at end of file diff --git a/dlls/src/input/input.def b/dlls/src/input/input.def new file mode 100644 index 0000000..05e3268 --- /dev/null +++ b/dlls/src/input/input.def @@ -0,0 +1,3 @@ +LIBRARY input +EXPORTS + ExportaFuncs diff --git a/dlls/src/input/input.h b/dlls/src/input/input.h new file mode 100644 index 0000000..5a9c634 --- /dev/null +++ b/dlls/src/input/input.h @@ -0,0 +1,6 @@ +#ifndef __EDIV_INPUT_H_ +#define __EDIV_INPUT_H_ + +int eDiv_Key(FUNCTION_PARAMS) ; + +#endif __EDIV_INPUT_H_ diff --git a/dlls/src/input/win32/input.sln b/dlls/src/input/win32/input.sln new file mode 100644 index 0000000..dcc4b9d --- /dev/null +++ b/dlls/src/input/win32/input.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "input", "input.vcproj", "{92E50294-4312-49E4-848B-5C9FF43AB27D}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Debug.ActiveCfg = Debug|Win32 + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Debug.Build.0 = Debug|Win32 + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Release.ActiveCfg = Release|Win32 + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/input/win32/input.vcproj b/dlls/src/input/win32/input.vcproj new file mode 100644 index 0000000..12ab80a --- /dev/null +++ b/dlls/src/input/win32/input.vcproj @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/math/math.c b/dlls/src/math/math.c new file mode 100644 index 0000000..4e619e3 --- /dev/null +++ b/dlls/src/math/math.c @@ -0,0 +1,400 @@ +/* + * eDiv Compiler + * Copyleft (C) 2000-2002 Sion Entertainment + * http://www.sion-e.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* EDIVSTD.DLL + * Esta librería contiene los datos más básicos que puede requerir un programa + * DIV, tal como las opciones de compilación, estructura reserved, etc. + */ + +#include +#include + + +#include +#include "math.h" + +int seno[90001] ; + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + CONST("pi",180000); + + FUNCTION("abs",1,eDiv_Abs); + FUNCTION("pow",2,eDiv_Pow); + FUNCTION("sqrt",1,eDiv_Sqrt); + FUNCTION("rand",2,eDiv_Rand); + FUNCTION("rand_seed",1,eDiv_RandSeed) ; + FUNCTION("sin",1,eDiv_Sin) ; + FUNCTION("cos",1,eDiv_Cos) ; + FUNCTION("tan",1,eDiv_Tan) ; + FUNCTION("get_angle",1,eDiv_GetAngle) ; + FUNCTION("get_dist",1,eDiv_GetDist) ; + FUNCTION("get_distx",2,eDiv_GetDistX) ; + FUNCTION("get_disty",2,eDiv_GetDistY) ; + FUNCTION("fget_angle",4,eDiv_FgetAngle) ; + FUNCTION("fget_dist",4,eDiv_FgetDist) ; + FUNCTION("near_angle",3,eDiv_NearAngle) ; + FUNCTION("cpysign",2,eDiv_cpysign) ; + FUNCTION("max",2,eDiv_max) ; + FUNCTION("min",2,eDiv_min) ; + FUNCTION("xmax",3,eDiv_xmax) ; + FUNCTION("xmin",3,eDiv_xmin) ; + FUNCTION("xmid",3,eDiv_xmid) ; + ENTRYPOINT(first_load) ; + + return TRUE; +} + + + + +int eDiv_Abs(FUNCTION_PARAMS) +{ + int a = getparm() ; + if ( a < 0 ) a = -a ; + return a ; +} + +int eDiv_Pow(FUNCTION_PARAMS) +{ + int a,b,c,n,i ; + b = getparm() ; + a = getparm() ; + n = 1 ; + c = b ; + if ( c < 0 ) c = -c ; + for ( i = 1 ; i < c ; i++ ) + { + n *= a ; + } + if ( b < 0 ) + n = 1 / n ; + return n ; +} + +int eDiv_Sqrt(FUNCTION_PARAMS) +{ + int a ; + a = getparm() ; + return sqrt( a ) ; +} + +int eDiv_Rand(FUNCTION_PARAMS) +{ + int a,b,n ; + b = getparm() ; + a = getparm() ; + n = (int)(rand()%(b-a+1))+a ; + return n ; +} + +int eDiv_RandSeed(FUNCTION_PARAMS) +{ + int a ; + a = getparm() ; + if ( a == 0 ) + srand(time(NULL)) ; + else + srand(a) ; + return 1 ; +} + +int eDiv_Sin(FUNCTION_PARAMS) +{ + int a ; + a = getparm() ; + a = prepara_angulo(a) ; + if ( a <= 90000 ) + return seno[a]; + if ( a <= 180000 ) + return seno[180000-a] ; + if ( a <= 270000 ) + return -seno[a-180000] ; + return -seno[360000-a] ; +} + +int eDiv_Cos(FUNCTION_PARAMS) +{ + int a ; + a = getparm() ; + a = prepara_angulo(a) ; + if ( a <= 90000 ) + return seno[90000-a]; + if ( a <= 180000 ) + return -seno[a-90000] ; + if ( a <= 270000 ) + return -seno[270000-a] ; + return seno[a-270000] ; +} + +int eDiv_Tan(FUNCTION_PARAMS) +{ + int a , b , c; + a = getparm() ; + a = prepara_angulo(a) ; + if ( a <= 90000 ) + b = seno[a]; + else + if ( a <= 180000 ) + b = seno[180000-a] ; + else + if ( a <= 270000 ) + b = -seno[a-180000] ; + else + b = -seno[360000-a] ; + if ( a <= 90000 ) + c = seno[90000-a]; + else + if ( a <= 180000 ) + c = -seno[a-90000] ; + else + if ( a <= 270000 ) + c = -seno[270000-a] ; + else + c = seno[a-270000] ; + + if ( c == 0 ) + return 0x7FFFFFFF ; + else + return ( (int)(b/c) ) ; + return 0 ; +} + + + +int eDiv_GetAngle(FUNCTION_PARAMS) +{ + int id1 , id2 ; + int x1 , x2 , y1, y2 ; + int a = getparm() ; + id1 = fp->procs_s[ fp->proc_orden[ *fp->proceso_actual ] ].id ; + id2 = a ; + 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 ; + if ( x2 < x1 ) + a+= 180 ; + }else + if ( y2 > y1 ) + a = 90 ; + else + a = 270 ; + a *= 1000 ; + a = prepara_angulo(a) ; + return a ; +} + +int eDiv_GetDist(FUNCTION_PARAMS) +{ + int id1 , id2 ; + int x1 , x2 , y1, y2 ; + int a = getparm() ; + id1 = fp->procs_s[ fp->proc_orden[*fp->proceso_actual] ].id ; + id2 = a ; + 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 ; +} + +int eDiv_GetDistX(FUNCTION_PARAMS) +{ + int a , b ; + b = getparm() ; /* distancia */ + a = getparm() ; /* angulo */ + a = (int) b* cos( (a/1000)*PIOVER180 ) ; + return a ; +} + +int eDiv_GetDistY(FUNCTION_PARAMS) +{ + int a , b ; + b = getparm() ; /* distancia */ + a = getparm() ; /* angulo */ + a = (int) b* sin( (a/1000)*PIOVER180 ) ; + return a ; +} + +int eDiv_FgetAngle(FUNCTION_PARAMS) +{ + int x1 , y1 , x2 , y2 , a ; + y2 = getparm() ; + x2 = getparm() ; + y1 = getparm() ; + x1 = getparm() ; + if ( (x2-x1) != 0 ) + { + a = atan( (double)((y2-y1) / (x2-x1)) ) / PIOVER180 ; + if ( x2 < x1 ) + a+= 180 ; + }else + if ( y2 > y1 ) + a = 90 ; + else + a = 270 ; + a *= 1000 ; + a = prepara_angulo(a) ; + return a ; +} + +int eDiv_FgetDist(FUNCTION_PARAMS) +{ + int x1 , y1 , x2 , y2 , a; + y2 = getparm() ; + x2 = getparm() ; + y1 = getparm() ; + x1 = getparm() ; + a = sqrt( pow( x2-x1 , 2 ) + pow( y2-y1 , 2 ) ) ; + return a ; +} + +int eDiv_NearAngle(FUNCTION_PARAMS) +{ + int a , b , c ; + c = getparm() ; + b = getparm() ; + a = getparm() ; + a = prepara_angulo(a) ; + b = prepara_angulo(b) ; + c = prepara_angulo(c) ; + if ( abs(a - b) <= c ) + return b ; + if ( a < b ) + { + if ( abs( b-a ) < 180000 ) + { + a = prepara_angulo( a+c ) ; + }else + { + a = prepara_angulo( a-c ) ; + } + return a ; + }else + { + if ( abs( b-a ) < 180000 ) + { + a = prepara_angulo( a-c ) ; + }else + { + a = prepara_angulo( a+c ) ; + } + return a ; + } + return 0 ; +} + +int eDiv_cpysign(FUNCTION_PARAMS) +{ + int s = getparm() ; + int n = getparm() ; + return ((s<0)?((n<0)?(n):(-n)):((n>=0)?(n):(-n))); +} + +int eDiv_max(FUNCTION_PARAMS) +{ + int n2 = getparm() ; + int n1 = getparm() ; + return ((n1>n2)?(n1):(n2)); +} + +int eDiv_min(FUNCTION_PARAMS) +{ + int n2 = getparm() ; + int n1 = getparm() ; + return ((n1m) m=n2; + if(n3>m) m=n3; + return m; +} + +int eDiv_xmin(FUNCTION_PARAMS) +{ + int n3 = getparm() ; + int n2 = getparm() ; + int n1 = getparm() ; + + int m=n1; + if(n2n2 && n1>n3 && n2>=n3) || + (n1>n2 && n1==n3 && n2n3) || + (n1>n2 && n1>n3 && n2n3 && n2>n3)) + return n3; + return n1; +} + + +/* + * Entrypoints + */ + +void first_load() +{ + int i ; + /* Calculamos los senos del 0 al 90000C */ + for ( i = 0 ; i < 90000 ; i++ ) + { + seno[i] = ftomil( sin( (i / 1000)*PIOVER180 ) ); + } + seno[90000]=1000; + srand(time(NULL)); +} + + +/* + * Funciones internas de la DLL + */ +int ftomil( float n ) +{ + + return ((int)(n*1000)) ; + +} + +int prepara_angulo( int n ) +{ + n = n % 360000 ; + if ( n < 0 ) n = n + 360000 ; + return n ; +} + diff --git a/dlls/src/math/math.def b/dlls/src/math/math.def new file mode 100644 index 0000000..1244a84 --- /dev/null +++ b/dlls/src/math/math.def @@ -0,0 +1,3 @@ +LIBRARY math +EXPORTS + ExportaFuncs diff --git a/dlls/src/math/math.h b/dlls/src/math/math.h new file mode 100644 index 0000000..f171458 --- /dev/null +++ b/dlls/src/math/math.h @@ -0,0 +1,33 @@ +#ifndef __EDIV_MATH_H +#define __EDIV_MATH_H + +#define PIOVER180 0.017453292519943295769236907684886 + + +int eDiv_Abs(FUNCTION_PARAMS) ; +int eDiv_Pow(FUNCTION_PARAMS) ; +int eDiv_Sqrt(FUNCTION_PARAMS) ; +int eDiv_Rand(FUNCTION_PARAMS) ; +int eDiv_RandSeed(FUNCTION_PARAMS) ; +int eDiv_Sin(FUNCTION_PARAMS) ; +int eDiv_Cos(FUNCTION_PARAMS) ; +int eDiv_Tan(FUNCTION_PARAMS) ; +int eDiv_GetAngle(FUNCTION_PARAMS) ; +int eDiv_GetDist(FUNCTION_PARAMS) ; +int eDiv_GetDistX(FUNCTION_PARAMS) ; +int eDiv_GetDistY(FUNCTION_PARAMS) ; +int eDiv_FgetAngle(FUNCTION_PARAMS) ; +int eDiv_FgetDist(FUNCTION_PARAMS) ; +int eDiv_NearAngle(FUNCTION_PARAMS) ; + +float eDiv_cpysign(float n,float s); +float eDiv_max(float n1,float n2); +float eDiv_min(float n1,float n2); +float eDiv_xmax(float n1,float n2,float n3); +float eDiv_xmin(float n1,float n2,float n3); +float eDiv_xmid(float n1,float n2,float n3); + +int ftomil(float) ; +int prepara_angulo( int ) ; + +#endif \ No newline at end of file diff --git a/dlls/src/math/win32/math.sln b/dlls/src/math/win32/math.sln new file mode 100644 index 0000000..67e0475 --- /dev/null +++ b/dlls/src/math/win32/math.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "math", "math.vcproj", "{56A4746D-5A73-4CA5-BD0C-959F14B503E7}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Debug.ActiveCfg = Debug|Win32 + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Debug.Build.0 = Debug|Win32 + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Release.ActiveCfg = Release|Win32 + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/math/win32/math.vcproj b/dlls/src/math/win32/math.vcproj new file mode 100644 index 0000000..107e938 --- /dev/null +++ b/dlls/src/math/win32/math.vcproj @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/scroll/scroll.c b/dlls/src/scroll/scroll.c new file mode 100644 index 0000000..beb05b6 --- /dev/null +++ b/dlls/src/scroll/scroll.c @@ -0,0 +1,115 @@ + + +#include +#include +//#include "../../shared/varindex.h" +#include "scroll.h" + + +struct +{ + int existe ; + int file, graph ; + int x0 , y0 , x1 , y1 ; + int z ; + int camera ; + int ratio ; + int speed ; + int region1 , region2 ; +}scrolls[10] ; + + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + + GLOBAL_STRUCT("scroll",9); + _INT("x0",0); + _INT("y0",0); + _INT("x1",0); + _INT("y1",0); + _INT("z",0); + _INT("camera",0); + _INT("ratio",0); + _INT("speed",0); + _INT("region1",0); + _INT("region2",0); + END_STRUCT; + + FUNCTION("start_scroll",6,eDiv_StartScroll) ; + + ENTRYPOINT( frame ) ; + + return TRUE ; +} + +FILE * fichero ; + +int eDiv_StartScroll(FUNCTION_PARAMS) +{ + int num , f , g1 , g2 , r , b ; + b = getparm() ; + r = getparm() ; + g2 = getparm() ; + g1 = getparm() ; + f = getparm() ; + num = getparm() ; + + if ( scrolls[num].existe ) + return -1 ; + + scrolls[num].existe = 1 ; +/* + fichero = fopen("scroll.txt" , "w+" ) ; + fprintf(fichero , "glo_scroll: %d" , varindex[_glo_scroll] ) ; + fclose(fichero) ;*/ + /* + fp->mem[ varindex[_glo_scroll] + 0 ] = 0 ; + fp->mem[ varindex[_glo_scroll] + 1 ] = 0 ; + fp->mem[ varindex[_glo_scroll] + 2 ] = 0 ; + fp->mem[ varindex[_glo_scroll] + 3 ] = 0 ; + fp->mem[ varindex[_glo_scroll] + 4 ] = 512 ; + fp->mem[ varindex[_glo_scroll] + 0 ] = 0 ; + fp->mem[ varindex[_glo_scroll] + 0 ] = b ; + fp->mem[ varindex[_glo_scroll] + 0 ] = 0 ; + fp->mem[ varindex[_glo_scroll] + 0 ] = r ; + fp->mem[ varindex[_glo_scroll] + 0 ] = r ; +*/ + return 1 ; +} + + + +//============== Entrypoints ===================================================== + +void frame(FUNCTION_PARAMS) +{ + /* + * de momento solo hay esta demostracion de que fp->Dibuja funciona xDD + * falta hacer los scrolls :P + */ +/* + SDL_Rect srcrect, dstrect ; + + + if ( fp->existe.dibuja ) + { + if ( fp->files[0].existe ) + { + if ( fp->files[0].mapa[1000].existe ) + { + srcrect.x = 0 ; + srcrect.y = 0 ; + srcrect.w = fp->files[0].mapa[1000].Surface->w ; + srcrect.h = fp->files[0].mapa[1000].Surface->h ; + fp->Dibuja( fp->files[0].mapa[1000].Surface , srcrect , srcrect , 0 , 128 ) ; + } + } + } + +*/ + +} + + + + diff --git a/dlls/src/scroll/scroll.def b/dlls/src/scroll/scroll.def new file mode 100644 index 0000000..7c30987 --- /dev/null +++ b/dlls/src/scroll/scroll.def @@ -0,0 +1,3 @@ +LIBRARY scroll +EXPORTS + ExportaFuncs diff --git a/dlls/src/scroll/scroll.h b/dlls/src/scroll/scroll.h new file mode 100644 index 0000000..8a22986 --- /dev/null +++ b/dlls/src/scroll/scroll.h @@ -0,0 +1,3 @@ + + +int eDiv_StartScroll(FUNCTION_PARAMS) ; \ No newline at end of file diff --git a/dlls/src/strings/conv.c b/dlls/src/strings/conv.c new file mode 100644 index 0000000..4d9dbf1 --- /dev/null +++ b/dlls/src/strings/conv.c @@ -0,0 +1,95 @@ +#include + +#include "conv.h" + +/* Tabla de conversión de caracteres MS-DOS a Windows */ + +int dos_chars=0; + +byte dos_to_win[256] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, +112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, +199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232, 239, 238, 236, 196, 197, +201, 230, 198, 244, 246, 242, 251, 249, 255, 214, 220, 248, 163, 216, 215, 131, +225, 237, 243, 250, 241, 209, 170, 186, 191, 174, 172, 189, 188, 161, 171, 187, +166, 166, 166, 166, 166, 193, 194, 192, 169, 166, 166, 43, 43, 162, 165, 43, + 43, 45, 45, 43, 45, 43, 227, 195, 43, 43, 45, 45, 166, 45, 43, 164, +240, 208, 202, 203, 200, 105, 205, 206, 207, 43, 43, 166, 95, 166, 204, 175, +211, 223, 212, 210, 245, 213, 181, 254, 222, 218, 219, 217, 253, 221, 175, 180, +173, 177, 61, 190, 182, 167, 247, 184, 176, 168, 183, 185, 179, 178, 166, 160 +}; + +/* Tabla de conversión de caracteres Windows a MS-DOS */ + +byte win_to_dos[256] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 159, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 255, 173, 189, 156, 207, 190, 254, 245, 249, 184, 166, 174, 170, 240, 169, 238, + 248, 241, 253, 252, 239, 230, 244, 250, 247, 251, 167, 175, 172, 171, 243, 168, + 183, 181, 182, 199, 142, 143, 146, 128, 212, 144, 210, 211, 222, 214, 215, 216, + 209, 165, 227, 224, 226, 229, 153, 158, 157, 235, 233, 234, 154, 237, 232, 225, + 133, 160, 131, 198, 132, 134, 145, 135, 138, 130, 136, 137, 141, 161, 140, 139, + 208, 164, 149, 162, 147, 228, 148, 246, 155, 151, 163, 150, 129, 236, 231, 152 +}; + +byte lower[256]; +byte upper[256]; + +byte c_convert (byte c) +{ + return dos_chars ? c : win_to_dos[c]; +} + + +void set_c_lower (const byte * from, const byte * to) +{ + if (dos_chars) + while (*from) lower[win_to_dos[*from++]] = win_to_dos[*to++] ; + else + while (*from) lower[*from++] = *to++ ; +} + +void set_c_upper (const byte * from, const byte * to) +{ + if (dos_chars) + while (*from) upper[win_to_dos[*from++]] = win_to_dos[*to++] ; + else + while (*from) upper[*from++] = *to++ ; +} + +void inicializa_lower() +{ + memset (lower, 0, 256); + + set_c_lower ("ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz"); + set_c_lower ("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopqrstuvwxyz"); + set_c_lower ("ÁÉÍÓÚÑÇÀÈÌÒÙÄËÏÖÜÝÂÊÎÔÛÆÃÅÕ","áéíóúñçàèìòùäëïöüýâêîôûæãåõ"); + set_c_lower("áéíóúñçàèìòùäëïöüýâêîôûæãåõ","áéíóúñçàèìòùäëïöüýâêîôûæãåõ"); + set_c_lower("1234567890#$_ºª","1234567890#$_ºª"); +} + +void inicializa_upper() +{ + memset (upper, 0, 256); + + set_c_upper ("abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + set_c_upper ("ABCDEFGHIJKLMNOPQRSTUVWXYZ","ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + set_c_upper ("áéíóúñçàèìòùäëïöüýâêîôûæãåõ","ÁÉÍÓÚÑÇÀÈÌÒÙÄËÏÖÜÝÂÊÎÔÛÆÃÅÕ"); + set_c_upper("ÁÉÍÓÚÑÇÀÈÌÒÙÄËÏÖÜÝÂÊÎÔÛÆÃÅÕ","ÁÉÍÓÚÑÇÀÈÌÒÙÄËÏÖÜÝÂÊÎÔÛÆÃÅÕ"); + set_c_upper("1234567890#$_ºª","1234567890#$_ºª"); +} \ No newline at end of file diff --git a/dlls/src/strings/conv.h b/dlls/src/strings/conv.h new file mode 100644 index 0000000..ae81b00 --- /dev/null +++ b/dlls/src/strings/conv.h @@ -0,0 +1,22 @@ +#ifndef __EDIV_CONV_H_ +#define __EDIV_CONV_H_ + +#ifndef byte + #define byte unsigned char +#endif + +byte dos_to_win[256]; +byte win_to_dos[256]; + +byte lower[256]; +byte upper[256]; + +byte c_convert(byte c); + +void set_c_lower (const byte *from, const byte *to); +void inicializa_lower(); + +void set_c_upper (const byte *from, const byte *to); +void inicializa_upper(); + +#endif __CONV_H_ \ No newline at end of file diff --git a/dlls/src/strings/strings.c b/dlls/src/strings/strings.c new file mode 100644 index 0000000..9b1adbb --- /dev/null +++ b/dlls/src/strings/strings.c @@ -0,0 +1,242 @@ +#include +#include + +#include +#include "conv.h" + +/************************/ +/* char() * */ +/* lower() * HECHA */ +/* strcat() * HECHA */ +/* strchr() * HECHA */ +/* strcmp() * HECHA */ +/* strcpy() * HECHA */ +/* strdel() * */ +/* strlen() * HECHA */ +/* strset() * HECHA */ +/* strstr() * HECHA */ +/* upper() * HECHA */ +/* calculate() * HECHA */ +/* fcalculate() * HECHA */ +/* itoa() * */ +/* asc() * */ /* [ text=ASC(65); // test="A";] (Una peticion suya :). */ +/* ftoa() * */ /* Para los nuevos FLOAT :) */ +/************************/ + +/* Rutinas eDiv! :) */ +char *DIV_strcpy(FUNCTION_PARAMS); +size_t DIV_strlen(FUNCTION_PARAMS); +int DIV_strcmp(FUNCTION_PARAMS); +char *DIV_strchr(FUNCTION_PARAMS); +char *DIV_strcat(FUNCTION_PARAMS); +char *DIV_strstr(FUNCTION_PARAMS); +int DIV_atoi(FUNCTION_PARAMS); +float DIV_atof(FUNCTION_PARAMS); +char *DIV_lower(FUNCTION_PARAMS); +char *DIV_upper(FUNCTION_PARAMS); +char *DIV_strset(FUNCTION_PARAMS); +char *DIV_itoa(FUNCTION_PARAMS); + +/* Rutinas internas */ +static int hexval(char c); + +/* Variables */ +byte i_lower=0; /* lower ya esta inicializado? */ +byte i_upper=0; /* upper ya esta inicializado? */ + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + + FUNCTION("strcpy",2,DIV_strcpy); + FUNCTION("strlen",1,DIV_strlen); + FUNCTION("strcmp",2,DIV_strcmp); + FUNCTION("strchr",2,DIV_strchr); + FUNCTION("strcat",2,DIV_strcat); + FUNCTION("strstr",2,DIV_strstr); + FUNCTION("strset",2,DIV_strset); + + /* Estas dos son iguales, lo sengundo es por una standarizacion :) */ + FUNCTION("calculate",1,DIV_atoi); + FUNCTION("atoi",1,DIV_atoi); + /* Idem a lo anterior, pero para los datos float :) */ + FUNCTION("fcalculate",1,DIV_atof); + FUNCTION("atof",1,DIV_atof); + + FUNCTION("lower",1,DIV_lower); + FUNCTION("upper",1,DIV_upper); + + return TRUE; +} + +char *DIV_strcpy(FUNCTION_PARAMS) +{ + char *src=(char *)getparm(); + char *dest=(char *)getparm(); + + char *tmp = dest; + + while ((*dest++ = *src++) != '\0'); + return tmp; +} + +size_t DIV_strlen(FUNCTION_PARAMS) +{ + char *s = (char *)getparm(); + const char *sc; + + for(sc = s; *sc != '\0'; ++sc); + return sc - s; +} + +char *DIV_strset(FUNCTION_PARAMS) +{ + int valor=getparm(); + char *cadena=(char *)getparm(); + + char *inicio=cadena; + + while (*cadena) + *cadena++ = (char)valor; + + return inicio; +} + +int DIV_strcmp(FUNCTION_PARAMS) +{ + const char *ct = (const char *)getparm(); + const char *cs = (const char *)getparm(); + + signed char __res; + + while (1) { + if ((__res = *cs - *ct++) != 0 || !*cs++) + break; + } + + return __res; +} + +char *DIV_strchr(FUNCTION_PARAMS) +{ + int c = getparm(); + const char *s = (const char *)getparm(); + + for(; *s != (char) c; ++s) + if (*s == '\0') + return NULL; + return (char *) s; +} + +char *DIV_strcat(FUNCTION_PARAMS) +{ + const char *src = (const char *)getparm(); + char *dest = (char *)getparm(); + + char *tmp = dest; + + while(*dest) + dest++; + while((*dest++ = *src++) != '\0') + ; + return tmp; +} + +char *DIV_strstr(FUNCTION_PARAMS) +{ + const char *s2 = (const char*)getparm(); + const char *s1 = (const char*)getparm(); + + int l1, l2; + + l2 = strlen(s2); + if (!l2) + return (char *)s1; + l1 = strlen(s1); + while(l1 >= l2) { + l1--; + if (!memcmp(s1,s2,l2)) + return (char *)s1; + s1++; + } + return NULL; +} + +int DIV_atoi(FUNCTION_PARAMS) +{ + const char *num = (const char*)getparm(); + int value = 0; + if (num[0] == '0' && num[1] == 'x') { + /* hexadecimal */ + num += 2; + while (*num && isxdigit(*num)) + value = value * 16 + hexval(*num++); + } else { + /* decimal */ + while (*num && isdigit(*num)) + value = value * 10 + *num++ - '0'; + } + + return value; +} + +float DIV_atof(FUNCTION_PARAMS) +{ + const char *num = (const char*)getparm(); + float value = 0; + if (num[0] == '0' && num[1] == 'x') { + /* hexadecimal */ + num += 2; + while (*num && isxdigit(*num)) + value = value * 16 + hexval(*num++); + } else { + /* decimal */ + while (*num && isdigit(*num)) + value = value * 10 + *num++ - '0'; + } + + return value; +} + +char *DIV_lower(FUNCTION_PARAMS) +{ + int i; + char *str=(char*)getparm(); + + if (!i_lower) + inicializa_lower(); + + for (i=0;str[i]!=0;i++) { + if (lower[str[i]]!=0) str[i]=lower[str[i]]; + } + + return str; +} + +char *DIV_upper(FUNCTION_PARAMS) +{ + int i; + char *str=(char*)getparm(); + + if (!i_upper) + inicializa_upper(); + + for (i=0;str[i]!=0;i++) { + if (upper[str[i]]!=0) str[i]=upper[str[i]]; + } + + return str; +} + +/* Rutinas internas */ +static int hexval(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + + return 0; +} + diff --git a/dlls/src/strings/strings.def b/dlls/src/strings/strings.def new file mode 100644 index 0000000..798f54a --- /dev/null +++ b/dlls/src/strings/strings.def @@ -0,0 +1,3 @@ +LIBRARY strings +EXPORTS + ExportaFuncs diff --git a/dlls/src/strings/win32/strings.sln b/dlls/src/strings/win32/strings.sln new file mode 100644 index 0000000..e552d89 --- /dev/null +++ b/dlls/src/strings/win32/strings.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "strings", "strings.vcproj", "{8983E45F-30DD-486C-AF5D-723E86BF5149}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Debug.ActiveCfg = Debug|Win32 + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Debug.Build.0 = Debug|Win32 + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Release.ActiveCfg = Release|Win32 + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/strings/win32/strings.vcproj b/dlls/src/strings/win32/strings.vcproj new file mode 100644 index 0000000..801a491 --- /dev/null +++ b/dlls/src/strings/win32/strings.vcproj @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/text/edivfont.h b/dlls/src/text/edivfont.h new file mode 100644 index 0000000..eca8ad0 --- /dev/null +++ b/dlls/src/text/edivfont.h @@ -0,0 +1,42 @@ +/* + * eDiv Compiler + * Copyleft (C) 2000-2002 Sion Entertainment + * http://www.sion-e.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + -Estructura de control + contiene informacion sobre el offset y tamaño del bmp en el fichero .fnt + para poder leerlo, tambien contiene el offset de la estructura de informacion + -Mapa de caracteres + es la imagen del mapa de caracteres, se copia directamente. +*/ + +#ifndef __EDIV_EDIVFONT_H_ +#define __EDIV_EDIVFONT_H_ + +#include + +struct _fuente_control_s{ + int offset_imagen ; + int size_imagen ; + int w , h , bytespp ; + SDL_Rect rect[256] ; + SDL_Surface *imagen ; +}; + +#endif \ No newline at end of file diff --git a/dlls/src/text/text.c b/dlls/src/text/text.c new file mode 100644 index 0000000..c4f4dd7 --- /dev/null +++ b/dlls/src/text/text.c @@ -0,0 +1,400 @@ +#include + +#include + +#include "edivfont.h" +#include "text.h" + + +#define MAX_FONTS 0xFF +#define MAX_WRITES 0xFFF + +struct _fuente_control_s fuente_control_s[MAX_FONTS]; +int existe[MAX_FONTS] ; + +struct +{ + int existe ; + int numerica ; /* 0: texto , 1: numerica (write_int) */ + int offset_var ; /* solo para numerica = 1 */ + int centrado ; /* solo para numerica = 1 */ + int fuente ; /* solo para numerica = 1 */ + int x , y ; + int cx , cy ; + SDL_Surface *imagen ; +}textos[MAX_WRITES] ; + + +int ExportaFuncs(EXPORTAFUNCS_PARAMS) +{ + CONST("all_text",0); + + FUNCTION("load_fnt",1,eDiv_LoadFnt) ; + FUNCTION("write",5,eDiv_Write) ; + FUNCTION("write_int",5,eDiv_WriteInt) ; + FUNCTION("move_text",3,eDiv_MoveText) ; + FUNCTION("delete_text",1,eDiv_DeleteText) ; + ENTRYPOINT( frame ) ; + ENTRYPOINT(first_load) ; + + return TRUE ; +} + +FILE *fichero ; + +int eDiv_LoadFnt(FUNCTION_PARAMS) +{ + FILE *fuente ; + char *pool ; + int i ; + fpos_t pos ; + const char *filename=getstrparm(); /* Fichero a cargar */ + + for ( i = 1 ; i <= MAX_FONTS ; i++ ) + { + if ( existe[i] == 0 ) + break ; + } + if ( i == MAX_FONTS ) { + fp->Runtime_Error(113); /* Demasiadas fuentes */ + return -1 ; + } + + fichero = fopen("text.txt" , "w+" ) ; + if((fuente = fopen(filename, "rb" ))==NULL) { + fclose(fichero); + fp->Runtime_Error(114); /* archivo de fuente no encontrado */ + return 0; + } + fprintf( fichero , "Leidos %d bytes\n" , (int)fread( &fuente_control_s[i] , 1 , sizeof(fuente_control_s[i]) , fuente ) ) ; + if (!(pool = malloc(fuente_control_s[i].size_imagen + 1 ) ) ) { + fp->Runtime_Error(100); /* memoria insuficiente */ + return 0; + } + pos = fuente_control_s[i].offset_imagen ; + fsetpos(fuente , &pos ) ; + fprintf(fichero , "Size of image: %d bytes\n" , fuente_control_s[i].size_imagen ) ; + fprintf(fichero , "Leidos %d bytes\n" , (int)fread( pool , 1 , fuente_control_s[i].size_imagen , fuente ) ) ; + fuente_control_s[i].imagen = SDL_CreateRGBSurfaceFrom( pool , fuente_control_s[i].w , fuente_control_s[i].h , fuente_control_s[i].bytespp * 8 , fuente_control_s[i].w * fuente_control_s[i].bytespp , 0 , 0 , 0, 0 ) ; + + fclose(fuente) ; + fclose(fichero) ; + + existe[i] = 1 ; + return i ; +} + + +int eDiv_Write(FUNCTION_PARAMS) +{ + int i , j ; + int ax ; + SDL_Rect dstrect ; + int fuente , x , y , centrado ; + int w , h ; + char *texto ; + texto = getstrparm() ; + centrado = getparm() ; + y = getparm() ; + x = getparm() ; + fuente = getparm() ; + + if(fuente<0 || fuente>MAX_FONTS || !existe[fuente]) { + fp->Runtime_Error(116); /* id de fuente no válido */ + return -1; + } + + for ( i = 1 ; i < MAX_WRITES ; i++ ) + { + if ( textos[i].existe == 0 ) + break ; + } + if ( i == MAX_WRITES ) { + fp->Runtime_Error(118); /* demasiados textos */ + return -1 ; + } + + + textos[i].x = x ; + textos[i].y = y ; + textos[i].numerica = 0 ; + textos[i].offset_var = 0 ; + textos[i].centrado = 0 ; + textos[i].fuente = 0 ; + + + /* Calculamos el ancho del fichero */ + w = 0 ; + for ( j = 0 ; (unsigned)j < strlen(texto) ; j++ ) + w += fuente_control_s[fuente].rect[ texto[j] ].w +1; + h = fuente_control_s[fuente].imagen->h ; + + textos[i].imagen = SDL_CreateRGBSurface(SDL_HWSURFACE, w , h , fuente_control_s[fuente].bytespp * 8 , 0 , 0 , 0 , 0 ) ; + SDL_SetColorKey( textos[i].imagen , SDL_SRCCOLORKEY | SDL_RLEACCEL , 0 ) ; + + + /* Escribimos */ + ax = 0 ; /* Valor de x acumulativo mientras se va escribiendo */ + for ( j = 0 ; (unsigned)j < strlen(texto) ; j++ ) + { + dstrect.x = ax ; + dstrect.y = fuente_control_s[fuente].rect[ texto[j] ].y ; + dstrect.w = fuente_control_s[fuente].rect[ texto[j] ].w ; + dstrect.h = fuente_control_s[fuente].rect[ texto[j] ].h ; + SDL_BlitSurface( fuente_control_s[fuente].imagen , &fuente_control_s[fuente].rect[ texto[j] ] , textos[i].imagen , &dstrect ) ; + ax += fuente_control_s[fuente].rect[ texto[j] ].w +1 ; + } + + /* Centrado */ + if ( centrado == 0 || centrado == 3 || centrado == 6 ) + textos[i].cx = 0 ; + if ( centrado == 1 || centrado == 4 || centrado == 7 ) + textos[i].cx = (int) textos[i].imagen->w / 2 ; + if ( centrado == 2 || centrado == 5 || centrado == 8 ) + textos[i].cx = textos[i].imagen->w -1 ; + if ( centrado > -1 && centrado < 3 ) + textos[i].cy = 0 ; + if ( centrado > 2 && centrado < 6 ) + textos[i].cy = (int) textos[i].imagen->h / 2 ; + if ( centrado > 5 && centrado < 9 ) + textos[i].cy = textos[i].imagen->h -1 ; + + + textos[i].existe = 1 ; + + return i ; +} + +int eDiv_WriteInt(FUNCTION_PARAMS) +{ + int i , j ; + int w , h , ax ; + SDL_Rect dstrect ; + int fuente , x , y , centrado , offset_var ; + char *texto ; + char texto2[30] ; + offset_var = getparm() ; + centrado = getparm() ; + y = getparm() ; + x = getparm() ; + fuente = getparm() ; + + if(fuente<0 || fuente>MAX_FONTS || !existe[fuente]) { + fp->Runtime_Error(116); /* id de fuente no válido */ + return -1; + } + + for ( i = 1 ; i < MAX_WRITES ; i++ ) + { + if ( textos[i].existe == 0 ) + break ; + } + if ( i == MAX_WRITES ) { + fp->Runtime_Error(118); /* demasiados textos */ + return -1 ; + } + + textos[i].x = x ; + textos[i].y = y ; + textos[i].numerica = 1 ; + textos[i].offset_var = offset_var ; + textos[i].centrado = centrado ; + textos[i].fuente = fuente ; + + + fichero = fopen("wrin.txt" , "w+") ; + fprintf( fichero , "valor: %i\n" , global("fps") ) ; + fclose(fichero) ; + + itoa( fp->mem[ textos[i].offset_var ] , texto2 , 10 ) ; + texto = texto2 ; + + + /* Calculamos el ancho del fichero */ + w = 0 ; + for ( j = 0 ; (unsigned)j < strlen(texto) ; j++ ) + w += fuente_control_s[fuente].rect[ texto[j] ].w +1; + h = fuente_control_s[fuente].imagen->h ; + + textos[i].imagen = SDL_CreateRGBSurface(SDL_HWSURFACE, w , h , fuente_control_s[fuente].bytespp * 8 , 0 , 0 , 0 , 0 ) ; + SDL_SetColorKey( textos[i].imagen , SDL_SRCCOLORKEY | SDL_RLEACCEL , 0 ) ; + + /* Escribimos */ + ax = 0 ; /* Valor de x acumulativo mientras se va escribiendo */ + for ( j = 0 ; (unsigned)j < strlen(texto) ; j++ ) + { + dstrect.x = ax ; + dstrect.y = fuente_control_s[fuente].rect[ texto[j] ].y ; + dstrect.w = fuente_control_s[fuente].rect[ texto[j] ].w ; + dstrect.h = fuente_control_s[fuente].rect[ texto[j] ].h ; + SDL_BlitSurface( fuente_control_s[fuente].imagen , &fuente_control_s[fuente].rect[ texto[j] ] , textos[i].imagen , &dstrect ) ; + ax += fuente_control_s[fuente].rect[ texto[j] ].w +1 ; + } + + /* Centrado */ + if ( centrado == 0 || centrado == 3 || centrado == 6 ) + textos[i].cx = 0 ; + if ( centrado == 1 || centrado == 4 || centrado == 7 ) + textos[i].cx = (int) textos[i].imagen->w / 2 ; + if ( centrado == 2 || centrado == 5 || centrado == 8 ) + textos[i].cx = textos[i].imagen->w -1 ; + if ( centrado > -1 && centrado < 3 ) + textos[i].cy = 0 ; + if ( centrado > 2 && centrado < 6 ) + textos[i].cy = (int) textos[i].imagen->h / 2 ; + if ( centrado > 5 && centrado < 9 ) + textos[i].cy = textos[i].imagen->h -1 ; + + + + textos[i].existe = 1 ; + + return i ; +} + +int eDiv_MoveText(FUNCTION_PARAMS) +{ + int i , x , y ; + y = getparm() ; + x = getparm() ; + i = getparm() ; + + textos[i].x = x ; + textos[i].y = y ; + + return 1 ; +} + +int eDiv_DeleteText(FUNCTION_PARAMS) +{ + int i; + i = getparm(); + + if (i==0) { + for (i=1;iMAX_WRITES) { + fp->Runtime_Error(119); /* id de texto no válido */ + return -1 ; + } + + textos[i].existe = 0; + + return 1; +} + + +/* + * Entrypoints + */ +void frame(FUNCTION_PARAMS) +{ + SDL_Rect srcrect, dstrect; + char *texto; + char texto2[30]; + int i, j; + int w, h, ax; + + for (i=0; i<0xFFF ;i++) + if ( textos[i].existe ) + { + if ( textos[i].numerica ) + { + SDL_FreeSurface( textos[i].imagen ) ; + + itoa( fp->mem[ textos[i].offset_var ] , texto2 , 10 ) ; + texto = texto2 ; + + /* Calculamos el ancho del fichero */ + w = 0 ; + for ( j = 0 ; (unsigned)j < strlen(texto) ; j++ ) + w += fuente_control_s[textos[i].fuente].rect[ texto[j] ].w +1; + h = fuente_control_s[textos[i].fuente].imagen->h ; + + textos[i].imagen = SDL_CreateRGBSurface(SDL_HWSURFACE, w , h , fuente_control_s[textos[i].fuente].bytespp * 8 , 0 , 0 , 0 , 0 ) ; + SDL_SetColorKey( textos[i].imagen , SDL_SRCCOLORKEY | SDL_RLEACCEL , 0 ) ; + + /* Escribimos */ + ax = 0 ; /* Valor de x acumulativo mientras se va escribiendo */ + for ( j = 0 ; (unsigned)j < strlen(texto) ; j++ ) + { + dstrect.x = ax ; + dstrect.y = fuente_control_s[textos[i].fuente].rect[ texto[j] ].y ; + dstrect.w = fuente_control_s[textos[i].fuente].rect[ texto[j] ].w ; + dstrect.h = fuente_control_s[textos[i].fuente].rect[ texto[j] ].h ; + SDL_BlitSurface( fuente_control_s[textos[i].fuente].imagen , &fuente_control_s[textos[i].fuente].rect[ texto[j] ] , textos[i].imagen , &dstrect ) ; + ax += fuente_control_s[textos[i].fuente].rect[ texto[j] ].w +1 ; + } + + /* Centrado */ + if ( textos[i].centrado == 0 || textos[i].centrado == 3 || textos[i].centrado == 6 ) + textos[i].cx = 0 ; + if ( textos[i].centrado == 1 || textos[i].centrado == 4 || textos[i].centrado == 7 ) + textos[i].cx = (int) textos[i].imagen->w / 2 ; + if ( textos[i].centrado == 2 || textos[i].centrado == 5 || textos[i].centrado == 8 ) + textos[i].cx = textos[i].imagen->w -1 ; + if ( textos[i].centrado > -1 && textos[i].centrado < 3 ) + textos[i].cy = 0 ; + if ( textos[i].centrado > 2 && textos[i].centrado < 6 ) + textos[i].cy = (int) textos[i].imagen->h / 2 ; + if ( textos[i].centrado > 5 && textos[i].centrado < 9 ) + textos[i].cy = textos[i].imagen->h -1 ; + } + + + srcrect.x = 0 ; + srcrect.y = 0 ; + srcrect.w = textos[i].imagen->w ; + srcrect.h = textos[i].imagen->h ; + + dstrect.x = textos[i].x - textos[i].cx ; + dstrect.y = textos[i].y - textos[i].cy ; + dstrect.w = srcrect.w ; + dstrect.h = srcrect.h ; + + fp->Dibuja( textos[i].imagen , srcrect, dstrect , 0 , 255 , 0 , 0 ) ; + } + + /* + * de momento solo hay esta demostracion de que fp->Dibuja funciona xDD + * falta hacer los scrolls :P + */ + /* + if ( fp->existe.dibuja ) + { + if ( fp->files[0].existe ) + { + if ( fp->files[0].mapa[1000].existe ) + { + srcrect.x = 0 ; + srcrect.y = 0 ; + srcrect.w = fp->files[0].mapa[1000].Surface->w ; + srcrect.h = fp->files[0].mapa[1000].Surface->h ; + fp->Dibuja( fp->files[0].mapa[1000].Surface , srcrect , srcrect , 0 , 128 ) ; + } + } + } + */ +} + + + +void first_load(FUNCTION_PARAMS) +{ + int i ; + for ( i = 0 ; i < 256 ; i++ ) + existe[i] = 0 ; + + for ( i = 0 ; i < 1024 ; i++ ) + textos[i].existe = 0 ; +} + + + diff --git a/dlls/src/text/text.def b/dlls/src/text/text.def new file mode 100644 index 0000000..f27fd0a --- /dev/null +++ b/dlls/src/text/text.def @@ -0,0 +1,3 @@ +LIBRARY text +EXPORTS + ExportaFuncs diff --git a/dlls/src/text/text.h b/dlls/src/text/text.h new file mode 100644 index 0000000..e2db9f0 --- /dev/null +++ b/dlls/src/text/text.h @@ -0,0 +1,10 @@ +#ifndef __EDIV_TEXT_H_ +#define __EDIV_TEXT_H_ + +int eDiv_LoadFnt(FUNCTION_PARMAS); +int eDiv_Write(FUNCTION_PARAMS); +int eDiv_WriteInt(FUNCTION_PARAMS); +int eDiv_MoveText(FUNCTION_PARAMS); +int eDiv_DeleteText(FUNCTION_PARAMS); + +#endif \ No newline at end of file diff --git a/dlls/src/text/win32/text.sln b/dlls/src/text/win32/text.sln new file mode 100644 index 0000000..593dc29 --- /dev/null +++ b/dlls/src/text/win32/text.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "text", "text.vcproj", "{71D05C32-B49A-4690-AA4D-1385D4257CDF}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Debug.ActiveCfg = Debug|Win32 + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Debug.Build.0 = Debug|Win32 + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Release.ActiveCfg = Release|Win32 + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/dlls/src/text/win32/text.vcproj b/dlls/src/text/win32/text.vcproj new file mode 100644 index 0000000..c03b583 --- /dev/null +++ b/dlls/src/text/win32/text.vcproj @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dlls/src/win32/dlls.sln b/dlls/src/win32/dlls.sln new file mode 100644 index 0000000..cbf1b7a --- /dev/null +++ b/dlls/src/win32/dlls.sln @@ -0,0 +1,63 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dinmem", "..\dinmem\win32\dinmem.vcproj", "{2FD59E33-AB54-47EC-A3E5-3619A3921ABF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "edivstd", "..\edivstd\win32\edivstd.vcproj", "{92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "file", "..\file\win32\file.vcproj", "{EA869297-5AC6-4603-BB86-9962207DB25F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graphics", "..\graphics\win32\graphics.vcproj", "{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "input", "..\input\win32\input.vcproj", "{92E50294-4312-49E4-848B-5C9FF43AB27D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "math", "..\math\win32\math.vcproj", "{56A4746D-5A73-4CA5-BD0C-959F14B503E7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "strings", "..\strings\win32\strings.vcproj", "{8983E45F-30DD-486C-AF5D-723E86BF5149}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "text", "..\text\win32\text.vcproj", "{71D05C32-B49A-4690-AA4D-1385D4257CDF}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Debug.ActiveCfg = Debug|Win32 + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Debug.Build.0 = Debug|Win32 + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Release.ActiveCfg = Release|Win32 + {2FD59E33-AB54-47EC-A3E5-3619A3921ABF}.Release.Build.0 = Release|Win32 + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Debug.ActiveCfg = Debug|Win32 + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Debug.Build.0 = Debug|Win32 + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Release.ActiveCfg = Release|Win32 + {92B930FB-7B7F-4DD6-A50C-8DE8E34461C2}.Release.Build.0 = Release|Win32 + {EA869297-5AC6-4603-BB86-9962207DB25F}.Debug.ActiveCfg = Debug|Win32 + {EA869297-5AC6-4603-BB86-9962207DB25F}.Debug.Build.0 = Debug|Win32 + {EA869297-5AC6-4603-BB86-9962207DB25F}.Release.ActiveCfg = Release|Win32 + {EA869297-5AC6-4603-BB86-9962207DB25F}.Release.Build.0 = Release|Win32 + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.ActiveCfg = Debug|Win32 + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.Build.0 = Debug|Win32 + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.ActiveCfg = Release|Win32 + {20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.Build.0 = Release|Win32 + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Debug.ActiveCfg = Debug|Win32 + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Debug.Build.0 = Debug|Win32 + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Release.ActiveCfg = Release|Win32 + {92E50294-4312-49E4-848B-5C9FF43AB27D}.Release.Build.0 = Release|Win32 + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Debug.ActiveCfg = Debug|Win32 + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Debug.Build.0 = Debug|Win32 + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Release.ActiveCfg = Release|Win32 + {56A4746D-5A73-4CA5-BD0C-959F14B503E7}.Release.Build.0 = Release|Win32 + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Debug.ActiveCfg = Debug|Win32 + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Debug.Build.0 = Debug|Win32 + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Release.ActiveCfg = Release|Win32 + {8983E45F-30DD-486C-AF5D-723E86BF5149}.Release.Build.0 = Release|Win32 + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Debug.ActiveCfg = Debug|Win32 + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Debug.Build.0 = Debug|Win32 + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Release.ActiveCfg = Release|Win32 + {71D05C32-B49A-4690-AA4D-1385D4257CDF}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal