Beispiel #1
0
static int
CommandSaveLayoutAndQuit (int argc, char **argv, int x, int y)
{
  if (!CommandSaveLayout (argc, argv, x, y))
    return CommandQuit (0, 0, 0, 0);
  return (1);
}
Beispiel #2
0
static void NetworkExecCommand_Quit(const CNetworkCommandQueue &ncq)
{
	Assert((ncq.Type & 0x7F) == MessageQuit);
	CNetworkCommandQuit nc;

	nc.Deserialize(&ncq.Data[0]);
	NetworkRemovePlayer(nc.player);
	CommandLog("quit", NoUnitP, FlushCommands, nc.player, -1, NoUnitP, NULL, -1);
	CommandQuit(nc.player);
}
Beispiel #3
0
int main(int argc, char **argv)
{
//	std::cerr << "Now starting...\n";
//	malloc_stats();
	int i=1;
	char cmdLine[15];
	BOOL end=FALSE;

	compdists=IOread=IOwrite=objs=0;
	std::cout << "**  MTree: An M-Tree based on Generalized Search Trees\n";
	while(strcmp(cmdLine, "quit")) {
		scanf("%s", cmdLine);
		if(!strcmp(cmdLine, "drop")) {
			CommandDrop("graphs.M3");
			if(argc<5) {
				std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] [sec_promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
				exit(-1);
			}
			MIN_UTIL=atof(argv[1]);
			SPLIT_FUNCTION=(s_function)atoi(argv[2]);
			PROMOTE_PART_FUNCTION=(pp_function)atoi(argv[3]);
			SECONDARY_PART_FUNCTION=(pp_function)atoi(argv[4]);
			if(SECONDARY_PART_FUNCTION==CONFIRMED) {
				std::cout << "The secondary promotion function must be an unconfirmed one\n";
				exit(-1);
			}
			if(PROMOTE_PART_FUNCTION==SAMPLING) {
				if(argc<6) {
					std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
					exit(-1);
				}
				NUM_CANDIDATES=atoi(argv[5]);
			}
			if(PROMOTE_PART_FUNCTION==CONFIRMED) {
				if(argc<6) {
					std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] [sec_promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
					exit(-1);
				}
				PROMOTE_VOTE_FUNCTION=(pv_function)atoi(argv[5]);
				if(PROMOTE_VOTE_FUNCTION==SAMPLINGV) {
					if(argc<7) {
						std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
						exit(-1);
					}
					NUM_CANDIDATES=atoi(argv[6]);
				}
				else if(PROMOTE_VOTE_FUNCTION==mM_RAD) {
					if(argc<7) {
						std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
						exit(-1);
					}
					RADIUS_FUNCTION=(r_function)atoi(argv[6]);
				}
			}
			switch(SPLIT_FUNCTION) {
				case G_HYPERPL:
					std::cout << "G_HYPL, ";
					break;
				case BAL_G_HYPERPL:
					std::cout << "BAL_G_HYPL, ";
					break;
				case BALANCED:
					std::cout << "BAL, ";
					break;
			}
			switch(PROMOTE_PART_FUNCTION) {
				case RANDOM:
					std::cout << "RAN_2 ";
					break;
				case MAX_UB_DIST:
					std::cout << "M_UB_d ";
					break;
				case SAMPLING:
					std::cout << "SAMP" << NUM_CANDIDATES << "_2 ";
					break;
				case MIN_RAD:
					std::cout << "m_R_2 ";
					break;
				case MIN_OVERLAPS:
					std::cout << "m_O_2 ";
					break;
				case CONFIRMED:
				switch(PROMOTE_VOTE_FUNCTION) {
					case RANDOMV:
						std::cout << "RAN_1 ";
						break;
					case SAMPLINGV:
						std::cout << "SAMP" << NUM_CANDIDATES << "_1 ";
						break;
					case MAX_LB_DIST:
						std::cout << "M_LB_d ";
						break;
					case mM_RAD:
						std::cout << "mM_";
						switch(RADIUS_FUNCTION) {
							case LB:
								std::cout << "m";
								break;
							case AVG:
								std::cout << "A";
								break;
							case UB:
								std::cout << "M";
								break;
						}
						std::cout << "_r ";
						break;
				}
				break;
			}
			switch(SECONDARY_PART_FUNCTION) {
				case RANDOM:
					std::cout << "(RAN_2)\n";
					break;
				case MAX_UB_DIST:
					std::cout << "(M_UB_d)\n";
					break;
				case SAMPLING:
					std::cout << "(SAMP" << NUM_CANDIDATES << "_2)\n";
					break;
				case MIN_RAD:
					std::cout << "(m_R_2)\n";
					break;
				case MIN_OVERLAPS:
					std::cout << "(m_O_2)\n";
					break;
			}
			CommandCreate("mtree", "graphs.M3");
		}
		else if(!strcmp(cmdLine, "select")) {
			MTobject *obj=Read();
			Pred *pred=new Pred(*obj);
			double r;

			scanf("%s", cmdLine);
			r=atof(cmdLine);

			SimpleQuery query(pred, r);

			delete obj;
			delete pred;
			if(!gist) CommandOpen("mtree", "graphs.M3");
			CommandSelect(query);
			CommandClose();
		}
		else if((!strcmp(cmdLine, "nearest"))||(!strcmp(cmdLine, "farthest"))) {
			int k;
			BOOL nearest=strcmp(cmdLine, "farthest");
			MTpred *pred;
			MTobject *obj=Read();

			scanf("%s", cmdLine);
			k=atoi(cmdLine);
			if(nearest) pred=new Pred(*obj);
			else {
				MTpred *npred=new Pred(*obj);

				pred=new NotPred(npred);
				delete npred;
			}
//			eps=atof(argv[1]);
			TopQuery query(pred, k);

			delete pred;
			if(!gist) CommandOpen("mtree", "graphs.M3");
			CommandNearest(query);
			CommandClose();
			delete obj;
		}
		else if(!strcmp(cmdLine, "cursor")) {
			MTobject *obj=Read();
			Pred pred(*obj);

			if(!gist) CommandOpen("mtree", "graphs.M3");
			MTcursor cursor(*gist, pred);

			scanf("%s", cmdLine);
			while(strcmp(cmdLine, "close")) {
				if(!strcmp(cmdLine, "next")) {
					int k;
					GiSTlist<MTentry *> list;

					scanf("%s", cmdLine);
					k=atoi(cmdLine);

//					std::cout << "Fetching next " << k << " entries...\n";
					for(; k>0; k--) list.Append(cursor.Next());
					while(!list.IsEmpty()) {
						MTentry *e=list.RemoveFront();
//						std::cout << e;
						delete e;
						objs++;
					}
				}
				scanf("%s", cmdLine);
			}
			delete obj;
			CommandClose();
		}
/*		else if(!strcmp(cmdLine, "find")) {
			int n, k, l, oldcompdists, oldIOread, oldobjs;

			scanf("%s", cmdLine);
			n=atoi(cmdLine);

			double **x=(double **)calloc(n, sizeof(double *));
			for(i=0; i<n; i++) x[i]=(double *)calloc(dimension, sizeof(double));
			MTpred **p=(MTpred **)calloc(n, sizeof(MTpred *));
			AndPred **ap=(AndPred **)calloc(n-1, sizeof(AndPred *));

			for(i=0; i<n; i++) {
				for(int j=0; j<dimension; j++) {
					scanf("%s", cmdLine);
					x[i][j]=atof(cmdLine);
				}
				if(x[i][0]>=0) {
					MTobject obj(x[i]);
//					std::cout << "obj=" << obj << std::endl;
					p[i]=new Pred(obj);
				}
				else {
					x[i][0]=-x[i][0];
					MTobject obj(x[i]);
//					std::cout << "obj=" << obj << std::endl;
					Pred *pr=new Pred(obj);
					p[i]=new NotPred(pr);
					delete pr;
				}
//				std::cout << "pred=" << *p[i] << std::endl;
			}
			if(n==2) std::cout << "d=" << p[1]->distance(((Pred *)p[0])->obj()) << std::endl;
			ap[0]=new AndPred(p[0], p[1]);
			for(i=1; i<n-1; i++) ap[i]=new AndPred(ap[i-1], p[i+1]);
//			std::cout << "Query: " << *ap[n-2] << std::endl;
			scanf("%s", cmdLine);
			k=atoi(cmdLine);
			compdists=IOread=IOwrite=0;

			TopQuery q(ap[n-2], k);

			if(!gist) CommandOpen("mtree", "graphs.M3");
			CommandNearest(q);
			std::cout << "Computed dists=" << compdists << "\nIO reads=" << IOread << "\nIO writes=" << IOwrite << "\nObjs=" << objs << std::endl;

			BOOL (*obs)[IndObjs]=new BOOL [n][IndObjs], pass=FALSE;

			l=-90;
			do {
				int j;

				for(j=0; j<IndObjs; j++)
					for(i=0; i<n; i++) obs[i][j]=FALSE;
				compdists=IOread=IOwrite=objs=0;
				l+=100;
				for(i=0; i<n; i++) {
					TopQuery qi(p[i], l);
					GiSTlist<GiSTobject *> list=gist->TopSearch(qi);

					while(!list.IsEmpty()) {
						MTentry *e=(MTentry *)list.RemoveFront();

						obs[i][e->Ptr()]=TRUE;
						delete e;
					}
				}
				for(j=0; j<IndObjs; j++) {
					BOOL check=TRUE;

					for(i=0; (i<n)&&check; i++) check=obs[i][j];
					if(check) objs++;
				}
//				std::cout << l << "=>" << objs << std::endl;
				if(objs>k) {
					pass=TRUE;
					l-=110;
					oldcompdists=compdists;
					oldIOread=IOread;
					oldobjs=objs;
				}
				if(!pass) {
					oldcompdists=compdists;
					oldIOread=IOread;
					oldobjs=objs;
				}
//				else if(objs==0) l+=90; // dangerous: could lead to infinite loops...
			} while(((objs<k)&&!pass)||((objs>k)&&pass));
			std::cout << l << "=>" << objs << std::endl;
			if(objs<k) std::cout << "Computed dists=" << oldcompdists << "\nIO reads=" << oldIOread << "\nObjs=" << oldobjs << std::endl;
			else std::cout << "Computed dists=" << compdists << "\nIO reads=" << IOread << "\nObjs=" << objs << std::endl;
			delete []obs;
			for(i=0; i<n; i++) delete x[i];
			free(x);
			for(i=0; i<n; i++) delete p[i];
			free(p);
			for(i=0; i<n-1; i++) delete ap[i];
			free(ap);
			compdists=IOread=IOwrite=objs=0;
			CommandClose();
		}
*/		else if(!strcmp(cmdLine, "check")) {
			if(!gist) CommandOpen("mtree", "graphs.M3");
			CommandCheck();
			CommandClose();
		}
		else if(!strcmp(cmdLine, "dump")) {
			if(!gist) CommandOpen("mtree", "graphs.M3");
			CommandDump();
			CommandClose();
		}
		else if(!strcmp(cmdLine, "stats")) {
			if(!gist) CommandOpen("mtree", "graphs.M3");
			CommandStats();
			CommandClose();
		}
		else if(!strcmp(cmdLine, "add")) {
			if(!gist) CommandOpen("mtree", "graphs.M3");
			scanf("%s", cmdLine);
			i=atoi(cmdLine);
			if(argc<5) {
				std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] [sec_promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
				exit(-1);
			}
			MIN_UTIL=atof(argv[1]);
			SPLIT_FUNCTION=(s_function)atoi(argv[2]);
			PROMOTE_PART_FUNCTION=(pp_function)atoi(argv[3]);
			SECONDARY_PART_FUNCTION=(pp_function)atoi(argv[4]);
			if(SECONDARY_PART_FUNCTION==CONFIRMED) {
				std::cout << "The secondary promotion function must be an unconfirmed one\n";
				exit(-1);
			}
			if(PROMOTE_PART_FUNCTION==SAMPLING) {
				if(argc<6) {
					std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
					exit(-1);
				}
				NUM_CANDIDATES=atoi(argv[5]);
			}
			if(PROMOTE_PART_FUNCTION==CONFIRMED) {
				if(argc<6) {
					std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] [sec_promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
					exit(-1);
				}
				PROMOTE_VOTE_FUNCTION=(pv_function)atoi(argv[5]);
				if(PROMOTE_VOTE_FUNCTION==SAMPLINGV) {
					if(argc<7) {
						std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
						exit(-1);
					}
					NUM_CANDIDATES=atoi(argv[6]);
				}
				else if(PROMOTE_VOTE_FUNCTION==mM_RAD) {
					if(argc<7) {
						std::cout << "Usage is: MTree [min_util] [split_f] [promote_f] ([vote_f] ([n_cand]|[radius_f]))\n";
						exit(-1);
					}
					RADIUS_FUNCTION=(r_function)atoi(argv[6]);
				}
			}
			switch(SPLIT_FUNCTION) {
				case G_HYPERPL:
					std::cout << "G_HYPL, ";
					break;
				case BAL_G_HYPERPL:
					std::cout << "BAL_G_HYPL, ";
					break;
				case BALANCED:
					std::cout << "BAL, ";
					break;
			}
			switch(PROMOTE_PART_FUNCTION) {
				case RANDOM:
					std::cout << "RAN_2 ";
					break;
				case MAX_UB_DIST:
					std::cout << "M_UB_d ";
					break;
				case SAMPLING:
					std::cout << "SAMP" << NUM_CANDIDATES << "_2 ";
					break;
				case MIN_RAD:
					std::cout << "m_R_2 ";
					break;
				case MIN_OVERLAPS:
					std::cout << "m_O_2 ";
					break;
				case CONFIRMED:
					switch(PROMOTE_VOTE_FUNCTION) {
						case RANDOMV:
							std::cout << "RAN_1 ";
							break;
						case SAMPLINGV:
							std::cout << "SAMP" << NUM_CANDIDATES << "_1 ";
							break;
						case MAX_LB_DIST:
							std::cout << "M_LB_d ";
							break;
						case mM_RAD:
							std::cout << "mM_";
							switch(RADIUS_FUNCTION) {
								case LB:
									std::cout << "m";
									break;
								case AVG:
									std::cout << "A";
									break;
								case UB:
									std::cout << "M";
									break;
							}
							std::cout << "_r ";
							break;
					}
					break;
			}
			switch(SECONDARY_PART_FUNCTION) {
				case RANDOM:
					std::cout << "(RAN_2)\n";
					break;
				case MAX_UB_DIST:
					std::cout << "(M_UB_d)\n";
					break;
				case SAMPLING:
					std::cout << "(SAMP" << NUM_CANDIDATES << "_2)\n";
					break;
				case MIN_RAD:
					std::cout << "(m_R_2)\n";
					break;
				case MIN_OVERLAPS:
					std::cout << "(m_O_2)\n";
					break;
			}
		}
		else if(!strcmp(cmdLine, "insert")) {
			MTobject *obj=Read();

			if(!gist) CommandOpen("mtree", "graphs.M3");
			CommandInsert(MTkey(*obj, 0, 0), i++);
			delete obj;
		}
		else if(!strcmp(cmdLine, "load")) {
			MTentry **entries;
			int n;

			if(argc<2) {
				std::cout << "Usage is: MTree [min_util]\n";
				exit(-1);
			}
			MIN_UTIL=atof(argv[1]);
			i=0;
			scanf("%s", cmdLine);
			n=atoi(cmdLine);
			entries=new MTentry*[n];
			for(i=0; i<n; i++) {
				MTobject *obj=Read();

				entries[i]=new MTentry(MTkey(*obj, 0, 0), i);
				delete obj;
			}
			CommandLoad("graphs.M3", entries, n);
			for(i=0; i<n; i++) delete entries[i];
			delete []entries;
		}
	}
	std::cout << "Computed dists=" << compdists << "\nIO reads=" << IOread << "\nIO writes=" << IOwrite << "\nObjs=" << objs << std::endl;
	CommandQuit();
//	std::cerr << "Now exiting...\n";
//	malloc_stats();
}
Beispiel #4
0
/**
**  Do next replay
*/
static void DoNextReplay()
{
	Assert(ReplayStep != 0);

	NextLogCycle = ReplayStep->GameCycle;

	if (NextLogCycle != GameCycle) {
		return;
	}

	const int unitSlot = ReplayStep->UnitNumber;
	const char *action = ReplayStep->Action.c_str();
	const int flags = ReplayStep->Flush;
	const Vec2i pos(ReplayStep->PosX, ReplayStep->PosY);
	const int arg1 = ReplayStep->PosX;
	const int arg2 = ReplayStep->PosY;
	CUnit *unit = unitSlot != -1 ? &UnitManager.GetSlotUnit(unitSlot) : NULL;
	CUnit *dunit = (ReplayStep->DestUnitNumber != -1 ? &UnitManager.GetSlotUnit(ReplayStep->DestUnitNumber) : NULL);
	const char *val = ReplayStep->Value.c_str();
	const int num = ReplayStep->Num;

	Assert(unitSlot == -1 || ReplayStep->UnitIdent == unit->Type->Ident);

	if (SyncRandSeed != ReplayStep->SyncRandSeed) {
#ifdef DEBUG
		if (!ReplayStep->SyncRandSeed) {
			// Replay without the 'sync info
			ThisPlayer->Notify("%s", _("No sync info for this replay !"));
		} else {
			ThisPlayer->Notify(_("Replay got out of sync (%lu) !"), GameCycle);
			DebugPrint("OUT OF SYNC %u != %u\n" _C_ SyncRandSeed _C_ ReplayStep->SyncRandSeed);
			DebugPrint("OUT OF SYNC GameCycle %lu \n" _C_ GameCycle);
			Assert(0);
			// ReplayStep = 0;
			// NextLogCycle = ~0UL;
			// return;
		}
#else
		ThisPlayer->Notify("%s", _("Replay got out of sync !"));
		ReplayStep = 0;
		NextLogCycle = ~0UL;
		return;
#endif
	}

	if (!strcmp(action, "stop")) {
		SendCommandStopUnit(*unit);
	} else if (!strcmp(action, "stand-ground")) {
		SendCommandStandGround(*unit, flags);
	} else if (!strcmp(action, "defend")) {
		SendCommandDefend(*unit, *dunit, flags);
	} else if (!strcmp(action, "follow")) {
		SendCommandFollow(*unit, *dunit, flags);
	} else if (!strcmp(action, "move")) {
		SendCommandMove(*unit, pos, flags);
	//Wyrmgus start
	} else if (!strcmp(action, "pick-up")) {
		SendCommandPickUp(*unit, *dunit, flags);
	//Wyrmgus end
	} else if (!strcmp(action, "repair")) {
		SendCommandRepair(*unit, pos, dunit, flags);
	} else if (!strcmp(action, "auto-repair")) {
		SendCommandAutoRepair(*unit, arg1);
	} else if (!strcmp(action, "attack")) {
		SendCommandAttack(*unit, pos, dunit, flags);
	} else if (!strcmp(action, "attack-ground")) {
		SendCommandAttackGround(*unit, pos, flags);
	//Wyrmgus start
	} else if (!strcmp(action, "use")) {
		SendCommandUse(*unit, *dunit, flags);
	} else if (!strcmp(action, "trade")) {
		SendCommandTrade(*unit, *dunit, flags);
	//Wyrmgus end
	} else if (!strcmp(action, "patrol")) {
		SendCommandPatrol(*unit, pos, flags);
	} else if (!strcmp(action, "board")) {
		SendCommandBoard(*unit, *dunit, flags);
	} else if (!strcmp(action, "unload")) {
		SendCommandUnload(*unit, pos, dunit, flags);
	} else if (!strcmp(action, "build")) {
		SendCommandBuildBuilding(*unit, pos, *UnitTypeByIdent(val), flags);
	} else if (!strcmp(action, "dismiss")) {
		SendCommandDismiss(*unit);
	} else if (!strcmp(action, "resource-loc")) {
		SendCommandResourceLoc(*unit, pos, flags);
	} else if (!strcmp(action, "resource")) {
		SendCommandResource(*unit, *dunit, flags);
	} else if (!strcmp(action, "return")) {
		SendCommandReturnGoods(*unit, dunit, flags);
	} else if (!strcmp(action, "train")) {
		//Wyrmgus start
//		SendCommandTrainUnit(*unit, *UnitTypeByIdent(val), flags);
		SendCommandTrainUnit(*unit, *UnitTypeByIdent(val), num, flags);
		//Wyrmgus end
	} else if (!strcmp(action, "cancel-train")) {
		SendCommandCancelTraining(*unit, num, (val && *val) ? UnitTypeByIdent(val) : NULL);
	} else if (!strcmp(action, "upgrade-to")) {
		SendCommandUpgradeTo(*unit, *UnitTypeByIdent(val), flags);
	} else if (!strcmp(action, "cancel-upgrade-to")) {
		SendCommandCancelUpgradeTo(*unit);
	//Wyrmgus start
	} else if (!strcmp(action, "transform-into")) {
		SendCommandTransformInto(*unit, *UnitTypeByIdent(val), flags);
	//Wyrmgus end
	} else if (!strcmp(action, "research")) {
		//Wyrmgus start
//		SendCommandResearch(*unit, *CUpgrade::Get(val), flags);
		SendCommandResearch(*unit, *CUpgrade::Get(val), num, flags);
		//Wyrmgus end
	} else if (!strcmp(action, "cancel-research")) {
		SendCommandCancelResearch(*unit);
	//Wyrmgus start
	} else if (!strcmp(action, "learn-ability")) {
		SendCommandLearnAbility(*unit, *CUpgrade::Get(val));
	//Wyrmgus end
	} else if (!strcmp(action, "spell-cast")) {
		SendCommandSpellCast(*unit, pos, dunit, num, flags);
	} else if (!strcmp(action, "auto-spell-cast")) {
		SendCommandAutoSpellCast(*unit, num, arg1);
	//Wyrmgus start
	} else if (!strcmp(action, "rally-point")) {
		SendCommandRallyPoint(*unit, pos);
	} else if (!strcmp(action, "quest")) {
		SendCommandQuest(*unit, GetQuest(val));
	} else if (!strcmp(action, "buy")) {
		SendCommandBuy(*unit, dunit, num);
	} else if (!strcmp(action, "produce-resource")) {
		SendCommandProduceResource(*unit, num);
	} else if (!strcmp(action, "sell-resource")) {
		SendCommandSellResource(*unit, arg1, num);
	} else if (!strcmp(action, "buy-resource")) {
		SendCommandBuyResource(*unit, arg1, num);
	//Wyrmgus end
	} else if (!strcmp(action, "diplomacy")) {
		int state;
		if (!strcmp(val, "neutral")) {
			state = DiplomacyNeutral;
		} else if (!strcmp(val, "allied")) {
			state = DiplomacyAllied;
		} else if (!strcmp(val, "enemy")) {
			state = DiplomacyEnemy;
		//Wyrmgus start
		} else if (!strcmp(val, "overlord")) {
			state = DiplomacyOverlord;
		} else if (!strcmp(val, "vassal")) {
			state = DiplomacyVassal;
		//Wyrmgus end
		} else if (!strcmp(val, "crazy")) {
			state = DiplomacyCrazy;
		} else {
			DebugPrint("Invalid diplomacy command: %s" _C_ val);
			state = -1;
		}
		SendCommandDiplomacy(arg1, state, arg2);
	} else if (!strcmp(action, "shared-vision")) {
		bool state;
		state = atoi(val) ? true : false;
		SendCommandSharedVision(arg1, state, arg2);
	} else if (!strcmp(action, "input")) {
		if (val[0] == '-') {
			CclCommand(val + 1, false);
		} else {
			HandleCheats(val);
		}
	} else if (!strcmp(action, "chat")) {
		SetMessage("%s", val);
		PlayGameSound(GameSounds.ChatMessage.Sound, MaxSampleVolume);
	} else if (!strcmp(action, "quit")) {
		CommandQuit(arg1);
	} else {
		DebugPrint("Invalid action: %s" _C_ action);
	}

	ReplayStep = ReplayStep->Next;
	NextLogCycle = ReplayStep ? (unsigned)ReplayStep->GameCycle : ~0UL;
}
Beispiel #5
0
bool CDebuggerWin::ExecCommand(char *linetext) 
{
	char emptystring[]=" ";
	char tmptext[MAX_LINE_SIZE+1];
	char *arglist[MAX_COMMAND_ARGS+1];
	int argcount=0,loop=0;
	bool cmd_ok=TRUE;

	enum {
		COMMAND_QUIT,
		COMMAND_RUN,
		COMMAND_STOP,
		COMMAND_STEP,
		COMMAND_BPOINT,
		COMMAND_BPOINTC,
		COMMAND_RESET,
		COMMAND_REGISTERS,
		COMMAND_MEM_SET,
		COMMAND_MEM_DUMP,
		COMMAND_MEM_LOAD,
		COMMAND_MEM_SAVE,
		COMMAND_CART_SET,
		COMMAND_CART_DUMP,
		COMMAND_CART_LOAD,
		COMMAND_CART_SAVE,
		COMMAND_HELP,
		COMMAND_SCRIPT,
		COMMAND_SEARCH,
		COMMAND_REM,
		COMMAND_EXECUTE,
		COMMAND_LOG,
		COMMAND_UNKNOWN
	};

	const struct command_list commands[]=
	{
		{ COMMAND_QUIT,      "QUIT"  ,"QUIT                           - Immediate exit from the emulator back to windows"        ,"" },
		{ COMMAND_RUN,       "RUN"   ,"RUN [xxxx]                     - Run from xxxx (optional)"                                ,"Usage: RUN [addr]" },
		{ COMMAND_STOP,      "STOP"  ,"STOP                           - Halt CPU"                                                ,"" },
		{ COMMAND_STEP,	     "STEP"  ,"STEP [xxxx]                    - Single Step the CPU from addr xxxx (optional)"           ,"" },
		{ COMMAND_SCRIPT,    "SCRIPT","SCRIPT <file>                  - Run a script file"                                       ,"Usage: SCRIPT <file>" },
		{ COMMAND_BPOINT,    "BP"    ,"BP [n] [xxxx]/CLR              - Set/List/Clear breakpoint n to xxxx"                     ,"Usage: BP [n] [xxxx]/CLR" },
		{ COMMAND_RESET,     "RESET" ,"RESET                          - Reset CPU, also halts"                                   ,"" },
		{ COMMAND_REGISTERS, "REG"   ,"REG [PC/SP/PS/X/Y/A] [Value]   - Display/Set registers"                                   ,"Usage: REG [PC/SP/PS/X/Y/A] [Value]" },

		{ COMMAND_MEM_SET,   "MS"    ,"MS <xxxx> <aa> [bb]..[ff]      - Set RAM xxxx to aa.bb,cc,etc"                            ,"Usage: MS <xxxx> <aa> [bb]..[ff]" },
		{ COMMAND_MEM_DUMP,  "MD"    ,"MD [xxxx] [yyyy]               - Dump RAM from xxxx to yyyy"                              ,"Usage: MD <xxxx> [yyyy]" },
		{ COMMAND_MEM_LOAD,  "MLOAD" ,"MLOAD <xxxx> <file>            - Load RAM from file starting at xxxx"                     ,"Usage: MLOAD <xxxx> <file>" },
		{ COMMAND_MEM_SAVE,  "MSAVE" ,"MSAVE <xxxx> <yyyy> <file>     - Save RAM to file from xxxx-yyyy"                         ,"Usage: MSAVE <xxxx> <yyyy> <file>" },
		{ COMMAND_SEARCH,    "MSRCH" ,"MSRCH <xxxx> <yyyy> \"param\"    - Search RAM for string"                                 ,"Usage: MSRCH <xxxx> <yyyy> \"param\"\\<aa bb cc ...>" },
		{ COMMAND_SEARCH,    "MSRCH" ,"MSRCH <xxxx> <yyyy> <aa bb ..> - Search RAM for bytes"                                    ,"Usage: MSRCH <xxxx> <yyyy> \"param\"\\<aa bb cc ...>" },

		{ COMMAND_CART_SET,  "CS"    ,"CS <xxxx> <aa> [bb]..[ff]      - Set cartridge memory xxxx to aa.bb,cc,etc"               ,"Usage: CS <xxxx> <aa> [bb]..[ff]" },
		{ COMMAND_CART_DUMP, "CD"    ,"CD [xxxxxx] [yyyyyy]           - Dump cartridge memory from xxxxxx to yyyyyy"             ,"Usage: CD <xxxxxx> [yyyyyy]" },
		{ COMMAND_CART_LOAD, "CLOAD" ,"CLOAD <xxxxxx> <file>          - Load cartridge from file starting at xxxxxx"             ,"Usage: CLOAD <xxxxxx> <file>" },
		{ COMMAND_CART_SAVE, "CSAVE" ,"CSAVE <xxxxxx> <yyyyyy> <file> - Save cartridge to file from xxxxxx-yyyyyy"               ,"Usage: CSAVE <xxxxxx> <yyyyyy> <file>" },
		{ COMMAND_SEARCH,    "CSRCH" ,"CSRCH <xxxx> <yyyy> \"param\"    - Search cartridge for string"                           ,"Usage: CSRCH <xxxx> <yyyy> \"param\"\\<aa bb cc ...>" },
		{ COMMAND_SEARCH,    "CSRCH" ,"CSRCH <xxxx> <yyyy> <aa bb ..> - Search cartridge for bytes"                              ,"Usage: CSRCH <xxxx> <yyyy> \"param\"\\<aa bb cc ...>" },

		{ COMMAND_REM,       "REM"   ,"REM - Some comments            - Script Remark/Comments, will be ignored "                ,"" },
		{ COMMAND_EXECUTE,   "EXEC"  ,"EXEC ....                      - Execute/Spawn external command"                          ,"Usage: EXEC (args....)" },
		{ COMMAND_LOG,       "LOG"   ,"LOG [filename] ....            - Log all output to a file"                                ,"Usage: LOG [filename]" },
		{ COMMAND_HELP,      "HELP"  ,"HELP                           - Prints this text"                                        ,"" },
		{ COMMAND_UNKNOWN,   ""      ,""                                                                                         ,"" }
	};

	// Dump back to the edit window
	strcpy(tmptext,">");
	strncat(tmptext,linetext,MAX_LINE_SIZE-1);
	tmptext[MAX_LINE_SIZE]=0;
	LineOutput(tmptext);

	// Splat remaining arg array to null
	for(loop=0;loop<MAX_COMMAND_ARGS;loop++) arglist[loop]=&emptystring[0];
	arglist[MAX_COMMAND_ARGS]=NULL;

	loop=0;
	// Put all to upper case
	while(linetext[loop]!=0x00)
	{
		linetext[loop]=toupper(linetext[loop]);
		loop++;
	}

	if((arglist[0]=Tokenize(linetext))!=NULL)
	{
		argcount++;
		while(argcount<MAX_COMMAND_ARGS)
		{
			if((arglist[argcount]=Tokenize(NULL))==NULL)
			{
				// Fix up the null string on the end
				arglist[argcount]=emptystring;
				break;
			}
			argcount++;
		}
	}

	// Process into argc/argv
	if(argcount)
	{
		loop=0;
		for(;;)
		{
			// Check for the end of the list
			if(strcmp(commands[loop].command,"")==0) break;
			// Check our command
			if(strcmp(commands[loop].command,arglist[0])==0) break;
			loop++;
		}


		switch(commands[loop].command_id)
		{
			case COMMAND_REM:
				cmd_ok=TRUE;
				break;
			case COMMAND_QUIT:
				cmd_ok=CommandQuit(argcount,arglist);
				break;
			case COMMAND_RUN:
				cmd_ok=CommandRun(argcount,arglist);
				break;
			case COMMAND_STOP:
				cmd_ok=CommandStop(argcount,arglist);
				break;
			case COMMAND_STEP:
				cmd_ok=CommandStep(argcount,arglist);
				break;
			case COMMAND_BPOINT:
				cmd_ok=CommandBpoint(argcount,arglist);
				break;
			case COMMAND_SCRIPT:
				cmd_ok=CommandScript(argcount,arglist);
				break;
			case COMMAND_SEARCH:
				cmd_ok=CommandSearch(argcount,arglist);
				break;
			case COMMAND_RESET:
				cmd_ok=CommandReset(argcount,arglist);
				break;
			case COMMAND_REGISTERS:
				cmd_ok=CommandRegisters(argcount,arglist);
				break;
			case COMMAND_MEM_SET:
				cmd_ok=CommandMemSet(argcount,arglist);
				break;
			case COMMAND_MEM_DUMP:
				cmd_ok=CommandMemDump(argcount,arglist);
				break;
			case COMMAND_MEM_LOAD:
				cmd_ok=CommandMemLoad(argcount,arglist);
				break;
			case COMMAND_MEM_SAVE:
				cmd_ok=CommandMemSave(argcount,arglist);
				break;
			case COMMAND_CART_SET:
				cmd_ok=CommandCartSet(argcount,arglist);
				break;
			case COMMAND_CART_DUMP:
				cmd_ok=CommandCartDump(argcount,arglist);
				break;
			case COMMAND_CART_LOAD:
				cmd_ok=CommandCartLoad(argcount,arglist);
				break;
			case COMMAND_CART_SAVE:
				cmd_ok=CommandCartSave(argcount,arglist);
				break;
			case COMMAND_EXECUTE:
				cmd_ok=CommandExecute(argcount,arglist);
				break;
			case COMMAND_LOG:
				cmd_ok=CommandLog(argcount,arglist);
				break;
			case COMMAND_HELP:
				{
					int loop=0;
					LineOutput("Supported Command Line Functions are:");
					do
					{
						if(strcmp(commands[loop].help,"")!=0) LineOutput(commands[loop].help);
						loop++;
					}
					while(commands[loop].command_id!=COMMAND_UNKNOWN);
					LineOutput("  ( <xx> - Mandatory agrument, [xx] - Optional argument )");
					LineOutput("");
					cmd_ok=TRUE;
				}
				break;
			default:
			case COMMAND_UNKNOWN:
				cmd_ok=CommandNotFound(argcount,arglist);
				break;
		}

		// Redraw all debug windows incase global data change
		AfxGetMainWnd()->PostMessage(WM_COMMAND,IDM_DRAW_DEBUG_WINDOWS);

		if(cmd_ok)	
		{
			// Clear the command line
			mpEditLine->SetWindowText("");
		}
		else
		{
			// Provide usage text if available
			if(strcmp(commands[loop].help,"")!=0) LineOutput(commands[loop].usage);
		}
	}
	return cmd_ok;
}
/**
 * Call with the port number as the only argument.
 * Never terminates (other than by signals, such as CTRL-C).
 */
int
main (int argc, char *const *argv)
{
#ifdef TEST
	unsigned char buf[65];
	int GetBufferName(unsigned char *buf);
	int j;
	for ( j=0; j<20; ++j )
	{
	GetBufferName(buf);
	int i;
	for ( i=0; i<20; ++i )
		fprintf(stdout, " %d", buf[i]);
	fprintf(stdout, "\n");
	
#else
  struct MHD_Daemon *d;
  struct timeval tv;
  struct timeval *tvp;
  fd_set rs;
  fd_set ws;
  fd_set es;
  MHD_socket max;
  MHD_UNSIGNED_LONG_LONG mhd_timeout;
  int	 Port;

  if (argc != 2)
	  // No port supplied by command line: default it to 80
	  Port = 80;
  else
	  Port = atoi (argv[1]);
 	
  //MySQLInit();
	
  if ( hid_init() )
	return 1;
  CommandInit();
  // Emulate a Recognize command here
  CmdRecognize();
  
  /* initialize PRNG */
  srand ((unsigned int) time (NULL));
  d = MHD_start_daemon (MHD_USE_DEBUG,
                        Port,
                        NULL, NULL,
			&create_response, NULL,
			MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15,
			MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL,
			MHD_OPTION_END);
  if (NULL == d)
    return 1;
  printf("HIDWebServer is listening on port %d\n", Port);
  while (1)
    {
      expire_sessions ();
      max = 0;
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
	break; /* fatal internal error */
      if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)
	{
	  tv.tv_sec = mhd_timeout / 1000;
	  tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
	  tvp = &tv;
	}
      else
	tvp = NULL;
      select (max + 1, &rs, &ws, &es, tvp);
      MHD_run (d);
    }
  MHD_stop_daemon (d);
  CommandQuit();
  hid_exit();
  return 0;
#endif
}