change operands for some instructions and start work on devices

This commit is contained in:
2026-07-16 13:13:38 +10:00
parent c270a48141
commit a2d90f620a
7 changed files with 32 additions and 13 deletions

12
src/device.c Normal file
View File

@@ -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;
}

View File

@@ -1,5 +1,18 @@
#pragma once #pragma once
#include <stdint.h>
#include <stdlib.h>
typedef struct { typedef struct {
char name[32];
} Device; 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)()
);

View File

@@ -13,7 +13,7 @@ const OperandType INSTRUCTION_OPERAND_TYPES[][3] = {
{OP_REG, OP_REG, OP_REG}, // SHF {OP_REG, OP_REG, OP_REG}, // SHF
{OP_REG, OP_REG, OP_NONE}, // JMP {OP_REG, OP_REG, OP_NONE}, // JMP
{OP_REG, OP_REG, OP_NONE}, // JIZ {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_NONE, OP_NONE, OP_NONE}, // RET
{OP_REG, OP_REG, OP_IMM4}, // PORT {OP_REG, OP_REG, OP_IMM4}, // PORT
{OP_NONE, OP_NONE, OP_NONE} // HLT {OP_NONE, OP_NONE, OP_NONE} // HLT

View File

@@ -11,7 +11,7 @@ typedef enum : uint8_t {
INST_XOR, INST_SHF, INST_JMP, INST_JIZ, INST_CALL, INST_RET, INST_PORT, INST_HLT INST_XOR, INST_SHF, INST_JMP, INST_JIZ, INST_CALL, INST_RET, INST_PORT, INST_HLT
} InstructionOpcode; } InstructionOpcode;
typedef enum { typedef enum : uint8_t {
// General purpose registers // General purpose registers
REG_A, REG_B, REG_C, REG_A, REG_B, REG_C,

View File

@@ -10,16 +10,7 @@ int main() {
} }
RomFile* romFile = readProgramFromFile("../test.bin"); 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); memoryLoadProgram(emu->mem, romFile->instructions, romFile->header.numInstructions);
//startEmulator(emu); //startEmulator(emu);
freeEmulator(emu); freeEmulator(emu);

View File

@@ -2,4 +2,4 @@ mvi a 2
mvi b 2 mvi b 2
add a b add a b
hlt hlt

3
tests/port.asm Normal file
View File

@@ -0,0 +1,3 @@
mvi a 1
port a 123 out
hlt