Skip to content

Commit

Permalink
initial port to GCWZero device
Browse files Browse the repository at this point in the history
  • Loading branch information
WildPenquin authored and ReinhardPrix committed Sep 8, 2014
1 parent 85d7e96 commit 11c2eaf
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 61 deletions.
54 changes: 54 additions & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,33 @@ enum _cmds {
#define EscapePressedR() KeyIsPressedR (SDLK_ESCAPE)
#define SpacePressedR() KeyIsPressedR (SDLK_SPACE)

#ifdef GCW0 // GCW0 keys are currently mapped to SDL key by the firmware...
#define Gcw0APressed() (KeyIsPressed(SDLK_LCTRL))
#define Gcw0BPressed() (KeyIsPressed(SDLK_LALT))
#define Gcw0XPressed() (KeyIsPressed(SDLK_LSHIFT))
#define Gcw0YPressed() (KeyIsPressed(SDLK_SPACE))
#define Gcw0RSPressed() (KeyIsPressed(SDLK_BACKSPACE))
#define Gcw0LSPressed() (KeyIsPressed(SDLK_TAB))
#define Gcw0StartPressed() (KeyIsPressed(SDLK_RETURN))
#define Gcw0SelectPressed() (KeyIsPressed(SDLK_ESCAPE))

#define Gcw0AnyButtonPressed() (Gcw0APressed() || Gcw0BPressed()\
|| Gcw0XPressed() || Gcw0YPressed() || Gcw0LSPressed() || Gcw0RSPressed()\
|| Gcw0StartPressed() || Gcw0SelectPressed())

#define Gcw0APressedR() (KeyIsPressedR(SDLK_LCTRL))
#define Gcw0BPressedR() (KeyIsPressedR(SDLK_LALT))
#define Gcw0XPressedR() (KeyIsPressedR(SDLK_LSHIFT))
#define Gcw0YPressedR() (KeyIsPressedR(SDLK_SPACE))
#define Gcw0RSPressedR() (KeyIsPressedR(SDLK_BACKSPACE))
#define Gcw0LSPressedR() (KeyIsPressedR(SDLK_TAB))
#define Gcw0StartPressedR() (KeyIsPressedR(SDLK_RETURN))
#define Gcw0SelectPressedR() (KeyIsPressedR(SDLK_ESCAPE))

#define Gcw0AnyButtonPressedR() (Gcw0APressedR() || Gcw0BPressedR()\
|| Gcw0XPressedR() || Gcw0YPressedR() || Gcw0LSPressedR()\
|| Gcw0RSPressedR() || Gcw0StartPressedR() || Gcw0SelectPressedR())
#endif // GCW0 keys

#define UpPressed() (cmd_is_active(CMD_UP))
#define DownPressed() (cmd_is_active(CMD_DOWN))
Expand All @@ -136,8 +163,35 @@ enum _cmds {
#define LeftPressedR() (cmd_is_activeR(CMD_LEFT))
#define RightPressedR() (cmd_is_activeR(CMD_RIGHT))

#define AnyCmdActive() (cmd_is_active(CMD_FIRE) || cmd_is_active(CMD_ACTIVATE) || cmd_is_active(CMD_TAKEOVER) )
#define AnyCmdActiveR() (cmd_is_activeR(CMD_FIRE) || cmd_is_activeR(CMD_ACTIVATE) || cmd_is_activeR(CMD_TAKEOVER) )

#define wait4key() do {while(1) {if(any_key_pressed()) break; else SDL_Delay(50);}; } while(0)

/* Now that I've added ability to clear binds, one can break Freedroid if one
* unbinds all UP / DOWN keys. That's why I've added these, with a fallback key
* too, so that one can ALWAYS navigate the menu.
* Currently MenuBack is not used. */
#define MenuUpR() (UpPressedR() || WheelUpPressed() || KeyIsPressedR(SDLK_UP))
#define MenuDownR() (DownPressedR() || WheelDownPressed() || KeyIsPressedR(SDLK_DOWN) )
#define MenuChooseR() (FirePressedR() || ReturnPressedR() || SpacePressedR())
#define MenuLeftR() (LeftPressedR() || MouseLeftPressed() || KeyIsPressedR(SDLK_LEFT))
#define MenuRightR() (RightPressedR() || MouseRightPressed() || KeyIsPressedR(SDLK_RIGHT) )
#define MenuBackR() (EscapePressedR()) // Not used ATM; but in the future, we might need in case a device has no Escape...

// For clearing a key in keyconfig (can be redefined here):
#define ClearBoundKeyR() (KeyIsPressedR(SDLK_BACKSPACE)) // Works for GCW0 too, currently, since backspace = RShoulder

/* Now for the pressed defines... */
#define MenuUp() (UpPressed() || WheelUpPressed() || KeyIsPressed(SDLK_UP))
#define MenuDown() (DownPressed() || WheelDownPressed() || KeyIsPressed(SDLK_DOWN) )
#define MenuChoose() (FirePressed() || ReturnPressed() || SpacePressed())
#define MenuLeft() (LeftPressed() || MouseLeftPressed() || KeyIsPressed(SDLK_LEFT))
#define MenuRight() (RightPressed() || MouseRightPressed() || KeyIsPressed(SDLK_RIGHT) )
#define MenuBack() (EscapePressed()) // Not used ATM; but in the future, we might need in case a device has no Escape...

#define ClearBoundKey() (KeyIsPressed(SDLK_BACKSPACE)) // Works for GCW0 too, currently, since backspace = RShoulder

// ----------------------------------------

#define COLLISION_STEPSIZE 0.1
Expand Down
9 changes: 7 additions & 2 deletions src/highscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,18 @@ UpdateHighscores (void)
SDL_BlitSurface (pic999, NULL, ne_screen, &dst);
h = FontHeight (Para_BFont);
DisplayText ("Great Score !", dst.x - h, dst.y - h, &User_Rect);
#ifndef ANDROID
#if !defined ANDROID && !defined ARCADEINPUT
DisplayText ("Enter your name: ", dst.x - 5*h, dst.y + dst.h, &User_Rect);
#endif
#ifdef ARCADEINPUT
DisplayText ("Enter with U/D, (L/R skip 5 chars),", dst.x - 6*h, dst.y + dst.h, &User_Rect);
DisplayText ("Act = toggle case, Fire to enter,", dst.x - 5*h, dst.y + dst.h + h, &User_Rect);
DisplayText ("Start when ready: ", dst.x - 5*h, dst.y + dst.h + h*2, &User_Rect);
#endif
SDL_Flip (ne_screen);

SDL_SetClipRect (ne_screen, NULL);
#ifndef ANDROID
#if !defined ANDROID
tmp_name = GetString (MAX_NAME_LEN, 2);
strcpy (new_entry->name, tmp_name);
free (tmp_name);
Expand Down
9 changes: 5 additions & 4 deletions src/influ.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ MoveInfluence (void)
if (RightPressed())
Me.speed.x += accel;

if (!SpacePressed())
Me.status = MOBILE;
// We only need this check if we want held fire to cause activate
if (!AnyCmdActive()) // Used to be !SpacePressed, which causes any fire button != SPACE behave differently than space
Me.status = MOBILE;

if (TransferCounter == 1)
{
Expand All @@ -192,8 +193,8 @@ MoveInfluence (void)
if (cmd_is_active(CMD_ACTIVATE)) // activate mode for Konsole and Lifts
Me.status = ACTIVATE;

if ( (FirePressed ()) && (NoDirectionPressed ()) &&(Me.status != WEAPON) && (Me.status != TRANSFERMODE) )
TransferCounter += Frame_Time();
if ( GameConfig.FireHoldTakeover && (FirePressed ()) && (NoDirectionPressed ()) &&(Me.status != WEAPON) && (Me.status != TRANSFERMODE) ) // Proposed FireActivatePressed here...
TransferCounter += Frame_Time(); // Or make it an option!

if ( (FirePressed() ) && (!NoDirectionPressed () ) && (Me.status != TRANSFERMODE) )
Me.status = WEAPON;
Expand Down
5 changes: 5 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,14 @@ InitFreedroid (int argc, char *const argv[])
GameConfig.FullUserRect = TRUE;
GameConfig.UseFullscreen = FALSE;
GameConfig.TakeoverActivates = TRUE;
GameConfig.FireHoldTakeover = TRUE;
GameConfig.ShowDecals = FALSE;
GameConfig.AllMapVisible = TRUE; // classic setting: map always visible
#ifdef GCW0
GameConfig.scale = 0.5; // Default for 320x200 device (GCW0)
#else
GameConfig.scale = 1.0; // overall scaling of _all_ graphics (e.g. for 320x200 displays)
#endif
GameConfig.HogCPU = FALSE; // default to being nice

// now load saved options from the config-file
Expand Down
48 changes: 41 additions & 7 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ int input_state[INPUT_LAST]; // array of states (pressed/released) of all keys

int key_cmds[CMD_LAST][3] = // array of mappings {key1,key2,key3 -> cmd}
{
#ifdef GCW0
{SDLK_UP, JOY_UP, 0 }, // CMD_UP
{SDLK_DOWN, JOY_DOWN, 0 }, // CMD_DOWN
{SDLK_LEFT, JOY_LEFT, 0 }, // CMD_LEFT
{SDLK_RIGHT, JOY_RIGHT, 0 }, // CMD_RIGHT
{SDLK_SPACE, SDLK_LCTRL, 0 },// CMD_FIRE
{SDLK_LALT, SDLK_LSHIFT, 0 }, // CMD_ACTIVATE
{SDLK_BACKSPACE, SDLK_TAB, 0 },// CMD_TAKEOVER
{0, 0, 0 }, // CMD_QUIT,
{SDLK_RETURN, 0, 0 }, // CMD_PAUSE,
{0, 0, 0 } // CMD_SCREENSHOT
#else
{SDLK_UP, JOY_UP, 'w' }, // CMD_UP
{SDLK_DOWN, JOY_DOWN, 's' }, // CMD_DOWN
{SDLK_LEFT, JOY_LEFT, 'a' }, // CMD_LEFT
Expand All @@ -71,6 +83,7 @@ int key_cmds[CMD_LAST][3] = // array of mappings {key1,key2,key3 -> cmd}
{'q', 'q', 'q' }, // CMD_QUIT,
{SDLK_PAUSE, 'p', 'p' }, // CMD_PAUSE,
{SDLK_F12, SDLK_F12, SDLK_F12 } // CMD_SCREENSHOT
#endif
};

char *keystr[INPUT_LAST];
Expand Down Expand Up @@ -104,13 +117,22 @@ char *cmd_strings[CMD_LAST] =
void
init_keystr (void)
{
keystr[0] = "NONE"; // Empty bind will otherwise crash on some platforms - also, we choose "NONE" as a placeholder...
#ifdef GCW0 // The GCW0 may change to joystick input altogether in the future - which will make these ifdefs unnecessary, I hope...
keystr[SDLK_BACKSPACE] = "RSldr";
keystr[SDLK_TAB] = "LSldr";
keystr[SDLK_RETURN] = "Start";
keystr[SDLK_SPACE] = "Y";
keystr[SDLK_ESCAPE] = "Select";
#else
keystr[SDLK_BACKSPACE] = "BS";
keystr[SDLK_TAB] = "Tab";
keystr[SDLK_CLEAR] = "Clear";
keystr[SDLK_RETURN] = "Return";
keystr[SDLK_PAUSE] = "Pause";
keystr[SDLK_ESCAPE] = "Esc";
keystr[SDLK_SPACE] = "Space";
keystr[SDLK_ESCAPE] = "Esc";
#endif
keystr[SDLK_CLEAR] = "Clear";
keystr[SDLK_PAUSE] = "Pause";
keystr[SDLK_EXCLAIM] = "!";
keystr[SDLK_QUOTEDBL] = "\"";
keystr[SDLK_HASH] = "#";
Expand Down Expand Up @@ -228,12 +250,18 @@ init_keystr (void)
keystr[SDLK_NUMLOCK] = "NumLock";
keystr[SDLK_CAPSLOCK] = "CapsLock";
keystr[SDLK_SCROLLOCK]= "ScrlLock";
keystr[SDLK_RSHIFT] = "RShift";
#ifdef GCW0
keystr[SDLK_LSHIFT] = "X";
keystr[SDLK_LCTRL] = "A";
keystr[SDLK_LALT] = "B";
#else
keystr[SDLK_LSHIFT] = "LShift";
keystr[SDLK_RCTRL] = "RCtrl";
keystr[SDLK_LCTRL] = "LCtrl";
keystr[SDLK_RALT] = "RAlt";
keystr[SDLK_LALT] = "LAlt";
#endif
keystr[SDLK_RSHIFT] = "RShift";
keystr[SDLK_RCTRL] = "RCtrl";
keystr[SDLK_RALT] = "RAlt";
keystr[SDLK_RMETA] = "RMeta";
keystr[SDLK_LMETA] = "LMeta";
keystr[SDLK_LSUPER] = "LSuper";
Expand Down Expand Up @@ -314,7 +342,7 @@ void
ReactToSpecialKeys(void)
{

if ( cmd_is_active(CMD_QUIT) )
if ( cmd_is_activeR(CMD_QUIT) )
QuitGameMenu();

if ( cmd_is_activeR(CMD_PAUSE) )
Expand Down Expand Up @@ -360,10 +388,16 @@ update_input (void)
case SDL_KEYDOWN:
current_modifiers = event.key.keysym.mod;
input_state[event.key.keysym.sym] = PRESSED;
#ifdef GCW0
if ( input_axis.x || input_axis.y ) axis_is_active = TRUE; // 4 GCW-0 ; breaks cursor keys after axis has been active...
#endif
break;
case SDL_KEYUP:
current_modifiers = event.key.keysym.mod;
input_state[event.key.keysym.sym] = RELEASED;
#ifdef GCW0
axis_is_active = FALSE;
#endif
break;

case SDL_JOYAXISMOTION:
Expand Down
Loading

0 comments on commit 11c2eaf

Please sign in to comment.