memory layout revamp

This commit is contained in:
Luxferre
2022-08-13 07:40:48 +03:00
parent 12a219fa64
commit df9d9b7cbc
+44 -36
View File
@@ -60,7 +60,7 @@
/* Command buffer size in bytes */ /* Command buffer size in bytes */
#ifndef GPD_AREA_SIZE #ifndef GPD_AREA_SIZE
#define GPD_AREA_SIZE 5100u #define GPD_AREA_SIZE 5000u
#endif #endif
/* Command buffer size in bytes */ /* Command buffer size in bytes */
@@ -90,23 +90,27 @@ struct CLTEntry {
ushort loc; /* compiled word location */ ushort loc; /* compiled word location */
}; };
struct EquiRAM { struct EquiRAM {
ushort stack_size; /* main/return stack size in words */
uchar literal_stack_size; /* literal stack size in bytes */
uchar lsp; /* literal stack pointer */
ushort msp; /* main stack pointer */
ushort rsp; /* return stack pointer */
ushort clt_start; /* compilation lookup table start */
ushort gpd_start; /* GPD area start */
ushort cmd_start; /* command buffer start */
ushort cmd_size; /* command buffer size in bytes */
ushort pc; /* program counter */
ushort cbp; /* compilation buffer pointer */
ushort cltp; /* compilation lookup table pointer */
ushort ibp; /* input buffer pointer */
uchar II; /* instruction ignore mode flag */
uchar CM; /* compilation mode flag */
uchar IM; /* interpretation mode flag */
uchar MM; /* minification bypass mode flag */
ushort main_stack[STACK_SIZE_WORDS]; ushort main_stack[STACK_SIZE_WORDS];
ushort return_stack[STACK_SIZE_WORDS]; ushort return_stack[STACK_SIZE_WORDS];
uchar literal_stack[LIT_STACK_SIZE]; uchar literal_stack[LIT_STACK_SIZE];
ushort pc; /* program counter */
ushort msp; /* main stack pointer */
ushort rsp; /* return stack pointer */
uchar lsp; /* literal stack pointer */
ushort cbp; /* compilation buffer pointer */
ushort cltp; /* compilation lookup table pointer */
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;
ushort ibp; /* input buffer pointer */
struct CLTEntry clt[CLT_ENTRIES_MAX]; /* compilation lookup table */ struct CLTEntry clt[CLT_ENTRIES_MAX]; /* compilation lookup table */
uchar gpd[GPD_AREA_SIZE]; uchar gpd[GPD_AREA_SIZE];
uchar cmdbuf[CMD_BUF_SIZE]; uchar cmdbuf[CMD_BUF_SIZE];
@@ -129,7 +133,8 @@ enum EquiErrors {
INVALID_INSTRUCTION, INVALID_INSTRUCTION,
INVALID_WORD, INVALID_WORD,
PORT_IO_ERROR, PORT_IO_ERROR,
PERSIST_IO_ERROR PERSIST_IO_ERROR,
RESTRICTED_WRITE_ERROR
}; };
/* Error reporting method */ /* Error reporting method */
@@ -164,6 +169,9 @@ void trapout(errcode) {
case PERSIST_IO_ERROR: case PERSIST_IO_ERROR:
cerr("Persistent storage I/O error\n"); cerr("Persistent storage I/O error\n");
break; break;
case RESTRICTED_WRITE_ERROR:
cerr("Attempt to write to a restricted RAM area\n");
break;
} }
exit(errcode); exit(errcode);
} }
@@ -578,11 +586,7 @@ void equi_main_loop() {
/* Equi VM entry point */ /* Equi VM entry point */
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
uchar instr, bc, mmode = 0, smode = 0; uchar instr, bc, smode = 0;
if(argc > 1 && argv[1][0] == 'm') /* enter minification mode, don't run the programs */
mmode = 1;
else if(argc > 1 && argv[1][0] == 's') /* enter silent mode, don't print the banners and prompts */
smode = 1;
/* _attempt_ to disable buffering for char input/output */ /* _attempt_ to disable buffering for char input/output */
#if !defined __CC65__ && !defined __TINYC__ #if !defined __CC65__ && !defined __TINYC__
setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0);
@@ -591,27 +595,31 @@ int main(int argc, char* argv[]) {
/* initialize the PRNG */ /* initialize the PRNG */
srand((unsigned)time(NULL)); srand((unsigned)time(NULL));
/* initialize the RAM in the most standard way */ /* initialize the RAM in the most standard way */
ram.gpd_start = (uchar *)&ram.gpd - (uchar *)&ram.main_stack; ram.stack_size = STACK_SIZE_WORDS;
ram.cmd_start = (uchar *)&ram.cmdbuf - (uchar *)&ram.main_stack; ram.literal_stack_size = LIT_STACK_SIZE;
ram.clt_start = (uchar *)&ram.clt - (uchar *)&ram.stack_size;
ram.gpd_start = (uchar *)&ram.gpd - (uchar *)&ram.stack_size;
ram.cmd_start = (uchar *)&ram.cmdbuf - (uchar *)&ram.stack_size;
ram.cmd_size = CMD_BUF_SIZE; ram.cmd_size = CMD_BUF_SIZE;
ram.II = ram.CM = ram.IM = 0; /* reset all flags */ ram.II = ram.CM = ram.IM = ram.MM = 0; /* reset all flags */
/* process command line params */
if(argc > 1 && argv[1][0] == 'm') /* enter minification mode, don't run the programs */
ram.MM = 1;
else if(argc > 1 && argv[1][0] == 's') /* enter silent mode, don't print the banners and prompts */
smode = 1;
/* Start both execution and input buffering from the start of command buffer (-1 because we use prefix increment) */ /* Start both execution and input buffering from the start of command buffer (-1 because we use prefix increment) */
ram.pc = ram.ibp = 65535U; ram.pc = ram.ibp = 65535U;
if(!mmode && !smode) { /* skip the terminal init and the greeting if in minification or silent mode */ if(!ram.MM && !smode) { /* skip the terminal init and the greeting if in minification or silent mode */
/* CC65-specific terminal init */ /* CC65-specific terminal init */
#ifdef __CC65__ #ifdef __CC65__
clrscr(); clrscr();
bc = cursor(1); bc = cursor(1);
#else /* VT100-compatible terminal init */ #else /* VT100-compatible terminal init */
printf("\033c"); printf("\033c");
#endif #endif
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022\nCLT: 0x%04X (%d bytes)\nGPD: 0x%04X (%d bytes)\nCommand buffer: 0x%04X (%d bytes)\nEqui ready\n\n> ", printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022\nCLT: 0x%04X (%d bytes)\nGPD: 0x%04X (%d bytes)\nCommand buffer: 0x%04X (%d bytes)\nEqui ready\n\n> ",
(unsigned int) ((uchar *)&ram.clt - (uchar *)&ram.main_stack), ram.clt_start, ram.gpd_start - ram.clt_start, ram.gpd_start, ram.cmd_start - ram.gpd_start, ram.cmd_start, ram.cmd_size);
(unsigned int) ((uchar *)&ram.gpd - (uchar *)&ram.clt),
ram.gpd_start,
ram.cmd_start - ram.gpd_start,
ram.cmd_start, ram.cmd_size);
} }
while(1) { /* Now, we're in the command mode loop */ while(1) { /* Now, we're in the command mode loop */
@@ -633,7 +641,7 @@ int main(int argc, char* argv[]) {
#endif #endif
ram.II = 0; ram.II = 0;
} else if(!ram.II && (instr == 0xFFU || instr == INS_QUIT)) { } else if(!ram.II && (instr == 0xFFU || instr == INS_QUIT)) {
if(mmode) { /* output command buffer contents to stdout and exit */ if(ram.MM) { /* output command buffer contents to stdout and exit */
ram.cmdbuf[++ram.ibp] = INS_QUIT; /* end program with INS_QUIT */ ram.cmdbuf[++ram.ibp] = INS_QUIT; /* end program with INS_QUIT */
ram.cmdbuf[++ram.ibp] = 0; /* and zero terminator */ ram.cmdbuf[++ram.ibp] = 0; /* and zero terminator */
puts((const char *)&ram.cmdbuf[0]); /* output the command buffer */ puts((const char *)&ram.cmdbuf[0]); /* output the command buffer */