diff --git a/avr/usbload/Makefile.test b/avr/usbload/Makefile.test index 982f39f..d818d3e 100644 --- a/avr/usbload/Makefile.test +++ b/avr/usbload/Makefile.test @@ -1,6 +1,16 @@ 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 + 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 + @md5sum out.smc + @md5sum out_ref.smc + @md5sum ../../roms/qd16boot02_half.smc + diff --git a/avr/usbload/inflate.c b/avr/usbload/inflate.c index 7aa168e..dfaa291 100644 --- a/avr/usbload/inflate.c +++ b/avr/usbload/inflate.c @@ -19,29 +19,49 @@ */ #include #include +#include #include "neginf/neginf.h" #include "inflate.h" +#include "assert.h" +#include "ringbuffer.h" char inflate_done = 0; char *mem; +char *mem_ref; + int addr = 0; +int addr_ref = 0; void inflate_init() { neginf_init(0); - mem = (char*)malloc(2<<16); + mem = (char*)malloc(2<<15); + mem_ref = (char*)malloc(2<<15); + addr_ref = 0; addr = 0; + rb_init(); } void inflate_flush() -{ +{ + while(!rb_isempty()){ + + mem[addr++] = rb_get(); + printf("final fill addr=0x%06x size=%i\n",addr,rb_free()); + } + printf("write out.smc\n"); FILE *file; file = fopen("out.smc","w"); - fwrite(mem,2<<16,1,file); + fwrite(mem,2<<15,1,file); fclose(file); + printf("write out_ref.smc\n"); + file = fopen("out_ref.smc","w"); + fwrite(mem_ref,2<<15,1,file); + fclose(file); + } void neginf_cb_completed() @@ -51,18 +71,33 @@ void neginf_cb_completed() void neginf_cb_seq_byte(nbyte byte) { - mem[addr] = byte; - addr++; + + mem_ref[addr_ref++] = byte; + + + if (rb_isfull()) + mem[addr++] = rb_get(); + + printf("addr=%x byte=%i size=%i\n",addr,byte, rb_free()); + rb_put(byte); + //assert(!rb_isfull()); } void neginf_cb_copy(nsize from, nsize to, nint length) { int i; - printf("neginf_cb_copy from=0x%06x to=0x%06x len=%i\n",from, to, length); - for (i=0; i o + o <-w + x + x <-r +b-> x +*/ + +#include "ringbuffer.h" + + + + +static char buf[ringbuffer_size]; +int rb_count; + +#define t &buf[ringbuffer_size - 1] +#define b &buf[0] + +//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)) + +void rb_init(void) +{ + r = b; + w = b; + rb_count = 0; + memset(buf,0,ringbuffer_size); +} + +char rb_get(void) +{ + rb_count--; + if (r > t) r = b; + return *r++; +} + + +char rb_read(void) +{ + + if (r > t) r = b; + return *r++; +} + + +void rb_put(char el) +{ + rb_count++; + if (w > t){ + w = b; + printf("wrap around\n"); + } + *w++ = el; +} diff --git a/avr/usbload/ringbuffer.h b/avr/usbload/ringbuffer.h new file mode 100644 index 0000000..b6f7f6b --- /dev/null +++ b/avr/usbload/ringbuffer.h @@ -0,0 +1,18 @@ + +#ifndef _RING_BUFFER_H_ +#define _RING_BUFFER_H_ + + +#define ringbuffer_size 32 + +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); + +#endif diff --git a/roms/qd16boot02_half.smc b/roms/qd16boot02_half.smc new file mode 100644 index 0000000..6d9ab23 Binary files /dev/null and b/roms/qd16boot02_half.smc differ