lc3-vm/src/main.h
2023-08-10 18:21:56 -05:00

51 lines
698 B
C

#ifndef MAIN_H
#define MAIN_H
#include <stdint.h>
#define MEMORY_MAX (1 << 16)
#define PC_START 0x3000
typedef uint16_t u16;
// registers
enum {
R_R0 = 0,
R_R1,
R_R2,
R_R3,
R_R4,
R_R5,
R_R6,
R_R7,
R_R8,
R_PC,
R_COND,
R_COUNT
};
// cond flags
enum {
FL_POS = 1 << 0,
FL_ZRO = 1 << 1,
FL_NEG = 1 << 2,
};
// memory mapped registers
enum {
MR_KBSR = 0xFE00, /* address of these registers in memory */
MR_KBDR = 0xFE02,
};
// Global variables
static u16 memory[MEMORY_MAX];
static u16 reg[R_COUNT];
static u16 running;
u16 sign_extend(u16 x, int bit_count);
void update_flags(u16 r);
void mem_write(u16 address, u16 value);
u16 mem_read(u16 address);
#endif