Commit d34d7028 authored by Sergio Costas's avatar Sergio Costas

Fixed z80free_tester.c

parent 1e2cd5d2
......@@ -4,7 +4,7 @@ CCo = gcc -O2 -Wall
all: z80free_tester
clean:
rm -f *.o
rm -f *.o z80free_tester
z80free_tester: z80free_tester.o Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o
$(CCo) -o z80free_tester z80free_tester.o Z80free.o Z80free_codes.o Z80free_codesCB.o Z80free_codesED.o Z80free_codesDD.o Z80free_codesFD.o Z80free_codesDDCB.o Z80free_codesFDCB.o
......
......@@ -21,125 +21,122 @@
#include "Z80free.h"
#include <stdio.h>
Z80FREE emulator,emulator2;
Z80FREE emulator, emulator2;
unsigned char memory[65536];
FILE *infile;
char test_name[20];
uint8_t ports[256];
uint16_t portdirs[256];
int portpos=0,elements=0;
FILE * infile;
char test_name[20];
uint8_t ports[256];
uint16_t portdirs[256];
int portpos = 0, elements = 0;
#define NO35
int compare_processors() {
if (emulator.Rm.br.A!=emulator2.Rm.br.A) {
printf("A should be %X but is %X\n",emulator2.Rm.br.A,emulator.Rm.br.A);
if (emulator.Rm.br.A != emulator2.Rm.br.A) {
printf("A should be %X but is %X\n", emulator2.Rm.br.A, emulator.Rm.br.A);
}
#ifdef NO35
if ((emulator.Rm.br.F|0x28)!=(emulator2.Rm.br.F|0x28)) {
printf("F should be %X but is %X\n",emulator2.Rm.br.F,emulator.Rm.br.F);
if ((emulator.Rm.br.F | 0x28) != (emulator2.Rm.br.F | 0x28)) {
printf("F should be %X but is %X\n", emulator2.Rm.br.F, emulator.Rm.br.F);
}
#else
if (emulator.Rm.br.F!=emulator2.Rm.br.F) {
printf("F should be %X but is %X\n",emulator2.Rm.br.F,emulator.Rm.br.F);
if (emulator.Rm.br.F != emulator2.Rm.br.F) {
printf("F should be %X but is %X\n", emulator2.Rm.br.F, emulator.Rm.br.F);
}
#endif
if (emulator.Rm.wr.BC!=emulator2.Rm.wr.BC) {
printf("BC should be %X but is %X\n",emulator2.Rm.wr.BC,emulator.Rm.wr.BC);
if (emulator.Rm.wr.BC != emulator2.Rm.wr.BC) {
printf("BC should be %X but is %X\n", emulator2.Rm.wr.BC, emulator.Rm.wr.BC);
}
if (emulator.Rm.wr.DE!=emulator2.Rm.wr.DE) {
printf("DE should be %X but is %X\n",emulator2.Rm.wr.DE,emulator.Rm.wr.DE);
if (emulator.Rm.wr.DE != emulator2.Rm.wr.DE) {
printf("DE should be %X but is %X\n", emulator2.Rm.wr.DE, emulator.Rm.wr.DE);
}
if (emulator.Rm.wr.HL!=emulator2.Rm.wr.HL) {
printf("HL should be %X but is %X\n",emulator2.Rm.wr.HL,emulator.Rm.wr.HL);
if (emulator.Rm.wr.HL != emulator2.Rm.wr.HL) {
printf("HL should be %X but is %X\n", emulator2.Rm.wr.HL, emulator.Rm.wr.HL);
}
if (emulator.Ra.br.A!=emulator2.Ra.br.A) {
printf("A' should be %X but is %X\n",emulator2.Ra.br.A,emulator.Ra.br.A);
if (emulator.Ra.br.A != emulator2.Ra.br.A) {
printf("A' should be %X but is %X\n", emulator2.Ra.br.A, emulator.Ra.br.A);
}
#ifdef NO35
if ((emulator.Ra.br.F|0x28)!=(emulator2.Ra.br.F|0x28)) {
printf("F' should be %X but is %X\n",emulator2.Ra.br.F,emulator.Ra.br.F);
if ((emulator.Ra.br.F | 0x28) != (emulator2.Ra.br.F | 0x28)) {
printf("F' should be %X but is %X\n", emulator2.Ra.br.F, emulator.Ra.br.F);
}
#else
if (emulator.Ra.br.F!=emulator2.Ra.br.F) {
printf("F' should be %X but is %X\n",emulator2.Ra.br.F,emulator.Ra.br.F);
if (emulator.Ra.br.F != emulator2.Ra.br.F) {
printf("F' should be %X but is %X\n", emulator2.Ra.br.F, emulator.Ra.br.F);
}
#endif
if (emulator.Ra.wr.BC!=emulator2.Ra.wr.BC) {
printf("BC' should be %X but is %X\n",emulator2.Ra.wr.BC,emulator.Ra.wr.BC);
if (emulator.Ra.wr.BC != emulator2.Ra.wr.BC) {
printf("BC' should be %X but is %X\n", emulator2.Ra.wr.BC, emulator.Ra.wr.BC);
}
if (emulator.Ra.wr.DE!=emulator2.Ra.wr.DE) {
printf("DE' should be %X but is %X\n",emulator2.Ra.wr.DE,emulator.Ra.wr.DE);
if (emulator.Ra.wr.DE != emulator2.Ra.wr.DE) {
printf("DE' should be %X but is %X\n", emulator2.Ra.wr.DE, emulator.Ra.wr.DE);
}
if (emulator.Ra.wr.HL!=emulator2.Ra.wr.HL) {
printf("HL' should be %X but is %X\n",emulator2.Ra.wr.HL,emulator.Ra.wr.HL);
if (emulator.Ra.wr.HL != emulator2.Ra.wr.HL) {
printf("HL' should be %X but is %X\n", emulator2.Ra.wr.HL, emulator.Ra.wr.HL);
}
if (emulator.Rm.wr.IX!=emulator2.Rm.wr.IX) {
printf("IX should be %X but is %X\n",emulator2.Rm.wr.IX,emulator.Rm.wr.IX);
if (emulator.Rm.wr.IX != emulator2.Rm.wr.IX) {
printf("IX should be %X but is %X\n", emulator2.Rm.wr.IX, emulator.Rm.wr.IX);
}
if (emulator.Rm.wr.IY!=emulator2.Rm.wr.IY) {
printf("IY should be %X but is %X\n",emulator2.Rm.wr.IY,emulator.Rm.wr.IY);
if (emulator.Rm.wr.IY != emulator2.Rm.wr.IY) {
printf("IY should be %X but is %X\n", emulator2.Rm.wr.IY, emulator.Rm.wr.IY);
}
if (emulator.PC!=emulator2.PC) {
printf("PC should be %X but is %X\n",emulator2.PC,emulator.PC);
if (emulator.PC != emulator2.PC) {
printf("PC should be %X but is %X\n", emulator2.PC, emulator.PC);
}
if (emulator.Rm.wr.SP!=emulator2.Rm.wr.SP) {
printf("SP should be %X but is %X\n",emulator2.Rm.wr.SP,emulator.Rm.wr.SP);
if (emulator.Rm.wr.SP != emulator2.Rm.wr.SP) {
printf("SP should be %X but is %X\n", emulator2.Rm.wr.SP, emulator.Rm.wr.SP);
}
if (emulator.HALT!=emulator2.HALT) {
printf("HALT should be %X but is %X\n",emulator2.HALT,emulator.HALT);
if (emulator.HALT != emulator2.HALT) {
printf("HALT should be %X but is %X\n", emulator2.HALT, emulator.HALT);
}
if (emulator.I!=emulator2.I) {
printf("I should be %X but is %X\n",emulator2.I,emulator.I);
if (emulator.I != emulator2.I) {
printf("I should be %X but is %X\n", emulator2.I, emulator.I);
}
if ((emulator.R&0x7F)!=(emulator2.R&0x7F)) {
printf("R should be %X but is %X\n",(emulator2.R&0x7F),(emulator.R&0x7F));
if ((emulator.R & 0x7F) != (emulator2.R & 0x7F)) {
printf("R should be %X but is %X\n", (emulator2.R & 0x7F), (emulator.R & 0x7F));
}
if (emulator.IM!=emulator2.IM) {
printf("IM should be %X but is %X\n",emulator2.IM,emulator.IM);
if (emulator.IM != emulator2.IM) {
printf("IM should be %X but is %X\n", emulator2.IM, emulator.IM);
}
if ((emulator.IFF1 == 1) != (emulator2.IFF1 == 1)) {
printf("IFF1 should be %X but is %X\n",emulator2.IFF1,emulator.IFF1);
printf("IFF1 should be %X but is %X\n", emulator2.IFF1, emulator.IFF1);
}
if (emulator.IFF2!=emulator2.IFF2) {
printf("IFF2 should be %X but is %X\n",emulator2.IFF2,emulator.IFF2);
if (emulator.IFF2 != emulator2.IFF2) {
printf("IFF2 should be %X but is %X\n", emulator2.IFF2, emulator.IFF2);
}
return 0;
}
int read_elements(Z80FREE *emulador) {
int tstates,retval;
unsigned short int v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
int tstates;
unsigned short int v1, v2, v3, v4, v5, v6, v7, v8, v9, v10;
Z80free_reset(emulador);
retval=fscanf(infile,"%hx %hx %hx %hx",(unsigned short int *)&emulador->Rm.wr.AF,(unsigned short int *)&emulador->Rm.wr.BC,(unsigned short int *)&emulador->Rm.wr.DE,(unsigned short int *)&emulador->Rm.wr.HL);
retval=fscanf(infile,"%hx %hx %hx %hx",&v7,&v8,&v9,&v10);
emulador->Ra.wr.AF=v7;
emulador->Ra.wr.BC=v8;
emulador->Ra.wr.DE=v9;
emulador->Ra.wr.HL=v10;
retval=fscanf(infile,"%hx %hx %hx %hx",(unsigned short int *)&emulador->Rm.wr.IX,(unsigned short int *)&emulador->Rm.wr.IY,(unsigned short int *)&emulador->Rm.wr.SP,(unsigned short int *)&emulador->PC);
retval=fscanf(infile,"%hx %hx %hx %hx %hx %hx %d",&v1,&v2,&v3,&v4,&v5,&v6,&tstates);
emulador->I=v1;
emulador->R=v2;
emulador->R2=v2;
emulador->IFF1=v3;
emulador->IFF2=v4;
emulador->IM=v5;
emulador->HALT=v6;
fscanf(infile, "%hx %hx %hx %hx", (unsigned short int *) &emulador->Rm.wr.AF, (unsigned short int *) &emulador->Rm.wr.BC, (unsigned short int *) &emulador->Rm.wr.DE, (unsigned short int *) &emulador->Rm.wr.HL);
fscanf(infile, "%hx %hx %hx %hx", &v7, &v8, &v9, &v10);
emulador->Ra.wr.AF = v7;
emulador->Ra.wr.BC = v8;
emulador->Ra.wr.DE = v9;
emulador->Ra.wr.HL = v10;
fscanf(infile, "%hx %hx %hx %hx", (unsigned short int *) &emulador->Rm.wr.IX, (unsigned short int *) &emulador->Rm.wr.IY, (unsigned short int *) &emulador->Rm.wr.SP, (unsigned short int *) &emulador->PC);
fscanf(infile, "%hx %hx %hx %hx %hx %hx %d", &v1, &v2, &v3, &v4, &v5, &v6, &tstates);
emulador->I = v1;
emulador->R = v2;
emulador->R2 = v2;
emulador->IFF1 = v3;
emulador->IFF2 = v4;
emulador->IM = v5;
emulador->HALT = v6;
return (tstates);
}
......@@ -148,110 +145,104 @@ int read_memory(char mode) {
// mode=0 : store value in memory
// mode=1 : compare value with memory
int position,retval,value;
int position, value;
retval=fscanf(infile,"%x",&position);
if (position==-1) {
fscanf(infile, "%x", &position);
if (position == -1) {
return -1;
}
do {
retval=fscanf(infile,"%x",&value);
if (value!=-1) {
fscanf(infile, "%x", &value);
if (value != -1) {
if (mode) {
if (memory[position]!=value) {
printf("Error in memory, address %X. Expected value: %X, current value: %X\n",position,value,memory[position]);
if (memory[position] != value) {
printf("Error in memory, address %X. Expected value: %X, current value: %X\n", position, value, memory[position]);
}
} else {
memory[position]=(uint8_t)value;
memory[position] = (uint8_t) value;
}
position++;
}
} while(value!=-1);
} while (value != -1);
return 0;
}
int read_inports() {
int addr, value;
int addr,value,retval;
portpos=0;
elements=0;
portpos = 0;
elements = 0;
while (1) {
retval=fscanf(infile,"%x",&addr);
if (addr==-1) {
fscanf(infile, "%x", &addr);
if (addr == -1) {
break;
}
retval=fscanf(infile,"%x",&value);
portdirs[elements]=(uint16_t)addr;
ports[elements]=(uint8_t)value;
fscanf(infile, "%x", &value);
portdirs[elements] = (uint16_t) addr;
ports[elements] = (uint8_t) value;
elements++;
}
return 0;
}
int read_test() {
int retval, tstates, tst2, totaltst;
int retval,tstates,tst2,totaltst;
retval=fscanf(infile,"%s",test_name);
if (retval<=0) {
retval = fscanf(infile, "%s", test_name);
if (retval <= 0) {
return -1;
}
printf("Test %s\n",test_name);
tstates=read_elements(&emulator);
while(0==read_memory(0)) {
printf("Test %s\n", test_name);
tstates = read_elements(&emulator);
while (0 == read_memory(0)) {
}
read_inports();
totaltst=0;
while(totaltst<tstates) {
totaltst+=Z80free_step(&emulator);
totaltst = 0;
while (totaltst < tstates) {
totaltst += Z80free_step(&emulator);
}
tst2=read_elements(&emulator2);
tst2 = read_elements(&emulator2);
compare_processors();
if (totaltst!=tst2) {
printf("Test needed %d tstates, but should needed %d\n",totaltst,tst2);
if (totaltst != tst2) {
printf("Test needed %d tstates, but should needed %d\n", totaltst, tst2);
}
while(0==read_memory(1)) {
while (0 == read_memory(1)) {
}
return 0;
}
uint8_t Z80free_Rd (uint16_t Addr) {
return ((uint8_t)memory[Addr]);
uint8_t Z80free_Rd(uint16_t Addr) {
return ((uint8_t) memory[Addr]);
}
void Z80free_Wr (uint16_t Addr, uint8_t Value) {
memory[Addr]=(unsigned char) Value;
void Z80free_Wr(uint16_t Addr, uint8_t Value) {
memory[Addr] = (unsigned char) Value;
}
uint8_t Z80free_In (uint16_t Port) {
uint8_t Z80free_In(uint16_t Port) {
uint8_t value;
if (portpos>=elements) {
if (portpos >= elements) {
printf("IN beyond values\n");
return 0;
}
if (Port!=portdirs[portpos])
printf("IN to port %X (should be %X)\n",Port,portdirs[portpos]);
value=ports[portpos];
if (Port != portdirs[portpos]) {
printf("IN to port %X (should be %X)\n", Port, portdirs[portpos]);
}
value = ports[portpos];
portpos++;
return (value);
}
void Z80free_Out (uint16_t Port, uint8_t Value) {
void Z80free_Out(uint16_t Port, uint8_t Value) {
}
int main() {
infile=fopen("tests.z80free","r");
while(0==read_test()) {
infile = fopen("tests.z80free", "r");
while (0 == read_test()) {
}
return 0;
......
File mode changed from 100644 to 100755
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment