mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-08-15 08:27:41 +00:00
gr-sim: combine the 6502 emulation stuff
This commit is contained in:
@@ -10,6 +10,24 @@ unsigned char ram[RAMSIZE];
|
|||||||
|
|
||||||
/* Registers */
|
/* Registers */
|
||||||
unsigned char a,y,x;
|
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) {
|
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++;
|
||||||
|
}
|
||||||
|
@@ -1,4 +1,14 @@
|
|||||||
#define RAMSIZE 128*1024
|
#define RAMSIZE 128*1024
|
||||||
extern unsigned char ram[RAMSIZE];
|
extern unsigned char ram[RAMSIZE];
|
||||||
extern unsigned char a,y,x;
|
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);
|
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);
|
||||||
|
|
||||||
|
72
gr-sim/l4d.c
72
gr-sim/l4d.c
@@ -18,62 +18,6 @@ static unsigned char input[MAX_INPUT];
|
|||||||
#define A4L 0x42
|
#define A4L 0x42
|
||||||
#define A4H 0x43
|
#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) {
|
static void getsrc(void) {
|
||||||
//getsrc:
|
//getsrc:
|
||||||
a=ram[y_indirect(src,y)]; // lda (src), y
|
a=ram[y_indirect(src,y)]; // lda (src), y
|
||||||
@@ -85,18 +29,6 @@ done_getsrc: ;
|
|||||||
//+ rts
|
//+ rts
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pha(void) {
|
|
||||||
|
|
||||||
s--;
|
|
||||||
ram[s]=a;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pla(void) {
|
|
||||||
|
|
||||||
a=ram[s];
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void buildcount(void) {
|
void buildcount(void) {
|
||||||
|
|
||||||
//buildcount:
|
//buildcount:
|
||||||
@@ -161,6 +93,8 @@ int main(int argc, char **argv) {
|
|||||||
int size;
|
int size;
|
||||||
short orgoff,paksize,pakoff;
|
short orgoff,paksize,pakoff;
|
||||||
|
|
||||||
|
init_6502();
|
||||||
|
|
||||||
fff=fopen("../mockingboard/outi.raw.lz4","r");
|
fff=fopen("../mockingboard/outi.raw.lz4","r");
|
||||||
if (fff==NULL) {
|
if (fff==NULL) {
|
||||||
fprintf(stderr,"Error opening!\n");
|
fprintf(stderr,"Error opening!\n");
|
||||||
@@ -174,8 +108,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
memcpy(&ram[0x2000],input,size);
|
memcpy(&ram[0x2000],input,size);
|
||||||
|
|
||||||
s=0x1ff;
|
|
||||||
|
|
||||||
//LZ4 data decompressor for Apple II
|
//LZ4 data decompressor for Apple II
|
||||||
//Peter Ferrie (peter.ferrie@gmail.com)
|
//Peter Ferrie (peter.ferrie@gmail.com)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user