2008-12-03 05:40:16 +00:00
|
|
|
#include <stdlib.h>
|
2010-08-24 23:00:40 +00:00
|
|
|
#include <stdint.h>
|
2008-12-03 05:40:16 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2010-08-24 23:00:40 +00:00
|
|
|
#include "../../compat/pgmspace.h"
|
2009-01-02 02:18:20 +00:00
|
|
|
#include "../../joystick/joystick.h"
|
2010-04-01 22:59:56 +00:00
|
|
|
#include "../../scrolltext/scrolltext.h"
|
2010-08-24 23:00:40 +00:00
|
|
|
#include "../../util.h"
|
|
|
|
#include "../../config.h"
|
2010-08-22 03:07:46 +00:00
|
|
|
#include "bearing.h"
|
2010-08-24 23:00:40 +00:00
|
|
|
#include "input.h"
|
2010-01-21 20:15:05 +00:00
|
|
|
|
2009-01-02 02:18:20 +00:00
|
|
|
#define WAIT(ms) wait(ms)
|
2010-04-01 22:59:56 +00:00
|
|
|
#define PM(value) pgm_read_byte(&value)
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* \defgroup TetrisInputDefinesPrivate Input: Internal constants
|
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
/***********
|
|
|
|
* defines *
|
|
|
|
***********/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/** amount of milliseconds that each loop cycle waits */
|
2008-12-03 05:40:16 +00:00
|
|
|
#define TETRIS_INPUT_TICKS 5
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* amount of milliseconds the input is ignored after the pause combo has been
|
|
|
|
* pressed, since it is difficult to release all buttons simultaneously
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
#define TETRIS_INPUT_PAUSE_TICKS 100
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* amount of allowed loop cycles while in pause mode so that the game
|
|
|
|
* automatically continues after five minutes
|
|
|
|
*/
|
2008-12-03 05:40:16 +00:00
|
|
|
#define TETRIS_INPUT_PAUSE_CYCLES 60000
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/** initial delay (in loop cycles) for key repeat */
|
2009-06-12 06:24:04 +00:00
|
|
|
#define TETRIS_INPUT_REPEAT_INITIALDELAY 35
|
2010-04-01 03:11:59 +00:00
|
|
|
/** delay (in loop cycles) for key repeat */
|
2009-06-12 06:24:04 +00:00
|
|
|
#define TETRIS_INPUT_REPEAT_DELAY 5
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/** amount of loop cyles the left button is ignored */
|
2008-12-03 05:40:16 +00:00
|
|
|
#define TETRIS_INPUT_CHATTER_TICKS_LEFT 12
|
2010-04-01 03:11:59 +00:00
|
|
|
/** amount of loop cyles the right button is ignored */
|
2008-12-03 05:40:16 +00:00
|
|
|
#define TETRIS_INPUT_CHATTER_TICKS_RIGHT 12
|
2010-04-01 03:11:59 +00:00
|
|
|
/** amount of loop cyles the down button is ignored */
|
2008-12-03 05:40:16 +00:00
|
|
|
#define TETRIS_INPUT_CHATTER_TICKS_DOWN 12
|
2010-04-01 03:11:59 +00:00
|
|
|
/** amount of loop cyles the clockwise rotation button is ignored */
|
|
|
|
#define TETRIS_INPUT_CHATTER_TICKS_ROT_CW 24
|
|
|
|
/** amount of loop cyles the counter clockwise rotation button is ignored */
|
|
|
|
#define TETRIS_INPUT_CHATTER_TICKS_ROT_CCW 24
|
|
|
|
/** amount of loop cyles the drop button is ignored */
|
2010-01-12 21:52:08 +00:00
|
|
|
#define TETRIS_INPUT_CHATTER_TICKS_DROP 20
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/** wait cycles per level (array of uint8_t) */
|
2009-06-12 06:24:04 +00:00
|
|
|
#define TETRIS_INPUT_LVL_CYCLES 200, 133, 100, 80, 66, 57, 50, 44, 40, 36, 33, \
|
|
|
|
30, 28, 26, 25, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup TetrisInputNoInterface Input: Internal non-interface functions
|
|
|
|
*/
|
|
|
|
/*@{*/
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
/***************************
|
|
|
|
* non-interface functions *
|
|
|
|
***************************/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* sets an ignore counter to a command specific value if it is 0
|
|
|
|
* @param pIn pointer to an input object
|
|
|
|
* @param cmd the command whose counter should be set
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
2010-12-15 15:25:56 +00:00
|
|
|
static void tetris_input_chatterProtect(tetris_input_t *pIn,
|
|
|
|
tetris_input_command_t cmd)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
// never exceed the index
|
|
|
|
assert(cmd < TETRIS_INCMD_NONE);
|
|
|
|
|
|
|
|
// amount of loop cycles a command is ignored after its button has been
|
|
|
|
// released (every command has its own counter)
|
2010-08-24 23:00:40 +00:00
|
|
|
static uint8_t const nInitialIgnoreValue[TETRIS_INCMD_NONE] PROGMEM =
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
TETRIS_INPUT_CHATTER_TICKS_LEFT,
|
|
|
|
TETRIS_INPUT_CHATTER_TICKS_RIGHT,
|
|
|
|
TETRIS_INPUT_CHATTER_TICKS_DOWN,
|
2010-04-01 03:11:59 +00:00
|
|
|
TETRIS_INPUT_CHATTER_TICKS_ROT_CW,
|
|
|
|
TETRIS_INPUT_CHATTER_TICKS_ROT_CCW,
|
2008-12-03 05:40:16 +00:00
|
|
|
TETRIS_INPUT_CHATTER_TICKS_DROP,
|
|
|
|
0, // TETRIS_INCMD_GRAVITY (irrelevant because it doesn't have a button)
|
|
|
|
0 // TETRIS_INCMD_PAUSE (is a combination of ROT_CW and DOWN)
|
|
|
|
};
|
|
|
|
|
|
|
|
// setting ignore counter according to the predefined array
|
|
|
|
if (pIn->nIgnoreCmdCounter[cmd] == 0)
|
|
|
|
{
|
|
|
|
// if the command isn't TETRIS_INCMD_PAUSE, setting the ignore counter
|
|
|
|
// is straight forward
|
|
|
|
if (cmd != TETRIS_INCMD_PAUSE)
|
|
|
|
{
|
|
|
|
pIn->nIgnoreCmdCounter[cmd] = PM(nInitialIgnoreValue[cmd]);
|
|
|
|
}
|
|
|
|
// TETRIS_INCMD_PAUSE is issued via a combination of the buttons for
|
|
|
|
// TETRIS_INCMD_ROT_CW and TETRIS_INCMD_DOWN, so we must set their
|
|
|
|
// ignore counters
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pIn->nIgnoreCmdCounter[TETRIS_INCMD_ROT_CW] =
|
|
|
|
TETRIS_INPUT_CHATTER_TICKS_ROT_CW;
|
|
|
|
pIn->nIgnoreCmdCounter[TETRIS_INCMD_DOWN] =
|
|
|
|
TETRIS_INPUT_CHATTER_TICKS_DOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The ignore counter of TETRIS_INCMD_PAUSE is either set to the counter
|
|
|
|
// value of TETRIS_INCMD_ROT_CW or TETRIS_INCMD_DOWN (whichever is higher).
|
|
|
|
if ((cmd == TETRIS_INCMD_ROT_CW) || (cmd == TETRIS_INCMD_DOWN))
|
|
|
|
{
|
|
|
|
// helper variables (which the compiler hopefully optimizes away)
|
2011-01-30 22:47:44 +00:00
|
|
|
uint8_t const nRotCw = pIn->nIgnoreCmdCounter[TETRIS_INCMD_ROT_CW];
|
|
|
|
uint8_t const nDown = pIn->nIgnoreCmdCounter[TETRIS_INCMD_DOWN];
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
pIn->nIgnoreCmdCounter[TETRIS_INCMD_PAUSE] =
|
2011-03-14 10:30:04 +00:00
|
|
|
nRotCw > nDown ? nRotCw : nDown;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
2010-08-22 03:07:46 +00:00
|
|
|
* remaps tetris commands according to current bearing of the bucket
|
|
|
|
* @param nBearing bearing of the bucket
|
2010-04-01 03:11:59 +00:00
|
|
|
* @param nCmd command which has to be mapped
|
|
|
|
* @return mapped tetris command
|
|
|
|
* @see tetris_input_command_t
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
2011-03-07 00:32:38 +00:00
|
|
|
static
|
2010-08-22 03:07:46 +00:00
|
|
|
tetris_input_command_t tetris_input_mapCommand(tetris_bearing_t nBearing,
|
2010-04-01 03:11:59 +00:00
|
|
|
tetris_input_command_t nCmd)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2011-03-07 00:32:38 +00:00
|
|
|
return (nCmd < TETRIS_INCMD_ROT_CCW) ? (nCmd - nBearing + 4) % 4u : nCmd;
|
2010-04-01 03:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* translates joystick movements into tetris commands
|
|
|
|
* @return interpreted joystick command
|
|
|
|
* @see tetris_input_command_t
|
|
|
|
*/
|
2010-12-15 15:25:56 +00:00
|
|
|
static tetris_input_command_t tetris_input_queryJoystick(tetris_input_t *pIn)
|
2010-04-01 03:11:59 +00:00
|
|
|
{
|
|
|
|
// map port input to a tetris command
|
|
|
|
tetris_input_command_t cmdJoystick;
|
2008-12-03 05:40:16 +00:00
|
|
|
if (JOYISFIRE)
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
cmdJoystick = TETRIS_INCMD_DROP;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
else if (JOYISLEFT)
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
cmdJoystick = TETRIS_INCMD_LEFT;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
else if (JOYISRIGHT)
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
cmdJoystick = TETRIS_INCMD_RIGHT;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
else if (JOYISUP && JOYISDOWN)
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
cmdJoystick = TETRIS_INCMD_PAUSE;
|
2008-12-03 05:40:16 +00:00
|
|
|
WAIT(TETRIS_INPUT_PAUSE_TICKS);
|
|
|
|
}
|
|
|
|
else if (JOYISDOWN)
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
cmdJoystick = TETRIS_INCMD_DOWN;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
else if (JOYISUP)
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
cmdJoystick = TETRIS_INCMD_ROT_CW;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
cmdJoystick = TETRIS_INCMD_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// decrement all ignore counters
|
2011-01-25 22:56:49 +00:00
|
|
|
for (uint8_t nIgnIndex = 0; nIgnIndex < TETRIS_INCMD_NONE; ++nIgnIndex)
|
2010-04-01 03:11:59 +00:00
|
|
|
{
|
|
|
|
if (pIn->nIgnoreCmdCounter[nIgnIndex] != 0)
|
|
|
|
{
|
|
|
|
--pIn->nIgnoreCmdCounter[nIgnIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// chatter protection
|
|
|
|
if (cmdJoystick < TETRIS_INCMD_NONE)
|
|
|
|
{
|
|
|
|
if (pIn->nIgnoreCmdCounter[cmdJoystick] == 0)
|
|
|
|
{
|
|
|
|
tetris_input_chatterProtect(pIn, cmdJoystick);
|
|
|
|
}
|
|
|
|
else if (cmdJoystick != pIn->cmdRawLast)
|
|
|
|
{
|
|
|
|
cmdJoystick = TETRIS_INCMD_NONE;
|
|
|
|
}
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
// memorize current command (for detecting prolonged key presses)
|
|
|
|
pIn->cmdRawLast = cmdJoystick;
|
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
// remap command according to current bearing
|
2010-04-01 03:11:59 +00:00
|
|
|
tetris_input_command_t cmdReturn =
|
2010-08-22 03:07:46 +00:00
|
|
|
tetris_input_mapCommand(pIn->nBearing, cmdJoystick);
|
2010-08-24 23:00:40 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
return cmdReturn;
|
|
|
|
}
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/*@}*/
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/****************************
|
|
|
|
* construction/destruction *
|
|
|
|
****************************/
|
|
|
|
|
|
|
|
tetris_input_t *tetris_input_construct(void)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
tetris_input_t *pIn = (tetris_input_t *)malloc(sizeof(tetris_input_t));
|
|
|
|
assert(pIn != NULL);
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
pIn->cmdRawLast = pIn->cmdLast = TETRIS_INCMD_NONE;
|
2010-08-22 03:07:46 +00:00
|
|
|
pIn->nBearing = TETRIS_BEARING_0;
|
2008-12-03 05:40:16 +00:00
|
|
|
tetris_input_setLevel(pIn, 0);
|
|
|
|
pIn->nLoopCycles = 0;
|
|
|
|
pIn->nRepeatCount = -TETRIS_INPUT_REPEAT_INITIALDELAY;
|
|
|
|
pIn->nPauseCount = 0;
|
|
|
|
memset(pIn->nIgnoreCmdCounter, 0, TETRIS_INCMD_NONE);
|
|
|
|
|
|
|
|
return pIn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
* input related functions *
|
|
|
|
***************************/
|
|
|
|
|
|
|
|
tetris_input_command_t tetris_input_getCommand(tetris_input_t *pIn,
|
2010-04-01 03:11:59 +00:00
|
|
|
tetris_input_pace_t nPace)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
assert (pIn != NULL);
|
|
|
|
|
|
|
|
// this variable both serves as the return value and as a flag for not
|
|
|
|
// leaving the function as long as its value is TETRIS_INCMD_NONE
|
|
|
|
tetris_input_command_t cmdReturn = TETRIS_INCMD_NONE;
|
|
|
|
|
|
|
|
// if the piece is gliding we grant the player a reasonable amount of time
|
|
|
|
// to make the game more controllable at higher falling speeds
|
2011-03-14 10:30:04 +00:00
|
|
|
uint8_t nMaxCycles = pIn->nMaxCycles > nPace ? pIn->nMaxCycles : nPace;
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
while (pIn->nLoopCycles < nMaxCycles)
|
|
|
|
{
|
2011-03-14 10:30:04 +00:00
|
|
|
// holds the (mapped) command value of the joystick
|
|
|
|
tetris_input_command_t cmdJoystick = tetris_input_queryJoystick(pIn);
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
switch (cmdJoystick)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
case TETRIS_INCMD_LEFT:
|
|
|
|
case TETRIS_INCMD_RIGHT:
|
|
|
|
case TETRIS_INCMD_DOWN:
|
2011-03-14 10:30:04 +00:00
|
|
|
// only react if either the current command differs from the last
|
|
|
|
// one or enough loop cycles have been run on the same command (for
|
|
|
|
// key repeat)
|
|
|
|
if (pIn->cmdLast != cmdJoystick ||
|
|
|
|
pIn->nRepeatCount++ >= TETRIS_INPUT_REPEAT_DELAY)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
// reset repeat counter
|
2008-12-03 05:40:16 +00:00
|
|
|
if (pIn->cmdLast != cmdJoystick)
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
// different command: we set an extra initial delay
|
|
|
|
pIn->nRepeatCount = -TETRIS_INPUT_REPEAT_INITIALDELAY;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
// same command: there's no extra initial delay
|
|
|
|
pIn->nRepeatCount = 0;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
// update cmdLast and return value
|
|
|
|
pIn->cmdLast = cmdReturn = cmdJoystick;
|
|
|
|
}
|
|
|
|
break;
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
case TETRIS_INCMD_DROP:
|
|
|
|
case TETRIS_INCMD_ROT_CW:
|
|
|
|
case TETRIS_INCMD_ROT_CCW:
|
|
|
|
// no key repeat here
|
|
|
|
if (pIn->cmdLast != cmdJoystick)
|
|
|
|
{
|
|
|
|
pIn->cmdLast = cmdReturn = cmdJoystick;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
2010-04-01 03:11:59 +00:00
|
|
|
break;
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
case TETRIS_INCMD_PAUSE:
|
|
|
|
// if this is an initial pause command, make sure that the logic
|
|
|
|
// module is informed about it
|
|
|
|
if (pIn->cmdLast != TETRIS_INCMD_PAUSE)
|
|
|
|
{
|
|
|
|
pIn->cmdLast = cmdReturn = cmdJoystick;
|
|
|
|
pIn->nPauseCount = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TETRIS_INCMD_NONE:
|
2011-03-14 10:30:04 +00:00
|
|
|
// If the game is paused (last command was TETRIS_INCMD_PAUSE) we
|
|
|
|
// ensure that the variable which holds that last command isn't
|
|
|
|
// touched. We use this as a flag so that the loop cycle counter
|
|
|
|
// doesn't get incremented. We count the number of pause cycles,
|
|
|
|
// though. If enough cycles have been run, we enforce the
|
|
|
|
// continuation of the game.
|
2010-04-01 03:11:59 +00:00
|
|
|
if ((pIn->cmdLast != TETRIS_INCMD_PAUSE) ||
|
|
|
|
(++pIn->nPauseCount > TETRIS_INPUT_PAUSE_CYCLES))
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2010-04-01 03:11:59 +00:00
|
|
|
pIn->cmdLast = TETRIS_INCMD_NONE;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
2010-04-01 03:11:59 +00:00
|
|
|
|
|
|
|
// reset repeat counter
|
|
|
|
pIn->nRepeatCount = -TETRIS_INPUT_REPEAT_INITIALDELAY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// reset automatic falling if the player has dropped a piece
|
2011-03-14 10:30:04 +00:00
|
|
|
if (cmdReturn == TETRIS_INCMD_DOWN || cmdReturn == TETRIS_INCMD_DROP)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
pIn->nLoopCycles = 0;
|
|
|
|
}
|
|
|
|
// otherwise ensure automatic falling (unless the game is running)
|
2011-03-14 10:30:04 +00:00
|
|
|
else if (pIn->cmdLast != TETRIS_INCMD_PAUSE)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
++pIn->nLoopCycles;
|
|
|
|
}
|
|
|
|
|
|
|
|
WAIT(TETRIS_INPUT_TICKS);
|
|
|
|
if (cmdReturn != TETRIS_INCMD_NONE)
|
|
|
|
{
|
|
|
|
return cmdReturn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// since we have left the loop we reset the cycle counter
|
|
|
|
pIn->nLoopCycles = 0;
|
|
|
|
|
|
|
|
return TETRIS_INCMD_GRAVITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tetris_input_setLevel(tetris_input_t *pIn,
|
|
|
|
uint8_t nLvl)
|
|
|
|
{
|
|
|
|
assert(pIn != NULL);
|
|
|
|
assert(nLvl <= TETRIS_INPUT_LEVELS - 1);
|
2009-06-12 06:24:04 +00:00
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
static uint8_t const nCycles[] PROGMEM = {TETRIS_INPUT_LVL_CYCLES};
|
2011-03-14 10:30:04 +00:00
|
|
|
pIn->nMaxCycles = PM(nCycles[nLvl]);
|
2009-06-12 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
|
2009-06-12 06:24:04 +00:00
|
|
|
void tetris_input_resetDownKeyRepeat(tetris_input_t *pIn)
|
|
|
|
{
|
|
|
|
assert(pIn != NULL);
|
|
|
|
if (pIn->cmdLast == TETRIS_INCMD_DOWN)
|
|
|
|
{
|
|
|
|
pIn->nRepeatCount = -TETRIS_INPUT_REPEAT_INITIALDELAY;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-01 03:11:59 +00:00
|
|
|
|
|
|
|
|
2010-08-22 03:07:46 +00:00
|
|
|
void tetris_input_setBearing(tetris_input_t *pIn,
|
|
|
|
tetris_bearing_t nBearing)
|
2010-04-01 03:11:59 +00:00
|
|
|
{
|
2011-03-14 10:30:04 +00:00
|
|
|
pIn->nBearing = nBearing;
|
2010-04-01 03:11:59 +00:00
|
|
|
|
2011-03-14 10:30:04 +00:00
|
|
|
// avoid weird key repeating effects because the currently pressed button
|
|
|
|
// changes its meaning as soon as the bearing changes
|
|
|
|
pIn->cmdLast = tetris_input_mapCommand(pIn->nBearing, pIn->cmdRawLast);
|
2010-04-01 03:11:59 +00:00
|
|
|
}
|