Example #1
0
static void term_int(int sig)
{
	exit_io();
	int_off();
	tcsetattr(0, TCSADRAIN, &old_term);
	puts("\nKilled by user");
	exit(0);
}
Example #2
0
int main(int argc, char *argv[])
{
	register char *s, *p;
	register int i;
	char *pn = basename(argv[0]);
	struct timeval tv;
#ifdef HAS_CONFIG
	struct stat sbuf;
#endif
#ifdef BOOTROM
	char *rom = "-r ";
#else
	char *rom = "";
#endif
#ifdef CPU_SPEED
	f_flag = CPU_SPEED;
	tmax = CPU_SPEED * 10000;
#endif

	while (--argc > 0 && (*++argv)[0] == '-')
		for (s = argv[0] + 1; *s != '\0'; s++)

			switch (*s) {
			case 's':	/* save core and CPU on exit */
				s_flag = 1;
				break;

			case 'l':	/* load core and CPU from file */
				l_flag = 1;
				break;

			case 'u':	/* trap undocumented ops */
				u_flag = 1;
				break;

			case 'i':	/* trap I/O on unused ports */
				i_flag = 1;
				break;

			case 'm':	/* initialise Z80 memory */
				if (*(s+1) != '\0') {
					m_flag = exatoi(s+1);
					s += strlen(s+1);
				} else {
					if (argc <= 1)
						goto usage;
					argc--;
					argv++;
					m_flag = exatoi(argv[0]);
				}
				break;

			case 'f':	/* set emulation speed */
				if (*(s+1) != '\0') {
					f_flag = atoi(s+1);
					s += strlen(s+1);
				} else {
					if (argc <= 1)
						goto usage;
					argc--;
					argv++;
					f_flag = atoi(argv[0]);
				}
				tmax = f_flag * 10000;
				break;

			case 'x':	/* get filename with Z80 executable */
				x_flag = 1;
				s++;
				if (*s == '\0') {
					if (argc <= 1)
						goto usage;
					argc--;
					argv++;
					s = argv[0];
				}
				p = xfn;
				while (*s)
					*p++ = *s++;
				*p = '\0';
				s--;
				break;

#ifdef BOOTROM
			case 'r':	/* load default boot ROM */
				x_flag = 1;
				strcpy(xfn, BOOTROM);
				break;
#endif

#ifdef HAS_DISKS
			case 'd':	/* get path for disk images */
				s++;
				if (*s == '\0') {
					if (argc <= 1)
						goto usage;
					argc--;
					argv++;
					s = argv[0];
				}
				p = diskdir = diskd;
				while (*s)
					*p++ = *s++;
				*p = '\0';
				s--;
				break;
#endif

			case '8':
				cpu = I8080;
				break;

			case 'z':
				cpu = Z80;
				break;

			case '?':
			case 'h':
				goto usage;

			default:
				printf("illegal option %c\n", *s);

usage:

#ifdef HAS_DISKS
				printf("usage:\t%s -z -8 -s -l -i -u %s-m val -f freq -x filename -d diskpath\n", pn, rom);
#else
				printf("usage:\t%s -z -8 -s -l -i -u %s-m val -f freq -x filename\n", pn, rom);
#endif
				puts("\t-z = emulate Zilog Z80");
				puts("\t-8 = emulate Intel 8080");
				puts("\t-s = save core and CPU");
				puts("\t-l = load core and CPU");
				puts("\t-i = trap on I/O to unused ports");
				puts("\t-u = trap on undocumented instructions");
#ifdef BOOTROM
				puts("\t-r = load and execute default ROM");
				printf("\t     %s\n", BOOTROM);
#endif
				puts("\t-m = init memory with val (00-FF)");
				puts("\t-f = CPU clock frequency freq in MHz");
				puts("\t-x = load and execute filename");
#ifdef HAS_DISKS
				puts("\t-d = use disks images at diskpath");
				puts("\t     default path for disk images:");
				puts("\t     ./disks");
				printf("\t     %s\n", DISKSDIR);
#endif
				exit(1);
			}

	putchar('\n');

	if (cpu == Z80) {
puts("#######  #####    ###            #####    ###   #     #");
puts("     #  #     #  #   #          #     #    #    ##   ##");
puts("    #   #     # #     #         #          #    # # # #");
puts("   #     #####  #     #  #####   #####     #    #  #  #");
puts("  #     #     # #     #               #    #    #     #");
puts(" #      #     #  #   #          #     #    #    #     #");
puts("#######  #####    ###            #####    ###   #     #");

	} else {

puts(" #####    ###     #####    ###            #####    ###   #     #");
puts("#     #  #   #   #     #  #   #          #     #    #    ##   ##");
puts("#     # #     #  #     # #     #         #          #    # # # #");
puts(" #####  #     #   #####  #     #  #####   #####     #    #  #  #");
puts("#     # #     #  #     # #     #               #    #    #     #");
puts("#     #  #   #   #     #  #   #          #     #    #    #     #");
puts(" #####    ###     #####    ###            #####    ###   #     #");
	}

	printf("\nRelease %s, %s\n", RELEASE, COPYR);

#ifdef	USR_COM
	printf("%s Release %s, %s\n\n", USR_COM, USR_REL, USR_CPR);
#else
	putchar('\n');
#endif
	if (f_flag > 0)
		printf("CPU speed is %d MHz\n", f_flag);
	else
		printf("CPU speed is unlimited\n");

	fflush(stdout);

	/* if the machine has configuration files try to find them */
#ifdef HAS_CONFIG
	/* first try ./conf */
	if ((stat("./conf", &sbuf) == 0) && S_ISDIR(sbuf.st_mode)) {
		strcpy(&confdir[0], "./conf");
	/* then CONFDIR as set in Makefile */
	} else {
		strcpy(&confdir[0], CONFDIR);
	}

	//printf("config = %s\n", &confdir[0]);
#endif

	/* seed random generator */
	gettimeofday(&tv, NULL);
	srand(tv.tv_sec);

	config();		/* read system configuration */
	init_memory();		/* initialise memory configuration */
	init_cpu();		/* initialise CPU */
	wrk_ram	= mem_base();	/* set work pointer for memory */

	/* fill memory content with some initial value */
	if (m_flag >= 0) {
		memset((char *) wrk_ram, m_flag, 65536);
	} else {
		for (i = 0; i < 65536; i++)
			*(wrk_ram + i) = (BYTE) (rand() % 256);
	}

	init_rom();		/* initialise ROM's */

	if (l_flag)		/* load core */
		if (load_core())
			return(1);

	int_on();		/* initialize UNIX interrupts */
	init_io();		/* initialize I/O devices */

	mon();			/* run system */

	if (s_flag)		/* save core */
		save_core();

	exit_io();		/* stop I/O devices */
	int_off();		/* stop UNIX interrupts */

	return(0);
}
Example #3
0
int main(int argc,char *args[])
{
	int n,c;
	unsigned long long prof,start,end;

	end_of_data_ptr=sbrk(0);

	time_now=time(NULL);

	printf("\n");
	printf("   ********************************************\n");
        printf("   *     Astonia 3 - The Conflict Server      *\n");
	printf("   *             Version %d.%02d.%02d              *\n",VERSION>>16,(VERSION>>8)&255,VERSION&255);
	printf("   ********************************************\n");
        printf("   * Copyright (C) 2001-2008 Intent Software  *\n");
	printf("   * Copyright (C) 1997-2001 Daniel Brockhaus *\n");
	printf("   ********************************************\n");
	printf("\n");

        if (argc>1) {
		while (1) {
			c=getopt(argc,args,"a:m:i:dhc");
			if (c==-1) break;

			switch (c) {
				case 'a': 	if (optarg) areaID=atoi(optarg); break;
				case 'm': 	if (optarg) areaM=atoi(optarg); break;
				case 'd': 	demon=1; break;
				case 'h':	fprintf(stderr,"Usage: %s [-a <areaID>] [-m <mirror>] [-n <use this class A net>] [-d] [-c]\n\n-d Demonize\n-c Disable concurrent database access\n\n",args[0]); exit(0);
				case 'c':	multi=0; break;
				//case 'n':	if (optarg) server_net=atoi(optarg); break;
				case 'i':	if (optarg) serverID=atoi(optarg); break;
			}
		}
	}

	if (!areaID) {
		printf("No areaID given, assuming areaID=1\n");
		areaID=1;
	}
	if (!areaM) {
		printf("No mirror given, assuming areaM=1\n");
		areaM=1;
	}
	if (!serverID) {
		printf("No serverID given, assuming serverID=1\n");
		serverID=1;
	}

#ifdef STAFF
	while (!check_staff_start()) sleep(1);
#endif


        // set character number limit depending on area
	switch(areaID) {
		case 1:		maxchars=512; break;
		case 2:		maxchars=896; break;
		case 3:		maxchars=384; break;
		case 4:		maxchars=2048; break;
		case 5:		maxchars=768; break;
		case 6:		maxchars=384; break;
		case 7:		maxchars=1280; break;
		case 8:		maxchars=384; break;
		case 9:		maxchars=1280; break;
		case 10:	maxchars=512; break;
		case 11:	maxchars=384; break;
		case 12:	maxitem=1024*48; maxchars=384; break;
		case 13:	maxchars=9*50+200; break;
		case 14:	maxchars=16*50+200; break;
		case 15:	maxchars=384; break;
		case 16:	maxchars=384; break;
		case 17:	maxchars=512; break;
		case 18:	maxchars=768; break;
		case 19:	maxchars=384; break;
		case 20:	maxchars=768; break;
		case 21:	maxchars=768; break;
		case 22:	maxchars=512; break;
		case 23:	maxchars=512; break;
		case 24:	maxchars=384; break;
		case 25:	maxchars=384+8*25*2; break;
		case 26:	maxchars=256; break;
		case 27:	maxchars=2048; break;
		case 28:	maxchars=384; break;
		case 29:	maxchars=512; break;
		case 30:	maxchars=384; break;
		case 31:	maxitem=1024*40; maxchars=512; break;
		case 32:	maxchars=1280; break;
		case 33:	maxchars=1600; break;
		case 34:	maxchars=1280; break;
		case 35:	maxchars=768; break;
		case 36:	maxchars=768; break;
		case 37:	maxchars=1024; break;

		default:	maxchars=768; break;
	}
	
	// set item and effect limit
	if (!maxitem) maxitem=max(maxchars*12+10240,20480);
	if (!maxeffect) maxeffect=max(maxchars*2,1024);

	printf("serverID=%d, areaID=%d, areaM=%d, maxchars=%d, maxitem=%d, maxeffect=%d\n\n",
	       serverID,areaID,areaM,maxchars,maxitem,maxeffect);

	if (demon) {
		printf("Demonizing...\n\n");
		
		if (fork()) exit(0);
		for (n=0; n<256; n++) close(n);
		setsid();
#ifndef STAFF
		nologin=1;
#endif
	}

        // ignore the silly pipe errors:
        signal(SIGPIPE,SIG_IGN);

	// ignore sighup - just to be safe
        signal(SIGHUP,SIG_IGN);

	/*signal(SIGSEGV,sig_crash);
	signal(SIGFPE,sig_crash);
	signal(SIGBUS,sig_crash);
	signal(SIGSTKFLT,sig_crash);*/

        // shutdown gracefully if possible:
        signal(SIGQUIT,sig_leave);
        signal(SIGINT,sig_leave);
        signal(SIGTERM,sig_leave);

	// show profile info on CTRL-Z
	signal(SIGTSTP,sig_showprof);

	// init random number generator
        srand(time_now);

	if (!init_smalloc()) exit(1);
	if (!init_mem()) exit(1);
        if (!init_prof()) exit(1);
	if (!init_log()) exit(1);	
        if (!init_database()) exit(1);
	if (!init_lookup())  exit(1);
        if (!init_sector())  exit(1);
        if (!init_los()) exit(1);
	if (!init_timer()) exit(1);
        if (!init_notify()) exit(1);
	if (!init_create()) exit(1);
        if (!init_lib()) exit(1);
	if (!init_io()) exit(1);
        if (!init_path()) exit(1);	
	if (!init_effect()) exit(1);
	if (!init_container()) exit(1);
	if (!init_store()) exit(1);
	if (!init_chat()) exit(1);

	init_sound_sector();

	xlog("AreaID=%d, AreaM=%d, entering game loop...",areaID,areaM);

	dlog(0,0,"Server started");
	prof_reset();

        while (!quit) {
		sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (busy)",areaID,areaM,serverID,online,(10000-server_idle)/100);
		start=rdtsc();
		lock_server();

		time_now=time(NULL);
		prof=prof_start(26); tick_date(); prof_stop(26,prof);
		prof=prof_start(22); tick_timer(); prof_stop(22,prof);
                prof=prof_start(4); tick_char(); prof_stop(4,prof);
                prof=prof_start(24); tick_effect(); prof_stop(24,prof);
		prof=prof_start(36); tick_clan(); prof_stop(36,prof);
		prof=prof_start(39); tick_club(); prof_stop(39,prof);
		prof=prof_start(5); tick_player(); prof_stop(5,prof);
		prof=prof_start(34); tick_login(); prof_stop(34,prof);
                prof=prof_start(6); pflush(); prof_stop(6,prof);
		prof=prof_start(7); io_loop(); prof_stop(7,prof);
                prof=prof_start(3); tick_chat(); prof_stop(3,prof);

		if (showprof) {
			show_prof();
			showprof=0;
		}
		
		prof=prof_start(8); prof_update(); prof_stop(8,prof);

		end=rdtsc();
		cycles=end-start;

		if ((ticker&2047)==0) {
			prof=prof_start(27); area_alive(0); prof_stop(27,prof);
			prof=prof_start(28); backup_players(); prof_stop(28,prof);
			call_stat_update();
			read_motd();			
			reinit_log();
		}

		if ((ticker&255)==0) {
			call_check_task();
			call_area_load();
			shutdown_warn();
#ifdef STAFF
			check_staff_stop();
#endif
		}

		if ((ticker&255)==168) {
			prof=prof_start(38);
			consistency_check_items();
			consistency_check_map();
			consistency_check_chars();
			consistency_check_containers();
			prof_stop(38,prof);
		}

                unlock_server();

		sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (idle)",areaID,areaM,serverID,online,(10000-server_idle)/100);

		prof=prof_start(1); tick_sleep(0); prof_stop(1,prof);
		
		ticker++;
	}

        xlog("Left game loop");
	respawn_check();

	for (n=1; n<MAXCHARS; n++) {
		if (ch[n].flags&CF_PLAYER) {
			exit_char(n);
		}
	}
	area_alive(1);

        show_prof();

	dlog(0,0,"Server stopped");

	xlog("map check");
	check_map();

        exit_lib();
	exit_database();

	xlog("Clean shutdown");
	showmem();
	exit_log();
	exit_io();

        return 0;
}
Example #4
0
int main(int argc, char *argv[]) {
    register char *s, *p;
    register char *pn = argv[0];

    // configure the I/O ports
    AD1PCFG = 0xFFFF; // Default all pins to digital
    mJTAGPortEnable(0); // turn off jtag

    // setup the CPU
    SYSTEMConfigPerformance(CLOCKFREQ); // System config performance
    mOSCSetPBDIV(OSC_PB_DIV_1); // fix the peripheral bus to half main clock speed
    INTEnableSystemMultiVectoredInt();

    TRISBbits.TRISB15 = 0;
 //   TRISDbits.TRISD11 = 0;
 //   ODCDbits.ODCD11 = 1;
 //   LATDbits.LATD11=0;

    TRISBbits.TRISB13 = 0;
    ODCBbits.ODCB13 = 1;
    PORTBbits.RB13=0;
#ifdef UARTConsole
    UARTInit();
#endif
    initKeyboard();

#ifdef UseVideo
    initVideo();
#endif



#ifdef CPU_SPEED
    f_flag = CPU_SPEED;
    tmax = CPU_SPEED * 10000;
#endif
    argc = 0;
    while (--argc > 0 && (*++argv)[0] == '-')
        for (s = argv[0] + 1; *s != '\0'; s++)
            switch (*s) {
                case 's': /* save core and CPU on exit */
                    s_flag = 1;
                    break;
                case 'l': /* load core and CPU from file */
                    l_flag = 1;
                    break;
#ifdef Z80_UNDOC
                case 'z': /* trap undocumented Z80 ops */
                    z_flag = 1;
                    break;
#endif
                case 'i': /* trap I/O on unused ports */
                    i_flag = 1;
                    break;
                case 'm': /* initialize Z80 memory */
                    m_flag = exatoi(s + 1);
                    s += strlen(s + 1);
                    break;
                case 'f': /* set emulation speed */
                    f_flag = atoi(s + 1);
                    s += strlen(s + 1);
                    tmax = f_flag * 10000;
                    break;
                case 'x': /* get filename with Z80 executable */
                    x_flag = 1;
                    s++;
                    p = xfn;
                    while (*s)
                        *p++ = *s++;
                    *p = '\0';
                    s--;
                    break;
                case '?':
                    goto usage;
                default:
                    printf("illegal option %c\n", *s);
#ifndef Z80_UNDOC
usage:
                    printf("usage:\t%s -s -l -i -mn -fn -xfilename\n", pn);
#else
usage:
                    printf("usage:\t%s -s -l -i -z -mn -fn -xfilename\n", pn);
#endif
                    puts("\ts = save core and cpu");
                    puts("\tl = load core and cpu");
                    puts("\ti = trap on I/O to unused ports");
#ifdef Z80_UNDOC
                    puts("\tz = trap on undocumented Z80 ops");
#endif
                    puts("\tm = init memory with n");
                    puts("\tf = CPU frequenzy n in MHz");
                    puts("\tx = load and execute filename");
                    exit(1);
            }

    putchar('\n');
    puts("#######  #####    ###            #####    ###   #     #");
    puts("     #  #     #  #   #          #     #    #    ##   ##");
    puts("    #   #     # #     #         #          #    # # # #");
    puts("   #     #####  #     #  #####   #####     #    #  #  #");
    puts("  #     #     # #     #               #    #    #     #");
    puts(" #      #     #  #   #          #     #    #    #     #");
    puts("#######  #####    ###            #####    ###   #     #");
    printf("\nRelease %s, %s\n", RELEASE, COPYR);
    printf("\nPort to PIC32 By kenseglerdesigns.com\n");
    if (f_flag > 0)
        printf("\nCPU speed is %d MHz\n", f_flag);
    else
        printf("\nCPU speed is unlimited\n");
#ifdef	USR_COM
    printf("\n%s Release %s, %s\n", USR_COM, USR_REL, USR_CPR);
#endif
    fflush(stdout);

    wrk_ram = PC = ram;
    STACK = ram +0xffff;
    memset((char *) ram, m_flag, 65536);
    if (l_flag)
        if (load_core())
            return (1);
    int_on();
    init_io();
    mon();
    if (s_flag)
        save_core();
    exit_io();
    int_off();
    return (0);
}