diff --git a/avr/bootloader/bootloader.c b/avr/bootloader/bootloader.c index 8852b65..46cdd60 100644 --- a/avr/bootloader/bootloader.c +++ b/avr/bootloader/bootloader.c @@ -471,13 +471,12 @@ int __attribute__ ((noreturn, OS_main)) main(void) jump_to_app(); } -#ifdef AVR_BTLDR_SWITCH ENABLE +#if AVR_BTLDR_SWITCH_ENABLE if ((AVR_BTLDR_EN_IN & ( 1 << AVR_BTLDR_EN_PIN)) == 0){ banner(); uart_puts("Bootloader flashing is disabled\n\r"); MCUSR = 0; leave_bootloader(); - } #endif diff --git a/avr/bootloader/config.h b/avr/bootloader/config.h index fe10820..0aeef10 100644 --- a/avr/bootloader/config.h +++ b/avr/bootloader/config.h @@ -20,3 +20,4 @@ #define DEBUG 1 #define DEBUG_USB 2 +#define AVR_BTLDR_SWITCH_ENABLE 1 diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index dbd39d0..8fe7997 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -23,14 +23,15 @@ F_CPU = 20000000 TARGET = main AVRDUDE = avrdude -c usbasp -p $(DEVICE) SIZE = avr-size -BOOT_ROM_SMALL = ../../roms/qd16boot01.smc -BOOT_ROM_FULL = ../../roms/qd16boot02.smc -ROM_CONVERT = ../../scripts/conv_rle.py +BOOT_ROM01 = ../../roms/qd16boot01.smc +BOOT_ROM02 = ../../roms/qd16boot02.smc +CONVERT_RLE = ../../scripts/conv_rle.py +CONVERT_ZIP = ../../scripts/conv_zip.py ifeq ($(DEBUG),1) - LDFLAGS =-Wl,-u,vfprintf -lprintf_flt + LDFLAGS =-Wl,-u,vfprintf CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0 OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \ main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \ @@ -79,11 +80,11 @@ fuse: flash: main.hex $(AVRDUDE) -U flash:w:main.hex:i -loader: - python $(ROM_CONVERT) $(BOOT_ROM_SMALL) +loader01: + python $(CONVERT_RLE) $(BOOT_ROM01) -loader_full: - python $(ROM_CONVERT) $(BOOT_ROM_FULL) +loader02: + python $(CONVERT_ZIP) $(BOOT_ROM02) .c.o: $(COMPILE) -c $< -o $@ diff --git a/avr/usbload/command.c b/avr/usbload/command.c index 811f4c1..bd4fff2 100644 --- a/avr/usbload/command.c +++ b/avr/usbload/command.c @@ -58,37 +58,6 @@ void usb_connect() } -void send_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 send_irq() -{ - snes_irq_on(); - snes_irq_lo(); - _delay_us(20); - snes_irq_hi(); - snes_irq_off(); -} - -void set_rom_mode() -{ - 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")); - } -} void boot_startup_rom(uint16_t init_delay) { @@ -97,8 +66,8 @@ void boot_startup_rom(uint16_t init_delay) info_P(PSTR("Fetch loader rom\n")); system_set_bus_avr(); - snes_irq_lo(); - system_snes_irq_off(); + //snes_irq_lo(); + //system_snes_irq_off(); system_set_rom_lorom(); //info_P(PSTR("Activate AVR bus\n")); @@ -138,7 +107,12 @@ void boot_startup_rom(uint16_t init_delay) system_send_snes_reset(); - _delay_ms(init_delay); + info_P(PSTR("Move Loader to wram")); + for (i=0;i<30;i++){ + _delay_ms(20); + info_P(PSTR(".")); + } + info_P(PSTR("\n")); } void banner(){ diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 4811853..d51bf05 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -50,8 +50,9 @@ #define DO_CRC_CHECK_LOADER 0 #define DO_CRC_CHECK 0 -#define DO_SHM_SCRATCHPAD 0 +#define DO_SHM_SCRATCHPAD 1 #define DO_SHM 0 #define DO_TIMER 0 +#define DO_SHELL 1 #endif diff --git a/avr/usbload/loader.h b/avr/usbload/loader.h index 9cfd436..25ca490 100644 --- a/avr/usbload/loader.h +++ b/avr/usbload/loader.h @@ -1,6 +1,6 @@ /* File: qd16boot01.smc -Time: Sun, 18 Oct 2009 09:40:40 +Time: Fri, 30 Oct 2009 16:49:11 */ #ifndef __FIFO_H__ #define __FIFO_H__ diff --git a/avr/usbload/main.c b/avr/usbload/main.c index 2d6cf8a..50491cc 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -56,8 +56,7 @@ extern FILE uart_stdout; #endif extern system_t system; -uint8_t debug_level = (DEBUG | DEBUG_CRC); - +uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC); usb_transaction_t usb_trans; @@ -170,11 +169,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_BULK_UPLOAD_END) { - if (usb_trans.req_state != REQ_STATUS_BULK_UPLOAD) { - debug_P(DEBUG_USB, - PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n")); - return 0; - } debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END:\n")); usb_trans.req_state = REQ_STATUS_IDLE; sram_bulk_write_end(); @@ -219,6 +213,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) * ------------------------------------------------------------------------- */ } else if (rq->bRequest == USB_SET_LAODER) { + debug_P(DEBUG_USB, PSTR("USB_SET_LAODER:\n")); usb_trans.loader_enabled = rq->wValue.word; ret_len = 0; } @@ -263,20 +258,14 @@ int main(void) usb_connect(); sei(); while (1) { - system_set_bus_avr(); system_set_wr_disable(); -/* - avr_bus_active(); - info_P(PSTR("Activate AVR bus\n")); - info_P(PSTR("Disable SNES WR\n")); - snes_wr_disable(); -*/ - info_P(PSTR("USB poll\n")); while (usb_trans.req_state != REQ_STATUS_SNES) { usbPoll(); +#if DO_SHELL #ifndef NO_DEBUG shell_run(); +#endif #endif } @@ -299,35 +288,24 @@ int main(void) system_set_bus_snes(); system_send_snes_reset(); irq_stop(); -/* - info_P(PSTR("-->Switch TO SNES\n")); - set_rom_mode(); - snes_wr_disable(); - info_P(PSTR("Disable SNES WR\n")); - snes_bus_active(); - info_P(PSTR("Activate SNES bus\n")); - irq_stop(); - send_reset(); -*/ - info_P(PSTR("Poll USB\n")); while ((usb_trans.req_state != REQ_STATUS_AVR)) { usbPoll(); +#if DO_SHELL #ifndef NO_DEBUG shell_run(); +#endif #endif } - //info_P(PSTR("-->Switch TO AVR\n")); + info_P(PSTR("-->Switch TO AVR\n")); shared_memory_init(); + irq_init(); if(usb_trans.loader_enabled) { - boot_startup_rom(500); + boot_startup_rom(50); } else { system_set_bus_avr(); system_send_snes_reset(); - //avr_bus_active(); - //send_reset(); - } - irq_init(); + globals_init(); } return 0; } diff --git a/avr/usbload/shell.c b/avr/usbload/shell.c index 1167b00..6c65a63 100644 --- a/avr/usbload/shell.c +++ b/avr/usbload/shell.c @@ -44,11 +44,11 @@ extern system_t system; -const PROGMEM char STR_ROM[] = "Rom"; -const PROGMEM char STR_RAM[] = "Sram"; -const PROGMEM char STR_BAT[] = "Battery"; -const PROGMEM char STR_SUPERFX[] = "SuperFX"; -const PROGMEM char STR_SA[] = "SA-1"; +const char STR_ROM[] PROGMEM = "Rom"; +const char STR_RAM[] PROGMEM = "Sram"; +const char STR_BAT[] PROGMEM = "Battery"; +const char STR_SUPERFX[] PROGMEM = "SuperFX"; +const char STR_SA[] PROGMEM = "SA-1"; uint8_t command_buf[RECEIVE_BUF_LEN]; @@ -59,6 +59,8 @@ volatile uint8_t cr = 0; uint8_t *token_ptr; +#if DO_SHELL + uint8_t *get_token(void) { uint8_t *p = token_ptr; @@ -408,45 +410,45 @@ void shell_run(void) } c = sram_read(0xffd6 - offset); - info_P(PSTR("TYPE 0x%04x \n"), (0xffd6 - offset)); + info_P(PSTR("TYPE 0x%04xc"), (0xffd6 - offset),c); switch(c){ case 0x00: - info_P(PSTR("%s\n"),STR_ROM); + info_P(PSTR("Rom\n")); break; case 0x01: - info_P(PSTR("%s + %s\n"),STR_ROM,STR_RAM); + info_P(PSTR("Rom + Sram\n")); break; case 0x02: - info_P(PSTR("%s + %s + %s\n"),STR_ROM,STR_RAM,STR_BAT); + info_P(PSTR("Rom + Sram + Battery\n")); break; case 0x13: - info_P(STR_SUPERFX); + info_P(PSTR("SuperFX\n")); break; case 0x14: - info_P(STR_SUPERFX); + info_P(PSTR("SuperFX\n")); break; case 0x15: - info_P(PSTR("%s + %s\n"),STR_SUPERFX,STR_RAM); + info_P(PSTR("SuperFX + Sram\n")); break; case 0x1a: - info_P(PSTR("%s + %s\n"),STR_SUPERFX,STR_RAM); + info_P(PSTR("SuperFX + Sram\n")); break; case 0x34: - info_P(STR_SA); + info_P(PSTR("SA-1")); break; case 0x35: - info_P(STR_SA); + info_P(PSTR("SA-1")); break; default: info_P(PSTR("Unkown 0x%02x\n"),c); break; } arg1 = ( 2 << ( sram_read(0xffd7 - offset) - 1 )); - info_P(PSTR("ROM 0x%04x %i MBit ( %i KiB)\n"), (0xffd7 - offset),arg1, ((arg1 / 1024) * 8) ); + info_P(PSTR("ROM 0x%04x %li MBit ( %li KiB)\n"), (0xffd7 - offset), (arg1 / 128), arg1); arg1 = ( 2 << ( sram_read(0xffd8 - offset) - 1 )); - info_P(PSTR("RAM 0x%04x %i MBit ( %i KiB)\n"), (0xffd8 - offset),arg1, ((arg1 / 1024) * 8) ); + info_P(PSTR("RAM 0x%04x %li KiB\n"), (0xffd8 - offset), arg1); - info_P(PSTR("CCODE 0x%04x \n"), (0xffd9 - offset)); + info_P(PSTR("CCODE 0x%04x "), (0xffd9 - offset)); c = sram_read(0xffd9 - offset); if (c==0x00 || c==0x01 || 0x0d ) info_P(PSTR("NTSC\n")); @@ -488,4 +490,4 @@ void shell_run(void) prompt(); } - +#endif diff --git a/quickdev16.tmproj b/quickdev16.tmproj index ba0bfc0..cbb97d9 100644 --- a/quickdev16.tmproj +++ b/quickdev16.tmproj @@ -3,7 +3,7 @@ currentDocument - avr/usbload/main.c + avr/usbload/shell.c documents @@ -21,33 +21,75 @@ 271 metaData + avr/usbload/Makefile + + caret + + column + 10 + line + 86 + + firstVisibleColumn + 0 + firstVisibleLine + 45 + avr/usbload/command.c caret column - 18 + 1 line - 42 + 100 firstVisibleColumn 0 firstVisibleLine - 95 + 122 - avr/usbload/command.h + avr/usbload/config.h caret column - 26 + 37 line - 30 + 54 firstVisibleColumn 0 firstVisibleLine + 7 + + avr/usbload/crc.c + + caret + + column + 0 + line + 59 + + firstVisibleColumn 0 + firstVisibleLine + 34 + + avr/usbload/debug.c + + caret + + column + 5 + line + 26 + + firstVisibleColumn + 0 + firstVisibleLine + 1 avr/usbload/irq.c @@ -56,86 +98,112 @@ column 0 line - 54 + 39 + columnSelection + firstVisibleColumn 0 firstVisibleLine - 26 + 23 + selectFrom + + column + 0 + line + 38 + + selectTo + + column + 0 + line + 39 + avr/usbload/main.c caret column - 18 + 0 line - 269 + 330 - columnSelection - firstVisibleColumn 0 firstVisibleLine - 247 - selectFrom - - column - 8 - line - 269 - - selectTo - - column - 23 - line - 269 - + 281 - avr/usbload/system.c + avr/usbload/shared_memory.c + + caret + + column + 26 + line + 247 + + firstVisibleColumn + 0 + firstVisibleLine + 222 + + avr/usbload/shell.c + + caret + + column + 83 + line + 444 + + firstVisibleColumn + 0 + firstVisibleLine + 409 + + avr/usbload/shell.h + + caret + + column + 22 + line + 23 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + avr/usbload/sram.c caret column 0 line - 119 + 321 firstVisibleColumn 0 firstVisibleLine - 78 + 288 - avr/usbload/system.h + avr/usbload/sram.h caret column - 12 + 23 line - 33 + 208 - columnSelection - firstVisibleColumn 0 firstVisibleLine - 1 - selectFrom - - column - 9 - line - 33 - - selectTo - - column - 19 - line - 33 - + 175 scripts/conv_rle.py @@ -151,6 +219,34 @@ firstVisibleLine 49 + scripts/conv_zip.py + + caret + + column + 46 + line + 22 + + firstVisibleColumn + 0 + firstVisibleLine + 6 + + scripts/zip2raw.rb + + caret + + column + 0 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 95 + snes/banktest/LoadGraphics.asm caret @@ -184,10 +280,18 @@ scripts/conv_rle.py avr/usbload/main.c - avr/usbload/command.h - avr/usbload/system.c - avr/usbload/system.h + avr/usbload/shell.h + avr/usbload/shell.c + scripts/conv_zip.py + avr/usbload/Makefile + scripts/zip2raw.rb + avr/usbload/shared_memory.c + avr/usbload/sram.h + avr/usbload/sram.c avr/usbload/command.c + avr/usbload/crc.c + avr/usbload/config.h + avr/usbload/debug.c avr/usbload/irq.c showFileHierarchyDrawer @@ -237,7 +341,15 @@ isExpanded subItems - + + webpy + + isExpanded + + subItems + + + snes diff --git a/scripts/conv_zip.py b/scripts/conv_zip.py index 62bef05..384ec05 100644 --- a/scripts/conv_zip.py +++ b/scripts/conv_zip.py @@ -9,14 +9,19 @@ huffman = False TARGET=os.getcwd() SOURCE=sys.argv[1] DEFLATE=os.path.basename(sys.argv[1]) + ".deflate" +PATH="/Users/david/Devel/arch/avr/code/quickdev16/scripts" +WINE="/Applications/Darwine/Wine.bundle/Contents/bin/wine" +KZIP=os.path.join(PATH,"kzip.exe") +DEFLOPT=os.path.join(PATH,"DeflOpt.exe") +ZIP2RAW=os.path.join(PATH,"zip2raw.rb") if os.path.isfile("rom.zip"): os.unlink("rom.zip") -os.system("wine kzip.exe rom /s1 %s" % SOURCE) -os.system("wine DeflOpt.exe /a rom.zip") -os.system("ruby zip2raw.rb rom.zip") +os.system("%s %s rom /s1 %s" % (WINE,KZIP,SOURCE)) +os.system("%s %s /a rom.zip" % (WINE,DEFLOPT)) +os.system("ruby %s rom.zip" % ZIP2RAW) if os.path.isfile("rom.zip"): os.unlink("rom.zip")