|
- #ifndef NES_INPUT_H_
- #define NES_INPUT_H_
-
- #include <stdint.h>
- #include <stdio.h>
-
-
- // Emulator Implementation
-
- typedef enum {
- input_Result_Error = -1,
- input_Result_OK,
- input_Result_Quit,
- input_Result_Menu,
- input_Result_Reset,
- input_Result_Save,
- input_Result_Load,
- input_Result_Cancel,
- } nes_Input_Result;
-
- #define nes_controller_num_buttons (8U)
-
- typedef enum {
- Button_A = 0,
- Button_B,
- Button_Select,
- Button_Start,
- Button_Up,
- Button_Down,
- Button_Left,
- Button_Right,
- } nes_Input_Button;
-
- typedef enum {
- Controller_Primary = 0b001,
- Controller_Expansion = 0b010,
- Controller_Microphone = 0b100,
- } nes_Controller_State;
-
- typedef struct {
- uint32_t buttons;
- int shift;
- } nes_controller;
-
- typedef struct {
- nes_controller controllers[2];
- } nes_input;
-
-
- #define nes_controller_bus_mask (0b11111000)
-
-
- uint8_t nes_input_read(nes_input* input, uint16_t addr);
-
- void nes_input_write(nes_input* input, uint16_t addr, uint8_t val);
-
-
- // System Glue
-
- typedef struct nes_Input_Reader_t {
- int (*init)(struct nes_Input_Reader_t*);
- void (*done)(struct nes_Input_Reader_t*);
- int (*update)(struct nes_Input_Reader_t*, nes_input*);
- void* data;
- } nes_Input_Reader;
-
- static inline int nes_input_init(nes_Input_Reader* reader) {
- return reader->init(reader);
- }
-
- static inline void nes_input_done(nes_Input_Reader* reader) {
- reader->done(reader);
- }
-
- static inline int nes_input_update(nes_Input_Reader* reader,
- nes_input* input) {
- return reader->update(reader, input);
- }
-
-
- #endif // NES_INPUT_H_
|