Browse Source

prepare commands

optixx 14 years ago
parent
commit
b092b3e182
3 changed files with 62 additions and 9 deletions
  1. 1 2
      avr/usbload/irq.c
  2. 5 7
      avr/usbload/main.c
  3. 56 0
      avr/usbload/system.c

+ 1 - 2
avr/usbload/irq.c

@@ -60,8 +60,7 @@ void leave_application(void)
 
 }
 
- 
-ISR (SIG_PIN_CHANGE3)
+ ISR (SIG_PIN_CHANGE3)
 {
     if (snes_reset_test()){
         info_P(PSTR("Catch SNES reset button\n"));

+ 5 - 7
avr/usbload/main.c

@@ -248,13 +248,12 @@ int main(void)
     uart_init();
     stdout = &uart_stdout;
     banner();
-    
+    shared_memory_init();
+    system_init();
     sram_init();
     pwm_init();
-    shared_memory_init();
-    snes_reset_hi();
-    snes_reset_off();
     irq_init();
+    
     boot_startup_rom(50);
     
     globals_init();
@@ -262,14 +261,14 @@ int main(void)
     
     usbInit();
     usb_connect();
+    sei();
     
     while (1) {
         avr_bus_active();
         info_P(PSTR("Activate AVR bus\n"));
-        snes_lorom();
+        //snes_lorom();
         info_P(PSTR("Disable SNES WR\n"));
         snes_wr_disable();
-        sei();
         info_P(PSTR("USB poll\n"));
         while (usb_trans.req_state != REQ_STATUS_SNES) {
             usbPoll();
@@ -277,7 +276,6 @@ int main(void)
         }
         
 #if DO_SHM
-        
         shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
 #endif
 

+ 56 - 0
avr/usbload/system.c

@@ -23,6 +23,8 @@
 #include <stdint.h>
 #include <avr/io.h>
 #include <util/delay.h>         /* for _delay_ms() */
+#include <avr/interrupt.h>      
+
 
 #include "config.h"
 #include "sram.h"
@@ -30,10 +32,64 @@
 #include "uart.h"
 #include "debug.h"
 #include "info.h"
+#include "requests.h"
 
 
 void system_init(void)
 {
+    snes_reset_hi();
+    snes_reset_off();
+    snes_irq_hi();
+    snes_irq_off();
 
 }   
 
+void system_reset()
+{
+    info_P(PSTR("Reset SNES\n"));
+    cli();
+    snes_reset_on();
+    snes_reset_lo();
+    _delay_ms(2);
+    snes_reset_hi();
+    snes_reset_off();
+    sei();
+}
+
+void system_send_irq()
+{
+    snes_irq_on();
+    snes_irq_lo();
+    _delay_us(20);
+    snes_irq_hi();
+    snes_irq_off();
+}
+
+void system_bus_avr()
+{
+    info_P(PSTR("Activate AVR bus\n"));
+    avr_bus_active();
+    info_P(PSTR("Disable SNES WR\n"));
+    snes_wr_disable();
+}
+
+void system_bus_snes()
+{
+    snes_wr_disable();
+    info_P(PSTR("Disable SNES WR\n"));
+    snes_bus_active();
+    info_P(PSTR("Activate SNES bus\n"));
+    irq_stop();
+}
+
+void system_rom_mode(usb_transaction_t *usb_trans)
+{
+    if (usb_trans->req_bank_size == 0x8000) {
+        snes_lorom();
+        info_P(PSTR("Set SNES lowrom \n"));
+    } else {
+        snes_hirom();
+        info_P(PSTR("Set SNES hirom \n"));
+    }
+}
+