Fixed Joypad.set, it uses 3 values instead of 2 now. True will take control of a button and make it on, False will take control and make it off, and Nil will not take control (allowing the user to press the button)

This commit is contained in:
adelikat 2009-03-14 21:00:28 +00:00
parent 741be87c62
commit 86562d9ad3
4 changed files with 54 additions and 10 deletions

View File

@ -1,4 +1,5 @@
---version 2.0.4 yet to be released---
14-mar-2009 - adelikat - Fixed Joypad.set, it uses 3 values instead of 2 now. True will take control of a button and make it on, False will take control and make it off, and Nil will not take control (allowing the user to press the button)
14-mar-2009 - adelikat - Fix major crash issue where NROM game savestates were writing erroneous information if a non NROM game was loaded prior
13-mar-2009 - adelikat - Closing game / Opening new game resets the frame counter
13-mar-2009 - adelikat - Win32 - Debugger - Scanlines and PPU Pixels are displayed even in vblank (lines 240-261)

View File

@ -12,6 +12,7 @@ int FCEU_LuaRunning();
int FCEU_LuaUsingJoypad(int);
uint8 FCEU_LuaReadJoypad(int);
uint8 FCEU_LuaReadJoypadFalse(int which); //adelikat - will be used to generate a 3rd button condition - false (in addition to true & nil)
int FCEU_LuaSpeed();
int FCEU_LuaFrameskip();
int FCEU_LuaRerecordCountSkip();

View File

@ -191,18 +191,30 @@ static uint8 ReadGPVS(int w)
static void UpdateGP(int w, void *data, int arg)
{
if(w==0)
if(w==0) //adelikat, 3/14/09: Changing the joypads to inclusive OR the user's joypad + the Lua joypad, this way lua only takes over the buttons it explicity says to
{
#ifdef _S9XLUA_H
joy[0]= FCEU_LuaUsingJoypad(0) ? FCEU_LuaReadJoypad(0) : *(uint32 *)joyports[0].ptr;
joy[2]= FCEU_LuaUsingJoypad(2) ? FCEU_LuaReadJoypad(2) : *(uint32 *)joyports[0].ptr >> 16;
//joy[0]= FCEU_LuaUsingJoypad(0) ? FCEU_LuaReadJoypad(0) : *(uint32 *)joyports[0].ptr;
joy[0]= FCEU_LuaUsingJoypad(0) ? (FCEU_LuaReadJoypad(0) | (*(uint32 *)joyports[0].ptr)) : *(uint32 *)joyports[0].ptr;
if (FCEU_LuaReadJoypadFalse(0))
joy[0] &= FCEU_LuaReadJoypadFalse(0);
//joy[2]= FCEU_LuaUsingJoypad(2) ? FCEU_LuaReadJoypad(2) : *(uint32 *)joyports[0].ptr >> 16;
joy[2]= FCEU_LuaUsingJoypad(2) ? (FCEU_LuaReadJoypad(2) | (*(uint32 *)joyports[0].ptr >> 16)) : *(uint32 *)joyports[0].ptr >> 16;
if (FCEU_LuaReadJoypadFalse(2))
joy[2] &= FCEU_LuaReadJoypadFalse(2);
#endif
}
else
{
#ifdef _S9XLUA_H
joy[1]= FCEU_LuaUsingJoypad(1) ? FCEU_LuaReadJoypad(1) : *(uint32 *)joyports[1].ptr >> 8;
joy[3]= FCEU_LuaUsingJoypad(3) ? FCEU_LuaReadJoypad(3) : *(uint32 *)joyports[1].ptr >> 24;
//joy[1]= FCEU_LuaUsingJoypad(1) ? FCEU_LuaReadJoypad(1) : *(uint32 *)joyports[1].ptr >> 8;
joy[1]= FCEU_LuaUsingJoypad(1) ? (FCEU_LuaReadJoypad(1) | (*(uint32 *)joyports[1].ptr >> 8)) : *(uint32 *)joyports[1].ptr >> 8;
if (FCEU_LuaReadJoypadFalse(1))
joy[1] &= FCEU_LuaReadJoypadFalse(1);
//joy[3]= FCEU_LuaUsingJoypad(3) ? FCEU_LuaReadJoypad(3) : *(uint32 *)joyports[1].ptr >> 24;
joy[3]= FCEU_LuaUsingJoypad(3) ? (FCEU_LuaReadJoypad(3) | (*(uint32 *)joyports[1].ptr >> 24)) : *(uint32 *)joyports[1].ptr >> 24;
if (FCEU_LuaReadJoypadFalse(3))
joy[3] &= FCEU_LuaReadJoypadFalse(3);
#endif
}

View File

@ -113,7 +113,9 @@ static int transparency;
// Our joypads.
static uint8 lua_joypads[4];
static uint8 lua_joypads_used;
//adelikat - adding these to generate the condition of false (previously false resulted in the "on" condition)
static uint8 lua_joypads_false[4];
static uint8 lua_joypads_used_false;
static enum { GUI_USED_SINCE_LAST_DISPLAY, GUI_USED_SINCE_LAST_FRAME, GUI_CLEAR } gui_used = GUI_CLEAR;
static uint8 *gui_data = NULL;
@ -146,6 +148,7 @@ static const char *button_mappings[] = {
static void FCEU_LuaOnStop() {
luaRunning = FALSE;
lua_joypads_used = 0;
lua_joypads_used_false = 0;
gui_used = GUI_CLEAR;
if (wasPaused && !FCEUI_EmulationPaused())
FCEUI_ToggleEmulationPause();
@ -659,7 +662,7 @@ static int joypad_read(lua_State *L) {
}
// joypad.write(int which, table buttons)
// joypad.set(int which, table buttons)
//
// Sets the given buttons to be pressed during the next
// frame advance. The table should have the right
@ -680,11 +683,29 @@ static int joypad_set(lua_State *L) {
lua_joypads_used |= 1 << (which-1);
lua_joypads[which-1] = 0;
lua_joypads_used_false |= 1 << (which -1);
lua_joypads[which-1] = 0;
int i;
for (i=0; i < 8; i++) {
lua_getfield(L, 2, button_mappings[i]);
//Button is not nil, so find out if it is true/false
if (!lua_isnil(L,-1))
{
if (lua_toboolean(L,-1)) //True
lua_joypads[which-1] |= 1 << i;
else //False
{
lua_joypads_false[which-1] = 1 << i; //Create a false joypad to overlay on the regular input, 0's will result in turning off and overriding the input
lua_joypads_false[which-1] = ~lua_joypads_false[which-1]; //1's will mean it does not take control
}
}
//Button is nil, so leave that button blank
else
{
}
lua_pop(L,1);
}
@ -2069,6 +2090,8 @@ int FCEU_LuaUsingJoypad(int which) {
return lua_joypads_used & (1 << which);
}
//adelikat: TODO: should I have a FCEU_LuaUsingJoypadFalse?
/**
* Reads the buttons Lua is feeding for the given joypad, in the same
* format as the OS-specific code.
@ -2081,6 +2104,13 @@ uint8 FCEU_LuaReadJoypad(int which) {
return lua_joypads[which];
}
//adelikat: Returns the buttons that will be specifically set to false (as opposed to on or nil)
//This will be used in input.cpp to &(and) against the input to override a button with a false value. This is a work around to allow 3 conditions to be sent be lua, true, false, nil
uint8 FCEU_LuaReadJoypadFalse(int which) {
lua_joypads_used_false &= ~(1 << which);
return lua_joypads_false[which];
}
/**
* If this function returns true, the movie code should NOT increment
* the rerecord count for a load-state.