BEEP-8 Helper Lib 1.0.0
Loading...
Searching...
No Matches
pad.h File Reference

This module provides classes and functions for managing gamepad input. More...

#include <cobj.h>
#include <nesctrl.h>

Go to the source code of this file.

Classes

class  CPadObj
 Class for managing a gamepad's input and state. More...
 

Enumerations

enum class  EPad {
  START , SELECT , LEFT , UP ,
  RIGHT , DOWN , BTN_A , BTN_B ,
  EPAD_MAX
}
 Enum for gamepad buttons.
 

Functions

CPadObj_CPadObj (u32 idx_)
 Get the CPadObj instance for a specific index.
 

Detailed Description

This module provides classes and functions for managing gamepad input.

The pad module offers functionalities to track and handle the state of gamepad buttons, integrating with NES controller emulation for touch screen inputs. It is designed for use in debugging environments, providing visual feedback and interaction through gamepad input.

The module is not intended for direct use in production games where a serial console does not exist. Its primary purpose is for debugging and development tools.

Note
This module serves only as a utility to emulate an NES controller on a touch panel, and its use is not recommended.

Usage example:

#include <stdio.h>
#include <beep8.h>
#include <nesctrl.h>
#include "pad.h"
// Define NES controller configuration
cfg.left_pix = 10;
cfg.top_pix = 10;
cfg.radius_pix = 5;
cfg.img_utile = B8_PPU_MAX_WTILE - 10;
cfg.img_vtile = B8_PPU_MAX_HTILE - 20;
cfg.img_pal = 1;
cfg.clear_color = B8_PPU_COLOR_BLACK;
cfg.debug_visual = true;
// Create an instance of CPadObj
CPadObj pad(0, &cfg);
// Main loop
while (true) {
pad.vOnStep();
// Initialize draw command buffer
b8PpuCmd cmd;
pad.vOnDraw(&cmd);
// Check button states
if (pad.GetCntHold(EPad::BTN_A) > 0) {
printf("A button is being held\n");
}
if (pad.GetCntRelease(EPad::BTN_B) > 0) {
printf("B button is released\n");
}
// Check other button states as needed
// ...
// Other game logic and rendering
// ...
}
Class for managing a gamepad's input and state.
Definition pad.h:81
Configuration for the NES controller.
Definition nesctrl.h:25
s16 radius_pix
Definition nesctrl.h:29
u8 img_vtile
Definition nesctrl.h:32
u8 clear_color
Definition nesctrl.h:36
bool debug_visual
Definition nesctrl.h:38
s16 left_pix
Definition nesctrl.h:27
s16 top_pix
Definition nesctrl.h:28
u8 img_utile
Definition nesctrl.h:31
u8 img_pal
Definition nesctrl.h:34
NES controller emulation module for touch screen devices.
This module provides classes and functions for managing gamepad input.

Function Documentation

◆ _CPadObj()

CPadObj * _CPadObj ( u32 idx_)
extern

Get the CPadObj instance for a specific index.

Parameters
idx_The index of the gamepad.
Returns
Pointer to the CPadObj instance.