diff --git a/src/device.c b/src/device.c new file mode 100644 index 0000000..c6cc2f3 --- /dev/null +++ b/src/device.c @@ -0,0 +1,12 @@ +#include "device.h" + +Device* createDevice( + const char* name, + void (*sendToDevice)(uint16_t number), + uint16_t (*receiveFromDevice)(), + void (*update)() +) { + Device* new = malloc(sizeof(Device)); + if (!new) + return NULL; +} \ No newline at end of file diff --git a/src/device.h b/src/device.h index 2473ca0..d4c797d 100644 --- a/src/device.h +++ b/src/device.h @@ -1,5 +1,18 @@ #pragma once +#include +#include typedef struct { + char name[32]; -} Device; \ No newline at end of file + void (*sendToDevice)(uint16_t number); + uint16_t (*receiveFromDevice)(); + void (*update)(); +} Device; + +Device* createDevice( + const char* name, + void (*sendToDevice)(uint16_t number), + uint16_t (*receiveFromDevice)(), + void (*update)() +); \ No newline at end of file diff --git a/src/instruction.c b/src/instruction.c index a4f8f2e..08eb147 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -13,7 +13,7 @@ const OperandType INSTRUCTION_OPERAND_TYPES[][3] = { {OP_REG, OP_REG, OP_REG}, // SHF {OP_REG, OP_REG, OP_NONE}, // JMP {OP_REG, OP_REG, OP_NONE}, // JIZ - {OP_REG, OP_REG, OP_NONE}, // CALL + {OP_IMM16, OP_NONE, OP_NONE},// CALL {OP_NONE, OP_NONE, OP_NONE}, // RET {OP_REG, OP_REG, OP_IMM4}, // PORT {OP_NONE, OP_NONE, OP_NONE} // HLT diff --git a/src/instruction.h b/src/instruction.h index 4bffb60..d026009 100644 --- a/src/instruction.h +++ b/src/instruction.h @@ -11,7 +11,7 @@ typedef enum : uint8_t { INST_XOR, INST_SHF, INST_JMP, INST_JIZ, INST_CALL, INST_RET, INST_PORT, INST_HLT } InstructionOpcode; -typedef enum { +typedef enum : uint8_t { // General purpose registers REG_A, REG_B, REG_C, diff --git a/src/main.c b/src/main.c index e458cbb..f24ee11 100644 --- a/src/main.c +++ b/src/main.c @@ -10,16 +10,7 @@ int main() { } RomFile* romFile = readProgramFromFile("../test.bin"); - - /*Instruction program[] = { - {INST_MVI, {REG_A, 0, 0}, 5, true}, - {INST_MVI, {REG_B, 0, 0}, 3, true}, - {INST_ADD, {REG_A, REG_B, 0}, 0, false}, - {INST_HLT, {}, 0, false} - };*/ - printf("%d\n", romFile->header.numInstructions); memoryLoadProgram(emu->mem, romFile->instructions, romFile->header.numInstructions); - //startEmulator(emu); freeEmulator(emu); diff --git a/tests/add.asm b/tests/add.asm index 843c9bd..c0ee31a 100644 --- a/tests/add.asm +++ b/tests/add.asm @@ -2,4 +2,4 @@ mvi a 2 mvi b 2 add a b -hlt +hlt \ No newline at end of file diff --git a/tests/port.asm b/tests/port.asm new file mode 100644 index 0000000..0abf7f1 --- /dev/null +++ b/tests/port.asm @@ -0,0 +1,3 @@ +mvi a 1 +port a 123 out +hlt \ No newline at end of file