83 lines
1.2 KiB
C++
83 lines
1.2 KiB
C++
#ifndef VM_H
|
|
#define VM_H
|
|
#include "vmas.h"
|
|
#include "vmcomp.h"
|
|
#include <stdint.h>
|
|
|
|
#define MOVI_SIZE 4
|
|
#define MOVR_SIZE 2
|
|
#define GETM_SIZE 4
|
|
#define PUTM_SIZE 4
|
|
#define ADDI_SIZE 4
|
|
enum regs { R0, R1, R2, R3, S0, S1, S2, S3, IP, BP, SP, NUM_REGS };
|
|
|
|
/*
|
|
MEMORY LOCATIONS AND IMMEDIATES ARE 16 BITS LONG
|
|
*/
|
|
enum ins {
|
|
MOVI,
|
|
MOVR,
|
|
LOAD,
|
|
STOR,
|
|
ADDI,
|
|
ADDR,
|
|
SUBI,
|
|
SUBR,
|
|
XORI,
|
|
XORR,
|
|
NOTI,
|
|
NOTR,
|
|
MULI,
|
|
MULR,
|
|
DIVI,
|
|
DIVR,
|
|
PUSH,
|
|
POOP,
|
|
CALL,
|
|
SHIT,
|
|
NOPE,
|
|
GERM,
|
|
NUM_OPS
|
|
};
|
|
|
|
class VM {
|
|
private:
|
|
////////////////////////
|
|
// VARIABLES
|
|
////////////////////////
|
|
|
|
uint16_t regs[0xb];
|
|
VMComponent ops[NUM_OPS];
|
|
struct flags {
|
|
uint8_t zf : 1;
|
|
uint8_t cf : 1;
|
|
};
|
|
VMAddrSpace as;
|
|
|
|
////////////////////////
|
|
// FUNCTIONS
|
|
///////////////////////
|
|
void initVariables(void);
|
|
void defineOpcodes(uint8_t * key);
|
|
/*
|
|
DBG UTILS
|
|
*/
|
|
uint8_t *reg_name(uint8_t);
|
|
/*
|
|
IMPLEMENTATIONS
|
|
*/
|
|
bool exec_movi(void);
|
|
bool exec_movr(void);
|
|
bool exec_movm(void);
|
|
bool exec_getm(void);
|
|
bool exec_putm(void);
|
|
bool exec_addi(void);
|
|
|
|
public:
|
|
VM(uint8_t * key);
|
|
VM(uint8_t * key, uint8_t *code, uint32_t codesize);
|
|
void status(void);
|
|
void run();
|
|
};
|
|
|
|
#endif |