mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-02-28 06:30:18 +00:00
gr-sim: add 6502 test harness
This commit is contained in:
parent
bf430d808a
commit
ecc4a5bb1c
92
gr-sim/6502_test.c
Normal file
92
gr-sim/6502_test.c
Normal file
@ -0,0 +1,92 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "6502_emulate.h"
|
||||
|
||||
|
||||
static void test_adc(void) {
|
||||
int i,j;
|
||||
|
||||
/* carry in 0 */
|
||||
for(i=0;i<256;i++) {
|
||||
for(j=0;j<256;j++) {
|
||||
c=0;
|
||||
a=i;
|
||||
adc(j);
|
||||
if (a!=((i+j)&0xff)) {
|
||||
printf("ADC: Error! %d+%d should be %d, not %d\n",i,j,i+j,a);
|
||||
}
|
||||
if (c!=(((i+j)>>8)&0x1)) {
|
||||
printf("ADC: Error! Carry should be %d, not %d\n",((i+j)>>8)&0x1,c);
|
||||
}
|
||||
if ((a==0) && (z!=1)) printf("ADC error, zflag wrong\n");
|
||||
if ((a!=0) && (z!=0)) printf("ADC error, zflag wrong\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* carry in 1 */
|
||||
for(i=0;i<256;i++) {
|
||||
for(j=0;j<256;j++) {
|
||||
c=1;
|
||||
a=i;
|
||||
adc(j);
|
||||
if (a!=((i+j+1)&0xff)) {
|
||||
printf("ADC: Error! %d+%d should be %d, not %d\n",i,j,i+j+1,a);
|
||||
}
|
||||
if (c!=(((i+j+1)>>8)&0x1)) {
|
||||
printf("ADC: Error! Carry should be %d, not %d\n",((i+j+1)>>8)&0x1,c);
|
||||
}
|
||||
if ((a==0) && (z!=1)) printf("ADC error, zflag wrong\n");
|
||||
if ((a!=0) && (z!=0)) printf("ADC error, zflag wrong\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_sbc(void) {
|
||||
int i,j;
|
||||
|
||||
/* carry in 1 */
|
||||
for(i=0;i<256;i++) {
|
||||
for(j=0;j<256;j++) {
|
||||
c=1;
|
||||
a=i;
|
||||
sbc(j);
|
||||
if (a!=((i-j-0)&0xff)) {
|
||||
printf("SBC: Error! %d-%d should be %d, not %d\n",i,j,i-j-0,a);
|
||||
}
|
||||
if (c!=(((i-j-0)>>8)&0x1)) {
|
||||
printf("SBC: Error! Carry should be %d, not %d\n",((i-j-0)>>8)&0x1,c);
|
||||
}
|
||||
if ((a==0) && (z!=1)) printf("SBC error, zflag wrong\n");
|
||||
if ((a!=0) && (z!=0)) printf("SBC error, zflag wrong\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* carry in 0 */
|
||||
for(i=0;i<256;i++) {
|
||||
for(j=0;j<256;j++) {
|
||||
c=0;
|
||||
a=i;
|
||||
sbc(j);
|
||||
if (a!=((i-j-1)&0xff)) {
|
||||
printf("SBC: Error! %d-%d should be %d, not %d\n",i,j,i-j-1,a);
|
||||
}
|
||||
if (c!=(((i-j-1)>>8)&0x1)) {
|
||||
printf("SBC: Error! Carry should be %d, not %d\n",((i-j-1)>>8)&0x1,c);
|
||||
}
|
||||
if ((a==0) && (z!=1)) printf("SBC error, zflag wrong\n");
|
||||
if ((a!=0) && (z!=0)) printf("SBC error, zflag wrong\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
test_adc();
|
||||
test_sbc();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
@ -7,7 +7,7 @@ SDL_INCLUDE= `sdl-config --cflags`
|
||||
|
||||
all: fade fixed_point rainbow sparkle starfield starfield_fixed kaleido \
|
||||
tfv mode7_demo text text_demo tfv_multiply rasterbars rasterbars_fixed \
|
||||
l4d
|
||||
l4d 6502_test
|
||||
|
||||
|
||||
#### Library
|
||||
@ -220,10 +220,17 @@ gr-sim.o: gr-sim.c gr-sim.h apple2_font.h
|
||||
6502_emulate.o: 6502_emulate.c 6502_emulate.h
|
||||
$(CC) $(CFLAGS) $(SDL_INCLUDE) -c 6502_emulate.c
|
||||
|
||||
6502_test: 6502_test.o 6502_emulate.o
|
||||
$(CC) $(LFLAGS) -o 6502_test 6502_test.o 6502_emulate.o
|
||||
|
||||
6502_test.o: 6502_test.c 6502_emulate.h
|
||||
$(CC) $(CFLAGS) -c 6502_test.c
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o gr-sim rainbow sparkle starfield starfield_fixed kaleido \
|
||||
tfv text mode7_demo fade fixed_point tfv_multiply \
|
||||
rasterbars rasterbars_fixed lookup_tables text_demo \
|
||||
l4d
|
||||
l4d 6502_test
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user