command.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * =====================================================================================
  3. *
  4. * ________ .__ __ ________ ____ ________
  5. * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  6. * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  7. * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  8. * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  9. * \__> \/ \/ \/ \/ \/
  10. *
  11. * www.optixx.org
  12. *
  13. *
  14. * Version: 1.0
  15. * Created: 07/21/2009 03:32:16 PM
  16. * Author: david@optixx.org
  17. *
  18. * =====================================================================================
  19. */
  20. #include <avr/io.h>
  21. #include <avr/interrupt.h>
  22. #include <util/delay.h>
  23. #include <stdlib.h>
  24. #include "config.h"
  25. #include "requests.h"
  26. #include "sram.h"
  27. #include "info.h"
  28. #include "irq.h"
  29. #include "usbdrv.h"
  30. #include "rle.h"
  31. #include "loader.h"
  32. extern uint32_t req_bank_size;
  33. extern const char _rom[] PROGMEM;
  34. void usb_connect()
  35. {
  36. uint8_t i = 0;
  37. info_P(PSTR("USB init\n"));
  38. usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
  39. cli();
  40. info_P(PSTR("USB disconnect\n"));
  41. i = 10;
  42. while (--i) { /* fake USB disconnect for > 250 ms */
  43. _delay_ms(50);
  44. }
  45. led_on();
  46. usbDeviceConnect();
  47. info_P(PSTR("USB connect\n"));
  48. }
  49. void send_reset()
  50. {
  51. info_P(PSTR("Reset SNES\n"));
  52. cli();
  53. snes_reset_on();
  54. snes_reset_lo();
  55. _delay_ms(2);
  56. snes_reset_hi();
  57. snes_reset_off();
  58. sei();
  59. }
  60. void send_irq()
  61. {
  62. snes_irq_on();
  63. snes_irq_lo();
  64. _delay_us(20);
  65. snes_irq_hi();
  66. snes_irq_off();
  67. }
  68. void set_rom_mode()
  69. {
  70. if (req_bank_size == 0x8000) {
  71. snes_lorom();
  72. info_P(PSTR("Set SNES lowrom \n"));
  73. } else {
  74. snes_hirom();
  75. info_P(PSTR("Set SNES hirom \n"));
  76. }
  77. }
  78. void boot_startup_rom(uint16_t init_delay)
  79. {
  80. info_P(PSTR("Fetch loader rom\n"));
  81. info_P(PSTR("Activate AVR bus\n"));
  82. avr_bus_active();
  83. info_P(PSTR("IRQ off\n"));
  84. snes_irq_lo();
  85. snes_irq_off();
  86. snes_lorom();
  87. rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
  88. info_P(PSTR("\n"));
  89. #if DO_CRC_CHECK_LOADER
  90. dump_memory(0x010000 - 0x100, 0x010000);
  91. uint16_t crc;
  92. crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
  93. info(PSTR("crc=%x\n"),crc);
  94. #endif
  95. snes_irq_lo();
  96. snes_irq_off();
  97. snes_hirom();
  98. snes_wr_disable();
  99. snes_bus_active();
  100. info_P(PSTR("Activate SNES bus\n"));
  101. send_reset();
  102. _delay_ms(init_delay);
  103. }
  104. void banner(){
  105. uint8_t i;
  106. for (i=0;i<40;i++)
  107. info_P(PSTR("\n"));
  108. info_P(PSTR(" ________ .__ __ ________ ____ ________\n"));
  109. info_P(PSTR(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
  110. info_P(PSTR(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
  111. info_P(PSTR(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
  112. info_P(PSTR(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
  113. info_P(PSTR(" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
  114. info_P(PSTR("\n"));
  115. info_P(PSTR(" www.optixx.org\n"));
  116. info_P(PSTR("\n"));
  117. info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
  118. }