Correcting error in string output and avoiding segment faults in vm

This commit is contained in:
Jeremiah Orians 2017-06-24 11:44:41 -04:00
parent 4963fcfebc
commit d3bed26e0a
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
3 changed files with 35 additions and 15 deletions

View File

@ -37,9 +37,11 @@ Added Low memory detection to stage2 FORTH and now exits gracefully
Minor refactor of stage3 FORTH by reepa
Stage3 FORTH WHILE's compile-time stack effect is now consistent with gforth
Changed behavior of stage2 FORTH's CREATE to better match the way it usually works.
Stage0 vm now will show an error message if the size of the rom exceeds the available memory
** Fixed
Updated checksums to reflect changes in stage2 FORTH
Fixed dis behavior in regards to hex values in strings
** Removed
the HERE and DP! are gone from ' now in stage3 FORTH

View File

@ -87,14 +87,25 @@ Broken:
void print_non_NULL(uint8_t c)
{
if(0 != c)
switch(c)
{
fprintf(stdout, "%c", c);
case 0: return;
case 32 ... 126:
{
fprintf(stdout, "%c", c);
break;
}
default: fprintf(stdout, "0x%X ", c);
}
}
void string_values(struct Instruction *c)
void string_values(struct Instruction *c, bool first)
{
if(first)
{
fprintf(stdout, "\"");
}
print_non_NULL(c->raw0);
print_non_NULL(c->raw1);
print_non_NULL(c->raw2);
@ -103,12 +114,12 @@ void string_values(struct Instruction *c)
if(0 != c->raw3)
{
read_instruction(c);
string_values(c);
string_values(c, false);
address = address + 4;
}
else
{
fprintf(stdout, "\t #STRING\n");
fprintf(stdout, "\"\t #STRING\n");
}
}
@ -231,7 +242,7 @@ void decode_Integer_4OP(struct Instruction* c)
}
default: /* Unknown 4OP */
{
string_values(c);
string_values(c, true);
return;
}
}
@ -555,7 +566,7 @@ void decode_Integer_3OP(struct Instruction* c)
}
default: /* Unknown 3OP*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -733,7 +744,7 @@ void decode_Integer_2OP(struct Instruction* c)
}
default: /* Unknown 2OP*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -801,7 +812,7 @@ void decode_1OP(struct Instruction* c)
}
default: /* Unknown 1OP*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -843,7 +854,7 @@ void decode_0OP(struct Instruction* c)
}
default: /* Unknown 1OP*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -1035,7 +1046,7 @@ void decode_Integer_2OPI(struct Instruction* c)
}
default: /* Unknown 2OPI*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -1280,7 +1291,7 @@ void decode_1OPI(struct Instruction* c)
}
default: /* Unknown 1OPI*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -1314,7 +1325,7 @@ void decode_0OPI(struct Instruction* c)
}
default: /* Unknown 1OPI*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -1375,7 +1386,7 @@ void decode_HALCODE(struct Instruction* c)
}
default: /* Unknown HALCODE*/
{
string_values(c);
string_values(c, true);
return;
}
}
@ -1439,7 +1450,7 @@ void eval_instruction(struct Instruction* c)
}
default: /* Not supported by this disassembler */
{
string_values(c);
string_values(c, true);
return;
}
}

7
vm.c
View File

@ -29,6 +29,13 @@ void load_program(struct lilith* vm, char* rom_name)
size_t end = ftell(program);
rewind(program);
/* Deal with the special case of the ROM is bigger than available memory */
if(end > vm->amount_of_Ram)
{
fprintf(stderr, "Program %s is %d bytes large but only %d bytes of memory have been allocated!\n", rom_name, (int)end, (int)vm->amount_of_Ram);
exit(EXIT_FAILURE);
}
/* Load the entire tape into memory */
fread(vm->memory, 1, end, program);