gr-sim: working on l4d

This commit is contained in:
Vince Weaver 2018-02-14 13:03:32 -05:00
parent b3601c9f78
commit 65bfb2ba45

View File

@ -1,204 +1,288 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "gr-sim.h" #include "6502_emulate.h"
#define MAX_INPUT 65536 #define MAX_INPUT 65536
static unsigned char input[MAX_INPUT]; static unsigned char input[MAX_INPUT];
#define src 0x0 #define src 0x0
#define dst 0x2 #define dst 0x2
#define end 0x4 #define end 0x4
#define count 0x6 #define count 0x6
#define delta 0x8 #define delta 0x8
#define A1L 0x3c #define A1L 0x3c
#define A1H 0x3d #define A1H 0x3d
#define A2L 0x3e #define A2L 0x3e
#define A2H 0x3f #define A2H 0x3f
#define A4L 0x42 #define A4L 0x42
#define A4H 0x43 #define A4H 0x43
static short s; static short s;
static int n,z,c,v;
void getsrc(void) {
//getsrc: void adc(int value) {
a=ram[y_indirect(src,y)]; // lda (src), y
ram[src]++; //inc src int temp_a;
if (ram[src]!=0) goto done_getsrc; //bne + int temp_value;
ram[src+1]++; //inc src+1 int result;
done_getsrc: ;
//+ rts temp_a=a&0xff;
} temp_value=value&0xff;
static void pha(void) { result=(temp_a+temp_value+c);
s--; c=(result&0x100)>>8;
ram[s]=a; n=(result&0x80)>>7;
}
v=!!((a^result)&(value^result)&0x80);
static void pla(void) {
a=result&0xff;
a=ram[s]; z=(a==0);
s++;
} }
void buildcount(void) { void sbc(int value) {
int temp_a;
int cnew,c; int result;
int temp_value;
//buildcount:
x=1; // ldx #1 temp_a=a&0xff;
ram[count+1]=x; //stx count+1 temp_value=value&0xff;
if (a!=0xf) goto done_buildcount; //cmp #$0f
//bne ++ result=temp_a-temp_value-(!c);
minus_buildcount:
ram[count]=a; //- sta count c=(result&0x100)>>8;
getsrc(); //jsr getsrc n=(result&0x80)>>7;
x=a; //tax
c=0; //clc v=!!((a^result)&((255-value)^result)&0x80);
cnew=(a+ram[count]+c)>0xff;
a=a+ram[count]+c; //adc count a=result&0xff;
if (cnew) goto skip_buildcount; // bcc + z=(a==0);
ram[count+1]++; //inc count+1 }
skip_buildcount:
x++; //+ inx void cmp(int value) {
x&=0xf;
if (x==0) goto minus_buildcount; //beq - int temp_a;
done_buildcount: ; //++ rts int temp_value;
}
temp_a=a&0xff;
int main(int argc, char **argv) { temp_value=value&0xff;
temp_a=temp_a-temp_value;
FILE *fff; c=(temp_a&0x100)>>8;
int size; n=(temp_a&0x80)>>7;
short orgoff,paksize,pakoff; z=(a==0);
}
fff=fopen("../mockingboard/outi.raw.lz4","r");
if (fff==NULL) { static void getsrc(void) {
fprintf(stderr,"Error opening!\n"); //getsrc:
return -1; a=ram[y_indirect(src,y)]; // lda (src), y
} ram[src]++; //inc src
if (ram[src]!=0) goto done_getsrc; //bne +
size=fread(input,sizeof(unsigned char),MAX_INPUT,fff); ram[src+1]++; //inc src+1
printf("Read %d bytes\n",size); done_getsrc: ;
printf("LOADED %02X%02X-1: %02X\n",ram[src+1],ram[src],a);
fclose(fff); //+ rts
}
memcpy(&ram[0x2000],input,size);
static void pha(void) {
s=0x1ff;
s--;
//LZ4 data decompressor for Apple II ram[s]=a;
//Peter Ferrie (peter.ferrie@gmail.com) }
//init = 0 ;set to 1 if you know the values static void pla(void) {
//hiunp = 0 ;unpacker entirely in high memory
//hipak = 0 ;packed data entirely in high memory (requires hiunp) a=ram[s];
s++;
//oep = 0; //first unpacked byte to run, you must set this by yourself }
orgoff = 0x8000; //offset of first unpacked byte, you must set this by yourself
paksize = size; //size of packed data, you must set this by yourself if hiunp=0 void buildcount(void) {
pakoff = 0x2000;
//buildcount:
x=1; // ldx #1
//LCBANK2 = $c083 ram[count+1]=x; // stx count+1
//MOVE = $fe2c cmp(0xf); // cmp #$0f
if (z==0) goto done_buildcount; // bne ++
a=(pakoff&0xff); //lda #<pakoff ;packed data offset minus_buildcount:
ram[src]=a; //sta src ram[count]=a; //- sta count
a=(pakoff+paksize)&0xff;//lda #<(pakoff+paksize) ;packed data size getsrc(); //jsr getsrc
ram[end]=a; // sta end x=a; //tax
a=(pakoff>>8); //lda #>pakoff c=0; //clc
ram[src+1]=a; //sta src+1 adc(ram[count]); //adc count
a=(pakoff+paksize)>>8; //lda #>(pakoff+paksize) if (c==0) goto skip_buildcount; // bcc +
ram[end+1]=a; // sta end+1 ram[count+1]++; //inc count+1
a=(orgoff>>8); //lda #>orgoff ;original unpacked data offset skip_buildcount:
ram[dst+1]=a; //sta dst+1 x++; //+ inx
a=(orgoff&0xff); //lda #<orgoff x&=0xff;
ram[dst]=a; // sta dst if (x==0) goto minus_buildcount; //beq -
done_buildcount: ; //++ rts
unpack: //;unpacker entrypoint }
goto unpmain; // jmp unpmain
unpmain: static void putdst(void) {
y=0; //ldy #0 printf("PUTADDR=%04X\n",y_indirect(dst,y));
// putdst:
parsetoken: ram[y_indirect(dst,y)]=a; // sta (dst), y
getsrc(); // jsr getsrc ram[dst]++; // inc dst
pha(); // pha if (ram[dst]!=0) goto putdst_end; // bne +
a<<=1; // lsr ram[dst+1]++; // inc dst+1
a<<=1; // lsr putdst_end:;
a<<=1; // lsr //+ rts
a<<=1; // lsr printf("PUT: %02X%02X-1,%02X = %02X\n",ram[dst+1],ram[dst],y,a);
a&=0xff; printf("0x8000 = %02X\n",ram[0x8000]);
if (a==0) goto copymatches; //beq copymatches }
#if 0
jsr buildcount static void getput(void) {
tax // getput:
jsr docopy getsrc(); // jsr getsrc
lda src putdst(); // ; fallthrough
cmp end }
lda src+1
sbc end+1 static void docopy(void) {
bcs done // docopy:
#endif docopy_label:
copymatches: getput(); // jsr getput
getsrc(); //jsr getsrc x--; // dex
#if 0 if (x!=0) goto docopy_label; // bne docopy
sta delta ram[count+1]--; // dec count+1
jsr getsrc if (ram[count+1]!=0) goto docopy_label; //bne docopy
sta delta+1 //rts
pla }
and #$0f
jsr buildcount
clc
adc #4
tax
bcc +
inc count+1 int main(int argc, char **argv) {
+ lda src+1
pha FILE *fff;
lda src int size;
pha short orgoff,paksize,pakoff;
sec
lda dst fff=fopen("../mockingboard/outi.raw.lz4","r");
sbc delta if (fff==NULL) {
sta src fprintf(stderr,"Error opening!\n");
lda dst+1 return -1;
sbc delta+1 }
sta src+1
jsr docopy size=fread(input,sizeof(unsigned char),MAX_INPUT,fff);
pla printf("Read %d bytes\n",size);
sta src
pla fclose(fff);
sta src+1
jmp parsetoken memcpy(&ram[0x2000],input,size);
done s=0x1ff;
pla
rts //LZ4 data decompressor for Apple II
//Peter Ferrie (peter.ferrie@gmail.com)
docopy
jsr getput //init = 0 ;set to 1 if you know the values
dex //hiunp = 0 ;unpacker entirely in high memory
bne docopy //hipak = 0 ;packed data entirely in high memory (requires hiunp)
dec count+1
bne docopy //oep = 0; //first unpacked byte to run, you must set this by yourself
rts orgoff = 0x8000; //offset of first unpacked byte, you must set this by yourself
paksize = size; //size of packed data, you must set this by yourself if hiunp=0
pakoff = 0x2008; // 8 byte offset to data?
getput
jsr getsrc //LCBANK2 = $c083
//MOVE = $fe2c
putdst
sta (dst), y a=(pakoff&0xff); //lda #<pakoff ;packed data offset
inc dst ram[src]=a; //sta src
bne + a=(pakoff+paksize)&0xff;//lda #<(pakoff+paksize) ;packed data size
inc dst+1 ram[end]=a; // sta end
+ rts a=(pakoff>>8); //lda #>pakoff
ram[src+1]=a; //sta src+1
#endif a=(pakoff+paksize)>>8; //lda #>(pakoff+paksize)
ram[end+1]=a; // sta end+1
return 0; a=(orgoff>>8); //lda #>orgoff ;original unpacked data offset
} ram[dst+1]=a; //sta dst+1
a=(orgoff&0xff); //lda #<orgoff
ram[dst]=a; // sta dst
printf("packed addr: %02X%02X\n",ram[src+1],ram[src]);
printf("packed end : %02X%02X\n",ram[end+1],ram[end]);
printf("dest addr : %02X%02X\n",ram[dst+1],ram[dst]);
//unpack: //;unpacker entrypoint
goto unpmain; // jmp unpmain
unpmain:
y=0; //ldy #0
parsetoken:
getsrc(); // jsr getsrc
pha(); // pha
a>>=1; // lsr
a>>=1; // lsr
a>>=1; // lsr
a>>=1; // lsr
a&=0xff;
if (a==0) goto copymatches; // beq copymatches
buildcount(); // jsr buildcount
x=a; // tax
docopy(); // jsr docopy
a=ram[src]; // lda src
cmp(ram[end]); // cmp end
a=ram[src+1]; // lda src+1
sbc(ram[end+1]); // sbc end+1
if (c) {
printf("Done!\n");
printf("src : %02X%02X\n",ram[src+1],ram[src]);
printf("packed end : %02X%02X\n",ram[end+1],ram[end]);
goto done; // bcs done
}
copymatches:
getsrc(); // jsr getsrc
ram[delta]=a; // sta delta
getsrc(); // jsr getsrc
ram[delta+1]=a; // sta delta+1
pla(); // pla
a=a&0xf; // and #$0f
buildcount(); // jsr buildcount
c=0; // clc
adc(4); // adc #4
x=a; // tax
if (c==0) goto copy_skip; // bcc +
ram[count+1]++; // inc count+1
copy_skip:
a=ram[src+1]; //+ lda src+1
pha(); // pha
a=ram[src]; // lda src
pha(); // pha
c=1; // sec
a=ram[dst]; // lda dst
sbc(ram[delta]); // sbc delta
ram[src]=a; // sta src
a=ram[dst+1]; // lda dst+1
sbc(ram[delta+1]); // sbc delta+1
ram[src+a]=a; // sta src+1
docopy(); // jsr docopy
pla(); // pla
ram[src]=a; // sta src
pla(); // pla
ram[src+1]=a; // sta src+1
goto parsetoken; // jmp parsetoken
done:
pla(); // pla
int i;
for(i=0;i<256;i++) {
if (i%16==0) printf("\n%04X: ",0x8000+i);
printf("%02X ",ram[0x8000+i]);
}
printf("\n");
// rts
return 0;
}