dos33fsprogs/gr-sim/6502_test/6502_test.c

93 lines
1.9 KiB
C
Raw Normal View History

2018-02-14 18:57:58 +00:00
#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);
}
2018-02-14 19:09:54 +00:00
if (c==(((i-j-0)>>8)&0x1)) {
2018-02-14 18:57:58 +00:00
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);
}
2018-02-14 19:09:54 +00:00
if (c==(((i-j-1)>>8)&0x1)) {
2018-02-14 18:57:58 +00:00
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;
}