From 337f29a79b1d109df7bed3ebdc28f79654cae491 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 1 Jul 2018 23:06:08 -0400 Subject: [PATCH] gr-sim: add shift and rotate support --- gr-sim/6502_emulate.c | 99 ++++++++++++++++++++++++++++++++++++++++++- gr-sim/6502_emulate.h | 5 +++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/gr-sim/6502_emulate.c b/gr-sim/6502_emulate.c index 565b31d2..616019cf 100644 --- a/gr-sim/6502_emulate.c +++ b/gr-sim/6502_emulate.c @@ -121,12 +121,109 @@ void lsr(void) { temp_a=a; temp_a&=0xff; - temp_a=temp_a>>1; + c=temp_a&0x1; + temp_a=temp_a>>1; a=(temp_a&0xff); + z=(a==0); + n=!!(a&0x80); // printf("LSR A=%x\n",a); } +void asl(void) { + int temp_a; + + temp_a=a; + temp_a&=0xff; + + c=!!(temp_a&0x80); + + temp_a=temp_a<<1; + a=(temp_a&0xff); + z=(a==0); + n=!!(a&0x80); +// printf("ASL A=%x\n",a); +} + + +void ror(void) { + int temp_a; + int old_c; + + old_c=c; + temp_a=a; + temp_a&=0xff; + + c=temp_a&0x1; + temp_a=temp_a>>1; + a=(temp_a&0xff); + a|=old_c<<7; + + z=(a==0); + n=!!(a&0x80); +// printf("ROR A=%x\n",a); +} + +void rol(void) { + int temp_a; + int old_c; + + old_c=c; + temp_a=a; + temp_a&=0xff; + + c=!!(temp_a&0x80); + + temp_a=temp_a<<1; + a=(temp_a&0xff); + a|=old_c; + + z=(a==0); + n=!!(a&0x80); +// printf("ROL A=%x\n",a); +} + + + +void ror_mem(int addr) { + int temp_a; + int old_c; + + old_c=c; + temp_a=ram[addr]; + temp_a&=0xff; + + c=temp_a&0x1; + temp_a=temp_a>>1; + ram[addr]=(temp_a&0xff); + ram[addr]|=old_c<<7; + + z=(ram[addr]==0); + n=!!(ram[addr]&0x80); +// printf("ROR %x=%x\n",addr,ram[addr]); +} + +void rol_mem(int addr) { + int temp_a; + int old_c; + + old_c=c; + temp_a=ram[addr]; + temp_a&=0xff; + + c=!!(temp_a&0x80); + + temp_a=temp_a<<1; + ram[addr]=(temp_a&0xff); + ram[addr]|=old_c; + + z=(ram[addr]==0); + n=!!(ram[addr]&0x80); +// printf("ROL %x=%x\n",addr,ram[addr]); +} + + + unsigned char high(int value) { return (value>>8)&0xff; } diff --git a/gr-sim/6502_emulate.h b/gr-sim/6502_emulate.h index fc67e629..cdf00854 100644 --- a/gr-sim/6502_emulate.h +++ b/gr-sim/6502_emulate.h @@ -12,6 +12,11 @@ void cmp(int value); void pha(void); void pla(void); void lsr(void); +void asl(void); +void ror(void); +void rol(void); +void ror_mem(int addr); +void rol_mem(int addr); unsigned char high(int value); unsigned char low(int value);