From 2bbd304ec7462ced2c4b4ca9baa7b8ae40003822 Mon Sep 17 00:00:00 2001 From: Russell-S-Harper Date: Sun, 7 Jul 2019 13:25:47 -0400 Subject: [PATCH] Added access of DATA section for LDI and SVI. --- README.md | 4 ++-- common/Makefile | 12 ++++++------ common/{page6.src => appl.src} | 31 ++++++++++++++++++++----------- common/macros.h | 17 ++++++++--------- xa-pre-process/main.c | 13 +++++++++++-- xa-pre-process/xapp.h | 2 +- xa-pre-process/xapp.re | 11 +++++++++-- 7 files changed, 57 insertions(+), 33 deletions(-) rename common/{page6.src => appl.src} (52%) diff --git a/README.md b/README.md index a58bce0..4193c77 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,14 @@ The meat of the project: * `common/common.h`: details of instructions * `common/common.asm`: assembler code for the instructions * `common/macros.h`: macros used to define the interpreted byte-code -* `common/page6.src`: sample source file using the macros +* `common/appl.src`: sample source file using the macros Auxiliary: * `emulator/*`: 6502 emulator (borrowed Mike Chambers’ Fake6502 CPU emulator v1.1 ©2011) * `xa-pre-process/*`: my utility `xapp` to convert 32-bit fixed decimal quantities so that `xa` can use them -Right now, for testing purposes, the code builds everything into one file `system.obj` and runs the code in the last block loaded, in this case, the code corresponding to `page6.src`. Eventually will support decoupling of system and application files. Application files will be inherently relocatable. +Right now, for testing purposes, the code builds everything into one file `system.obj` and runs the code in the last block loaded, in this case, the code corresponding to `appl.src`. Eventually will support decoupling of system and application files. Application files will be inherently relocatable. To build and run: diff --git a/common/Makefile b/common/Makefile index 81509d7..4632d6e 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,17 +1,17 @@ XAPP=../xa-pre-process/xapp -system.obj: common.obj page6.obj - cat common.obj page6.obj > system.obj +system.obj: common.obj appl.obj + cat common.obj appl.obj > system.obj common.obj: rom.h common.h common.asm xa -C -M common.asm -l common.lbl -o common.obj -page6.obj: rom.h macros.h globals.h page6.src - cpp -P page6.src | $(XAPP) > page6.asm - xa -C -M page6.asm -l page6.lbl -o page6.obj +appl.obj: rom.h macros.h globals.h appl.src + cpp -P appl.src | $(XAPP) > appl.asm + xa -C -M appl.asm -l appl.lbl -o appl.obj globals.h: common.obj grep -E '^(FN_XR|FN_0X|PLS_1|MNS_1|ADDR)' common.lbl | sed -e 's/, 0, 0x0000//' -e 's/, / = /' -e 's/ 0x/ \x24/' > globals.h clean: - rm -f globals.h page6.asm common.obj page6.obj common.lbl page6.lbl system.obj + rm -f globals.h appl.asm common.obj appl.obj common.lbl appl.lbl system.obj diff --git a/common/page6.src b/common/appl.src similarity index 52% rename from common/page6.src rename to common/appl.src index 548c83e..9782751 100644 --- a/common/page6.src +++ b/common/appl.src @@ -2,27 +2,31 @@ #include "macros.h" #include "globals.h" - * = $1000 ; any address outside of page zero is okay + * = $300 ; any address outside of page zero is okay because all code is relocatable CODE(DEMO) + START CMN SET(R0, 9.4662) - SET(R1, 5) + SET(R1, SQRT2) LDI(R7, R1) MUL(R7, R7, R7) - SVI(R1, R0) PSH(R0) BRS(FACTORIAL) POP(R4) - SET(R5, 1) + SET(R5, E) LDI(R6, R5) + SET(R1, ZERO) + INR(R1) + SVI(R1, R6) + LDI(R0, R1) ESC BRK BEGIN(FACTORIAL) POP(R1) - SET(R2, 3) + SET(R2, 1) MOD(R3, R1, R2) SUB(R1, R1, R3) _1 TST(R1) @@ -36,9 +40,14 @@ END(FACTORIAL) END(DEMO) -DATA(WORKING) -PI VALUE(3.14159) -E VALUE(2.71828) -SQRT2 VALUE(1.41421) -ZERO RESERVE(2) -END(WORKING) +DATA(_) + + ; preset constants + DEFINE(PI, 3.14159) + DEFINE(E, 2.71828) + DEFINE(SQRT2, 1.41421) + + ; working space + RESERVE(2) + +END(_) diff --git a/common/macros.h b/common/macros.h index f131cdf..9d660da 100644 --- a/common/macros.h +++ b/common/macros.h @@ -78,24 +78,23 @@ #define EXT(f) .BYTE _EXT_C + (f) ; header for fixed code or data -#define FIXED(l) .BYTE _SM_FXD:.WORD l, _END_##l - l:* = * - 5:l .( +#define FIXED(l) .BYTE _SM_FXD : .WORD l, _END_##l - l : * = * - 5 : l .( ; header for relocatable code: l(abel) => starting offset, length of code -#define CODE(l) .BYTE _RLC_CD:.WORD _start - l, _END_##l - l: * = * -5:l .( +#define CODE(l) .BYTE _RLC_CD : .WORD _start - l, _END_##l - l : * = * - 5 : l .( #define START &_start ; header for relocatable data: l(abel) => length of zeroed data, length of preset data -#define DATA(l) .BYTE _RLC_DT:.WORD _END_##l - _zero, _zero - l: * = * - 5:l .( -#define ZERO &_zero +#define DATA(l) .BYTE _RLC_DT : .WORD _END_##l - _zero, _zero - l : * = * - 5 : l .( : &_data -; initialize v(alue) -#define VALUE(v) .BYTE _SET_V(#v) +; define l(abel), v(alue) +#define DEFINE(l, v) &l .BYTE _SET_V(#v) -; reserve c(ount) -#define RESERVE(c) * = * + c * 4 +; reserve c(ount) & provide an alias for _zero +#define RESERVE(c) &ZERO : &_zero : * = * + (c) * 4 ; common begin and end #define BEGIN(l) l .( -#define END(l) .):_END_##l +#define END(l) .) : _END_##l #endif /* __MACROS_H */ diff --git a/xa-pre-process/main.c b/xa-pre-process/main.c index 2d2f30c..6b2328e 100644 --- a/xa-pre-process/main.c +++ b/xa-pre-process/main.c @@ -27,8 +27,17 @@ int main(int argc, char **argv) const char *s = "", *p, *q; switch (tokens[i].type) { - /* Process each _SET_V("") command */ - case TT_COMMAND: + /* Process each _SET_V("