Subj : Re: cc65 compression technique optimizations?
To   : Andreas Kohlbach
From : Harry Potter
Date : Wed Oct 09 2019 12:03 pm

On Wednesday, October 9, 2019 at 2:55:44 PM UTC-4, Andreas Kohlbach wrote:
> Yes, post some snippets please. I won't be able to help because I am a
> lousy 6502 assembly coder but generally interested what you have done so
> far.
> --
> Andreas
>
It is written in C using cc65.  Here are two code snippets:
-------------------------
static unsigned sslz_getcomp (int pos, register unsigned char len)
{
  register unsigned i2, j2; //register unsigned char k;
  static unsigned char k, n, o;//=0;
  static unsigned char comp, compa, bestcomp;
  bestcomp=(len<<3)+2;
  tmpcptr=&InBuffer[pos];
  i=5;
  if (len<=3) i=7;
  if (len<=2) i=7;
  j2=(len<=2?60:len<=3?600:7*1024);
  if (pos<j2) j2=pos;
  o=0;
  for (i2=1; i2<=j2; ++i2) {
     --tmpcptr;
     if (len>=4) {
        if (i2==1) {i+=3; k+=3;}
        if (i2==250) {i+=4; k+=3;}
        if (i2==1800) {i+=3; k+=3;}
     }
     j=i; n=0;
     for (e=0; e<len; ++e) {
        if (cin[e]==((unsigned char*)tmpcptr)[e]) {
           sslz_tocomp[e]=1;
           ++n;
           ++j;
        } else {
           sslz_tocomp[e]=0;
           j+=9;
        }
     }
     if (j<bestcomp && n>=2) {
        if (n>=2) o=1;
        bestcomp=j;
        //m=1;
        sslz_offs=i2-1;
        //memcpy (&sslz_best, &sslz_tocomp, sizeof(sslz_tocomp));
        __asm__ (
           "\tldx\t_buflen\n"
           "\tdex\n"
           "@aaa:\r\n"
           "\tlda\t_sslz_tocomp,x\n"
           "\tsta\t_sslz_best,x\n"
           "\tdex\n"
           "\tbpl\t@aaa\n"
           );
     }
  }
  sslz_comp=bestcomp;
  return o;
}
-------------------------
     j=0; y=&InBuffer[in+i];
     for (k=0; k<108 && j<108; /*++k*/) {
        if ((len!=2 && len!=3 && len<7) && j>=12) {j=108; break;}
        m=0;
        --y;
        if ((unsigned)y<(unsigned)&InBuffer) {k= 108; break;}
        if (cin[i]==*y) break;
        if (j>=0) {
           for (l=1;l<=j; ++l) {
              //if (InBuffer[in+i-l-1]==InBuffer[in+i-j-1]) {
              if (*y==y[l]) {
                 m=1; break;
              }
           }
        }
        if (m) {++j; continue;}
        ++j;
        ++k;
     }
xcomp:
     l2=in+i;
     if (k<108 && j<108) {
        po_offs[i]=k; //comp+=/*5-(k<4)*/(k<6?1:getnumbits(po_getnumlits(vz.InPos-buflen+i+1)));
        if (len!=2 && len!=3 && len<7) comp+=EstimDist(k,
po_getnumlits(in+i));
        else comp+=EstimDist (k, po_getnumlits2(l2));       }
     else {
        po_offs[i]=-1;
        if ((len!=2 && len!=3 && len<7)) x=po_writelit (l2, InBuffer[l2], &l);
        else x=po_writelit1a (in+i, InBuffer[in+i], &l);
        po_nl1[i]=x; po_nl2[i]=l;
        comp+=EstimDist (x, l)+1;
     }
  }
------------------------------

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)