command.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include "system.h"
  33. extern usb_transaction_t usb_trans;
  34. extern system_t system;
  35. extern const char *_rom[];
  36. extern const char _rom01[];
  37. extern const int _rom_size[];
  38. void usb_connect()
  39. {
  40. uint8_t i = 0;
  41. info_P(PSTR("USB init\n"));
  42. usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
  43. cli();
  44. info_P(PSTR("USB disconnect\n"));
  45. i = 10;
  46. while (--i) { /* fake USB disconnect for > 250 ms */
  47. _delay_ms(50);
  48. }
  49. led_on();
  50. usbDeviceConnect();
  51. info_P(PSTR("USB connect\n"));
  52. }
  53. void boot_startup_rom(uint16_t init_delay)
  54. {
  55. uint8_t i;
  56. uint32_t addr = 0x000000;
  57. info_P(PSTR("Fetch loader rom\n"));
  58. system_set_bus_avr();
  59. //snes_irq_lo();
  60. //system_snes_irq_off();
  61. system_set_rom_lorom();
  62. //info_P(PSTR("Activate AVR bus\n"));
  63. //avr_bus_active();
  64. //info_P(PSTR("IRQ off\n"));
  65. //snes_irq_lo();
  66. //snes_irq_off();
  67. //snes_lorom();
  68. for (i=0; i<ROM_BUFFER_CNT; i++){
  69. addr += rle_decode(_rom[i], _rom_size[i], addr);
  70. }
  71. info_P(PSTR("\n"));
  72. #if DO_CRC_CHECK_LOADER
  73. dump_memory(0x010000 - 0x100, 0x010000);
  74. uint16_t crc;
  75. crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
  76. info(PSTR("crc=%x\n"),crc);
  77. #endif
  78. //snes_irq_lo();
  79. //snes_irq_off();
  80. //snes_hirom();
  81. //snes_wr_disable();
  82. //system_set_bus_snes();
  83. //system_set_rom_hirom();
  84. //system_set_wr_disable();
  85. //system_snes_irq_off();
  86. snes_irq_lo();
  87. system_snes_irq_off();
  88. system_set_rom_hirom();
  89. system_set_wr_disable();
  90. system_set_bus_snes();
  91. system_send_snes_reset();
  92. info_P(PSTR("Move Loader to wram"));
  93. for (i=0;i<30;i++){
  94. _delay_ms(20);
  95. info_P(PSTR("."));
  96. }
  97. info_P(PSTR("\n"));
  98. }
  99. void banner(){
  100. uint8_t i;
  101. for (i=0;i<40;i++)
  102. info_P(PSTR("\n"));
  103. info_P(PSTR(" ________ .__ __ ________ ____ ________\n"));
  104. info_P(PSTR(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
  105. info_P(PSTR(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
  106. info_P(PSTR(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
  107. info_P(PSTR(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
  108. info_P(PSTR(" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
  109. info_P(PSTR("\n"));
  110. info_P(PSTR(" www.optixx.org\n"));
  111. info_P(PSTR("\n"));
  112. info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
  113. }
  114. void transaction_status(){
  115. info_P(PSTR("\nAddr 0x%06lx\n"),usb_trans.req_addr);
  116. info_P(PSTR("Bank 0x%02x\n"),usb_trans.req_bank);
  117. info_P(PSTR("Banksize 0x%06lx\n"),usb_trans.req_bank_size);
  118. info_P(PSTR("Bankcount 0x%02x\n"),usb_trans.req_bank_cnt);
  119. info_P(PSTR("Status 0x%02x\n"),usb_trans.req_state);
  120. info_P(PSTR("Percent %02i\n"),usb_trans.req_percent);
  121. info_P(PSTR("TX buffer %02i\n"),usb_trans.tx_remaining);
  122. info_P(PSTR("RX buffer %02i\n"),usb_trans.rx_remaining);
  123. info_P(PSTR("Syncerr %02i\n"),usb_trans.sync_errors);
  124. }