Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3cc6f41e2 | ||
|
|
5a439f56bb | ||
|
|
7a8ae11ce1 | ||
|
|
e177b17ad8 | ||
|
|
54acc416b0 | ||
|
|
185b833929 | ||
|
|
97137ed993 | ||
|
|
e13b124e93 | ||
|
|
76254835ca | ||
|
|
1adabc080f | ||
|
|
6eead3e37d | ||
|
|
05bb485495 | ||
|
|
3c39e11784 | ||
|
|
2ad1d63ca6 | ||
|
|
53376edc09 | ||
|
|
ef82981d42 | ||
|
|
697742d59f | ||
|
|
6935aa9693 | ||
|
|
67e02fb38e | ||
|
|
a9a366895a | ||
|
|
596a26323a | ||
|
|
13c71760c8 | ||
|
|
f027b93a1a | ||
|
|
5b6e62a428 | ||
|
|
ea3113142e | ||
|
|
08a1c0b3e0 | ||
|
|
2e59b07d7d | ||
|
|
ec555efafd | ||
|
|
cfceee4db3 | ||
|
|
1d0eae3aec | ||
|
|
650b182ab4 | ||
|
|
b092b3e182 | ||
|
|
ab3f7704f0 | ||
|
|
859dcadbac | ||
|
|
c897497e24 | ||
|
|
ba64d2a683 | ||
|
|
65a852ebb4 | ||
|
|
2e99c42510 | ||
|
|
d777415549 | ||
|
|
3f91df1af6 | ||
|
|
1bbc73c363 | ||
|
|
a019317b6e | ||
|
|
243658c0d3 | ||
|
|
080598cb97 | ||
|
|
51087abaa2 | ||
|
|
7671a35127 | ||
|
|
1a7fb2487e | ||
|
|
a341e10efc | ||
|
|
b7cc7ea935 | ||
|
|
55aa99c4d3 | ||
|
|
2e432cd7a7 | ||
|
|
d3a48efb0b | ||
|
|
7c9aca48c9 | ||
|
|
440c24ad78 | ||
|
|
0d7fc524f2 | ||
|
|
b2e13a54eb | ||
|
|
850d1790cb | ||
|
|
9b3dcc844f | ||
|
|
5767b13385 | ||
|
|
ec68a9a1a1 | ||
|
|
54ac4204ed | ||
|
|
8a8b21615c | ||
|
|
49df405d14 | ||
|
|
7f0a9f9285 | ||
|
|
e7e5cfd126 | ||
|
|
6c702b9a68 | ||
|
|
2bdc53bd21 | ||
|
|
415b79751d | ||
|
|
b9425b1da5 | ||
|
|
9c4c880b0b | ||
|
|
c6b9c57e6d | ||
|
|
0295c8c385 | ||
|
|
2e01e2bfb3 | ||
|
|
07a0296886 | ||
|
|
0d473fd0dd | ||
|
|
5451aeb39b | ||
|
|
fa27d73167 | ||
|
|
4b0bec820e | ||
|
|
105575bc37 | ||
|
|
8beb0bbb4f | ||
|
|
6db781d12d | ||
|
|
a86d9d26bd | ||
|
|
d86f0ad5a9 | ||
|
|
d9b729754c | ||
|
|
f5cdf71fb1 | ||
|
|
d008551968 | ||
|
|
0d2c2c274b | ||
|
|
a28a7e928a | ||
|
|
8650109879 | ||
|
|
c30ca4ca54 | ||
|
|
2d601dac17 | ||
|
|
f8599fb60a | ||
|
|
db616a1637 | ||
|
|
935c1d6f7f | ||
|
|
325a09eff2 | ||
|
|
dab671a5da | ||
|
|
485a7831db | ||
|
|
99cee555c1 | ||
|
|
dc67d91c4f | ||
|
|
90d4a0d019 | ||
|
|
9be841521f | ||
|
|
e3067c7256 | ||
|
|
3a1f58ce18 | ||
|
|
a6e8d7e033 | ||
|
|
1fb3cfdfd9 | ||
|
|
04b2b9a02a | ||
|
|
58b422771a | ||
|
|
6256cab7ef | ||
|
|
c60d2f92fa | ||
|
|
aeb3638e1f | ||
|
|
0b81db48e3 | ||
|
|
5e31bc1946 | ||
|
|
9e1fec1ec6 | ||
|
|
87b5936c02 | ||
|
|
9efca9e242 | ||
|
|
f9e1a7a151 | ||
|
|
68b882acfb | ||
|
|
9469398c04 |
@@ -1,4 +0,0 @@
|
||||
--- !ditz.rubyforge.org,2008-03-06/config
|
||||
name: David
|
||||
email: david@optixx.org
|
||||
issue_dir: bugs
|
||||
+32
-12
@@ -33,6 +33,10 @@
|
||||
#include "config.h"
|
||||
#include "usbdrv/usbdrv.c"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* USBasp requests, taken from the original USBasp sourcecode
|
||||
*/
|
||||
@@ -74,8 +78,12 @@
|
||||
(LED_DIR ^= (1 << LED_PIN)));}
|
||||
|
||||
|
||||
#define AVR_BTLDR_EN_PORT PORTC
|
||||
#define AVR_BTLDR_EN_DIR DDRC
|
||||
#define AVR_BTLDR_EN_PIN PC1
|
||||
#define AVR_BTLDR_EN_IN PINC
|
||||
|
||||
|
||||
#undef AVR_BTLDR_SWITCH
|
||||
/*
|
||||
* some predefined signatures, taken from the original USBasp sourcecode
|
||||
*/
|
||||
@@ -449,6 +457,29 @@ int __attribute__ ((noreturn, OS_main)) main(void)
|
||||
uint16_t delay = 0;
|
||||
timeout = TIMEOUT;
|
||||
|
||||
DDRC &= ~(1 << AVR_BTLDR_EN_PIN);
|
||||
PORTC &= ~(1 << AVR_BTLDR_EN_PIN);
|
||||
|
||||
/*
|
||||
* if watchdog reset, disable watchdog and jump to app
|
||||
*/
|
||||
if (reset & _BV(WDRF)) {
|
||||
uart_puts("Found watchdog reset\n\r");
|
||||
MCUSR = 0;
|
||||
wdt_disable();
|
||||
uart_puts("Jump to 0x0000\n\r");
|
||||
jump_to_app();
|
||||
}
|
||||
|
||||
#ifdef AVR_BTLDR_SWITCH ENABLE
|
||||
if ((AVR_BTLDR_EN_IN & ( 1 << AVR_BTLDR_EN_PIN)) == 0){
|
||||
banner();
|
||||
uart_puts("Bootloader flashing is disabled\n\r");
|
||||
MCUSR = 0;
|
||||
leave_bootloader();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* if power-on reset, quit bootloader via watchdog reset
|
||||
@@ -459,17 +490,6 @@ int __attribute__ ((noreturn, OS_main)) main(void)
|
||||
MCUSR = 0;
|
||||
leave_bootloader();
|
||||
}
|
||||
/*
|
||||
* if watchdog reset, disable watchdog and jump to app
|
||||
*/
|
||||
else if (reset & _BV(WDRF)) {
|
||||
uart_puts("Found watchdog reset\n\r");
|
||||
MCUSR = 0;
|
||||
wdt_disable();
|
||||
uart_puts("Jump to 0x0000\n\r");
|
||||
jump_to_app();
|
||||
}
|
||||
|
||||
banner();
|
||||
uart_puts("Enter programming mode\n\r");
|
||||
/*
|
||||
|
||||
+19
-10
@@ -19,27 +19,31 @@
|
||||
DEBUG = 1
|
||||
TTY = /dev/tty.PL2303-00002126
|
||||
DEVICE = atmega644
|
||||
F_CPU = 20000000 # in Hz
|
||||
F_CPU = 20000000
|
||||
TARGET = main
|
||||
AVRDUDE = avrdude -c usbasp -p $(DEVICE)
|
||||
SIZE = avr-size
|
||||
|
||||
BOOT_ROM01 = ../../roms/qd16boot01.smc
|
||||
BOOT_ROM02 = ../../roms/qd16boot02.smc
|
||||
CONVERT_RLE = ../../scripts/conv_rle.py
|
||||
CONVERT_ZIP = ../../scripts/conv_zip.py
|
||||
|
||||
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
LDFLAGS = -Wl,-u,vfprintf -lprintf_flt
|
||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||
LDFLAGS =-Wl,-u,vfprintf
|
||||
CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \
|
||||
main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \
|
||||
dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \
|
||||
irq.o command.o testing.o
|
||||
system.o pwm.o util.o shell.o irq.o command.o testing.o inflate.o neginf/neginf.o
|
||||
else
|
||||
LDFLAGS = -Wl,-u
|
||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO
|
||||
LDFLAGS =-Wl,-u
|
||||
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 \
|
||||
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 irq.o
|
||||
sram.o crc.o debug.o dump.o rle.c loader.o \
|
||||
system.o util.o info.o shared_memory.o command.o irq.o \
|
||||
pwm.o inflate.o neginf/neginf.o
|
||||
endif
|
||||
|
||||
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||
@@ -76,6 +80,11 @@ fuse:
|
||||
flash: main.hex
|
||||
$(AVRDUDE) -U flash:w:main.hex:i
|
||||
|
||||
loader01:
|
||||
python $(CONVERT_RLE) $(BOOT_ROM01)
|
||||
|
||||
loader02:
|
||||
python $(CONVERT_ZIP) $(BOOT_ROM02)
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $< -o $@
|
||||
@@ -105,4 +114,4 @@ cpp:
|
||||
$(COMPILE) -E main.c
|
||||
|
||||
clean:
|
||||
rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
|
||||
rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s neginf/*.o
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
MD5=md5
|
||||
|
||||
all:
|
||||
gcc -c loader_test.c
|
||||
gcc -c inflate.c
|
||||
gcc -c neginf/neginf.c
|
||||
gcc -c inflate_test.c
|
||||
gcc -c ringbuffer.c
|
||||
gcc -o inflate_test inflate.o neginf.o inflate_test.o loader_test.o ringbuffer.o
|
||||
loader:
|
||||
python ../../scripts/conv_zip_test.py ../../roms/qd16boot02_half.smc
|
||||
|
||||
test:
|
||||
./inflate_test
|
||||
@$(MD5) out.smc
|
||||
@$(MD5) out_ref.smc
|
||||
@$(MD5) ../../roms/qd16boot02_half.smc
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# Revision: $:Id: checksize 83 2006-01-05 22:20:53Z cs $
|
||||
|
||||
error=0
|
||||
codelimit=65536 # default value
|
||||
codelimit=61440 # default value
|
||||
datalimit=4064 # default value; leave 32 bytes for stack
|
||||
|
||||
if [ $# -gt 1 ]; then
|
||||
|
||||
+83
-28
@@ -28,38 +28,93 @@
|
||||
#include "sram.h"
|
||||
#include "info.h"
|
||||
#include "irq.h"
|
||||
#include "usbdrv.h"
|
||||
#include "rle.h"
|
||||
#include "loader.h"
|
||||
#include "system.h"
|
||||
|
||||
extern uint32_t req_bank_size;
|
||||
#include "neginf/neginf.h"
|
||||
#include "inflate.h"
|
||||
|
||||
|
||||
void send_reset()
|
||||
extern usb_transaction_t usb_trans;
|
||||
extern system_t system;
|
||||
|
||||
extern const char *_rom[];
|
||||
extern const char _rom01[];
|
||||
extern const int _rom_size[];
|
||||
|
||||
void usb_connect()
|
||||
{
|
||||
info_P(PSTR("Reset SNES\n"));
|
||||
uint8_t i = 0;
|
||||
info_P(PSTR("USB init\n"));
|
||||
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
||||
cli();
|
||||
snes_reset_on();
|
||||
snes_reset_lo();
|
||||
_delay_ms(2);
|
||||
snes_reset_hi();
|
||||
snes_reset_off();
|
||||
sei();
|
||||
}
|
||||
|
||||
void send_irq()
|
||||
{
|
||||
snes_irq_on();
|
||||
snes_irq_lo();
|
||||
_delay_us(20);
|
||||
snes_irq_hi();
|
||||
snes_irq_off();
|
||||
}
|
||||
|
||||
void set_rom_mode()
|
||||
{
|
||||
if (req_bank_size == 0x8000) {
|
||||
snes_lorom();
|
||||
info_P(PSTR("Set SNES lowrom \n"));
|
||||
} else {
|
||||
snes_hirom();
|
||||
info_P(PSTR("Set SNES hirom \n"));
|
||||
info_P(PSTR("USB disconnect\n"));
|
||||
i = 10;
|
||||
while (--i) { /* fake USB disconnect for > 250 ms */
|
||||
_delay_ms(50);
|
||||
}
|
||||
led_on();
|
||||
usbDeviceConnect();
|
||||
info_P(PSTR("USB connect\n"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void boot_startup_rom(uint16_t init_delay)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t c;
|
||||
uint16_t j;
|
||||
uint32_t addr = 0x000000;
|
||||
PGM_VOID_P p_addr;
|
||||
|
||||
info_P(PSTR("Fetch loader rom\n"));
|
||||
|
||||
system_set_bus_avr();
|
||||
snes_irq_lo();
|
||||
system_snes_irq_off();
|
||||
system_set_rom_lorom();
|
||||
|
||||
|
||||
inflate_init();
|
||||
for (i=0; i<ROM_BUFFER_CNT; i++){
|
||||
p_addr = _rom[i];
|
||||
printf("idx: %i %lx\n",i,p_addr);
|
||||
for (j=0; j<_rom_size[i]; j++){
|
||||
//rle_decode(_rom[i], _rom_size[i], addr);
|
||||
c = pgm_read_byte((PGM_VOID_P)p_addr++);
|
||||
printf("%02x ",c);
|
||||
neginf_process_byte(c);
|
||||
|
||||
}
|
||||
}
|
||||
info_P(PSTR("\n"));
|
||||
|
||||
#if DO_CRC_CHECK_LOADER
|
||||
dump_memory(0x010000 - 0x100, 0x010000);
|
||||
uint16_t crc;
|
||||
crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
|
||||
info(PSTR("crc=%x\n"),crc);
|
||||
#endif
|
||||
|
||||
|
||||
snes_irq_lo();
|
||||
system_snes_irq_off();
|
||||
system_set_rom_hirom();
|
||||
system_set_wr_disable();
|
||||
system_set_bus_snes();
|
||||
|
||||
|
||||
system_send_snes_reset();
|
||||
_delay_ms(init_delay);
|
||||
}
|
||||
|
||||
void banner(){
|
||||
|
||||
}
|
||||
|
||||
void transaction_status(){
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
#ifndef __COMMAND_H__
|
||||
#define __COMMAND_H__
|
||||
|
||||
void send_reset();
|
||||
void send_irq();
|
||||
void set_rom_mode();
|
||||
void usb_connect();
|
||||
void boot_startup_rom(uint16_t init_delay);
|
||||
void banner();
|
||||
void transaction_status();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -42,9 +42,16 @@
|
||||
#define USB_MAX_TRANS 0xff
|
||||
#define USB_CRC_CHECK 0x01
|
||||
|
||||
#define TRANSFER_BUFFER_SIZE 0x200
|
||||
#define FORMAT_BUFFER_LEN 0x0FF
|
||||
#define TRANSFER_BUFFER_SIZE 0x000
|
||||
#define FORMAT_BUFFER_LEN 0x080
|
||||
#define RECEIVE_BUF_LEN 0x030
|
||||
#define HW_VERSION "2.6"
|
||||
#define SW_VERSION "1.0"
|
||||
|
||||
#define DO_CRC_CHECK_LOADER 0
|
||||
#define DO_CRC_CHECK 0
|
||||
#define DO_SHM_SCRATCHPAD 0
|
||||
#define DO_SHM 0
|
||||
#define DO_TIMER 0
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
|
||||
bottom_addr,top_addr);
|
||||
|
||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||
if (addr && addr % bank_size == 0) {
|
||||
if (addr && ((addr % bank_size) == 0)) {
|
||||
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++;
|
||||
|
||||
+4
-18
@@ -30,21 +30,6 @@ extern FILE uart_stdout;
|
||||
|
||||
extern int debug_level; /* the higher, the more messages... */
|
||||
|
||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||
#else
|
||||
void debug(int level, char* format, ...) {
|
||||
#ifdef NO_DEBUG
|
||||
|
||||
#else
|
||||
va_list args;
|
||||
if (!(debug_level & level))
|
||||
return;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NO_INFO
|
||||
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
|
||||
@@ -59,10 +44,11 @@ void debug_P(int level, PGM_P format, ...) {
|
||||
va_list args;
|
||||
if (!(debug_level & level))
|
||||
return;
|
||||
strlcpy_P(buffer_debug,format,FORMAT_BUFFER_LEN);
|
||||
strlcpy_P((char*)buffer_debug,format,FORMAT_BUFFER_LEN);
|
||||
va_start(args, format);
|
||||
vprintf(buffer_debug, args);
|
||||
vprintf((char*)buffer_debug, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "info.h"
|
||||
#include "uart.h"
|
||||
#include "sram.h"
|
||||
#include "dump.h"
|
||||
|
||||
|
||||
extern FILE uart_stdout;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/22/2009
|
||||
* Author: jannis@harderweb.de
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "neginf/neginf.h"
|
||||
#include "inflate.h"
|
||||
#include "assert.h"
|
||||
#include "ringbuffer.h"
|
||||
|
||||
char inflate_done = 0;
|
||||
char *mem_ref;
|
||||
|
||||
int addr_ref = 0;
|
||||
|
||||
int cnt_hit = 0;
|
||||
int cnt = 0;
|
||||
|
||||
|
||||
void inflate_init()
|
||||
{
|
||||
neginf_init(0);
|
||||
mem_ref = (char*)malloc(2<<15);
|
||||
addr_ref = 0;
|
||||
rb_init();
|
||||
}
|
||||
|
||||
void inflate_flush()
|
||||
{
|
||||
|
||||
rb_flush();
|
||||
FILE *file;
|
||||
printf("write out_ref.smc\n");
|
||||
file = fopen("out_ref.smc","w");
|
||||
fwrite(mem_ref,2<<15,1,file);
|
||||
fclose(file);
|
||||
printf("cnt=%i cnt_hit=%i\n",cnt,cnt_hit);
|
||||
}
|
||||
|
||||
void neginf_cb_completed()
|
||||
{
|
||||
inflate_done = 1;
|
||||
}
|
||||
|
||||
void neginf_cb_seq_byte(nbyte byte)
|
||||
{
|
||||
mem_ref[addr_ref++] = byte;
|
||||
rb_put(byte);
|
||||
}
|
||||
|
||||
void neginf_cb_copy(nsize from, nsize to, nint length)
|
||||
{
|
||||
int i;
|
||||
cnt++;
|
||||
if ((to - from) < ( 1024 * 2 ) ){
|
||||
cnt_hit++;
|
||||
}
|
||||
printf("neginf_cb_copy from=0x%06x to=0x%06x dist=%i len=%i\n",(int)from, (int)to, (int)(to - from), (int)length);
|
||||
for (i=0; i<length;i++){
|
||||
mem_ref[to+i] = mem_ref[from+i];
|
||||
}
|
||||
addr_ref = to + length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 09/22/2009
|
||||
* Author: jannis@harderweb.de
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __INFLATE_H__
|
||||
#define __INFLATE_H__
|
||||
|
||||
extern char inflate_done;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "neginf/neginf.h"
|
||||
#include "inflate.h"
|
||||
#include "loader_test.h"
|
||||
|
||||
extern const char _rom[];
|
||||
extern char inflate_done;
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
int j;
|
||||
char c;
|
||||
inflate_init();
|
||||
for (j=0; j< ROM_ZIP_SIZE; j++){
|
||||
neginf_process_byte(_rom[j]);
|
||||
}
|
||||
while(!inflate_done)
|
||||
neginf_process_byte(0x00);
|
||||
inflate_flush();
|
||||
return 0;
|
||||
}
|
||||
+2
-20
@@ -32,24 +32,6 @@
|
||||
extern FILE uart_stdout;
|
||||
|
||||
|
||||
#if defined(NO_INFO) && defined(__GNUC__)
|
||||
|
||||
#define info(format, args...) ((void)0)
|
||||
|
||||
#else
|
||||
void info(char* format, ...) {
|
||||
#ifdef NO_INFO
|
||||
|
||||
#else
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_INFO
|
||||
uint8_t buffer_info[FORMAT_BUFFER_LEN];
|
||||
#endif
|
||||
@@ -63,10 +45,10 @@ void info_P(PGM_P format, ...) {
|
||||
#ifdef NO_INFO
|
||||
|
||||
#else
|
||||
strlcpy_P(buffer_info,format,FORMAT_BUFFER_LEN);
|
||||
strlcpy_P((char*)buffer_info,format,FORMAT_BUFFER_LEN);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(buffer_info, args);
|
||||
vprintf((char*)buffer_info, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
}
|
||||
|
||||
+6
-2
@@ -34,7 +34,9 @@
|
||||
#include "debug.h"
|
||||
#include "info.h"
|
||||
#include "sram.h"
|
||||
|
||||
#include "system.h"
|
||||
|
||||
extern system_t system;
|
||||
|
||||
void (*jump_to_app) (void) = 0x0000;
|
||||
|
||||
@@ -43,24 +45,26 @@ void irq_init(){
|
||||
PCMSK3 |=(1<<PCINT27);
|
||||
PCICR |= (1<<PCIE3);
|
||||
sei();
|
||||
system.reset_irq = RESET_IRQ_ON;
|
||||
}
|
||||
|
||||
void irq_stop(){
|
||||
cli();
|
||||
PCMSK3 &=~(1<<PCINT27);
|
||||
sei();
|
||||
system.reset_irq = RESET_IRQ_OFF;
|
||||
}
|
||||
|
||||
void leave_application(void)
|
||||
{
|
||||
cli();
|
||||
usbDeviceDisconnect();
|
||||
system.avr_reset_count++;
|
||||
wdt_enable(WDTO_15MS);
|
||||
while (1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ISR (SIG_PIN_CHANGE3)
|
||||
{
|
||||
if (snes_reset_test()){
|
||||
|
||||
@@ -22,4 +22,7 @@
|
||||
#ifndef __IRQ_H__
|
||||
#define __IRQ_H__
|
||||
|
||||
void irq_init();
|
||||
void irq_stop();
|
||||
void leave_application(void);
|
||||
#endif
|
||||
|
||||
+2113
-1948
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,14 @@
|
||||
|
||||
/*
|
||||
File: qd16boot02.smc
|
||||
Time: Sat, 24 Oct 2009 19:05:36
|
||||
*/
|
||||
#ifndef __FIFO_H__
|
||||
#define __FIFO_H__
|
||||
|
||||
#define ROM_BUFFER_SIZE 31091
|
||||
#define ROM_HUFFMAN_SIZE 0
|
||||
#define ROM_RLE_SIZE 31091
|
||||
#define ROM_ZIP_SIZE 33654
|
||||
#define ROM_BUFFER_CNT 2
|
||||
|
||||
void irq_init();
|
||||
#define ROM_BUFFER_SIZE01 32767
|
||||
#define ROM_BUFFER_SIZE02 887
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,6 @@
|
||||
#ifndef __FIFO_H__
|
||||
#define __FIFO_H__
|
||||
|
||||
#define ROM_SIZE 30346
|
||||
#define ROM_ZIP_SIZE 35543
|
||||
|
||||
#endif
|
||||
+147
-247
@@ -26,6 +26,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "usbdrv.h"
|
||||
#include "oddebug.h"
|
||||
@@ -44,35 +45,21 @@
|
||||
#include "loader.h"
|
||||
#include "command.h"
|
||||
#include "shared_memory.h"
|
||||
#include "irq.h"
|
||||
#include "pwm.h"
|
||||
#include "testing.h"
|
||||
#include "shell.h"
|
||||
#include "system.h"
|
||||
|
||||
|
||||
|
||||
extern const char _rom[] PROGMEM;
|
||||
#ifndef NO_DEBUG
|
||||
extern FILE uart_stdout;
|
||||
#endif
|
||||
extern system_t system;
|
||||
|
||||
uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM);
|
||||
|
||||
uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
|
||||
uint32_t req_addr = 0;
|
||||
uint32_t req_addr_end = 0;
|
||||
uint32_t req_size;
|
||||
uint8_t req_bank;
|
||||
uint32_t req_bank_size;
|
||||
uint16_t req_bank_cnt;
|
||||
uint8_t req_percent;
|
||||
uint8_t req_percent_last;
|
||||
uint8_t req_state = REQ_STATUS_IDLE;
|
||||
uint8_t rx_remaining = 0;
|
||||
uint8_t tx_remaining = 0;
|
||||
uint16_t sync_errors = 0;
|
||||
uint8_t tx_buffer[32];
|
||||
uint8_t data_buffer[4];
|
||||
uint32_t addr;
|
||||
uint16_t crc = 0;
|
||||
|
||||
uint8_t debug_level = (DEBUG | DEBUG_CRC);
|
||||
|
||||
|
||||
usb_transaction_t usb_trans;
|
||||
|
||||
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
{
|
||||
@@ -82,53 +69,61 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
|
||||
if (rq->bRequest == USB_BULK_UPLOAD_INIT) {
|
||||
|
||||
req_bank = 0;
|
||||
rx_remaining = 0;
|
||||
usb_trans.req_bank = 0;
|
||||
usb_trans.rx_remaining = 0;
|
||||
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word,
|
||||
rq->wIndex.word);
|
||||
req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
||||
req_bank_cnt = rq->wIndex.word;
|
||||
req_addr_end = (uint32_t) req_bank_size *req_bank_cnt;
|
||||
req_percent = 0;
|
||||
req_percent_last = 0;
|
||||
sync_errors = 0;
|
||||
usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
||||
usb_trans.req_bank_cnt = rq->wIndex.word;
|
||||
usb_trans.req_addr_end = (uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt;
|
||||
usb_trans.req_percent = 0;
|
||||
usb_trans.req_percent_last = 0;
|
||||
usb_trans.sync_errors = 0;
|
||||
debug_P(DEBUG_USB,
|
||||
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);
|
||||
usb_trans.req_bank_size, usb_trans.req_bank_cnt, usb_trans.req_addr_end);
|
||||
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt);
|
||||
if (req_addr == 0x000000) {
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0);
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, usb_trans.req_bank_cnt);
|
||||
#if DO_TIMER
|
||||
if (usb_trans.req_addr == 0x000000) {
|
||||
#ifndef NO_DEBUG
|
||||
timer_start();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} else if (rq->bRequest == USB_BULK_UPLOAD_ADDR) {
|
||||
|
||||
req_state = REQ_STATUS_BULK_UPLOAD;
|
||||
req_addr = rq->wValue.word;
|
||||
req_addr = req_addr << 16;
|
||||
req_addr = req_addr | rq->wIndex.word;
|
||||
rx_remaining = rq->wLength.word;
|
||||
usb_trans.req_state = REQ_STATUS_BULK_UPLOAD;
|
||||
usb_trans.req_addr = rq->wValue.word;
|
||||
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||
usb_trans.rx_remaining = rq->wLength.word;
|
||||
|
||||
|
||||
|
||||
if (req_addr && req_addr % req_bank_size == 0) {
|
||||
if (usb_trans.req_addr && usb_trans.req_addr % usb_trans.req_bank_size == 0) {
|
||||
#if DO_TIMER
|
||||
#ifndef NO_DEBUG
|
||||
#ifdef FLT_DEBUG
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||
req_bank, req_addr, timer_stop());
|
||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||
#else
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||
req_bank, req_addr, timer_stop_int());
|
||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
||||
#endif
|
||||
req_bank++;
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_bank);
|
||||
sram_bulk_write_start(req_addr);
|
||||
timer_start();
|
||||
timer_start();
|
||||
#endif
|
||||
#endif
|
||||
usb_trans.req_bank++;
|
||||
|
||||
} else {
|
||||
sram_bulk_write_start(req_addr);
|
||||
sram_bulk_write_start(usb_trans.req_addr);
|
||||
}
|
||||
ret_len = USB_MAX_TRANS;
|
||||
|
||||
@@ -136,97 +131,73 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} else if (rq->bRequest == USB_BULK_UPLOAD_NEXT) {
|
||||
usb_trans.req_state = REQ_STATUS_BULK_UPLOAD;
|
||||
usb_trans.req_addr = rq->wValue.word;
|
||||
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||
usb_trans.rx_remaining = rq->wLength.word;
|
||||
|
||||
req_state = REQ_STATUS_BULK_UPLOAD;
|
||||
req_addr = rq->wValue.word;
|
||||
req_addr = req_addr << 16;
|
||||
req_addr = req_addr | rq->wIndex.word;
|
||||
rx_remaining = rq->wLength.word;
|
||||
|
||||
req_percent = (uint32_t)( 100 * req_addr ) / req_addr_end;
|
||||
if (req_percent!=req_percent_last){
|
||||
//debug_P(DEBUG_USB,
|
||||
// PSTR("USB_BULK_UPLOAD_ADDR: precent=%i\n", req_percent);
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_percent);
|
||||
sram_bulk_write_start(req_addr);
|
||||
#if DO_SHM
|
||||
usb_trans.req_percent = (uint32_t)( 100 * usb_trans.req_addr ) / usb_trans.req_addr_end;
|
||||
if (usb_trans.req_percent!=usb_trans.req_percent_last){
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, usb_trans.req_percent);
|
||||
}
|
||||
req_percent_last = req_percent;
|
||||
|
||||
#if 0
|
||||
if (req_addr && (req_addr % 0x1000) == 0) {
|
||||
debug_P(DEBUG_USB,
|
||||
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_addr,
|
||||
req_bank_size));
|
||||
|
||||
}
|
||||
sram_bulk_write_start(req_addr);
|
||||
#endif
|
||||
|
||||
#if SHM_SCRATCHPAD
|
||||
if (!shared_memory_scratchpad_region_save_helper(req_addr)){
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_NEXT: scratchpad_region_save_helper was dirty\n"));
|
||||
sram_bulk_write_start(req_addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (req_addr && (req_addr % req_bank_size) == 0) {
|
||||
usb_trans.req_percent_last = usb_trans.req_percent;
|
||||
shared_memory_scratchpad_region_save_helper(usb_trans.req_addr);
|
||||
#endif
|
||||
if (usb_trans.req_addr && (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
|
||||
#if DO_TIMER
|
||||
#ifndef NO_DEBUG
|
||||
#ifdef FLT_DEBUG
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||
req_bank, req_addr, timer_stop());
|
||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||
#else
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||
req_bank, req_addr, timer_stop_int());
|
||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
||||
#endif
|
||||
timer_start();
|
||||
#endif
|
||||
#endif
|
||||
usb_trans.req_bank++;
|
||||
#if DO_SHM
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, usb_trans.req_bank);
|
||||
#endif
|
||||
req_bank++;
|
||||
timer_start();
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, req_bank);
|
||||
sram_bulk_write_start(req_addr);
|
||||
|
||||
}
|
||||
ret_len = USB_MAX_TRANS;
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} else if (rq->bRequest == USB_BULK_UPLOAD_END) {
|
||||
if (req_state != REQ_STATUS_BULK_UPLOAD) {
|
||||
if (usb_trans.req_state != REQ_STATUS_BULK_UPLOAD) {
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n"));
|
||||
return 0;
|
||||
}
|
||||
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END:\n"));
|
||||
req_state = REQ_STATUS_IDLE;
|
||||
usb_trans.req_state = REQ_STATUS_IDLE;
|
||||
sram_bulk_write_end();
|
||||
#if DO_SHM
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
|
||||
#endif
|
||||
ret_len = 0;
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} else if (rq->bRequest == USB_CRC) {
|
||||
req_addr = rq->wValue.word;
|
||||
req_addr = req_addr << 16;
|
||||
req_addr = req_addr | rq->wIndex.word;
|
||||
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), req_addr);
|
||||
crc_check_bulk_memory(0x000000, req_addr, req_bank_size);
|
||||
ret_len = 0;
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} else if (rq->bRequest == USB_MODE_SNES) {
|
||||
req_state = REQ_STATUS_SNES;
|
||||
debug_P(DEBUG_USB, PSTR("USB_MODE_SNES:\n"));
|
||||
usb_trans.req_addr = rq->wValue.word;
|
||||
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), usb_trans.req_addr);
|
||||
crc_check_bulk_memory(0x000000, usb_trans.req_addr, usb_trans.req_bank_size);
|
||||
ret_len = 0;
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} else if (rq->bRequest == USB_MODE_AVR) {
|
||||
req_state = REQ_STATUS_AVR;
|
||||
usb_trans.req_state = REQ_STATUS_AVR;
|
||||
debug_P(DEBUG_USB, PSTR("USB_MODE_AVR:\n"));
|
||||
ret_len = 0;
|
||||
/*
|
||||
@@ -239,139 +210,85 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
} else if (rq->bRequest == USB_CRC_ADDR) {
|
||||
req_state = REQ_STATUS_CRC;
|
||||
req_addr = rq->wValue.word;
|
||||
req_addr = req_addr << 16;
|
||||
req_addr = req_addr | rq->wIndex.word;
|
||||
debug_P(DEBUG_USB, PSTR("USB_CRC_ADDR: addr=0x%lx size=%i\n"), req_addr,
|
||||
rq->wLength.word);
|
||||
req_size = rq->wLength.word;
|
||||
req_size = req_size << 2;
|
||||
tx_remaining = 2;
|
||||
debug_P(DEBUG_USB, PSTR("USB_CRC_ADDR: addr=0x%lx size=%li\n"), req_addr,
|
||||
req_size);
|
||||
|
||||
crc = crc_check_memory_range(req_addr, req_size, read_buffer);
|
||||
tx_buffer[0] = crc & 0xff;
|
||||
tx_buffer[1] = (crc >> 8) & 0xff;
|
||||
ret_len = 2;
|
||||
req_state = REQ_STATUS_IDLE;
|
||||
} else if (rq->bRequest == USB_SET_LAODER) {
|
||||
usb_trans.loader_enabled = rq->wValue.word;
|
||||
ret_len = 0;
|
||||
}
|
||||
|
||||
usbMsgPtr = data_buffer;
|
||||
return ret_len; /* default for not implemented requests: return no data back to host */
|
||||
usbMsgPtr = usb_trans.rx_buffer;
|
||||
return ret_len;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
void usb_connect()
|
||||
{
|
||||
uint8_t i = 0;
|
||||
info_P(PSTR("USB init\n"));
|
||||
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
||||
cli();
|
||||
info_P(PSTR("USB disconnect\n"));
|
||||
i = 10;
|
||||
while (--i) { /* fake USB disconnect for > 250 ms */
|
||||
led_on();
|
||||
_delay_ms(15);
|
||||
led_off();
|
||||
_delay_ms(35);
|
||||
}
|
||||
led_on();
|
||||
usbDeviceConnect();
|
||||
info_P(PSTR("USB connect\n"));
|
||||
}
|
||||
|
||||
|
||||
void boot_startup_rom()
|
||||
{
|
||||
info_P(PSTR("Boot startup rom\n"));
|
||||
info_P(PSTR("Activate AVR bus\n"));
|
||||
avr_bus_active();
|
||||
info_P(PSTR("IRQ off\n"));
|
||||
snes_irq_lo();
|
||||
snes_irq_off();
|
||||
snes_lorom();
|
||||
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
|
||||
info_P(PSTR("\n"));
|
||||
#if 1
|
||||
dump_memory(0x10000 - 0x100, 0x10000);
|
||||
#endif
|
||||
snes_hirom();
|
||||
snes_wr_disable();
|
||||
snes_bus_active();
|
||||
info_P(PSTR("Activate SNES bus\n"));
|
||||
send_reset();
|
||||
_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;
|
||||
memset(&usb_trans,0,sizeof(usb_transaction_t));
|
||||
|
||||
usb_trans.req_addr = 0;
|
||||
usb_trans.req_addr_end = 0;
|
||||
usb_trans.req_state = REQ_STATUS_IDLE;
|
||||
usb_trans.rx_remaining = 0;
|
||||
usb_trans.tx_remaining = 0;
|
||||
usb_trans.sync_errors = 0;
|
||||
usb_trans.loader_enabled = 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
|
||||
#ifndef NO_DEBUG
|
||||
uart_init();
|
||||
stdout = &uart_stdout;
|
||||
banner();
|
||||
#endif
|
||||
shared_memory_init();
|
||||
system_init();
|
||||
snes_reset_hi();
|
||||
snes_reset_off();
|
||||
sram_init();
|
||||
//pwm_init();
|
||||
irq_init();
|
||||
boot_startup_rom();
|
||||
boot_startup_rom(50);
|
||||
globals_init();
|
||||
//pwm_stop();
|
||||
usbInit();
|
||||
usb_connect();
|
||||
sei();
|
||||
while (1) {
|
||||
avr_bus_active();
|
||||
info_P(PSTR("Activate AVR bus\n"));
|
||||
snes_lorom();
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
snes_wr_disable();
|
||||
sei();
|
||||
info_P(PSTR("USB poll\n"));
|
||||
while (req_state != REQ_STATUS_SNES) {
|
||||
usbPoll();
|
||||
}
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
|
||||
|
||||
#if SHM_SCRATCHPAD
|
||||
system_set_bus_avr();
|
||||
system_set_wr_disable();
|
||||
info_P(PSTR("USB poll\n"));
|
||||
while (usb_trans.req_state != REQ_STATUS_SNES) {
|
||||
usbPoll();
|
||||
#ifdef DO_SHELL
|
||||
#ifndef NO_DEBUG
|
||||
shell_run();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DO_SHM
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
|
||||
#endif
|
||||
|
||||
#if DO_SHM_SCRATCHPAD
|
||||
shared_memory_scratchpad_region_tx_restore();
|
||||
shared_memory_scratchpad_region_rx_restore();
|
||||
#endif
|
||||
info_P(PSTR("USB poll done\n"));
|
||||
|
||||
#if DO_CRC_CHECK
|
||||
info_P(PSTR("-->CRC Check\n"));
|
||||
crc_check_bulk_memory(0x000000, usb_trans.req_bank_size * usb_trans.req_bank_cnt, usb_trans.req_bank_size);
|
||||
#endif
|
||||
|
||||
system_set_rom_mode(&usb_trans);
|
||||
system_set_wr_disable();
|
||||
system_set_bus_snes();
|
||||
system_send_snes_reset();
|
||||
irq_stop();
|
||||
/*
|
||||
info_P(PSTR("-->Switch TO SNES\n"));
|
||||
set_rom_mode();
|
||||
snes_wr_disable();
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
@@ -379,46 +296,29 @@ int main(void)
|
||||
info_P(PSTR("Activate SNES bus\n"));
|
||||
irq_stop();
|
||||
send_reset();
|
||||
*/
|
||||
info_P(PSTR("Poll USB\n"));
|
||||
while ((req_state != REQ_STATUS_AVR)) {
|
||||
while ((usb_trans.req_state != REQ_STATUS_AVR)) {
|
||||
usbPoll();
|
||||
#ifdef DO_SHELL
|
||||
#ifndef NO_DEBUG
|
||||
shell_run();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DO_IRQ
|
||||
uint8_t i;
|
||||
uint16_t irq_count = 0;
|
||||
i = 10;
|
||||
while (--i) {
|
||||
_delay_ms(100);
|
||||
}
|
||||
info_P(PSTR("Send IRQ %i\n"), ++irq_count);
|
||||
send_irq();
|
||||
#endif
|
||||
|
||||
#ifdef DO_BUS_STEALING
|
||||
avr_bus_active();
|
||||
sram_bulk_read_start(0x003000);
|
||||
c = sram_bulk_read();
|
||||
i = 5;
|
||||
while (--i) {
|
||||
_delay_ms(500);
|
||||
info_P(PSTR("Wait to switch to snes mode %i\n"), i);
|
||||
}
|
||||
|
||||
if (req_bank_size == 0x8000) {
|
||||
snes_lorom();
|
||||
} else {
|
||||
snes_hirom();
|
||||
}
|
||||
snes_wr_disable();
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
snes_bus_active();
|
||||
info_P(PSTR("Activate SNES bus\n"));
|
||||
info_P(PSTR("Read 0x3000=%c\n"), c);
|
||||
#endif
|
||||
}
|
||||
//info_P(PSTR("-->Switch TO AVR\n"));
|
||||
shared_memory_init();
|
||||
if(usb_trans.loader_enabled) {
|
||||
boot_startup_rom(500);
|
||||
} else {
|
||||
system_set_bus_avr();
|
||||
system_send_snes_reset();
|
||||
//avr_bus_active();
|
||||
//send_reset();
|
||||
|
||||
}
|
||||
irq_init();
|
||||
boot_startup_rom();
|
||||
globals_init();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
Loader Version 1
|
||||
|
||||
DEBUG:
|
||||
Bootloader: 4096
|
||||
CODE: 24984
|
||||
RAM: 742
|
||||
LOADER: 31091
|
||||
|
||||
NO_DEBUG:
|
||||
Bootloader: 4096
|
||||
CODE: 7532
|
||||
RAM: 344
|
||||
LOADER: 31091
|
||||
|
||||
|
||||
Loader Version 2
|
||||
|
||||
DEBUG:
|
||||
Bootloader: 4096
|
||||
CODE: 24984
|
||||
RAM: 742
|
||||
LOADER: 58046
|
||||
|
||||
NO_DEBUG:
|
||||
Bootloader: 4096
|
||||
CODE: 7532
|
||||
RAM: 344
|
||||
LOADER: 58046
|
||||
|
||||
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* neginf.c
|
||||
* neginf -- embedded inflate lib
|
||||
*
|
||||
* inflate routines
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "neginf.h"
|
||||
#include "neginf_priv.h"
|
||||
|
||||
typedef void(*mode_fun)() ;
|
||||
|
||||
static neginf_state state;
|
||||
static const mode_fun mode_tab[mode_count] = {
|
||||
&await_block,
|
||||
&raw_block_begin,
|
||||
&raw_block_begin2,
|
||||
&raw_block,
|
||||
&fixed_block_begin,
|
||||
&huff_block,
|
||||
&huff_len_addbits,
|
||||
&huff_dist,
|
||||
&huff_dist_addbits,
|
||||
&dynamic_block_begin,
|
||||
&dynamic_read_lc,
|
||||
&dynamic_read_lit_len,
|
||||
&dynamic_read_dist
|
||||
};
|
||||
|
||||
void neginf_init(nsize start_pos)
|
||||
{
|
||||
state.queue_size = 0;
|
||||
state.mode = mode_await_block;
|
||||
state.last_block = 0;
|
||||
#ifdef NEGINF_POS_TRACKING
|
||||
state.output_pos = start_pos;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void neginf_process_byte(nbyte byte)
|
||||
{
|
||||
assert(state.queue_size <= 16);
|
||||
state.input_queue |= (byte << state.queue_size);
|
||||
state.queue_size += 8;
|
||||
|
||||
while(state.queue_size >= 16)
|
||||
{
|
||||
//printf("qsize=%i mode=%i\n",state.queue_size,state.mode);
|
||||
mode_tab[state.mode]();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NEGINF_POS_TRACKING
|
||||
nsize neginf_output_position()
|
||||
{
|
||||
return state.output_pos;
|
||||
}
|
||||
#endif
|
||||
|
||||
nint lookahead()
|
||||
{
|
||||
//printf("lookahead\n");
|
||||
return state.input_queue;
|
||||
}
|
||||
|
||||
void consume(ntiny amount)
|
||||
{
|
||||
//printf("consume %i %i\n",state.queue_size,amount);
|
||||
assert(state.queue_size > amount);
|
||||
state.input_queue >>= amount;
|
||||
state.queue_size -= amount;
|
||||
}
|
||||
|
||||
void await_block()
|
||||
{
|
||||
//printf("wait block\n");
|
||||
if(state.last_block)
|
||||
{
|
||||
neginf_cb_completed();
|
||||
consume(16);
|
||||
}
|
||||
else
|
||||
{
|
||||
nint la = lookahead();
|
||||
state.last_block = la & 1;
|
||||
consume(3);
|
||||
switch(la & 6)
|
||||
{
|
||||
case 0: // 00 uncompressed
|
||||
consume((state.queue_size) & 7); // align to byte
|
||||
state.mode = mode_raw_block_begin;
|
||||
break;
|
||||
case 2: // 01 fixed huffman
|
||||
state.mode = mode_fixed_block_begin;
|
||||
break;
|
||||
case 4: // 10 dynamic huffman
|
||||
state.mode = mode_dynamic_block_begin;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void raw_block_begin()
|
||||
{
|
||||
//printf("raw block begin\n");
|
||||
state.raw_size = lookahead() & 0xFFFF; // size of raw block
|
||||
consume(16);
|
||||
state.mode = mode_raw_block_begin2;
|
||||
}
|
||||
|
||||
void raw_block_begin2()
|
||||
{
|
||||
//printf("raw block begin2\n");
|
||||
consume(16); // we ignore the inverted size
|
||||
state.mode = mode_raw_block;
|
||||
}
|
||||
|
||||
void raw_block()
|
||||
{
|
||||
//printf("raw block\n");
|
||||
if(state.raw_size == 0)
|
||||
{
|
||||
state.mode = mode_await_block;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.raw_size--;
|
||||
neginf_cb_seq_byte(lookahead() & 0xFF);
|
||||
#ifdef NEGINF_POS_TRACKING
|
||||
state.output_pos++;
|
||||
#endif
|
||||
consume(8);
|
||||
}
|
||||
}
|
||||
|
||||
void fixed_block_begin()
|
||||
{
|
||||
//printf("fixed block begin\n");
|
||||
|
||||
nint i = 0;
|
||||
for(; i < 144; i++)
|
||||
state.lit_len_lengths[i] = 8;
|
||||
for(; i < 256; i++)
|
||||
state.lit_len_lengths[i] = 9;
|
||||
for(; i < 280; i++)
|
||||
state.lit_len_lengths[i] = 7;
|
||||
for(; i < 288; i++)
|
||||
state.lit_len_lengths[i] = 8;
|
||||
|
||||
ntiny j;
|
||||
for(j = 0; i < 32; i++)
|
||||
state.dist_lengths[i] = 5;
|
||||
|
||||
compute_begins();
|
||||
state.mode = mode_huff_block;
|
||||
}
|
||||
|
||||
void huff_block()
|
||||
{
|
||||
//printf("huff block\n");
|
||||
nint code = lit_len_read();
|
||||
if(code == 256)
|
||||
{
|
||||
state.mode = mode_await_block;
|
||||
}
|
||||
else if(code < 256)
|
||||
{
|
||||
neginf_cb_seq_byte(code);
|
||||
#ifdef NEGINF_POS_TRACKING
|
||||
state.output_pos++;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
state.code = code;
|
||||
state.mode = mode_huff_len_addbits;
|
||||
}
|
||||
}
|
||||
|
||||
void huff_len_addbits()
|
||||
{
|
||||
//printf("huff len addbits\n");
|
||||
nint len;
|
||||
nint code = state.code;
|
||||
nint la = lookahead();
|
||||
if(code < 265)
|
||||
len = code - 257 + 3;
|
||||
else if(code < 269)
|
||||
{
|
||||
len = (code - 265) * 2 + 11 + (la & 1);
|
||||
consume(1);
|
||||
}
|
||||
else if(code < 273)
|
||||
{
|
||||
len = (code - 269) * 4 + 19 + (la & 3);
|
||||
consume(2);
|
||||
}
|
||||
else if(code < 277)
|
||||
{
|
||||
len = (code - 273) * 8 + 35 + (la & 7);
|
||||
consume(3);
|
||||
}
|
||||
else if(code < 281)
|
||||
{
|
||||
len = (code - 277) * 16 + 67 + (la & 15);
|
||||
consume(4);
|
||||
}
|
||||
else if(code < 285)
|
||||
{
|
||||
len = (code - 281) * 32 + 131 + (la & 31);
|
||||
consume(5);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = 258;
|
||||
}
|
||||
state.match_len = len;
|
||||
state.mode = mode_huff_dist;
|
||||
}
|
||||
|
||||
void huff_dist()
|
||||
{
|
||||
//printf("huff dist\n");
|
||||
state.tcode = dist_read();
|
||||
state.mode = mode_huff_dist_addbits;
|
||||
}
|
||||
|
||||
void huff_dist_addbits()
|
||||
{
|
||||
//printf("huff addbits\n");
|
||||
nint dist;
|
||||
ntiny code = state.tcode;
|
||||
|
||||
if(code < 4)
|
||||
{
|
||||
dist = code+1;
|
||||
}
|
||||
else if(code > 29)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
nint la = lookahead();
|
||||
ntiny len = (code - 2) / 2;
|
||||
dist = ((2 + (code & 1)) << len) + 1 + (((1 << len) - 1) & la);
|
||||
consume(len);
|
||||
}
|
||||
neginf_cb_rel_copy(dist, state.match_len);
|
||||
#ifdef NEGINF_POS_TRACKING
|
||||
state.output_pos += state.match_len;
|
||||
#endif
|
||||
|
||||
state.mode = mode_huff_block;
|
||||
}
|
||||
|
||||
void dynamic_block_begin()
|
||||
{
|
||||
nint j;
|
||||
ntiny i;
|
||||
//printf("dynamic block begin\n");
|
||||
for(j = 0; j < 288; j++)
|
||||
state.lit_len_lengths[j] = 0;
|
||||
for(i = 0; i < 32; i++)
|
||||
state.dist_lengths[i] = 0;
|
||||
for(i = 0; i < 19; i++)
|
||||
state.hc_lengths[i] = 0;
|
||||
|
||||
nint la = lookahead();
|
||||
state.hlit = (la & 31) + 257;
|
||||
state.hdist = ((la >> 5) & 31) + 1;
|
||||
state.hclen = ((la >> 10) & 15) + 4;
|
||||
state.torder = 0;
|
||||
consume(5+5+4);
|
||||
state.mode = mode_dynamic_read_lc;
|
||||
}
|
||||
|
||||
void dynamic_read_lc()
|
||||
{
|
||||
//printf("dynamic read lc\n");
|
||||
if(state.hclen == 0)
|
||||
{
|
||||
compute_begin(state.hc_lengths, state.hc_begins, 19);
|
||||
state.mode = mode_dynamic_read_lit_len;
|
||||
state.order = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
static const ntiny order[19] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
};
|
||||
ntiny i = lookahead() & 7;
|
||||
state.hc_lengths[order[state.torder]] = i;
|
||||
consume(3);
|
||||
|
||||
state.torder++;
|
||||
state.hclen--;
|
||||
}
|
||||
}
|
||||
|
||||
void dynamic_read_lit_len()
|
||||
{
|
||||
//printf("dynamic read lit len\n");
|
||||
if(state.hlit == 0)
|
||||
{
|
||||
state.mode = mode_dynamic_read_dist;
|
||||
state.order = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.hlit -= lc_read(state.lit_len_lengths);
|
||||
}
|
||||
}
|
||||
|
||||
void dynamic_read_dist()
|
||||
{
|
||||
//printf("dynamic read dist\n");
|
||||
if(state.hdist == 0)
|
||||
{
|
||||
compute_begins();
|
||||
state.mode = mode_huff_block;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.hdist -= lc_read(state.dist_lengths);
|
||||
}
|
||||
}
|
||||
|
||||
ntiny lc_read(ntiny * lenghts)
|
||||
{
|
||||
//printf("read lc\n");
|
||||
ntiny code = huff_read(state.hc_lengths, state.hc_begins, 19);
|
||||
// this reads 7 bits max so we still have 9 bits left in the buffer
|
||||
if(code < 16)
|
||||
{
|
||||
lenghts[state.order] = code;
|
||||
state.order++;
|
||||
return 1;
|
||||
}
|
||||
else if(code == 16)
|
||||
{
|
||||
ntiny i;
|
||||
ntiny copy = (lookahead() & 3) + 3;
|
||||
consume(2);
|
||||
for(i = 0; i < copy; i++)
|
||||
lenghts[state.order + i] = lenghts[state.order - 1];
|
||||
state.order += copy;
|
||||
return copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
ntiny fill;
|
||||
ntiny i;
|
||||
|
||||
if(code == 17)
|
||||
{
|
||||
fill = (lookahead() & 7) + 3;
|
||||
consume(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
fill = (lookahead() & 127) + 11;
|
||||
consume(7);
|
||||
}
|
||||
for(i = 0; i < fill; i++)
|
||||
{
|
||||
lenghts[state.order] = 0;
|
||||
state.order++;
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void compute_begins()
|
||||
{
|
||||
//printf("compute begins\n");
|
||||
compute_begin(state.lit_len_lengths, state.lit_len_begins, 288);
|
||||
compute_begin(state.dist_lengths, state.dist_begins, 32);
|
||||
}
|
||||
|
||||
|
||||
void compute_begin(ntiny * lengths, nint * begins, nint size)
|
||||
{
|
||||
ntiny j;
|
||||
nint i;
|
||||
//printf("compute begin\n");
|
||||
for(j = 0; j < 14; j++)
|
||||
begins[j] = 0;
|
||||
for(i = 0; i < size; i++)
|
||||
{
|
||||
nint len = lengths[i];
|
||||
if(len != 0 && len != 15)
|
||||
begins[len-1] += 1 << (15 - len);
|
||||
}
|
||||
nint acc = 0;
|
||||
for(j = 0; j < 14; j++)
|
||||
{
|
||||
nint val = begins[j];
|
||||
acc += val;
|
||||
begins[j] = acc;
|
||||
}
|
||||
}
|
||||
|
||||
nint lit_len_read()
|
||||
{
|
||||
//printf("lit len read\n");
|
||||
|
||||
return huff_read(state.lit_len_lengths, state.lit_len_begins, 288);
|
||||
}
|
||||
|
||||
nint dist_read()
|
||||
{
|
||||
//printf("dist read\n");
|
||||
return huff_read(state.dist_lengths, state.dist_begins, 32);
|
||||
}
|
||||
|
||||
nint huff_read(ntiny * lenghts, nint * begins, nint size)
|
||||
{
|
||||
//printf("huff read\n");
|
||||
nint code = 0;
|
||||
ntiny i;
|
||||
for(i = 1; i < 16; i++)
|
||||
{
|
||||
|
||||
code |= (lookahead() & 1) << (15-i);
|
||||
consume(1);
|
||||
if(i == 15 || code < begins[i-1])
|
||||
break;
|
||||
}
|
||||
code -= begins[i-2];
|
||||
code >>= (15-i);
|
||||
nint j;
|
||||
for(j = 0; j < size; j++)
|
||||
{
|
||||
if(lenghts[j] == i)
|
||||
{
|
||||
if(code == 0)
|
||||
return j;
|
||||
code--;
|
||||
}
|
||||
}
|
||||
//assert(0);
|
||||
return 0; // silent warning
|
||||
}
|
||||
|
||||
#ifndef NEGINF_USE_SEQ_WRITES
|
||||
void neginf_cb_seq_byte(nbyte byte)
|
||||
{
|
||||
neginf_cb_byte(state.output_pos, byte);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NEGINF_USE_REL_COPY
|
||||
void neginf_cb_rel_copy(nint distance, nint length)
|
||||
{
|
||||
neginf_cb_copy(state.output_pos - distance, state.output_pos, length);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* neginf.h
|
||||
* neginf -- embedded inflate lib
|
||||
*
|
||||
* public header file
|
||||
*/
|
||||
|
||||
#ifndef NEGINF_H
|
||||
#define NEGINF_H
|
||||
|
||||
#include "neginf_conf.h"
|
||||
|
||||
#if defined(NEGINF_USE_SEQ_WRITES) && defined(NEGINF_USE_REL_COPY)
|
||||
#else
|
||||
#ifndef NEGINF_POS_TRACKING
|
||||
#define NEGINF_POS_TRACKING
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void neginf_init(nsize start_pos);
|
||||
void neginf_process_byte(nbyte byte);
|
||||
|
||||
#ifdef NEGINF_POS_TRACKING
|
||||
nsize neginf_output_position();
|
||||
#endif
|
||||
|
||||
// callbacks
|
||||
|
||||
#ifdef NEGINF_USE_SEQ_WRITES
|
||||
void neginf_cb_seq_byte(nbyte byte);
|
||||
#else
|
||||
void neginf_cb_byte(nsize pos, nbyte byte);
|
||||
#endif
|
||||
|
||||
#ifdef NEGINF_USE_REL_COPY
|
||||
void neginf_cb_rel_copy(nint distance, nint length);
|
||||
#else
|
||||
void neginf_cb_copy(nsize from, nsize to, nint length);
|
||||
#endif
|
||||
|
||||
void neginf_cb_completed();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* neginf_conf.h
|
||||
* neginf -- embedded inflate lib
|
||||
*
|
||||
* configuration header file
|
||||
*/
|
||||
|
||||
#ifndef NEGINF_CONF_H
|
||||
#define NEGINF_CONF_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define NEGINF_USE_SEQ_WRITES
|
||||
//#define NEGINF_USE_REL_COPY
|
||||
//#define NEGINF_POS_TRACKING
|
||||
|
||||
//#define NEGINF_8BIT
|
||||
#define NEGINF_PACKED_STATE
|
||||
|
||||
|
||||
#ifdef NEGINF_8BIT
|
||||
|
||||
typedef char nbool;
|
||||
typedef uint8_t nbyte;
|
||||
typedef uint8_t ntiny;
|
||||
typedef uint16_t nint;
|
||||
typedef uint32_t nbuf;
|
||||
|
||||
typedef uint32_t nsize;
|
||||
|
||||
#else
|
||||
|
||||
typedef int nbool; // boolean
|
||||
typedef uint8_t nbyte; // has to be exaclty 8 bit, unsigned
|
||||
typedef unsigned int ntiny; // has to be at least 8 bit, unsigned
|
||||
typedef unsigned int nint; // has to be at least 16 bit, unsigned
|
||||
typedef unsigned int nbuf; // has to be at least 24 bit, unsigned
|
||||
|
||||
|
||||
typedef size_t nsize; // has be at least 24 bit, unsigned
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* neginf_priv.h
|
||||
* neginf -- embedded inflate lib
|
||||
*
|
||||
* internal header file
|
||||
*/
|
||||
|
||||
#ifndef NEGINF_PRIV_H
|
||||
#define NEGINF_PRIV_H
|
||||
|
||||
typedef struct neginf_state_s neginf_state;
|
||||
struct neginf_state_s {
|
||||
ntiny queue_size; // 0 .. 24
|
||||
ntiny mode;
|
||||
nbool last_block;
|
||||
#ifdef NEGINF_POS_TRACKING
|
||||
nsize output_pos;
|
||||
#endif
|
||||
// can be left uninitialized
|
||||
nbuf input_queue; // three input bytes
|
||||
|
||||
ntiny raw_size;
|
||||
ntiny tcode;
|
||||
nint code;
|
||||
nint match_len;
|
||||
|
||||
nint order;
|
||||
ntiny torder;
|
||||
nint hlit;
|
||||
ntiny hdist;
|
||||
ntiny hclen;
|
||||
|
||||
ntiny lit_len_lengths[288];
|
||||
nint lit_len_begins[14];
|
||||
|
||||
ntiny dist_lengths[32];
|
||||
nint dist_begins[14];
|
||||
|
||||
ntiny hc_lengths[19];
|
||||
nint hc_begins[14];
|
||||
// what could be saved by limiting this to 7
|
||||
// will be lost due to the extra code i guess
|
||||
|
||||
|
||||
}
|
||||
#ifdef NEGINF_PACKED_STATE
|
||||
__attribute__((__packed__))
|
||||
#endif
|
||||
;
|
||||
|
||||
enum neginf_mode {
|
||||
mode_await_block = 0,
|
||||
mode_raw_block_begin,
|
||||
mode_raw_block_begin2,
|
||||
mode_raw_block,
|
||||
mode_fixed_block_begin,
|
||||
mode_huff_block,
|
||||
mode_huff_len_addbits,
|
||||
mode_huff_dist,
|
||||
mode_huff_dist_addbits,
|
||||
mode_dynamic_block_begin,
|
||||
mode_dynamic_read_lc,
|
||||
mode_dynamic_read_lit_len,
|
||||
mode_dynamic_read_dist,
|
||||
mode_count
|
||||
};
|
||||
|
||||
static void await_block();
|
||||
static void raw_block_begin();
|
||||
static void raw_block_begin2();
|
||||
static void raw_block();
|
||||
static void fixed_block_begin();
|
||||
static void huff_block();
|
||||
static void huff_len_addbits();
|
||||
static void huff_dist();
|
||||
static void huff_dist_addbits();
|
||||
static void dynamic_block_begin();
|
||||
static void dynamic_read_lc();
|
||||
static void dynamic_read_lit_len();
|
||||
static void dynamic_read_dist();
|
||||
|
||||
static void compute_begins();
|
||||
static void compute_begin(ntiny * lengths, nint * begins, nint size);
|
||||
static nint lit_len_read();
|
||||
static nint dist_read();
|
||||
static nint huff_read(ntiny * lengths, nint * begins, nint size);
|
||||
static ntiny lc_read(ntiny * lengths);
|
||||
|
||||
static nint lookahead();
|
||||
static void consume(ntiny amount);
|
||||
|
||||
#ifndef NEGINF_USE_SEQ_WRITES
|
||||
static void neginf_cb_seq_byte(nbyte byte);
|
||||
#endif
|
||||
|
||||
#ifndef NEGINF_USE_REL_COPY
|
||||
void neginf_cb_rel_copy(nint distance, nint length);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "pwm.h"
|
||||
#include "debug.h"
|
||||
#include "info.h"
|
||||
#include "sram.h"
|
||||
|
||||
|
||||
#define PWM_SINE_MAX 64
|
||||
#define PWM_OVERFLOW_MAX 1024
|
||||
|
||||
#if 0
|
||||
|
||||
uint8_t pwm_sine_table[] = {
|
||||
0x7f,0x8b,0x97,0xa4,0xaf,0xbb,0xc5,0xcf,0xd9,0xe1,0xe8,0xef,0xf4,0xf8,0xfb,0xfd,
|
||||
0xfd,0xfd,0xfb,0xf8,0xf3,0xee,0xe7,0xe0,0xd7,0xce,0xc4,0xb9,0xae,0xa2,0x96,0x89,
|
||||
0x7e,0x71,0x65,0x59,0x4d,0x42,0x37,0x2d,0x24,0x1c,0x15,0x0f,0x09,0x05,0x03,0x01,
|
||||
0x01,0x01,0x03,0x07,0x0b,0x11,0x17,0x1f,0x28,0x31,0x3b,0x46,0x52,0x5e,0x6a,0x76
|
||||
};
|
||||
|
||||
volatile uint8_t pwm_setting;
|
||||
volatile uint16_t pwm_overflow;
|
||||
volatile uint8_t pwm_idx;
|
||||
volatile uint16_t pwm_overflow_max;
|
||||
|
||||
ISR(TIMER2_COMPA_vect) {
|
||||
static uint8_t pwm_cnt=0;
|
||||
OCR2A += (uint16_t)T_PWM;
|
||||
|
||||
if (pwm_setting> pwm_cnt)
|
||||
led_pwm_on();
|
||||
else
|
||||
led_pwm_off();
|
||||
|
||||
if (pwm_cnt==(uint8_t)(PWM_STEPS-1))
|
||||
pwm_cnt=0;
|
||||
else
|
||||
pwm_cnt++;
|
||||
if (pwm_overflow_max == pwm_overflow++ ){
|
||||
pwm_setting = pwm_sine_table[pwm_idx++];
|
||||
pwm_overflow = 0;
|
||||
if (PWM_SINE_MAX == pwm_idx)
|
||||
pwm_idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void pwm_speed(uint16_t val) {
|
||||
pwm_overflow_max = val;
|
||||
}
|
||||
|
||||
void pwm_speed_slow(uint16_t val) {
|
||||
pwm_overflow_max = PWM_OVERFLOW_MAX * 2 ;
|
||||
}
|
||||
|
||||
void pwm_speed_fast(uint16_t val) {
|
||||
pwm_overflow_max = PWM_OVERFLOW_MAX / 2;
|
||||
}
|
||||
|
||||
void pwm_speed_normal(uint16_t val) {
|
||||
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
||||
}
|
||||
|
||||
|
||||
void pwm_set(uint8_t val) {
|
||||
pwm_setting = val;
|
||||
}
|
||||
|
||||
void pwm_stop(void) {
|
||||
while(pwm_setting!=0xfd);
|
||||
TIMSK2 = 0;
|
||||
}
|
||||
|
||||
void pwm_init(void) {
|
||||
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
||||
pwm_setting = 0x7f;
|
||||
pwm_overflow = 0;
|
||||
//cli();
|
||||
TCCR2B = 1;
|
||||
TIMSK2 |= (1<<OCIE2A);
|
||||
sei();
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#ifndef __PWM_H__
|
||||
#define __PWM_H__
|
||||
|
||||
#define F_PWM 100 // PWM-Frequenz in Hz
|
||||
#define PWM_STEPS 256 // PWM-Schritte pro Zyklus(1..256)
|
||||
|
||||
#define T_PWM (F_CPU/(F_PWM*PWM_STEPS)) // Systemtakte pro PWM-Takt
|
||||
|
||||
#if (T_PWM<(93+5))
|
||||
#error T_PWM zu klein, F_CPU muss vergrösst werden oder F_PWM oder PWM_STEPS verkleinert werden
|
||||
#endif
|
||||
|
||||
void pwm_init(void);
|
||||
void pwm_stop(void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -38,5 +38,23 @@
|
||||
#define USB_MODE_SNES 10
|
||||
#define USB_MODE_AVR 11
|
||||
#define USB_AVR_RESET 12
|
||||
#define USB_SET_LAODER 13
|
||||
|
||||
typedef struct usb_transaction_t {
|
||||
uint32_t req_addr;
|
||||
uint32_t req_addr_end;
|
||||
uint8_t req_bank;
|
||||
uint32_t req_bank_size;
|
||||
uint16_t req_bank_cnt;
|
||||
uint8_t req_percent;
|
||||
uint8_t req_percent_last;
|
||||
uint8_t req_state;
|
||||
uint8_t rx_remaining;
|
||||
uint8_t tx_remaining ;
|
||||
uint16_t sync_errors;
|
||||
uint8_t tx_buffer[32];
|
||||
uint8_t rx_buffer[8];
|
||||
uint8_t loader_enabled;
|
||||
} usb_transaction_t;
|
||||
|
||||
#endif /* __REQUESTS_H_INCLUDED__ */
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
// AT90USB/ringbuffer.c
|
||||
// Simple Ring-Buffer (FIFO) for Elements of type char
|
||||
// S. Salewski, 19-MAR-2007
|
||||
|
||||
/*
|
||||
t-> o
|
||||
o <-w
|
||||
x
|
||||
x <-r
|
||||
b-> x
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "ringbuffer.h"
|
||||
#define memory_size 65536
|
||||
#define t &buf[ringbuffer_size - 1]
|
||||
#define b &buf[0]
|
||||
|
||||
char buf[ringbuffer_size];
|
||||
int rb_count;
|
||||
char *memory;
|
||||
int pos_mem;
|
||||
int pos_head;
|
||||
|
||||
|
||||
//char *t = &buf[ringbuffer_size - 1];
|
||||
//char *b = &buf[0];
|
||||
|
||||
char *r; // position from where we can read (if rb_count > 0)
|
||||
char *w; // next free position (if rb_count < ringbuffer_size))
|
||||
char *o; // output pointer
|
||||
|
||||
void rb_init()
|
||||
{
|
||||
r = b;
|
||||
w = b;
|
||||
o = b;
|
||||
rb_count = 0;
|
||||
memory = (char*)malloc(memory_size);
|
||||
pos_mem = 0;
|
||||
pos_head = 0;
|
||||
}
|
||||
|
||||
|
||||
void rb_dump()
|
||||
{
|
||||
int i;
|
||||
printf("b=0x%02x t=0x%02x w=0x%02x o=0x%02x\n",*b,*t,*w,*o);
|
||||
for (i=0; i<ringbuffer_size; i++)
|
||||
printf("%02i 0x%02x\n",i, buf[i]);
|
||||
|
||||
}
|
||||
void rb_flush(){
|
||||
FILE *file;
|
||||
while(!rb_isempty()){
|
||||
memory[pos_mem++] = rb_get();
|
||||
}
|
||||
printf("write out.smc\n");
|
||||
file = fopen("out.smc","w");
|
||||
fwrite(memory,memory_size,1,file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
char rb_get(void)
|
||||
{
|
||||
rb_count--;
|
||||
if (r > t)
|
||||
r = b;
|
||||
return *r++;
|
||||
}
|
||||
|
||||
|
||||
char rb_read(int pos)
|
||||
{
|
||||
char *p;
|
||||
printf("rb_read: pos_mem=%06i pos_head=%06i pos=%06i\n",
|
||||
pos_mem, pos_head,pos);
|
||||
|
||||
if ( pos_head - pos > ringbuffer_size){
|
||||
printf("rb_read: memory[%i]=0x%02x \n",
|
||||
pos,
|
||||
memory[pos]);
|
||||
return memory[pos];
|
||||
}
|
||||
if (w - index >= b)
|
||||
p = w - index;
|
||||
else
|
||||
p = b + (b - ( w - index ));
|
||||
return *p;
|
||||
}
|
||||
|
||||
void rb_copy(int from,int to,int len){
|
||||
int i;
|
||||
char c;
|
||||
for (i = from; i< to; i++){
|
||||
c = rb_read(i);
|
||||
rb_put(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void rb_put(char el)
|
||||
{
|
||||
pos_head++;
|
||||
rb_count++;
|
||||
|
||||
if ( rb_count > ringbuffer_size){
|
||||
rb_dump();
|
||||
memory[pos_mem++]=*o++;
|
||||
if (o > t){
|
||||
o = b;
|
||||
}
|
||||
}
|
||||
printf("rb_count=%i pos_head=0x%06x add_mem=0x%06x\n",rb_count, pos_head,pos_mem);
|
||||
|
||||
if (w > t){
|
||||
w = b;
|
||||
}
|
||||
*w++ = el;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
#ifndef _RING_BUFFER_H_
|
||||
#define _RING_BUFFER_H_
|
||||
|
||||
|
||||
#define ringbuffer_size 8
|
||||
|
||||
extern int rb_count;
|
||||
|
||||
#define rb_free() (ringbuffer_size - rb_count)
|
||||
#define rb_isfull() (rb_count == ringbuffer_size)
|
||||
#define rb_isempty() (rb_count == 0)
|
||||
|
||||
void rb_init(void);
|
||||
void rb_put(char el);
|
||||
char rb_get(void);
|
||||
void rb_flush(void);
|
||||
|
||||
#endif
|
||||
+7
-4
@@ -32,14 +32,14 @@
|
||||
|
||||
#define RUNCHAR 0x90
|
||||
|
||||
uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||
#if 0
|
||||
|
||||
uint32_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||
{
|
||||
uint8_t in_byte, in_repeat, last_byte;
|
||||
uint32_t out_len, out_len_left;
|
||||
info_P(PSTR("RLE decode len=%li addr=0x%08lx\n"), in_len, out_addr);
|
||||
last_byte = 0;
|
||||
|
||||
out_len_left = out_len;
|
||||
sram_bulk_write_start(out_addr);
|
||||
#define INBYTE(b) \
|
||||
do { \
|
||||
@@ -99,5 +99,8 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||
last_byte = in_byte;
|
||||
}
|
||||
sram_bulk_write_end();
|
||||
return 0;
|
||||
info_P(PSTR("\nDone addr=0x%08lx\n"), out_addr);
|
||||
return out_addr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -23,6 +23,6 @@
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
uint8_t rle_decode(PGM_VOID_P in_addr, uint32_t in_len, uint32_t out_addr);
|
||||
uint32_t rle_decode(PGM_VOID_P in_addr, uint32_t in_len, uint32_t out_addr);
|
||||
|
||||
#endif
|
||||
|
||||
+96
-31
@@ -31,6 +31,8 @@
|
||||
#include "debug.h"
|
||||
#include "dump.h"
|
||||
#include "info.h"
|
||||
#include "crc.h"
|
||||
|
||||
|
||||
uint8_t irq_addr_lo;
|
||||
uint8_t irq_addr_hi;
|
||||
@@ -46,29 +48,43 @@ uint8_t scratchpad_locked_rx = 1;
|
||||
uint8_t scratchpad_locked_tx = 1;
|
||||
|
||||
|
||||
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
||||
void shared_memory_init(void){
|
||||
scratchpad_locked_rx = 1;
|
||||
scratchpad_locked_tx = 1;
|
||||
|
||||
if(addr > (SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE) && scratchpad_locked_tx){
|
||||
}
|
||||
|
||||
|
||||
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
||||
|
||||
|
||||
|
||||
#if DO_SHM_SCRATCHPAD
|
||||
if(addr > (SHARED_MEM_TX_LOC_STATE + (SHARED_MEM_TX_LOC_SIZE )) && scratchpad_locked_tx){
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),addr);
|
||||
shared_memory_scratchpad_region_tx_save();
|
||||
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_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),addr);
|
||||
shared_memory_scratchpad_region_rx_save();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void shared_memory_scratchpad_region_tx_save()
|
||||
{
|
||||
#if 0
|
||||
sram_bulk_addr_save();
|
||||
|
||||
#if SHARED_SCRATCHPAD_CRC
|
||||
uint16_t crc;
|
||||
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);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||
|
||||
#endif
|
||||
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: unlock\n"));
|
||||
@@ -76,21 +92,28 @@ void shared_memory_scratchpad_region_tx_save()
|
||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||
scratchpad_locked_tx = 0;
|
||||
|
||||
#if 0
|
||||
#if SHARED_SCRATCHPAD_CRC
|
||||
do_crc_update(0, scratchpad_region_tx,SHARED_MEM_TX_LOC_SIZE);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||
#endif
|
||||
|
||||
#if SHARED_SCRATCHPAD_DUMP
|
||||
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
|
||||
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||
#endif
|
||||
sram_bulk_addr_restore();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void shared_memory_scratchpad_region_rx_save()
|
||||
{
|
||||
#if 0
|
||||
|
||||
sram_bulk_addr_save();
|
||||
#if SHARED_SCRATCHPAD_CRC
|
||||
uint16_t crc;
|
||||
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);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
|
||||
#endif
|
||||
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: unlock\n"));
|
||||
@@ -98,27 +121,42 @@ void shared_memory_scratchpad_region_rx_save()
|
||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||
scratchpad_locked_rx = 0;
|
||||
|
||||
#if 0
|
||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_tx);
|
||||
#if SHARED_SCRATCHPAD_CRC
|
||||
do_crc_update(0, scratchpad_region_rx,SHARED_MEM_RX_LOC_SIZE);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
|
||||
#endif
|
||||
|
||||
#if SHARED_SCRATCHPAD_DUMP
|
||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
|
||||
dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||
#endif
|
||||
sram_bulk_addr_restore();
|
||||
|
||||
}
|
||||
|
||||
void shared_memory_scratchpad_region_tx_restore()
|
||||
{
|
||||
if (scratchpad_locked_tx)
|
||||
return;
|
||||
|
||||
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,
|
||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||
scratchpad_locked_tx = 1;
|
||||
#if 0
|
||||
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
|
||||
|
||||
#if SHARED_SCRATCHPAD_DUMP
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
|
||||
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||
scratchpad_locked_tx = 1;
|
||||
|
||||
#if SHARED_SCRATCHPAD_DUMP
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: buffer\n"));
|
||||
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
|
||||
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||
#endif
|
||||
|
||||
#if SHARED_SCRATCHPAD_CRC
|
||||
uint16_t crc;
|
||||
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);
|
||||
@@ -131,17 +169,27 @@ void shared_memory_scratchpad_region_rx_restore()
|
||||
{
|
||||
if (scratchpad_locked_rx)
|
||||
return;
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: lock\n"));
|
||||
|
||||
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: lock\n"));
|
||||
|
||||
#if SHARED_SCRATCHPAD_DUMP
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
|
||||
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||
#endif
|
||||
|
||||
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||
scratchpad_locked_rx = 1;
|
||||
|
||||
#if 0
|
||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_rx);
|
||||
dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||
#if SHARED_SCRATCHPAD_DUMP
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n"));
|
||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
|
||||
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#if SHARED_SCRATCHPAD_CRC
|
||||
uint16_t crc;
|
||||
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);
|
||||
@@ -181,16 +229,24 @@ void shared_memory_irq_restore()
|
||||
|
||||
void shared_memory_write(uint8_t cmd, uint8_t value)
|
||||
{
|
||||
|
||||
if (scratchpad_locked_tx)
|
||||
#if DO_SHM
|
||||
#if DO_SHM_SCRATCHPAD
|
||||
if (scratchpad_locked_tx){
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
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);
|
||||
|
||||
sram_bulk_addr_save();
|
||||
|
||||
#if (DO_SHM_SCRATCHPAD==0)
|
||||
shared_memory_scratchpad_tx_save();
|
||||
#endif
|
||||
#if SHARED_MEM_SWITCH_IRQ
|
||||
shared_memory_irq_hook();
|
||||
#endif
|
||||
|
||||
sram_write(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_SNES_ACK);
|
||||
sram_write(SHARED_MEM_TX_LOC_CMD, cmd);
|
||||
@@ -216,10 +272,14 @@ void shared_memory_write(uint8_t cmd, uint8_t value)
|
||||
snes_lorom();
|
||||
snes_wr_disable();
|
||||
|
||||
#if (DO_SHM_SCRATCHPAD==0)
|
||||
shared_memory_scratchpad_tx_restore();
|
||||
#endif
|
||||
#if SHARED_MEM_SWITCH_IRQ
|
||||
shared_memory_irq_restore();
|
||||
//sram_bulk_addr_restore();
|
||||
|
||||
#endif
|
||||
sram_bulk_addr_restore();
|
||||
#endif
|
||||
}
|
||||
|
||||
void shared_memory_yield()
|
||||
@@ -239,16 +299,20 @@ void shared_memory_yield()
|
||||
int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
||||
{
|
||||
uint8_t state;
|
||||
|
||||
if (scratchpad_locked_rx)
|
||||
#if DO_SHM
|
||||
#if DO_SHM_SCRATCHPAD
|
||||
if (scratchpad_locked_rx){
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
sram_bulk_addr_save();
|
||||
|
||||
state = sram_read(SHARED_MEM_RX_LOC_STATE);
|
||||
if (state != SHARED_MEM_RX_AVR_ACK){
|
||||
sram_bulk_addr_restore();
|
||||
return 1;
|
||||
}
|
||||
sram_bulk_addr_save();
|
||||
|
||||
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
|
||||
*len = sram_read(SHARED_MEM_RX_LOC_LEN);
|
||||
@@ -276,5 +340,6 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
||||
snes_lorom();
|
||||
snes_wr_disable();
|
||||
sram_bulk_addr_restore();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,11 @@
|
||||
#define SHARED_IRQ_HANDLER_LO 0x0ffe4
|
||||
#define SHARED_IRQ_HANDLER_HI 0x0ffe5
|
||||
|
||||
#define SHARED_SCRATCHPAD_DUMP 0
|
||||
#define SHARED_SCRATCHPAD_CRC 0
|
||||
|
||||
|
||||
|
||||
void shared_memory_init(void);
|
||||
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr);
|
||||
void shared_memory_scratchpad_region_tx_save();
|
||||
void shared_memory_scratchpad_region_tx_restore();
|
||||
|
||||
@@ -0,0 +1,487 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <avr/io.h>
|
||||
#include <stdlib.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
|
||||
|
||||
#include "pwm.h"
|
||||
#include "debug.h"
|
||||
#include "info.h"
|
||||
#include "sram.h"
|
||||
#include "util.h"
|
||||
#include "uart.h"
|
||||
#include "dump.h"
|
||||
#include "irq.h"
|
||||
#include "config.h"
|
||||
#include "crc.h"
|
||||
#include "command.h"
|
||||
#include "shared_memory.h"
|
||||
#include "system.h"
|
||||
|
||||
|
||||
extern system_t system;
|
||||
|
||||
uint8_t command_buf[RECEIVE_BUF_LEN];
|
||||
uint8_t recv_buf[RECEIVE_BUF_LEN];
|
||||
|
||||
volatile uint8_t recv_counter = 0;
|
||||
volatile uint8_t cr = 0;
|
||||
|
||||
uint8_t *token_ptr;
|
||||
|
||||
#ifdef DO_SHELL
|
||||
|
||||
uint8_t *get_token(void)
|
||||
{
|
||||
uint8_t *p = token_ptr;
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
if (*p == '\0')
|
||||
return NULL;
|
||||
token_ptr = p;
|
||||
do {
|
||||
token_ptr++;
|
||||
if (*token_ptr == ' ' || *token_ptr == '\n' || *token_ptr == '\r') {
|
||||
*token_ptr++ = '\0';
|
||||
break;
|
||||
}
|
||||
} while (*token_ptr != ' ' && *token_ptr != '\n' && *token_ptr != '\r');
|
||||
return p;
|
||||
}
|
||||
|
||||
uint8_t get_dec(uint32_t *decval)
|
||||
{
|
||||
const uint8_t *t;
|
||||
t = get_token();
|
||||
if (t != NULL) {
|
||||
int x = util_sscandec(t);
|
||||
if (x < 0)
|
||||
return 0;
|
||||
*decval = x;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t parse_hex(const uint8_t *s, uint32_t *hexval)
|
||||
{
|
||||
uint32_t x = util_sscanhex(s);
|
||||
*hexval = (uint32_t) x;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t get_hex(uint32_t *hexval)
|
||||
{
|
||||
const uint8_t *t;
|
||||
t = get_token();
|
||||
if (t != NULL)
|
||||
return parse_hex(t, hexval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t get_hex_arg2(uint32_t *hexval1, uint32_t *hexval2)
|
||||
{
|
||||
return get_hex(hexval1) && get_hex(hexval2);
|
||||
}
|
||||
|
||||
uint8_t get_hex_arg3(uint32_t *hexval1, uint32_t *hexval2, uint32_t *hexval3)
|
||||
{
|
||||
return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3);
|
||||
}
|
||||
|
||||
static uint8_t get_int32(uint32_t *val)
|
||||
{
|
||||
if (!get_hex(val)){
|
||||
info_P(PSTR("Invalid argument!\n"));
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t get_int8(uint8_t *val)
|
||||
{
|
||||
uint32_t ret;
|
||||
if (!get_hex(&ret) ||ret > 0xff){
|
||||
info_P(PSTR("Invalid argument!\n"));
|
||||
return 0;
|
||||
}else{
|
||||
*val = (uint8_t)ret;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_bool(void)
|
||||
{
|
||||
const uint8_t *t;
|
||||
t = get_token();
|
||||
if (t != NULL) {
|
||||
int result = util_sscanbool(t);
|
||||
if (result >= 0)
|
||||
return result;
|
||||
}
|
||||
info_P(PSTR("Invalid argument (should be 0 or 1)!\n"));
|
||||
return -1;
|
||||
}
|
||||
void prompt(void){
|
||||
|
||||
uart_putc('\r');
|
||||
uart_putc('\n');
|
||||
uart_putc('>');
|
||||
|
||||
}
|
||||
|
||||
ISR(USART0_RX_vect)
|
||||
{
|
||||
UCSR0B &= (255 - (1<<RXCIE0));// Interrupts disable for RxD
|
||||
sei();
|
||||
if(recv_counter == (sizeof(recv_buf)-1)) {
|
||||
cr=1;
|
||||
recv_buf[recv_counter]='\0';
|
||||
recv_counter=0;
|
||||
prompt();
|
||||
}
|
||||
recv_buf[recv_counter] = UDR0;
|
||||
uart_putc(recv_buf[recv_counter]);
|
||||
if (recv_buf[recv_counter] == 0x0d) {
|
||||
/* recv_buf[recv_counter] = 0; */
|
||||
cr = 1;
|
||||
recv_buf[++recv_counter]='\0';
|
||||
recv_counter = 0;
|
||||
prompt();
|
||||
} else {
|
||||
// we accept backspace or delete
|
||||
if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f) && recv_counter > 0) {
|
||||
recv_counter--;
|
||||
} else {
|
||||
recv_counter++;
|
||||
}
|
||||
}
|
||||
UCSR0B |= (1<<RXCIE0);
|
||||
}
|
||||
|
||||
enum cmds {
|
||||
CMD_DUMP,
|
||||
CMD_DUMPVEC,
|
||||
CMD_DUMPHEADER,
|
||||
CMD_CRC,
|
||||
CMD_EXIT,
|
||||
CMD_RESET,
|
||||
CMD_RESETSNIFF,
|
||||
CMD_IRQ,
|
||||
CMD_AVR,
|
||||
CMD_SNES,
|
||||
CMD_LOROM,
|
||||
CMD_HIROM,
|
||||
CMD_WR,
|
||||
CMD_SHMWR,
|
||||
CMD_SHMSAVE,
|
||||
CMD_SHMRESTORE,
|
||||
CMD_LOADER,
|
||||
CMD_RECONNECT,
|
||||
CMD_STATUS,
|
||||
CMD_SYS,
|
||||
CMD_HELP
|
||||
};
|
||||
|
||||
uint8_t cmdlist[][CMD_HELP] PROGMEM = {
|
||||
{"DUMP"},
|
||||
{"DUMPVEC"},
|
||||
{"DUMPHEADER"},
|
||||
{"CRC"},
|
||||
{"EXIT"},
|
||||
{"RESET"},
|
||||
{"RESETSNIFF"},
|
||||
{"IRQ"},
|
||||
{"AVR"},
|
||||
{"SNES"},
|
||||
{"LOROM"},
|
||||
{"HIROM"},
|
||||
{"WR"},
|
||||
{"SHMWR"},
|
||||
{"SHMSAVE"},
|
||||
{"SHMRESTORE"},
|
||||
{"LOADER"},
|
||||
{"RECONNECT"},
|
||||
{"STATUS"},
|
||||
{"SYS"},
|
||||
{"HELP"},
|
||||
};
|
||||
|
||||
|
||||
void shell_help(void){
|
||||
uint8_t i;
|
||||
info_P(PSTR("\n"));
|
||||
for (i=CMD_DUMP; i<CMD_HELP; i++){
|
||||
info_P((PGM_P)cmdlist[i]);
|
||||
info_P(PSTR("\n"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void shell_run(void)
|
||||
{
|
||||
uint8_t *t;
|
||||
uint32_t arg1;
|
||||
uint32_t arg2;
|
||||
uint32_t arg3;
|
||||
uint16_t crc;
|
||||
uint16_t offset;
|
||||
uint16_t i;
|
||||
uint8_t c;
|
||||
|
||||
if (!cr)
|
||||
return;
|
||||
cr=0;
|
||||
strcpy((char*)command_buf, (char*)recv_buf);
|
||||
|
||||
token_ptr = command_buf;
|
||||
t = get_token();
|
||||
|
||||
if (t == NULL)
|
||||
shell_help();
|
||||
|
||||
util_strupper(t);
|
||||
|
||||
if (strcmp_P((const char*)t,(PGM_P)cmdlist[CMD_DUMP]) == 0) {
|
||||
if (get_hex_arg2(&arg1,&arg2))
|
||||
dump_memory(arg1,arg2);
|
||||
else
|
||||
info_P(PSTR("DUMP <start addr> <end addr>\n"));
|
||||
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_CRC]) == 0) {
|
||||
if (get_hex_arg2(&arg1,&arg2)){
|
||||
crc = crc_check_bulk_memory(arg1,arg2,0x8000);
|
||||
info_P(PSTR("0x%06lx - 0x%06lx crc=0x%04x\n"),arg1,arg2,crc);
|
||||
} else
|
||||
info_P(PSTR("CRC <start addr> <end addr>\n"));
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_EXIT]) == 0) {
|
||||
leave_application();
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESET]) == 0) {
|
||||
system_send_snes_reset();
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_IRQ]) == 0) {
|
||||
info_P(PSTR("Send IRQ\n"));
|
||||
snes_irq_on();
|
||||
snes_irq_lo();
|
||||
_delay_us(20);
|
||||
snes_irq_hi();
|
||||
snes_irq_off();
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_AVR]) == 0) {
|
||||
//info_P(PSTR("Activate AVR bus\n"));
|
||||
//avr_bus_active();
|
||||
//snes_irq_lo();
|
||||
//snes_irq_off();
|
||||
system_set_bus_avr();
|
||||
snes_irq_lo();
|
||||
system_snes_irq_off();
|
||||
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SNES]) == 0) {
|
||||
//info_P(PSTR("Activate SNES bus\n"));
|
||||
//snes_irq_lo();
|
||||
//snes_irq_off();
|
||||
//snes_wr_disable();
|
||||
//snes_bus_active();
|
||||
snes_irq_lo();
|
||||
system_snes_irq_off();
|
||||
system_set_wr_disable();
|
||||
system_set_bus_snes();
|
||||
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOROM]) == 0) {
|
||||
//info_P(PSTR("Set LOROM\n"));
|
||||
//snes_lorom();
|
||||
//snes_wr_disable();
|
||||
system_set_rom_lorom();
|
||||
system_set_wr_disable();
|
||||
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HIROM]) == 0) {
|
||||
//info_P(PSTR("Set HIROM\n"));
|
||||
//snes_hirom();
|
||||
//snes_wr_disable();
|
||||
system_set_rom_hirom();
|
||||
system_set_wr_disable();
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_WR]) == 0) {
|
||||
arg1 = get_bool();
|
||||
if(arg1==1){
|
||||
info_P(PSTR("Set WR enable"));
|
||||
snes_wr_enable();
|
||||
}else if (arg1==0){
|
||||
info_P(PSTR("Set WR disable"));
|
||||
snes_wr_disable();
|
||||
}
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESETSNIFF]) == 0) {
|
||||
arg1 = get_bool();
|
||||
if(arg1==1){
|
||||
info_P(PSTR("Start Reset sniffer"));
|
||||
irq_init();
|
||||
}else if (arg1==0){
|
||||
info_P(PSTR("Stop Reset sniffer"));
|
||||
irq_stop();
|
||||
}
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_DUMPVEC]) == 0) {
|
||||
uint16_t offset;
|
||||
if (system.rom_mode==LOROM)
|
||||
offset = 0x8000;
|
||||
else
|
||||
offset = 0x0000;
|
||||
|
||||
info_P(PSTR("ABORT 0x%04x 0x%04x\n"), (0xFFE8 - offset),sram_read16_be(0xFFE8 - offset));
|
||||
info_P(PSTR("BRK 0x%04x 0x%04x\n"), (0xFFE6 - offset),sram_read16_be(0xFFE6 - offset));
|
||||
info_P(PSTR("COP 0x%04x 0x%04x\n"), (0xFFE4 - offset),sram_read16_be(0xFFE4 - offset));
|
||||
info_P(PSTR("IRQ 0x%04x 0x%04x\n"), (0xFFEE - offset),sram_read16_be(0xFFEE - offset));
|
||||
info_P(PSTR("NMI 0x%04x 0x%04x\n"), (0xFFEA - offset),sram_read16_be(0xFFEA - offset));
|
||||
info_P(PSTR("RES 0x%04x 0x%04x\n"), (0xFFFC - offset),sram_read16_be(0xFFFC - offset));
|
||||
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_DUMPHEADER]) == 0) {
|
||||
|
||||
if (system.rom_mode==LOROM)
|
||||
offset = 0x8000;
|
||||
else
|
||||
offset = 0x0000;
|
||||
/*
|
||||
# $ffc0..$ffd4 => Name of the ROM, typically in ASCII, using spaces to pad the name to 21 bytes.
|
||||
# $ffd5 => ROM layout, typically $20 for LoROM, or $21 for HiROM. Add $10 for FastROM.
|
||||
# $ffd6 => Cartridge type, typically $00 for ROM only, or $02 for ROM with save-RAM.
|
||||
# $ffd7 => ROM size byte.
|
||||
# $ffd8 => RAM size byte.
|
||||
# $ffd9 => Country code, which selects the video in the emulator. Values $00, $01, $0d use NTSC. Values in range $02..$0c use PAL. Other values are invalid.
|
||||
# $ffda => Licensee code. If this value is $33, then the ROM has an extended header with ID at $ffb2..$ffb5.
|
||||
# $ffdb => Version number, typically $00.
|
||||
# $ffdc..$ffdd => Checksum complement, which is the bitwise-xor of the checksum and $ffff.
|
||||
# $ffde..$ffdf => SNES checksum, an unsigned 16-bit checksum of bytes.
|
||||
# $ffe0..$ffe3 => Unknown.
|
||||
*/
|
||||
info_P(PSTR("NAME 0x%04x "), (0xffc0 - offset));
|
||||
for(arg1=(0xffc0 - offset); arg1<(0xffc0 - offset + 21);arg1++){
|
||||
c = sram_read(arg1);
|
||||
if (c>0x1f && c<0x7f)
|
||||
printf("%c",c);
|
||||
}
|
||||
printf("\n");
|
||||
c = sram_read(0xffd5 - offset);
|
||||
info_P(PSTR("LAYOUT 0x%04x "), (0xffd5 - offset));
|
||||
|
||||
switch(c){
|
||||
case 0x20:
|
||||
info_P(PSTR("LoROM, not fast\n"));
|
||||
break;
|
||||
case 0x21:
|
||||
info_P(PSTR("HiRom, not fast\n"));
|
||||
break;
|
||||
case 0x30:
|
||||
info_P(PSTR("LoROM, fast\n"));
|
||||
break;
|
||||
case 0x31:
|
||||
info_P(PSTR("HiRom, fast\n"));
|
||||
break;
|
||||
default:
|
||||
info_P(PSTR("Unkown 0x%02x\n"),c);
|
||||
break;
|
||||
}
|
||||
|
||||
c = sram_read(0xffd6 - offset);
|
||||
info_P(PSTR("TYPE 0x%04x "), (0xffd6 - offset),c);
|
||||
switch(c){
|
||||
case 0x00:
|
||||
info_P(PSTR("Rom\n"));
|
||||
break;
|
||||
case 0x01:
|
||||
info_P(PSTR("Rom + Sram\n"));
|
||||
break;
|
||||
case 0x02:
|
||||
info_P(PSTR("Rom + Sram + Battery\n"));
|
||||
break;
|
||||
case 0x13:
|
||||
info_P(PSTR("SuperFX\n"));
|
||||
break;
|
||||
case 0x14:
|
||||
info_P(PSTR("SuperFX\n"));
|
||||
break;
|
||||
case 0x15:
|
||||
info_P(PSTR("SuperFX + Sram\n"));
|
||||
break;
|
||||
case 0x1a:
|
||||
info_P(PSTR("SuperFX + Sram\n"));
|
||||
break;
|
||||
case 0x34:
|
||||
info_P(PSTR("SA-1"));
|
||||
break;
|
||||
case 0x35:
|
||||
info_P(PSTR("SA-1"));
|
||||
break;
|
||||
default:
|
||||
info_P(PSTR("Unkown 0x%02x\n"),c);
|
||||
break;
|
||||
}
|
||||
arg1 = ( 2 << ( sram_read(0xffd7 - offset) - 1 ));
|
||||
info_P(PSTR("ROM 0x%04x %li MBit ( %li KiB)\n"), (0xffd7 - offset), (arg1 / 128), arg1);
|
||||
arg1 = ( 2 << ( sram_read(0xffd8 - offset) - 1 ));
|
||||
info_P(PSTR("RAM 0x%04x %li KiB\n"), (0xffd8 - offset), arg1);
|
||||
|
||||
info_P(PSTR("CCODE 0x%04x "), (0xffd9 - offset));
|
||||
c = sram_read(0xffd9 - offset);
|
||||
if (c==0x00 || c==0x01 || 0x0d )
|
||||
info_P(PSTR("NTSC\n"));
|
||||
else if (c>=0x02 || c<=0x0c )
|
||||
info_P(PSTR("PAL\n"));
|
||||
else
|
||||
info_P(PSTR("Unkown 0x%02x\n"),c);
|
||||
|
||||
info_P(PSTR("LIC 0x%04x 0x%02x\n"), (0xffda - offset),sram_read(0xffda - offset));
|
||||
info_P(PSTR("VER 0x%04x 0x%02x\n"), (0xffdb - offset),sram_read(0xffdb - offset));
|
||||
info_P(PSTR("SUM1 0x%04x 0x%04x\n"), (0xffdc - offset),sram_read16_be(0xffdc - offset));
|
||||
info_P(PSTR("SUM2 0x%04x 0x%04x\n"), (0xffde - offset),sram_read16_be(0xffde - offset));
|
||||
|
||||
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMWR]) == 0) {
|
||||
if (get_hex_arg2(&arg1,&arg2))
|
||||
shared_memory_write((uint8_t)arg1, (uint8_t)arg1);
|
||||
else
|
||||
info_P(PSTR("SHMWR <command> <value>\n"));
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMSAVE]) == 0) {
|
||||
shared_memory_scratchpad_region_tx_save();
|
||||
shared_memory_scratchpad_region_rx_save();
|
||||
info_P(PSTR("Save scratchpad\n"));
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMRESTORE]) == 0) {
|
||||
shared_memory_scratchpad_region_tx_restore();
|
||||
shared_memory_scratchpad_region_rx_restore();
|
||||
info_P(PSTR("Restore scratchpad\n"));
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOADER]) == 0) {
|
||||
boot_startup_rom(500);
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RECONNECT]) == 0) {
|
||||
usb_connect();
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_STATUS]) == 0) {
|
||||
transaction_status();
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SYS]) == 0) {
|
||||
system_status();
|
||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HELP]) == 0) {
|
||||
shell_help();
|
||||
}
|
||||
prompt();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#ifndef __SHELL_H__
|
||||
#define __SHELL_H__
|
||||
|
||||
void shell_run(void);
|
||||
|
||||
#endif
|
||||
+23
-12
@@ -34,7 +34,7 @@
|
||||
uint32_t addr_current = 0;
|
||||
uint32_t addr_stash = 0;
|
||||
|
||||
void system_init(void)
|
||||
void sram_init(void)
|
||||
{
|
||||
/*-------------------------------------------------*/
|
||||
|
||||
@@ -114,14 +114,16 @@ void sreg_set(uint32_t addr)
|
||||
|
||||
}
|
||||
|
||||
inline void sram_bulk_addr_save()
|
||||
void sram_bulk_addr_save()
|
||||
{
|
||||
addr_stash = addr_current;
|
||||
debug_P(DEBUG_SRAM, PSTR("sram_bulk_addr_save: addr=0x%08lx\n\r"), addr_stash);
|
||||
}
|
||||
|
||||
inline void sram_bulk_addr_restore()
|
||||
{
|
||||
sreg_set(addr_stash);
|
||||
debug_P(DEBUG_SRAM, PSTR("sram_bulk_addr_restore: addr=0x%08lx\n\r"), addr_stash);
|
||||
sram_bulk_write_start(addr_stash);
|
||||
}
|
||||
|
||||
|
||||
@@ -213,9 +215,16 @@ uint8_t sram_read(uint32_t addr)
|
||||
|
||||
}
|
||||
|
||||
uint16_t sram_read16_be(uint32_t addr){
|
||||
uint8_t hi = sram_read(addr);
|
||||
uint8_t lo = sram_read(addr+1);
|
||||
return (hi << 8 | lo );
|
||||
}
|
||||
|
||||
void sram_bulk_write_start(uint32_t addr)
|
||||
{
|
||||
debug_P(DEBUG_SRAM, PSTR("sram_bulk_write_start: addr=0x%08lx\n\r"), addr);
|
||||
addr_current = addr;
|
||||
|
||||
avr_data_out();
|
||||
|
||||
@@ -225,21 +234,21 @@ void sram_bulk_write_start(uint32_t addr)
|
||||
|
||||
sreg_set(addr);
|
||||
|
||||
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||
|
||||
}
|
||||
|
||||
inline void sram_bulk_write_next(void)
|
||||
{
|
||||
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||
counter_up();
|
||||
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||
addr_current++;
|
||||
counter_up();
|
||||
}
|
||||
|
||||
inline void sram_bulk_write( uint8_t data)
|
||||
{
|
||||
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||
AVR_DATA_PORT = data;
|
||||
}
|
||||
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||
}
|
||||
|
||||
void sram_bulk_write_end(void)
|
||||
{
|
||||
@@ -290,8 +299,11 @@ void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len)
|
||||
addr, src, len);
|
||||
sram_bulk_write_start(addr);
|
||||
for (i = addr; i < (addr + len); i++){
|
||||
sram_bulk_write(*ptr++);
|
||||
sram_bulk_write_next();
|
||||
sram_bulk_write(*ptr);
|
||||
//hack
|
||||
if ((i+1) < (addr + len))
|
||||
sram_bulk_write_next();
|
||||
ptr++;
|
||||
}
|
||||
sram_bulk_write_end();
|
||||
}
|
||||
@@ -305,9 +317,8 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
||||
addr, dst, len);
|
||||
sram_bulk_read_start(addr);
|
||||
for (i = addr; i < (addr + len); i++) {
|
||||
*ptr = sram_bulk_read();
|
||||
dst[i] = sram_bulk_read();
|
||||
sram_bulk_read_next();
|
||||
ptr++;
|
||||
}
|
||||
sram_bulk_read_end();
|
||||
}
|
||||
|
||||
+12
-8
@@ -86,22 +86,22 @@
|
||||
#define AVR_ADDR_LATCH_DIR DDRC
|
||||
#define AVR_ADDR_LATCH_PIN PC6
|
||||
|
||||
#define avr_addr_latch_hi() (AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN)))
|
||||
#define avr_addr_latch_lo() (AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN)))
|
||||
#define avr_addr_latch_hi() (AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN))
|
||||
#define avr_addr_latch_lo() (AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN))
|
||||
|
||||
#define AVR_ADDR_SCK_PORT PORTC
|
||||
#define AVR_ADDR_SCK_DIR DDRC
|
||||
#define AVR_ADDR_SCK_PIN PC5
|
||||
|
||||
#define avr_addr_sck_hi() (AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN)))
|
||||
#define avr_addr_sck_lo() (AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN)))
|
||||
#define avr_addr_sck_hi() (AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN))
|
||||
#define avr_addr_sck_lo() (AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN))
|
||||
|
||||
#define AVR_ADDR_SER_PORT PORTC
|
||||
#define AVR_ADDR_SER_DIR DDRC
|
||||
#define AVR_ADDR_SER_PIN PC4
|
||||
|
||||
#define avr_addr_ser_hi() (AVR_ADDR_SER_PORT |= (1 << AVR_ADDR_SER_PIN)))
|
||||
#define avr_addr_ser_lo() (AVR_ADDR_SER_PORT &= ~(1 << AVR_ADDR_SER_PIN)))
|
||||
#define avr_addr_ser_hi() (AVR_ADDR_SER_PORT |= (1 << AVR_ADDR_SER_PIN))
|
||||
#define avr_addr_ser_lo() (AVR_ADDR_SER_PORT &= ~(1 << AVR_ADDR_SER_PIN))
|
||||
|
||||
#define AVR_ADDR_LOAD_PORT PORTC
|
||||
#define AVR_ADDR_LOAD_DIR DDRC
|
||||
@@ -137,6 +137,8 @@
|
||||
#define led_off() ((LED_PORT &=~ (1 << LED_PIN)),\
|
||||
(LED_DIR |= (1 << LED_PIN)))
|
||||
|
||||
#define led_pwm_on() (LED_DIR &=~ (1 << LED_PIN))
|
||||
#define led_pwm_off() (LED_DIR |= (1 << LED_PIN))
|
||||
|
||||
/* ---------------------------- PORT D ---------------------------- */
|
||||
|
||||
@@ -151,7 +153,8 @@
|
||||
(AVR_CS_DIR |= (1 << AVR_CS_PIN)))
|
||||
|
||||
#define snes_bus_active() ((AVR_SNES_SW_PORT |= (1 << AVR_SNES_SW_PIN)),\
|
||||
(AVR_CS_DIR &= ~(1 << AVR_CS_PIN)))
|
||||
(AVR_CS_DIR &= ~(1 << AVR_CS_PIN)),\
|
||||
(AVR_CS_PORT |= (1 << AVR_CS_PIN)))
|
||||
|
||||
#define HI_LOROM_SW_PORT PORTD
|
||||
#define HI_LOROM_SW_DIR DDRD
|
||||
@@ -193,7 +196,7 @@
|
||||
|
||||
|
||||
|
||||
void system_init(void);
|
||||
void sram_init(void);
|
||||
void sreg_set(uint32_t addr);
|
||||
|
||||
uint8_t sram_read(uint32_t addr);
|
||||
@@ -203,6 +206,7 @@ void sram_bulk_read_start(uint32_t addr);
|
||||
inline void sram_bulk_read_next(void);
|
||||
inline void sram_bulk_read_end(void);
|
||||
uint8_t sram_bulk_read(void);
|
||||
uint16_t sram_read16_be(uint32_t addr);
|
||||
|
||||
void sram_bulk_write_start(uint32_t addr);
|
||||
inline void sram_bulk_write_next(void);
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h> /* for _delay_ms() */
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "sram.h"
|
||||
#include "system.h"
|
||||
#include "uart.h"
|
||||
#include "debug.h"
|
||||
#include "info.h"
|
||||
#include "requests.h"
|
||||
#include "irq.h"
|
||||
|
||||
system_t system;
|
||||
|
||||
void system_init(void)
|
||||
{
|
||||
snes_reset_hi();
|
||||
snes_reset_off();
|
||||
system.reset_line = RESET_OFF;
|
||||
|
||||
snes_irq_hi();
|
||||
snes_irq_off();
|
||||
system.irq_line = IRQ_OFF;
|
||||
|
||||
|
||||
snes_wr_disable();
|
||||
system.wr_line = WR_DISABLE;
|
||||
|
||||
avr_bus_active();
|
||||
system.bus_mode = MODE_AVR;
|
||||
|
||||
snes_lorom();
|
||||
system.rom_mode = LOROM;
|
||||
|
||||
system.snes_reset_count = 0;
|
||||
system.avr_reset_count = 0;
|
||||
|
||||
system.reset_irq = RESET_IRQ_OFF;
|
||||
|
||||
}
|
||||
|
||||
void system_send_snes_reset()
|
||||
{
|
||||
info_P(PSTR("Reset SNES\n"));
|
||||
cli();
|
||||
snes_reset_on();
|
||||
snes_reset_lo();
|
||||
_delay_ms(2);
|
||||
snes_reset_hi();
|
||||
snes_reset_off();
|
||||
sei();
|
||||
system.snes_reset_count++;
|
||||
}
|
||||
|
||||
void system_send_snes_irq()
|
||||
{
|
||||
snes_irq_on();
|
||||
snes_irq_lo();
|
||||
_delay_us(20);
|
||||
snes_irq_hi();
|
||||
snes_irq_off();
|
||||
}
|
||||
|
||||
void system_snes_irq_off()
|
||||
{
|
||||
snes_irq_off();
|
||||
system.irq_line = IRQ_OFF;
|
||||
}
|
||||
|
||||
void system_snes_irq_on()
|
||||
{
|
||||
snes_irq_on();
|
||||
system.irq_line = IRQ_ON;
|
||||
}
|
||||
|
||||
|
||||
void system_set_bus_avr()
|
||||
{
|
||||
avr_bus_active();
|
||||
info_P(PSTR("Activate AVR bus\n"));
|
||||
system.bus_mode = MODE_AVR;
|
||||
}
|
||||
|
||||
void system_set_wr_disable(){
|
||||
snes_wr_disable();
|
||||
system.wr_line = WR_DISABLE;
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
}
|
||||
|
||||
void system_set_wr_enable(){
|
||||
snes_wr_enable();
|
||||
system.wr_line = WR_ENABLE;
|
||||
info_P(PSTR("Enable SNES WR\n"));
|
||||
}
|
||||
|
||||
void system_set_bus_snes()
|
||||
{
|
||||
snes_bus_active();
|
||||
system.bus_mode = MODE_SNES;
|
||||
info_P(PSTR("Activate SNES bus\n"));
|
||||
}
|
||||
|
||||
void system_set_rom_mode(usb_transaction_t *usb_trans)
|
||||
{
|
||||
if (usb_trans->req_bank_size == 0x8000) {
|
||||
snes_lorom();
|
||||
system.rom_mode = LOROM;
|
||||
info_P(PSTR("Set SNES lorom \n"));
|
||||
} else {
|
||||
snes_hirom();
|
||||
system.rom_mode = HIROM;
|
||||
info_P(PSTR("Set SNES hirom \n"));
|
||||
}
|
||||
}
|
||||
|
||||
void system_set_rom_lorom()
|
||||
{
|
||||
snes_lorom();
|
||||
system.rom_mode = LOROM;
|
||||
info_P(PSTR("Set SNES lorom \n"));
|
||||
}
|
||||
|
||||
|
||||
void system_set_rom_hirom()
|
||||
{
|
||||
snes_hirom();
|
||||
system.rom_mode = HIROM;
|
||||
info_P(PSTR("Set SNES hirom \n"));
|
||||
}
|
||||
|
||||
char* system_status_helper(uint8_t val){
|
||||
if (val)
|
||||
return "ON";
|
||||
else
|
||||
return "OFF";
|
||||
}
|
||||
|
||||
char* system_status_bus(uint8_t val){
|
||||
if (val)
|
||||
return "SNES";
|
||||
else
|
||||
return "AVR";
|
||||
}
|
||||
|
||||
char* system_status_rom(uint8_t val){
|
||||
if (val)
|
||||
return "HIROM";
|
||||
else
|
||||
return "LOROM";
|
||||
}
|
||||
|
||||
void system_status(){
|
||||
info_P(PSTR("\nBus Mode %s\n"),system_status_bus(system.bus_mode));
|
||||
info_P(PSTR("Rom Mode %s\n"),system_status_rom(system.rom_mode));
|
||||
info_P(PSTR("Reset Line %s\n"),system_status_helper(system.reset_line));
|
||||
info_P(PSTR("IRQ Line %s\n"),system_status_helper(system.irq_line));
|
||||
info_P(PSTR("WR Line %s\n"),system_status_helper(system.wr_line));
|
||||
info_P(PSTR("Reset IRQ %s\n"),system_status_helper(system.reset_irq));
|
||||
info_P(PSTR("SNES Reset 0x%02x\n"),system.snes_reset_count);
|
||||
info_P(PSTR("AVR Reset 0x%02x\n"),system.avr_reset_count);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __SYSTEM_H__
|
||||
#define __SYSTEM_H__
|
||||
|
||||
#include "requests.h"
|
||||
|
||||
|
||||
|
||||
typedef struct system_t {
|
||||
enum bus_mode_e { MODE_AVR, MODE_SNES } bus_mode;
|
||||
enum rom_mode_e { LOROM, HIROM } rom_mode;
|
||||
enum reset_line_e { RESET_OFF, RESET_ON } reset_line;
|
||||
enum irq_line_e { IRQ_ON, IRQ_OFF } irq_line;
|
||||
enum wr_line_e { WR_DISABLE, WR_ENABLE } wr_line;
|
||||
enum reset_irq_e { RESET_IRQ_OFF, RESET_IRQ_ON } reset_irq;
|
||||
|
||||
uint8_t snes_reset_count;
|
||||
uint8_t avr_reset_count;
|
||||
} system_t;
|
||||
|
||||
void system_init(void);
|
||||
void system_init(void);
|
||||
void system_send_snes_reset(void);
|
||||
void system_send_snes_irq(void);
|
||||
void system_set_bus_avr(void);
|
||||
void system_set_bus_snes(void);
|
||||
void system_set_rom_mode(usb_transaction_t *usb_trans);
|
||||
void system_set_rom_hirom(void);
|
||||
void system_set_rom_lorom(void);
|
||||
void system_snes_irq_off(void);
|
||||
void system_set_wr_disable(void);
|
||||
void system_set_wr_enable(void);
|
||||
|
||||
void system_status();
|
||||
|
||||
#endif
|
||||
+1156
-400
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@
|
||||
#include "debug.h"
|
||||
#include "crc.h"
|
||||
#include "info.h"
|
||||
#include "dump.h"
|
||||
|
||||
void test_read_write()
|
||||
{
|
||||
@@ -92,6 +93,30 @@ void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
||||
}
|
||||
|
||||
|
||||
void test_memory_pattern(uint32_t bottom_addr, uint32_t top_addr, uint32_t bank_size)
|
||||
{
|
||||
uint32_t addr = 0;
|
||||
uint8_t pattern = 0x55;
|
||||
info_P(PSTR("test_memory_pattern: bottom_addr=0x%08lx top_addr=0x%08lx\n"), bottom_addr, top_addr);
|
||||
sram_bulk_write_start(bottom_addr);
|
||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||
if (addr % bank_size == 0){
|
||||
pattern++;
|
||||
info_P(PSTR("test_memory_pattern: write addr=0x%08lx pattern=0x%08lx\n"), addr, pattern);
|
||||
}
|
||||
sram_bulk_write(pattern);
|
||||
}
|
||||
sram_bulk_write_end();
|
||||
|
||||
|
||||
for (addr = bottom_addr; addr < top_addr; addr+=bank_size) {
|
||||
info_P(PSTR("test_memory_pattern: dump bottom_addr=0x%08lx top_addr=0x%08lx\n"), addr, addr + bank_size);
|
||||
dump_memory(addr, addr + bank_size );
|
||||
info_P(PSTR("----------------------------------------------------------------\n"));
|
||||
}
|
||||
|
||||
crc_check_bulk_memory((uint32_t)bottom_addr,top_addr, bank_size);
|
||||
}
|
||||
|
||||
void test_crc()
|
||||
{
|
||||
|
||||
+7
-2
@@ -25,6 +25,8 @@
|
||||
#include "uart.h"
|
||||
#include "fifo.h"
|
||||
|
||||
|
||||
|
||||
volatile struct {
|
||||
uint8_t tmr_int:1;
|
||||
uint8_t adc_int:1;
|
||||
@@ -35,6 +37,9 @@ volatile struct {
|
||||
volatile char rxbuff;
|
||||
|
||||
|
||||
|
||||
static int uart_stream(char c, FILE *stream);
|
||||
|
||||
FILE uart_stdout = FDEV_SETUP_STREAM(uart_stream, NULL, _FDEV_SETUP_WRITE);
|
||||
|
||||
void uart_init(void)
|
||||
@@ -47,7 +52,7 @@ void uart_init(void)
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ISR(USART0_RX_vect)
|
||||
{
|
||||
uint8_t c;
|
||||
@@ -57,7 +62,7 @@ ISR(USART0_RX_vect)
|
||||
intflags.rx_int = 1;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void uart_putc(uint8_t c)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,6 @@ void uart_init(void);
|
||||
void uart_putc(const uint8_t);
|
||||
void uart_puts(const char *s);
|
||||
void uart_puts_P(PGM_P s);
|
||||
static int uart_stream(char c, FILE *stream);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+13
-21
@@ -39,32 +39,24 @@
|
||||
#include "crc.h"
|
||||
#include "usb_bulk.h"
|
||||
|
||||
extern uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
|
||||
extern uint32_t req_addr;
|
||||
extern uint32_t req_size;
|
||||
extern uint8_t req_bank;
|
||||
extern uint32_t req_bank_size;
|
||||
extern uint8_t req_state;
|
||||
extern uint8_t rx_remaining;
|
||||
extern uint8_t tx_remaining;
|
||||
extern uint8_t tx_buffer[32];
|
||||
extern uint16_t crc;
|
||||
|
||||
extern usb_transaction_t usb_trans;
|
||||
|
||||
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
uint8_t i;
|
||||
|
||||
if (len > rx_remaining) {
|
||||
if (len > usb_trans.rx_remaining) {
|
||||
info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
|
||||
rx_remaining, len);
|
||||
len = rx_remaining;
|
||||
usb_trans.rx_remaining, len);
|
||||
len = usb_trans.rx_remaining;
|
||||
}
|
||||
if (req_state == REQ_STATUS_BULK_UPLOAD) {
|
||||
if (usb_trans.req_state == REQ_STATUS_BULK_UPLOAD) {
|
||||
|
||||
rx_remaining -= len;
|
||||
usb_trans.rx_remaining -= len;
|
||||
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);
|
||||
usb_trans.req_addr, len, usb_trans.rx_remaining);
|
||||
ptr = data;
|
||||
i = len;
|
||||
while(i--){
|
||||
@@ -78,13 +70,13 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
||||
uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
if (len > tx_remaining)
|
||||
len = tx_remaining;
|
||||
tx_remaining -= len;
|
||||
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, tx_remaining);
|
||||
if (len > usb_trans.tx_remaining)
|
||||
len = usb_trans.tx_remaining;
|
||||
usb_trans.tx_remaining -= len;
|
||||
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, usb_trans.tx_remaining);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
*data = tx_buffer[len];
|
||||
*data = usb_trans.tx_buffer[len];
|
||||
data++;
|
||||
}
|
||||
return len;
|
||||
|
||||
@@ -127,7 +127,7 @@ section at the end of this file).
|
||||
* (e.g. HID), but never want to send any data. This option saves a couple
|
||||
* of bytes in flash memory and the transmit buffers in RAM.
|
||||
*/
|
||||
#define USB_CFG_INTR_POLL_INTERVAL 200
|
||||
#define USB_CFG_INTR_POLL_INTERVAL 20
|
||||
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
|
||||
* interval. The value is in milliseconds and must not be less than 10 ms for
|
||||
* low speed devices.
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
uint8_t *util_strupper(uint8_t *s)
|
||||
{
|
||||
uint8_t *p;
|
||||
for (p = s; *p != '\0'; p++)
|
||||
if (*p >= 'a' && *p <= 'z')
|
||||
*p += 'A' - 'a';
|
||||
return s;
|
||||
}
|
||||
|
||||
uint8_t *util_strlower(uint8_t *s)
|
||||
{
|
||||
uint8_t *p;
|
||||
for (p = s; *p != '\0'; p++)
|
||||
if (*p >= 'A' && *p <= 'Z')
|
||||
*p += 'a' - 'A';
|
||||
return s;
|
||||
}
|
||||
|
||||
void util_chomp(uint8_t *s)
|
||||
{
|
||||
uint16_t len;
|
||||
|
||||
len = strlen((char*)s);
|
||||
if (len >= 2 && s[len - 1] == '\n' && s[len - 2] == '\r')
|
||||
s[len - 2] = '\0';
|
||||
else if (len >= 1 && (s[len - 1] == '\n' || s[len - 1] == '\r'))
|
||||
s[len - 1] = '\0';
|
||||
}
|
||||
|
||||
void util_trim(uint8_t *s)
|
||||
{
|
||||
uint8_t *p = s;
|
||||
uint8_t *q;
|
||||
/* skip leading whitespace */
|
||||
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
||||
p++;
|
||||
/* now p points at the first non-whitespace uint8_tacter */
|
||||
|
||||
if (*p == '\0') {
|
||||
/* only whitespace */
|
||||
*s = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
q = s + strlen((char*)s);
|
||||
/* skip trailing whitespace */
|
||||
/* we have found p < q such that *p is non-whitespace,
|
||||
so this loop terminates with q >= p */
|
||||
do
|
||||
q--;
|
||||
while (*q == ' ' || *q == '\t' || *q == '\r' || *q == '\n');
|
||||
|
||||
/* now q points at the last non-whitespace uint8_tacter */
|
||||
/* cut off trailing whitespace */
|
||||
*++q = '\0';
|
||||
|
||||
/* move to string */
|
||||
memmove(s, p, q + 1 - p);
|
||||
}
|
||||
|
||||
uint32_t util_sscandec(const uint8_t *s)
|
||||
{
|
||||
uint32_t result;
|
||||
if (*s == '\0')
|
||||
return -1;
|
||||
result = 0;
|
||||
for (;;) {
|
||||
if (*s >= '0' && *s <= '9')
|
||||
result = 10 * result + *s - '0';
|
||||
else if (*s == '\0')
|
||||
return result;
|
||||
else
|
||||
return -1;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t util_sscanhex(const uint8_t *s)
|
||||
{
|
||||
int32_t result;
|
||||
if (*s == '\0')
|
||||
return -1;
|
||||
result = 0;
|
||||
for (;;) {
|
||||
if (*s >= '0' && *s <= '9')
|
||||
result = 16 * result + *s - '0';
|
||||
else if (*s >= 'A' && *s <= 'F')
|
||||
result = 16 * result + *s - 'A' + 10;
|
||||
else if (*s >= 'a' && *s <= 'f')
|
||||
result = 16 * result + *s - 'a' + 10;
|
||||
else if (*s == '\0')
|
||||
return result;
|
||||
else
|
||||
return -1;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t util_sscanbool(const uint8_t *s)
|
||||
{
|
||||
if (*s == '0' && s[1] == '\0')
|
||||
return 0;
|
||||
if (*s == '1' && s[1] == '\0')
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* ________ .__ __ ________ ____ ________
|
||||
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||
* \__> \/ \/ \/ \/ \/
|
||||
*
|
||||
* www.optixx.org
|
||||
*
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/21/2009 03:32:16 PM
|
||||
* Author: david@optixx.org
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#ifndef __UTIL_H__
|
||||
#define __UTIL_H__
|
||||
|
||||
uint8_t *util_strupper(uint8_t *s);
|
||||
uint8_t *util_strlower(uint8_t *s);
|
||||
void util_chomp(uint8_t *s);
|
||||
void util_trim(uint8_t *s);
|
||||
uint32_t util_sscandec(const uint8_t *s);
|
||||
uint32_t util_sscanhex(const uint8_t *s);
|
||||
uint8_t util_sscanbool(const uint8_t *s);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
x 2009-10-13 Send PCB to seeed
|
||||
x 2009-10-13 RS232 cable add programm header and sio lines
|
||||
x 2009-10-13 Assemble No. 006 & No. 007
|
||||
x 2009-10-13 Flash all cartridge with latest firmware and bootloader
|
||||
x 2009-10-13 Bootloader lockbits
|
||||
x 2009-10-13 Rework No. 002
|
||||
x 2009-10-13 Package for Quickdev16
|
||||
x 2009-10-13 Add struct for usb and communcations flags
|
||||
x 2009-10-13 Mail snega2usb about OEM
|
||||
x 2009-10-13 Email to seeed about the retour package
|
||||
|
||||
Vendored
Vendored
Vendored
Vendored
Vendored
Vendored
Vendored
Vendored
Vendored
Vendored
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user