Made EquiRAM structure the main source of truth about sizing
This commit is contained in:
@@ -28,16 +28,20 @@
|
||||
#else
|
||||
|
||||
#define cgetc() (fgetc(stdin))
|
||||
#define cputc(c) (fputc(c, stdout))
|
||||
|
||||
#endif
|
||||
|
||||
/* Definitions section */
|
||||
|
||||
#define EQUI_VER "0.0.1"
|
||||
|
||||
#define ushort unsigned short /* basic 16-bit integer */
|
||||
#define uchar unsigned char /* basic 8-bit integer */
|
||||
#define WS sizeof(ushort) /* Equi word size in bytes */
|
||||
#define CLT_ENTRY_LEN 6u /* Amount of significant compiled word characters */
|
||||
#define CLT_ENTRY_SIZE (CLT_ENTRY_LEN + WS) /* Full size in bytes taken by one CLT entry */
|
||||
#define BS 8u /* Backspace character code */
|
||||
|
||||
/* Configuration section (constants overridable at compile-time) */
|
||||
|
||||
@@ -51,14 +55,9 @@
|
||||
#define LIT_STACK_SIZE 32u
|
||||
#endif
|
||||
|
||||
/* GPD (general purpose data) area start address */
|
||||
#ifndef GPD_AREA_START
|
||||
#define GPD_AREA_START 0x2300u
|
||||
#endif
|
||||
|
||||
/* Command buffer start address */
|
||||
#ifndef CMD_BUF_START
|
||||
#define CMD_BUF_START 0x3b80u
|
||||
/* Command buffer size in bytes */
|
||||
#ifndef GPD_AREA_SIZE
|
||||
#define GPD_AREA_SIZE 6400u
|
||||
#endif
|
||||
|
||||
/* Command buffer size in bytes */
|
||||
@@ -66,33 +65,18 @@
|
||||
#define CMD_BUF_SIZE 15600u
|
||||
#endif
|
||||
|
||||
/* Maximum amount of CLT entries */
|
||||
#ifndef CLT_ENTRIES_MAX
|
||||
#define CLT_ENTRIES_MAX 512u
|
||||
#endif
|
||||
|
||||
/* Some necessary constants and offsets derived from the above values */
|
||||
#define STACK_SIZE_WORDS (STACK_SIZE / WS) /* Main and return stack size in words */
|
||||
#define MAIN_STACK_ADDR 0u /* Main stack address */
|
||||
#define RETURN_STACK_ADDR STACK_SIZE /* Return stack address */
|
||||
#define LIT_STACK_ADDR (RETURN_STACK_ADDR + STACK_SIZE) /* Literal stack address */
|
||||
#define PC_ADDR (LIT_STACK_ADDR + LIT_STACK_SIZE) /* Program counter address */
|
||||
#define CBP_ADDR (PC_ADDR + WS) /* Compilation buffer pointer location address */
|
||||
#define CLTP_ADDR (CBP_ADDR + WS) /* Compilation lookup table pointer location address */
|
||||
#define FLAGS_ADDR (CLTP_ADDR + WS) /* Flags register address */
|
||||
#define GPD_START_LOC_ADDR (FLAGS_ADDR + 1u) /* Location where GPD_AREA_START value is stored */
|
||||
#define CMD_START_LOC_ADDR (GPD_START_LOC_ADDR + WS) /* Location where CMD_BUF_START value is stored */
|
||||
#define CMD_SIZE_LOC_ADDR (CMD_START_LOC_ADDR + WS) /* Location where CMD_BUF_SIZE value is stored */
|
||||
#define CLT_START (CMD_SIZE_LOC_ADDR + 213u) /* should be 0x300 by default */
|
||||
#define CLT_SIZE (GPD_AREA_START - CLT_START) /* Compilation lookup table size in bytes */
|
||||
#define CLT_ENTRIES_MAX (CLT_SIZE / CLT_ENTRY_SIZE) /* Maximum amount of entries in CLT, must be integer */
|
||||
#define GPD_AREA_SIZE (CMD_BUF_START - GPD_AREA_START) /* GPD area size in bytes */
|
||||
|
||||
/*
|
||||
* Structures that describe Equi machine RAM using the above configuration
|
||||
*/
|
||||
|
||||
struct EquiFlags {
|
||||
unsigned int II:1; /* instruction ignore mode */
|
||||
unsigned int CM:1; /* compilation mode */
|
||||
unsigned int IM:1; /* interpretation mode */
|
||||
};
|
||||
|
||||
struct CLTEntry {
|
||||
uchar name[CLT_ENTRY_LEN]; /* compiled word name */
|
||||
ushort loc; /* compiled word location */
|
||||
@@ -108,17 +92,18 @@ struct EquiRAM {
|
||||
uchar lsp; /* literal stack pointer */
|
||||
ushort cbp; /* compilation buffer pointer */
|
||||
ushort cltp; /* compilation lookup table pointer */
|
||||
struct EquiFlags flags;
|
||||
unsigned int II:1; /* instruction ignore mode */
|
||||
unsigned int CM:1; /* compilation mode */
|
||||
unsigned int IM:1; /* interpretation mode */
|
||||
ushort gpd_start;
|
||||
ushort cmd_start;
|
||||
ushort cmd_size;
|
||||
uchar reserved[206u]; /* reserved space */
|
||||
ushort ibp; /* input buffer pointer */
|
||||
struct CLTEntry clt[CLT_ENTRIES_MAX]; /* compilation lookup table */
|
||||
uchar gpd[GPD_AREA_SIZE];
|
||||
uchar cmdbuf[CMD_BUF_SIZE];
|
||||
};
|
||||
|
||||
|
||||
/* Before running the main code, instantiate the machine RAM */
|
||||
static struct EquiRAM ram;
|
||||
|
||||
@@ -127,12 +112,20 @@ static uchar* flatram = (uchar *)&ram;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
/* initialize the RAM in the most standard way */
|
||||
ram.gpd_start = GPD_AREA_START;
|
||||
ram.cmd_start = CMD_BUF_START;
|
||||
ram.gpd_start = (uchar *)&ram.gpd - (uchar *)&ram.main_stack;
|
||||
ram.cmd_start = (uchar *)&ram.cmdbuf - (uchar *)&ram.main_stack;
|
||||
ram.cmd_size = CMD_BUF_SIZE;
|
||||
ram.pc = ram.cmd_start; /* Start execution from the start of command buffer */
|
||||
ram.ibp = ram.cmd_start; /* Start input buffering from the start of command buffer */
|
||||
|
||||
printf("Equi command buffer: 0x%X\n", ram.cmd_size);
|
||||
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022\n\nCLT: 0x%X (%d bytes)\nGPD: 0x%X (%d bytes)\nCommand buffer: 0x%X (%d bytes)\nEqui ready\n\n",
|
||||
(uchar *)&ram.clt - (uchar *)&ram.main_stack,
|
||||
(uchar *)&ram.gpd - (uchar *)&ram.clt,
|
||||
ram.gpd_start,
|
||||
ram.cmd_start - ram.gpd_start,
|
||||
ram.cmd_start, ram.cmd_size);
|
||||
|
||||
cputc('>');
|
||||
cgetc();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user