From bf430d808a2f81e6c273ffb081a5c2877641ada2 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 14 Feb 2018 13:10:01 -0500 Subject: [PATCH] gr-sim: combine the 6502 emulation stuff --- gr-sim/6502_emulate.c | 82 +++++++++++++++++++++++++++++++++++++++++++ gr-sim/6502_emulate.h | 10 ++++++ gr-sim/l4d.c | 72 ++----------------------------------- 3 files changed, 94 insertions(+), 70 deletions(-) diff --git a/gr-sim/6502_emulate.c b/gr-sim/6502_emulate.c index 4e939dea..4d81b8a9 100644 --- a/gr-sim/6502_emulate.c +++ b/gr-sim/6502_emulate.c @@ -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++; +} diff --git a/gr-sim/6502_emulate.h b/gr-sim/6502_emulate.h index 04155bcc..321eb39f 100644 --- a/gr-sim/6502_emulate.h +++ b/gr-sim/6502_emulate.h @@ -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); + diff --git a/gr-sim/l4d.c b/gr-sim/l4d.c index 0aaa95c6..023c314a 100644 --- a/gr-sim/l4d.c +++ b/gr-sim/l4d.c @@ -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)