New BasicBot works, but very very basic (only numbers).

This commit is contained in:
qfox 2008-07-22 20:17:43 +00:00
parent 34c60610ea
commit 9bd8553976
11 changed files with 277 additions and 101 deletions

View File

@ -34,7 +34,7 @@
#include "common.h" #include "common.h"
#include "../../fceu.h" //mbg merge 7/18/06 added #include "../../fceu.h" //mbg merge 7/18/06 added
#include "basicbot.h" #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 // Cleanup: static function declarations moved here
static void BotSyntaxError(int errorcode); static void BotSyntaxError(int errorcode);
@ -1727,6 +1727,7 @@ static void DebugByteCode(int code[])
**/ **/
void UpdateBasicBot() void UpdateBasicBot()
{ {
if (FCEU_BotMode() != BOTMODE_OLDBOT) return;
// If there is any input on the buffer, dont update yet. // If there is any input on the buffer, dont update yet.
// [0] means the number of inputs left on the BotInput buffer // [0] means the number of inputs left on the BotInput buffer
if(BotInput[0]) if(BotInput[0])
@ -2238,7 +2239,7 @@ static void StartBasicBot()
{ {
// show message // show message
debugS("Running!"); debugS("Running!");
FCEU_SetBotMode(1); FCEU_SetBotMode(BOTMODE_OLDBOT);
BotRunning = true; BotRunning = true;
EvaluateError = false; EvaluateError = false;
FromGUI(); FromGUI();
@ -2262,7 +2263,6 @@ static void StartBasicBot()
**/ **/
static void StopBasicBot() static void StopBasicBot()
{ {
//FCEU_SetBotMode(0);
BotRunning = false; BotRunning = false;
BotAttempts = 0; BotAttempts = 0;
BotFrames = 0; BotFrames = 0;
@ -2271,7 +2271,7 @@ static void StopBasicBot()
BotBestScore[0] = BotBestScore[1] = BotBestScore[2] = BotBestScore[3] = -999999999; BotBestScore[0] = BotBestScore[1] = BotBestScore[2] = BotBestScore[3] = -999999999;
NewAttempt = true; NewAttempt = true;
SetDlgItemText(hwndBasicBot,GUI_BOT_RUN,"Run!"); SetDlgItemText(hwndBasicBot,GUI_BOT_RUN,"Run!");
FCEU_SetBotMode(0); FCEU_SetBotMode(BOTMODE_OFF);
FCEUI_FrameAdvanceEnd(); FCEUI_FrameAdvanceEnd();
} }
@ -2458,7 +2458,7 @@ static BOOL CALLBACK BasicBotCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA
p1 = true; p1 = true;
case GUI_BOT_EXTERNAL: case GUI_BOT_EXTERNAL:
// set the botmode // set the botmode
FCEU_SetBotMode(p1?0:1); FCEU_SetBotMode(p1?BOTMODE_OFF:BOTMODE_OLDBOT);
break; break;
case GUI_BOT_SAVE: case GUI_BOT_SAVE:
FromGUI(); FromGUI();
@ -2592,7 +2592,7 @@ void CreateBasicBot()
*/ */
void InitCode() 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 (LoadBasicBotFile("default.bot"))
if (false) if (false)
{ {
@ -2630,7 +2630,7 @@ void UpdateExternalButton()
{ {
if (hwndBasicBot) if (hwndBasicBot)
{ {
if (FCEU_BotMode()) if (FCEU_BotMode() == BOTMODE_OLDBOT)
{ {
CheckDlgButton(hwndBasicBot, GUI_BOT_INTERNAL, 0); CheckDlgButton(hwndBasicBot, GUI_BOT_INTERNAL, 0);
CheckDlgButton(hwndBasicBot, GUI_BOT_EXTERNAL, 1); CheckDlgButton(hwndBasicBot, GUI_BOT_EXTERNAL, 1);

View File

@ -1,10 +1,36 @@
#include "common.h" #include "common.h"
#include "../../fceu.h" //mbg merge 7/18/06 added #include "../../fceu.h" // BotInput
#include "basicbot2.h" #include "basicbot2.h"
#include "../../input.h" // qfox: fceu_botmode() fceu_setbotmode() #include "../../input.h" // fceu_botmode() fceu_setbotmode() BOTMODES
#include <time.h> // 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 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() { void BotCreateBasicBot() {
if(hwndBasicBot) { if(hwndBasicBot) {
@ -20,8 +46,19 @@ void BotCreateBasicBot() {
HMENU hmenu = LoadMenu(fceu_hInstance,"BASICBOTMENU"); HMENU hmenu = LoadMenu(fceu_hInstance,"BASICBOTMENU");
// add menu to window // add menu to window
SetMenu(hwndBasicBot, hmenu); 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) { static BOOL CALLBACK WindowCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) { 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 case BN_CLICKED: // mouse click on item in gui
{ {
break; switch(LOWORD(wParam))
} {
case GUI_BOT_TEST: case BOT_BUTTON_UPDATE:
{ {
GetAllInputs();
break;
}
case BOT_BUTTON_RUN:
{
break;
}
case BOT_BUTTON_TEST:
{
break;
}
}
break; break;
} }
default: default:
@ -72,10 +121,84 @@ static BOOL CALLBACK WindowCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR
return 0; return 0;
} }
static void BotCloseWindow() { // Called from main emulator loop
if (hwndBasicBot) { void BasicBotGetInput() {
DestroyWindow(hwndBasicBot); printf("yes?");
hwndBasicBot = 0; 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);
} }

View File

@ -1,6 +1,12 @@
#ifndef _BASICBOT2_H_ #ifndef _BASICBOT2_H_
#define _BASICBOT2_H_ #define _BASICBOT2_H_
// statics are only used in this file
void BotCreateBasicBot(); void BotCreateBasicBot();
static BOOL CALLBACK WindowCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 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_ #endif // _BASICBOT2_H_

View File

@ -455,6 +455,19 @@ static void DriverKill(void)
#ifdef _USE_SHARED_MEMORY_ #ifdef _USE_SHARED_MEMORY_
HANDLE mapGameMemBlock; HANDLE mapGameMemBlock;
HANDLE mapRAM; 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; uint32 *BotInput;
void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM) void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM)
@ -685,19 +698,22 @@ doloopy:
int32 ssize=0; ///contains sound samples count int32 ssize=0; ///contains sound samples count
#ifdef _USE_SHARED_MEMORY_ #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 #endif
FCEU_UpdateBot();
FCEUI_Emulate(&gfx, &sound, &ssize, 0); //emulate a single frame FCEUI_Emulate(&gfx, &sound, &ssize, 0); //emulate a single frame
FCEUD_Update(gfx, sound, ssize); //update displays and debug tools 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() //mbg 6/30/06 - close game if we were commanded to by calls nested in FCEUI_Emulate()
if(closeGame) if(closeGame)
{ {
FCEUI_CloseGame(); FCEUI_CloseGame();
GameInfo = 0; GameInfo = 0;
} }
} }
//xbsave = NULL; //xbsave = NULL;
@ -734,7 +750,7 @@ doloopy:
//if in bot mode, don't idle. eat the CPU up :) //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... //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; int notAlternateThrottle = !(soundoptions&SO_OLDUP) && soundo && ((NoWaiting&1)?(256*16):fps_scale) >= 64;
if(notAlternateThrottle) if(notAlternateThrottle)
@ -781,7 +797,7 @@ void _updateWindow()
// Count = (Count<<8)/temp_fps_scale; // Count = (Count<<8)/temp_fps_scale;
// //
// //Disable sound and throttling for BotMode--we want max speed! // //Disable sound and throttling for BotMode--we want max speed!
// if(FCEU_BotMode()) // if(FCEU_BotMode() != BOTMODE_OFF)
// { // {
// if(XBuf && (skipcount >= 64)) // 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 //mbg merge 7/19/06 - leaving this untouched but untested
//its probably not optimal //its probably not optimal
if(FCEU_BotMode()) { if(FCEU_BotMode() != BOTMODE_OFF) {
//this counts the number of frames we've skipped blitting //this counts the number of frames we've skipped blitting
// qfox 09/17/06: for bot evaluation purposes, the number // qfox 09/17/06: for bot evaluation purposes, the number
// of frames to be skipped is set from the // of frames to be skipped is set from the

View File

@ -1484,48 +1484,51 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIB
CAPTION "Dialog" CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
EDITTEXT IDC_EDIT1,44,5,281,14,ES_AUTOHSCROLL EDITTEXT BOT_TF_ROM,44,5,281,14,ES_AUTOHSCROLL | WS_DISABLED
EDITTEXT IDC_EDIT2,44,19,281,12,ES_AUTOHSCROLL EDITTEXT BOT_TF_COMMENT,44,19,281,12,ES_AUTOHSCROLL | WS_DISABLED
LTEXT "Rom",IDC_STATIC,5,5,39,14,SS_CENTERIMAGE LTEXT "Rom",IDC_STATIC,5,5,39,14,SS_CENTERIMAGE
LTEXT "Comment",IDC_STATIC,5,19,39,13,SS_CENTERIMAGE LTEXT "Comment",IDC_STATIC,5,19,39,13,SS_CENTERIMAGE
LTEXT "A",IDC_STATIC,5,44,40,13,SS_CENTERIMAGE PUSHBUTTON "Run",BOT_BUTTON_RUN,251,158,74,14,WS_DISABLED
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
LTEXT "Score 1",IDC_STATIC,5,158,39,14,SS_CENTERIMAGE LTEXT "Score 1",IDC_STATIC,5,158,39,14,SS_CENTERIMAGE
EDITTEXT IDC_EDIT20,44,158,50,14,ES_AUTOHSCROLL EDITTEXT BOT_TF_SCORE1_DESC,44,158,50,14,ES_AUTOHSCROLL | WS_DISABLED
EDITTEXT IDC_EDIT19,94,158,136,14,ES_AUTOHSCROLL
LTEXT "Score 2",IDC_STATIC,5,172,39,14,SS_CENTERIMAGE LTEXT "Score 2",IDC_STATIC,5,172,39,14,SS_CENTERIMAGE
EDITTEXT IDC_EDIT21,44,172,50,14,ES_AUTOHSCROLL EDITTEXT BOT_TF_SCORE2_DESC,44,172,50,14,ES_AUTOHSCROLL | WS_DISABLED
EDITTEXT IDC_EDIT22,94,172,136,14,ES_AUTOHSCROLL EDITTEXT BOT_TF_SCORE2_VALUE,94,172,136,14,ES_AUTOHSCROLL | WS_DISABLED
LTEXT "Score 3",IDC_STATIC,5,186,39,14,SS_CENTERIMAGE LTEXT "Score 3",IDC_STATIC,5,186,39,14,SS_CENTERIMAGE
EDITTEXT IDC_EDIT23,44,186,50,14,ES_AUTOHSCROLL EDITTEXT BOT_TF_SCORE3_DESC,44,186,50,14,ES_AUTOHSCROLL | WS_DISABLED
EDITTEXT IDC_EDIT24,94,186,136,14,ES_AUTOHSCROLL EDITTEXT BOT_TF_SCORE3_VALUE,94,186,136,14,ES_AUTOHSCROLL | WS_DISABLED
CTEXT "Description",IDC_STATIC,44,147,50,11,SS_CENTERIMAGE 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 "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 END
@ -1679,6 +1682,7 @@ BEGIN
VERTGUIDE, 181 VERTGUIDE, 181
VERTGUIDE, 189 VERTGUIDE, 189
VERTGUIDE, 229 VERTGUIDE, 229
VERTGUIDE, 251
VERTGUIDE, 325 VERTGUIDE, 325
VERTGUIDE, 331 VERTGUIDE, 331
TOPMARGIN, 5 TOPMARGIN, 5
@ -1697,7 +1701,7 @@ BEGIN
HORZGUIDE, 158 HORZGUIDE, 158
HORZGUIDE, 172 HORZGUIDE, 172
HORZGUIDE, 186 HORZGUIDE, 186
HORZGUIDE, 197 HORZGUIDE, 200
END END
END END
#endif // APSTUDIO_INVOKED #endif // APSTUDIO_INVOKED
@ -1831,6 +1835,11 @@ BEGIN
END END
MENUITEM "Play Best", 0 MENUITEM "Play Best", 0
MENUITEM "Reset", 0 MENUITEM "Reset", 0
POPUP "Mode"
BEGIN
MENUITEM "Simple", ID_MODE_SIMPLE, CHECKED
MENUITEM "Advanced", ID_MODE_ADVANCED, INACTIVE
END
END END
#endif // Dutch (Netherlands) resources #endif // Dutch (Netherlands) resources

View File

@ -461,30 +461,35 @@
#define IDC_BUTTON8 1146 #define IDC_BUTTON8 1146
#define IDC_EDIT1 1147 #define IDC_EDIT1 1147
#define IDC_BUTTON9 1148 #define IDC_BUTTON9 1148
#define IDC_EDIT2 1148 #define BOT_TF_COMMENT 1148
#define IDC_LIST2 1149 #define IDC_LIST2 1149
#define IDC_EDIT3 1149 #define BOT_TF_A_1 1149
#define IDC_EDIT4 1150 #define BOT_TF_B_1 1150
#define IDC_EDIT5 1152 #define BOT_TF_SELECT_1 1152
#define IDC_EDIT6 1153 #define BOT_TF_START_1 1153
#define IDC_EDIT7 1154 #define BOT_TF_UP_1 1154
#define IDC_EDIT8 1156 #define BOT_TF_DOWN_1 1156
#define IDC_EDIT9 1157 #define BOT_TF_LEFT_1 1157
#define IDC_EDIT10 1158 #define BOT_TF_RIGHT_1 1158
#define IDC_EDIT11 1160 #define BOT_TF_A_2 1160
#define IDC_EDIT12 1161 #define BOT_TF_B_2 1161
#define IDC_EDIT13 1162 #define BOT_TF_SELECT_2 1162
#define IDC_EDIT14 1163 #define BOT_TF_START_2 1163
#define IDC_EDIT15 1164 #define BOT_TF_UP_2 1164
#define IDC_EDIT16 1165 #define BOT_TF_DOWN_2 1165
#define IDC_EDIT17 1166 #define BOT_TF_LEFT_2 1166
#define IDC_EDIT18 1167 #define BOT_TF_RIGHT_2 1167
#define IDC_EDIT20 1169 #define BOT_TF_SCORE1_DESC 1169
#define IDC_EDIT19 1176 #define BOT_BUTTON_UPDATE 1171
#define IDC_EDIT21 1181 #define BOT_BUTTON_RUN 1172
#define IDC_EDIT22 1182 #define BOT_BUTTON_TEST 1173
#define IDC_EDIT23 1183 #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 IDC_EDIT24 1184
#define BOT_TF_SCORE3_VALUE 1184
#define MENU_NETWORK 40040 #define MENU_NETWORK 40040
#define MENU_PALETTE 40041 #define MENU_PALETTE 40041
#define MENU_SOUND 40042 #define MENU_SOUND 40042
@ -638,6 +643,8 @@
#define ID_FILE_CLEAR 40221 #define ID_FILE_CLEAR 40221
#define ID_FILE_LOAD 40222 #define ID_FILE_LOAD 40222
#define ID_FILE_SAVE40223 40223 #define ID_FILE_SAVE40223 40223
#define ID_MODE_SIMPLE 40224
#define ID_MODE_ADVANCED 40225
#define MW_ValueLabel2 65423 #define MW_ValueLabel2 65423
#define MW_ValueLabel1 65426 #define MW_ValueLabel1 65426
#define GUI_BOT_DEBUG 65436 #define GUI_BOT_DEBUG 65436
@ -648,8 +655,8 @@
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 123 #define _APS_NEXT_RESOURCE_VALUE 123
#define _APS_NEXT_COMMAND_VALUE 40224 #define _APS_NEXT_COMMAND_VALUE 40226
#define _APS_NEXT_CONTROL_VALUE 1156 #define _APS_NEXT_CONTROL_VALUE 1175
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif

View File

@ -923,7 +923,16 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
break; break;
case MENU_EXTERNAL_INPUT: 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; EnableExternalInput = EnableExternalInput?0:1;
UpdateCheckedMenuItems(); break; UpdateCheckedMenuItems(); break;
break; break;

View File

@ -534,7 +534,7 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski
if(EmulationPaused&2) if(EmulationPaused&2)
EmulationPaused &= ~1; // clear paused flag temporarily (frame advance) 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); memcpy(XBuf, XBackBuf, 256*256);
FCEU_PutImage(); FCEU_PutImage();
@ -545,7 +545,7 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski
return; return;
} }
if(!FCEU_BotMode()) if(FCEU_BotMode() == BOTMODE_OFF)
{ {
AutoFire(); AutoFire();
UpdateAutosave(); UpdateAutosave();

View File

@ -39,10 +39,10 @@
#include "fds.h" #include "fds.h"
#include "driver.h" #include "driver.h"
// qfox: For UpdateExternalButton(), called when the
// botmode state changes, to update a label in gui.
#ifdef WIN32 #ifdef WIN32
#include "drivers/win/main.h" #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/basicbot.h"
#include "drivers/win/basicbot2.h" // qfox: new bot #include "drivers/win/basicbot2.h" // qfox: new bot
#include "drivers/win/memwatch.h" #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 uint8 joy[4]={0,0,0,0}; //HACK - should be static but movie needs it
static uint8 LastStrobe; static uint8 LastStrobe;
static int BotMode = 0; BOTMODES BotMode = BOTMODE_OFF;
#ifdef _USE_SHARED_MEMORY_ #ifdef _USE_SHARED_MEMORY_
static uint32 BotPointer = 0; //mbg merge 7/18/06 changed to uint32 static uint32 BotPointer = 0; //mbg merge 7/18/06 changed to uint32
#endif #endif
@ -268,12 +269,12 @@ static void StrobeGP(int w)
static INPUTC GPC={ReadGP,0,StrobeGP,UpdateGP,0,0,LogGP,LoadGP}; static INPUTC GPC={ReadGP,0,StrobeGP,UpdateGP,0,0,LogGP,LoadGP};
static INPUTC GPCVS={ReadGPVS,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; return BotMode;
} }
void FCEU_SetBotMode(int x) void FCEU_SetBotMode(BOTMODES x)
{ {
BotMode = x; BotMode = x;
#ifdef WIN32 #ifdef WIN32
@ -294,7 +295,7 @@ void FCEU_UpdateBot()
{ {
#ifdef _USE_SHARED_MEMORY_ #ifdef _USE_SHARED_MEMORY_
//This is the external input (aka bot) code //This is the external input (aka bot) code
if(!BotMode) if(BotMode == BOTMODE_OFF)
return; return;
if(BotInput[0]) if(BotInput[0])
{ {
@ -333,7 +334,7 @@ void FCEU_UpdateBot()
void FCEU_UpdateInput(void) void FCEU_UpdateInput(void)
{ {
//tell all drivers to poll input and set up their logical states //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++) for(int port=0;port<2;port++)
joyports[port].driver->Update(port,joyports[port].ptr,joyports[port].attrib); joyports[port].driver->Update(port,joyports[port].ptr,joyports[port].attrib);

View File

@ -89,10 +89,15 @@ extern struct FCPORT
} portFC; } 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_DrawInput(uint8 *buf);
void FCEU_UpdateInput(void); void FCEU_UpdateInput(void);
int FCEU_BotMode(void);
void FCEU_SetBotMode(int x);
void InitializeInput(void); void InitializeInput(void);
void FCEU_UpdateBot(void); void FCEU_UpdateBot(void);
extern void (*PStrobe[2])(void); extern void (*PStrobe[2])(void);

View File

@ -533,7 +533,7 @@ bool FCEUSS_Load(char *fname)
//If in bot mode, don't do a backup when loading. //If in bot mode, don't do a backup when loading.
//Otherwise you eat at the hard disk, since so many //Otherwise you eat at the hard disk, since so many
//states are being loaded. //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) if(fname)
{ {