NESe (pronounced "Nessie") is a NES emulator based on the e6502 emulator, also written in C with a focus on speed and portability for use on embedded platforms, especially ARM.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.6KB

  1. #ifndef NES_INPUT_H_
  2. #define NES_INPUT_H_
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. // Emulator Implementation
  6. typedef enum {
  7. input_Result_Error = -1,
  8. input_Result_OK,
  9. input_Result_Quit,
  10. input_Result_Menu,
  11. input_Result_Reset,
  12. input_Result_Save,
  13. input_Result_Load,
  14. input_Result_Cancel,
  15. } nes_Input_Result;
  16. #define nes_controller_num_buttons (8U)
  17. typedef enum {
  18. Button_A = 0,
  19. Button_B,
  20. Button_Select,
  21. Button_Start,
  22. Button_Up,
  23. Button_Down,
  24. Button_Left,
  25. Button_Right,
  26. } nes_Input_Button;
  27. typedef enum {
  28. Controller_Primary = 0b001,
  29. Controller_Expansion = 0b010,
  30. Controller_Microphone = 0b100,
  31. } nes_Controller_State;
  32. typedef struct {
  33. uint32_t buttons;
  34. int shift;
  35. } nes_controller;
  36. typedef struct {
  37. nes_controller controllers[2];
  38. } nes_input;
  39. #define nes_controller_bus_mask (0b11111000)
  40. uint8_t nes_input_read(nes_input* input, uint16_t addr);
  41. void nes_input_write(nes_input* input, uint16_t addr, uint8_t val);
  42. // System Glue
  43. typedef struct nes_Input_Reader_t {
  44. int (*init)(struct nes_Input_Reader_t*);
  45. void (*done)(struct nes_Input_Reader_t*);
  46. int (*update)(struct nes_Input_Reader_t*, nes_input*);
  47. void* data;
  48. } nes_Input_Reader;
  49. static inline int nes_input_init(nes_Input_Reader* reader) {
  50. return reader->init(reader);
  51. }
  52. static inline void nes_input_done(nes_Input_Reader* reader) {
  53. reader->done(reader);
  54. }
  55. static inline int nes_input_update(nes_Input_Reader* reader,
  56. nes_input* input) {
  57. return reader->update(reader, input);
  58. }
  59. #endif // NES_INPUT_H_