Commit 4d2aeefc authored by Sergio Costas's avatar Sergio Costas

Passed uncrustify to the generated code, to have a template to modify the generator

parent 62092dc5
......@@ -14,1228 +14,1702 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#include "Z80free.h"
int Z80free_codes (Z80FREE *processor,uint8_t opcode) {
static uint8_t tmp1;
int Z80free_codes(Z80FREE *processor, uint8_t opcode) {
static uint8_t tmp1;
static uint16_t tmp2;
switch(opcode) {
switch (opcode) {
case 0: // NOP
return (4);
break;
break;
case 1: // LD BC,nn
processor->Rm.wr.BC=Z80free_read_param_16(processor);
processor->Rm.wr.BC = Z80free_read_param_16(processor);
return (10);
break;
break;
case 2: // LD (BC),A
Z80free_Wr_Internal(processor,processor->Rm.wr.BC,processor->Rm.br.A);
Z80free_Wr_Internal(processor, processor->Rm.wr.BC, processor->Rm.br.A);
return (7);
break;
break;
case 3: // INC BC
processor->Rm.wr.BC=Z80free_doIncDec16(processor,processor->Rm.wr.BC,0);
processor->Rm.wr.BC = Z80free_doIncDec16(processor, processor->Rm.wr.BC, 0);
return (6);
break;
break;
case 4: // INC B
processor->Rm.br.B=Z80free_doIncDec(processor,processor->Rm.br.B,0);
processor->Rm.br.B = Z80free_doIncDec(processor, processor->Rm.br.B, 0);
return (4);
break;
break;
case 5: // DEC B
processor->Rm.br.B=Z80free_doIncDec(processor,processor->Rm.br.B,1);
processor->Rm.br.B = Z80free_doIncDec(processor, processor->Rm.br.B, 1);
return (4);
break;
break;
case 6: // LD B,n
processor->Rm.br.B=Z80free_read_param_8(processor);
processor->Rm.br.B = Z80free_read_param_8(processor);
return (7);
break;
break;
case 7: // RLCA
processor->Rm.br.A=Z80free_doRLC(processor,0,processor->Rm.br.A);
processor->Rm.br.A = Z80free_doRLC(processor, 0, processor->Rm.br.A);
return (4);
break;
break;
case 8: // EX AF,AF'
tmp2=processor->Rm.wr.AF;
processor->Rm.wr.AF=processor->Ra.wr.AF;
processor->Ra.wr.AF=tmp2;
tmp2 = processor->Rm.wr.AF;
processor->Rm.wr.AF = processor->Ra.wr.AF;
processor->Ra.wr.AF = tmp2;
return (4);
break;
break;
case 9: // ADD HL,BC
processor->Rm.wr.HL=Z80free_doArithmetic16(processor,processor->Rm.wr.HL,processor->Rm.wr.BC,0,0);
processor->Rm.wr.HL = Z80free_doArithmetic16(processor, processor->Rm.wr.HL, processor->Rm.wr.BC, 0, 0);
return (11);
break;
break;
case 10: // LD A,(BC)
processor->Rm.br.A=Z80free_Rd_Internal(processor,processor->Rm.wr.BC);
processor->Rm.br.A = Z80free_Rd_Internal(processor, processor->Rm.wr.BC);
return (7);
break;
break;
case 11: // DEC BC
processor->Rm.wr.BC=Z80free_doIncDec16(processor,processor->Rm.wr.BC,1);
processor->Rm.wr.BC = Z80free_doIncDec16(processor, processor->Rm.wr.BC, 1);
return (6);
break;
break;
case 12: // INC C
processor->Rm.br.C=Z80free_doIncDec(processor,processor->Rm.br.C,0);
processor->Rm.br.C = Z80free_doIncDec(processor, processor->Rm.br.C, 0);
return (4);
break;
break;
case 13: // DEC C
processor->Rm.br.C=Z80free_doIncDec(processor,processor->Rm.br.C,1);
processor->Rm.br.C = Z80free_doIncDec(processor, processor->Rm.br.C, 1);
return (4);
break;
break;
case 14: // LD C,n
processor->Rm.br.C=Z80free_read_param_8(processor);
processor->Rm.br.C = Z80free_read_param_8(processor);
return (7);
break;
break;
case 15: // RRCA
processor->Rm.br.A=Z80free_doRRC(processor,0,processor->Rm.br.A);
processor->Rm.br.A = Z80free_doRRC(processor, 0, processor->Rm.br.A);
return (4);
break;
break;
case 16: // DJNZ n
tmp1=Z80free_read_param_8(processor);
tmp1 = Z80free_read_param_8(processor);
processor->Rm.br.B--;
if (processor->Rm.br.B) {
Z80free_jump_relative(processor,tmp1);
Z80free_jump_relative(processor, tmp1);
return (13);
} else {
return (8);
}
break;
break;
case 17: // LD DE,nn
processor->Rm.wr.DE=Z80free_read_param_16(processor);
processor->Rm.wr.DE = Z80free_read_param_16(processor);
return (10);
break;
break;
case 18: // LD (DE),A
Z80free_Wr_Internal(processor,processor->Rm.wr.DE,processor->Rm.br.A);
Z80free_Wr_Internal(processor, processor->Rm.wr.DE, processor->Rm.br.A);
return (7);
break;
break;
case 19: // INC DE
processor->Rm.wr.DE=Z80free_doIncDec16(processor,processor->Rm.wr.DE,0);
processor->Rm.wr.DE = Z80free_doIncDec16(processor, processor->Rm.wr.DE, 0);
return (6);
break;
break;
case 20: // INC D
processor->Rm.br.D=Z80free_doIncDec(processor,processor->Rm.br.D,0);
processor->Rm.br.D = Z80free_doIncDec(processor, processor->Rm.br.D, 0);
return (4);
break;
break;
case 21: // DEC D
processor->Rm.br.D=Z80free_doIncDec(processor,processor->Rm.br.D,1);
processor->Rm.br.D = Z80free_doIncDec(processor, processor->Rm.br.D, 1);
return (4);
break;
break;
case 22: // LD D,n
processor->Rm.br.D=Z80free_read_param_8(processor);
processor->Rm.br.D = Z80free_read_param_8(processor);
return (7);
break;
break;
case 23: // RLA
processor->Rm.br.A=Z80free_doRL(processor,0,processor->Rm.br.A);
processor->Rm.br.A = Z80free_doRL(processor, 0, processor->Rm.br.A);
return (4);
break;
break;
case 24: // JR n
tmp1=Z80free_read_param_8(processor);
Z80free_jump_relative(processor,tmp1);
tmp1 = Z80free_read_param_8(processor);
Z80free_jump_relative(processor, tmp1);
return (12);
break;
break;
case 25: // ADD HL,DE
processor->Rm.wr.HL=Z80free_doArithmetic16(processor,processor->Rm.wr.HL,processor->Rm.wr.DE,0,0);
processor->Rm.wr.HL = Z80free_doArithmetic16(processor, processor->Rm.wr.HL, processor->Rm.wr.DE, 0, 0);
return (11);
break;
break;
case 26: // LD A,(DE)
processor->Rm.br.A=Z80free_Rd_Internal(processor,processor->Rm.wr.DE);
processor->Rm.br.A = Z80free_Rd_Internal(processor, processor->Rm.wr.DE);
return (7);
break;
break;
case 27: // DEC DE
processor->Rm.wr.DE=Z80free_doIncDec16(processor,processor->Rm.wr.DE,1);
processor->Rm.wr.DE = Z80free_doIncDec16(processor, processor->Rm.wr.DE, 1);
return (6);
break;
break;
case 28: // INC E
processor->Rm.br.E=Z80free_doIncDec(processor,processor->Rm.br.E,0);
processor->Rm.br.E = Z80free_doIncDec(processor, processor->Rm.br.E, 0);
return (4);
break;
break;
case 29: // DEC E
processor->Rm.br.E=Z80free_doIncDec(processor,processor->Rm.br.E,1);
processor->Rm.br.E = Z80free_doIncDec(processor, processor->Rm.br.E, 1);
return (4);
break;
break;
case 30: // LD E,n
processor->Rm.br.E=Z80free_read_param_8(processor);
processor->Rm.br.E = Z80free_read_param_8(processor);
return (7);
break;
break;
case 31: // RRA
processor->Rm.br.A=Z80free_doRR(processor,0,processor->Rm.br.A);
processor->Rm.br.A = Z80free_doRR(processor, 0, processor->Rm.br.A);
return (4);
break;
break;
case 32: // JR NZ,n
tmp1=Z80free_read_param_8(processor);
if (0==(F_Z&processor->Rm.br.F)) {
Z80free_jump_relative(processor,tmp1);
tmp1 = Z80free_read_param_8(processor);
if (0 == (F_Z & processor->Rm.br.F)) {
Z80free_jump_relative(processor, tmp1);
return (12);
} else {
return (7);
}
break;
break;
case 33: // LD HL,nn
processor->Rm.wr.HL=Z80free_read_param_16(processor);
processor->Rm.wr.HL = Z80free_read_param_16(processor);
return (10);
break;
break;
case 34: // LD (nn),HL
Z80free_write16(processor, Z80free_read_param_16(processor),processor->Rm.wr.HL);
Z80free_write16(processor, Z80free_read_param_16(processor), processor->Rm.wr.HL);
return (16);
break;
break;
case 35: // INC HL
processor->Rm.wr.HL=Z80free_doIncDec16(processor,processor->Rm.wr.HL,0);
processor->Rm.wr.HL = Z80free_doIncDec16(processor, processor->Rm.wr.HL, 0);
return (6);
break;
break;
case 36: // INC H
processor->Rm.br.H=Z80free_doIncDec(processor,processor->Rm.br.H,0);
processor->Rm.br.H = Z80free_doIncDec(processor, processor->Rm.br.H, 0);
return (4);
break;
break;
case 37: // DEC H
processor->Rm.br.H=Z80free_doIncDec(processor,processor->Rm.br.H,1);
processor->Rm.br.H = Z80free_doIncDec(processor, processor->Rm.br.H, 1);
return (4);
break;
break;
case 38: // LD H,n
processor->Rm.br.H=Z80free_read_param_8(processor);
processor->Rm.br.H = Z80free_read_param_8(processor);
return (7);
break;
break;
case 39: // DAA
Z80free_doDAA(processor);
return (4);
break;
break;
case 40: // JR Z,n
tmp1=Z80free_read_param_8(processor);
if (F_Z&processor->Rm.br.F) {
Z80free_jump_relative(processor,tmp1);
tmp1 = Z80free_read_param_8(processor);
if (F_Z & processor->Rm.br.F) {
Z80free_jump_relative(processor, tmp1);
return (12);
} else {
return (7);
}
break;
break;
case 41: // ADD HL,HL
processor->Rm.wr.HL=Z80free_doArithmetic16(processor,processor->Rm.wr.HL,processor->Rm.wr.HL,0,0);
processor->Rm.wr.HL = Z80free_doArithmetic16(processor, processor->Rm.wr.HL, processor->Rm.wr.HL, 0, 0);
return (11);
break;
break;
case 42: // LD HL,(nn)
processor->Rm.wr.HL=Z80free_read16(processor, Z80free_read_param_16(processor));
processor->Rm.wr.HL = Z80free_read16(processor, Z80free_read_param_16(processor));
return (16);
break;
break;
case 43: // DEC HL
processor->Rm.wr.HL=Z80free_doIncDec16(processor,processor->Rm.wr.HL,1);
processor->Rm.wr.HL = Z80free_doIncDec16(processor, processor->Rm.wr.HL, 1);
return (6);
break;
break;
case 44: // INC L
processor->Rm.br.L=Z80free_doIncDec(processor,processor->Rm.br.L,0);
processor->Rm.br.L = Z80free_doIncDec(processor, processor->Rm.br.L, 0);
return (4);
break;
break;
case 45: // DEC L
processor->Rm.br.L=Z80free_doIncDec(processor,processor->Rm.br.L,1);
processor->Rm.br.L = Z80free_doIncDec(processor, processor->Rm.br.L, 1);
return (4);
break;
break;
case 46: // LD L,n
processor->Rm.br.L=Z80free_read_param_8(processor);
processor->Rm.br.L = Z80free_read_param_8(processor);
return (7);
break;
break;
case 47: // CPL
processor->Rm.br.A=255-processor->Rm.br.A;
Z80free_adjustFlags(processor,processor->Rm.br.A);
Z80free_setFlag(processor,F_H);
Z80free_setFlag(processor,F_N);
processor->Rm.br.A = 255 - processor->Rm.br.A;
Z80free_adjustFlags(processor, processor->Rm.br.A);
Z80free_setFlag(processor, F_H);
Z80free_setFlag(processor, F_N);
return (4);
break;
break;
case 48: // JR NC,n
tmp1=Z80free_read_param_8(processor);
if (0==(F_C&processor->Rm.br.F)) {
Z80free_jump_relative(processor,tmp1);
tmp1 = Z80free_read_param_8(processor);
if (0 == (F_C & processor->Rm.br.F)) {
Z80free_jump_relative(processor, tmp1);
return (12);
} else {
return (7);
}
break;
break;
case 49: // LD SP,nn
processor->Rm.wr.SP=Z80free_read_param_16(processor);
processor->Rm.wr.SP = Z80free_read_param_16(processor);
return (10);
break;
break;
case 50: // LD (nn),A
Z80free_Wr_Internal(processor,Z80free_read_param_16(processor),processor->Rm.br.A);
Z80free_Wr_Internal(processor, Z80free_read_param_16(processor), processor->Rm.br.A);
return (13);
break;
break;
case 51: // INC SP
processor->Rm.wr.SP=Z80free_doIncDec16(processor,processor->Rm.wr.SP,0);
processor->Rm.wr.SP = Z80free_doIncDec16(processor, processor->Rm.wr.SP, 0);
return (6);
break;
break;
case 52: // INC b(HL)
Z80free_Wr_Internal(processor,processor->Rm.wr.HL,Z80free_doIncDec(processor,Z80free_Rd_Internal(processor,processor->Rm.wr.HL),0));
Z80free_Wr_Internal(processor, processor->Rm.wr.HL, Z80free_doIncDec(processor, Z80free_Rd_Internal(processor, processor->Rm.wr.HL), 0));
return (11);
break;
break;
case 53: // DEC b(HL)
Z80free_Wr_Internal(processor,processor->Rm.wr.HL,Z80free_doIncDec(processor,Z80free_Rd_Internal(processor,processor->Rm.wr.HL),1));
Z80free_Wr_Internal(processor, processor->Rm.wr.HL, Z80free_doIncDec(processor, Z80free_Rd_Internal(processor, processor->Rm.wr.HL), 1));
return (11);
break;
break;
case 54: // LD (HL),n
Z80free_Wr_Internal(processor,processor->Rm.wr.HL,Z80free_read_param_8(processor));
Z80free_Wr_Internal(processor, processor->Rm.wr.HL, Z80free_read_param_8(processor));
return (10);
break;
break;
case 55: // SCF
Z80free_setFlag(processor,F_C);
Z80free_resFlag(processor,F_H);
Z80free_resFlag(processor,F_N);
Z80free_adjustFlags(processor,processor->Rm.br.A);
Z80free_setFlag(processor, F_C);
Z80free_resFlag(processor, F_H);
Z80free_resFlag(processor, F_N);
Z80free_adjustFlags(processor, processor->Rm.br.A);
return (4);
break;
break;
case 56: // JR CF,n
tmp1=Z80free_read_param_8(processor);
if (F_C&processor->Rm.br.F) {
Z80free_jump_relative(processor,tmp1);
tmp1 = Z80free_read_param_8(processor);
if (F_C & processor->Rm.br.F) {
Z80free_jump_relative(processor, tmp1);
return (12);
} else {
return (7);
}
break;
break;
case 57: // ADD HL,SP
processor->Rm.wr.HL=Z80free_doArithmetic16(processor,processor->Rm.wr.HL,processor->Rm.wr.SP,0,0);
processor->Rm.wr.HL = Z80free_doArithmetic16(processor, processor->Rm.wr.HL, processor->Rm.wr.SP, 0, 0);
return (11);
break;
break;
case 58: // LD A,(nn)
processor->Rm.br.A=Z80free_Rd_Internal(processor,Z80free_read_param_16(processor));
processor->Rm.br.A = Z80free_Rd_Internal(processor, Z80free_read_param_16(processor));
return (13);
break;
break;
case 59: // DEC SP
processor->Rm.wr.SP=Z80free_doIncDec16(processor,processor->Rm.wr.SP,1);
processor->Rm.wr.SP = Z80free_doIncDec16(processor, processor->Rm.wr.SP, 1);
return (6);
break;
break;
case 60: // INC A
processor->Rm.br.A=Z80free_doIncDec(processor,processor->Rm.br.A,0);
processor->Rm.br.A = Z80free_doIncDec(processor, processor->Rm.br.A, 0);
return (4);
break;
break;
case 61: // DEC A
processor->Rm.br.A=Z80free_doIncDec(processor,processor->Rm.br.A,1);
processor->Rm.br.A = Z80free_doIncDec(processor, processor->Rm.br.A, 1);
return (4);
break;
break;
case 62: // LD A,n
processor->Rm.br.A=Z80free_read_param_8(processor);
processor->Rm.br.A = Z80free_read_param_8(processor);
return (7);
break;
break;
case 63: // CCF
Z80free_valFlag(processor,F_C,(~processor->Rm.br.F)&F_C);
Z80free_resFlag(processor,F_N);
Z80free_adjustFlags(processor,processor->Rm.br.A);
Z80free_valFlag(processor, F_C, (~processor->Rm.br.F) & F_C);
Z80free_resFlag(processor, F_N);
Z80free_adjustFlags(processor, processor->Rm.br.A);
return (4);
break;
break;
case 64: // LD B,B
processor->Rm.br.B=processor->Rm.br.B;
processor->Rm.br.B = processor->Rm.br.B;
return (4);
break;
break;
case 65: // LD B,C
processor->Rm.br.B=processor->Rm.br.C;
processor->Rm.br.B = processor->Rm.br.C;
return (4);
break;
break;
case 66: // LD B,D
processor->Rm.br.B=processor->Rm.br.D;
processor->Rm.br.B = processor->Rm.br.D;
return (4);
break;
break;
case 67: // LD B,E
processor->Rm.br.B=processor->Rm.br.E;
processor->Rm.br.B = processor->Rm.br.E;
return (4);
break;
break;
case 68: // LD B,H
processor->Rm.br.B=processor->Rm.br.H;
processor->Rm.br.B = processor->Rm.br.H;
return (4);
break;
break;
case 69: // LD B,L
processor->Rm.br.B=processor->Rm.br.L;
processor->Rm.br.B = processor->Rm.br.L;
return (4);
break;
break;
case 70: // LD B,(HL)
processor->Rm.br.B=Z80free_Rd_Internal(processor,processor->Rm.wr.HL);
processor->Rm.br.B = Z80free_Rd_Internal(processor, processor->Rm.wr.HL);
return (7);
break;
break;
case 71: // LD B,A
processor->Rm.br.B=processor->Rm.br.A;
processor->Rm.br.B = processor->Rm.br.A;
return (4);
break;
break;
case 72: // LD C,B
processor->Rm.br.C=processor->Rm.br.B;
processor->Rm.br.C = processor->Rm.br.B;
return (4);
break;
break;
case 73: // LD C,C
processor->Rm.br.C=processor->Rm.br.C;
processor->Rm.br.C = processor->Rm.br.C;
return (4);
break;
break;
case 74: // LD C,D
processor->Rm.br.C=processor->Rm.br.D;
processor->Rm.br.C = processor->Rm.br.D;
return (4);
break;
break;
case 75: // LD C,E
processor->Rm.br.C=processor->Rm.br.E;
processor->Rm.br.C = processor->Rm.br.E;
return (4);
break;
break;
case 76: // LD C,H
processor->Rm.br.C=processor->Rm.br.H;
processor->Rm.br.C = processor->Rm.br.H;
return (4);
break;
break;
case 77: // LD C,L
processor->Rm.br.C=processor->Rm.br.L;
processor->Rm.br.C = processor->Rm.br.L;