Commit 61dfd1f4 authored by Sergio Costas's avatar Sergio Costas

First changes to remove "byte" and "word" types, and use uint8_t and uint16_t

parent de4aa7fd
This diff is collapsed.
......@@ -18,146 +18,145 @@
*
*/
#ifndef Z80FREE_H
#define Z80FREE_H
#include <endian.h>
#include <stdbool.h>
#ifndef Z80_H
typedef unsigned short int word;
typedef unsigned char byte;
#endif
#include <stdint.h>
extern int Z80free_parityBit[256];
#define F_S 0x80
#define F_Z 0x40
#define F_5 0x20
#define F_H 0x10
#define F_3 0x08
#define F_PV 0x04
#define F_N 0x02
#define F_C 0x01
#define F_S 0x80
#define F_Z 0x40
#define F_5 0x20
#define F_H 0x10
#define F_3 0x08
#define F_PV 0x04
#define F_N 0x02
#define F_C 0x01
//enum Z80free_prefix {Z80XX, Z80CB, Z80DD, Z80ED, Z80FD};
// enum Z80free_prefix {Z80XX, Z80CB, Z80DD, Z80ED, Z80FD};
typedef union {
/** Word registers. */
struct
{
word AF, BC, DE, HL, IX, IY, SP;
struct {
uint16_t AF, BC, DE, HL, IX, IY, SP;
} wr;
/** Byte registers. SP can be accessed partially to simplify the load/save code. */
#if __BYTE_ORDER == __LITTLE_ENDIAN
struct
{
byte F,A, C,B, E,D, L,H, IXl,IXh, IYl,IYh, P,S;
struct {
uint8_t F, A, C, B, E, D, L, H, IXl, IXh, IYl, IYh, P, S;
} br;
#else
struct
{
byte A,F, B,C, D,E, H,L, IXh,IXl, IYh,IYl, S,P;
struct {
uint8_t A, F, B, C, D, E, H, L, IXh, IXl, IYh, IYl, S, P;
} br;
#endif
} Z80FRegs;
enum Z80Status {Z80XX, Z80CB, Z80DD, Z80ED, Z80FD, Z80INT};
enum Z80Status {
Z80XX,
Z80CB,
Z80DD,
Z80ED,
Z80FD,
Z80INT
};
/** A Z80 execution context. */
typedef struct
{
Z80FRegs Ra; /* Alternate register set (R) */
Z80FRegs Rm; /* Main register set (R) */
word PC; /* Program counter */
byte R; /* Refresh */
byte R2; /* Upper bit for Refresh */
byte I;
byte IFF1; /* Interrupt Flipflop 1. If it's 2, decrement it and don't allow INT */
byte IFF2; /* Interrupt Flipflop 2 */
byte IM; /* Interrupt mode */
byte HALT; /* HALT status */
byte INT_P; /* INT pending */
byte NMI_P; /* NMI pending */
byte empty_bus; /* value for empty bus when procesing a maskable int */
word IAddr; /* address with offset for IX+d and IY+d */
byte IAddr_done; /* if 1, IAddr contains a valid data */
enum Z80Status Status;
bool M1; /* true if the processor is in M1 state */
word subtstates; /* counts the number of tstates since the starting of the instruction */
typedef struct {
Z80FRegs Ra; /* Alternate register set (R) */
Z80FRegs Rm; /* Main register set (R) */
uint16_t PC; /* Program counter */
uint8_t R; /* Refresh */
uint8_t R2; /* Upper bit for Refresh */
uint8_t I;
uint8_t IFF1; /* Interrupt Flipflop 1. If it's 2, decrement it and don't allow INT */
uint8_t IFF2; /* Interrupt Flipflop 2 */
uint8_t IM; /* Interrupt mode */
uint8_t HALT; /* HALT status */
uint8_t INT_P; /* INT pending */
uint8_t NMI_P; /* NMI pending */
uint8_t empty_bus; /* value for empty bus when procesing a maskable int */
uint16_t IAddr; /* address with offset for IX+d and IY+d */
uint8_t IAddr_done; /* if 1, IAddr contains a valid data */
enum Z80Status Status;
bool M1; /* true if the processor is in M1 state */
uint16_t subtstates; /* counts the number of tstates since the starting of the instruction */
} Z80FREE;
/* internal Z80 methods */
void Z80free_setFlag(Z80FREE *processor, byte flag);
void Z80free_resFlag(Z80FREE *processor, byte flag);
void Z80free_valFlag(Z80FREE *processor, byte flag, int val);
int Z80free_getFlag(Z80FREE *processor, byte flag);
void Z80free_adjustFlags (Z80FREE *processor, byte val);
void Z80free_adjustFlagSZP (Z80FREE *processor, byte val);
void Z80free_adjustLogicFlag (Z80FREE *processor, int flagH);
byte Z80free_doArithmetic (Z80FREE *processor, byte value1,byte value2, int withCarry, int isSub);
word Z80free_doArithmetic16 (Z80FREE *processor, word value1,word value2, int withCarry, int isSub);
void Z80free_doAND (Z80FREE *processor, byte value);
void Z80free_doOR (Z80FREE *processor, byte value);
void Z80free_doXOR (Z80FREE *processor, byte value);
void Z80free_doBIT (Z80FREE *processor, int b, byte val);
byte Z80free_doSetRes (Z80FREE *processor, int bit, int pos, byte val);
byte Z80free_doIncDec (Z80FREE *processor, byte val, int isDec);
word Z80free_doIncDec16 (Z80FREE *processor, word val, int isDec);
byte Z80free_doRLC (Z80FREE *processor, int adjFlags, byte val);
byte Z80free_doRL (Z80FREE *processor, int adjFlags, byte val);
byte Z80free_doRRC (Z80FREE *processor, int adjFlags, byte val);
byte Z80free_doRR (Z80FREE *processor, int adjFlags, byte val);
byte Z80free_doSL (Z80FREE *processor, int isArith, byte val);
byte Z80free_doSR (Z80FREE *processor, int isArith, byte val);
void Z80free_doPush (Z80FREE *processor, word val);
word Z80free_doPop (Z80FREE *processor);
void Z80free_doDAA (Z80FREE *processor);
byte Z80free_readR(Z80FREE *processor);
void Z80free_setR(Z80FREE *processor,byte value);
byte Z80free_readI(Z80FREE *processor);
void Z80free_setFlag(Z80FREE *processor, uint8_t flag);
void Z80free_resFlag(Z80FREE *processor, uint8_t flag);
void Z80free_valFlag(Z80FREE *processor, uint8_t flag, int val);
int Z80free_getFlag(Z80FREE *processor, uint8_t flag);
void Z80free_adjustFlags(Z80FREE *processor, uint8_t val);
void Z80free_adjustFlagSZP(Z80FREE *processor, uint8_t val);
void Z80free_adjustLogicFlag(Z80FREE *processor, int flagH);
uint8_t Z80free_doArithmetic(Z80FREE *processor, uint8_t value1, uint8_t value2, int withCarry, int isSub);
uint16_t Z80free_doArithmetic16(Z80FREE *processor, uint16_t value1, uint16_t value2, int withCarry, int isSub);
void Z80free_doAND(Z80FREE *processor, uint8_t value);
void Z80free_doOR(Z80FREE *processor, uint8_t value);
void Z80free_doXOR(Z80FREE *processor, uint8_t value);
void Z80free_doBIT(Z80FREE *processor, int b, uint8_t val);
uint8_t Z80free_doSetRes(Z80FREE *processor, int bit, int pos, uint8_t val);
uint8_t Z80free_doIncDec(Z80FREE *processor, uint8_t val, int isDec);
uint16_t Z80free_doIncDec16(Z80FREE *processor, uint16_t val, int isDec);
uint8_t Z80free_doRLC(Z80FREE *processor, int adjFlags, uint8_t val);
uint8_t Z80free_doRL(Z80FREE *processor, int adjFlags, uint8_t val);
uint8_t Z80free_doRRC(Z80FREE *processor, int adjFlags, uint8_t val);
uint8_t Z80free_doRR(Z80FREE *processor, int adjFlags, uint8_t val);
uint8_t Z80free_doSL(Z80FREE *processor, int isArith, uint8_t val);
uint8_t Z80free_doSR(Z80FREE *processor, int isArith, uint8_t val);
void Z80free_doPush(Z80FREE *processor, uint16_t val);
uint16_t Z80free_doPop(Z80FREE *processor);
void Z80free_doDAA(Z80FREE *processor);
uint8_t Z80free_readR(Z80FREE *processor);
void Z80free_setR(Z80FREE *processor, uint8_t value);
uint8_t Z80free_readI(Z80FREE *processor);
void Z80free_doRRD(Z80FREE *processor);
void Z80free_doRLD(Z80FREE *processor);
void Z80free_jump_relative(Z80FREE *processor,byte relvar);
word Z80free_addr_relative(Z80FREE *processor,word address);
word Z80free_addr_relativeXDCB(Z80FREE *processor,word address,byte d1);
byte Z80free_read_param_8(Z80FREE *z80);
word Z80free_read_param_16(Z80FREE *z80);
word Z80free_read16 (Z80FREE *processor, word addr);
void Z80free_write16 (Z80FREE *processor, word addr,word val);
void Z80free_jump_relative(Z80FREE *processor, uint8_t relvar);
uint16_t Z80free_addr_relative(Z80FREE *processor, uint16_t address);
uint16_t Z80free_addr_relativeXDCB(Z80FREE *processor, uint16_t address, uint8_t d1);
uint8_t Z80free_read_param_8(Z80FREE *z80);
uint16_t Z80free_read_param_16(Z80FREE *z80);
uint16_t Z80free_read16(Z80FREE *processor, uint16_t addr);
void Z80free_write16(Z80FREE *processor, uint16_t addr, uint16_t val);
/* external Z80 methods */
void Z80free_reset(Z80FREE *);
int Z80free_step(Z80FREE *);
int Z80free_ustep(Z80FREE *);
void Z80free_INT(Z80FREE *,byte);
void Z80free_INT(Z80FREE *, uint8_t);
void Z80free_INTserved(Z80FREE *);
byte Z80free_Rd_Internal (Z80FREE *processor,word Addr);
void Z80free_Wr_Internal (Z80FREE *processor,word Addr, byte Value);
byte Z80free_In_Internal (Z80FREE *processor,word Port);
void Z80free_Out_Internal (Z80FREE *processor,word Port, byte Value);
uint8_t Z80free_Rd_Internal(Z80FREE *processor, uint16_t Addr);
void Z80free_Wr_Internal(Z80FREE *processor, uint16_t Addr, uint8_t Value);
uint8_t Z80free_In_Internal(Z80FREE *processor, uint16_t Port);
void Z80free_Out_Internal(Z80FREE *processor, uint16_t Port, uint8_t Value);
byte Z80free_Rd (word Addr);
void Z80free_Wr (word Addr, byte Value);
byte Z80free_In (word Port);
void Z80free_Out (word Port, byte Value);
uint8_t Z80free_Rd(uint16_t Addr);
void Z80free_Wr(uint16_t Addr, uint8_t Value);
uint8_t Z80free_In(uint16_t Port);
void Z80free_Out(uint16_t Port, uint8_t Value);
/* Opcode functions */
int Z80free_codes (Z80FREE *processor,byte opcode);
int Z80free_codesCB (Z80FREE *processor,byte opcode);
int Z80free_codesDD (Z80FREE *processor,byte opcode);
int Z80free_codesED (Z80FREE *processor,byte opcode);
int Z80free_codesFD (Z80FREE *processor,byte opcode);
int Z80free_codesDDCB (Z80FREE *processor,byte d1);
int Z80free_codesFDCB (Z80FREE *processor,byte d1);
int Z80free_codes(Z80FREE *processor, uint8_t opcode);
int Z80free_codesCB(Z80FREE *processor, uint8_t opcode);
int Z80free_codesDD(Z80FREE *processor, uint8_t opcode);
int Z80free_codesED(Z80FREE *processor, uint8_t opcode);
int Z80free_codesFD(Z80FREE *processor, uint8_t opcode);
int Z80free_codesDDCB(Z80FREE *processor, uint8_t d1);
int Z80free_codesFDCB(Z80FREE *processor, uint8_t d1);
#endif
This diff is collapsed.
......@@ -27,7 +27,7 @@ unsigned char memory[65536];
FILE *infile;
char test_name[20];
byte ports[256];
word portdirs[256];
uint16_t portdirs[256];
int portpos=0,elements=0;
#define NO35
......@@ -184,7 +184,7 @@ int read_inports() {
break;
}
retval=fscanf(infile,"%x",&value);
portdirs[elements]=(word)addr;
portdirs[elements]=(uint16_t)addr;
ports[elements]=(byte)value;
elements++;
}
......@@ -218,17 +218,17 @@ int read_test() {
return 0;
}
byte Z80free_Rd (word Addr) {
byte Z80free_Rd (uint16_t Addr) {
return ((byte)memory[Addr]);
}
void Z80free_Wr (word Addr, byte Value) {
void Z80free_Wr (uint16_t Addr, byte Value) {
memory[Addr]=(unsigned char) Value;
}
byte Z80free_In (word Port) {
byte Z80free_In (uint16_t Port) {
byte value;
......@@ -244,7 +244,7 @@ byte Z80free_In (word Port) {
return (value);
}
void Z80free_Out (word Port, byte Value) {
void Z80free_Out (uint16_t Port, byte Value) {
}
......
int read_elements(Z80FREE *emulador) {
int tstates,retval;
unsigned short int v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
int tstates, retval;
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);
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;
emulador->I = v1;
emulador->R = v2;
emulador->R2 = v2;
emulador->IFF1 = v3;
emulador->IFF2 = v4;
emulador->IM = v5;
emulador->HALT = v6;
return (tstates);
}
......@@ -30,49 +28,45 @@ int read_memory(char mode) {
// mode=0 : store value in memory
// mode=1 : compare value with memory
int position,retval,value;
int position, retval, value;
retval=fscanf(infile,"%x",&position);
if (position==-1) {
retval = fscanf(infile, "%x", &position);
if (position == -1) {
return -1;
}
do {
retval=fscanf(infile,"%x",&value);
if (value!=-1) {
retval = 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]= (byte) value;
memory[position] = (uint8_t) value;
}
position++;
}
} while(value!=-1);
} while (value != -1);
return 0;
}
int read_inports() {
int retval, value, addr;
portpos=0;
elements=0;
portpos = 0;
elements = 0;
while (1) {
retval=fscanf(infile,"%x",&addr);
if (addr==-1) {
retval = fscanf(infile, "%x", &addr);
if (addr == -1) {
break;
}
retval=fscanf(infile,"%x",&value);
portdirs[elements]=(word) addr;
ports[elements]=(byte) value;
retval = fscanf(infile, "%x", &value);
portdirs[elements] = (uint16_t) addr;
ports[elements] = (uint8_t) value;
elements++;
}
return 0;
}
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