From bb4a67e9d2320670b14e6376bcd309c888e394c0 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 12 Oct 2018 17:10:31 -0400 Subject: [PATCH] nibble_table: validating qkumba's DOS read nibble generation code --- gr-sim/6502_emulate.c | 75 +++++++++++++++++++++++++++++++++++++++++-- gr-sim/6502_emulate.h | 5 +++ gr-sim/dos/Makefile | 31 ++++++++++++++++++ gr-sim/dos/nibble.c | 50 +++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 gr-sim/dos/Makefile create mode 100644 gr-sim/dos/nibble.c diff --git a/gr-sim/6502_emulate.c b/gr-sim/6502_emulate.c index 612f3287..c67fb919 100644 --- a/gr-sim/6502_emulate.c +++ b/gr-sim/6502_emulate.c @@ -207,9 +207,9 @@ void lsr(void) { c=temp_a&0x1; temp_a=temp_a>>1; - a=(temp_a&0xff); + a=(temp_a&0x7f); // always shift 0 into top z=(a==0); - n=!!(a&0x80); + n=!!(a&0x80); // can this ever be 1? no? // printf("LSR A=%x\n",a); } @@ -362,6 +362,21 @@ void bit(int value) { } + /* a is not modified */ +void bit_mem(int addr) { + int temp_a; + + temp_a=a&ram[addr]; + temp_a&=0xff; + + z=(temp_a==0); + + n=(ram[addr]&0x80); + v=(ram[addr]&0x40); + +} + + void lda(int addr) { a=ram[addr]; @@ -441,6 +456,62 @@ void eor(int value) { } +void ora(int value) { + + int temp_a; + int temp_value; + int result; + + temp_a=a&0xff; + temp_value=value&0xff; + + result=(temp_a|temp_value); + + n=(result&0x80)>>7; + + a=result&0xff; + z=(a==0); + +} + +void ora_mem(int addr) { + + int temp_a; + int temp_value; + int result; + + temp_a=a&0xff; + temp_value=ram[addr]&0xff; + + result=(temp_a|temp_value); + + n=(result&0x80)>>7; + + a=result&0xff; + z=(a==0); + +} + +void and(int value) { + + int temp_a; + int temp_value; + int result; + + temp_a=a&0xff; + temp_value=value&0xff; + + result=(temp_a&temp_value); + + n=(result&0x80)>>7; + + a=result&0xff; + z=(a==0); + +} + + + unsigned char high(int value) { return (value>>8)&0xff; } diff --git a/gr-sim/6502_emulate.h b/gr-sim/6502_emulate.h index 4f116050..5fbd6253 100644 --- a/gr-sim/6502_emulate.h +++ b/gr-sim/6502_emulate.h @@ -8,7 +8,12 @@ unsigned short y_indirect(unsigned char base, unsigned char y); int init_6502(void); void adc(int value); void sbc(int value); +void and(int value); +void and_mem(int addr); +void ora(int value); +void ora_mem(int addr); void eor(int value); +void eor_mem(int addr); void cmp(int value); void cpy(int value); void cpx(int value); diff --git a/gr-sim/dos/Makefile b/gr-sim/dos/Makefile new file mode 100644 index 00000000..e27edd16 --- /dev/null +++ b/gr-sim/dos/Makefile @@ -0,0 +1,31 @@ +CC = gcc +CFLAGS = -Wall -O2 -I.. -g +LFLAGS = -lm + +SDL_LIBS= `sdl-config --libs` +SDL_INCLUDE= `sdl-config --cflags` +GR_SIM = ../gr-sim.a + +all: nibble + +#### + +nibble: nibble.o $(GR_SIM) + $(CC) $(LFLAGS) $(SDL_LIBS) -o nibble nibble.o $(GR_SIM) + +nibble.o: nibble.c + $(CC) $(CFLAGS) -c nibble.c + +#### + +nibble2: nibble2.o $(GR_SIM) + $(CC) $(LFLAGS) $(SDL_LIBS) -o nibble2 nibble2.o $(GR_SIM) + +nibble2.o: nibble2.c + $(CC) $(CFLAGS) -c nibble2.c + + +#### + +clean: + rm -f *~ *.o nibble nibble2 diff --git a/gr-sim/dos/nibble.c b/gr-sim/dos/nibble.c new file mode 100644 index 00000000..22645129 --- /dev/null +++ b/gr-sim/dos/nibble.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include + +#include "gr-sim.h" +#include "tfv_utils.h" +#include "tfv_zp.h" +#include "6502_emulate.h" + +int main(int argc, char **argv) { + + int yy; + + grsim_init(); + gr(); + + yy=0; + printf("****yy=%d\n",yy); + + y=yy; // ldy #0 + x=3; // ldx #3 +L1: + ram[0x3c]=x; // stx $3c + a=x; // txa + asl(); // asl + bit_mem(0x3c); // bit $3c + if (z==1) goto L3; // beq L3 + ora_mem(0x3c); // ora $3c + eor(0xff); // eor #$ff + and(0x7e); // and #$7e +L2: + if (c==1) goto L3; // bcs L3 + lsr(); // lsr + if (z==0) goto L2; // bne L2 + + a=y; // tya + printf("%x=%x\n",x,a); // sta nibtbl, x + y++; // iny +L3: + x++; // inx + if (!(x&0x80)) goto L1; // bpl L1 + + + + return 0; +} +