Ver código fonte

cleanup uploader code

David Voswinkel 15 anos atrás
pai
commit
553ef0059a
4 arquivos alterados com 52 adições e 68 exclusões
  1. 0 7
      avr/usbload/Makefile
  2. 49 52
      avr/usbload/main.c
  3. 1 7
      avr/usbload/rle.c
  4. 2 2
      avr/usbload/rle.h

+ 0 - 7
avr/usbload/Makefile

@@ -6,13 +6,6 @@
 # /   \_/.  \  |  /  \  \___|    <  |    `   \  ___/\   / |   \  |__\  \
 # \_____\ \_/____/|__|\___  >__|_ \/_______  /\___  >\_/  |___|\_____  /
 #        \__>             \/     \/        \/     \/                 \/
-#              ___.
-#  __ __  _____\_ |__
-# |  |  \/  ___/| __ \
-# |  |  /\___ \ | \_\ \
-# |____//____  >|___  /
-#            \/     \/
-#
 #                                  www.optixx.org
 #
 #

+ 49 - 52
avr/usbload/main.c

@@ -42,6 +42,7 @@
 #include "watchdog.h"
 #include "huffman-decode.h"
 #include "rle.h"
+#include "loader.h"
 
 
 extern const char _rom[] PROGMEM;
@@ -380,11 +381,55 @@ void decompress_huffman(void){
     printf("Done\n");
 }
 
-void decompress_rle(void){
-    rle_decode(&_rom,30180,0x000000);
-    printf("Done\n");
+
+
+void send_reset(){
+    printf("Reset Snes\n");
+    snes_reset_on();
+    snes_reset_lo();
+    _delay_ms(2);
+    snes_reset_hi();
+    snes_reset_off();
+}
+
+void send_irq(){
+    snes_irq_on();
+    snes_irq_lo();
+    _delay_us(20);
+    snes_irq_hi();
+    snes_irq_off();
+}
+
+void set_rom_mode(){
+    if (req_bank_size == 0x8000){
+        snes_lorom();
+        printf("Set Snes lowrom \n");
+    } else {
+        snes_hirom();
+        printf("Set Snes hirom \n");
+    }
+}
+
+
+void usb_connect(){
+    uint8_t i = 0;
+    printf("USB init\n");
+    usbDeviceDisconnect();      /* enforce re-enumeration, do this while */
+    cli();                             
+    printf("USB disconnect\n");
+    i = 10;
+    while (--i) {               /* fake USB disconnect for > 250 ms */
+        led_on(); 
+        _delay_ms(35);
+        led_off();
+        _delay_ms(65);
+    }
+    led_on();
+    usbDeviceConnect();
+    printf("USB connect\n");
 }
 
+
 void boot_startup_rom(){
     
     uint8_t i = 0;
@@ -411,9 +456,8 @@ void boot_startup_rom(){
     snes_irq_off();
 */  
 
-    decompress_rle();
+    rle_decode(&_rom, ROM_SIZE, 0x000000);
     dump_memory(0x10000 - 0x100, 0x10000);
-    //crc_check_bulk_memory(0x00000, 0x10000, 0x8000);
  
     snes_reset_hi();
     snes_reset_off();
@@ -438,53 +482,6 @@ void boot_startup_rom(){
     
 }
 
-void send_reset(){
-    printf("Reset Snes\n");
-    snes_reset_on();
-    snes_reset_lo();
-    _delay_ms(2);
-    snes_reset_hi();
-    snes_reset_off();
-}
-
-void send_irq(){
-    snes_irq_on();
-    snes_irq_lo();
-    _delay_us(20);
-    snes_irq_hi();
-    snes_irq_off();
-}
-
-void set_rom_mode(){
-    if (req_bank_size == 0x8000){
-        snes_lorom();
-        printf("Set Snes lowrom \n");
-    } else {
-        snes_hirom();
-        printf("Set Snes hirom \n");
-    }
-}
-
-
-void usb_connect(){
-    uint8_t i = 0;
-    printf("USB init\n");
-    usbDeviceDisconnect();      /* enforce re-enumeration, do this while */
-    cli();                             
-    printf("USB disconnect\n");
-    i = 10;
-    while (--i) {               /* fake USB disconnect for > 250 ms */
-        led_on(); 
-        _delay_ms(35);
-        led_off();
-        _delay_ms(65);
-    }
-    led_on();
-    usbDeviceConnect();
-    printf("USB connect\n");
-}
-
-
 int main(void)
 {
     uint8_t i;

+ 1 - 7
avr/usbload/rle.c

@@ -36,6 +36,7 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
 	uint8_t in_byte, in_repeat, last_byte;
 	uint32_t out_len, out_len_left;
     printf("RLE decode len=%li addr=0x%08lx\n",in_len,out_addr);
+    last_byte = 0;
     
 	out_len_left = out_len;
     sram_bulk_write_start(out_addr);
@@ -56,18 +57,11 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
         out_addr++;\
 	} while(0)
 
-		/*
-		** Handle first byte separately (since we have to get angry
-		** in case of an orphaned RLE code).
-		*/
 	INBYTE(in_byte);
 
 	if (in_byte == RUNCHAR) {
 		INBYTE(in_repeat);
 		if (in_repeat != 0) {
-			/* Note Error, not Incomplete (which is at the end
-			** of the string only). This is a programmer error.
-			*/
 			printf("Orphaned RLE code at start\n");
 			return 1;
 		}

+ 2 - 2
avr/usbload/rle.h

@@ -18,8 +18,8 @@
  * =====================================================================================
  */
 
- #ifndef __SRAM_H__
- #define __SRAM_H__
+ #ifndef __RLE_H__
+ #define __RLE_H__
  
 #include <avr/pgmspace.h>