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.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

31 Zeilen
906B

  1. #include "nes.h"
  2. static uint8_t read_controller_bit(nes_controller* controller) {
  3. uint8_t state = 1;
  4. if (controller->shift < 0) {
  5. state = (controller->buttons >> Button_A) & 1;
  6. } else if (controller->shift < nes_controller_num_buttons) {
  7. state = (controller->buttons >> controller->shift) & 1;
  8. controller->shift++;
  9. }
  10. return state;
  11. }
  12. uint8_t nes_input_read(nes_input* input, uint16_t addr) {
  13. nes_controller* controller =
  14. &input->controllers[(nes_input_2_reg == addr)];
  15. return ((addr >> 8) & nes_controller_bus_mask) |
  16. read_controller_bit(controller);
  17. }
  18. void nes_input_write(nes_input* input, uint16_t addr, uint8_t val) {
  19. if (val & 1) {
  20. input->controllers[0].shift = -1;
  21. input->controllers[1].shift = -1;
  22. } else {
  23. input->controllers[0].shift = 0;
  24. input->controllers[1].shift = 0;
  25. }
  26. }