Skip to content

Commit

Permalink
libz80: update - resync build fixes note this is a fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Cox committed Jun 17, 2020
1 parent fc79125 commit dbb17ab
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion libz80/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ RRD computes correct value and sets flags appropriately
RLD computes correct value and sets flags appropriately
SRA preserves bit 7
Fix RLC m, RRC m, RL m, RR m. They were doing a "rotate immediate," in effect.
DEC ss and INC ss increment the proper regster, and preserve flags.
DEC ss and INC ss increment the proper register, and preserve flags.
ADD IX,rr and ADD IY,rr set the flags propelry
SBC HL,pp sets the flags properly
ADC HL,pp and ADD HL,pp set the flags properly
Expand Down
6 changes: 6 additions & 0 deletions libz80/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
libz80 - Z80 emulation library
===============================

The original one appears to be dead - at least nobody responded to the
emulatuon bug so this is a fork that actually gets 16bit math flags correct
in the corner cases where the standard version leaves Z incorrectly clear.



*© Gabriel Gambetta ([email protected]) 2000 - 2014*

*Version 2.1.1*
Expand Down
6 changes: 3 additions & 3 deletions libz80/codegen/mktables.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ struct Z80OpcodeTable* createTableTree(FILE* opcodes, FILE* table)
mainTable = calloc(1, sizeof(struct Z80OpcodeTable));
mainTable->name = strdup("");

fprintf(table, "static struct Z80OpcodeTable opcodes_main;\n");
fprintf(table, "static const struct Z80OpcodeTable opcodes_main;\n");

rewind(opcodes);

Expand Down Expand Up @@ -531,7 +531,7 @@ struct Z80OpcodeTable* createTableTree(FILE* opcodes, FILE* table)
current->entries[code].table = calloc(1, sizeof(struct Z80OpcodeTable));
current = current->entries[code].table;
current->name = strdup(tmp);
fprintf(table, "static struct Z80OpcodeTable opcodes_%s;\n", current->name);
fprintf(table, "static const struct Z80OpcodeTable opcodes_%s;\n", current->name);

printf("%s ", tmp);
}
Expand Down Expand Up @@ -627,7 +627,7 @@ void outputTable(struct Z80OpcodeTable* table, FILE* file)

printf("Outputting table %s...", table->name);

fprintf(file, "static struct Z80OpcodeTable opcodes_%s = { %d, {\n", table->name, table->opcode_offset);
fprintf(file, "static const struct Z80OpcodeTable opcodes_%s = { %d, {\n", table->name, table->opcode_offset);

for (i = 0, opc = table->entries; i < 256; i++, opc++)
{
Expand Down
32 changes: 16 additions & 16 deletions libz80/codegen/mktables.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(ADC|SBC|ADD|SUB) A,\((IX|IY)\+d\)
ctx->tstates += 5;
char displacement = read8(ctx, ctx->PC++);
signed char displacement = read8(ctx, ctx->PC++);
BR.A = doArithmetic(ctx, read8(ctx, WR.%2 + displacement), F1_%1, F2_%1);

(ADC|SBC|ADD|SUB) A,n
Expand All @@ -37,7 +37,7 @@ ADD (IX|IY),(SP|BC|DE|IX|IY)

(AND|XOR|OR) \((IX|IY)\+d\)
ctx->tstates += 5;
do%1(ctx, read8(ctx, WR.%2 + (char) read8(ctx, ctx->PC++)));
do%1(ctx, read8(ctx, WR.%2 + (signed char) read8(ctx, ctx->PC++)));

(AND|XOR|OR) (A|B|C|D|E|H|L|IXh|IXl|IYh|IYl)
do%1(ctx, BR.%2);
Expand All @@ -58,7 +58,7 @@ BIT ([0-7]),\(HL\)

BIT ([0-7]),\((IX|IY)\+d\)
ctx->tstates += 2;
ushort address = WR.%2 + (char) read8(ctx, ctx->PC++);
ushort address = WR.%2 + (signed char) read8(ctx, ctx->PC++);
doBIT_indexed(ctx, %1, address);

(SET|RES) ([0-7]),(A|B|C|D|E|H|L)
Expand All @@ -70,7 +70,7 @@ BIT ([0-7]),\((IX|IY)\+d\)

(SET|RES) ([0-7]),\((IX|IY)\+d\)
ctx->tstates += 2;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
write8(ctx, WR.%3 + off, doSetRes(ctx, SR_%1, %2, read8(ctx, WR.%3 + off)));


Expand Down Expand Up @@ -124,7 +124,7 @@ RET

DJNZ \(PC\+e\)
ctx->tstates += 1;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
BR.B--;
if (BR.B)
{
Expand Down Expand Up @@ -202,7 +202,7 @@ CP \(HL\)

CP \((IX|IY)\+d\)
ctx->tstates += 5;
char displacement = read8(ctx, ctx->PC++);
signed char displacement = read8(ctx, ctx->PC++);
byte val = read8(ctx, WR.%1 + displacement);
doArithmetic(ctx, val, 0, 1);
adjustFlags(ctx, val);
Expand Down Expand Up @@ -271,7 +271,7 @@ CPI

(INC|DEC) \((IX|IY)\+d\)
ctx->tstates += 6;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
byte value = read8(ctx, WR.%2 + off);
write8(ctx, WR.%2 + off, doIncDec(ctx, value, ID_%1));

Expand Down Expand Up @@ -364,11 +364,11 @@ LD \(HL\),n

LD \((IX|IY)\+d\),(A|B|C|D|E|H|L)
ctx->tstates += 5;
write8(ctx, WR.%1 + (char) read8(ctx, ctx->PC++), BR.%2);
write8(ctx, WR.%1 + (signed char) read8(ctx, ctx->PC++), BR.%2);

LD \((IX|IY)\+d\),n
ctx->tstates += 2;
char offset = read8(ctx, ctx->PC++);
signed char offset = read8(ctx, ctx->PC++);
byte n = read8(ctx, ctx->PC++);
write8(ctx, WR.%1 + offset, n);

Expand All @@ -392,7 +392,7 @@ LD (A|B|C|D|E|H|L),\(HL\)

LD (A|B|C|D|E|H|L),\((IX|IY)\+d\)
ctx->tstates += 5;
BR.%1 = read8(ctx, WR.%2 + (char) read8(ctx, ctx->PC++));
BR.%1 = read8(ctx, WR.%2 + (signed char) read8(ctx, ctx->PC++));

LD (A|B|C|D|E|H|L),\(nn\)
BR.%1 = read8(ctx, read16(ctx, ctx->PC));
Expand All @@ -403,25 +403,25 @@ LD (A|B|C|D|E|H|L|IXh|IXl|IYh|IYl),(A|B|C|D|E|H|L|IXh|IXl|IYh|IYl)

LD (A|B|C|D|E|H|L),(SL|SR)A \((IX|IY)\+d\)
ctx->tstates += 2;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
BR.%1 = do%2(ctx, read8(ctx, WR.%3 + off), 1);
write8(ctx, WR.%3 + off, BR.%1);

LD (A|B|C|D|E|H|L),(SL|SR)L \((IX|IY)\+d\)
ctx->tstates += 2;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
BR.%1 = do%2(ctx, read8(ctx, WR.%3 + off), 0);
write8(ctx, WR.%3 + off, BR.%1);

LD (A|B|C|D|E|H|L),(RL|RLC|RR|RRC) \((IX|IY)\+d\)
ctx->tstates += 2;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
BR.%1 = do%2(ctx, 1, read8(ctx, WR.%3 + off));
write8(ctx, WR.%3 + off, BR.%1);

LD (A|B|C|D|E|H|L),(SET|RES) ([0-7]),\((IX|IY)\+d\)
ctx->tstates += 2;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
BR.%1 = doSetRes(ctx, SR_%2, %3, read8(ctx, WR.%4 + off));
write8(ctx, WR.%4 + off, BR.%1);

Expand Down Expand Up @@ -573,7 +573,7 @@ PUSH (AF|BC|DE|HL|IX|IY)

(RLC|RRC|RL|RR) \((IX|IY)\+d\)
ctx->tstates += 2;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
write8(ctx, WR.%2 + off, do%1(ctx, 1, read8(ctx, WR.%2 + off)));

(RL|RR|RLC|RRC)A
Expand Down Expand Up @@ -610,7 +610,7 @@ RRD

(SL|SR)(L|A) \((IX|IY)\+d\)
ctx->tstates += 2;
char off = read8(ctx, ctx->PC++);
signed char off = read8(ctx, ctx->PC++);
write8(ctx, WR.%3 + off, do%1(ctx, read8(ctx, WR.%3 + off), IA_%2));

(SL|SR)(L|A) (A|B|C|D|E|H|L|IXh|IXl|IYh|IYl)
Expand Down
12 changes: 6 additions & 6 deletions libz80/z80.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ struct Z80OpcodeEntry
int operand_type;
char* format;

struct Z80OpcodeTable* table;
const struct Z80OpcodeTable* table;
};


struct Z80OpcodeTable
{
int opcode_offset;
struct Z80OpcodeEntry entries[256];
const struct Z80OpcodeEntry entries[256];
};


Expand Down Expand Up @@ -661,8 +661,8 @@ static void doDAA(Z80Context * ctx) {

static void do_execute(Z80Context* ctx)
{
struct Z80OpcodeTable* current = &opcodes_main;
struct Z80OpcodeEntry* entries = current->entries;
const struct Z80OpcodeTable* current = &opcodes_main;
const struct Z80OpcodeEntry* entries = current->entries;
Z80OpcodeFunc func;

byte opcode;
Expand Down Expand Up @@ -786,8 +786,8 @@ unsigned Z80ExecuteTStates(Z80Context* ctx, unsigned tstates)
void Z80Debug (Z80Context* ctx, char* dump, char* decode)
{
char tmp[20];
struct Z80OpcodeTable* current = &opcodes_main;
struct Z80OpcodeEntry* entries = current->entries;
const struct Z80OpcodeTable* current = &opcodes_main;
const struct Z80OpcodeEntry* entries = current->entries;
char* fmt;
byte opcode;
ushort parm;
Expand Down
2 changes: 1 addition & 1 deletion libz80/z80.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef union
ushort AF, BC, DE, HL, IX, IY, SP;
} wr;

/** Byte registers. Note that SP can't be accesed partially. */
/** Byte registers. Note that SP can't be accessed partially. */
struct
{
byte F, A, C, B, E, D, L, H, IXl, IXh, IYl, IYh;
Expand Down

0 comments on commit dbb17ab

Please sign in to comment.