Fixed error in 1OPI decode and added intial HALCODE instruction prototypes

This commit is contained in:
Jeremiah Orians 2016-06-04 12:05:10 -04:00
parent b095b1ace9
commit 899adf2dab
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
3 changed files with 143 additions and 1 deletions

View File

@ -194,6 +194,31 @@
# HALCODE hh hh hh is the HALCODE callID, invalid HALCODE SHOULD NOT BE USED.
42 hh hh hh
42 00 xx xx # Reserved
...
42 0F xx xx # Reserved
# Tape console HALCODE is used for interacting with any tape console attached to the system.
# In this reference implementation we will be interacting with a simplified version of the series 10 console.
# All compatible implementations need to ensure to implement functional equivelents.
# Provided of course that any deviations would not change any output specified to be written to tape.
# Padding with Zeros til start/end of page/segment however is acceptable.
# The following 3 devices must exact with the following IDs
# Keyboard/tty :: 00 00 00 00
# Tape 1 :: 00 00 11 00
# Tape 2 :: 00 00 11 01
42 10 00 00 # FOPEN :: Feed on device who's ID matches the contents register 0 until first non-zero byte is found.
42 10 00 01 # FCLOSE :: Close out writes to device who's ID matches the contents of register 0.
42 10 00 02 # FSEEK :: seek forward or backward the number of bytes specified in register 1 on the device who's ID matches the contents of register 0.
42 10 00 03 # REWIND :: rewind back to first non-zero byte found on tape.
42 10 00 04 # Reserved
...
42 10 00 FF # Reserved
42 10 01 00 # FGETC :: read 1 byte into register 0 from device who's ID is in register 1
42 10 01 01 # Reserved
...
42 10 01 FF # Reserved
42 10 02 00 # FPUTC :: write 1 byte from register 0 to device who's ID is in register 1
# Reserved Block 1, At this time these instructions only produce a warning; but could do anything. DO NOT USE.
43 xx xx xx

117
vm.c
View File

@ -1,6 +1,9 @@
#include "vm.h"
#define DEBUG true;
FILE* tape_01;
FILE* tape_02;
/* Load program tape into Memory */
void load_program(struct lilith* vm, char **argv)
{
@ -37,6 +40,112 @@ void read_instruction(struct lilith* vm, struct Instruction *current)
unpack_instruction(current);
}
/* Process HALCODE instructions */
bool eval_HALCODE(struct lilith* vm, struct Instruction* c)
{
switch(c->HAL_CODE)
{
case 0x100000: /* fopen */
{
if(0x00001100 == vm->reg[0])
{
tape_01 = fopen("tape_01", "r");
}
if (0x00001101 == vm->reg[0])
{
tape_02 = fopen("tape_02", "w");
}
break;
}
case 0x100001: /* fclose */
{
if(0x00001100 == vm->reg[0])
{
fclose(tape_01);
}
if (0x00001101 == vm->reg[0])
{
fclose(tape_02);
}
break;
}
case 0x100002: /* fseek */
{
if(0x00001100 == vm->reg[0])
{
fseek(tape_01, vm->reg[1], SEEK_CUR);
}
if (0x00001101 == vm->reg[0])
{
fseek(tape_02, vm->reg[1], SEEK_CUR);
}
break;
}
case 0x100003: /* rewind */
{
if(0x00001100 == vm->reg[0])
{
rewind(tape_01);
}
if (0x00001101 == vm->reg[0])
{
rewind(tape_02);
}
break;
}
case 0x100100: /* fgetc */
{
int32_t byte = -1;
if (0x00000000 == vm->reg[1])
{
byte = fgetc(stdin);
}
if(0x00001100 == vm->reg[1])
{
byte = fgetc(tape_01);
}
if (0x00001101 == vm->reg[1])
{
byte = fgetc(tape_02);
}
vm->reg[0] = byte;
break;
}
case 0x100200: /* fputc */
{
int32_t byte = vm->reg[0];
if (0x00000000 == vm->reg[1])
{
fputc(byte, stdout);
}
if(0x00001100 == vm->reg[1])
{
fputc(byte, tape_01);
}
if (0x00001101 == vm->reg[1])
{
fputc(byte, tape_02);
}
break;
}
default: return true;
}
return false;
}
/* Process 4OP Integer instructions */
bool eval_4OP_Int(struct lilith* vm, struct Instruction* c)
{
@ -1201,6 +1310,14 @@ void eval_instruction(struct lilith* vm, struct Instruction* current)
}
case 0x42: /* HALCODE */
{
decode_HALCODE(current);
invalid = eval_HALCODE(vm, current);
if ( invalid )
{
vm->halted = true;
fprintf(stderr, "Invalid HALCODE\nComputer Program has Halted\n");
}
break;
}
case 0xFF: /* Deal with HALT */
{

2
vm.h
View File

@ -139,7 +139,7 @@ void decode_1OPI(struct Instruction* c)
c->Immediate[3] = c->operation[6];
c->Immediate[4] = c->operation[7];
c->HAL_CODE = 0;
c->reg0 = c->raw3/16;
c->reg0 = c->raw1/16;
}
/* Deal with 0OPI */
void decode_0OPI(struct Instruction* c)