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.

31 line
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. }