command.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/interrupt.h>
  21. #include <util/delay.h>
  22. #include <stdlib.h>
  23. #include "config.h"
  24. #include "requests.h"
  25. #include "sram.h"
  26. #include "info.h"
  27. #include "irq.h"
  28. #include "usbdrv.h"
  29. #if defined(BOOT_COMPRESS_RLE)
  30. #include "rle.h"
  31. #endif
  32. #if defined(BOOT_COMPRESS_ZIP)
  33. #include "neginf/neginf.h"
  34. #include "inflate.h"
  35. #endif
  36. #if defined(BOOT_COMPRESS_FASTLZ)
  37. #include "fastlz.h"
  38. #endif
  39. #include "loader.h"
  40. #include "system.h"
  41. extern usb_transaction_t usb_trans;
  42. extern system_t my_system;
  43. extern const char *_rom[];
  44. extern const char _rom01[];
  45. extern const int _rom_size[];
  46. void usb_connect()
  47. {
  48. uint8_t i = 0;
  49. info_P(PSTR("USB init\n"));
  50. usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
  51. cli();
  52. info_P(PSTR("USB disconnect\n"));
  53. i = 10;
  54. while (--i) { /* fake USB disconnect for > 250 ms */
  55. _delay_ms(50);
  56. }
  57. led_on();
  58. usbDeviceConnect();
  59. info_P(PSTR("USB connect\n"));
  60. }
  61. void boot_startup_rom(uint16_t init_delay)
  62. {
  63. uint8_t i;
  64. #if defined(BOOT_COMPRESS_RLE)
  65. uint32_t addr = 0x000000;
  66. #endif
  67. #if defined(BOOT_COMPRESS_ZIP)
  68. uint8_t c;
  69. uint16_t j;
  70. PGM_VOID_P p_addr;
  71. #endif
  72. info_P(PSTR("Fetch Loader: %s from AVR PROGMEM\n"), LOADER_NAME);
  73. system_set_bus_avr();
  74. // snes_irq_lo();
  75. // system_snes_irq_off();
  76. system_set_rom_lorom();
  77. // info_P(PSTR("Activate AVR bus\n"));
  78. // avr_bus_active();
  79. // info_P(PSTR("IRQ off\n"));
  80. // snes_irq_lo();
  81. // snes_irq_off();
  82. // snes_lorom();
  83. info_P(PSTR("Unpack Loader with using method: %s\n"), LOADER_COMPRESS);
  84. #if defined(BOOT_COMPRESS_RLE)
  85. for (i = 0; i < ROM_BUFFER_CNT; i++) {
  86. addr += rle_decode(_rom[i], _rom_size[i], addr);
  87. }
  88. #endif
  89. #if defined(BOOT_COMPRESS_ZIP)
  90. //inflate_init();
  91. neginf_init(0);
  92. for (i=0; i<ROM_BUFFER_CNT; i++){
  93. p_addr = _rom[i];
  94. info_P(PSTR("idx=%i addr=%lx %s\n"), i, p_addr);
  95. for (j=0; j<_rom_size[i]; j++){
  96. c = pgm_read_byte((PGM_VOID_P)p_addr++);
  97. neginf_process_byte(c);
  98. }
  99. }
  100. #endif
  101. #if defined(BOOT_COMPRESS_FASTLZ)
  102. uint32_t rlen = _rom_size[0]+ _rom_size[1];
  103. fastlz_decompress2(_rom[0], _rom[0], rlen);
  104. #endif
  105. info_P(PSTR("\n"));
  106. #if DO_CRC_CHECK_LOADER
  107. dump_memory(0x010000 - 0x100, 0x010000);
  108. uint16_t crc;
  109. crc = crc_check_bulk_memory((uint32_t) 0x000000, 0x010000, 0x010000);
  110. info(PSTR("crc=%x\n"), crc);
  111. #endif
  112. // snes_irq_lo();
  113. // snes_irq_off();
  114. // snes_hirom();
  115. // snes_wr_disable();
  116. // system_set_bus_snes();
  117. // system_set_rom_hirom();
  118. // system_set_wr_disable();
  119. // system_snes_irq_off();
  120. snes_irq_lo();
  121. system_snes_irq_off();
  122. system_set_rom_hirom();
  123. system_set_wr_disable();
  124. system_set_bus_snes();
  125. system_send_snes_reset();
  126. info_P(PSTR("Move Loader to wram"));
  127. for (i = 0; i < 30; i++) {
  128. _delay_ms(20);
  129. info_P(PSTR("."));
  130. }
  131. info_P(PSTR("\n"));
  132. }
  133. void banner()
  134. {
  135. uint8_t i;
  136. for (i = 0; i < 40; i++)
  137. info_P(PSTR("\n"));
  138. info_P(PSTR
  139. (" ________ .__ __ ________ ____ ________\n"));
  140. info_P(PSTR
  141. (" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
  142. info_P(PSTR
  143. (" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
  144. info_P(PSTR
  145. (" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
  146. info_P(PSTR
  147. (" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
  148. info_P(PSTR
  149. (" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
  150. info_P(PSTR("\n"));
  151. info_P(PSTR(" www.optixx.org\n"));
  152. info_P(PSTR("\n"));
  153. info_P(PSTR("Hardware Version: %s Software Version: %s Build Date: %s \n"), HW_VERSION, SW_VERSION, __DATE__ );
  154. }
  155. void transaction_status()
  156. {
  157. info_P(PSTR("\nAddr 0x%06lx\n"), usb_trans.req_addr);
  158. info_P(PSTR("Bank 0x%02x\n"), usb_trans.req_bank);
  159. info_P(PSTR("Banksize 0x%06lx\n"), usb_trans.req_bank_size);
  160. info_P(PSTR("Bankcount 0x%02x\n"), usb_trans.req_bank_cnt);
  161. info_P(PSTR("Status 0x%02x\n"), usb_trans.req_state);
  162. info_P(PSTR("Percent %02i\n"), usb_trans.req_percent);
  163. info_P(PSTR("TX buffer %02i\n"), usb_trans.tx_remaining);
  164. info_P(PSTR("RX buffer %02i\n"), usb_trans.rx_remaining);
  165. info_P(PSTR("Syncerr %02i\n"), usb_trans.sync_errors);
  166. }