Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3cc6f41e2 | ||
|
|
5a439f56bb | ||
|
|
7a8ae11ce1 | ||
|
|
e177b17ad8 | ||
|
|
54acc416b0 | ||
|
|
185b833929 | ||
|
|
97137ed993 | ||
|
|
e13b124e93 | ||
|
|
05bb485495 | ||
|
|
3c39e11784 | ||
|
|
4b0bec820e |
@ -31,19 +31,19 @@ CONVERT_ZIP = ../../scripts/conv_zip.py
|
||||
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
LDFLAGS =-Wl,-u,vfprintf -lprintf_flt
|
||||
LDFLAGS =-Wl,-u,vfprintf
|
||||
CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \
|
||||
main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \
|
||||
dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \
|
||||
system.o pwm.o util.o shell.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
|
||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.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
|
||||
pwm.o inflate.o neginf/neginf.o
|
||||
endif
|
||||
|
||||
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||
@ -114,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
|
||||
|
||||
19
avr/usbload/Makefile.test
Normal file
19
avr/usbload/Makefile.test
Normal file
@ -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
|
||||
|
||||
@ -33,6 +33,9 @@
|
||||
#include "loader.h"
|
||||
#include "system.h"
|
||||
|
||||
#include "neginf/neginf.h"
|
||||
#include "inflate.h"
|
||||
|
||||
|
||||
extern usb_transaction_t usb_trans;
|
||||
extern system_t system;
|
||||
@ -58,42 +61,15 @@ void usb_connect()
|
||||
}
|
||||
|
||||
|
||||
void send_reset()
|
||||
{
|
||||
info_P(PSTR("Reset SNES\n"));
|
||||
cli();
|
||||
snes_reset_on();
|
||||
snes_reset_lo();
|
||||
_delay_ms(2);
|
||||
snes_reset_hi();
|
||||
snes_reset_off();
|
||||
sei();
|
||||
}
|
||||
|
||||
void send_irq()
|
||||
{
|
||||
snes_irq_on();
|
||||
snes_irq_lo();
|
||||
_delay_us(20);
|
||||
snes_irq_hi();
|
||||
snes_irq_off();
|
||||
}
|
||||
|
||||
void set_rom_mode()
|
||||
{
|
||||
if (usb_trans.req_bank_size == 0x8000) {
|
||||
snes_lorom();
|
||||
info_P(PSTR("Set SNES lowrom \n"));
|
||||
} else {
|
||||
snes_hirom();
|
||||
info_P(PSTR("Set SNES hirom \n"));
|
||||
}
|
||||
}
|
||||
|
||||
void boot_startup_rom(uint16_t init_delay)
|
||||
{
|
||||
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();
|
||||
@ -101,15 +77,18 @@ void boot_startup_rom(uint16_t init_delay)
|
||||
system_snes_irq_off();
|
||||
system_set_rom_lorom();
|
||||
|
||||
//info_P(PSTR("Activate AVR bus\n"));
|
||||
//avr_bus_active();
|
||||
//info_P(PSTR("IRQ off\n"));
|
||||
//snes_irq_lo();
|
||||
//snes_irq_off();
|
||||
//snes_lorom();
|
||||
|
||||
inflate_init();
|
||||
for (i=0; i<ROM_BUFFER_CNT; i++){
|
||||
addr += rle_decode(_rom[i], _rom_size[i], addr);
|
||||
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"));
|
||||
|
||||
@ -120,16 +99,7 @@ void boot_startup_rom(uint16_t init_delay)
|
||||
info(PSTR("crc=%x\n"),crc);
|
||||
#endif
|
||||
|
||||
//snes_irq_lo();
|
||||
//snes_irq_off();
|
||||
//snes_hirom();
|
||||
//snes_wr_disable();
|
||||
|
||||
//system_set_bus_snes();
|
||||
//system_set_rom_hirom();
|
||||
//system_set_wr_disable();
|
||||
//system_snes_irq_off();
|
||||
|
||||
|
||||
snes_irq_lo();
|
||||
system_snes_irq_off();
|
||||
system_set_rom_hirom();
|
||||
@ -142,31 +112,9 @@ void boot_startup_rom(uint16_t init_delay)
|
||||
}
|
||||
|
||||
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 transaction_status(){
|
||||
info_P(PSTR("\nAddr 0x%06lx\n"),usb_trans.req_addr);
|
||||
info_P(PSTR("Bank 0x%02x\n"),usb_trans.req_bank);
|
||||
info_P(PSTR("Banksize 0x%06lx\n"),usb_trans.req_bank_size);
|
||||
info_P(PSTR("Bankcount 0x%02x\n"),usb_trans.req_bank_cnt);
|
||||
info_P(PSTR("Status 0x%02x\n"),usb_trans.req_state);
|
||||
info_P(PSTR("Percent %02i\n"),usb_trans.req_percent);
|
||||
info_P(PSTR("TX buffer %02i\n"),usb_trans.tx_remaining);
|
||||
info_P(PSTR("RX buffer %02i\n"),usb_trans.rx_remaining);
|
||||
info_P(PSTR("Syncerr %02i\n"),usb_trans.sync_errors);
|
||||
}
|
||||
|
||||
|
||||
@ -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];
|
||||
|
||||
85
avr/usbload/inflate.c
Normal file
85
avr/usbload/inflate.c
Normal file
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
28
avr/usbload/inflate.h
Normal file
28
avr/usbload/inflate.h
Normal file
@ -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
|
||||
44
avr/usbload/inflate_test.c
Normal file
44
avr/usbload/inflate_test.c
Normal file
@ -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;
|
||||
}
|
||||
@ -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
|
||||
|
||||
4055
avr/usbload/loader.c
4055
avr/usbload/loader.c
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,14 @@
|
||||
/*
|
||||
File: qd16boot01.smc
|
||||
Time: Tue, 20 Oct 2009 21:42:10
|
||||
File: qd16boot02.smc
|
||||
Time: Sat, 24 Oct 2009 19:05:36
|
||||
*/
|
||||
#ifndef __FIFO_H__
|
||||
#define __FIFO_H__
|
||||
|
||||
#define ROM_HUFFMAN_SIZE 0
|
||||
#define ROM_RLE_SIZE 31091
|
||||
#define ROM_BUFFER_CNT 1
|
||||
#define ROM_ZIP_SIZE 33654
|
||||
#define ROM_BUFFER_CNT 2
|
||||
|
||||
#define ROM_BUFFER_SIZE01 31091
|
||||
#define ROM_BUFFER_SIZE01 32767
|
||||
#define ROM_BUFFER_SIZE02 887
|
||||
|
||||
#endif
|
||||
|
||||
2229
avr/usbload/loader_test.c
Normal file
2229
avr/usbload/loader_test.c
Normal file
File diff suppressed because it is too large
Load Diff
7
avr/usbload/loader_test.h
Normal file
7
avr/usbload/loader_test.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef __FIFO_H__
|
||||
#define __FIFO_H__
|
||||
|
||||
#define ROM_ZIP_SIZE 35543
|
||||
|
||||
#endif
|
||||
@ -193,14 +193,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
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_SNES) {
|
||||
usb_trans.req_state = REQ_STATUS_SNES;
|
||||
debug_P(DEBUG_USB, PSTR("USB_MODE_SNES:\n"));
|
||||
ret_len = 0;
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
@ -254,11 +246,11 @@ int main(void)
|
||||
shared_memory_init();
|
||||
system_init();
|
||||
sram_init();
|
||||
pwm_init();
|
||||
//pwm_init();
|
||||
irq_init();
|
||||
boot_startup_rom(50);
|
||||
globals_init();
|
||||
pwm_stop();
|
||||
//pwm_stop();
|
||||
usbInit();
|
||||
usb_connect();
|
||||
sei();
|
||||
@ -266,17 +258,13 @@ int main(void)
|
||||
|
||||
system_set_bus_avr();
|
||||
system_set_wr_disable();
|
||||
/*
|
||||
avr_bus_active();
|
||||
info_P(PSTR("Activate AVR bus\n"));
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
snes_wr_disable();
|
||||
*/
|
||||
info_P(PSTR("USB poll\n"));
|
||||
while (usb_trans.req_state != REQ_STATUS_SNES) {
|
||||
usbPoll();
|
||||
#ifdef DO_SHELL
|
||||
#ifndef NO_DEBUG
|
||||
shell_run();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -312,9 +300,12 @@ int main(void)
|
||||
info_P(PSTR("Poll USB\n"));
|
||||
while ((usb_trans.req_state != REQ_STATUS_AVR)) {
|
||||
usbPoll();
|
||||
#ifdef DO_SHELL
|
||||
#ifndef NO_DEBUG
|
||||
shell_run();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
//info_P(PSTR("-->Switch TO AVR\n"));
|
||||
shared_memory_init();
|
||||
|
||||
466
avr/usbload/neginf/neginf.c
Normal file
466
avr/usbload/neginf/neginf.c
Normal file
@ -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
|
||||
43
avr/usbload/neginf/neginf.h
Normal file
43
avr/usbload/neginf/neginf.h
Normal file
@ -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
|
||||
48
avr/usbload/neginf/neginf_conf.h
Normal file
48
avr/usbload/neginf/neginf_conf.h
Normal file
@ -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
|
||||
102
avr/usbload/neginf/neginf_priv.h
Normal file
102
avr/usbload/neginf/neginf_priv.h
Normal file
@ -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
|
||||
|
||||
|
||||
@ -31,6 +31,8 @@
|
||||
#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,
|
||||
@ -99,3 +101,4 @@ void pwm_init(void) {
|
||||
TIMSK2 |= (1<<OCIE2A);
|
||||
sei();
|
||||
}
|
||||
#endif
|
||||
126
avr/usbload/ringbuffer.c
Normal file
126
avr/usbload/ringbuffer.c
Normal file
@ -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;
|
||||
}
|
||||
19
avr/usbload/ringbuffer.h
Normal file
19
avr/usbload/ringbuffer.h
Normal file
@ -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
|
||||
@ -32,6 +32,8 @@
|
||||
|
||||
#define RUNCHAR 0x90
|
||||
|
||||
#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;
|
||||
@ -100,3 +102,5 @@ uint32_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||
info_P(PSTR("\nDone addr=0x%08lx\n"), out_addr);
|
||||
return out_addr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -44,13 +44,6 @@
|
||||
|
||||
extern system_t system;
|
||||
|
||||
const char STR_ROM[] PROGMEM = "Rom";
|
||||
const char STR_RAM[] PROGMEM = "Sram";
|
||||
const char STR_BAT[] PROGMEM = "Battery";
|
||||
const char STR_SUPERFX[] PROGMEM = "SuperFX";
|
||||
const char STR_SA[] PROGMEM = "SA-1";
|
||||
|
||||
|
||||
uint8_t command_buf[RECEIVE_BUF_LEN];
|
||||
uint8_t recv_buf[RECEIVE_BUF_LEN];
|
||||
|
||||
@ -59,6 +52,8 @@ volatile uint8_t cr = 0;
|
||||
|
||||
uint8_t *token_ptr;
|
||||
|
||||
#ifdef DO_SHELL
|
||||
|
||||
uint8_t *get_token(void)
|
||||
{
|
||||
uint8_t *p = token_ptr;
|
||||
@ -408,7 +403,7 @@ void shell_run(void)
|
||||
}
|
||||
|
||||
c = sram_read(0xffd6 - offset);
|
||||
info_P(PSTR("TYPE 0x%04xc"), (0xffd6 - offset),c);
|
||||
info_P(PSTR("TYPE 0x%04x "), (0xffd6 - offset),c);
|
||||
switch(c){
|
||||
case 0x00:
|
||||
info_P(PSTR("Rom\n"));
|
||||
@ -489,3 +484,4 @@ void shell_run(void)
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
1556
avr/usbload/tags
1556
avr/usbload/tags
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>currentDocument</key>
|
||||
<string>avr/usbload/shell.c</string>
|
||||
<string>scripts/conv_zip_test.py</string>
|
||||
<key>documents</key>
|
||||
<array>
|
||||
<dict>
|
||||
@ -21,75 +21,33 @@
|
||||
<integer>271</integer>
|
||||
<key>metaData</key>
|
||||
<dict>
|
||||
<key>avr/usbload/Makefile</key>
|
||||
<key>avr/usbload/inflate.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>10</integer>
|
||||
<integer>21</integer>
|
||||
<key>line</key>
|
||||
<integer>86</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>45</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/command.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>1</integer>
|
||||
<key>line</key>
|
||||
<integer>100</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>122</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/config.h</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>37</integer>
|
||||
<key>line</key>
|
||||
<integer>54</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>7</integer>
|
||||
<integer>18</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/crc.c</key>
|
||||
<key>avr/usbload/inflate_test.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>0</integer>
|
||||
<key>line</key>
|
||||
<integer>59</integer>
|
||||
<integer>28</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>34</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/debug.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>5</integer>
|
||||
<key>line</key>
|
||||
<integer>26</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/irq.c</key>
|
||||
<dict>
|
||||
@ -121,103 +79,19 @@
|
||||
<integer>39</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>avr/usbload/main.c</key>
|
||||
<key>avr/usbload/loader_test.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>0</integer>
|
||||
<key>line</key>
|
||||
<integer>330</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>281</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/shared_memory.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>26</integer>
|
||||
<key>line</key>
|
||||
<integer>247</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>222</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/shell.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>83</integer>
|
||||
<key>line</key>
|
||||
<integer>444</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>409</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/shell.h</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>22</integer>
|
||||
<key>line</key>
|
||||
<integer>23</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/sram.c</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>0</integer>
|
||||
<key>line</key>
|
||||
<integer>321</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>288</integer>
|
||||
</dict>
|
||||
<key>avr/usbload/sram.h</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>23</integer>
|
||||
<key>line</key>
|
||||
<integer>208</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>175</integer>
|
||||
</dict>
|
||||
<key>scripts/conv_rle.py</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>0</integer>
|
||||
<key>line</key>
|
||||
<integer>86</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>49</integer>
|
||||
</dict>
|
||||
<key>scripts/conv_zip.py</key>
|
||||
<dict>
|
||||
@ -231,21 +105,21 @@
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>6</integer>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
<key>scripts/zip2raw.rb</key>
|
||||
<key>scripts/conv_zip_test.py</key>
|
||||
<dict>
|
||||
<key>caret</key>
|
||||
<dict>
|
||||
<key>column</key>
|
||||
<integer>0</integer>
|
||||
<integer>38</integer>
|
||||
<key>line</key>
|
||||
<integer>0</integer>
|
||||
<integer>39</integer>
|
||||
</dict>
|
||||
<key>firstVisibleColumn</key>
|
||||
<integer>0</integer>
|
||||
<key>firstVisibleLine</key>
|
||||
<integer>95</integer>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
<key>snes/banktest/LoadGraphics.asm</key>
|
||||
<dict>
|
||||
@ -278,21 +152,12 @@
|
||||
</dict>
|
||||
<key>openDocuments</key>
|
||||
<array>
|
||||
<string>scripts/conv_rle.py</string>
|
||||
<string>avr/usbload/main.c</string>
|
||||
<string>avr/usbload/shell.h</string>
|
||||
<string>avr/usbload/shell.c</string>
|
||||
<string>scripts/conv_zip.py</string>
|
||||
<string>avr/usbload/Makefile</string>
|
||||
<string>scripts/zip2raw.rb</string>
|
||||
<string>avr/usbload/shared_memory.c</string>
|
||||
<string>avr/usbload/sram.h</string>
|
||||
<string>avr/usbload/sram.c</string>
|
||||
<string>avr/usbload/command.c</string>
|
||||
<string>avr/usbload/crc.c</string>
|
||||
<string>avr/usbload/config.h</string>
|
||||
<string>avr/usbload/debug.c</string>
|
||||
<string>avr/usbload/irq.c</string>
|
||||
<string>avr/usbload/loader_test.c</string>
|
||||
<string>avr/usbload/inflate_test.c</string>
|
||||
<string>avr/usbload/inflate.c</string>
|
||||
<string>scripts/conv_zip_test.py</string>
|
||||
<string>scripts/conv_zip.py</string>
|
||||
</array>
|
||||
<key>showFileHierarchyDrawer</key>
|
||||
<false/>
|
||||
@ -321,21 +186,6 @@
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>packages</key>
|
||||
<dict>
|
||||
<key>isExpanded</key>
|
||||
<true/>
|
||||
<key>subItems</key>
|
||||
<dict>
|
||||
<key>huffman</key>
|
||||
<dict>
|
||||
<key>isExpanded</key>
|
||||
<true/>
|
||||
<key>subItems</key>
|
||||
<dict/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>scripts</key>
|
||||
<dict>
|
||||
<key>isExpanded</key>
|
||||
@ -351,35 +201,6 @@
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>snes</key>
|
||||
<dict>
|
||||
<key>isExpanded</key>
|
||||
<true/>
|
||||
<key>subItems</key>
|
||||
<dict/>
|
||||
</dict>
|
||||
<key>tools</key>
|
||||
<dict>
|
||||
<key>isExpanded</key>
|
||||
<true/>
|
||||
<key>subItems</key>
|
||||
<dict>
|
||||
<key>qdinc</key>
|
||||
<dict>
|
||||
<key>isExpanded</key>
|
||||
<true/>
|
||||
<key>subItems</key>
|
||||
<dict/>
|
||||
</dict>
|
||||
<key>ucon64</key>
|
||||
<dict>
|
||||
<key>isExpanded</key>
|
||||
<true/>
|
||||
<key>subItems</key>
|
||||
<dict/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
|
||||
BIN
roms/qd16boot02_half.smc
Normal file
BIN
roms/qd16boot02_half.smc
Normal file
Binary file not shown.
78
scripts/conv_zip_test.py
Normal file
78
scripts/conv_zip_test.py
Normal file
@ -0,0 +1,78 @@
|
||||
import binascii
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
|
||||
LEN = 2**16
|
||||
huffman = False
|
||||
TARGET=os.getcwd()
|
||||
SOURCE=sys.argv[1]
|
||||
DEFLATE=os.path.basename(sys.argv[1]) + ".deflate"
|
||||
PATH="/Users/david/Devel/arch/avr/code/quickdev16/scripts"
|
||||
|
||||
WINE="/Applications/Darwine/Wine.bundle/Contents/bin/wine"
|
||||
KZIP=os.path.join(PATH,"kzip.exe")
|
||||
DEFLOPT=os.path.join(PATH,"DeflOpt.exe")
|
||||
ZIP2RAW=os.path.join(PATH,"zip2raw.rb")
|
||||
|
||||
method = 1
|
||||
|
||||
if method==0:
|
||||
if os.path.isfile("rom.zip"):
|
||||
os.unlink("rom.zip")
|
||||
|
||||
os.system("%s %s rom /s1 %s" % (WINE,KZIP,SOURCE))
|
||||
os.system("%s %s /a rom.zip" % (WINE,DEFLOPT))
|
||||
os.system("ruby %s rom.zip" % ZIP2RAW)
|
||||
|
||||
if os.path.isfile("rom.zip"):
|
||||
os.unlink("rom.zip")
|
||||
data = open(DEFLATE).read()
|
||||
os.unlink(DEFLATE)
|
||||
else:
|
||||
os.system("gzip < %s >/tmp/test" % SOURCE )
|
||||
data = open("/tmp/test").read()
|
||||
os.unlink("/tmp/test")
|
||||
data = data[10:]
|
||||
|
||||
zip_size = len(data)
|
||||
cfile = open("/tmp/loader_test.c","w")
|
||||
hfile = open("/tmp/loader_test.h","w")
|
||||
|
||||
|
||||
hfile.write('''
|
||||
#ifndef __FIFO_H__
|
||||
#define __FIFO_H__
|
||||
|
||||
#define ROM_ZIP_SIZE %i
|
||||
''' % zip_size)
|
||||
hfile.write('\n#endif\n')
|
||||
hfile.close()
|
||||
|
||||
cfile.write('''/*
|
||||
File: %s
|
||||
Time: %s
|
||||
*/
|
||||
''')
|
||||
|
||||
|
||||
cfile.write('''
|
||||
const char _rom[%i] = {
|
||||
''' % (zip_size))
|
||||
for idx,c in enumerate(data):
|
||||
c = ord(c)
|
||||
if idx<len(data)-1:
|
||||
cfile.write("0x%02x," % c)
|
||||
else:
|
||||
cfile.write("0x%02x" % c)
|
||||
if idx and idx%16==0:
|
||||
cfile.write("\n")
|
||||
cfile.write('''
|
||||
};
|
||||
''')
|
||||
|
||||
cfile.close()
|
||||
|
||||
shutil.copy("/tmp/loader_test.c", os.path.join(TARGET,"loader_test.c"))
|
||||
shutil.copy("/tmp/loader_test.h", os.path.join(TARGET,"loader_test.h"))
|
||||
Loading…
x
Reference in New Issue
Block a user