try new ringbuffer
This commit is contained in:
parent
7a8ae11ce1
commit
5a439f56bb
@ -27,41 +27,32 @@
|
|||||||
#include "ringbuffer.h"
|
#include "ringbuffer.h"
|
||||||
|
|
||||||
char inflate_done = 0;
|
char inflate_done = 0;
|
||||||
char *mem;
|
|
||||||
char *mem_ref;
|
char *mem_ref;
|
||||||
|
|
||||||
int addr = 0;
|
|
||||||
int addr_ref = 0;
|
int addr_ref = 0;
|
||||||
|
|
||||||
|
int cnt_hit = 0;
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
|
||||||
void inflate_init()
|
void inflate_init()
|
||||||
{
|
{
|
||||||
neginf_init(0);
|
neginf_init(0);
|
||||||
mem = (char*)malloc(2<<15);
|
|
||||||
mem_ref = (char*)malloc(2<<15);
|
mem_ref = (char*)malloc(2<<15);
|
||||||
addr_ref = 0;
|
addr_ref = 0;
|
||||||
addr = 0;
|
|
||||||
rb_init();
|
rb_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void inflate_flush()
|
void inflate_flush()
|
||||||
{
|
{
|
||||||
while(!rb_isempty()){
|
|
||||||
|
|
||||||
mem[addr++] = rb_get();
|
rb_flush();
|
||||||
printf("final fill addr=0x%06x size=%i\n",addr,rb_free());
|
|
||||||
}
|
|
||||||
printf("write out.smc\n");
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
file = fopen("out.smc","w");
|
|
||||||
fwrite(mem,2<<15,1,file);
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
printf("write out_ref.smc\n");
|
printf("write out_ref.smc\n");
|
||||||
file = fopen("out_ref.smc","w");
|
file = fopen("out_ref.smc","w");
|
||||||
fwrite(mem_ref,2<<15,1,file);
|
fwrite(mem_ref,2<<15,1,file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
printf("cnt=%i cnt_hit=%i\n",cnt,cnt_hit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void neginf_cb_completed()
|
void neginf_cb_completed()
|
||||||
@ -71,32 +62,21 @@ void neginf_cb_completed()
|
|||||||
|
|
||||||
void neginf_cb_seq_byte(nbyte byte)
|
void neginf_cb_seq_byte(nbyte byte)
|
||||||
{
|
{
|
||||||
|
|
||||||
mem_ref[addr_ref++] = byte;
|
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);
|
rb_put(byte);
|
||||||
//assert(!rb_isfull());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void neginf_cb_copy(nsize from, nsize to, nint length)
|
void neginf_cb_copy(nsize from, nsize to, nint length)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
cnt++;
|
||||||
printf("neginf_cb_copy addr=0x%06x from=0x%06x to=0x%06x len=%i\n",addr,from, to, length);
|
if ((to - from) < ( 1024 * 2 ) ){
|
||||||
|
cnt_hit++;
|
||||||
|
}
|
||||||
|
printf("neginf_cb_copy from=0x%06x to=0x%06x dist=%i len=%i\n",from, to, (to - from), length);
|
||||||
for (i=0; i<length;i++){
|
for (i=0; i<length;i++){
|
||||||
mem_ref[to+i] = mem_ref[from+i];
|
mem_ref[to+i] = mem_ref[from+i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<length;i++){
|
|
||||||
mem[to+i] = mem_ref[from+i];
|
|
||||||
}
|
|
||||||
addr = to + length;
|
|
||||||
addr_ref = to + length;
|
addr_ref = to + length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,42 +10,66 @@ t-> o
|
|||||||
b-> x
|
b-> x
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "ringbuffer.h"
|
#include "ringbuffer.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define ringbuffer_size 2048
|
||||||
|
#define memory_size 65536
|
||||||
|
|
||||||
|
|
||||||
static char buf[ringbuffer_size];
|
|
||||||
int rb_count;
|
|
||||||
|
|
||||||
#define t &buf[ringbuffer_size - 1]
|
#define t &buf[ringbuffer_size - 1]
|
||||||
#define b &buf[0]
|
#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 *t = &buf[ringbuffer_size - 1];
|
||||||
//char *b = &buf[0];
|
//char *b = &buf[0];
|
||||||
|
|
||||||
char *r; // position from where we can read (if rb_count > 0)
|
char *r; // position from where we can read (if rb_count > 0)
|
||||||
char *w; // next free position (if rb_count < ringbuffer_size))
|
char *w; // next free position (if rb_count < ringbuffer_size))
|
||||||
|
|
||||||
void rb_init(void)
|
void rb_init()
|
||||||
{
|
{
|
||||||
r = b;
|
r = b;
|
||||||
w = b;
|
w = b;
|
||||||
rb_count = 0;
|
rb_count = 0;
|
||||||
memset(buf,0,ringbuffer_size);
|
memory = (char*)malloc(memory_size);
|
||||||
|
pos_mem = 0;
|
||||||
|
pos_head = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
char rb_get(void)
|
||||||
{
|
{
|
||||||
rb_count--;
|
rb_count--;
|
||||||
if (r > t) r = b;
|
if (r > t)
|
||||||
|
r = b;
|
||||||
return *r++;
|
return *r++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char rb_read(void)
|
char rb_read(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (r > t) r = b;
|
if (r > t) r = b;
|
||||||
return *r++;
|
return *r++;
|
||||||
}
|
}
|
||||||
@ -53,10 +77,16 @@ char rb_read(void)
|
|||||||
|
|
||||||
void rb_put(char el)
|
void rb_put(char el)
|
||||||
{
|
{
|
||||||
|
pos_head++;
|
||||||
rb_count++;
|
rb_count++;
|
||||||
|
|
||||||
|
if ( rb_count > ringbuffer_size)
|
||||||
|
memory[pos_mem++]=el;
|
||||||
|
|
||||||
|
printf("rb_count=%i pos_head=0x%06x add_mem=0x%06x\n",rb_count, pos_head,pos_mem);
|
||||||
|
|
||||||
if (w > t){
|
if (w > t){
|
||||||
w = b;
|
w = b;
|
||||||
printf("wrap around\n");
|
}
|
||||||
}
|
|
||||||
*w++ = el;
|
*w++ = el;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,5 +14,6 @@ extern int rb_count;
|
|||||||
void rb_init(void);
|
void rb_init(void);
|
||||||
void rb_put(char el);
|
void rb_put(char el);
|
||||||
char rb_get(void);
|
char rb_get(void);
|
||||||
|
void rb_flush(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user