get inflate test working

This commit is contained in:
optixx
2009-10-25 17:31:08 +01:00
parent 185b833929
commit 54acc416b0
13 changed files with 2703 additions and 126 deletions

View File

@@ -31,7 +31,7 @@ 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 \

View File

@@ -0,0 +1,6 @@
all:
gcc -c loader_test.c
gcc -c inflate.c
gcc -c neginf/neginf.c
gcc -c inflate_test.c
gcc -o inflate_test inflate.o neginf.o inflate_test.o loader_test.o

View File

@@ -61,37 +61,6 @@ void usb_connect()
}
void send_reset()
{
info_P(PSTR("Reset SNES\n"));
cli();
snes_reset_on();
snes_reset_lo();
_delay_ms(2);
snes_reset_hi();
snes_reset_off();
sei();
}
void send_irq()
{
snes_irq_on();
snes_irq_lo();
_delay_us(20);
snes_irq_hi();
snes_irq_off();
}
void set_rom_mode()
{
if (usb_trans.req_bank_size == 0x8000) {
snes_lorom();
info_P(PSTR("Set SNES lowrom \n"));
} else {
snes_hirom();
info_P(PSTR("Set SNES hirom \n"));
}
}
void boot_startup_rom(uint16_t init_delay)
{
@@ -108,12 +77,6 @@ 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++){
@@ -136,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();
@@ -158,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);
}

View File

@@ -17,21 +17,30 @@
*
* =====================================================================================
*/
#include <string.h>
#include <stdio.h>
#include "neginf/neginf.h"
#include "inflate.h"
#include "sram.h"
char inflate_done = 0;
char *mem;
int addr = 0;
void inflate_init()
{
printf("inflate_init\n");
neginf_init(0);
sram_bulk_write_start(0x000000);
mem = (char*)malloc(2<<16);
addr = 0;
}
void inflate_flush()
{
FILE *file;
file = fopen("out.smc","w");
fwrite(mem,2<<16,1,file);
fclose(file);
}
void neginf_cb_completed()
@@ -41,30 +50,18 @@ void neginf_cb_completed()
void neginf_cb_seq_byte(nbyte byte)
{
//printf("neginf_cb_seq_byte %x", byte);
sram_bulk_write(byte);
mem[addr] = byte;
addr++;
}
//uint8_t buffer[512];
void neginf_cb_copy(nsize from, nsize to, nint length)
{
uint32_t addr;
uint8_t c;
printf("neginf_cb_copy %lx %lx %li\n", from, to, length);
sram_bulk_addr_save();
for (addr=from; addr<from+length; addr++){
c = sram_read(addr);
sram_write(addr,c);
}
sram_bulk_addr_restore();
/*
sram_bulk_addr_save();
sram_bulk_copy_into_buffer(from, buffer, length);
sram_bulk_copy_from_buffer(to, buffer, length);
sram_bulk_addr_restore();
*/
int i;
printf("neginf_cb_copy from=0x%06x to=0x%06x len=%i\n",from, to, length);
for (i=0; i<length;i++)
mem[to+i] = mem[from+i];
addr = to + length;
}

View File

@@ -0,0 +1,42 @@
/*
* =====================================================================================
*
* ________ .__ __ ________ ____ ________
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
* \__> \/ \/ \/ \/ \/
*
* 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;
void 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();
}

View File

@@ -1,6 +1,6 @@
/*
File: qd16boot02.smc
Time: Tue, 20 Oct 2009 22:07:40
Time: Sat, 24 Oct 2009 19:05:36
*/
#ifndef __FIFO_H__
#define __FIFO_H__

2254
avr/usbload/loader_test.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#ifndef __FIFO_H__
#define __FIFO_H__
#define ROM_ZIP_SIZE 35945
#endif

View File

@@ -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;
/*
* -------------------------------------------------------------------------
*/
@@ -266,12 +258,6 @@ 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();

View File

@@ -7,6 +7,7 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "neginf.h"
#include "neginf_priv.h"
@@ -46,8 +47,10 @@ 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]();
}
}
@@ -61,11 +64,13 @@ nsize neginf_output_position()
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;
@@ -73,6 +78,7 @@ void consume(ntiny amount)
void await_block()
{
//printf("wait block\n");
if(state.last_block)
{
neginf_cb_completed();
@@ -103,6 +109,7 @@ void await_block()
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;
@@ -110,12 +117,14 @@ void raw_block_begin()
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;
@@ -133,6 +142,8 @@ void raw_block()
void fixed_block_begin()
{
//printf("fixed block begin\n");
nint i = 0;
for(; i < 144; i++)
state.lit_len_lengths[i] = 8;
@@ -153,6 +164,7 @@ void fixed_block_begin()
void huff_block()
{
//printf("huff block\n");
nint code = lit_len_read();
if(code == 256)
{
@@ -174,6 +186,7 @@ void huff_block()
void huff_len_addbits()
{
//printf("huff len addbits\n");
nint len;
nint code = state.code;
nint la = lookahead();
@@ -214,12 +227,14 @@ void huff_len_addbits()
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;
@@ -250,6 +265,7 @@ 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++)
@@ -268,6 +284,7 @@ void dynamic_block_begin()
void dynamic_read_lc()
{
//printf("dynamic read lc\n");
if(state.hclen == 0)
{
compute_begin(state.hc_lengths, state.hc_begins, 19);
@@ -290,6 +307,7 @@ void dynamic_read_lc()
void dynamic_read_lit_len()
{
//printf("dynamic read lit len\n");
if(state.hlit == 0)
{
state.mode = mode_dynamic_read_dist;
@@ -303,6 +321,7 @@ void dynamic_read_lit_len()
void dynamic_read_dist()
{
//printf("dynamic read dist\n");
if(state.hdist == 0)
{
compute_begins();
@@ -316,6 +335,7 @@ void dynamic_read_dist()
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)
@@ -361,6 +381,7 @@ ntiny lc_read(ntiny * lenghts)
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);
}
@@ -370,6 +391,7 @@ 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++)
@@ -389,16 +411,20 @@ void compute_begin(ntiny * lengths, nint * begins, nint size)
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++)
@@ -421,7 +447,7 @@ nint huff_read(ntiny * lenghts, nint * begins, nint size)
code--;
}
}
assert(0);
//assert(0);
return 0; // silent warning
}

View File

@@ -16,7 +16,7 @@
//#define NEGINF_USE_REL_COPY
//#define NEGINF_POS_TRACKING
#define NEGINF_8BIT
//#define NEGINF_8BIT
#define NEGINF_PACKED_STATE