gr-sim: combine the 6502 emulation stuff

This commit is contained in:
Vince Weaver 2018-02-14 13:10:01 -05:00
parent 65bfb2ba45
commit bf430d808a
3 changed files with 94 additions and 70 deletions

View File

@ -10,6 +10,24 @@ unsigned char ram[RAMSIZE];
/* Registers */
unsigned char a,y,x;
unsigned short sp;
/* Flags */
unsigned int n,z,c,v;
int init_6502(void) {
a=0;
y=0;
x=0;
sp=0x1ff;
n=0; z=0; c=0; v=0;
return 0;
}
unsigned short y_indirect(unsigned char base, unsigned char y) {
@ -23,3 +41,67 @@ unsigned short y_indirect(unsigned char base, unsigned char y) {
}
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);
}
void pha(void) {
sp--;
ram[sp]=a;
}
void pla(void) {
a=ram[sp];
sp++;
}

View File

@ -1,4 +1,14 @@
#define RAMSIZE 128*1024
extern unsigned char ram[RAMSIZE];
extern unsigned char a,y,x;
extern unsigned short sp;
extern unsigned int n,z,c,v;
unsigned short y_indirect(unsigned char base, unsigned char y);
int init_6502(void);
void adc(int value);
void sbc(int value);
void cmp(int value);
void pha(void);
void pla(void);

View File

@ -18,62 +18,6 @@ static unsigned char input[MAX_INPUT];
#define A4L 0x42
#define A4H 0x43
static short s;
static int n,z,c,v;
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:
a=ram[y_indirect(src,y)]; // lda (src), y
@ -85,18 +29,6 @@ done_getsrc: ;
//+ rts
}
static void pha(void) {
s--;
ram[s]=a;
}
static void pla(void) {
a=ram[s];
s++;
}
void buildcount(void) {
//buildcount:
@ -161,6 +93,8 @@ int main(int argc, char **argv) {
int size;
short orgoff,paksize,pakoff;
init_6502();
fff=fopen("../mockingboard/outi.raw.lz4","r");
if (fff==NULL) {
fprintf(stderr,"Error opening!\n");
@ -174,8 +108,6 @@ int main(int argc, char **argv) {
memcpy(&ram[0x2000],input,size);
s=0x1ff;
//LZ4 data decompressor for Apple II
//Peter Ferrie (peter.ferrie@gmail.com)