Compare commits
30 Commits
quickdev16
...
progmem
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3928f5548e | ||
|
|
b8a45b6a38 | ||
|
|
bc08b4a71a | ||
|
|
bb1367c243 | ||
|
|
710aa2d53a | ||
|
|
9908f32103 | ||
|
|
2a143d3d9f | ||
|
|
72678f3ed5 | ||
|
|
3381998d0f | ||
|
|
98c470dbc0 | ||
|
|
cd948a94d1 | ||
|
|
346216ceb8 | ||
|
|
4bd3876adc | ||
|
|
c6e27c7c1f | ||
|
|
44df97f81a | ||
|
|
b1db3f6ae0 | ||
|
|
f273b986c1 | ||
|
|
bb209bb464 | ||
|
|
507957f7cc | ||
|
|
a741a2ff3a | ||
|
|
ba7f2dd94b | ||
|
|
4fa167a61d | ||
|
|
b375b0d510 | ||
|
|
ced4b73075 | ||
|
|
0887e64266 | ||
|
|
34ed695dee | ||
|
|
d8eb1eb4a4 | ||
|
|
d67158f523 | ||
|
|
ce327a382e | ||
|
|
ba27b79bb3 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -27,3 +27,12 @@
|
|||||||
*.vfat
|
*.vfat
|
||||||
*.wla*
|
*.wla*
|
||||||
*.rcc
|
*.rcc
|
||||||
|
*.log
|
||||||
|
bootloader
|
||||||
|
snesuploader
|
||||||
|
tmtags
|
||||||
|
bsnes
|
||||||
|
web
|
||||||
|
ucon64.exe
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ clean:
|
|||||||
|
|
||||||
.PHONY: all clean interactive-isp interactive-serial launch-bootloader
|
.PHONY: all clean interactive-isp interactive-serial launch-bootloader
|
||||||
|
|
||||||
flash:
|
flash: bootloader.hex
|
||||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -U flash:w:$<
|
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -U flash:w:$<
|
||||||
|
|
||||||
flash-eeprom-%: %.eep.hex
|
flash-eeprom-%: %.eep.hex
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
boot_page_erase(flash_address.word);
|
boot_page_erase(flash_address.word);
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
uart_puts("\n\r");
|
uart_puts("\n\rWrite Flash");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -406,9 +406,10 @@ void leave_bootloader(void)
|
|||||||
* disconnect usb
|
* disconnect usb
|
||||||
*/
|
*/
|
||||||
usbDeviceDisconnect();
|
usbDeviceDisconnect();
|
||||||
|
#if 0
|
||||||
for (uint8_t i = 0; i < 50; i++)
|
for (uint8_t i = 0; i < 50; i++)
|
||||||
_delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
_delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* enable watchdog to soft-reset the uC for clean startup of new application
|
* enable watchdog to soft-reset the uC for clean startup of new application
|
||||||
*/
|
*/
|
||||||
@@ -421,6 +422,13 @@ void leave_bootloader(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void banner(){
|
||||||
|
uart_puts("\n\r");
|
||||||
|
uart_puts("\n\r");
|
||||||
|
uart_puts("\n\r");
|
||||||
|
uart_puts("Quickdev16 Bootloader v0.2\n\r");
|
||||||
|
uart_puts("www.optixx.org\n\r");
|
||||||
|
}
|
||||||
|
|
||||||
int __attribute__ ((noreturn, OS_main)) main(void)
|
int __attribute__ ((noreturn, OS_main)) main(void)
|
||||||
{
|
{
|
||||||
@@ -441,12 +449,12 @@ int __attribute__ ((noreturn, OS_main)) main(void)
|
|||||||
uint16_t delay = 0;
|
uint16_t delay = 0;
|
||||||
timeout = TIMEOUT;
|
timeout = TIMEOUT;
|
||||||
|
|
||||||
uart_puts("Snesram Bootloader v0.1\n\r");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if power-on reset, quit bootloader via watchdog reset
|
* if power-on reset, quit bootloader via watchdog reset
|
||||||
*/
|
*/
|
||||||
if (reset & _BV(PORF)) {
|
if (reset & _BV(PORF)) {
|
||||||
|
banner();
|
||||||
uart_puts("Found power on reset\n\r");
|
uart_puts("Found power on reset\n\r");
|
||||||
MCUSR = 0;
|
MCUSR = 0;
|
||||||
leave_bootloader();
|
leave_bootloader();
|
||||||
@@ -458,15 +466,11 @@ int __attribute__ ((noreturn, OS_main)) main(void)
|
|||||||
uart_puts("Found watchdog reset\n\r");
|
uart_puts("Found watchdog reset\n\r");
|
||||||
MCUSR = 0;
|
MCUSR = 0;
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
DLED_TGL;
|
uart_puts("Jump to 0x0000\n\r");
|
||||||
_delay_ms(500);
|
|
||||||
DLED_TGL;
|
|
||||||
_delay_ms(500);
|
|
||||||
uart_puts("Jump to main\n\r");
|
|
||||||
jump_to_app();
|
jump_to_app();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
banner();
|
||||||
uart_puts("Enter programming mode\n\r");
|
uart_puts("Enter programming mode\n\r");
|
||||||
/*
|
/*
|
||||||
* else: enter programming mode
|
* else: enter programming mode
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ ifeq ($(DEBUG),1)
|
|||||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \
|
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 \
|
main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \
|
||||||
dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \
|
dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \
|
||||||
command.o testing.o
|
irq.o command.o testing.o
|
||||||
else
|
else
|
||||||
LDFLAGS = -Wl,-u
|
LDFLAGS = -Wl,-u
|
||||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO
|
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO
|
||||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o \
|
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 dump.o timer.o watchdog.o rle.c loader.o \
|
uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o \
|
||||||
info.o shared_memory.o command.o
|
info.o shared_memory.o command.o irq.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -26,18 +27,21 @@
|
|||||||
#include "requests.h"
|
#include "requests.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
#include "irq.h"
|
||||||
|
|
||||||
extern uint32_t req_bank_size;
|
extern uint32_t req_bank_size;
|
||||||
|
|
||||||
|
|
||||||
void send_reset()
|
void send_reset()
|
||||||
{
|
{
|
||||||
info("Reset Snes\n");
|
info_P(PSTR("Reset SNES\n"));
|
||||||
|
cli();
|
||||||
snes_reset_on();
|
snes_reset_on();
|
||||||
snes_reset_lo();
|
snes_reset_lo();
|
||||||
_delay_ms(2);
|
_delay_ms(2);
|
||||||
snes_reset_hi();
|
snes_reset_hi();
|
||||||
snes_reset_off();
|
snes_reset_off();
|
||||||
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_irq()
|
void send_irq()
|
||||||
@@ -53,9 +57,9 @@ void set_rom_mode()
|
|||||||
{
|
{
|
||||||
if (req_bank_size == 0x8000) {
|
if (req_bank_size == 0x8000) {
|
||||||
snes_lorom();
|
snes_lorom();
|
||||||
info("Set Snes lowrom \n");
|
info_P(PSTR("Set SNES lowrom \n"));
|
||||||
} else {
|
} else {
|
||||||
snes_hirom();
|
snes_hirom();
|
||||||
info("Set Snes hirom \n");
|
info_P(PSTR("Set SNES hirom \n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@
|
|||||||
#define USB_CRC_CHECK 0x01
|
#define USB_CRC_CHECK 0x01
|
||||||
|
|
||||||
#define TRANSFER_BUFFER_SIZE 0x200
|
#define TRANSFER_BUFFER_SIZE 0x200
|
||||||
|
#define FORMAT_BUFFER_LEN 0x0FF
|
||||||
|
#define HW_VERSION "2.6"
|
||||||
|
#define SW_VERSION "1.0"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
|
|||||||
uint32_t addr = 0;
|
uint32_t addr = 0;
|
||||||
uint8_t req_bank = 0;
|
uint8_t req_bank = 0;
|
||||||
sram_bulk_read_start(bottom_addr);
|
sram_bulk_read_start(bottom_addr);
|
||||||
debug(DEBUG_CRC,"crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n",
|
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n"),
|
||||||
bottom_addr,top_addr);
|
bottom_addr,top_addr);
|
||||||
|
|
||||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
if (addr && addr % bank_size == 0) {
|
if (addr && addr % bank_size == 0) {
|
||||||
debug(DEBUG_CRC,"crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n",
|
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
||||||
req_bank,addr,crc);
|
req_bank,addr,crc);
|
||||||
req_bank++;
|
req_bank++;
|
||||||
crc = 0;
|
crc = 0;
|
||||||
@@ -85,7 +85,7 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
|
|||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
}
|
}
|
||||||
if (addr % 0x8000 == 0)
|
if (addr % 0x8000 == 0)
|
||||||
debug(DEBUG_CRC,"crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n",
|
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
||||||
req_bank,addr,crc);
|
req_bank,addr,crc);
|
||||||
sram_bulk_read_end();
|
sram_bulk_read_end();
|
||||||
return crc;
|
return crc;
|
||||||
|
|||||||
@@ -20,11 +20,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
@@ -46,4 +46,23 @@ void debug(int level, char* format, ...) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_INFO
|
||||||
|
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
|
#else
|
||||||
|
void debug_P(int level, PGM_P format, ...) {
|
||||||
|
#ifdef NO_DEBUG
|
||||||
|
|
||||||
|
#else
|
||||||
|
va_list args;
|
||||||
|
if (!(debug_level & level))
|
||||||
|
return;
|
||||||
|
strlcpy_P(buffer_debug,format,FORMAT_BUFFER_LEN);
|
||||||
|
va_start(args, format);
|
||||||
|
vprintf(buffer_debug, args);
|
||||||
|
va_end(args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
@@ -39,5 +39,17 @@ void debug(int level, char *format, ...);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
|
arguments. We use this extension here to preprocess pmesg away. */
|
||||||
|
#define debug_P(level, format, args...) ((void)0)
|
||||||
|
#else
|
||||||
|
void debug_P(int level, PGM_P format, ...);
|
||||||
|
/* print a message, if it is considered significant enough.
|
||||||
|
Adapted from [K&R2], p. 174 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* DEBUG_H */
|
#endif /* DEBUG_H */
|
||||||
|
|
||||||
|
|||||||
@@ -47,21 +47,21 @@ void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (clear) {
|
if (clear) {
|
||||||
info("*\n");
|
info_P(PSTR("*\n"));
|
||||||
clear = 0;
|
clear = 0;
|
||||||
}
|
}
|
||||||
info("%08lx:", addr + i);
|
info_P(PSTR("%08lx:"), addr + i);
|
||||||
for (j = 0; j < 16; j++) {
|
for (j = 0; j < 16; j++) {
|
||||||
info(" %02x", packet[i + j]);
|
info_P(PSTR(" %02x"), packet[i + j]);
|
||||||
}
|
}
|
||||||
info(" |");
|
info_P(PSTR(" |"));
|
||||||
for (j = 0; j < 16; j++) {
|
for (j = 0; j < 16; j++) {
|
||||||
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||||
info("%c", packet[i + j]);
|
info_P(PSTR("%c"), packet[i + j]);
|
||||||
else
|
else
|
||||||
info(".");
|
info_P(PSTR("."));
|
||||||
}
|
}
|
||||||
info("|\n");
|
info_P(PSTR("|\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +72,11 @@ void dump_memory(uint32_t bottom_addr, uint32_t top_addr)
|
|||||||
sram_bulk_read_start(bottom_addr);
|
sram_bulk_read_start(bottom_addr);
|
||||||
for ( addr = bottom_addr; addr < top_addr; addr++) {
|
for ( addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
if (addr%0x10 == 0)
|
if (addr%0x10 == 0)
|
||||||
info("\n%08lx:", addr);
|
info_P(PSTR("\n%08lx:"), addr);
|
||||||
byte = sram_bulk_read();
|
byte = sram_bulk_read();
|
||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
info(" %02x", byte);
|
info_P(PSTR(" %02x"), byte);
|
||||||
}
|
}
|
||||||
info("\n");
|
info_P(PSTR("\n"));
|
||||||
sram_bulk_read_end();
|
sram_bulk_read_end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,12 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -47,3 +50,25 @@ void info(char* format, ...) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_INFO
|
||||||
|
uint8_t buffer_info[FORMAT_BUFFER_LEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
|
|
||||||
|
#define info(format, args...) ((void)0)
|
||||||
|
|
||||||
|
#else
|
||||||
|
void info_P(PGM_P format, ...) {
|
||||||
|
#ifdef NO_INFO
|
||||||
|
|
||||||
|
#else
|
||||||
|
strlcpy_P(buffer_info,format,FORMAT_BUFFER_LEN);
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vprintf(buffer_info, args);
|
||||||
|
va_end(args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#if defined(NO_INFO) && defined(__GNUC__)
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
@@ -39,4 +39,15 @@ void info(char *format, ...);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
|
arguments. We use this extension here to preprocess pmesg away. */
|
||||||
|
#define info_P(format, args...) ((void)0)
|
||||||
|
#else
|
||||||
|
void info_P(PGM_P format, ...);
|
||||||
|
/* print a message, if it is considered significant enough.
|
||||||
|
Adapted from [K&R2], p. 174 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
72
avr/usbload/irq.c
Normal file
72
avr/usbload/irq.c
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h> /* for sei() */
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "usbdrv.h"
|
||||||
|
#include "oddebug.h" /* This is also an example for using debug
|
||||||
|
* macros */
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "sram.h"
|
||||||
|
|
||||||
|
|
||||||
|
void (*jump_to_app) (void) = 0x0000;
|
||||||
|
|
||||||
|
void irq_init(){
|
||||||
|
cli();
|
||||||
|
PCMSK3 |=(1<<PCINT27);
|
||||||
|
PCICR |= (1<<PCIE3);
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
|
||||||
|
void irq_stop(){
|
||||||
|
cli();
|
||||||
|
PCMSK3 &=~(1<<PCINT27);
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
|
||||||
|
void leave_application(void)
|
||||||
|
{
|
||||||
|
cli();
|
||||||
|
usbDeviceDisconnect();
|
||||||
|
wdt_enable(WDTO_15MS);
|
||||||
|
while (1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ISR (SIG_PIN_CHANGE3)
|
||||||
|
{
|
||||||
|
if (snes_reset_test()){
|
||||||
|
info_P(PSTR("Catch SNES reset button\n"));
|
||||||
|
info_P(PSTR("Set watchdog...\n"));
|
||||||
|
leave_application();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
25
avr/usbload/irq.h
Normal file
25
avr/usbload/irq.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __IRQ_H__
|
||||||
|
#define __IRQ_H__
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,4 +6,6 @@
|
|||||||
#define ROM_HUFFMAN_SIZE 0
|
#define ROM_HUFFMAN_SIZE 0
|
||||||
#define ROM_RLE_SIZE 31091
|
#define ROM_RLE_SIZE 31091
|
||||||
|
|
||||||
|
void irq_init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
extern const char _rom[] PROGMEM;
|
extern const char _rom[] PROGMEM;
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM );
|
uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM);
|
||||||
|
|
||||||
uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
|
uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
|
||||||
uint32_t req_addr = 0;
|
uint32_t req_addr = 0;
|
||||||
@@ -84,7 +84,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
|
|
||||||
req_bank = 0;
|
req_bank = 0;
|
||||||
rx_remaining = 0;
|
rx_remaining = 0;
|
||||||
debug(DEBUG_USB, "USB_BULK_UPLOAD_INIT: %i %i\n", rq->wValue.word,
|
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word,
|
||||||
rq->wIndex.word);
|
rq->wIndex.word);
|
||||||
req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
||||||
req_bank_cnt = rq->wIndex.word;
|
req_bank_cnt = rq->wIndex.word;
|
||||||
@@ -92,8 +92,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
req_percent = 0;
|
req_percent = 0;
|
||||||
req_percent_last = 0;
|
req_percent_last = 0;
|
||||||
sync_errors = 0;
|
sync_errors = 0;
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n",
|
PSTR("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
|
||||||
req_bank_size, req_bank_cnt, req_addr_end);
|
req_bank_size, req_bank_cnt, req_addr_end);
|
||||||
|
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt);
|
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt);
|
||||||
@@ -114,12 +114,12 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
|
|
||||||
if (req_addr && req_addr % req_bank_size == 0) {
|
if (req_addr && req_addr % req_bank_size == 0) {
|
||||||
#ifdef FLT_DEBUG
|
#ifdef FLT_DEBUG
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
|
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
req_bank, req_addr, timer_stop());
|
req_bank, req_addr, timer_stop());
|
||||||
#else
|
#else
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n",
|
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
req_bank, req_addr, timer_stop_int());
|
req_bank, req_addr, timer_stop_int());
|
||||||
#endif
|
#endif
|
||||||
req_bank++;
|
req_bank++;
|
||||||
@@ -145,8 +145,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
|
|
||||||
req_percent = (uint32_t)( 100 * req_addr ) / req_addr_end;
|
req_percent = (uint32_t)( 100 * req_addr ) / req_addr_end;
|
||||||
if (req_percent!=req_percent_last){
|
if (req_percent!=req_percent_last){
|
||||||
//debug(DEBUG_USB,
|
//debug_P(DEBUG_USB,
|
||||||
// "USB_BULK_UPLOAD_ADDR: precent=%i\n", req_percent);
|
// PSTR("USB_BULK_UPLOAD_ADDR: precent=%i\n", req_percent);
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_percent);
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_percent);
|
||||||
sram_bulk_write_start(req_addr);
|
sram_bulk_write_start(req_addr);
|
||||||
}
|
}
|
||||||
@@ -154,8 +154,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (req_addr && (req_addr % 0x1000) == 0) {
|
if (req_addr && (req_addr % 0x1000) == 0) {
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_NEXT: bank=0x%02x addr=0x%08lx crc=%04x\n",
|
PSTR("USB_BULK_UPLOAD_NEXT: bank=0x%02x addr=0x%08lx crc=%04x\n",
|
||||||
req_bank, req_addr, crc_check_bulk_memory(req_addr - 0x1000,
|
req_bank, req_addr, crc_check_bulk_memory(req_addr - 0x1000,
|
||||||
req_addr,
|
req_addr,
|
||||||
req_bank_size));
|
req_bank_size));
|
||||||
@@ -164,21 +164,23 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
sram_bulk_write_start(req_addr);
|
sram_bulk_write_start(req_addr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SHM_SCRATCHPAD
|
||||||
if (!shared_memory_scratchpad_region_save_helper(req_addr)){
|
if (!shared_memory_scratchpad_region_save_helper(req_addr)){
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_NEXT: scratchpad_region_save_helper was dirty\n");
|
PSTR("USB_BULK_UPLOAD_NEXT: scratchpad_region_save_helper was dirty\n"));
|
||||||
sram_bulk_write_start(req_addr);
|
sram_bulk_write_start(req_addr);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (req_addr && (req_addr % req_bank_size) == 0) {
|
if (req_addr && (req_addr % req_bank_size) == 0) {
|
||||||
#ifdef FLT_DEBUG
|
#ifdef FLT_DEBUG
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
|
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
req_bank, req_addr, timer_stop());
|
req_bank, req_addr, timer_stop());
|
||||||
#else
|
#else
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n",
|
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
req_bank, req_addr, timer_stop_int());
|
req_bank, req_addr, timer_stop_int());
|
||||||
#endif
|
#endif
|
||||||
req_bank++;
|
req_bank++;
|
||||||
@@ -193,11 +195,11 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_BULK_UPLOAD_END) {
|
} else if (rq->bRequest == USB_BULK_UPLOAD_END) {
|
||||||
if (req_state != REQ_STATUS_BULK_UPLOAD) {
|
if (req_state != REQ_STATUS_BULK_UPLOAD) {
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n");
|
PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
debug(DEBUG_USB, "USB_BULK_UPLOAD_END:\n");
|
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END:\n"));
|
||||||
req_state = REQ_STATUS_IDLE;
|
req_state = REQ_STATUS_IDLE;
|
||||||
sram_bulk_write_end();
|
sram_bulk_write_end();
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
|
||||||
@@ -210,7 +212,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
req_addr = rq->wValue.word;
|
req_addr = rq->wValue.word;
|
||||||
req_addr = req_addr << 16;
|
req_addr = req_addr << 16;
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
req_addr = req_addr | rq->wIndex.word;
|
||||||
debug(DEBUG_USB, "USB_CRC: addr=0x%08lx \n", req_addr);
|
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), req_addr);
|
||||||
crc_check_bulk_memory(0x000000, req_addr, req_bank_size);
|
crc_check_bulk_memory(0x000000, req_addr, req_bank_size);
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
@@ -218,20 +220,20 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_MODE_SNES) {
|
} else if (rq->bRequest == USB_MODE_SNES) {
|
||||||
req_state = REQ_STATUS_SNES;
|
req_state = REQ_STATUS_SNES;
|
||||||
debug(DEBUG_USB, "USB_MODE_SNES:\n");
|
debug_P(DEBUG_USB, PSTR("USB_MODE_SNES:\n"));
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_MODE_AVR) {
|
} else if (rq->bRequest == USB_MODE_AVR) {
|
||||||
req_state = REQ_STATUS_AVR;
|
req_state = REQ_STATUS_AVR;
|
||||||
debug(DEBUG_USB, "USB_MODE_AVR:\n");
|
debug_P(DEBUG_USB, PSTR("USB_MODE_AVR:\n"));
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_AVR_RESET) {
|
} else if (rq->bRequest == USB_AVR_RESET) {
|
||||||
debug(DEBUG_USB, "USB_AVR_RESET:\n");
|
debug_P(DEBUG_USB, PSTR("USB_AVR_RESET:\n"));
|
||||||
soft_reset();
|
soft_reset();
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
@@ -243,12 +245,12 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
req_addr = rq->wValue.word;
|
req_addr = rq->wValue.word;
|
||||||
req_addr = req_addr << 16;
|
req_addr = req_addr << 16;
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
req_addr = req_addr | rq->wIndex.word;
|
||||||
debug(DEBUG_USB, "USB_CRC_ADDR: addr=0x%lx size=%i\n", req_addr,
|
debug_P(DEBUG_USB, PSTR("USB_CRC_ADDR: addr=0x%lx size=%i\n"), req_addr,
|
||||||
rq->wLength.word);
|
rq->wLength.word);
|
||||||
req_size = rq->wLength.word;
|
req_size = rq->wLength.word;
|
||||||
req_size = req_size << 2;
|
req_size = req_size << 2;
|
||||||
tx_remaining = 2;
|
tx_remaining = 2;
|
||||||
debug(DEBUG_USB, "USB_CRC_ADDR: addr=0x%lx size=%li\n", req_addr,
|
debug_P(DEBUG_USB, PSTR("USB_CRC_ADDR: addr=0x%lx size=%li\n"), req_addr,
|
||||||
req_size);
|
req_size);
|
||||||
|
|
||||||
crc = crc_check_memory_range(req_addr, req_size, read_buffer);
|
crc = crc_check_memory_range(req_addr, req_size, read_buffer);
|
||||||
@@ -271,108 +273,114 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
void usb_connect()
|
void usb_connect()
|
||||||
{
|
{
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
info("USB init\n");
|
info_P(PSTR("USB init\n"));
|
||||||
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
||||||
cli();
|
cli();
|
||||||
info("USB disconnect\n");
|
info_P(PSTR("USB disconnect\n"));
|
||||||
i = 10;
|
i = 10;
|
||||||
while (--i) { /* fake USB disconnect for > 250 ms */
|
while (--i) { /* fake USB disconnect for > 250 ms */
|
||||||
led_on();
|
led_on();
|
||||||
_delay_ms(35);
|
_delay_ms(15);
|
||||||
led_off();
|
led_off();
|
||||||
_delay_ms(65);
|
_delay_ms(35);
|
||||||
}
|
}
|
||||||
led_on();
|
led_on();
|
||||||
usbDeviceConnect();
|
usbDeviceConnect();
|
||||||
info("USB connect\n");
|
info_P(PSTR("USB connect\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void boot_startup_rom()
|
void boot_startup_rom()
|
||||||
{
|
{
|
||||||
|
info_P(PSTR("Boot startup rom\n"));
|
||||||
info("Activate AVR bus\n");
|
info_P(PSTR("Activate AVR bus\n"));
|
||||||
avr_bus_active();
|
avr_bus_active();
|
||||||
info("IRQ off\n");
|
info_P(PSTR("IRQ off\n"));
|
||||||
snes_irq_lo();
|
snes_irq_lo();
|
||||||
snes_irq_off();
|
snes_irq_off();
|
||||||
snes_lorom();
|
snes_lorom();
|
||||||
info("Set Snes lowrom \n");
|
|
||||||
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
|
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
#if 1
|
||||||
dump_memory(0x10000 - 0x100, 0x10000);
|
dump_memory(0x10000 - 0x100, 0x10000);
|
||||||
snes_reset_hi();
|
#endif
|
||||||
snes_reset_off();
|
|
||||||
snes_irq_lo();
|
|
||||||
snes_irq_off();
|
|
||||||
info("IRQ off\n");
|
|
||||||
snes_hirom();
|
snes_hirom();
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
info("Disable snes WR\n");
|
|
||||||
snes_bus_active();
|
snes_bus_active();
|
||||||
info("Activate Snes bus\n");
|
info_P(PSTR("Activate SNES bus\n"));
|
||||||
_delay_ms(20);
|
|
||||||
send_reset();
|
send_reset();
|
||||||
_delay_ms(200);
|
_delay_ms(50);
|
||||||
|
send_reset();
|
||||||
|
_delay_ms(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void banner(){
|
||||||
|
uint8_t i;
|
||||||
|
for (i=0;i<40;i++)
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
info_P(PSTR(" ________ .__ __ ________ ____ ________\n"));
|
||||||
|
info_P(PSTR(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
|
||||||
|
info_P(PSTR(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
|
||||||
|
info_P(PSTR(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
|
||||||
|
info_P(PSTR(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
|
||||||
|
info_P(PSTR(" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
info_P(PSTR(" www.optixx.org\n"));
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void globals_init(){
|
||||||
|
req_addr = 0;
|
||||||
|
req_addr_end = 0;
|
||||||
|
req_state = REQ_STATUS_IDLE;
|
||||||
|
rx_remaining = 0;
|
||||||
|
tx_remaining = 0;
|
||||||
|
sync_errors = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
uart_init();
|
uart_init();
|
||||||
stdout = &uart_stdout;
|
stdout = &uart_stdout;
|
||||||
|
banner();
|
||||||
info("Sytem start\n");
|
|
||||||
system_init();
|
system_init();
|
||||||
|
snes_reset_hi();
|
||||||
#if 0
|
snes_reset_off();
|
||||||
test_read_write();
|
irq_init();
|
||||||
test_bulk_read_write();
|
|
||||||
test_crc();
|
|
||||||
while (1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
info("Boot startup rom\n");
|
|
||||||
boot_startup_rom();
|
boot_startup_rom();
|
||||||
|
globals_init();
|
||||||
|
|
||||||
usbInit();
|
usbInit();
|
||||||
usb_connect();
|
usb_connect();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
avr_bus_active();
|
avr_bus_active();
|
||||||
info("Activate AVR bus\n");
|
info_P(PSTR("Activate AVR bus\n"));
|
||||||
info("IRQ off\n");
|
|
||||||
snes_irq_lo();
|
|
||||||
snes_irq_off();
|
|
||||||
info("Set Snes lowrom\n");
|
|
||||||
snes_lorom();
|
snes_lorom();
|
||||||
info("Disable snes WR\n");
|
info_P(PSTR("Disable SNES WR\n"));
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
sei();
|
sei();
|
||||||
info("USB poll\n");
|
info_P(PSTR("USB poll\n"));
|
||||||
while (req_state != REQ_STATUS_SNES) {
|
while (req_state != REQ_STATUS_SNES) {
|
||||||
usbPoll();
|
usbPoll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
|
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
|
||||||
|
|
||||||
//shared_memory_scratchpad_region_tx_restore();
|
#if SHM_SCRATCHPAD
|
||||||
//shared_memory_scratchpad_region_rx_restore();
|
shared_memory_scratchpad_region_tx_restore();
|
||||||
|
shared_memory_scratchpad_region_rx_restore();
|
||||||
info("USB poll done\n");
|
#endif
|
||||||
|
info_P(PSTR("USB poll done\n"));
|
||||||
set_rom_mode();
|
set_rom_mode();
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
info("Disable snes WR\n");
|
info_P(PSTR("Disable SNES WR\n"));
|
||||||
snes_bus_active();
|
snes_bus_active();
|
||||||
info("Activate Snes bus\n");
|
info_P(PSTR("Activate SNES bus\n"));
|
||||||
_delay_ms(100);
|
irq_stop();
|
||||||
send_reset();
|
send_reset();
|
||||||
|
info_P(PSTR("Poll USB\n"));
|
||||||
info("Poll\n");
|
while ((req_state != REQ_STATUS_AVR)) {
|
||||||
while (req_state != REQ_STATUS_AVR) {
|
|
||||||
usbPoll();
|
usbPoll();
|
||||||
|
|
||||||
#ifdef DO_IRQ
|
#ifdef DO_IRQ
|
||||||
@@ -382,7 +390,7 @@ int main(void)
|
|||||||
while (--i) {
|
while (--i) {
|
||||||
_delay_ms(100);
|
_delay_ms(100);
|
||||||
}
|
}
|
||||||
info("Send IRQ %i\n", ++irq_count);
|
info_P(PSTR("Send IRQ %i\n"), ++irq_count);
|
||||||
send_irq();
|
send_irq();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -393,26 +401,24 @@ int main(void)
|
|||||||
i = 5;
|
i = 5;
|
||||||
while (--i) {
|
while (--i) {
|
||||||
_delay_ms(500);
|
_delay_ms(500);
|
||||||
info("Wait to switch to snes mode %i\n", i);
|
info_P(PSTR("Wait to switch to snes mode %i\n"), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req_bank_size == 0x8000) {
|
if (req_bank_size == 0x8000) {
|
||||||
snes_lorom();
|
snes_lorom();
|
||||||
info("Set Snes lowrom \n");
|
|
||||||
} else {
|
} else {
|
||||||
snes_hirom();
|
snes_hirom();
|
||||||
info("Set Snes hirom \n");
|
|
||||||
}
|
}
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
info("Disable snes WR\n");
|
info_P(PSTR("Disable SNES WR\n"));
|
||||||
snes_bus_active();
|
snes_bus_active();
|
||||||
info("Activate Snes bus\n");
|
info_P(PSTR("Activate SNES bus\n"));
|
||||||
info("Read 0x3000=%c\n", c);
|
info_P(PSTR("Read 0x3000=%c\n"), c);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
info("Boot startup rom\n");
|
irq_init();
|
||||||
boot_startup_rom();
|
boot_startup_rom();
|
||||||
|
globals_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +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;
|
uint8_t in_byte, in_repeat, last_byte;
|
||||||
uint32_t out_len, out_len_left;
|
uint32_t out_len, out_len_left;
|
||||||
info("RLE decode len=%li addr=0x%08lx\n", in_len, out_addr);
|
info_P(PSTR("RLE decode len=%li addr=0x%08lx\n"), in_len, out_addr);
|
||||||
last_byte = 0;
|
last_byte = 0;
|
||||||
|
|
||||||
out_len_left = out_len;
|
out_len_left = out_len;
|
||||||
@@ -63,7 +63,7 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
|||||||
if (in_byte == RUNCHAR) {
|
if (in_byte == RUNCHAR) {
|
||||||
INBYTE(in_repeat);
|
INBYTE(in_repeat);
|
||||||
if (in_repeat != 0) {
|
if (in_repeat != 0) {
|
||||||
info("Orphaned RLE code at start\n");
|
info_P(PSTR("Orphaned RLE code at start\n"));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
OUTBYTE(RUNCHAR);
|
OUTBYTE(RUNCHAR);
|
||||||
@@ -74,7 +74,7 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
|||||||
while (in_len > 0) {
|
while (in_len > 0) {
|
||||||
INBYTE(in_byte);
|
INBYTE(in_byte);
|
||||||
if (in_len % 1024 == 0)
|
if (in_len % 1024 == 0)
|
||||||
info(".");
|
info_P(PSTR("."));
|
||||||
if (in_byte == RUNCHAR) {
|
if (in_byte == RUNCHAR) {
|
||||||
INBYTE(in_repeat);
|
INBYTE(in_repeat);
|
||||||
if (in_repeat == 0) {
|
if (in_repeat == 0) {
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ uint8_t scratchpad_locked_tx = 1;
|
|||||||
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
||||||
|
|
||||||
if(addr > (SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE) && scratchpad_locked_tx){
|
if(addr > (SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE) && scratchpad_locked_tx){
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n",addr);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),addr);
|
||||||
shared_memory_scratchpad_region_tx_save();
|
shared_memory_scratchpad_region_tx_save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(addr > (SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE) && scratchpad_locked_rx){
|
if(addr > (SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE) && scratchpad_locked_rx){
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n",addr);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),addr);
|
||||||
shared_memory_scratchpad_region_rx_save();
|
shared_memory_scratchpad_region_rx_save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -64,14 +64,14 @@ uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
|||||||
|
|
||||||
void shared_memory_scratchpad_region_tx_save()
|
void shared_memory_scratchpad_region_tx_save()
|
||||||
{
|
{
|
||||||
#if 1
|
#if 0
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
||||||
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: unlock\n");
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: unlock\n"));
|
||||||
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
||||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||||
scratchpad_locked_tx = 0;
|
scratchpad_locked_tx = 0;
|
||||||
@@ -86,14 +86,14 @@ void shared_memory_scratchpad_region_tx_save()
|
|||||||
|
|
||||||
void shared_memory_scratchpad_region_rx_save()
|
void shared_memory_scratchpad_region_rx_save()
|
||||||
{
|
{
|
||||||
#if 1
|
#if 0
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
||||||
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_rx_save: unlock\n");
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: unlock\n"));
|
||||||
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||||
scratchpad_locked_rx = 0;
|
scratchpad_locked_rx = 0;
|
||||||
@@ -109,7 +109,7 @@ void shared_memory_scratchpad_region_tx_restore()
|
|||||||
if (scratchpad_locked_tx)
|
if (scratchpad_locked_tx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_restore: lock\n");
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: lock\n"));
|
||||||
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
||||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||||
scratchpad_locked_tx = 1;
|
scratchpad_locked_tx = 1;
|
||||||
@@ -118,11 +118,11 @@ void shared_memory_scratchpad_region_tx_restore()
|
|||||||
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
||||||
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_restore: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: crc=%x\n"),crc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ void shared_memory_scratchpad_region_rx_restore()
|
|||||||
{
|
{
|
||||||
if (scratchpad_locked_rx)
|
if (scratchpad_locked_rx)
|
||||||
return;
|
return;
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: lock\n");
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: lock\n"));
|
||||||
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||||
scratchpad_locked_rx = 1;
|
scratchpad_locked_rx = 1;
|
||||||
@@ -145,7 +145,7 @@ void shared_memory_scratchpad_region_rx_restore()
|
|||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
||||||
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_rx_restore: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: crc=%x\n"),crc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,9 +183,9 @@ void shared_memory_write(uint8_t cmd, uint8_t value)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (scratchpad_locked_tx)
|
if (scratchpad_locked_tx)
|
||||||
debug(DEBUG_SHM,"shared_memory_write: locked_tx\n");
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||||
|
|
||||||
debug(DEBUG_SHM,"shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n",
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
||||||
SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value);
|
SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value);
|
||||||
|
|
||||||
sram_bulk_addr_save();
|
sram_bulk_addr_save();
|
||||||
@@ -241,7 +241,7 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
|||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
|
||||||
if (scratchpad_locked_rx)
|
if (scratchpad_locked_rx)
|
||||||
debug(DEBUG_SHM,"shared_memory_write: locked_tx\n");
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||||
|
|
||||||
|
|
||||||
state = sram_read(SHARED_MEM_RX_LOC_STATE);
|
state = sram_read(SHARED_MEM_RX_LOC_STATE);
|
||||||
@@ -252,7 +252,7 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
|||||||
|
|
||||||
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
|
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
|
||||||
*len = sram_read(SHARED_MEM_RX_LOC_LEN);
|
*len = sram_read(SHARED_MEM_RX_LOC_LEN);
|
||||||
debug(DEBUG_SHM,"shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n",
|
debug_P(DEBUG_SHM, PSTR("shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
||||||
SHARED_MEM_RX_LOC_CMD, *cmd, SHARED_MEM_RX_LOC_LEN, *len);
|
SHARED_MEM_RX_LOC_CMD, *cmd, SHARED_MEM_RX_LOC_LEN, *len);
|
||||||
|
|
||||||
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD,buffer, *len);
|
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD,buffer, *len);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
#define SHARED_MEM_TX_CMD_TERMINATE 0x06
|
#define SHARED_MEM_TX_CMD_TERMINATE 0x06
|
||||||
|
|
||||||
#define SHARED_MEM_TX_LOC_STATE 0x000000
|
#define SHARED_MEM_TX_LOC_STATE 0x000000
|
||||||
#define SHARED_MEM_TX_LOC_SIZE 0x000100
|
#define SHARED_MEM_TX_LOC_SIZE 0x000040
|
||||||
#define SHARED_MEM_TX_LOC_CMD 0x000001
|
#define SHARED_MEM_TX_LOC_CMD 0x000001
|
||||||
#define SHARED_MEM_TX_LOC_PAYLOAD 0x000002
|
#define SHARED_MEM_TX_LOC_PAYLOAD 0x000002
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
#define SHARED_MEM_RX_CMD_FILESEL 0x01
|
#define SHARED_MEM_RX_CMD_FILESEL 0x01
|
||||||
|
|
||||||
#define SHARED_MEM_RX_LOC_STATE 0x001000
|
#define SHARED_MEM_RX_LOC_STATE 0x001000
|
||||||
#define SHARED_MEM_RX_LOC_SIZE 0x000100
|
#define SHARED_MEM_RX_LOC_SIZE 0x000040
|
||||||
#define SHARED_MEM_RX_LOC_CMD 0x001001
|
#define SHARED_MEM_RX_LOC_CMD 0x001001
|
||||||
#define SHARED_MEM_RX_LOC_LEN 0x001002
|
#define SHARED_MEM_RX_LOC_LEN 0x001002
|
||||||
#define SHARED_MEM_RX_LOC_PAYLOAD 0x001003
|
#define SHARED_MEM_RX_LOC_PAYLOAD 0x001003
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
uint32_t addr_current = 0;
|
uint32_t addr_current = 0;
|
||||||
uint32_t addr_stash = 0;
|
uint32_t addr_stash = 0;
|
||||||
|
|
||||||
|
|
||||||
void system_init(void)
|
void system_init(void)
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
@@ -48,18 +47,17 @@ void system_init(void)
|
|||||||
| (1 << AVR_ADDR_SCK_PIN)
|
| (1 << AVR_ADDR_SCK_PIN)
|
||||||
| (1 << AVR_ADDR_SER_PIN)
|
| (1 << AVR_ADDR_SER_PIN)
|
||||||
| (1 << AVR_ADDR_LOAD_PIN)
|
| (1 << AVR_ADDR_LOAD_PIN)
|
||||||
| (1 << AVR_ADDR_DOWN_PIN)
|
|
||||||
| (1 << AVR_ADDR_UP_PIN));
|
| (1 << AVR_ADDR_UP_PIN));
|
||||||
|
|
||||||
DDRC &= ~ (1 << SNES_WR_PIN);
|
DDRC &= ~ ((1 << SNES_WR_PIN)
|
||||||
|
| (1 << AVR_BTLDR_EN_PIN));
|
||||||
|
|
||||||
PORTC &= ~((1 << AVR_ADDR_LATCH_PIN)
|
PORTC &= ~((1 << AVR_ADDR_LATCH_PIN)
|
||||||
| (1 << AVR_ADDR_SCK_PIN)
|
| (1 << AVR_ADDR_SCK_PIN)
|
||||||
| (1 << SNES_WR_PIN));
|
| (1 << SNES_WR_PIN));
|
||||||
|
|
||||||
|
|
||||||
PORTC |= ( (1 << AVR_ADDR_DOWN_PIN)
|
PORTC |= ( (1 << AVR_ADDR_UP_PIN)
|
||||||
| (1 << AVR_ADDR_UP_PIN)
|
|
||||||
| (1 << AVR_ADDR_LOAD_PIN));
|
| (1 << AVR_ADDR_LOAD_PIN));
|
||||||
|
|
||||||
//| (1 << SNES_WR_PIN));
|
//| (1 << SNES_WR_PIN));
|
||||||
@@ -93,23 +91,22 @@ void system_init(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sreg_set(uint32_t addr)
|
void sreg_set(uint32_t addr)
|
||||||
{
|
{
|
||||||
uint8_t i = 24;
|
uint8_t i = 24;
|
||||||
debug(DEBUG_SREG,"sreg_set: addr=0x%08lx",addr);
|
debug_P(DEBUG_SREG, PSTR("sreg_set: addr=0x%08lx"),addr);
|
||||||
while(i--) {
|
while(i--) {
|
||||||
if ((addr & ( 1L << i))){
|
if ((addr & ( 1L << i))){
|
||||||
debug(DEBUG_SREG,"1");
|
debug_P(DEBUG_SREG, PSTR("1"));
|
||||||
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
||||||
} else {
|
} else {
|
||||||
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
||||||
debug(DEBUG_SREG,"0");
|
debug_P(DEBUG_SREG, PSTR("0"));
|
||||||
}
|
}
|
||||||
AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
|
AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
|
||||||
AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
|
AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
|
||||||
}
|
}
|
||||||
debug(DEBUG_SREG,"\n");
|
debug_P(DEBUG_SREG, PSTR("\n"));
|
||||||
AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
|
AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
|
||||||
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);
|
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);
|
||||||
|
|
||||||
@@ -130,7 +127,7 @@ inline void sram_bulk_addr_restore()
|
|||||||
|
|
||||||
void sram_bulk_read_start(uint32_t addr)
|
void sram_bulk_read_start(uint32_t addr)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_read_start: addr=0x%08lx\n\r", addr);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_read_start: addr=0x%08lx\n\r"), addr);
|
||||||
|
|
||||||
addr_current = addr;
|
addr_current = addr;
|
||||||
|
|
||||||
@@ -176,7 +173,7 @@ inline uint8_t sram_bulk_read(void)
|
|||||||
|
|
||||||
void sram_bulk_read_end(void)
|
void sram_bulk_read_end(void)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_read_end:\n");
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_read_end:\n"));
|
||||||
|
|
||||||
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
@@ -186,7 +183,7 @@ void sram_bulk_read_end(void)
|
|||||||
uint8_t sram_read(uint32_t addr)
|
uint8_t sram_read(uint32_t addr)
|
||||||
{
|
{
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
debug(DEBUG_SRAM_RAW,"sram_read: addr=0x%08lx\n\r", addr);
|
debug_P(DEBUG_SRAM_RAW, PSTR("sram_read: addr=0x%08lx\n\r"), addr);
|
||||||
|
|
||||||
avr_data_in();
|
avr_data_in();
|
||||||
|
|
||||||
@@ -218,7 +215,7 @@ uint8_t sram_read(uint32_t addr)
|
|||||||
|
|
||||||
void sram_bulk_write_start(uint32_t addr)
|
void sram_bulk_write_start(uint32_t addr)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_write_start: addr=0x%08lx\n\r", addr);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_write_start: addr=0x%08lx\n\r"), addr);
|
||||||
|
|
||||||
avr_data_out();
|
avr_data_out();
|
||||||
|
|
||||||
@@ -246,7 +243,7 @@ inline void sram_bulk_write( uint8_t data)
|
|||||||
|
|
||||||
void sram_bulk_write_end(void)
|
void sram_bulk_write_end(void)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_write_end:");
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_write_end:"));
|
||||||
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
avr_data_in();
|
avr_data_in();
|
||||||
@@ -255,7 +252,7 @@ void sram_bulk_write_end(void)
|
|||||||
|
|
||||||
void sram_write(uint32_t addr, uint8_t data)
|
void sram_write(uint32_t addr, uint8_t data)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM_RAW,"sram_write: addr=0x%08lx data=%x\n\r", addr, data);
|
debug_P(DEBUG_SRAM_RAW, PSTR("sram_write: addr=0x%08lx data=%x\n\r"), addr, data);
|
||||||
|
|
||||||
avr_data_out();
|
avr_data_out();
|
||||||
|
|
||||||
@@ -289,7 +286,7 @@ void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len)
|
|||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint8_t *ptr = src;
|
uint8_t *ptr = src;
|
||||||
debug(DEBUG_SRAM,"sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r",
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r"),
|
||||||
addr, src, len);
|
addr, src, len);
|
||||||
sram_bulk_write_start(addr);
|
sram_bulk_write_start(addr);
|
||||||
for (i = addr; i < (addr + len); i++){
|
for (i = addr; i < (addr + len); i++){
|
||||||
@@ -304,7 +301,7 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
|||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint8_t *ptr = dst;
|
uint8_t *ptr = dst;
|
||||||
debug(DEBUG_SRAM,"sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r",
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r"),
|
||||||
addr, dst, len);
|
addr, dst, len);
|
||||||
sram_bulk_read_start(addr);
|
sram_bulk_read_start(addr);
|
||||||
for (i = addr; i < (addr + len); i++) {
|
for (i = addr; i < (addr + len); i++) {
|
||||||
@@ -317,11 +314,11 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
|||||||
|
|
||||||
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
debug(DEBUG_SRAM,"sram_bulk_set: addr=0x%08lx len=%li\n\r", addr,len);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_set: addr=0x%08lx len=%li\n\r"), addr,len);
|
||||||
sram_bulk_write_start(addr);
|
sram_bulk_write_start(addr);
|
||||||
for (i = addr; i < (addr + len); i++) {
|
for (i = addr; i < (addr + len); i++) {
|
||||||
if (0 == i % 0xfff)
|
if (0 == i % 0xfff)
|
||||||
debug(DEBUG_SRAM,"sram_bulk_set: addr=0x%08lx\n\r", i);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_set: addr=0x%08lx\n\r"), i);
|
||||||
sram_bulk_write(value);
|
sram_bulk_write(value);
|
||||||
sram_bulk_write_next();
|
sram_bulk_write_next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,6 @@
|
|||||||
|
|
||||||
#define avr_data_out() (AVR_DATA_DIR = 0xff)
|
#define avr_data_out() (AVR_DATA_DIR = 0xff)
|
||||||
|
|
||||||
#define LED_PORT PORTC
|
|
||||||
#define LED_DIR DDRC
|
|
||||||
#define LED_PIN PC7
|
|
||||||
|
|
||||||
#define led_on() ((LED_PORT &=~ (1 << LED_PIN)),\
|
|
||||||
(LED_DIR &=~ (1 << LED_PIN)))
|
|
||||||
#define led_off() ((LED_PORT &=~ (1 << LED_PIN)),\
|
|
||||||
(LED_DIR |= (1 << LED_PIN)))
|
|
||||||
|
|
||||||
/* ---------------------------- PORT B ---------------------------- */
|
/* ---------------------------- PORT B ---------------------------- */
|
||||||
|
|
||||||
@@ -85,17 +77,6 @@
|
|||||||
#define snes_irq_off() (SNES_IRQ_DIR &= ~(1 << SNES_IRQ_PIN))
|
#define snes_irq_off() (SNES_IRQ_DIR &= ~(1 << SNES_IRQ_PIN))
|
||||||
#define snes_irq_lo() (SNES_IRQ_PORT &= ~(1 << SNES_IRQ_PIN))
|
#define snes_irq_lo() (SNES_IRQ_PORT &= ~(1 << SNES_IRQ_PIN))
|
||||||
|
|
||||||
#define SNES_RESET_PORT PORTB
|
|
||||||
#define SNES_RESET_DIR DDRB
|
|
||||||
#define SNES_RESET_PIN PB4
|
|
||||||
|
|
||||||
|
|
||||||
#define snes_reset_on() (SNES_RESET_DIR |= (1 << SNES_RESET_PIN))
|
|
||||||
#define snes_reset_hi() (SNES_RESET_PORT |= (1 << SNES_RESET_PIN))
|
|
||||||
|
|
||||||
#define snes_reset_off() (SNES_RESET_DIR &= ~(1 << SNES_RESET_PIN))
|
|
||||||
#define snes_reset_lo() (SNES_RESET_PORT &= ~(1 << SNES_RESET_PIN))
|
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- PORT C ---------------------------- */
|
/* ---------------------------- PORT C ---------------------------- */
|
||||||
|
|
||||||
@@ -129,12 +110,12 @@
|
|||||||
#define counter_load() ((AVR_ADDR_LOAD_PORT &= ~(1 << AVR_ADDR_LOAD_PIN)),\
|
#define counter_load() ((AVR_ADDR_LOAD_PORT &= ~(1 << AVR_ADDR_LOAD_PIN)),\
|
||||||
(AVR_ADDR_LOAD_PORT |= (1 << AVR_ADDR_LOAD_PIN)))
|
(AVR_ADDR_LOAD_PORT |= (1 << AVR_ADDR_LOAD_PIN)))
|
||||||
|
|
||||||
#define AVR_ADDR_DOWN_PORT PORTC
|
#define AVR_BTLDR_EN_PORT PORTC
|
||||||
#define AVR_ADDR_DOWN_DIR DDRC
|
#define AVR_BTLDR_EN_DIR DDRC
|
||||||
#define AVR_ADDR_DOWN_PIN PC1
|
#define AVR_BTLDR_EN_PIN PC1
|
||||||
|
|
||||||
#define counter_down() ((AVR_ADDR_DOWN_PORT &= ~(1 << AVR_ADDR_DOWN_PIN)),\
|
#define btldr_down() ((AVR_BTLDR_EN_PORT &= ~(1 << AVR_BTLDR_EN_PIN)),\
|
||||||
(AVR_ADDR_DOWN_PORT |= (1 << AVR_ADDR_DOWN_PIN)))
|
(AVR_BTLDR_EN_PORT |= (1 << AVR_BTLDR_EN_PIN)))
|
||||||
|
|
||||||
#define AVR_ADDR_UP_PORT PORTC
|
#define AVR_ADDR_UP_PORT PORTC
|
||||||
#define AVR_ADDR_UP_DIR DDRC
|
#define AVR_ADDR_UP_DIR DDRC
|
||||||
@@ -147,6 +128,16 @@
|
|||||||
#define SNES_WR_DIR DDRC
|
#define SNES_WR_DIR DDRC
|
||||||
#define SNES_WR_PIN PC3
|
#define SNES_WR_PIN PC3
|
||||||
|
|
||||||
|
#define LED_PORT PORTC
|
||||||
|
#define LED_DIR DDRC
|
||||||
|
#define LED_PIN PC7
|
||||||
|
|
||||||
|
#define led_on() ((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
|
(LED_DIR &=~ (1 << LED_PIN)))
|
||||||
|
#define led_off() ((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
|
(LED_DIR |= (1 << LED_PIN)))
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- PORT D ---------------------------- */
|
/* ---------------------------- PORT D ---------------------------- */
|
||||||
|
|
||||||
#define AVR_SNES_PORT PORTD
|
#define AVR_SNES_PORT PORTD
|
||||||
@@ -177,6 +168,27 @@
|
|||||||
|
|
||||||
#define snes_wr_enable() (SNES_WR_EN_PORT |= (1 << SNES_WR_EN_PIN))
|
#define snes_wr_enable() (SNES_WR_EN_PORT |= (1 << SNES_WR_EN_PIN))
|
||||||
|
|
||||||
|
#define SNES_RESET_PORT PORTD
|
||||||
|
#define SNES_RESET_DIR DDRD
|
||||||
|
#define SNES_RESET_PIN PD3
|
||||||
|
#define SNES_RESET_INP PIND
|
||||||
|
|
||||||
|
#define snes_reset_on() (SNES_RESET_DIR |= (1 << SNES_RESET_PIN))
|
||||||
|
#define snes_reset_hi() (SNES_RESET_PORT |= (1 << SNES_RESET_PIN))
|
||||||
|
|
||||||
|
#define snes_reset_off() (SNES_RESET_DIR &= ~(1 << SNES_RESET_PIN))
|
||||||
|
#define snes_reset_lo() (SNES_RESET_PORT &= ~(1 << SNES_RESET_PIN))
|
||||||
|
|
||||||
|
#define snes_reset_test() ((SNES_RESET_INP & (1 << SNES_RESET_PIN)) == 0)
|
||||||
|
|
||||||
|
#define MMC_PORT PORTB
|
||||||
|
#define MMC_DIR DDRB
|
||||||
|
|
||||||
|
#define MMC_MISO_PIN PB6
|
||||||
|
#define MMC_MOSI_PIN PB5
|
||||||
|
#define MMC_SCK_PIN PB7
|
||||||
|
#define MMC_CS_PIN PB4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ void test_read_write()
|
|||||||
}
|
}
|
||||||
addr = 0x000000;
|
addr = 0x000000;
|
||||||
while (addr++ <= 0x0000ff) {
|
while (addr++ <= 0x0000ff) {
|
||||||
info("read addr=0x%08lx %x\n", addr, sram_read(addr));
|
info_P(PSTR("read addr=0x%08lx %x\n"), addr, sram_read(addr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ void test_bulk_read_write()
|
|||||||
addr = 0x000000;
|
addr = 0x000000;
|
||||||
sram_bulk_read_start(addr);
|
sram_bulk_read_start(addr);
|
||||||
while (addr <= 0x8000) {
|
while (addr <= 0x8000) {
|
||||||
info("addr=0x%08lx %x\n", addr, sram_bulk_read());
|
info_P(PSTR("addr=0x%08lx %x\n"), addr, sram_bulk_read());
|
||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
addr++;
|
addr++;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
|||||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
c = sram_bulk_read();
|
c = sram_bulk_read();
|
||||||
if (c != 0xff)
|
if (c != 0xff)
|
||||||
info("addr=0x%08lx c=0x%x\n", addr, c);
|
info_P(PSTR("addr=0x%08lx c=0x%x\n"), addr, c);
|
||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
}
|
}
|
||||||
sram_bulk_read_end();
|
sram_bulk_read_end();
|
||||||
@@ -95,12 +95,12 @@ void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
|||||||
|
|
||||||
void test_crc()
|
void test_crc()
|
||||||
{
|
{
|
||||||
info("test_crc: clear\n");
|
info_P(PSTR("test_crc: clear\n"));
|
||||||
avr_bus_active();
|
avr_bus_active();
|
||||||
sram_bulk_set(0x000000, 0x10000, 0xff);
|
sram_bulk_set(0x000000, 0x10000, 0xff);
|
||||||
info("test_crc: crc\n");
|
info_P(PSTR("test_crc: crc\n"));
|
||||||
crc_check_bulk_memory(0x000000, 0x10000, 0x8000);
|
crc_check_bulk_memory(0x000000, 0x10000, 0x8000);
|
||||||
info("test_crc: check\n");
|
info_P(PSTR("test_crc: check\n"));
|
||||||
test_non_zero_memory(0x000000, 0x10000);
|
test_non_zero_memory(0x000000, 0x10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
#include "sram.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern uint8_t snes_reset_line;
|
||||||
|
|
||||||
#ifndef OCR1A
|
#ifndef OCR1A
|
||||||
#define OCR1A OCR1 // 2313 support
|
#define OCR1A OCR1 // 2313 support
|
||||||
@@ -53,6 +57,7 @@ uint16_t volatile second; // count seconds
|
|||||||
ISR (SIG_OUTPUT_COMPARE1A)
|
ISR (SIG_OUTPUT_COMPARE1A)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
#if XTAL % DEBOUNCE // bei rest
|
#if XTAL % DEBOUNCE // bei rest
|
||||||
OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
|
OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -56,14 +56,14 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
|||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
if (len > rx_remaining) {
|
if (len > rx_remaining) {
|
||||||
info("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n",
|
info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
|
||||||
rx_remaining, len);
|
rx_remaining, len);
|
||||||
len = rx_remaining;
|
len = rx_remaining;
|
||||||
}
|
}
|
||||||
if (req_state == REQ_STATUS_BULK_UPLOAD) {
|
if (req_state == REQ_STATUS_BULK_UPLOAD) {
|
||||||
|
|
||||||
rx_remaining -= len;
|
rx_remaining -= len;
|
||||||
debug(DEBUG_USB_TRANS,"usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n",
|
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n"),
|
||||||
req_addr, len, rx_remaining);
|
req_addr, len, rx_remaining);
|
||||||
ptr = data;
|
ptr = data;
|
||||||
i = len;
|
i = len;
|
||||||
@@ -81,7 +81,7 @@ uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
|||||||
if (len > tx_remaining)
|
if (len > tx_remaining)
|
||||||
len = tx_remaining;
|
len = tx_remaining;
|
||||||
tx_remaining -= len;
|
tx_remaining -= len;
|
||||||
debug(DEBUG_USB_TRANS,"usbFunctionRead len=%i tx_remaining=%i \n", len, tx_remaining);
|
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, tx_remaining);
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
*data = tx_buffer[len];
|
*data = tx_buffer[len];
|
||||||
|
|||||||
@@ -248,7 +248,6 @@ section at the end of this file).
|
|||||||
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
||||||
* details.
|
* details.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_NAME 'S', 'N', 'E', 'S', 'R', 'A', 'M'
|
|
||||||
#define USB_CFG_DEVICE_NAME 'Q', 'U', 'I', 'C', 'K', 'D', 'E', 'V', '1', '6'
|
#define USB_CFG_DEVICE_NAME 'Q', 'U', 'I', 'C', 'K', 'D', 'E', 'V', '1', '6'
|
||||||
#define USB_CFG_DEVICE_NAME_LEN 10
|
#define USB_CFG_DEVICE_NAME_LEN 10
|
||||||
/* Same as above for the device name. If you don't want a device name, undefine
|
/* Same as above for the device name. If you don't want a device name, undefine
|
||||||
|
|||||||
BIN
packages/libusb-win32-device-bin-0.1.12.2.tar.gz
Normal file
BIN
packages/libusb-win32-device-bin-0.1.12.2.tar.gz
Normal file
Binary file not shown.
BIN
packages/libusb-win32-filter-bin-0.1.12.2.exe
Normal file
BIN
packages/libusb-win32-filter-bin-0.1.12.2.exe
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
0
report.txt
Normal file
0
report.txt
Normal file
77
snes/loadertest/Makefile
Normal file
77
snes/loadertest/Makefile
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# SDK Config
|
||||||
|
|
||||||
|
|
||||||
|
PLATFORM=$(shell uname)
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),Linux)
|
||||||
|
# Linux Wine
|
||||||
|
SDK=/home/david/.wine/drive_c/65xx_FreeSDK
|
||||||
|
WINE=wine
|
||||||
|
EMU=../../tools/bsnes/bsnes
|
||||||
|
DISASM=/home/david/Devel/arch/snes/devkit/bin/disasm
|
||||||
|
UCON=ucon64
|
||||||
|
else
|
||||||
|
# Mac Wine
|
||||||
|
SDK=/Users/david/.wine/drive_c/65xx_FreeSDK
|
||||||
|
WINE=wine
|
||||||
|
EMU=zsnes
|
||||||
|
DISASM=/Users/david/Devel/arch/snes/devkit/bin/disasm
|
||||||
|
UCON=ucon64
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(WINE) $(SDK)/bin/WDC816CC.exe
|
||||||
|
AS=$(WINE) $(SDK)/bin/WDC816AS.exe
|
||||||
|
LD=$(WINE) $(SDK)/bin/WDCLN.exe
|
||||||
|
PADBIN=$(WINE) tools/padbin.exe
|
||||||
|
|
||||||
|
# Project
|
||||||
|
|
||||||
|
INC=$(SDK)/include
|
||||||
|
LIBS=-L$(SDK)/lib/cc
|
||||||
|
#-L$(SDK)/lib/c134
|
||||||
|
|
||||||
|
|
||||||
|
OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj
|
||||||
|
APP=loadertest.smc
|
||||||
|
GFX=debugfont
|
||||||
|
|
||||||
|
all: $(APP)
|
||||||
|
|
||||||
|
run:
|
||||||
|
$(EMU) $(APP)
|
||||||
|
|
||||||
|
|
||||||
|
disasm: $(APP)
|
||||||
|
rm -rf $(APP)
|
||||||
|
$(DISASM) $(APP) > $(APP).asm
|
||||||
|
|
||||||
|
upload: header
|
||||||
|
ucon64 --port=usb --xsnesram $(APP)
|
||||||
|
|
||||||
|
repair: $(APP)
|
||||||
|
$(UCON) -snes -chk $(APP) 2>&1 >/dev/null
|
||||||
|
rm -rf *.bak
|
||||||
|
|
||||||
|
header: $(APP)
|
||||||
|
$(UCON) -smc $(APP)
|
||||||
|
rm -rf *.bak
|
||||||
|
|
||||||
|
StartupSnes.obj: StartupSnes.asm
|
||||||
|
$(AS) -V $?
|
||||||
|
|
||||||
|
ressource.obj: ressource.asm
|
||||||
|
$(AS) -V $?
|
||||||
|
|
||||||
|
%.obj: %.c
|
||||||
|
$(CC) -wl -wp -sop -MC -I $(INC) $?
|
||||||
|
|
||||||
|
$(APP): $(OBJS)
|
||||||
|
$(LD) -B -HB -M21 -V -T -Pff \
|
||||||
|
-C008000,0000 -U0000,0000 \
|
||||||
|
-Avectors=FFE4,7FE4 \
|
||||||
|
-Aregistration_data=FFB0,7FB0 \
|
||||||
|
-Aressource=18000,8000 \
|
||||||
|
-N $(OBJS) $(LIBS) -O $@
|
||||||
|
$(PADBIN) 0x20000 $(APP)
|
||||||
|
clean:
|
||||||
|
rm -vf $(APP) *.obj *.TMP
|
||||||
90
snes/loadertest/PPU.c
Normal file
90
snes/loadertest/PPU.c
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
byte tileMapLocation[4];
|
||||||
|
word characterLocation[4];
|
||||||
|
|
||||||
|
void waitForVBlank(void)
|
||||||
|
{
|
||||||
|
byte Status;
|
||||||
|
do {
|
||||||
|
Status = *(byte *) 0x4210;
|
||||||
|
} while (!(Status & 0x80));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTileMapLocation(word vramDst, byte screenProp, byte bgNumber)
|
||||||
|
{
|
||||||
|
tileMapLocation[bgNumber] = ((vramDst >> 8) & 0xfc) | (screenProp & 0x03);
|
||||||
|
*(byte *) (0x2107 + bgNumber) = tileMapLocation[bgNumber];
|
||||||
|
}
|
||||||
|
|
||||||
|
void restoreTileMapLocation(byte bgNumber)
|
||||||
|
{
|
||||||
|
*(byte *) (0x2107 + bgNumber) = tileMapLocation[bgNumber];
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCharacterLocation(word vramDst, byte bgNumber)
|
||||||
|
{
|
||||||
|
characterLocation[bgNumber] = vramDst;
|
||||||
|
if (bgNumber < 2) {
|
||||||
|
*(byte *) 0x210b =
|
||||||
|
(characterLocation[1] >> 8 & 0xf0) + (characterLocation[0] >> 12);
|
||||||
|
} else {
|
||||||
|
*(byte *) 0x210c =
|
||||||
|
(characterLocation[3] >> 8 & 0xf0) + (characterLocation[2] >> 12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void restoreCharacterLocation(byte bgNumber)
|
||||||
|
{
|
||||||
|
setCharacterLocation(characterLocation[bgNumber], bgNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VRAMByteWrite(byte value, word vramDst)
|
||||||
|
{
|
||||||
|
*(byte *) 0x2115 = 0x80;
|
||||||
|
*(word *) 0x2116 = vramDst;
|
||||||
|
|
||||||
|
*(byte *) 0x2118 = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VRAMLoad(word src, word vramDst, word size)
|
||||||
|
{
|
||||||
|
// set address in VRam for read or write ($2116) + block size transfer ($2115)
|
||||||
|
*(byte *) 0x2115 = 0x80;
|
||||||
|
*(word *) 0x2116 = vramDst;
|
||||||
|
|
||||||
|
*(word *) 0x4300 = 0x1801; // set DMA control register (1 word inc)
|
||||||
|
// and destination ($21xx xx -> 0x18)
|
||||||
|
*(word *) 0x4302 = src; // DMA channel x source address offset
|
||||||
|
// (low $4302 and high $4303 optimisation)
|
||||||
|
*(byte *) 0x4304 = 0x01; // DMA channel x source address bank
|
||||||
|
*(word *) 0x4305 = size; // DMA channel x transfer size
|
||||||
|
// (low $4305 and high $4306 optimisation)
|
||||||
|
|
||||||
|
// Turn on DMA transfer for this channel
|
||||||
|
waitForVBlank();
|
||||||
|
*(byte *) 0x2100 = 0x80;
|
||||||
|
*(byte *) 0x420b = 0x01;
|
||||||
|
*(byte *) 0x2100 = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGRAMLoad(word src, byte cgramDst, word size)
|
||||||
|
{
|
||||||
|
|
||||||
|
// set address in VRam for read or write + block size
|
||||||
|
*(byte *) 0x2121 = cgramDst;
|
||||||
|
|
||||||
|
*(word *) 0x4300 = 0x2200; // set DMA control register (1 byte inc)
|
||||||
|
// and destination ($21xx xx -> 022)
|
||||||
|
*(word *) 0x4302 = src; // DMA channel x source address offset
|
||||||
|
// (low $4302 and high $4303 optimisation)
|
||||||
|
*(byte *) 0x4304 = 0x01; // DMA channel x source address bank
|
||||||
|
*(word *) 0x4305 = size; // DMA channel x transfer size
|
||||||
|
// (low $4305 and high $4306 optimisation)
|
||||||
|
|
||||||
|
// Turn on DMA transfer for this channel
|
||||||
|
waitForVBlank();
|
||||||
|
*(byte *) 0x2100 = 0x80;
|
||||||
|
*(byte *) 0x420b = 0x01;
|
||||||
|
*(byte *) 0x2100 = 0x00;
|
||||||
|
}
|
||||||
11
snes/loadertest/PPU.h
Normal file
11
snes/loadertest/PPU.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
extern byte tileMapLocation[4];
|
||||||
|
extern word characterLocation[4];
|
||||||
|
|
||||||
|
void waitForVBlank(void);
|
||||||
|
void setTileMapLocation(word vramDst, byte screenProp, byte bgNumber);
|
||||||
|
void restoreTileMapLocation(byte bgNumber);
|
||||||
|
void setCharacterLocation(word vramDst, byte bgNumber);
|
||||||
|
void restoreCharacterLocation(byte bgNumber);
|
||||||
|
void VRAMByteWrite(byte value, word vramDst);
|
||||||
|
void VRAMLoad(word src, word vramDst, word size);
|
||||||
|
void CGRAMLoad(word src, byte cgramDst, word size);
|
||||||
240
snes/loadertest/StartupSnes.asm
Normal file
240
snes/loadertest/StartupSnes.asm
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
; SNES ROM startup code
|
||||||
|
|
||||||
|
;******************************************************************************
|
||||||
|
;*** Define a special section in case most of the code is not in bank 0. ***
|
||||||
|
;******************************************************************************
|
||||||
|
|
||||||
|
;STACK EQU $01ff ;CHANGE THIS FOR YOUR SYSTEM
|
||||||
|
|
||||||
|
;STARTUP SECTION OFFSET $008000
|
||||||
|
|
||||||
|
CODE
|
||||||
|
|
||||||
|
XDEF START
|
||||||
|
START:
|
||||||
|
XREF _~main
|
||||||
|
|
||||||
|
sei ; Disabled interrupts
|
||||||
|
clc ; clear carry to switch to native mode
|
||||||
|
xce ; Xchange carry & emulation bit. native mode
|
||||||
|
rep #$18 ; Binary mode (decimal mode off), X/Y 16 bit
|
||||||
|
LONGI ON
|
||||||
|
ldx #$1FFF ; set stack to $1FFF
|
||||||
|
txs
|
||||||
|
|
||||||
|
rep #$30
|
||||||
|
longa on
|
||||||
|
longi on
|
||||||
|
|
||||||
|
; Init data used for heap
|
||||||
|
; see heap definition below
|
||||||
|
XREF _~_heap_top
|
||||||
|
XREF _~_mem_start
|
||||||
|
stz _~_heap_top
|
||||||
|
stz _~_mem_start
|
||||||
|
|
||||||
|
XREF _~preInit
|
||||||
|
jsr >_~preInit
|
||||||
|
|
||||||
|
sep #$30 ; X,Y,A are 8 bit numbers
|
||||||
|
LONGA OFF
|
||||||
|
LONGI OFF
|
||||||
|
lda #$8F ; screen off, full brightness
|
||||||
|
sta $2100 ; brightness + screen enable register
|
||||||
|
stz $2101 ; Sprite register (size + address in VRAM)
|
||||||
|
stz $2102 ; Sprite registers (address of sprite memory [OAM])
|
||||||
|
stz $2103 ; "" ""
|
||||||
|
stz $2105 ; Mode 0, = Graphic mode register
|
||||||
|
stz $2106 ; noplanes, no mosaic, = Mosaic register
|
||||||
|
stz $2107 ; Plane 0 map VRAM location
|
||||||
|
stz $2108 ; Plane 1 map VRAM location
|
||||||
|
stz $2109 ; Plane 2 map VRAM location
|
||||||
|
stz $210A ; Plane 3 map VRAM location
|
||||||
|
stz $210B ; Plane 0+1 Tile data location
|
||||||
|
stz $210C ; Plane 2+3 Tile data location
|
||||||
|
stz $210D ; Plane 0 scroll x (first 8 bits)
|
||||||
|
stz $210D ; Plane 0 scroll x (last 3 bits) #$0 - #$07ff
|
||||||
|
stz $210E ; Plane 0 scroll y (first 8 bits)
|
||||||
|
stz $210E ; Plane 0 scroll y (last 3 bits) #$0 - #$07ff
|
||||||
|
stz $210F ; Plane 1 scroll x (first 8 bits)
|
||||||
|
stz $210F ; Plane 1 scroll x (last 3 bits) #$0 - #$07ff
|
||||||
|
stz $2110 ; Plane 1 scroll y (first 8 bits)
|
||||||
|
stz $2110 ; Plane 1 scroll y (last 3 bits) #$0 - #$07ff
|
||||||
|
stz $2111 ; Plane 2 scroll x (first 8 bits)
|
||||||
|
stz $2111 ; Plane 2 scroll x (last 3 bits) #$0 - #$07ff
|
||||||
|
stz $2112 ; Plane 2 scroll y (first 8 bits)
|
||||||
|
stz $2112 ; Plane 2 scroll y (last 3 bits) #$0 - #$07ff
|
||||||
|
stz $2113 ; Plane 3 scroll x (first 8 bits)
|
||||||
|
stz $2113 ; Plane 3 scroll x (last 3 bits) #$0 - #$07ff
|
||||||
|
stz $2114 ; Plane 3 scroll y (first 8 bits)
|
||||||
|
stz $2114 ; Plane 3 scroll y (last 3 bits) #$0 - #$07ff
|
||||||
|
lda #$80 ; increase VRAM address after writing to $2119
|
||||||
|
sta $2115 ; VRAM address increment register
|
||||||
|
stz $2116 ; VRAM address low
|
||||||
|
stz $2117 ; VRAM address high
|
||||||
|
stz $211A ; Initial Mode 7 setting register
|
||||||
|
stz $211B ; Mode 7 matrix parameter A register (low)
|
||||||
|
lda #$01
|
||||||
|
sta $211B ; Mode 7 matrix parameter A register (high)
|
||||||
|
stz $211C ; Mode 7 matrix parameter B register (low)
|
||||||
|
stz $211C ; Mode 7 matrix parameter B register (high)
|
||||||
|
stz $211D ; Mode 7 matrix parameter C register (low)
|
||||||
|
stz $211D ; Mode 7 matrix parameter C register (high)
|
||||||
|
stz $211E ; Mode 7 matrix parameter D register (low)
|
||||||
|
sta $211E ; Mode 7 matrix parameter D register (high)
|
||||||
|
stz $211F ; Mode 7 center position X register (low)
|
||||||
|
stz $211F ; Mode 7 center position X register (high)
|
||||||
|
stz $2120 ; Mode 7 center position Y register (low)
|
||||||
|
stz $2120 ; Mode 7 center position Y register (high)
|
||||||
|
stz $2121 ; Color number register ($0-ff)
|
||||||
|
stz $2123 ; BG1 & BG2 Window mask setting register
|
||||||
|
stz $2124 ; BG3 & BG4 Window mask setting register
|
||||||
|
stz $2125 ; OBJ & Color Window mask setting register
|
||||||
|
stz $2126 ; Window 1 left position register
|
||||||
|
stz $2127 ; Window 2 left position register
|
||||||
|
stz $2128 ; Window 3 left position register
|
||||||
|
stz $2129 ; Window 4 left position register
|
||||||
|
stz $212A ; BG1, BG2, BG3, BG4 Window Logic register
|
||||||
|
stz $212B ; OBJ, Color Window Logic Register (or,and,xor,xnor)
|
||||||
|
sta $212C ; Main Screen designation (planes, sprites enable)
|
||||||
|
stz $212D ; Sub Screen designation
|
||||||
|
stz $212E ; Window mask for Main Screen
|
||||||
|
stz $212F ; Window mask for Sub Screen
|
||||||
|
lda #$30
|
||||||
|
sta $2130 ; Color addition & screen addition init setting
|
||||||
|
stz $2131 ; Add/Sub sub designation for screen, sprite, color
|
||||||
|
lda #$E0
|
||||||
|
sta $2132 ; color data for addition/subtraction
|
||||||
|
stz $2133 ; Screen setting (interlace x,y/enable SFX data)
|
||||||
|
stz $4200 ; Enable V-blank, interrupt, Joypad register
|
||||||
|
lda #$FF
|
||||||
|
sta $4201 ; Programmable I/O port
|
||||||
|
stz $4202 ; Multiplicand A
|
||||||
|
stz $4203 ; Multiplier B
|
||||||
|
stz $4204 ; Multiplier C
|
||||||
|
stz $4205 ; Multiplicand C
|
||||||
|
stz $4206 ; Divisor B
|
||||||
|
stz $4207 ; Horizontal Count Timer
|
||||||
|
stz $4208 ; Horizontal Count Timer MSB (most significant bit)
|
||||||
|
stz $4209 ; Vertical Count Timer
|
||||||
|
stz $420A ; Vertical Count Timer MSB
|
||||||
|
stz $420B ; General DMA enable (bits 0-7)
|
||||||
|
stz $420C ; Horizontal DMA (HDMA) enable (bits 0-7)
|
||||||
|
stz $420D ; Access cycle designation (slow/fast rom)
|
||||||
|
cli ; Enable interrupts
|
||||||
|
|
||||||
|
rep #$30
|
||||||
|
longa on
|
||||||
|
longi on
|
||||||
|
|
||||||
|
jsr >_~main
|
||||||
|
brk
|
||||||
|
|
||||||
|
XDEF IRQ
|
||||||
|
IRQ:
|
||||||
|
XREF _~IRQHandler
|
||||||
|
LONGA ON
|
||||||
|
LONGI ON
|
||||||
|
rep #$30
|
||||||
|
pha
|
||||||
|
phx
|
||||||
|
phy
|
||||||
|
jsr _~IRQHandler
|
||||||
|
ply
|
||||||
|
plx
|
||||||
|
pla
|
||||||
|
rti
|
||||||
|
|
||||||
|
XDEF NMI
|
||||||
|
NMI:
|
||||||
|
XREF _~NMIHandler
|
||||||
|
LONGA ON
|
||||||
|
LONGI ON
|
||||||
|
rep #$30
|
||||||
|
pha
|
||||||
|
phx
|
||||||
|
phy
|
||||||
|
phd
|
||||||
|
phb
|
||||||
|
lda #$0000
|
||||||
|
sep #$30 ; X,Y,A are 8 bit numbers
|
||||||
|
LONGA OFF
|
||||||
|
LONGI OFF
|
||||||
|
lda $4210 ; Read NMI
|
||||||
|
LONGA ON
|
||||||
|
LONGI ON
|
||||||
|
rep #$30
|
||||||
|
jsr _~NMIHandler
|
||||||
|
plb
|
||||||
|
pld
|
||||||
|
ply
|
||||||
|
plx
|
||||||
|
pla
|
||||||
|
rti
|
||||||
|
|
||||||
|
DIRQ:
|
||||||
|
rti
|
||||||
|
|
||||||
|
ENDS
|
||||||
|
|
||||||
|
;******************************************************************************
|
||||||
|
;*** Heap definition ***
|
||||||
|
;******************************************************************************
|
||||||
|
|
||||||
|
DATA
|
||||||
|
|
||||||
|
XDEF _~heap_start
|
||||||
|
XDEF _~heap_end
|
||||||
|
|
||||||
|
_~heap_start:
|
||||||
|
WORD $1000
|
||||||
|
_~heap_end:
|
||||||
|
WORD $1200
|
||||||
|
|
||||||
|
;******************************************************************************
|
||||||
|
;*** SNES ROM Registartion Data ***
|
||||||
|
;******************************************************************************
|
||||||
|
|
||||||
|
REGISTRATION_DATA SECTION
|
||||||
|
|
||||||
|
MAKER_CODE FCC /FF/
|
||||||
|
GAME_CODE FCC /SMWJ/
|
||||||
|
FIXED_VALUE0 BYTE $00, $00, $00, $00, $00, $00, $00
|
||||||
|
EXPANSION_RAM_SIZE BYTE $00
|
||||||
|
SPECIAL_VERSION BYTE $00
|
||||||
|
CARTRIDGE_TYPE_SUB BYTE $00
|
||||||
|
GAME_TITLE FCC /GAME TITLE !/
|
||||||
|
;012345678901234567890;
|
||||||
|
MAP_MODE BYTE $20
|
||||||
|
CARTRIDGE_SIZE BYTE $00
|
||||||
|
ROM_SIZE BYTE $09
|
||||||
|
RAM_SIZE BYTE $00
|
||||||
|
DESTINATION_CODE BYTE $00
|
||||||
|
FIXED_VALUE1 BYTE $33
|
||||||
|
MASK_ROM_VERSION BYTE $00
|
||||||
|
COMPLEMENT_CHECK BYTE $00, $00
|
||||||
|
CHEKSUM BYTE $00, $00
|
||||||
|
|
||||||
|
;******************************************************************************
|
||||||
|
;*** SNES Interrupts and Reset vector ***
|
||||||
|
;******************************************************************************
|
||||||
|
|
||||||
|
VECTORS SECTION
|
||||||
|
; Native vector
|
||||||
|
N_COP DW DIRQ
|
||||||
|
N_BRK DW DIRQ
|
||||||
|
N_ABORT DW DIRQ
|
||||||
|
N_NMI DW NMI
|
||||||
|
N_RSRVD DW DIRQ
|
||||||
|
N_IRQ DW IRQ
|
||||||
|
DS 4
|
||||||
|
; Emulation vector
|
||||||
|
E_COP DW DIRQ
|
||||||
|
E_RSRVD DW DIRQ
|
||||||
|
E_ABORT DW DIRQ
|
||||||
|
E_NMI DW DIRQ
|
||||||
|
E_RESET DW START
|
||||||
|
E_IRQ DW DIRQ
|
||||||
|
|
||||||
|
END
|
||||||
|
|
||||||
37
snes/loadertest/crc.c
Normal file
37
snes/loadertest/crc.c
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
|
||||||
|
word crc_update(char far * data, word size)
|
||||||
|
{
|
||||||
|
word i;
|
||||||
|
word j;
|
||||||
|
word crc = 0;
|
||||||
|
for (j = 0; j < size; j++) {
|
||||||
|
crc = crc ^ ((word) data[j] << 8);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
if (crc & 0x8000)
|
||||||
|
crc = (crc << 1) ^ 0x1021;
|
||||||
|
else
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
word crc_update_mem(unsigned long addr, word size)
|
||||||
|
{
|
||||||
|
word i;
|
||||||
|
word j;
|
||||||
|
word crc = 0;
|
||||||
|
for (j = 0; j < size; j++) {
|
||||||
|
crc = crc ^ ((word) * (byte *) (addr + j) << 8);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
if (crc & 0x8000)
|
||||||
|
crc = (crc << 1) ^ 0x1021;
|
||||||
|
else
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
3
snes/loadertest/crc.h
Normal file
3
snes/loadertest/crc.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
word crc_update(byte * data, word size);
|
||||||
|
word crc_update_mem(unsigned long, word size);
|
||||||
8
snes/loadertest/data.h
Normal file
8
snes/loadertest/data.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
#ifndef _DATA
|
||||||
|
|
||||||
|
typedef unsigned char byte;
|
||||||
|
typedef unsigned short word;
|
||||||
|
|
||||||
|
#define _DATA
|
||||||
|
#endif
|
||||||
224
snes/loadertest/debug.c
Normal file
224
snes/loadertest/debug.c
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
#include "data.h"
|
||||||
|
#include "pad.h"
|
||||||
|
#include "PPU.h"
|
||||||
|
#include "ressource.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define DEBUG_BUFFER_SIZE 128
|
||||||
|
|
||||||
|
word debugMap[0x400];
|
||||||
|
char debug_buffer[DEBUG_BUFFER_SIZE];
|
||||||
|
char screen_buffer[DEBUG_BUFFER_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
void debug_init(void)
|
||||||
|
{
|
||||||
|
word i;
|
||||||
|
for (i = 0; i < 0x400; i++) {
|
||||||
|
debugMap[i] = 0x00;
|
||||||
|
}
|
||||||
|
memset(debug_buffer, 0, DEBUG_BUFFER_SIZE);
|
||||||
|
memset(screen_buffer, 0,DEBUG_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void debug_enable(void)
|
||||||
|
{
|
||||||
|
VRAMLoad((word) debugFont_pic, 0x5000, 2048);
|
||||||
|
VRAMLoad((word) debugMap, 0x4000, 0x0800);
|
||||||
|
setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
|
||||||
|
setCharacterLocation(0x5000, (byte) 0);
|
||||||
|
*(byte *) 0x2100 = 0x0f; // enable background
|
||||||
|
|
||||||
|
// Font Color
|
||||||
|
// hex(24 << 10 | 24 << 5 | 24 ) = '0x6318'
|
||||||
|
*(byte *) 0x2121 = 0x02;
|
||||||
|
*(byte *) 0x2122 = 0xff;
|
||||||
|
*(byte *) 0x2122 = 0x7f;
|
||||||
|
|
||||||
|
// Font Border Color
|
||||||
|
*(byte *) 0x2121 = 0x00;
|
||||||
|
*(byte *) 0x2122 = 0x00;
|
||||||
|
*(byte *) 0x2122 = 0x00;
|
||||||
|
|
||||||
|
// Background Color
|
||||||
|
*(byte *) 0x2121 = 0x01;
|
||||||
|
*(byte *) 0x2122 = 0x05;
|
||||||
|
*(byte *) 0x2122 = 0x29;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void clears(void)
|
||||||
|
{
|
||||||
|
word i, y;
|
||||||
|
for (y = 0; y < 20; y++) {
|
||||||
|
waitForVBlank();
|
||||||
|
for (i = 0; i < 32; i++) {
|
||||||
|
*(byte *) 0x2115 = 0x80;
|
||||||
|
*(word *) 0x2116 = 0x4000 + i + (y * 0x20);
|
||||||
|
*(byte *) 0x2118 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _print_char(word y, word x, char c)
|
||||||
|
{
|
||||||
|
waitForVBlank();
|
||||||
|
VRAMByteWrite((byte) (c - 32), (word) (0x4000 + x + (y * 0x20)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _print_screen(word y, char *buffer)
|
||||||
|
{
|
||||||
|
char l;
|
||||||
|
unsigned int x;
|
||||||
|
x = y * 0x20;
|
||||||
|
l = strlen(buffer);
|
||||||
|
waitForVBlank();
|
||||||
|
while (*buffer) {
|
||||||
|
if (*buffer == '\n') {
|
||||||
|
while (x++ < 32) {
|
||||||
|
*(byte *) 0x2115 = 0x80;
|
||||||
|
*(word *) 0x2116 = 0x4000 + x + (y * 0x20);
|
||||||
|
*(byte *) 0x2118 = 0;
|
||||||
|
}
|
||||||
|
x = 0;
|
||||||
|
y += 0x20;
|
||||||
|
buffer++;
|
||||||
|
waitForVBlank();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*(byte *) 0x2115 = 0x80;
|
||||||
|
*(word *) 0x2116 = 0x4000 + x;
|
||||||
|
*(byte *) 0x2118 = *buffer - 32;
|
||||||
|
x++;
|
||||||
|
buffer++;
|
||||||
|
#if 1
|
||||||
|
waitForVBlank();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void _print_console(const char *buffer)
|
||||||
|
{
|
||||||
|
while (*buffer)
|
||||||
|
*(byte *) 0x3000 = *buffer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void printfc(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsprintf(debug_buffer, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
_print_console(debug_buffer);
|
||||||
|
//memset(debug_buffer,0,DEBUG_BUFFER_SIZE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void printfs(word y, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsprintf(screen_buffer, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
_print_screen(y, screen_buffer);
|
||||||
|
//memset(screen_buffer, 0, DEBUG_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printc_packet(unsigned long addr, unsigned int len, byte * packet)
|
||||||
|
{
|
||||||
|
unsigned int i, j;
|
||||||
|
unsigned int sum = 0;
|
||||||
|
unsigned int last_sum = 0;
|
||||||
|
unsigned int clear = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i += 16) {
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
sum += packet[i + j];
|
||||||
|
}
|
||||||
|
if (!sum) {
|
||||||
|
clear = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_sum == sum) {
|
||||||
|
clear = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clear) {
|
||||||
|
printfc("*\n");
|
||||||
|
clear = 0;
|
||||||
|
}
|
||||||
|
printfc("%06lX:", addr + i);
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
printfc(" %02x", packet[i + j]);
|
||||||
|
}
|
||||||
|
printfc(" |");
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||||
|
printfc("%c", packet[i + j]);
|
||||||
|
else
|
||||||
|
printfc(".");
|
||||||
|
}
|
||||||
|
printfc("|\n");
|
||||||
|
last_sum = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* keep the linker happy
|
||||||
|
*/
|
||||||
|
int open(const char *_name, int _mode)
|
||||||
|
{
|
||||||
|
_print_console("open called\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int close(int fd)
|
||||||
|
{
|
||||||
|
_print_console("close called\n");
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t read(int fd, void *buff, size_t len)
|
||||||
|
{
|
||||||
|
_print_console("read called\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t write(int fd, void *buffer, size_t len)
|
||||||
|
{
|
||||||
|
_print_console("write called\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
long lseek(int fd, long off, int count)
|
||||||
|
{
|
||||||
|
_print_console("lseek called\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int unlink(const char *name)
|
||||||
|
{
|
||||||
|
_print_console("unlink called\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isatty()
|
||||||
|
{
|
||||||
|
_print_console("isatty called\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
8
snes/loadertest/debug.h
Normal file
8
snes/loadertest/debug.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
void debug_init(void);
|
||||||
|
void debug_enable(void);
|
||||||
|
void printfs(word y, const char *fmt, ...);
|
||||||
|
void printfc(const char *fmt, ...);
|
||||||
|
void clears(void);
|
||||||
|
void printc_packet(unsigned long addr, unsigned int len, byte * packet);
|
||||||
106
snes/loadertest/event.c
Normal file
106
snes/loadertest/event.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "data.h";
|
||||||
|
#include "event.h";
|
||||||
|
|
||||||
|
event *events;
|
||||||
|
|
||||||
|
void initEvents(void)
|
||||||
|
{
|
||||||
|
events = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
event *createEvent(char (*callback) (word counter))
|
||||||
|
{
|
||||||
|
event *myEvent;
|
||||||
|
|
||||||
|
myEvent = (event *) malloc(sizeof(event));
|
||||||
|
|
||||||
|
myEvent->VBlankCount = 0;
|
||||||
|
myEvent->callback = callback;
|
||||||
|
myEvent->nextEvent = NULL;
|
||||||
|
myEvent->previousEvent = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
return myEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
event *addEvent(char (*callback) (word counter), int noDuplicateCallback)
|
||||||
|
{
|
||||||
|
|
||||||
|
event *lastEvent;
|
||||||
|
event *myEvent;
|
||||||
|
|
||||||
|
if (events == NULL) {
|
||||||
|
events = createEvent(callback);
|
||||||
|
return events;
|
||||||
|
} else {
|
||||||
|
lastEvent = events;
|
||||||
|
// TODO optimise this with noduplicate
|
||||||
|
while (lastEvent->nextEvent != NULL) {
|
||||||
|
if (noDuplicateCallback == 1 && lastEvent->callback == *callback) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
lastEvent = lastEvent->nextEvent;
|
||||||
|
}
|
||||||
|
if (noDuplicateCallback == 1 && lastEvent->callback == *callback) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
myEvent = createEvent(callback);
|
||||||
|
myEvent->previousEvent = lastEvent;
|
||||||
|
lastEvent->nextEvent = myEvent;
|
||||||
|
return myEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeEvent(event * eventElement)
|
||||||
|
{
|
||||||
|
|
||||||
|
byte alone = 0;
|
||||||
|
event *next, *previous;
|
||||||
|
|
||||||
|
next = eventElement->nextEvent;
|
||||||
|
previous = eventElement->previousEvent;
|
||||||
|
|
||||||
|
if (eventElement->nextEvent != NULL && eventElement->previousEvent != NULL) {
|
||||||
|
alone++;
|
||||||
|
next->previousEvent = previous;
|
||||||
|
previous->nextEvent = next;
|
||||||
|
|
||||||
|
} else if (eventElement->nextEvent != NULL) {
|
||||||
|
alone++;
|
||||||
|
next->previousEvent = NULL;
|
||||||
|
events = next;
|
||||||
|
|
||||||
|
} else if (eventElement->previousEvent != NULL) {
|
||||||
|
alone++;
|
||||||
|
previous->nextEvent = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(eventElement);
|
||||||
|
|
||||||
|
if (alone == 0) {
|
||||||
|
events = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void processEvents(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
event *currentEvent;
|
||||||
|
char returnValue;
|
||||||
|
|
||||||
|
currentEvent = events;
|
||||||
|
while (currentEvent != NULL) {
|
||||||
|
returnValue = currentEvent->callback(currentEvent->VBlankCount);
|
||||||
|
if (returnValue == EVENT_CONTINUE) {
|
||||||
|
currentEvent->VBlankCount++;
|
||||||
|
} else {
|
||||||
|
removeEvent(currentEvent);
|
||||||
|
}
|
||||||
|
currentEvent = currentEvent->nextEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
snes/loadertest/event.h
Normal file
17
snes/loadertest/event.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
typedef struct event {
|
||||||
|
word VBlankCount;
|
||||||
|
char (*callback) (word counter);
|
||||||
|
struct event *previousEvent;
|
||||||
|
struct event *nextEvent;
|
||||||
|
} event;
|
||||||
|
|
||||||
|
#define EVENT_STOP 0
|
||||||
|
#define EVENT_CONTINUE 1
|
||||||
|
|
||||||
|
extern event *events;
|
||||||
|
|
||||||
|
void initEvents(void);
|
||||||
|
extern event *addEvent(char (*callback) (word counter),
|
||||||
|
int noDuplicateCallback);
|
||||||
|
extern void removeEvent(event * eventElement);
|
||||||
|
extern void processEvents(void);
|
||||||
48
snes/loadertest/integer.h
Normal file
48
snes/loadertest/integer.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*-------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Integer type definitions for FatFs module
|
||||||
|
*/
|
||||||
|
/*-------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef _INTEGER
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These types must be 16-bit, 32-bit or larger integer
|
||||||
|
*/
|
||||||
|
typedef int INT;
|
||||||
|
typedef unsigned int UINT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These types must be 8-bit integer
|
||||||
|
*/
|
||||||
|
typedef signed char CHAR;
|
||||||
|
typedef unsigned char UCHAR;
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These types must be 16-bit integer
|
||||||
|
*/
|
||||||
|
typedef short SHORT;
|
||||||
|
typedef unsigned short USHORT;
|
||||||
|
typedef unsigned short WORD;
|
||||||
|
typedef unsigned short WCHAR;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These types must be 32-bit integer
|
||||||
|
*/
|
||||||
|
typedef long LONG;
|
||||||
|
typedef unsigned long ULONG;
|
||||||
|
typedef unsigned long DWORD;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Boolean type
|
||||||
|
*/
|
||||||
|
// enum { false = 0 , true } bool;
|
||||||
|
|
||||||
|
//typedef int BOOL;
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
#define _INTEGER
|
||||||
|
#endif
|
||||||
93
snes/loadertest/main.c
Normal file
93
snes/loadertest/main.c
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "data.h";
|
||||||
|
#include "pad.h";
|
||||||
|
#include "event.h";
|
||||||
|
#include "myEvents.h";
|
||||||
|
#include "ressource.h";
|
||||||
|
#include "PPU.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "integer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*FUNC) (void);
|
||||||
|
|
||||||
|
padStatus pad1;
|
||||||
|
|
||||||
|
void initInternalRegisters(void)
|
||||||
|
{
|
||||||
|
characterLocation[0] = 0x0000;
|
||||||
|
characterLocation[1] = 0x0000;
|
||||||
|
characterLocation[2] = 0x0000;
|
||||||
|
characterLocation[3] = 0x0000;
|
||||||
|
debug_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void preInit(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
// For testing purpose ...
|
||||||
|
// Insert code here to be executed before register init
|
||||||
|
}
|
||||||
|
|
||||||
|
void halt(void)
|
||||||
|
{
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wait(void)
|
||||||
|
{
|
||||||
|
printfc("SNES::wait: press A to continue\n");
|
||||||
|
enablePad();
|
||||||
|
pad1 = readPad((byte) 0);
|
||||||
|
while (!pad1.A) {
|
||||||
|
waitForVBlank();
|
||||||
|
pad1 = readPad((byte) 0);
|
||||||
|
}
|
||||||
|
printfc("SNES::wait: done\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void boot(DWORD addr)
|
||||||
|
{
|
||||||
|
FUNC fn;
|
||||||
|
//printfc("SNES::boot addr=%lx\n", addr);
|
||||||
|
fn = (FUNC) addr;
|
||||||
|
fn();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char i;
|
||||||
|
unsigned char j;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
initInternalRegisters();
|
||||||
|
*(byte *) 0x2105 = 0x01; // MODE 1 value
|
||||||
|
*(byte *) 0x212c = 0x01; // Plane 0 (bit one) enable register
|
||||||
|
*(byte *) 0x212d = 0x00; // All subPlane disable
|
||||||
|
*(byte *) 0x2100 = 0x0f; // enable background
|
||||||
|
|
||||||
|
debug_enable();
|
||||||
|
i=0;
|
||||||
|
j=0;
|
||||||
|
while (1) {
|
||||||
|
printfs(0,"IRQ COUNT %i", i);
|
||||||
|
printfs(1,"NMI COUNT %i", j++);
|
||||||
|
waitForVBlank();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRQHandler(void)
|
||||||
|
{
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NMIHandler(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
// processEvents();
|
||||||
|
}
|
||||||
103
snes/loadertest/myEvents.c
Normal file
103
snes/loadertest/myEvents.c
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
#include "data.h";
|
||||||
|
#include "pad.h";
|
||||||
|
#include "event.h";
|
||||||
|
|
||||||
|
extern padStatus pad1;
|
||||||
|
extern word scrollValue;
|
||||||
|
|
||||||
|
char fadeOut(word counter)
|
||||||
|
{
|
||||||
|
static byte fadeOutValue;
|
||||||
|
|
||||||
|
if (counter == 0) {
|
||||||
|
// init fade value
|
||||||
|
fadeOutValue = 0x0f;
|
||||||
|
} else {
|
||||||
|
fadeOutValue--;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(byte *) 0x2100 = fadeOutValue;
|
||||||
|
|
||||||
|
if (fadeOutValue == 0x00) {
|
||||||
|
return EVENT_STOP;
|
||||||
|
} else {
|
||||||
|
return EVENT_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char fadeIn(word counter)
|
||||||
|
{
|
||||||
|
static byte fadeInValue;
|
||||||
|
|
||||||
|
if (counter == 0) {
|
||||||
|
// init fade value
|
||||||
|
fadeInValue = 0x00;
|
||||||
|
} else {
|
||||||
|
fadeInValue++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(byte *) 0x2100 = fadeInValue;
|
||||||
|
|
||||||
|
if (fadeInValue >= 0x0f) {
|
||||||
|
return EVENT_STOP;
|
||||||
|
} else {
|
||||||
|
return EVENT_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char mosaicOut(word counter)
|
||||||
|
{
|
||||||
|
static byte mosaicOutValue;
|
||||||
|
|
||||||
|
if (counter == 0) {
|
||||||
|
// init fade value
|
||||||
|
mosaicOutValue = 0xff;
|
||||||
|
} else {
|
||||||
|
mosaicOutValue -= 0x10;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(byte *) 0x2106 = mosaicOutValue;
|
||||||
|
|
||||||
|
if (mosaicOutValue == 0x0f) {
|
||||||
|
return EVENT_STOP;
|
||||||
|
} else {
|
||||||
|
return EVENT_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char mosaicIn(word counter)
|
||||||
|
{
|
||||||
|
static byte mosaicInValue;
|
||||||
|
|
||||||
|
if (counter == 0) {
|
||||||
|
// init fade value
|
||||||
|
mosaicInValue = 0x0f;
|
||||||
|
} else {
|
||||||
|
mosaicInValue += 0x10;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(byte *) 0x2106 = mosaicInValue;
|
||||||
|
|
||||||
|
if (mosaicInValue == 0xff) {
|
||||||
|
return EVENT_STOP;
|
||||||
|
} else {
|
||||||
|
return EVENT_CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char NMIReadPad(word counter)
|
||||||
|
{
|
||||||
|
pad1 = readPad((byte) 0);
|
||||||
|
|
||||||
|
return EVENT_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
char scrollLeft(word counter)
|
||||||
|
{
|
||||||
|
scrollValue++;
|
||||||
|
|
||||||
|
*(byte *) 0x210d = (byte) scrollValue;
|
||||||
|
*(byte *) 0x210d = (byte) (scrollValue >> 8);
|
||||||
|
|
||||||
|
return EVENT_CONTINUE;
|
||||||
|
}
|
||||||
6
snes/loadertest/myEvents.h
Normal file
6
snes/loadertest/myEvents.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
char fadeOut(word counter);
|
||||||
|
char fadeIn(word counter);
|
||||||
|
char mosaicOut(word counter);
|
||||||
|
char mosaicIn(word counter);
|
||||||
|
char NMIReadPad(word counter);
|
||||||
|
char scrollLeft(word counter);
|
||||||
26
snes/loadertest/pad.c
Normal file
26
snes/loadertest/pad.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "data.h";
|
||||||
|
#include "pad.h";
|
||||||
|
#include "debug.h";
|
||||||
|
|
||||||
|
void enablePad(void)
|
||||||
|
{
|
||||||
|
// Enable pad reading and NMI
|
||||||
|
*(byte *) 0x4200 = 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
|
void disablePad(void)
|
||||||
|
{
|
||||||
|
// Enable pad reading and NMI
|
||||||
|
*(byte *) 0x4200 = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
padStatus readPad(byte padNumber)
|
||||||
|
{
|
||||||
|
word test;
|
||||||
|
padStatus *status;
|
||||||
|
padNumber = padNumber << 1;
|
||||||
|
test = (word) * (byte *) 0x4218 + padNumber << 8;
|
||||||
|
test |= (word) * (byte *) 0x4219 + padNumber;
|
||||||
|
status = (padStatus *) & test;
|
||||||
|
return *status;
|
||||||
|
}
|
||||||
20
snes/loadertest/pad.h
Normal file
20
snes/loadertest/pad.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
typedef struct padStatus {
|
||||||
|
byte right:1;
|
||||||
|
byte left:1;
|
||||||
|
byte down:1;
|
||||||
|
byte up:1;
|
||||||
|
byte start:1; // Enter
|
||||||
|
byte select:1; // Space
|
||||||
|
byte Y:1; // X
|
||||||
|
byte B:1; // C
|
||||||
|
// --------------------------------
|
||||||
|
byte Dummy:4;
|
||||||
|
byte R:1; // Z
|
||||||
|
byte L:1; // A
|
||||||
|
byte X:1; // S
|
||||||
|
byte A:1; // D
|
||||||
|
} padStatus;
|
||||||
|
|
||||||
|
extern void enablePad(void);
|
||||||
|
extern void disablePad(void);
|
||||||
|
extern padStatus readPad(byte padNumber);
|
||||||
9
snes/loadertest/ressource.asm
Normal file
9
snes/loadertest/ressource.asm
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
ressource .section
|
||||||
|
|
||||||
|
|
||||||
|
XDEF _~debugFont_pic
|
||||||
|
_~debugFont_pic
|
||||||
|
INSERT ressource/debugFont.pic
|
||||||
|
|
||||||
|
|
||||||
|
.ends
|
||||||
2
snes/loadertest/ressource.h
Normal file
2
snes/loadertest/ressource.h
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
extern word debugFont_pic[];
|
||||||
BIN
snes/loadertest/ressource/debugFont.clr
Normal file
BIN
snes/loadertest/ressource/debugFont.clr
Normal file
Binary file not shown.
BIN
snes/loadertest/ressource/debugFont.pcx
Normal file
BIN
snes/loadertest/ressource/debugFont.pcx
Normal file
Binary file not shown.
BIN
snes/loadertest/ressource/debugFont.pic
Normal file
BIN
snes/loadertest/ressource/debugFont.pic
Normal file
Binary file not shown.
BIN
snes/loadertest/ressource/debugFont.xcf
Normal file
BIN
snes/loadertest/ressource/debugFont.xcf
Normal file
Binary file not shown.
BIN
snes/loadertest/tools/padbin.exe
Normal file
BIN
snes/loadertest/tools/padbin.exe
Normal file
Binary file not shown.
36
snes/quickdevloader/conv_rle.py
Normal file
36
snes/quickdevloader/conv_rle.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import binascii
|
||||||
|
data = open("rom.smc","r").read()
|
||||||
|
data = binascii.rlecode_hqx(data)
|
||||||
|
|
||||||
|
cfile = open("loader.c","w")
|
||||||
|
hfile = open("loader.h","w")
|
||||||
|
|
||||||
|
hfile.write('''
|
||||||
|
#ifndef __FIFO_H__
|
||||||
|
#define __FIFO_H__
|
||||||
|
|
||||||
|
#define ROM_SIZE %i
|
||||||
|
|
||||||
|
#endif
|
||||||
|
''' % len(data))
|
||||||
|
|
||||||
|
cfile.write('''
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <loader.h>
|
||||||
|
|
||||||
|
const char _rom[ROM_SIZE] PROGMEM = {
|
||||||
|
''')
|
||||||
|
|
||||||
|
for idx,c in enumerate(data):
|
||||||
|
c = ord(c)
|
||||||
|
if idx<len(data)-1:
|
||||||
|
cfile.write("0x%02x," % c)
|
||||||
|
else:
|
||||||
|
cfile.write("0x%02x" % c)
|
||||||
|
if idx and idx%16==0:
|
||||||
|
cfile.write("\n")
|
||||||
|
cfile.write('''
|
||||||
|
};
|
||||||
|
''')
|
||||||
|
cfile.close()
|
||||||
1904
snes/quickdevloader/loader.c
Normal file
1904
snes/quickdevloader/loader.c
Normal file
File diff suppressed because it is too large
Load Diff
7
snes/quickdevloader/loader.h
Normal file
7
snes/quickdevloader/loader.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
#ifndef __FIFO_H__
|
||||||
|
#define __FIFO_H__
|
||||||
|
|
||||||
|
#define ROM_SIZE 30346
|
||||||
|
|
||||||
|
#endif
|
||||||
24
snes/quickdevloader/makefile
Normal file
24
snes/quickdevloader/makefile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# 65816 stuff
|
||||||
|
AC = wla-65816
|
||||||
|
AFLAGS = -o
|
||||||
|
LD = wlalink
|
||||||
|
LDFLAGS = -vsr
|
||||||
|
FL = snesflash
|
||||||
|
FLFLAGS = -wf
|
||||||
|
UCON = ucon64
|
||||||
|
UCONFLAGS = --port=usb --xsnesram
|
||||||
|
SFILES = main.asm
|
||||||
|
OFILES = $(SFILES:.asm=.o)
|
||||||
|
ROMFILE = main.smc
|
||||||
|
EMU = zsnes
|
||||||
|
# spc stuff
|
||||||
|
SPCAC = wla-spc700
|
||||||
|
SPCSFILES = data/apu/apucode.asm
|
||||||
|
SPCOFILES = $(SPCSFILES:.asm=.o)
|
||||||
|
SPCFILE = $(SPCSFILES:.asm=.bin)
|
||||||
|
|
||||||
|
|
||||||
|
all:
|
||||||
|
mv -v main.smc main.smc.last
|
||||||
|
wget http://dforce3000.de/main.smc
|
||||||
|
python ../../scripts/conv_rle.py main.smc
|
||||||
957
todo.sh
Executable file
957
todo.sh
Executable file
@@ -0,0 +1,957 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
# NOTE: Todo.sh requires the .todo/config configuration file to run.
|
||||||
|
# Place the .todo/config file in your home directory or use the -d option for a custom location.
|
||||||
|
|
||||||
|
# Your todo/done/report.txt locations
|
||||||
|
export TODO_DIR=$(pwd)
|
||||||
|
export TODO_FILE="$TODO_DIR/todo.txt"
|
||||||
|
export DONE_FILE="$TODO_DIR/done.txt"
|
||||||
|
export REPORT_FILE="$TODO_DIR/report.txt"
|
||||||
|
export TMP_FILE="$TODO_DIR/todo.tmp"
|
||||||
|
|
||||||
|
[ -f VERSION-FILE ] && . VERSION-FILE || VERSION="@DEV_VERSION@"
|
||||||
|
version() { sed -e 's/^ //' <<EndVersion
|
||||||
|
TODO.TXT Command Line Interface v$VERSION
|
||||||
|
|
||||||
|
First release: 5/11/2006
|
||||||
|
Original conception by: Gina Trapani (http://ginatrapani.org)
|
||||||
|
Contributors: http://github.com/ginatrapani/todo.txt-cli/network
|
||||||
|
License: GPL, http://www.gnu.org/copyleft/gpl.html
|
||||||
|
More information and mailing list at http://todotxt.com
|
||||||
|
Code repository: http://github.com/ginatrapani/todo.txt-cli/tree/master
|
||||||
|
EndVersion
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set script name early.
|
||||||
|
TODO_SH=$(basename "$0")
|
||||||
|
export TODO_SH
|
||||||
|
|
||||||
|
oneline_usage="$TODO_SH [-fhpantvV] [-d todo_config] action [task_number] [task_description]"
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
sed -e 's/^ //' <<EndUsage
|
||||||
|
Usage: $oneline_usage
|
||||||
|
Try '$TODO_SH -h' for more information.
|
||||||
|
EndUsage
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
shorthelp()
|
||||||
|
{
|
||||||
|
sed -e 's/^ //' <<EndHelp
|
||||||
|
Usage: $oneline_usage
|
||||||
|
|
||||||
|
Actions:
|
||||||
|
add|a "THING I NEED TO DO +project @context"
|
||||||
|
addto DEST "TEXT TO ADD"
|
||||||
|
append|app NUMBER "TEXT TO APPEND"
|
||||||
|
archive
|
||||||
|
command [ACTIONS]
|
||||||
|
del|rm NUMBER [TERM]
|
||||||
|
dp|depri NUMBER
|
||||||
|
do NUMBER
|
||||||
|
help
|
||||||
|
list|ls [TERM...]
|
||||||
|
listall|lsa [TERM...]
|
||||||
|
listcon|lsc
|
||||||
|
listfile|lf SRC [TERM...]
|
||||||
|
listpri|lsp [PRIORITY]
|
||||||
|
listproj|lsprj
|
||||||
|
move|mv NUMBER DEST [SRC]
|
||||||
|
prepend|prep NUMBER "TEXT TO PREPEND"
|
||||||
|
pri|p NUMBER PRIORITY
|
||||||
|
replace NUMBER "UPDATED TODO"
|
||||||
|
report
|
||||||
|
|
||||||
|
See "help" for more details.
|
||||||
|
EndHelp
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
sed -e 's/^ //' <<EndHelp
|
||||||
|
Usage: $oneline_usage
|
||||||
|
|
||||||
|
Actions:
|
||||||
|
add "THING I NEED TO DO +project @context"
|
||||||
|
a "THING I NEED TO DO +project @context"
|
||||||
|
Adds THING I NEED TO DO to your todo.txt file on its own line.
|
||||||
|
Project and context notation optional.
|
||||||
|
Quotes optional.
|
||||||
|
|
||||||
|
addto DEST "TEXT TO ADD"
|
||||||
|
Adds a line of text to any file located in the todo.txt directory.
|
||||||
|
For example, addto inbox.txt "decide about vacation"
|
||||||
|
|
||||||
|
append NUMBER "TEXT TO APPEND"
|
||||||
|
app NUMBER "TEXT TO APPEND"
|
||||||
|
Adds TEXT TO APPEND to the end of the todo on line NUMBER.
|
||||||
|
Quotes optional.
|
||||||
|
|
||||||
|
archive
|
||||||
|
Moves done items from todo.txt to done.txt and removes blank lines.
|
||||||
|
|
||||||
|
command [ACTIONS]
|
||||||
|
Runs the remaining arguments using only todo.sh builtins.
|
||||||
|
Will not call any .todo.actions.d scripts.
|
||||||
|
|
||||||
|
del NUMBER [TERM]
|
||||||
|
rm NUMBER [TERM]
|
||||||
|
Deletes the item on line NUMBER in todo.txt.
|
||||||
|
If term specified, deletes only the term from the line.
|
||||||
|
|
||||||
|
depri NUMBER
|
||||||
|
dp NUMBER
|
||||||
|
Deprioritizes (removes the priority) from the item
|
||||||
|
on line NUMBER in todo.txt.
|
||||||
|
|
||||||
|
do NUMBER[, NUMBER, NUMBER, ...]
|
||||||
|
Marks item(s) on line NUMBER as done in todo.txt.
|
||||||
|
|
||||||
|
help
|
||||||
|
Display this help message.
|
||||||
|
|
||||||
|
list [TERM...]
|
||||||
|
ls [TERM...]
|
||||||
|
Displays all todo's that contain TERM(s) sorted by priority with line
|
||||||
|
numbers. If no TERM specified, lists entire todo.txt.
|
||||||
|
|
||||||
|
listall [TERM...]
|
||||||
|
lsa [TERM...]
|
||||||
|
Displays all the lines in todo.txt AND done.txt that contain TERM(s)
|
||||||
|
sorted by priority with line numbers. If no TERM specified, lists
|
||||||
|
entire todo.txt AND done.txt concatenated and sorted.
|
||||||
|
|
||||||
|
listcon
|
||||||
|
lsc
|
||||||
|
Lists all the task contexts that start with the @ sign in todo.txt.
|
||||||
|
|
||||||
|
listfile SRC [TERM...]
|
||||||
|
lf SRC [TERM...]
|
||||||
|
Displays all the lines in SRC file located in the todo.txt directory,
|
||||||
|
sorted by priority with line numbers. If TERM specified, lists
|
||||||
|
all lines that contain TERM in SRC file.
|
||||||
|
|
||||||
|
listpri [PRIORITY]
|
||||||
|
lsp [PRIORITY]
|
||||||
|
Displays all items prioritized PRIORITY.
|
||||||
|
If no PRIORITY specified, lists all prioritized items.
|
||||||
|
|
||||||
|
listproj
|
||||||
|
lsprj
|
||||||
|
Lists all the projects that start with the + sign in todo.txt.
|
||||||
|
|
||||||
|
move NUMBER DEST [SRC]
|
||||||
|
mv NUMBER DEST [SRC]
|
||||||
|
Moves a line from source text file (SRC) to destination text file (DEST).
|
||||||
|
Both source and destination file must be located in the directory defined
|
||||||
|
in the configuration directory. When SRC is not defined
|
||||||
|
it's by default todo.txt.
|
||||||
|
|
||||||
|
prepend NUMBER "TEXT TO PREPEND"
|
||||||
|
prep NUMBER "TEXT TO PREPEND"
|
||||||
|
Adds TEXT TO PREPEND to the beginning of the todo on line NUMBER.
|
||||||
|
Quotes optional.
|
||||||
|
|
||||||
|
pri NUMBER PRIORITY
|
||||||
|
p NUMBER PRIORITY
|
||||||
|
Adds PRIORITY to todo on line NUMBER. If the item is already
|
||||||
|
prioritized, replaces current priority with new PRIORITY.
|
||||||
|
PRIORITY must be an uppercase letter between A and Z.
|
||||||
|
|
||||||
|
replace NUMBER "UPDATED TODO"
|
||||||
|
Replaces todo on line NUMBER with UPDATED TODO.
|
||||||
|
|
||||||
|
report
|
||||||
|
Adds the number of open todo's and closed done's to report.txt.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-@
|
||||||
|
Hide context names in list output. Use twice to show context
|
||||||
|
names (default).
|
||||||
|
-+
|
||||||
|
Hide project names in list output. Use twice to show project
|
||||||
|
names (default).
|
||||||
|
-d CONFIG_FILE
|
||||||
|
Use a configuration file other than the default ~/.todo/config
|
||||||
|
-f
|
||||||
|
Forces actions without confirmation or interactive input
|
||||||
|
-h
|
||||||
|
Display a short help message
|
||||||
|
-p
|
||||||
|
Plain mode turns off colors
|
||||||
|
-P
|
||||||
|
Hide priority labels in list output. Use twice to show
|
||||||
|
priority labels (default).
|
||||||
|
-a
|
||||||
|
Don't auto-archive tasks automatically on completion
|
||||||
|
-n
|
||||||
|
Don't preserve line numbers; automatically remove blank lines
|
||||||
|
on task deletion
|
||||||
|
-t
|
||||||
|
Prepend the current date to a task automatically
|
||||||
|
when it's added.
|
||||||
|
-v
|
||||||
|
Verbose mode turns on confirmation messages
|
||||||
|
-vv
|
||||||
|
Extra verbose mode prints some debugging information
|
||||||
|
-V
|
||||||
|
Displays version, license and credits
|
||||||
|
|
||||||
|
|
||||||
|
Environment variables:
|
||||||
|
TODOTXT_AUTO_ARCHIVE=0 is same as option -a
|
||||||
|
TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE
|
||||||
|
TODOTXT_FORCE=1 is same as option -f
|
||||||
|
TODOTXT_PRESERVE_LINE_NUMBERS=0 is same as option -n
|
||||||
|
TODOTXT_PLAIN=1 is same as option -p
|
||||||
|
TODOTXT_DATE_ON_ADD=1 is same as option -t
|
||||||
|
TODOTXT_VERBOSE=1 is same as option -v
|
||||||
|
TODOTXT_DEFAULT_ACTION="" run this when called with no arguments
|
||||||
|
TODOTXT_SORT_COMMAND="sort ..." customize list output
|
||||||
|
TODOTXT_FINAL_FILTER="sed ..." customize list after color, P@+ hiding
|
||||||
|
EndHelp
|
||||||
|
|
||||||
|
if [ -d "$TODO_ACTIONS_DIR" ]
|
||||||
|
then
|
||||||
|
echo ""
|
||||||
|
for action in "$TODO_ACTIONS_DIR"/*
|
||||||
|
do
|
||||||
|
if [ -x "$action" ]
|
||||||
|
then
|
||||||
|
"$action" usage
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
echo "$*"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup()
|
||||||
|
{
|
||||||
|
[ -f "$TMP_FILE" ] && rm "$TMP_FILE"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
archive()
|
||||||
|
{
|
||||||
|
#defragment blank lines
|
||||||
|
sed -i.bak -e '/./!d' "$TODO_FILE"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x " "$TODO_FILE"
|
||||||
|
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
|
||||||
|
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||||
|
cp "$TODO_FILE" "$TMP_FILE"
|
||||||
|
sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
|
||||||
|
#[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed."
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
|
||||||
|
cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# == PROCESS OPTIONS ==
|
||||||
|
while getopts ":fhpnatvV+@Pd:" Option
|
||||||
|
do
|
||||||
|
case $Option in
|
||||||
|
'@' )
|
||||||
|
## HIDE_CONTEXT_NAMES starts at zero (false); increment it to one
|
||||||
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
|
## is seen after that, increment it again so that an even
|
||||||
|
## number hides project names and an odd number shows project
|
||||||
|
## names.
|
||||||
|
: $(( HIDE_CONTEXT_NAMES++ ))
|
||||||
|
if [ $(( $HIDE_CONTEXT_NAMES % 2 )) -eq 0 ]
|
||||||
|
then
|
||||||
|
## Zero or even value -- show context names
|
||||||
|
unset HIDE_CONTEXTS_SUBSTITUTION
|
||||||
|
else
|
||||||
|
## One or odd value -- hide context names
|
||||||
|
export HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}'
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
'+' )
|
||||||
|
## HIDE_PROJECT_NAMES starts at zero (false); increment it to one
|
||||||
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
|
## is seen after that, increment it again so that an even
|
||||||
|
## number hides project names and an odd number shows project
|
||||||
|
## names.
|
||||||
|
: $(( HIDE_PROJECT_NAMES++ ))
|
||||||
|
if [ $(( $HIDE_PROJECT_NAMES % 2 )) -eq 0 ]
|
||||||
|
then
|
||||||
|
## Zero or even value -- show project names
|
||||||
|
unset HIDE_PROJECTS_SUBSTITUTION
|
||||||
|
else
|
||||||
|
## One or odd value -- hide project names
|
||||||
|
export HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}'
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
a )
|
||||||
|
TODOTXT_AUTO_ARCHIVE=0
|
||||||
|
;;
|
||||||
|
d )
|
||||||
|
TODOTXT_CFG_FILE=$OPTARG
|
||||||
|
;;
|
||||||
|
f )
|
||||||
|
TODOTXT_FORCE=1
|
||||||
|
;;
|
||||||
|
h )
|
||||||
|
shorthelp
|
||||||
|
;;
|
||||||
|
n )
|
||||||
|
TODOTXT_PRESERVE_LINE_NUMBERS=0
|
||||||
|
;;
|
||||||
|
p )
|
||||||
|
TODOTXT_PLAIN=1
|
||||||
|
;;
|
||||||
|
P )
|
||||||
|
## HIDE_PRIORITY_LABELS starts at zero (false); increment it to one
|
||||||
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
|
## is seen after that, increment it again so that an even
|
||||||
|
## number hides project names and an odd number shows project
|
||||||
|
## names.
|
||||||
|
: $(( HIDE_PRIORITY_LABELS++ ))
|
||||||
|
if [ $(( $HIDE_PRIORITY_LABELS % 2 )) -eq 0 ]
|
||||||
|
then
|
||||||
|
## Zero or even value -- show priority labels
|
||||||
|
unset HIDE_PRIORITY_SUBSTITUTION
|
||||||
|
else
|
||||||
|
## One or odd value -- hide priority labels
|
||||||
|
export HIDE_PRIORITY_SUBSTITUTION="([A-Z])[[:space:]]"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
t )
|
||||||
|
TODOTXT_DATE_ON_ADD=1
|
||||||
|
;;
|
||||||
|
v )
|
||||||
|
: $(( TODOTXT_VERBOSE++ ))
|
||||||
|
;;
|
||||||
|
V )
|
||||||
|
version
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $(($OPTIND - 1))
|
||||||
|
|
||||||
|
# defaults if not yet defined
|
||||||
|
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1}
|
||||||
|
TODOTXT_PLAIN=${TODOTXT_PLAIN:-0}
|
||||||
|
TODOTXT_CFG_FILE=${TODOTXT_CFG_FILE:-$HOME/.todo/config}
|
||||||
|
TODOTXT_FORCE=${TODOTXT_FORCE:-0}
|
||||||
|
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
|
||||||
|
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1}
|
||||||
|
TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
|
||||||
|
TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
|
||||||
|
TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2}
|
||||||
|
TODOTXT_FINAL_FILTER=${TODOTXT_FINAL_FILTER:-cat}
|
||||||
|
|
||||||
|
# Export all TODOTXT_* variables
|
||||||
|
export ${!TODOTXT_@}
|
||||||
|
|
||||||
|
# Default color map
|
||||||
|
export NONE=''
|
||||||
|
export BLACK='\\033[0;30m'
|
||||||
|
export RED='\\033[0;31m'
|
||||||
|
export GREEN='\\033[0;32m'
|
||||||
|
export BROWN='\\033[0;33m'
|
||||||
|
export BLUE='\\033[0;34m'
|
||||||
|
export PURPLE='\\033[0;35m'
|
||||||
|
export CYAN='\\033[0;36m'
|
||||||
|
export LIGHT_GREY='\\033[0;37m'
|
||||||
|
export DARK_GREY='\\033[1;30m'
|
||||||
|
export LIGHT_RED='\\033[1;31m'
|
||||||
|
export LIGHT_GREEN='\\033[1;32m'
|
||||||
|
export YELLOW='\\033[1;33m'
|
||||||
|
export LIGHT_BLUE='\\033[1;34m'
|
||||||
|
export LIGHT_PURPLE='\\033[1;35m'
|
||||||
|
export LIGHT_CYAN='\\033[1;36m'
|
||||||
|
export WHITE='\\033[1;37m'
|
||||||
|
export DEFAULT='\\033[0m'
|
||||||
|
|
||||||
|
# Default priority->color map.
|
||||||
|
export PRI_A=$YELLOW # color for A priority
|
||||||
|
export PRI_B=$GREEN # color for B priority
|
||||||
|
export PRI_C=$LIGHT_BLUE # color for C priority
|
||||||
|
export PRI_X=$WHITE # color for rest of them
|
||||||
|
|
||||||
|
[ -e "$TODOTXT_CFG_FILE" ] || {
|
||||||
|
CFG_FILE_ALT="$HOME/todo.cfg"
|
||||||
|
|
||||||
|
if [ -e "$CFG_FILE_ALT" ]
|
||||||
|
then
|
||||||
|
TODOTXT_CFG_FILE="$CFG_FILE_ALT"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
[ -e "$TODOTXT_CFG_FILE" ] || {
|
||||||
|
CFG_FILE_ALT="$HOME/.todo.cfg"
|
||||||
|
|
||||||
|
if [ -e "$CFG_FILE_ALT" ]
|
||||||
|
then
|
||||||
|
TODOTXT_CFG_FILE="$CFG_FILE_ALT"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z "$TODO_ACTIONS_DIR" -o ! -d "$TODO_ACTIONS_DIR" ]
|
||||||
|
then
|
||||||
|
TODO_ACTIONS_DIR="$HOME/.todo/actions"
|
||||||
|
export TODO_ACTIONS_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -d "$TODO_ACTIONS_DIR" ] || {
|
||||||
|
TODO_ACTIONS_DIR_ALT="$HOME/.todo.actions.d"
|
||||||
|
|
||||||
|
if [ -d "$TODO_ACTIONS_DIR_ALT" ]
|
||||||
|
then
|
||||||
|
TODO_ACTIONS_DIR="$TODO_ACTIONS_DIR_ALT"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# === SANITY CHECKS (thanks Karl!) ===
|
||||||
|
#[ -r "$TODOTXT_CFG_FILE" ] || die "Fatal error: Cannot read configuration file $TODOTXT_CFG_FILE"
|
||||||
|
|
||||||
|
#. "$TODOTXT_CFG_FILE"
|
||||||
|
|
||||||
|
ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
||||||
|
|
||||||
|
[ -z "$ACTION" ] && usage
|
||||||
|
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
|
||||||
|
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $TODO_DIR"
|
||||||
|
|
||||||
|
[ -w "$TMP_FILE" ] || echo -n > "$TMP_FILE" || die "Fatal Error: Unable to write to $TMP_FILE"
|
||||||
|
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
|
||||||
|
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
|
||||||
|
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
|
||||||
|
|
||||||
|
if [ $TODOTXT_PLAIN = 1 ]; then
|
||||||
|
PRI_A=$NONE
|
||||||
|
PRI_B=$NONE
|
||||||
|
PRI_C=$NONE
|
||||||
|
PRI_X=$NONE
|
||||||
|
DEFAULT=$NONE
|
||||||
|
fi
|
||||||
|
|
||||||
|
# === HEAVY LIFTING ===
|
||||||
|
shopt -s extglob
|
||||||
|
|
||||||
|
_list() {
|
||||||
|
local FILE="$1"
|
||||||
|
## If the file starts with a "/" use absolute path. Otherwise,
|
||||||
|
## try to find it in either $TODO_DIR or using a relative path
|
||||||
|
if [ "${1:0:1}" == / ]
|
||||||
|
then
|
||||||
|
## Absolute path
|
||||||
|
src="$FILE"
|
||||||
|
elif [ -f "$TODO_DIR/$FILE" ]
|
||||||
|
then
|
||||||
|
## Path relative to todo.sh directory
|
||||||
|
src="$TODO_DIR/$1"
|
||||||
|
elif [ -f "$FILE" ]
|
||||||
|
then
|
||||||
|
## Path relative to current working directory
|
||||||
|
src="$FILE"
|
||||||
|
else
|
||||||
|
echo "TODO: File $FILE does not exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Get our search arguments, if any
|
||||||
|
shift ## was file name, new $1 is first search term
|
||||||
|
|
||||||
|
## Prefix the filter_command with the pre_filter_command
|
||||||
|
filter_command="${pre_filter_command:-}"
|
||||||
|
|
||||||
|
for search_term in "$@"
|
||||||
|
do
|
||||||
|
## See if the first character of $search_term is a dash
|
||||||
|
if [ ${search_term:0:1} != '-' ]
|
||||||
|
then
|
||||||
|
## First character isn't a dash: hide lines that don't match
|
||||||
|
## this $search_term
|
||||||
|
filter_command="${filter_command:-} ${filter_command:+|} \
|
||||||
|
grep -i \"$search_term\" "
|
||||||
|
else
|
||||||
|
## First character is a dash: hide lines that match this
|
||||||
|
## $search_term
|
||||||
|
#
|
||||||
|
## Remove the first character (-) before adding to our filter command
|
||||||
|
filter_command="${filter_command:-} ${filter_command:+|} \
|
||||||
|
grep -v -i \"${search_term:1}\" "
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
## If post_filter_command is set, append it to the filter_command
|
||||||
|
[ -n "$post_filter_command" ] && {
|
||||||
|
filter_command="${filter_command:-}${filter_command:+ | }${post_filter_command:-}"
|
||||||
|
}
|
||||||
|
|
||||||
|
## Figure out how much padding we need to use
|
||||||
|
## We need one level of padding for each power of 10 $LINES uses
|
||||||
|
LINES=$( sed -n '$ =' "$src" )
|
||||||
|
PADDING=${#LINES}
|
||||||
|
|
||||||
|
## Number the file, then run the filter command,
|
||||||
|
## then sort and mangle output some more
|
||||||
|
items=$(
|
||||||
|
sed = "$src" \
|
||||||
|
| sed "N; s/^/ /; s/ *\(.\{$PADDING,\}\)\n/\1 /" \
|
||||||
|
| grep -v "^[0-9]\+ *$"
|
||||||
|
)
|
||||||
|
if [ "${filter_command}" ]; then
|
||||||
|
filtered_items=$(echo -ne "$items" | eval ${filter_command})
|
||||||
|
else
|
||||||
|
filtered_items=$items
|
||||||
|
fi
|
||||||
|
filtered_items=$(
|
||||||
|
echo -ne "$filtered_items" \
|
||||||
|
| sed '''
|
||||||
|
s/^ /00000/;
|
||||||
|
s/^ /0000/;
|
||||||
|
s/^ /000/;
|
||||||
|
s/^ /00/;
|
||||||
|
s/^ /0/;
|
||||||
|
''' \
|
||||||
|
| eval ${TODOTXT_SORT_COMMAND} \
|
||||||
|
| sed '''
|
||||||
|
/^[0-9]\{'$PADDING'\} x /! {
|
||||||
|
s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g;
|
||||||
|
s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g;
|
||||||
|
s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g;
|
||||||
|
s/\(.*([D-Z]).*\)/'$PRI_X'\1'$DEFAULT'/g;
|
||||||
|
}
|
||||||
|
''' \
|
||||||
|
| sed '''
|
||||||
|
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
|
||||||
|
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||||
|
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
||||||
|
''' \
|
||||||
|
| eval ${TODOTXT_FINAL_FILTER} \
|
||||||
|
)
|
||||||
|
echo -ne "$filtered_items${filtered_items:+\n}"
|
||||||
|
|
||||||
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
|
NUMTASKS=$( echo -ne "$filtered_items" | sed -n '$ =' )
|
||||||
|
TOTALTASKS=$( echo -ne "$items" | sed -n '$ =' )
|
||||||
|
|
||||||
|
echo "--"
|
||||||
|
echo "TODO: ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown from $FILE"
|
||||||
|
fi
|
||||||
|
if [ $TODOTXT_VERBOSE -gt 1 ]
|
||||||
|
then
|
||||||
|
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
export -f _list
|
||||||
|
|
||||||
|
# == HANDLE ACTION ==
|
||||||
|
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||||
|
|
||||||
|
## If the first argument is "command", run the rest of the arguments
|
||||||
|
## using todo.sh builtins.
|
||||||
|
## Else, run a actions script with the name of the command if it exists
|
||||||
|
## or fallback to using a builtin
|
||||||
|
if [ "$action" == command ]
|
||||||
|
then
|
||||||
|
## Get rid of "command" from arguments list
|
||||||
|
shift
|
||||||
|
## Reset action to new first argument
|
||||||
|
action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' )
|
||||||
|
elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ]
|
||||||
|
then
|
||||||
|
"$TODO_ACTIONS_DIR/$action" "$@"
|
||||||
|
cleanup
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Only run if $action isn't found in .todo.actions.d
|
||||||
|
case $action in
|
||||||
|
"add" | "a")
|
||||||
|
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
|
||||||
|
echo -n "Add: "
|
||||||
|
read input
|
||||||
|
else
|
||||||
|
[ -z "$2" ] && die "usage: $TODO_SH add \"TODO ITEM\""
|
||||||
|
shift
|
||||||
|
input=$*
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
||||||
|
now=`date '+%Y-%m-%d'`
|
||||||
|
input="$now $input"
|
||||||
|
fi
|
||||||
|
echo "$input" >> "$TODO_FILE"
|
||||||
|
TASKNUM=$(sed -n '$ =' "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added on line $TASKNUM."
|
||||||
|
cleanup;;
|
||||||
|
|
||||||
|
"addto" )
|
||||||
|
[ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\""
|
||||||
|
dest="$TODO_DIR/$2"
|
||||||
|
[ -z "$3" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\""
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
input=$*
|
||||||
|
|
||||||
|
if [ -f "$dest" ]; then
|
||||||
|
echo "$input" >> "$dest"
|
||||||
|
TASKNUM=$(sed -n '$ =' "$dest")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added to $dest on line $TASKNUM."
|
||||||
|
else
|
||||||
|
echo "TODO: Destination file $dest does not exist."
|
||||||
|
fi
|
||||||
|
cleanup;;
|
||||||
|
|
||||||
|
"append" | "app" )
|
||||||
|
errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\""
|
||||||
|
shift; item=$1; shift
|
||||||
|
|
||||||
|
[ -z "$item" ] && die "$errmsg"
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
todo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ -z "$todo" ] && die "$item: No such todo."
|
||||||
|
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||||
|
echo -n "Append: "
|
||||||
|
read input
|
||||||
|
else
|
||||||
|
input=$*
|
||||||
|
fi
|
||||||
|
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
|
else
|
||||||
|
echo "TODO: Error appending task $item."
|
||||||
|
fi
|
||||||
|
cleanup;;
|
||||||
|
|
||||||
|
"archive" )
|
||||||
|
archive;;
|
||||||
|
|
||||||
|
"del" | "rm" )
|
||||||
|
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||||
|
errmsg="usage: $TODO_SH del ITEM#"
|
||||||
|
item=$2
|
||||||
|
[ -z "$item" ] && die "$errmsg"
|
||||||
|
|
||||||
|
if [ -z "$3" ]; then
|
||||||
|
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
if sed -ne "$item p" "$TODO_FILE" | grep "^."; then
|
||||||
|
DELETEME=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
|
||||||
|
if [ $TODOTXT_FORCE = 0 ]; then
|
||||||
|
echo "Delete '$DELETEME'? (y/n)"
|
||||||
|
read ANSWER
|
||||||
|
else
|
||||||
|
ANSWER="y"
|
||||||
|
fi
|
||||||
|
if [ "$ANSWER" = "y" ]; then
|
||||||
|
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
|
||||||
|
# delete line (changes line numbers)
|
||||||
|
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$TODO_FILE"
|
||||||
|
else
|
||||||
|
# leave blank line behind (preserves line numbers)
|
||||||
|
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
|
||||||
|
fi
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
|
||||||
|
cleanup
|
||||||
|
else
|
||||||
|
echo "TODO: No tasks were deleted."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$item: No such todo."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item."
|
||||||
|
fi ;;
|
||||||
|
|
||||||
|
"depri" | "dp" )
|
||||||
|
item=$2
|
||||||
|
errmsg="usage: $TODO_SH depri ITEM#"
|
||||||
|
|
||||||
|
todo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ -z "$todo" ] && die "$item: No such todo."
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
|
||||||
|
sed -e $item"s/^(.) //" "$TODO_FILE" > /dev/null 2>&1
|
||||||
|
|
||||||
|
if [ "$?" -eq 0 ]; then
|
||||||
|
#it's all good, continue
|
||||||
|
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
|
||||||
|
NEWTODO=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item deprioritized."
|
||||||
|
cleanup
|
||||||
|
else
|
||||||
|
die "$errmsg"
|
||||||
|
fi;;
|
||||||
|
|
||||||
|
"do" )
|
||||||
|
errmsg="usage: $TODO_SH do ITEM#"
|
||||||
|
# shift so we get arguments to the do request
|
||||||
|
shift;
|
||||||
|
|
||||||
|
# Split multiple do's, if comma seperated change to whitespace sepereated
|
||||||
|
# Loop the 'do' function for each item
|
||||||
|
for item in `echo $* | tr ',' ' '`; do
|
||||||
|
[ -z "$item" ] && die "$errmsg"
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
|
||||||
|
todo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ -z "$todo" ] && die "$item: No such todo."
|
||||||
|
|
||||||
|
now=`date '+%Y-%m-%d'`
|
||||||
|
# remove priority once item is done
|
||||||
|
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
||||||
|
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done."
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||||
|
archive
|
||||||
|
fi
|
||||||
|
cleanup ;;
|
||||||
|
|
||||||
|
"help" )
|
||||||
|
help
|
||||||
|
;;
|
||||||
|
|
||||||
|
"list" | "ls" )
|
||||||
|
shift ## Was ls; new $1 is first search term
|
||||||
|
_list "$TODO_FILE" "$@"
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
;;
|
||||||
|
|
||||||
|
"listall" | "lsa" )
|
||||||
|
shift ## Was lsa; new $1 is first search term
|
||||||
|
|
||||||
|
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
||||||
|
_list "$TMP_FILE" "$@"
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
;;
|
||||||
|
|
||||||
|
"listfile" | "lf" )
|
||||||
|
shift ## Was listfile, next $1 is file name
|
||||||
|
FILE="$1"
|
||||||
|
shift ## Was filename; next $1 is first search term
|
||||||
|
|
||||||
|
_list "$FILE" "$@"
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
;;
|
||||||
|
|
||||||
|
"listcon" | "lsc" )
|
||||||
|
grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u
|
||||||
|
cleanup ;;
|
||||||
|
|
||||||
|
"listproj" | "lsprj" )
|
||||||
|
grep -o '[^ ]*+[^ ]\+' "$TODO_FILE" | grep '^+' | sort -u
|
||||||
|
cleanup ;;
|
||||||
|
|
||||||
|
|
||||||
|
"listpri" | "lsp" )
|
||||||
|
shift ## was "listpri", new $1 is priority to list
|
||||||
|
|
||||||
|
if [ "${1:-}" ]
|
||||||
|
then
|
||||||
|
## A priority was specified
|
||||||
|
pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || {
|
||||||
|
die "usage: $TODO_SH listpri PRIORITY
|
||||||
|
note: PRIORITY must a single letter from A to Z."
|
||||||
|
}
|
||||||
|
else
|
||||||
|
## No priority specified; show all priority tasks
|
||||||
|
pri="[[:upper:]]"
|
||||||
|
fi
|
||||||
|
pri="($pri)"
|
||||||
|
|
||||||
|
_list "$TODO_FILE" "$pri"
|
||||||
|
;;
|
||||||
|
|
||||||
|
"move" | "mv" )
|
||||||
|
# replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||||
|
errmsg="usage: $TODO_SH mv ITEM# DEST [SRC]"
|
||||||
|
item=$2
|
||||||
|
dest="$TODO_DIR/$3"
|
||||||
|
src="$TODO_DIR/$4"
|
||||||
|
|
||||||
|
[ -z "$item" ] && die "$errmsg"
|
||||||
|
[ -z "$4" ] && src="$TODO_FILE"
|
||||||
|
[ -z "$dest" ] && die "$errmsg"
|
||||||
|
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
|
||||||
|
if [ -f "$src" ]; then
|
||||||
|
if [ -f "$dest" ]; then
|
||||||
|
if sed -ne "$item p" "$src" | grep "^."; then
|
||||||
|
MOVEME=$(sed "$item!d" "$src")
|
||||||
|
if [ $TODOTXT_FORCE = 0 ]; then
|
||||||
|
echo "Move '$MOVEME' from $src to $dest? (y/n)"
|
||||||
|
read ANSWER
|
||||||
|
else
|
||||||
|
ANSWER="y"
|
||||||
|
fi
|
||||||
|
if [ "$ANSWER" = "y" ]; then
|
||||||
|
if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
|
||||||
|
# delete line (changes line numbers)
|
||||||
|
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src"
|
||||||
|
else
|
||||||
|
# leave blank line behind (preserves line numbers)
|
||||||
|
sed -i.bak -e $item"s/^.*//" "$src"
|
||||||
|
fi
|
||||||
|
echo "$MOVEME" >> "$dest"
|
||||||
|
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
|
||||||
|
cleanup
|
||||||
|
else
|
||||||
|
echo "TODO: No tasks moved."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$item: No such item in $src."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "TODO: Destination file $dest does not exist."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "TODO: Source file $src does not exist."
|
||||||
|
fi
|
||||||
|
cleanup;;
|
||||||
|
|
||||||
|
"prepend" | "prep" )
|
||||||
|
errmsg="usage: $TODO_SH prepend ITEM# \"TEXT TO PREPEND\""
|
||||||
|
shift; item=$1; shift
|
||||||
|
|
||||||
|
[ -z "$item" ] && die "$errmsg"
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
|
||||||
|
todo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ -z "$todo" ] && die "$item: No such todo."
|
||||||
|
|
||||||
|
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||||
|
echo -n "Prepend: "
|
||||||
|
read input
|
||||||
|
else
|
||||||
|
input=$*
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test for then set priority
|
||||||
|
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
|
||||||
|
priority=$(sed "$item!d" "$TODO_FILE" | awk -F '\\(|\\)' '{print $2}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If priority isn't set prepend
|
||||||
|
if [ -z $priority ]; then
|
||||||
|
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
|
else
|
||||||
|
echo "TODO: Error prepending task $item."
|
||||||
|
fi
|
||||||
|
# If priority is set, remove priority, prepend and add back priority
|
||||||
|
else
|
||||||
|
if sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1 &|" "$TODO_FILE"; then
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
|
else
|
||||||
|
echo "TODO: Error prepending task $item."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
cleanup;;
|
||||||
|
|
||||||
|
"pri" | "p" )
|
||||||
|
item=$2
|
||||||
|
newpri=$( printf "%s\n" "$3" | tr 'a-z' 'A-Z' )
|
||||||
|
|
||||||
|
errmsg="usage: $TODO_SH pri ITEM# PRIORITY
|
||||||
|
note: PRIORITY must be anywhere from A to Z."
|
||||||
|
|
||||||
|
[ "$#" -ne 3 ] && die "$errmsg"
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
[[ "$newpri" = @([A-Z]) ]] || die "$errmsg"
|
||||||
|
|
||||||
|
sed -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE" > /dev/null 2>&1
|
||||||
|
|
||||||
|
if [ "$?" -eq 0 ]; then
|
||||||
|
#it's all good, continue
|
||||||
|
sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE"
|
||||||
|
NEWTODO=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item prioritized ($newpri)."
|
||||||
|
cleanup
|
||||||
|
else
|
||||||
|
die "$errmsg"
|
||||||
|
fi;;
|
||||||
|
|
||||||
|
"replace" )
|
||||||
|
errmsg="usage: $TODO_SH replace ITEM# \"UPDATED ITEM\""
|
||||||
|
shift; item=$1; shift
|
||||||
|
|
||||||
|
[ -z "$item" ] && die "$errmsg"
|
||||||
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
|
||||||
|
todo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ -z "$todo" ] && die "$item: No such todo."
|
||||||
|
|
||||||
|
# Test for then set priority
|
||||||
|
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
|
||||||
|
priority=$(sed "$item!d" "$TODO_FILE" | awk -F '\\(|\\)' '{print $2}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||||
|
echo -n "Replacement: "
|
||||||
|
read input
|
||||||
|
else
|
||||||
|
input=$*
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If priority isn't set replace, if it is remove priority, replace then add priority again
|
||||||
|
if [ -z $priority ]; then
|
||||||
|
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
|
||||||
|
else
|
||||||
|
sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1|" "$TODO_FILE"
|
||||||
|
fi
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $todo"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "replaced with"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $NEWTODO"
|
||||||
|
cleanup;;
|
||||||
|
|
||||||
|
"report" )
|
||||||
|
#archive first
|
||||||
|
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
|
||||||
|
sed -i.bak '/^x /d' "$TODO_FILE"
|
||||||
|
|
||||||
|
NUMLINES=$( sed -n '$ =' "$TODO_FILE" )
|
||||||
|
if [ ${NUMLINES:-0} = "0" ]; then
|
||||||
|
echo "datetime todos dones" >> "$REPORT_FILE"
|
||||||
|
fi
|
||||||
|
#now report
|
||||||
|
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
||||||
|
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||||
|
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' ';
|
||||||
|
echo ${TDONE:-0})
|
||||||
|
echo $TECHO >> "$REPORT_FILE"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||||
|
cat "$REPORT_FILE"
|
||||||
|
cleanup;;
|
||||||
|
|
||||||
|
* )
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user