snes.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // insert cool lengthy disclaimer here
  2. // snes.c: SNES hardware control (resetting)
  3. #include <avr/io.h>
  4. #include "avrcompat.h"
  5. #include "config.h"
  6. #include "uart.h"
  7. #include "snes.h"
  8. #include "memory.h"
  9. #include "fileops.h"
  10. #include "ff.h"
  11. uint8_t initloop=1;
  12. uint32_t sram_crc, sram_crc_old;
  13. uint32_t sram_size = 8192; // sane default
  14. void snes_init() {
  15. DDRD |= _BV(PD5); // PD5 = RESET_DIR
  16. DDRD |= _BV(PD6); // PD6 = RESET
  17. snes_reset(1);
  18. }
  19. /*
  20. * sets the SNES reset state.
  21. *
  22. * state: put SNES in reset state when 1, release when 0
  23. */
  24. void snes_reset(int state) {
  25. if(state) {
  26. DDRD |= _BV(PD6); // /RESET pin -> out
  27. PORTD &= ~_BV(PD6); // /RESET = 0
  28. PORTD |= _BV(PD5); // RESET_DIR = 1;
  29. } else {
  30. PORTD &= ~_BV(PD5); // RESET_DIR = 0;
  31. DDRD &= ~_BV(PD6); // /RESET pin -> in
  32. PORTD |= _BV(PD6); // /RESET = 1
  33. }
  34. }
  35. /*
  36. * SD2SNES main loop.
  37. * monitors SRAM changes, menu selections and other things
  38. */
  39. void snes_main_loop() {
  40. if(initloop) {
  41. sram_crc_old = calc_sram_crc(sram_size);
  42. initloop=0;
  43. }
  44. sram_crc = calc_sram_crc(sram_size);
  45. if(sram_crc != sram_crc_old) {
  46. uart_putc('U');
  47. uart_putcrlf();
  48. save_sram("/test.srm", sram_size);
  49. }
  50. sram_crc_old = sram_crc;
  51. uart_putc('.');
  52. }