fatal signal handler ;)

This commit is contained in:
Gabriel Lorenzo 2002-09-06 17:43:38 +00:00
parent 83f6da7905
commit 0348301411
10 changed files with 227 additions and 123 deletions

View file

@ -1,60 +0,0 @@
PROGRAM colorido;
LOCAL
i1 , i2 ;
r , g , b ;
fondo ;
vx , vy ;
angulo ;
graf_barra[200] ;
BEGIN
rand_seed( 0 ) ;
from i2 = 36 to 165 ;
for ( i1 = 160 - ((( i2-36 ) * 75 ) / 129 ) ; i1 < 160 + ((( i2-36 ) * 75 ) / 129 ) ; i1++ )
r = 255 - 2*fget_dist( i1 , i2 , 160 , 36 ) ; if ( r< 0) r = 0 ; end
g = 255 - 2*fget_dist( i1 , i2 , 85 , 165 ) ; if ( g< 0) g = 0 ; end
b = 255 - 2*fget_dist( i1 , i2 , 245 , 165 ) ; if ( b< 0) b = 0 ; end
put_pixel( i1 , i2 , rgb(r,g,b) ) ;
end
FRAME;
end
fondo = new_map( 320 , 200 , 0 , 0 , 0 ) ;
screen_copy( 0 , 0 , fondo , 0 , 0 , 320 , 200 ) ;
map_block_copy( 0 , graph , 0 , 0 , fondo , 85 , 36 , 150 , 126 ) ;
clear_screen() ;
angle = 1500 ;
from i1 = 0 to 199 ;
angle+= 3000 ;
graf_barra[i1] = new_map( 320 , 1 , 0 , 0 , 0 ) ;
map_block_copy( 0 , graf_barra[i1] , 0 , 0 , fondo , 0 , i1*1 , 320 , 1 ) ;
end
vx = rand( -3 , 3 ) ;
vy = rand( -3 , 3 ) ;
flags = 4 ;
transparency = 128 ;
loop
angle+= 15000 ;
from i1 = 0 to 199 ;
put( 0 , graf_barra[i1] , cos(angle+i1*6000) / 50 , i1 *1 ) ;
end
frame;
clear_screen() ;
end
end
PROCESS barra( graph , angle , y ) ;
BEGIN
LOOP
angle += 15000 ;
x = cos(angle+i1*30000) / 50 ;
FRAME;
END
END

View file

@ -1,41 +0,0 @@
PROGRAM regiones;
GLOBAL
grafico ;
cuad ;
tras = 0 ;
LOCAL
i1 , i2 ;
BEGIN
define_region(1 , 0 , 0 , 200 , 200 ) ;
region = 1 ;
// cuad = draw( 3 , rgb(0,255,0) , 14 , 0 , 10 , 10 , 20 , 20 ) ;
graph = load_bmp("sion.bmp") ;
file = load_fpg("test.fpg") ;
put_screen(file,1) ;
detras() ;
//graph = 1 ;
LOOP
// tras = (tras+1) % 16 ;
// if ( tras > 15 ) tras = 0 ; end
// move_draw( cuad , rgb(0,255,0) , tras , 10+tras , 10+tras*2 , 20+tras*2 , 20+tras*4 ) ;
if ( key(_right)) x+=5 ; end
if ( key(_left)) x-=5 ; end
if ( key(_up)) y-= 5 ; end
if ( key(_down)) y+=5 ; end
// if ( key(_d)) delete_draw( cuad ) ; end
FRAME;
END
END
PROCESS detras()
BEGIN
graph = load_bmp("ediv.bmp") ;
x = 160 ;
y = 100 ;
z = 10 ;
LOOP
FRAME;
END
END

View file

@ -1,22 +0,0 @@
PROGRAM colorido;
LOCAL
i1 , i2 ;
r , g , b ;
BEGIN
from i2 = 36 to 165 ;
for ( i1 = 160 - ((( i2-36 ) * 75 ) / 129 ) ; i1 < 160 + ((( i2-36 ) * 75 ) / 129 ) ; i1++ )
r = 255 - 2*fget_dist( i1 , i2 , 160 , 36 ) ; if ( r< 0) r = 0 ; end
g = 255 - 2*fget_dist( i1 , i2 , 85 , 165 ) ; if ( g< 0) g = 0 ; end
b = 255 - 2*fget_dist( i1 , i2 , 245 , 165 ) ; if ( b< 0) b = 0 ; end
put_pixel( i1 , i2 , rgb(r,g,b) ) ;
end
end
loop
frame;
end
end

Binary file not shown.

Binary file not shown.

191
ediv/src/stub/fatal.c Normal file
View file

@ -0,0 +1,191 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
/* General fatal signal handling code for SDL */
#ifdef NO_SIGNAL_H
/* No signals on this platform, nothing to do.. */
void eDIV_InstallParachute(void)
{
return;
}
void eDIV_UninstallParachute(void)
{
return;
}
#else
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <SDL/SDL.h>
#include "fatal.h"
#include "main.h"
#include "inte.h"
#ifdef __CYGWIN__
#define DISABLE_STDIO
#endif
/* This installs some signal handlers for the more common fatal signals,
so that if the programmer is lazy, the app doesn't die so horribly if
the program crashes.
*/
static void print_msg(const char *text)
{
#ifndef DISABLE_STDIO
fprintf(stderr, "%s", text);
#endif
}
static void eDIV_Parachute(int sig)
{
signal(sig, SIG_DFL);
print_msg("Fatal signal: ");
switch (sig) {
case SIGSEGV:
print_msg("Segmentation Fault");
break;
#ifdef SIGBUS
#if SIGBUS != SIGSEGV
case SIGBUS:
print_msg("Bus Error");
break;
#endif
#endif /* SIGBUS */
#ifdef SIGFPE
case SIGFPE:
print_msg("Floating Point Exception");
break;
#endif /* SIGFPE */
#ifdef SIGQUIT
case SIGQUIT:
print_msg("Keyboard Quit");
break;
#endif /* SIGQUIT */
#ifdef SIGPIPE
case SIGPIPE:
print_msg("Broken Pipe");
break;
#endif /* SIGPIPE */
default:
#ifndef DISABLE_STDIO
fprintf(stderr, "# %d", sig);
#endif
break;
}
print_msg(" (eDIV Parachute Deployed)\n");
#ifndef DISABLE_STDIO
printf("dbg: ignore_errors:%d",ignore_errors);
#ifdef DBG
printf(", debug:%d",debug);
#endif
printf("\ndbg: num_procesos:%d, proceso actual:%d\n",num_proc_orden,proceso_actual);
printf("dbg: imem:%d, imem_max:%d, mem:0x%X\n",imem,imem_max,mem);
printf("dbg: sp:%d, pila:0x%X, pila_max:%d\n",sp,pila,pila_max);
if(pila) {
int s,e,i;
s=sp-10; if(s<0) s=0;
e=sp+10; if(e>pila_max) e=pila_max;
printf("dbg: Volcado de pila (%d-%d):\ndbg: ",s,e);
for(i=s;i<=e;i++) {
printf("%d",pila[i]);
if(i!=e) printf(", ");
}
printf("\n");
}
#endif
SDL_Quit();
exit(-sig);
}
static int eDIV_fatal_signals[] = {
SIGSEGV,
#ifdef SIGBUS
SIGBUS,
#endif
#ifdef SIGFPE
SIGFPE,
#endif
#ifdef SIGQUIT
SIGQUIT,
#endif
#ifdef SIGPIPE
SIGPIPE,
#endif
0
};
void eDIV_InstallParachute(void)
{
int i;
void (*ohandler)(int);
/* Set a handler for any fatal signal not already handled */
for ( i=0; eDIV_fatal_signals[i]; ++i ) {
ohandler = signal(eDIV_fatal_signals[i], eDIV_Parachute);
if ( ohandler != SIG_DFL ) {
signal(eDIV_fatal_signals[i], ohandler);
}
}
#ifdef SIGALRM
/* Set SIGALRM to be ignored -- necessary on Solaris */
{
struct sigaction action, oaction;
/* Set SIG_IGN action */
memset(&action, 0, (sizeof action));
action.sa_handler = SIG_IGN;
sigaction(SIGALRM, &action, &oaction);
/* Reset original action if it was already being handled */
if ( oaction.sa_handler != SIG_DFL ) {
sigaction(SIGALRM, &oaction, NULL);
}
}
#endif
return;
}
void eDIV_UninstallParachute(void)
{
int i;
void (*ohandler)(int);
/* Remove a handler for any fatal signal handled */
for ( i=0; eDIV_fatal_signals[i]; ++i ) {
ohandler = signal(eDIV_fatal_signals[i], SIG_DFL);
if ( ohandler != eDIV_Parachute ) {
signal(eDIV_fatal_signals[i], ohandler);
}
}
}
#endif /* NO_SIGNAL_H */

27
ediv/src/stub/fatal.h Normal file
View file

@ -0,0 +1,27 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@devolution.com
*/
/* General fatal signal handling code for SDL */
extern void eDIV_InstallParachute(void);
extern void eDIV_UninstallParachute(void);

View file

@ -34,6 +34,7 @@
#include "kernel.h"
#include "inte.h"
#include "varindex.h"
#include "fatal.h"
#define long_header 9 // Longitud de la cabecera al inicio de los programas
@ -66,6 +67,8 @@ int main(int argc, char* argv[])
numdlls=0;
n_externs=0;
eDIV_InstallParachute();
for ( i = 0 ; i < 100 ; i++ )
tiempo[ i ] = 0 ;
tiempo_i = 0 ;

Binary file not shown.

View file

@ -275,6 +275,9 @@ makelib win32.rel
<File
RelativePath="..\..\stub\error.c">
</File>
<File
RelativePath="..\..\stub\fatal.c">
</File>
<File
RelativePath="..\..\stub\inte.c">
</File>
@ -303,6 +306,9 @@ makelib win32.rel
<File
RelativePath="..\..\shared\extern.h">
</File>
<File
RelativePath="..\..\stub\fatal.h">
</File>
<File
RelativePath="..\..\stub\inte.h">
</File>