commit df9d9b7cbcbea8a1b481a08db90c2f7a7cb7e2a8
parent 12a219fa64a65ee4254b3489f095eba9663f329a
Author: Luxferre <lux@ferre>
Date: Sat, 13 Aug 2022 07:40:48 +0300
memory layout revamp
Diffstat:
M | equi.c | | | 76 | ++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
1 file changed, 42 insertions(+), 34 deletions(-)
diff --git a/equi.c b/equi.c
@@ -60,7 +60,7 @@
/* Command buffer size in bytes */
#ifndef GPD_AREA_SIZE
-#define GPD_AREA_SIZE 5100u
+#define GPD_AREA_SIZE 5000u
#endif
/* Command buffer size in bytes */
@@ -90,23 +90,27 @@ struct CLTEntry {
ushort loc; /* compiled word location */
};
-struct EquiRAM {
- ushort main_stack[STACK_SIZE_WORDS];
- ushort return_stack[STACK_SIZE_WORDS];
- uchar literal_stack[LIT_STACK_SIZE];
- ushort pc; /* program counter */
+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 */
- uchar lsp; /* literal 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 */
- 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 */
+ 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 return_stack[STACK_SIZE_WORDS];
+ uchar literal_stack[LIT_STACK_SIZE];
struct CLTEntry clt[CLT_ENTRIES_MAX]; /* compilation lookup table */
uchar gpd[GPD_AREA_SIZE];
uchar cmdbuf[CMD_BUF_SIZE];
@@ -129,7 +133,8 @@ enum EquiErrors {
INVALID_INSTRUCTION,
INVALID_WORD,
PORT_IO_ERROR,
- PERSIST_IO_ERROR
+ PERSIST_IO_ERROR,
+ RESTRICTED_WRITE_ERROR
};
/* Error reporting method */
@@ -164,6 +169,9 @@ void trapout(errcode) {
case PERSIST_IO_ERROR:
cerr("Persistent storage I/O error\n");
break;
+ case RESTRICTED_WRITE_ERROR:
+ cerr("Attempt to write to a restricted RAM area\n");
+ break;
}
exit(errcode);
}
@@ -578,11 +586,7 @@ void equi_main_loop() {
/* Equi VM entry point */
int main(int argc, char* argv[]) {
- uchar instr, bc, mmode = 0, 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;
+ uchar instr, bc, smode = 0;
/* _attempt_ to disable buffering for char input/output */
#if !defined __CC65__ && !defined __TINYC__
setvbuf(stdin, NULL, _IONBF, 0);
@@ -591,27 +595,31 @@ int main(int argc, char* argv[]) {
/* initialize the PRNG */
srand((unsigned)time(NULL));
/* initialize the RAM in the most standard way */
- ram.gpd_start = (uchar *)&ram.gpd - (uchar *)&ram.main_stack;
- ram.cmd_start = (uchar *)&ram.cmdbuf - (uchar *)&ram.main_stack;
+ ram.stack_size = STACK_SIZE_WORDS;
+ 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.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) */
ram.pc = ram.ibp = 65535U;
- if(!mmode && !smode) { /* skip the terminal init and the greeting if in minification or silent mode */
- /* CC65-specific terminal init */
+ if(!ram.MM && !smode) { /* skip the terminal init and the greeting if in minification or silent mode */
+ /* CC65-specific terminal init */
#ifdef __CC65__
- clrscr();
- bc = cursor(1);
+ clrscr();
+ bc = cursor(1);
#else /* VT100-compatible terminal init */
- printf("\033c");
+ printf("\033c");
#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> ",
- (unsigned int) ((uchar *)&ram.clt - (uchar *)&ram.main_stack),
- (unsigned int) ((uchar *)&ram.gpd - (uchar *)&ram.clt),
- ram.gpd_start,
- ram.cmd_start - ram.gpd_start,
- ram.cmd_start, ram.cmd_size);
+ 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> ",
+ ram.clt_start, ram.gpd_start - ram.clt_start, 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 */
@@ -633,7 +641,7 @@ int main(int argc, char* argv[]) {
#endif
ram.II = 0;
} 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] = 0; /* and zero terminator */
puts((const char *)&ram.cmdbuf[0]); /* output the command buffer */