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.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

92 行
1.8KB

  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. input_Result_View,
  16. input_Result_Refresh,
  17. input_Result_Scale,
  18. input_Result_Effect,
  19. } nes_Input_Result;
  20. #define nes_controller_num_buttons (8U)
  21. typedef enum {
  22. Button_A = 0,
  23. Button_B,
  24. Button_Select,
  25. Button_Start,
  26. Button_Up,
  27. Button_Down,
  28. Button_Left,
  29. Button_Right,
  30. } nes_Input_Button;
  31. typedef enum {
  32. Controller_Primary = 0b001,
  33. Controller_Expansion = 0b010,
  34. Controller_Microphone = 0b100,
  35. } nes_Controller_State;
  36. typedef struct {
  37. uint32_t buttons;
  38. int shift;
  39. } nes_controller;
  40. typedef struct {
  41. nes_controller controllers[2];
  42. } nes_input;
  43. #define nes_controller_bus_mask (0b11111000)
  44. uint8_t nes_input_read(nes_input* input, uint16_t addr);
  45. void nes_input_write(nes_input* input, uint16_t addr, uint8_t val);
  46. // System Glue
  47. struct nese_Components;
  48. typedef struct nes_Input_Reader_t {
  49. int (*init)(struct nes_Input_Reader_t*);
  50. void (*done)(struct nes_Input_Reader_t*);
  51. int (*update)(struct nes_Input_Reader_t*,
  52. struct nese_Components*);
  53. void* data;
  54. int menu_timer;
  55. } nes_Input_Reader;
  56. static inline int nes_input_init(nes_Input_Reader* reader) {
  57. return reader->init(reader);
  58. }
  59. static inline void nes_input_done(nes_Input_Reader* reader) {
  60. reader->done(reader);
  61. }
  62. static inline int nes_input_update(
  63. nes_Input_Reader* reader,
  64. struct nese_Components* comp
  65. ) {
  66. return reader->update(reader, comp);
  67. }
  68. #endif // NES_INPUT_H_