diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2ba9eed --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +# Equi reference implementation build project + +PROJNAME=equi +CFILES=equi.c +PBTDIR=platform-build-tools + +desktopcc: + cc -std=c89 -Os -o $(PROJNAME) $(CFILES) + strip $(PROJNAME) + +tcc: + tcc -std=c89 -o $(PROJNAME) $(CFILES) + +apple2-build: + cl65 --standard c89 -O -Os -t apple2 -o $(PROJNAME).apple2 $(CFILES) + +apple2: apple2-build + cp $(PBTDIR)/apple2/tpl.dsk equi.dsk + java -jar $(PBTDIR)/apple2/ac.jar -p $(PROJNAME).dsk $(PROJNAME).system sys < $$(cl65 --print-target-path)/apple2/util/loader.system + java -jar $(PBTDIR)/apple2/ac.jar -as $(PROJNAME).dsk $(PROJNAME) bin < $(PROJNAME).apple2 + rm *.o *.apple2 diff --git a/equi.md b/README.md similarity index 98% rename from equi.md rename to README.md index 351ba42..3aec20b 100644 --- a/equi.md +++ b/README.md @@ -140,7 +140,9 @@ The following constants can be adjusted at compile time: - `LIT_STACK_SIZE` - literal stack size in bytes (255 max); - `GPD_AREA_START` - GPD area start address in the virtual RAM; - `CMD_BUF_START` - command buffer start address in the virtual RAM; -- `CMD_BUF_SIZE` - command buffer size in bytes (65535 max); +- `CMD_BUF_SIZE` - command buffer size in bytes (65535 max). + +Please keep in mind that the reference implementation code primarily serves as a, well, reference on how the specification should be implemented, so it emphasizes on code portability and readability over performance whenever such a choice arises. ### Building with GCC/Clang/MinGW (for current mainstream targets) diff --git a/equi.c b/equi.c index 5f95709..141cbe1 100644 --- a/equi.c +++ b/equi.c @@ -36,46 +36,46 @@ #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 6 /* Amount of significant compiled word characters */ +#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 */ /* Configuration section (constants overridable at compile-time) */ /* Main and return stack size in bytes */ #ifndef STACK_SIZE -#define STACK_SIZE 256 +#define STACK_SIZE 256u #endif /* Literal stack size in bytes */ #ifndef LIT_STACK_SIZE -#define LIT_STACK_SIZE 32 +#define LIT_STACK_SIZE 32u #endif /* GPD (general purpose data) area start address */ #ifndef GPD_AREA_START -#define GPD_AREA_START 0x2300 +#define GPD_AREA_START 0x2300u #endif /* Command buffer start address */ #ifndef CMD_BUF_START -#define CMD_BUF_START 0x3b80 +#define CMD_BUF_START 0x3b80u #endif /* Command buffer size in bytes */ #ifndef CMD_BUF_SIZE -#define CMD_BUF_SIZE 15600 +#define CMD_BUF_SIZE 15600u #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 0 /* Main stack address */ +#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 + 1) /* Location where GPD_AREA_START value is stored */ +#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 */ @@ -94,7 +94,7 @@ struct EquiFlags { }; struct CLTEntry { - uchar name[6]; /* compiled word name */ + uchar name[CLT_ENTRY_LEN]; /* compiled word name */ ushort loc; /* compiled word location */ }; @@ -112,7 +112,7 @@ struct EquiRAM { ushort gpd_start; ushort cmd_start; ushort cmd_size; - uchar reserved[206]; /* reserved space */ + uchar reserved[206u]; /* reserved space */ struct CLTEntry clt[CLT_ENTRIES_MAX]; /* compilation lookup table */ uchar gpd[GPD_AREA_SIZE]; uchar cmdbuf[CMD_BUF_SIZE];