From 9bd855397649d40240f428d2a9c39e8aee3d0cf3 Mon Sep 17 00:00:00 2001 From: qfox Date: Tue, 22 Jul 2008 20:17:43 +0000 Subject: [PATCH] New BasicBot works, but very very basic (only numbers). --- src/drivers/win/basicbot.cpp | 14 ++-- src/drivers/win/basicbot2.cpp | 145 +++++++++++++++++++++++++++++++--- src/drivers/win/basicbot2.h | 8 +- src/drivers/win/main.cpp | 34 +++++--- src/drivers/win/res.rc | 81 ++++++++++--------- src/drivers/win/resource.h | 55 +++++++------ src/drivers/win/window.cpp | 11 ++- src/fceu.cpp | 4 +- src/input.cpp | 15 ++-- src/input.h | 9 ++- src/state.cpp | 2 +- 11 files changed, 277 insertions(+), 101 deletions(-) diff --git a/src/drivers/win/basicbot.cpp b/src/drivers/win/basicbot.cpp index 7ca4d6ff..88730266 100644 --- a/src/drivers/win/basicbot.cpp +++ b/src/drivers/win/basicbot.cpp @@ -34,7 +34,7 @@ #include "common.h" #include "../../fceu.h" //mbg merge 7/18/06 added #include "basicbot.h" -#include "../../input.h" // qfox: fceu_botmode() fceu_setbotmode() +#include "../../input.h" // qfox: fceu_botmode() fceu_setbotmode() BOTMODES // Cleanup: static function declarations moved here static void BotSyntaxError(int errorcode); @@ -1727,6 +1727,7 @@ static void DebugByteCode(int code[]) **/ void UpdateBasicBot() { + if (FCEU_BotMode() != BOTMODE_OLDBOT) return; // If there is any input on the buffer, dont update yet. // [0] means the number of inputs left on the BotInput buffer if(BotInput[0]) @@ -2238,7 +2239,7 @@ static void StartBasicBot() { // show message debugS("Running!"); - FCEU_SetBotMode(1); + FCEU_SetBotMode(BOTMODE_OLDBOT); BotRunning = true; EvaluateError = false; FromGUI(); @@ -2262,7 +2263,6 @@ static void StartBasicBot() **/ static void StopBasicBot() { - //FCEU_SetBotMode(0); BotRunning = false; BotAttempts = 0; BotFrames = 0; @@ -2271,7 +2271,7 @@ static void StopBasicBot() BotBestScore[0] = BotBestScore[1] = BotBestScore[2] = BotBestScore[3] = -999999999; NewAttempt = true; SetDlgItemText(hwndBasicBot,GUI_BOT_RUN,"Run!"); - FCEU_SetBotMode(0); + FCEU_SetBotMode(BOTMODE_OFF); FCEUI_FrameAdvanceEnd(); } @@ -2458,7 +2458,7 @@ static BOOL CALLBACK BasicBotCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA p1 = true; case GUI_BOT_EXTERNAL: // set the botmode - FCEU_SetBotMode(p1?0:1); + FCEU_SetBotMode(p1?BOTMODE_OFF:BOTMODE_OLDBOT); break; case GUI_BOT_SAVE: FromGUI(); @@ -2592,7 +2592,7 @@ void CreateBasicBot() */ void InitCode() { - CheckDlgButton(hwndBasicBot, FCEU_BotMode() ? GUI_BOT_EXTERNAL : GUI_BOT_INTERNAL, 1); // select the player1 radiobutton + CheckDlgButton(hwndBasicBot, FCEU_BotMode() == BOTMODE_OLDBOT ? GUI_BOT_EXTERNAL : GUI_BOT_INTERNAL, 1); // select the player1 radiobutton //if (LoadBasicBotFile("default.bot")) if (false) { @@ -2630,7 +2630,7 @@ void UpdateExternalButton() { if (hwndBasicBot) { - if (FCEU_BotMode()) + if (FCEU_BotMode() == BOTMODE_OLDBOT) { CheckDlgButton(hwndBasicBot, GUI_BOT_INTERNAL, 0); CheckDlgButton(hwndBasicBot, GUI_BOT_EXTERNAL, 1); diff --git a/src/drivers/win/basicbot2.cpp b/src/drivers/win/basicbot2.cpp index 5c3b1fc8..3a390000 100644 --- a/src/drivers/win/basicbot2.cpp +++ b/src/drivers/win/basicbot2.cpp @@ -1,10 +1,36 @@ #include "common.h" -#include "../../fceu.h" //mbg merge 7/18/06 added +#include "../../fceu.h" // BotInput #include "basicbot2.h" -#include "../../input.h" // qfox: fceu_botmode() fceu_setbotmode() +#include "../../input.h" // fceu_botmode() fceu_setbotmode() BOTMODES +#include // random seed -// static variables and functions are only used in this file +// Static variables and functions are only used in this file static HWND hwndBasicBot = 0; // GUI handle +static char * inputStrings[16]; // from gui +static int inputNumbers[16]; // temp: the values +static char * romString; +static char * commentString; +static char * scoreString[3][2]; // score[n][title/value] + +// put all the inputs into an array for easy iterative access (indices are synced with inputStrings) +static int inputs[] = { + BOT_TF_A_1, + BOT_TF_B_1, + BOT_TF_SELECT_1, + BOT_TF_START_1, + BOT_TF_UP_1, + BOT_TF_DOWN_1, + BOT_TF_LEFT_1, + BOT_TF_RIGHT_1, + BOT_TF_A_2, + BOT_TF_B_2, + BOT_TF_SELECT_2, + BOT_TF_START_2, + BOT_TF_UP_2, + BOT_TF_DOWN_2, + BOT_TF_LEFT_2, + BOT_TF_RIGHT_2 +}; void BotCreateBasicBot() { if(hwndBasicBot) { @@ -20,8 +46,19 @@ void BotCreateBasicBot() { HMENU hmenu = LoadMenu(fceu_hInstance,"BASICBOTMENU"); // add menu to window SetMenu(hwndBasicBot, hmenu); + // initialize the random generator + srand( (unsigned)time( NULL ) ); } + FCEU_SetBotMode(BOTMODE_NEWBOT); } +static void BotCloseWindow() { + if (hwndBasicBot) { + DestroyWindow(hwndBasicBot); + hwndBasicBot = 0; + } + FCEU_SetBotMode(BOTMODE_OFF); +} + static BOOL CALLBACK WindowCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { @@ -55,10 +92,22 @@ static BOOL CALLBACK WindowCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR { case BN_CLICKED: // mouse click on item in gui { - break; - } - case GUI_BOT_TEST: - { + switch(LOWORD(wParam)) + { + case BOT_BUTTON_UPDATE: + { + GetAllInputs(); + break; + } + case BOT_BUTTON_RUN: + { + break; + } + case BOT_BUTTON_TEST: + { + break; + } + } break; } default: @@ -72,10 +121,84 @@ static BOOL CALLBACK WindowCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR return 0; } -static void BotCloseWindow() { - if (hwndBasicBot) { - DestroyWindow(hwndBasicBot); - hwndBasicBot = 0; +// Called from main emulator loop +void BasicBotGetInput() { + printf("yes?"); + if (FCEU_BotMode() != BOTMODE_NEWBOT) { + printf(" no...\n"); + return; } + BotInput[0] = 1; // number of frames on the buffer (starts at BotInput[1]) + BotInput[1] = 0; // reset first (and only) frame + for (int i=0;i<16;i++) { + if ((int)(((double)rand()/(double)RAND_MAX)*1000) < inputNumbers[i]) { + // Button flags: + // button - player 1 - player 2 + // A 1 9 + // B 2 10 + // select 3 11 + // start 4 12 + // up 5 13 + // down 6 14 + // left 7 15 + // right 8 16 + // The input code will read the value of BotInput[1] + // If flag 17 is set, it will load a savestate, else + // it takes this input and puts the lower byte in 1 + // and the upper byte in 2. + BotInput[1] |= 1 << i; + } + } + printf(" yes! %d\n", BotInput[1]); +} + + +/** + * Get the length of a textfield ("edit control") or textarea + * It's more of a macro really. + * Returns 0 when an error occurs, the length of current + * contents in any other case (check LastError in case of 0) + */ +static unsigned int FieldLength(HWND winhandle,int controlid) { + HWND hwndItem = GetDlgItem(winhandle,controlid); + return SendMessage(hwndItem,WM_GETTEXTLENGTH,0,0); +} + +/** + * wrapper functions + **/ +static char * GetText(int controlid) { + unsigned int count = FieldLength(hwndBasicBot,controlid); + char *t = new char[count+1]; + GetDlgItemTextA(hwndBasicBot,controlid,t,count+1); + return t; +} +static UINT GetInt(int controlid) { + BOOL * x = new BOOL(); + return GetDlgItemInt(hwndBasicBot,controlid, x, true); +} +static void SetInt(int controlid, int value) { + SetDlgItemInt(hwndBasicBot, controlid, value, true); +} +static void SetText(int controlid, char * str) { + SetDlgItemTextA(hwndBasicBot, controlid, str); +} + +// get data from all the inputs from the gui and store it +static void GetAllInputs() { + // for all 8 buttons, twice + for (int i=0; i<16; ++i) { + inputStrings[i] = GetText(inputs[i]); + inputNumbers[i] = GetInt(inputs[i]); + SetInt(inputs[i], inputNumbers[i]); + } + romString = GetText(BOT_TF_ROM); + commentString = GetText(BOT_TF_COMMENT); + scoreString[0][0] = GetText(BOT_TF_SCORE1_DESC); + scoreString[0][1] = GetText(BOT_TF_SCORE1_VALUE); + scoreString[1][0] = GetText(BOT_TF_SCORE2_DESC); + scoreString[1][1] = GetText(BOT_TF_SCORE2_VALUE); + scoreString[2][0] = GetText(BOT_TF_SCORE3_DESC); + scoreString[2][1] = GetText(BOT_TF_SCORE3_VALUE); } diff --git a/src/drivers/win/basicbot2.h b/src/drivers/win/basicbot2.h index 19528275..93a0269a 100644 --- a/src/drivers/win/basicbot2.h +++ b/src/drivers/win/basicbot2.h @@ -1,6 +1,12 @@ #ifndef _BASICBOT2_H_ #define _BASICBOT2_H_ + // statics are only used in this file void BotCreateBasicBot(); static BOOL CALLBACK WindowCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - void BotCloseWindow(); + static void BotCloseWindow(); + void BasicBotGetInput(); + static unsigned int FieldLength(HWND winhandle,int controlid); + static char * GetText(int controlid); + static UINT GetInt(int controlid); + static void GetAllInputs(); #endif // _BASICBOT2_H_ \ No newline at end of file diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index f99a7d51..15b9de1d 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -455,6 +455,19 @@ static void DriverKill(void) #ifdef _USE_SHARED_MEMORY_ HANDLE mapGameMemBlock; HANDLE mapRAM; + +// qfox: about BotInput +// If in botmode, BasicBot will put the input in this variable. +// FCEU_UpdateBot() in input.cpp will then fill the controller +// inputs according to this variable. The layout is as follows: +// bit 0-7 = player 1 controller +// bits 8-15 = player 2 controller +// bit 17 = load savestate 1 if set +// Order of these buttons bitwise: +// A B SELECT START UP DOWN LEFT RIGHT +// TODO: fix a new variable to tell the function to load a save +// state to allow the bot to compute four players (since +// there's not enough space to do so now) uint32 *BotInput; void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM) @@ -685,19 +698,22 @@ doloopy: int32 ssize=0; ///contains sound samples count #ifdef _USE_SHARED_MEMORY_ - UpdateBasicBot(); + // press input like BasicBot tells you to + UpdateBasicBot(); // qfox: old bot + // same as above, for the new bot + BasicBotGetInput(); // qfox: new bot (uses same input variables and mechanism as old bot, for now) + FCEU_UpdateBot(); // qfox: shouldnt this be inside the sharedmemory ifdef?? (it is now, was below the endif) #endif - FCEU_UpdateBot(); FCEUI_Emulate(&gfx, &sound, &ssize, 0); //emulate a single frame FCEUD_Update(gfx, sound, ssize); //update displays and debug tools - //mbg 6/30/06 - close game if we were commanded to by calls nested in FCEUI_Emulate() - if(closeGame) - { + //mbg 6/30/06 - close game if we were commanded to by calls nested in FCEUI_Emulate() + if(closeGame) + { FCEUI_CloseGame(); GameInfo = 0; - } + } } //xbsave = NULL; @@ -734,7 +750,7 @@ doloopy: //if in bot mode, don't idle. eat the CPU up :) //mbg - why should we do this? does bot mode set the paused flag? that doesnt seem right... - if(!FCEU_BotMode()) + if(FCEU_BotMode() == BOTMODE_OFF) { int notAlternateThrottle = !(soundoptions&SO_OLDUP) && soundo && ((NoWaiting&1)?(256*16):fps_scale) >= 64; if(notAlternateThrottle) @@ -781,7 +797,7 @@ void _updateWindow() // Count = (Count<<8)/temp_fps_scale; // // //Disable sound and throttling for BotMode--we want max speed! -// if(FCEU_BotMode()) +// if(FCEU_BotMode() != BOTMODE_OFF) // { // if(XBuf && (skipcount >= 64)) // { @@ -990,7 +1006,7 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) { //mbg merge 7/19/06 - leaving this untouched but untested //its probably not optimal - if(FCEU_BotMode()) { + if(FCEU_BotMode() != BOTMODE_OFF) { //this counts the number of frames we've skipped blitting // qfox 09/17/06: for bot evaluation purposes, the number // of frames to be skipped is set from the diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 5143beae..44d42c4c 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -1484,48 +1484,51 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIB CAPTION "Dialog" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - EDITTEXT IDC_EDIT1,44,5,281,14,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT2,44,19,281,12,ES_AUTOHSCROLL + EDITTEXT BOT_TF_ROM,44,5,281,14,ES_AUTOHSCROLL | WS_DISABLED + EDITTEXT BOT_TF_COMMENT,44,19,281,12,ES_AUTOHSCROLL | WS_DISABLED LTEXT "Rom",IDC_STATIC,5,5,39,14,SS_CENTERIMAGE LTEXT "Comment",IDC_STATIC,5,19,39,13,SS_CENTERIMAGE - LTEXT "A",IDC_STATIC,5,44,40,13,SS_CENTERIMAGE - EDITTEXT IDC_EDIT3,45,44,136,13,ES_AUTOHSCROLL - LTEXT "B",IDC_STATIC,5,57,40,12,SS_CENTERIMAGE - EDITTEXT IDC_EDIT4,45,57,136,12,ES_AUTOHSCROLL - LTEXT "Start",IDC_STATIC,5,69,40,13,SS_CENTERIMAGE - EDITTEXT IDC_EDIT5,45,69,136,13,ES_AUTOHSCROLL - LTEXT "Select",IDC_STATIC,5,82,40,13,SS_CENTERIMAGE - EDITTEXT IDC_EDIT6,45,82,136,13,ES_AUTOHSCROLL - LTEXT "Up",IDC_STATIC,5,95,40,13,SS_CENTERIMAGE - EDITTEXT IDC_EDIT7,45,95,136,13,ES_AUTOHSCROLL - LTEXT "Down",IDC_STATIC,5,108,40,13,SS_CENTERIMAGE - EDITTEXT IDC_EDIT8,45,108,136,13,ES_AUTOHSCROLL - LTEXT "Left",IDC_STATIC,5,121,40,13,SS_CENTERIMAGE - EDITTEXT IDC_EDIT9,45,121,136,13,ES_AUTOHSCROLL - LTEXT "Right",IDC_STATIC,5,134,40,13,SS_CENTERIMAGE - EDITTEXT IDC_EDIT10,45,134,136,13,ES_AUTOHSCROLL - CTEXT "Player 1",IDC_STATIC,45,33,136,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT - EDITTEXT IDC_EDIT11,189,44,136,13,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT12,189,57,136,12,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT13,189,69,136,13,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT14,189,82,136,13,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT15,189,95,136,13,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT16,189,108,136,13,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT17,189,121,136,13,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT18,189,134,136,13,ES_AUTOHSCROLL - CTEXT "Player 2",IDC_STATIC,189,32,136,12,SS_CENTERIMAGE,WS_EX_TRANSPARENT - PUSHBUTTON "Run",IDC_BUTTON2,275,186,50,14 + PUSHBUTTON "Run",BOT_BUTTON_RUN,251,158,74,14,WS_DISABLED LTEXT "Score 1",IDC_STATIC,5,158,39,14,SS_CENTERIMAGE - EDITTEXT IDC_EDIT20,44,158,50,14,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT19,94,158,136,14,ES_AUTOHSCROLL + EDITTEXT BOT_TF_SCORE1_DESC,44,158,50,14,ES_AUTOHSCROLL | WS_DISABLED LTEXT "Score 2",IDC_STATIC,5,172,39,14,SS_CENTERIMAGE - EDITTEXT IDC_EDIT21,44,172,50,14,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT22,94,172,136,14,ES_AUTOHSCROLL + EDITTEXT BOT_TF_SCORE2_DESC,44,172,50,14,ES_AUTOHSCROLL | WS_DISABLED + EDITTEXT BOT_TF_SCORE2_VALUE,94,172,136,14,ES_AUTOHSCROLL | WS_DISABLED LTEXT "Score 3",IDC_STATIC,5,186,39,14,SS_CENTERIMAGE - EDITTEXT IDC_EDIT23,44,186,50,14,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT24,94,186,136,14,ES_AUTOHSCROLL + EDITTEXT BOT_TF_SCORE3_DESC,44,186,50,14,ES_AUTOHSCROLL | WS_DISABLED + EDITTEXT BOT_TF_SCORE3_VALUE,94,186,136,14,ES_AUTOHSCROLL | WS_DISABLED CTEXT "Description",IDC_STATIC,44,147,50,11,SS_CENTERIMAGE + EDITTEXT BOT_TF_SCORE1_VALUE,94,158,136,14,ES_AUTOHSCROLL | WS_DISABLED CTEXT "Condition",IDC_STATIC,94,147,135,11,SS_CENTERIMAGE + CTEXT "Player 1 input",IDC_STATIC,45,33,136,11,SS_CENTERIMAGE,WS_EX_TRANSPARENT + LTEXT "A",IDC_STATIC,5,44,40,13,SS_CENTERIMAGE + LTEXT "B",IDC_STATIC,5,57,40,12,SS_CENTERIMAGE + LTEXT "Select",IDC_STATIC,5,69,40,13,SS_CENTERIMAGE + LTEXT "Start",IDC_STATIC,5,82,40,13,SS_CENTERIMAGE + LTEXT "Up",IDC_STATIC,5,95,40,13,SS_CENTERIMAGE + LTEXT "Down",IDC_STATIC,5,108,40,13,SS_CENTERIMAGE + LTEXT "Left",IDC_STATIC,5,121,40,13,SS_CENTERIMAGE + LTEXT "Right",IDC_STATIC,5,134,40,13,SS_CENTERIMAGE + EDITTEXT BOT_TF_B_1,45,57,136,12,ES_AUTOHSCROLL + EDITTEXT BOT_TF_SELECT_1,45,69,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_START_1,45,82,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_UP_1,45,95,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_DOWN_1,45,108,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_LEFT_1,45,121,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_RIGHT_1,45,134,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_A_1,45,44,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_RIGHT_2,189,134,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_LEFT_2,189,121,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_DOWN_2,189,108,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_UP_2,189,95,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_START_2,189,82,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_SELECT_2,189,69,136,13,ES_AUTOHSCROLL + EDITTEXT BOT_TF_B_2,189,57,136,12,ES_AUTOHSCROLL + EDITTEXT BOT_TF_A_2,189,44,136,13,ES_AUTOHSCROLL + CTEXT "Player 2 input",IDC_STATIC,189,32,136,12,SS_CENTERIMAGE,WS_EX_TRANSPARENT + PUSHBUTTON "Update Inputs",BOT_BUTTON_UPDATE,251,186,74,14 + PUSHBUTTON "TEST",BOT_BUTTON_TEST,251,172,74,14,WS_DISABLED + CTEXT "Use only numbers for now, chance 0-1000",IDC_STATIC,89,19,185,12,SS_CENTERIMAGE END @@ -1679,6 +1682,7 @@ BEGIN VERTGUIDE, 181 VERTGUIDE, 189 VERTGUIDE, 229 + VERTGUIDE, 251 VERTGUIDE, 325 VERTGUIDE, 331 TOPMARGIN, 5 @@ -1697,7 +1701,7 @@ BEGIN HORZGUIDE, 158 HORZGUIDE, 172 HORZGUIDE, 186 - HORZGUIDE, 197 + HORZGUIDE, 200 END END #endif // APSTUDIO_INVOKED @@ -1831,6 +1835,11 @@ BEGIN END MENUITEM "Play Best", 0 MENUITEM "Reset", 0 + POPUP "Mode" + BEGIN + MENUITEM "Simple", ID_MODE_SIMPLE, CHECKED + MENUITEM "Advanced", ID_MODE_ADVANCED, INACTIVE + END END #endif // Dutch (Netherlands) resources diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index 1997c404..7627d8d0 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -461,30 +461,35 @@ #define IDC_BUTTON8 1146 #define IDC_EDIT1 1147 #define IDC_BUTTON9 1148 -#define IDC_EDIT2 1148 +#define BOT_TF_COMMENT 1148 #define IDC_LIST2 1149 -#define IDC_EDIT3 1149 -#define IDC_EDIT4 1150 -#define IDC_EDIT5 1152 -#define IDC_EDIT6 1153 -#define IDC_EDIT7 1154 -#define IDC_EDIT8 1156 -#define IDC_EDIT9 1157 -#define IDC_EDIT10 1158 -#define IDC_EDIT11 1160 -#define IDC_EDIT12 1161 -#define IDC_EDIT13 1162 -#define IDC_EDIT14 1163 -#define IDC_EDIT15 1164 -#define IDC_EDIT16 1165 -#define IDC_EDIT17 1166 -#define IDC_EDIT18 1167 -#define IDC_EDIT20 1169 -#define IDC_EDIT19 1176 -#define IDC_EDIT21 1181 -#define IDC_EDIT22 1182 -#define IDC_EDIT23 1183 +#define BOT_TF_A_1 1149 +#define BOT_TF_B_1 1150 +#define BOT_TF_SELECT_1 1152 +#define BOT_TF_START_1 1153 +#define BOT_TF_UP_1 1154 +#define BOT_TF_DOWN_1 1156 +#define BOT_TF_LEFT_1 1157 +#define BOT_TF_RIGHT_1 1158 +#define BOT_TF_A_2 1160 +#define BOT_TF_B_2 1161 +#define BOT_TF_SELECT_2 1162 +#define BOT_TF_START_2 1163 +#define BOT_TF_UP_2 1164 +#define BOT_TF_DOWN_2 1165 +#define BOT_TF_LEFT_2 1166 +#define BOT_TF_RIGHT_2 1167 +#define BOT_TF_SCORE1_DESC 1169 +#define BOT_BUTTON_UPDATE 1171 +#define BOT_BUTTON_RUN 1172 +#define BOT_BUTTON_TEST 1173 +#define BOT_TF_ROM 1174 +#define BOT_TF_SCORE1_VALUE 1176 +#define BOT_TF_SCORE2_DESC 1181 +#define BOT_TF_SCORE2_VALUE 1182 +#define BOT_TF_SCORE3_DESC 1183 #define IDC_EDIT24 1184 +#define BOT_TF_SCORE3_VALUE 1184 #define MENU_NETWORK 40040 #define MENU_PALETTE 40041 #define MENU_SOUND 40042 @@ -638,6 +643,8 @@ #define ID_FILE_CLEAR 40221 #define ID_FILE_LOAD 40222 #define ID_FILE_SAVE40223 40223 +#define ID_MODE_SIMPLE 40224 +#define ID_MODE_ADVANCED 40225 #define MW_ValueLabel2 65423 #define MW_ValueLabel1 65426 #define GUI_BOT_DEBUG 65436 @@ -648,8 +655,8 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 123 -#define _APS_NEXT_COMMAND_VALUE 40224 -#define _APS_NEXT_CONTROL_VALUE 1156 +#define _APS_NEXT_COMMAND_VALUE 40226 +#define _APS_NEXT_CONTROL_VALUE 1175 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index b9103ff4..020e6461 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -923,7 +923,16 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) break; case MENU_EXTERNAL_INPUT: - FCEU_SetBotMode(1^FCEU_BotMode()); + // qfox: TODO: this should be looked into. treat true external input as special versus the bot input + // right now it is compatible with the old mode, but pressing this menuoption will turn off + // the new bot if on... + FCEU_SetBotMode( + ( + (1^(FCEU_BotMode() == BOTMODE_OFF?0:1))==1? + BOTMODE_OLDBOT: + BOTMODE_OFF + ) + ); EnableExternalInput = EnableExternalInput?0:1; UpdateCheckedMenuItems(); break; break; diff --git a/src/fceu.cpp b/src/fceu.cpp index bda09134..fef25d32 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -534,7 +534,7 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski if(EmulationPaused&2) EmulationPaused &= ~1; // clear paused flag temporarily (frame advance) - else if((EmulationPaused&1) || FCEU_BotMode()) + else if((EmulationPaused&1) || FCEU_BotMode() != BOTMODE_OFF) { memcpy(XBuf, XBackBuf, 256*256); FCEU_PutImage(); @@ -545,7 +545,7 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski return; } - if(!FCEU_BotMode()) + if(FCEU_BotMode() == BOTMODE_OFF) { AutoFire(); UpdateAutosave(); diff --git a/src/input.cpp b/src/input.cpp index 6c1067d1..78f935e1 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -39,10 +39,10 @@ #include "fds.h" #include "driver.h" -// qfox: For UpdateExternalButton(), called when the -// botmode state changes, to update a label in gui. #ifdef WIN32 #include "drivers/win/main.h" +// qfox: For UpdateExternalButton(), called when the +// botmode state changes, to update a label in gui. #include "drivers/win/basicbot.h" #include "drivers/win/basicbot2.h" // qfox: new bot #include "drivers/win/memwatch.h" @@ -86,7 +86,8 @@ static uint8 joy_readbit[2]; uint8 joy[4]={0,0,0,0}; //HACK - should be static but movie needs it static uint8 LastStrobe; -static int BotMode = 0; +BOTMODES BotMode = BOTMODE_OFF; + #ifdef _USE_SHARED_MEMORY_ static uint32 BotPointer = 0; //mbg merge 7/18/06 changed to uint32 #endif @@ -268,12 +269,12 @@ static void StrobeGP(int w) static INPUTC GPC={ReadGP,0,StrobeGP,UpdateGP,0,0,LogGP,LoadGP}; static INPUTC GPCVS={ReadGPVS,0,StrobeGP,UpdateGP,0,0,LogGP,LoadGP}; -int FCEU_BotMode() +BOTMODES FCEU_BotMode() { return BotMode; } -void FCEU_SetBotMode(int x) +void FCEU_SetBotMode(BOTMODES x) { BotMode = x; #ifdef WIN32 @@ -294,7 +295,7 @@ void FCEU_UpdateBot() { #ifdef _USE_SHARED_MEMORY_ //This is the external input (aka bot) code - if(!BotMode) + if(BotMode == BOTMODE_OFF) return; if(BotInput[0]) { @@ -333,7 +334,7 @@ void FCEU_UpdateBot() void FCEU_UpdateInput(void) { //tell all drivers to poll input and set up their logical states - if(!FCEUMOV_Mode(MOVIEMODE_PLAY) && !BotMode) + if(!FCEUMOV_Mode(MOVIEMODE_PLAY) && BotMode == BOTMODE_OFF) { for(int port=0;port<2;port++) joyports[port].driver->Update(port,joyports[port].ptr,joyports[port].attrib); diff --git a/src/input.h b/src/input.h index 26bc3a99..8f3c60e0 100644 --- a/src/input.h +++ b/src/input.h @@ -89,10 +89,15 @@ extern struct FCPORT } portFC; +enum BOTMODES { + BOTMODE_OFF = 0, + BOTMODE_OLDBOT = 1, + BOTMODE_NEWBOT = 2 +}; +BOTMODES FCEU_BotMode(void); +void FCEU_SetBotMode(BOTMODES x); void FCEU_DrawInput(uint8 *buf); void FCEU_UpdateInput(void); -int FCEU_BotMode(void); -void FCEU_SetBotMode(int x); void InitializeInput(void); void FCEU_UpdateBot(void); extern void (*PStrobe[2])(void); diff --git a/src/state.cpp b/src/state.cpp index ec524dc6..951a850b 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -533,7 +533,7 @@ bool FCEUSS_Load(char *fname) //If in bot mode, don't do a backup when loading. //Otherwise you eat at the hard disk, since so many //states are being loaded. - if(FCEUSS_LoadFP(st,FCEU_BotMode()?SSLOADPARAM_NOBACKUP:SSLOADPARAM_BACKUP)) + if(FCEUSS_LoadFP(st,FCEU_BotMode() != BOTMODE_OFF?SSLOADPARAM_NOBACKUP:SSLOADPARAM_BACKUP)) { if(fname) {