Added access of DATA section for LDI and SVI.

This commit is contained in:
Russell-S-Harper 2019-07-07 13:25:47 -04:00
parent 5b78dcbd82
commit 2bbd304ec7
7 changed files with 57 additions and 33 deletions

View File

@ -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:

View File

@ -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

View File

@ -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(_)

View File

@ -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 */

View File

@ -27,8 +27,17 @@ int main(int argc, char **argv)
const char *s = "", *p, *q;
switch (tokens[i].type)
{
/* Process each _SET_V("<expr>") command */
case TT_COMMAND:
/* Process each _SET_V("<label>") command */
case TT_LABEL:
/* Extract the start and ending indices */
p = strchr(tokens[i].text, '"') + 1;
q = strrchr(tokens[i].text, '"');
j = (int)(q - p);
/* Output in .BYTE format */
printf("0, <(%.*s - _data), >(%.*s - _data), 0", j, p, j, p);
break;
/* Process each _SET_V("<expression>") command */
case TT_EXPRESSION:
/* Extract the start and ending indices */
p = strchr(tokens[i].text, '"') + 1;
q = strrchr(tokens[i].text, '"');

View File

@ -50,7 +50,7 @@
typedef enum
{
TT_COMMAND, TT_DEFAULT, TT_WHITE_SPACE, TT_END_OF_LINE
TT_LABEL, TT_EXPRESSION, TT_DEFAULT, TT_WHITE_SPACE, TT_END_OF_LINE
} TOKEN_TYPE;
typedef struct

View File

@ -72,18 +72,25 @@ int tokenizeInput(const char *cursor, TOKEN *tokens)
WHITE_SPACE = BELL | BACKSPACE | HORIZONTAL_TAB | ESCAPE | DELETE | SPACE ;
SET_V_BGN = LOW_LINE [Ss][Ee][Tt] LOW_LINE [Vv] WHITE_SPACE* LEFT_PARENTHESIS WHITE_SPACE* QUOTATION_MARK ;
SET_V_END = QUOTATION_MARK WHITE_SPACE* RIGHT_PARENTHESIS ;
VALID = DIGIT | LETTER | EXCLAMATION_MARK | DOLLAR_SIGN | PERCENT_SIGN | AMPERSAND
| LEFT_PARENTHESIS | RIGHT_PARENTHESIS | ASTERISK | PLUS_SIGN | HYPHEN_MINUS
| FULL_STOP | SOLIDUS | LESS_THAN_SIGN | EQUALS_SIGN | GREATER_THAN_SIGN
| LOW_LINE | VERTICAL_LINE | TILDE | WHITE_SPACE ;
COMMAND = LOW_LINE [Ss][Ee][Tt] LOW_LINE [Vv] WHITE_SPACE* LEFT_PARENTHESIS WHITE_SPACE* QUOTATION_MARK VALID+ QUOTATION_MARK WHITE_SPACE* RIGHT_PARENTHESIS ;
LABEL = SET_V_BGN ( LETTER | LOW_LINE ) ( LETTER | LOW_LINE | DIGIT )* SET_V_END ;
EXPRESSION = SET_V_BGN VALID+ SET_V_END ;
DEFAULT = . ;
END_OF_LINE = ( LINE_FEED | VERTICAL_TAB | FORM_FEED | CARRIAGE_RETURN )+ ;
COMMAND { i = copyToken(tokens, i, TT_COMMAND, token, (int)(cursor - token)); continue; }
LABEL { i = copyToken(tokens, i, TT_LABEL, token, (int)(cursor - token)); continue; }
EXPRESSION { i = copyToken(tokens, i, TT_EXPRESSION, token, (int)(cursor - token)); continue; }
DEFAULT { i = copyToken(tokens, i, TT_DEFAULT, token, (int)(cursor - token)); continue; }
WHITE_SPACE { i = copyToken(tokens, i, TT_WHITE_SPACE, token, (int)(cursor - token)); continue; }
END_OF_LINE { i = copyToken(tokens, i, TT_END_OF_LINE, token, (int)(cursor - token)); continue; }