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,7 +1,7 @@
#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];
@ -19,14 +19,69 @@ static unsigned char input[MAX_INPUT];
#define A4H 0x43 #define A4H 0x43
static short s; static short s;
static int n,z,c,v;
void getsrc(void) { void adc(int value) {
int temp_a;
int temp_value;
int result;
temp_a=a&0xff;
temp_value=value&0xff;
result=(temp_a+temp_value+c);
c=(result&0x100)>>8;
n=(result&0x80)>>7;
v=!!((a^result)&(value^result)&0x80);
a=result&0xff;
z=(a==0);
}
void sbc(int value) {
int temp_a;
int result;
int temp_value;
temp_a=a&0xff;
temp_value=value&0xff;
result=temp_a-temp_value-(!c);
c=(result&0x100)>>8;
n=(result&0x80)>>7;
v=!!((a^result)&((255-value)^result)&0x80);
a=result&0xff;
z=(a==0);
}
void cmp(int value) {
int temp_a;
int temp_value;
temp_a=a&0xff;
temp_value=value&0xff;
temp_a=temp_a-temp_value;
c=(temp_a&0x100)>>8;
n=(temp_a&0x80)>>7;
z=(a==0);
}
static void getsrc(void) {
//getsrc: //getsrc:
a=ram[y_indirect(src,y)]; // lda (src), y a=ram[y_indirect(src,y)]; // lda (src), y
ram[src]++; //inc src ram[src]++; //inc src
if (ram[src]!=0) goto done_getsrc; //bne + if (ram[src]!=0) goto done_getsrc; //bne +
ram[src+1]++; //inc src+1 ram[src+1]++; //inc src+1
done_getsrc: ; done_getsrc: ;
printf("LOADED %02X%02X-1: %02X\n",ram[src+1],ram[src],a);
//+ rts //+ rts
} }
@ -44,29 +99,62 @@ static void pla(void) {
void buildcount(void) { void buildcount(void) {
int cnew,c;
//buildcount: //buildcount:
x=1; // ldx #1 x=1; // ldx #1
ram[count+1]=x; // stx count+1 ram[count+1]=x; // stx count+1
if (a!=0xf) goto done_buildcount; //cmp #$0f cmp(0xf); // cmp #$0f
//bne ++ if (z==0) goto done_buildcount; // bne ++
minus_buildcount: minus_buildcount:
ram[count]=a; //- sta count ram[count]=a; //- sta count
getsrc(); //jsr getsrc getsrc(); //jsr getsrc
x=a; //tax x=a; //tax
c=0; //clc c=0; //clc
cnew=(a+ram[count]+c)>0xff; adc(ram[count]); //adc count
a=a+ram[count]+c; //adc count if (c==0) goto skip_buildcount; // bcc +
if (cnew) goto skip_buildcount; // bcc +
ram[count+1]++; //inc count+1 ram[count+1]++; //inc count+1
skip_buildcount: skip_buildcount:
x++; //+ inx x++; //+ inx
x&=0xf; x&=0xff;
if (x==0) goto minus_buildcount; //beq - if (x==0) goto minus_buildcount; //beq -
done_buildcount: ; //++ rts done_buildcount: ; //++ rts
} }
static void putdst(void) {
printf("PUTADDR=%04X\n",y_indirect(dst,y));
// putdst:
ram[y_indirect(dst,y)]=a; // sta (dst), y
ram[dst]++; // inc dst
if (ram[dst]!=0) goto putdst_end; // bne +
ram[dst+1]++; // inc dst+1
putdst_end:;
//+ rts
printf("PUT: %02X%02X-1,%02X = %02X\n",ram[dst+1],ram[dst],y,a);
printf("0x8000 = %02X\n",ram[0x8000]);
}
static void getput(void) {
// getput:
getsrc(); // jsr getsrc
putdst(); // ; fallthrough
}
static void docopy(void) {
// docopy:
docopy_label:
getput(); // jsr getput
x--; // dex
if (x!=0) goto docopy_label; // bne docopy
ram[count+1]--; // dec count+1
if (ram[count+1]!=0) goto docopy_label; //bne docopy
//rts
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE *fff; FILE *fff;
@ -98,7 +186,7 @@ int main(int argc, char **argv) {
//oep = 0; //first unpacked byte to run, you must set this by yourself //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 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 paksize = size; //size of packed data, you must set this by yourself if hiunp=0
pakoff = 0x2000; pakoff = 0x2008; // 8 byte offset to data?
//LCBANK2 = $c083 //LCBANK2 = $c083
@ -117,7 +205,12 @@ int main(int argc, char **argv) {
a=(orgoff&0xff); //lda #<orgoff a=(orgoff&0xff); //lda #<orgoff
ram[dst]=a; // sta dst ram[dst]=a; // sta dst
unpack: //;unpacker entrypoint 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 goto unpmain; // jmp unpmain
unpmain: unpmain:
@ -126,79 +219,70 @@ unpmain:
parsetoken: parsetoken:
getsrc(); // jsr getsrc getsrc(); // jsr getsrc
pha(); // pha pha(); // pha
a<<=1; // lsr a>>=1; // lsr
a<<=1; // lsr a>>=1; // lsr
a<<=1; // lsr a>>=1; // lsr
a<<=1; // lsr a>>=1; // lsr
a&=0xff; a&=0xff;
if (a==0) goto copymatches; // beq copymatches if (a==0) goto copymatches; // beq copymatches
#if 0
jsr buildcount buildcount(); // jsr buildcount
tax x=a; // tax
jsr docopy docopy(); // jsr docopy
lda src a=ram[src]; // lda src
cmp end cmp(ram[end]); // cmp end
lda src+1 a=ram[src+1]; // lda src+1
sbc end+1 sbc(ram[end+1]); // sbc end+1
bcs done if (c) {
#endif 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: copymatches:
getsrc(); // jsr getsrc getsrc(); // jsr getsrc
#if 0 ram[delta]=a; // sta delta
sta delta getsrc(); // jsr getsrc
jsr getsrc ram[delta+1]=a; // sta delta+1
sta delta+1 pla(); // pla
pla a=a&0xf; // and #$0f
and #$0f buildcount(); // jsr buildcount
jsr buildcount c=0; // clc
clc adc(4); // adc #4
adc #4 x=a; // tax
tax if (c==0) goto copy_skip; // bcc +
bcc + ram[count+1]++; // inc count+1
inc count+1 copy_skip:
+ lda src+1 a=ram[src+1]; //+ lda src+1
pha pha(); // pha
lda src a=ram[src]; // lda src
pha pha(); // pha
sec c=1; // sec
lda dst a=ram[dst]; // lda dst
sbc delta sbc(ram[delta]); // sbc delta
sta src ram[src]=a; // sta src
lda dst+1 a=ram[dst+1]; // lda dst+1
sbc delta+1 sbc(ram[delta+1]); // sbc delta+1
sta src+1 ram[src+a]=a; // sta src+1
jsr docopy docopy(); // jsr docopy
pla pla(); // pla
sta src ram[src]=a; // sta src
pla pla(); // pla
sta src+1 ram[src+1]=a; // sta src+1
jmp parsetoken goto parsetoken; // jmp parsetoken
done done:
pla pla(); // pla
rts
docopy
jsr getput
dex
bne docopy
dec count+1
bne docopy
rts
int i;
for(i=0;i<256;i++) {
if (i%16==0) printf("\n%04X: ",0x8000+i);
printf("%02X ",ram[0x8000+i]);
}
getput printf("\n");
jsr getsrc // rts
putdst
sta (dst), y
inc dst
bne +
inc dst+1
+ rts
#endif
return 0; return 0;
} }