standardize

This commit is contained in:
Luxferre
2022-08-06 09:34:32 +03:00
parent db589f3904
commit 152744e84a
2 changed files with 39 additions and 21 deletions
+25 -16
View File
@@ -9,10 +9,25 @@
* @author Luxferre
*/
/* Standard includes */
/* Standard includes with size optimizations for TCC */
#ifdef __TINYC__
#include <tcclib.h>
#else
#include <stdlib.h>
#include <stdio.h>
#endif
/*
* Non-standard includes
* To save space, we emulate necessary conio functions on non-6502 systems, not vice versa
*/
#ifdef __CC65__
#include <conio.h>
#else
#endif
/* Definitions section */
@@ -51,7 +66,6 @@
/* 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 0 /* Main stack address */
#define RETURN_STACK_ADDR STACK_SIZE /* Return stack address */
#define LIT_STACK_ADDR (RETURN_STACK_ADDR + STACK_SIZE) /* Literal stack address */
@@ -72,9 +86,9 @@
*/
struct EquiFlags {
uchar II:1; /* instruction ignore mode */
uchar CM:1; /* compilation mode */
uchar IM:1; /* interpretation mode */
unsigned int II:1; /* instruction ignore mode */
unsigned int CM:1; /* compilation mode */
unsigned int IM:1; /* interpretation mode */
};
struct CLTEntry {
@@ -103,22 +117,17 @@ struct EquiRAM {
};
/*
* Before running the main code, instantiate and initialize the machine RAM
*/
static struct EquiRAM ram = {
.gpd_start = GPD_AREA_START,
.cmd_start = CMD_BUF_START,
.cmd_size = CMD_BUF_SIZE
};
/* Before running the main code, instantiate the machine RAM */
static struct EquiRAM ram;
/* Also create an alternative view of the same RAM area for direct offset-based access */
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.cmd_size = CMD_BUF_SIZE;
printf("0x%X", ram.cmd_size);
+14 -5
View File
@@ -31,7 +31,7 @@ Address range|Size (bytes)|Purpose
0x0000-0x00ff|256 |Main stack
0x0100-0x01ff|256 |Return stack
0x0200-0x021f|32 |Literal stack
0x0220-0x0221|2 |PC
0x0220-0x0221|2 |PC (program counter)
0x0222-0x0223|2 |MSP (main stack pointer)
0x0224-0x0225|2 |RSP (return stack pointer)
0x0226 |1 |LSP (literal stack pointer)
@@ -144,15 +144,24 @@ The following constants can be adjusted at compile time:
### Building with GCC/Clang/MinGW (for current mainstream targets)
Build with default parameters:
Build with default parameters (you can override any of the above constants with `-D` switch:
```
cc --std=c89 -Os -o equi equi.c
cc -std=c89 -Os -o equi equi.c [-DSTACK_SIZE=... ...]
```
Build with reconfiguring the defaults - specify any of the above constants after `-D` switch:
### Building with TCC (TinyCC, Tiny C Compiler)
Equi's codebase detects TCC and attempts to save size by linking against tcclib instead of the standard libraries. Note that TCC doesn't support size optimization switches and C89 standard in the most recent versions, so it will fall back to C99 instead. Anyway, the most sensible command to build Equi with TCC is:
```
cc --std=c89 -Os [-DSTACK_SIZE=... ...] -o equi equi.c
tcc -std=c89 -o equi equi.c [-DSTACK_SIZE=... ...]
```
### Building with CC65 (for 6502-based targets)
This is where things start to get interesting, as we need to specify the exact target machine for CC65. For now, Equi reference implementation is only being tested for Apple II, so the commands to build it would be:
```
cc65 --standard c89 -O -Os -t apple2 -o equi.s equi.c
```