diff --git a/src/drivers/win/basicbot.cpp b/src/drivers/win/basicbot.cpp index 8c4750f2..6b84d901 100644 --- a/src/drivers/win/basicbot.cpp +++ b/src/drivers/win/basicbot.cpp @@ -37,7 +37,7 @@ // go up each time something is released to the public, so you'll // know your version is the latest or whatever. Version will be // put in the project as well. -static char BBversion[] = "0.2.2"; +static char BBversion[] = "0.2.2b"; static HWND hwndBasicBot = 0; // qfox: GUI handle static bool BotRunning = false; // qfox: Is the bot computing or not? I think... @@ -45,8 +45,8 @@ static bool BotRunning = false; // qfox: Is the bot computing or not? I think. static uint32 rand1=1, rand2=0x1337EA75, rand3=0x0BADF00D; #define BOT_MAXCODE 1024 // qfox: max length of code, 1kb may be too little... -#define BOT_FORMULAS 21 -static char Formula[BOT_FORMULAS][BOT_MAXCODE]; // qfox: These hold the 21 formula's entered in the GUI: +#define BOT_FORMULAS 27 // qfox: number of code fields in the array +static char Formula[BOT_FORMULAS][BOT_MAXCODE]; // qfox: These hold the BOT_FORMULAS formula's entered in the GUI: static int CODE_1_A = 0, CODE_1_B = 1, CODE_1_SELECT = 2, @@ -67,9 +67,13 @@ static int CODE_1_A = 0, CODE_MAX = 17, CODE_TIE1 = 18, CODE_TIE2 = 19, - CODE_TIE3 = 20; -static char ExtraCode[BOT_MAXCODE]; // qfox: Contains the extra code, executed after dealing - // with input. + CODE_TIE3 = 20, + CODE_X = 21, + CODE_Y = 22, + CODE_Z = 23, + CODE_P = 24, + CODE_Q = 25, + CODE_EXTRA = 26; #define BOT_MAXCOUNTERS 256 static int BotCounter[BOT_MAXCOUNTERS]; // qfox: The counters. All ints, maybe change this to @@ -1285,7 +1289,7 @@ void UpdateBasicBot() } // luke: Run extra commands - EvaluateFormula(ExtraCode); + EvaluateFormula(Formula[CODE_EXTRA]); // qfox: remember the buttons pressed in this frame LastButtonPressed = BotInput[1]; } @@ -1355,7 +1359,7 @@ void CheckCode() EvaluateFormula(Formula[i]); } debugS("Error at extra code"); - EvaluateFormula(ExtraCode); + EvaluateFormula(Formula[CODE_EXTRA]); if (!EvaluateError) { debugS("Code syntax ok!"); @@ -1383,8 +1387,6 @@ static void SaveBasicBot() ofn.lpstrInitialDir=BasicBotDir; if(GetSaveFileName(&ofn)) { - int i,j; - //Save the directory if(ofn.nFileOffset < 1024) { @@ -1394,7 +1396,8 @@ static void SaveBasicBot() BasicBotDir[ofn.nFileOffset]=0; } - //quick get length of nameo + int i; + //luke: quick get length of nameo for(i=0;i<2048;i++) { if(nameo[i] == 0) @@ -1403,7 +1406,7 @@ static void SaveBasicBot() } } - //add .bot if nameo doesn't have it + //luke: add .bot if fn doesn't have it if((i < 4 || nameo[i-4] != '.') && i < 2040) { nameo[i] = '.'; @@ -1412,8 +1415,18 @@ static void SaveBasicBot() nameo[i+3] = 't'; nameo[i+4] = 0; } - - FILE *fp=FCEUD_UTF8fopen(nameo,"wb"); + SaveBasicBotFile(nameo); + } +} +/** + * qfox: save to supplied filename + */ +static void SaveBasicBotFile(char fn[]) +{ + FILE *fp=FCEUD_UTF8fopen(fn,"wb"); + if (fp != NULL) + { + int i,j; fputc('b',fp); fputc('o',fp); fputc('t',fp); @@ -1425,14 +1438,9 @@ static void SaveBasicBot() fputc(Formula[i][j],fp); } } - for(j=0;j will have to figure out the load/save part first. // todo: why the hell is this event not firing? CheckDlgButton(hwndBasicBot, GUI_BOT_P1, 0); // select the player1 radiobutton + LoadBasicBotFile("default.bot"); + ToGUI(); + // test echo, to botmode toggle button, doesnt work + SetDlgItemText(hwndBasicBot,GUI_BOT_BOTMODE,"hello"); break; case WM_CLOSE: case WM_QUIT: - // todo: save last used settings - // qfox: before closing, it quickly copies the contents to the variables... for some reason. FromGUI(); + SaveBasicBotFile("default.bot"); DestroyWindow(hwndBasicBot); hwndBasicBot=0; break; @@ -1717,9 +1746,6 @@ static BOOL CALLBACK BasicBotCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA } break; case GUI_BOT_CLOSE: - FromGUI(); // qfox: might tear this out later. seems a little pointless. - DestroyWindow(hwndBasicBot); - hwndBasicBot=0; break; case GUI_BOT_BOTMODE: // qfox: toggle external input mode @@ -1740,6 +1766,11 @@ static BOOL CALLBACK BasicBotCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA // qfox: the small update button above the static variables ("U"), // only update the statics. UpdateStatics(); + break; + case GUI_BOT_TEST: + MessageBox(hwndBasicBot, "Showing", "Hrm", MB_OK); + SetDlgItemText(hwndBasicBot,GUI_BOT_BOTMODE,"hello"); + break; default: break; } @@ -1781,7 +1812,6 @@ void CreateBasicBot() hwndBasicBot=CreateDialog(fceu_hInstance,"BASICBOT",NULL,BasicBotCallB); EditPlayerOne = true; BotRunning = false; - ToGUI(); } } diff --git a/src/drivers/win/basicbot.h b/src/drivers/win/basicbot.h index 942c3452..613cb582 100644 --- a/src/drivers/win/basicbot.h +++ b/src/drivers/win/basicbot.h @@ -13,4 +13,8 @@ static void FromGUI(); static void UpdateStatics(); void UpdateExternalButton(); + static void LoadBasicBotFile(char fn[]); + static void LoadBasicBot(); + static void SaveBasicBotFile(char fn[]); + static void SaveBasicBot(); #endif // _BASICBOT_H_ diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index e4382a8e..5201c1c3 100644 Binary files a/src/drivers/win/res.rc and b/src/drivers/win/res.rc differ diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 285df309..3f85611c 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -5,10 +5,15 @@ #define GUI_BOT_CLOSE 1 #define IDI_ICON1 101 #define IDI_ICON2 102 +#define GUI_BOT_END 1009 #define GUI_BOT_X 1010 +#define GUI_BOT_TIE1 1011 +#define GUI_BOT_TIE2 1012 +#define GUI_BOT_TIE3 1013 #define GUI_BOT_SAVE 1014 #define GUI_BOT_LOAD 1015 #define GUI_BOT_RUN 1016 +#define GUI_BOT_MAX 1017 #define GUI_BOT_Y 1018 #define GUI_BOT_KEYS 1019 #define GUI_BOT_EXTRA 1020 @@ -19,6 +24,7 @@ #define GUI_BOT_BOTMODE 1025 #define GUI_BOT_P 1026 #define GUI_BOT_Q 1027 +#define GUI_BOT_TEST 1028 #define GUI_BOT_P1 1035 #define GUI_BOT_CLEAR 1036 #define GUI_BOT_ATTEMPTS 1037