chiptune: found bug in lz4 code

This commit is contained in:
Vince Weaver 2018-02-20 23:18:28 -05:00
parent 0cb0911151
commit 0850eb63c1
2 changed files with 51 additions and 24 deletions

View File

@ -131,21 +131,21 @@ done_getsrc:
; buildcount ; buildcount
;============ ;============
buildcount: buildcount:
ldx #1 ldx #1 ; high count starts at 1
stx count+1 stx count+1 ; (loops at zero?)
cmp #$0f cmp #$0f ; if LITERAL_COUNT < 15, we are done
bne done_buildcount bne done_buildcount
minus_buildcount: buildcount_loop:
sta count sta count ; save LITERAL_COUNT (15)
jsr getsrc jsr getsrc ; get the next byte
tax tax ; put in X
clc clc
adc count adc count ; add new byte to old value
bcc skip_buildcount bcc bc_8bit_oflow ; if overflow, increment high byte
inc count+1 inc count+1
skip_buildcount: bc_8bit_oflow:
inx inx ; check if read value was 255
beq minus_buildcount beq buildcount_loop ; if it was, keep looping and adding
done_buildcount: done_buildcount:
rts rts
@ -168,14 +168,27 @@ putdst:
putdst_end: putdst_end:
rts rts
;================ ;=============================
; docopy ; docopy
;================ ;=============================
; copies ram[count+1]-1:X bytes
; from src to dst
docopy: docopy:
; working around bug in original code that would loop 256 too
; many times if incoming X was equal to 0
cpx #$0
bne docopy_loop
jsr getput jsr getput
dex dex
bne docopy bne docopy_hack
dec count+1
bne docopy docopy_loop:
jsr getput ; get/put byte
dex ; decrement count
bne docopy_loop ; if not zero, loop
docopy_hack:
dec count+1 ; if zero, decrement high byte
bne docopy_loop ; if not zero, loop
rts rts

View File

@ -39,22 +39,24 @@ void buildcount(void) {
ram[count+1]=x; // ?? // stx count+1 ram[count+1]=x; // ?? // stx count+1
cmp(0xf); // if 15, more complicated // cmp #$0f cmp(0xf); // if 15, more complicated // cmp #$0f
if (z==0) goto done_buildcount; // otherwise A is count // bne ++ if (z==0) goto done_buildcount; // otherwise A is count // bne ++
minus_buildcount: buildcount_loop:
ram[count]=a; //- sta count ram[count]=a; //- sta count
// printf("MBC "); // printf("MBC ");
printf("\tADDITIONAL BUILDCOUNT ");
getsrc(); //jsr getsrc getsrc(); //jsr getsrc
printf("\tADDITIONAL BUILDCOUNT 0x%x, adding 0x%x\n",a,ram[count]);
x=a; //tax x=a; //tax
c=0; //clc c=0; //clc
adc(ram[count]); //adc count adc(ram[count]); //adc count
printf("\tGOT 0x%x c=%d\n",a,c);
if (c==0) goto skip_buildcount; // bcc + if (c==0) goto skip_buildcount; // bcc +
ram[count+1]++; //inc count+1 ram[count+1]++; //inc count+1
skip_buildcount: skip_buildcount:
x++; //+ inx printf("\tUPDATED COUNT %02X%02X\n",ram[count+1],a);
if (x==0) goto minus_buildcount; //beq - x++; // check if x is 255 //+ inx
if (x==0) goto buildcount_loop; // if so, add in next byte //beq -
done_buildcount: ; //++ rts done_buildcount: ; //++ rts
printf("\tBUILDCOUNT= r[c+1]=%02X r[c]=%02X a=%02X x=%02X\n", printf("\tBUILDCOUNT= %02X%02X r[c+1]=%02X r[c]=%02X a=%02X x=%02X\n",
ram[count+1],ram[count],a,x); ram[count+1],a,ram[count+1],ram[count],a,x);
} }
@ -79,14 +81,26 @@ static void getput(void) {
putdst(); // ; fallthrough putdst(); // ; fallthrough
} }
// 202 -> 201 -> 100 -> 1FF
// 201 -> 100 -> 1FF
// 200 -> 2ff -> 2fe
// 1ff -> 1fe
static void docopy(void) { static void docopy(void) {
printf("\tDOCOPY ENTRY: %02X%02X\n",ram[count+1],x);
// docopy: // docopy:
if (x==0) {
getput();
x--;
goto dc_hack;
}
docopy_label: docopy_label:
printf("\tDOCOPY %02X%02X: ",ram[count+1]-1,x); printf("\tDOCOPY %02X%02X: ",ram[count+1],x);
getput(); // jsr getput getput(); // jsr getput
x--; // dex x--; // dex
if (x!=0) goto docopy_label; // bne docopy if (x!=0) goto docopy_label; // bne docopy
dc_hack:
ram[count+1]--; // dec count+1 ram[count+1]--; // dec count+1
if (ram[count+1]!=0) goto docopy_label; //bne docopy if (ram[count+1]!=0) goto docopy_label; //bne docopy
//rts //rts