diff --git a/ISA_HEX_Map.org b/ISA_HEX_Map.org index f78a634..732030f 100644 --- a/ISA_HEX_Map.org +++ b/ISA_HEX_Map.org @@ -411,12 +411,14 @@ The following 3 devices must exist with the following exact IDs | Tape 2 | 00 00 11 01 | **** Required Device HALCODE -| Hex | Name | Comment | -|-------------+--------+----------------------------------------------------------------------------------------------------------------------------------| -| 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. | +| Hex | Name | Comment | +|-------------+-------------+------------------------------------------------------------------------------------------------| +| 42 10 00 00 | FOPEN_READ | Feed on device who's ID matches the contents of register 0 until first non-zero byte is found. | +| 42 10 00 01 | FOPEN_WRITE | Feed on device who's ID matches the contents of register 0 until first zero byte is found | +| 42 10 00 02 | FCLOSE | Close out writes to 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 | 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. | **** Reserved Block for Hardware specific implementation details | Hex | Name | diff --git a/asm.c b/asm.c index 03a2cfa..72a9640 100644 --- a/asm.c +++ b/asm.c @@ -309,14 +309,14 @@ void assemble(struct Token* p) setExpression(p, "JUMP", "3C00", 4); /* HALCODE Group */ - setExpression(p, "FOPEN", "42100000", 4); - setExpression(p, "FCLOSE", "42100001", 4); - setExpression(p, "FSEEK", "42100002", 4); + setExpression(p, "FOPEN_READ", "42100000", 4); + setExpression(p, "FOPEN_WRITE", "42100001", 4); + setExpression(p, "FCLOSE", "42100002", 4); setExpression(p, "REWIND", "42100003", 4); + setExpression(p, "FSEEK", "42100004", 4); setExpression(p, "FGETC", "42100100", 4); setExpression(p, "FPUTC", "42100200", 4); - //setExpression(p, "", ""); /* 0OP Group*/ setExpression(p, "NOP", "00000000", 4); setExpression(p, "HALT", "FFFFFFFF", 4); diff --git a/disasm.c b/disasm.c index 28f76e0..ffded53 100644 --- a/disasm.c +++ b/disasm.c @@ -980,26 +980,31 @@ void decode_HALCODE(struct Instruction* c) /* Convert to Human readable form */ switch(c->HAL_CODE) { - case 0x100000: /* FOPEN */ + case 0x100000: /* FOPEN_READ */ { - strncpy(Name, "FOPEN", 19); + strncpy(Name, "FOPEN_READ", 19); break; } - case 0x100001: /* FCLOSE */ + case 0x100001: /* FOPEN_WRITE */ + { + strncpy(Name, "FOPEN_WRITE", 19); + break; + } + case 0x100002: /* FCLOSE */ { strncpy(Name, "FCLOSE", 19); break; } - case 0x100002: /* FSEEK */ - { - strncpy(Name, "FSEEK", 19); - break; - } case 0x100003: /* REWIND */ { strncpy(Name, "REWIND", 19); break; } + case 0x100004: /* FSEEK */ + { + strncpy(Name, "FSEEK", 19); + break; + } case 0x100100: /* FGETC */ { strncpy(Name, "FGETC", 19); diff --git a/vm.c b/vm.c index 5fb5310..676a70d 100644 --- a/vm.c +++ b/vm.c @@ -3,7 +3,8 @@ uint32_t performance_counter; /* Prototypes for functions in vm_instructions.c*/ -void vm_FOPEN(struct lilith* vm); +void vm_FOPEN_READ(struct lilith* vm); +void vm_FOPEN_WRITE(struct lilith* vm); void vm_FCLOSE(struct lilith* vm); void vm_FSEEK(struct lilith* vm); void vm_REWIND(struct lilith* vm); @@ -318,16 +319,25 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) switch(c->HAL_CODE) { - case 0x100000: /* fopen */ + case 0x100000: /* fopen_read */ { #ifdef DEBUG - strncpy(Name, "FOPEN", 19); + strncpy(Name, "FOPEN_READ", 19); #endif - vm_FOPEN(vm); + vm_FOPEN_READ(vm); break; } - case 0x100001: /* fclose */ + case 0x100001: /* fopen_write */ + { + #ifdef DEBUG + strncpy(Name, "FOPEN_WRITE", 19); + #endif + + vm_FOPEN_WRITE(vm); + break; + } + case 0x100002: /* fclose */ { #ifdef DEBUG strncpy(Name, "FCLOSE", 19); @@ -336,15 +346,6 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) vm_FCLOSE(vm); break; } - case 0x100002: /* fseek */ - { - #ifdef DEBUG - strncpy(Name, "FSEEK", 19); - #endif - - vm_FSEEK(vm); - break; - } case 0x100003: /* rewind */ { #ifdef DEBUG @@ -354,6 +355,15 @@ bool eval_HALCODE(struct lilith* vm, struct Instruction* c) vm_REWIND(vm); break; } + case 0x100004: /* fseek */ + { + #ifdef DEBUG + strncpy(Name, "FSEEK", 19); + #endif + + vm_FSEEK(vm); + break; + } case 0x100100: /* fgetc */ { #ifdef DEBUG diff --git a/vm_instructions.c b/vm_instructions.c index c627d4a..11fe51f 100644 --- a/vm_instructions.c +++ b/vm_instructions.c @@ -128,13 +128,26 @@ uint32_t shift_register(uint32_t source, uint32_t amount, bool left, bool zero) return tmp; } -void vm_FOPEN(struct lilith* vm) +void vm_FOPEN_READ(struct lilith* vm) { if(0x00001100 == vm->reg[0]) { tape_01 = fopen("tape_01", "r"); } + if (0x00001101 == vm->reg[0]) + { + tape_02 = fopen("tape_02", "r"); + } +} + +void vm_FOPEN_WRITE(struct lilith* vm) +{ + if(0x00001100 == vm->reg[0]) + { + tape_01 = fopen("tape_01", "w"); + } + if (0x00001101 == vm->reg[0]) { tape_02 = fopen("tape_02", "w");