From 553ef0059a0438cf8f05c7205a60c00a35aab7d2 Mon Sep 17 00:00:00 2001 From: David Voswinkel Date: Sat, 1 Aug 2009 15:16:11 +0200 Subject: [PATCH] cleanup uploader code --- avr/usbload/Makefile | 7 --- avr/usbload/main.c | 109 +++++++++++++++++++++---------------------- avr/usbload/rle.c | 8 +--- avr/usbload/rle.h | 4 +- 4 files changed, 56 insertions(+), 72 deletions(-) diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index 46e7bf9..e3a20a7 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -6,13 +6,6 @@ # / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ # \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / # \__> \/ \/ \/ \/ \/ -# ___. -# __ __ _____\_ |__ -# | | \/ ___/| __ \ -# | | /\___ \ | \_\ \ -# |____//____ >|___ / -# \/ \/ -# # www.optixx.org # # diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 01068a1..f988354 100644 --- a/avr/usbload/main.c +++ b/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,63 +381,7 @@ void decompress_huffman(void){ printf("Done\n"); } -void decompress_rle(void){ - rle_decode(&_rom,30180,0x000000); - printf("Done\n"); -} -void boot_startup_rom(){ - - uint8_t i = 0; - - printf("Activate AVR bus\n"); - avr_bus_active(); - - printf("IRQ off\n"); - snes_irq_lo(); - snes_irq_off(); - - snes_lorom(); - printf("Set Snes lowrom \n"); - -/* - printf("Set Snes hirom\n"); - snes_hirom(); - - printf("Disable snes WR\n"); - snes_wr_disable(); - - printf("IRQ off\n"); - snes_irq_lo(); - snes_irq_off(); -*/ - - decompress_rle(); - dump_memory(0x10000 - 0x100, 0x10000); - //crc_check_bulk_memory(0x00000, 0x10000, 0x8000); - - snes_reset_hi(); - snes_reset_off(); - snes_irq_lo(); - snes_irq_off(); - printf("IRQ off\n"); - snes_hirom(); - snes_wr_disable(); - printf("Disable snes WR\n"); - snes_bus_active(); - printf("Activate Snes bus\n"); - _delay_ms(100); - printf("Reset Snes\n"); - send_reset(); - i = 20; - printf("Wait"); - while (--i){ - _delay_ms(500); - printf("."); - } - printf("\n"); - -} void send_reset(){ printf("Reset Snes\n"); @@ -485,6 +430,58 @@ void usb_connect(){ } +void boot_startup_rom(){ + + uint8_t i = 0; + + printf("Activate AVR bus\n"); + avr_bus_active(); + + printf("IRQ off\n"); + snes_irq_lo(); + snes_irq_off(); + + snes_lorom(); + printf("Set Snes lowrom \n"); + +/* + printf("Set Snes hirom\n"); + snes_hirom(); + + printf("Disable snes WR\n"); + snes_wr_disable(); + + printf("IRQ off\n"); + snes_irq_lo(); + snes_irq_off(); +*/ + + rle_decode(&_rom, ROM_SIZE, 0x000000); + dump_memory(0x10000 - 0x100, 0x10000); + + snes_reset_hi(); + snes_reset_off(); + snes_irq_lo(); + snes_irq_off(); + printf("IRQ off\n"); + snes_hirom(); + snes_wr_disable(); + printf("Disable snes WR\n"); + snes_bus_active(); + printf("Activate Snes bus\n"); + _delay_ms(100); + printf("Reset Snes\n"); + send_reset(); + i = 20; + printf("Wait"); + while (--i){ + _delay_ms(500); + printf("."); + } + printf("\n"); + +} + int main(void) { uint8_t i; diff --git a/avr/usbload/rle.c b/avr/usbload/rle.c index 5c196b5..dbe5164 100644 --- a/avr/usbload/rle.c +++ b/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; } diff --git a/avr/usbload/rle.h b/avr/usbload/rle.h index ecfa014..9e25601 100644 --- a/avr/usbload/rle.h +++ b/avr/usbload/rle.h @@ -18,8 +18,8 @@ * ===================================================================================== */ - #ifndef __SRAM_H__ - #define __SRAM_H__ + #ifndef __RLE_H__ + #define __RLE_H__ #include