discovered that I misread the spec, initial attempt at correcting the problem

This commit is contained in:
Jeremiah Orians 2016-06-05 12:44:37 -04:00
parent 2525630074
commit 53d32a2ac3
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
4 changed files with 99 additions and 90 deletions

View File

@ -235,29 +235,29 @@
** 1OPI Groups
1OPI i ii ii is the Immediate, a = a OP i ii ii
*** Conditional Jumps
2C ai ii ii # JUMP.C a i ii ii :: Carry? a; PC = PC + i ii ii
2D ai ii ii # JUMP.B a i ii ii :: Borrow? a; PC = PC + i ii ii
2E ai ii ii # JUMP.O a i ii ii :: Overflow? a; PC = PC + i ii ii
2F ai ii ii # JUMP.G a i ii ii :: GT? a; PC = PC + i ii ii
30 ai ii ii # JUMP.GE a i ii ii :: GT? a | EQ? a; PC = PC + i ii ii
31 ai ii ii # JUMP.E a i ii ii :: EQ? a; PC = PC + i ii ii
32 ai ii ii # JUMP.NE a i ii ii :: NEQ? a; PC = PC + i ii ii
33 ai ii ii # JUMP.LE a i ii ii :: LT? a | EQ? a; PC = PC + i ii ii
34 ai ii ii # JUMP.L a i ii ii :: LT? a; PC = PC + i ii ii
35 ai ii ii # JUMP.Z a i ii ii :: ZERO? a; PC = PC + i ii ii
36 ai ii ii # JUMP.NZ a i ii ii :: NZERO? a; PC = PC + i ii ii
37 xx xx xx # Reserved
38 xx xx xx # Reserved
39 xx xx xx # Reserved
3A xx xx xx # Reserved
3B xx xx xx # Reserved
*** Conditional Integer Jumps
2C 0a ii ii # JUMP.C a i ii ii :: Carry? a; PC = PC + i ii ii
2C 1a ii ii # JUMP.B a i ii ii :: Borrow? a; PC = PC + i ii ii
2C 2a ii ii # JUMP.O a i ii ii :: Overflow? a; PC = PC + i ii ii
2C 3a ii ii # JUMP.G a i ii ii :: GT? a; PC = PC + i ii ii
2C 4a ii ii # JUMP.GE a i ii ii :: GT? a | EQ? a; PC = PC + i ii ii
2C 5a ii ii # JUMP.E a i ii ii :: EQ? a; PC = PC + i ii ii
2C 6a ii ii # JUMP.NE a i ii ii :: NEQ? a; PC = PC + i ii ii
2C 7a ii ii # JUMP.LE a i ii ii :: LT? a | EQ? a; PC = PC + i ii ii
2C 8a ii ii # JUMP.L a i ii ii :: LT? a; PC = PC + i ii ii
2C 9a ii ii # JUMP.Z a i ii ii :: ZERO? a; PC = PC + i ii ii
2C Aa ii ii # JUMP.NZ a i ii ii :: NZERO? a; PC = PC + i ii ii
2C Bx xx xx # Reserved
2C Cx xx xx # Reserved
2C Dx xx xx # Reserved
2C Ex xx xx # Reserved
2C Fx xx xx # Reserved
** 0OPI group
0OPI ii ii ii is the Immediate, OP ii ii ii
0OPI ii ii is the Immediate, OP ii ii
*** Unconditional jumps
3C ii ii ii # JUMP ii ii ii :: PC = PC + ii ii ii
3C 00 ii ii # JUMP ii ii :: PC = PC + ii ii
** Reserved Block 0
At this time these instructions only produce a warning; but could do anything.

View File

@ -14,7 +14,7 @@ struct Instruction
uint32_t raw_XOP;
char XOP[6];
char operation[9];
int32_t raw_Immediate;
int16_t raw_Immediate;
char Immediate[7];
uint32_t HAL_CODE;
uint8_t reg0;
@ -744,74 +744,72 @@ void decode_Integer_2OPI(struct Instruction* c)
void decode_1OPI(struct Instruction* c)
{
/* Parse Raw Data */
c->raw_Immediate = (c->raw1%16)*0x10000 + c->raw2*0x100 + c->raw3;
/* Sign extend immediate*/
c->raw_Immediate = c->raw_Immediate << 12;
c->raw_Immediate = c->raw_Immediate >> 12;
c->raw_Immediate = c->raw2*0x100 + c->raw3;
c->Immediate[0] = c->operation[3];
c->Immediate[1] = c->operation[4];
c->Immediate[2] = c->operation[5];
c->Immediate[3] = c->operation[6];
c->Immediate[4] = c->operation[7];
c->HAL_CODE = 0;
c->reg0 = c->raw1/16;
c->raw_XOP = c->raw1/16;
c->reg0 = c->raw1%16;
char Name[20] = "ILLEGAL_1OPI";
/* Convert to Human readable form */
switch(c->raw0)
switch(c->raw_XOP)
{
case 0x2C: /* JUMP.C */
case 0x0: /* JUMP.C */
{
strncpy(Name, "JUMP.C", 19);
break;
}
case 0x2D: /* JUMP.B */
case 0x1: /* JUMP.B */
{
strncpy(Name, "JUMP.B", 19);
break;
}
case 0x2E: /* JUMP.O */
case 0x2: /* JUMP.O */
{
strncpy(Name, "JUMP.O", 19);
break;
}
case 0x2F: /* JUMP.G */
case 0x3: /* JUMP.G */
{
strncpy(Name, "JUMP.G", 19);
break;
}
case 0x30: /* JUMP.GE */
case 0x4: /* JUMP.GE */
{
strncpy(Name, "JUMP.GE", 19);
break;
}
case 0x31: /* JUMP.E */
case 0x5: /* JUMP.E */
{
strncpy(Name, "JUMP.E", 19);
break;
}
case 0x32: /* JUMP.NE */
case 0x6: /* JUMP.NE */
{
strncpy(Name, "JUMP.NE", 19);
break;
}
case 0x33: /* JUMP.LE */
case 0x7: /* JUMP.LE */
{
strncpy(Name, "JUMP.LE", 19);
break;
}
case 0x34: /* JUMP.L */
case 0x8: /* JUMP.L */
{
strncpy(Name, "JUMP.L", 19);
break;
}
case 0x35: /* JUMP.Z */
case 0x9: /* JUMP.Z */
{
strncpy(Name, "JUMP.Z", 19);
break;
}
case 0x36: /* JUMP.NZ */
case 0xA: /* JUMP.NZ */
{
strncpy(Name, "JUMP.NZ", 19);
break;
@ -829,23 +827,22 @@ void decode_1OPI(struct Instruction* c)
void decode_0OPI(struct Instruction* c)
{
/* Parse Raw Data */
c->raw_Immediate = c->raw1*0x10000 + c->raw2*0x100 + c->raw3;
/* Sign extend immediate*/
c->raw_Immediate = c->raw_Immediate << 8;
c->raw_Immediate = c->raw_Immediate >> 8;
c->Immediate[0] = c->operation[2];
c->Immediate[1] = c->operation[3];
c->Immediate[2] = c->operation[4];
c->Immediate[3] = c->operation[5];
c->Immediate[4] = c->operation[6];
c->Immediate[5] = c->operation[7];
c->raw_Immediate = c->raw2*0x100 + c->raw3;
c->Immediate[0] = c->operation[4];
c->Immediate[1] = c->operation[5];
c->Immediate[2] = c->operation[6];
c->Immediate[3] = c->operation[7];
c->HAL_CODE = 0;
c->raw_XOP = c->raw1;
c->XOP[0] = c->operation[2];
c->XOP[1] = c->operation[3];
char Name[20] = "ILLEGAL_0OPI";
/* Convert to Human readable form */
switch(c->raw0)
switch(c->raw_XOP)
{
case 0x3C: /* JUMP */
case 0x00: /* JUMP */
{
strncpy(Name, "JUMP", 19);
break;
@ -939,7 +936,7 @@ void eval_instruction(struct Instruction* c)
decode_Integer_2OPI(c);
break;
}
case 0x2C ... 0x3B: /* Core 1OPI */
case 0x2C: /* Core 1OPI */
{
decode_1OPI(c);
break;

53
vm.c
View File

@ -1126,8 +1126,8 @@ bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c)
return false;
}
/* Process 1OPI instructions */
bool eval_1OPI(struct lilith* vm, struct Instruction* c)
/* Process 1OPI Integer instructions */
bool eval_Integer_1OPI(struct lilith* vm, struct Instruction* c)
{
bool C, B, O, GT, EQ, LT;
uint32_t tmp;
@ -1141,10 +1141,10 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
EQ = tmp & EQual;
LT = tmp & LessThan;
/* 0x2C ... 0x3B */
switch(c->raw0)
/* 0x2C */
switch(c->raw_XOP)
{
case 0x2C: /* JUMP.C */
case 0x0: /* JUMP.C */
{
if(1 == C)
{
@ -1153,7 +1153,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x2D: /* JUMP.B */
case 0x1: /* JUMP.B */
{
if(1 == B)
{
@ -1162,7 +1162,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x2E: /* JUMP.O */
case 0x2: /* JUMP.O */
{
if(1 == O)
{
@ -1171,7 +1171,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x2F: /* JUMP.G */
case 0x3: /* JUMP.G */
{
if(1 == GT)
{
@ -1180,7 +1180,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x30: /* JUMP.GE */
case 0x4: /* JUMP.GE */
{
if((1 == GT) || (1 == EQ))
{
@ -1189,7 +1189,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x31: /* JUMP.E */
case 0x5: /* JUMP.E */
{
if(1 == EQ)
{
@ -1198,7 +1198,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x32: /* JUMP.NE */
case 0x6: /* JUMP.NE */
{
if(1 != EQ)
{
@ -1207,7 +1207,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x33: /* JUMP.LE */
case 0x7: /* JUMP.LE */
{
if((1 == EQ) || (1 == LT))
{
@ -1216,7 +1216,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x34: /* JUMP.L */
case 0x8: /* JUMP.L */
{
if(1 == LT)
{
@ -1225,7 +1225,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x35: /* JUMP.Z */
case 0x9: /* JUMP.Z */
{
if(0 == tmp)
{
@ -1234,7 +1234,7 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
}
break;
}
case 0x36: /* JUMP.NZ */
case 0xA: /* JUMP.NZ */
{
if(0 != tmp)
{
@ -1248,6 +1248,21 @@ bool eval_1OPI(struct lilith* vm, struct Instruction* c)
return false;
}
/* Process 0OPI Integer instructions */
bool eval_Integer_0OPI(struct lilith* vm, struct Instruction* c)
{
switch(c->raw_XOP)
{
case 0x00: /* JUMP */
{
vm->ip = vm->ip + c->raw_Immediate - 4;
break;
}
default: return true;
}
return false;
}
/* Use Opcode to decide what to do and then have it done */
void eval_instruction(struct lilith* vm, struct Instruction* current)
{
@ -1294,18 +1309,18 @@ void eval_instruction(struct lilith* vm, struct Instruction* current)
if ( invalid) goto fail;
break;
}
case 0x2C ... 0x3B:
case 0x2C:
{
decode_1OPI(current);
invalid = eval_1OPI(vm, current);
invalid = eval_Integer_1OPI(vm, current);
if ( invalid) goto fail;
break;
}
case 0x3C: /* JUMP */
{
decode_0OPI(current);
/* Adust the IP relative the the start of this instruction*/
vm->ip = vm->ip + current->raw_Immediate - 4;
invalid = eval_Integer_0OPI(vm, current);
if ( invalid) goto fail;
break;
}
case 0x42: /* HALCODE */

39
vm.h
View File

@ -23,7 +23,7 @@ struct Instruction
uint32_t raw_XOP;
char XOP[6];
char operation[9];
int32_t raw_Immediate;
int16_t raw_Immediate;
char Immediate[7];
uint32_t HAL_CODE;
uint8_t reg0;
@ -129,31 +129,28 @@ void decode_2OPI(struct Instruction* c)
/* Deal with 1OPI */
void decode_1OPI(struct Instruction* c)
{
c->raw_Immediate = (c->raw1%16)*0x10000 + c->raw2*0x100 + c->raw3;
/* Sign extend immediate*/
c->raw_Immediate = c->raw_Immediate << 12;
c->raw_Immediate = c->raw_Immediate >> 12;
c->Immediate[0] = c->operation[3];
c->Immediate[1] = c->operation[4];
c->Immediate[2] = c->operation[5];
c->Immediate[3] = c->operation[6];
c->Immediate[4] = c->operation[7];
c->raw_Immediate = c->raw2*0x100 + c->raw3;
c->Immediate[0] = c->operation[4];
c->Immediate[1] = c->operation[5];
c->Immediate[2] = c->operation[6];
c->Immediate[3] = c->operation[7];
c->HAL_CODE = 0;
c->reg0 = c->raw1/16;
c->raw_XOP = c->raw1/16;
c->XOP[0] = c->operation[2];
c->reg0 = c->raw1%16;
}
/* Deal with 0OPI */
void decode_0OPI(struct Instruction* c)
{
c->raw_Immediate = c->raw1*0x10000 + c->raw2*0x100 + c->raw3;
/* Sign extend immediate*/
c->raw_Immediate = c->raw_Immediate << 8;
c->raw_Immediate = c->raw_Immediate >> 8;
c->Immediate[0] = c->operation[2];
c->Immediate[1] = c->operation[3];
c->Immediate[2] = c->operation[4];
c->Immediate[3] = c->operation[5];
c->Immediate[4] = c->operation[6];
c->Immediate[5] = c->operation[7];
c->raw_Immediate = c->raw2*0x100 + c->raw3;
c->Immediate[0] = c->operation[4];
c->Immediate[1] = c->operation[5];
c->Immediate[2] = c->operation[6];
c->Immediate[3] = c->operation[7];
c->HAL_CODE = 0;
c->raw_XOP = c->raw1;
c->XOP[0] = c->operation[2];
c->XOP[1] = c->operation[3];
}
/* Deal with Halcode */