Modules/input

From MSX Game Library

< Modules

input

Code: input.h

Category: Core

Dependencies: None

Samples:

The input module handle input from the general purpose port (better known as the joystick port; including joystick and mouse) and from the keyboard.

Usage

To use this module, include "input.h" in your source code, and add "input" to the modules list (LibModules) in your project's configuration file (project_config.js).

Check joystick bouton example:

u8 joyStat = Joystick_Read(JOY_PORT_1);
if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_A))
{
	// Joystick A boutton pressed
}
else if (IS_JOY_PRESSED(joyStat, JOY_INPUT_TRIGGER_B))
{
	// Joystick B boutton pressed
}

Check key example:

if(Keyboard_IsKeyPressed(KEY_RETURN))
{
	// "Return" key pressed
}

A quicker way to check keyboard is to read a whole keys row at once:

u8 row8 = Keyboard_Read(8); // The row that include the arrow keys
if(IS_KEY_PRESSED(row8, KEY_RIGHT))
{
	// "Right arrow" key pressed
}
else if(IS_KEY_PRESSED(row8, KEY_LEFT))
{
	// "Left arrow" key pressed
}

Samples

See module use cases in the sample programs:

Settings

Library configuration (msxgl_config.h):

// Input module setting
#define INPUT_USE_JOYSTICK			TRUE	// Add functions to handle joystick using I/O port
#define INPUT_USE_KEYBOARD			TRUE	// Add functions to handle keyboard using I/O port
#define INPUT_USE_MOUSE				TRUE	// Add support for Mouse handling functions
#define INPUT_USE_DETECT			TRUE	// Add feature to detect device plugged in General purpose ports
#define INPUT_USE_ISR_PROTECTION	TRUE	// Disable interruptions while access PSG registers (needed if you use BIOS or access PSG in your own ISR)
#define INPUT_JOY_UPDATE			FALSE	// Add function to update all joystick states at once
// Key update handler
#define INPUT_KB_UPDATE				FALSE	// Add function to update all keyboard rows at once
#define INPUT_KB_UPDATE_MIN			0		// First row to update
#define INPUT_KB_UPDATE_MAX			8		// Last row to update (10 for numerical-pad, 8 otherwise)

Dependencies

Dependency on other modules: None

Documentation