mirror of
https://github.com/Russell-S-Harper/COMMON.git
synced 2024-11-23 17:33:58 +00:00
Merge pull request #52 from Russell-S-Harper/development
Added access of DATA section for LDI and SVI.
This commit is contained in:
commit
fa7ebb7794
@ -34,14 +34,14 @@ The meat of the project:
|
|||||||
* `common/common.h`: details of instructions
|
* `common/common.h`: details of instructions
|
||||||
* `common/common.asm`: assembler code for the instructions
|
* `common/common.asm`: assembler code for the instructions
|
||||||
* `common/macros.h`: macros used to define the interpreted byte-code
|
* `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:
|
Auxiliary:
|
||||||
|
|
||||||
* `emulator/*`: 6502 emulator (borrowed Mike Chambers’ Fake6502 CPU emulator v1.1 ©2011)
|
* `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
|
* `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:
|
To build and run:
|
||||||
|
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
XAPP=../xa-pre-process/xapp
|
XAPP=../xa-pre-process/xapp
|
||||||
|
|
||||||
system.obj: common.obj page6.obj
|
system.obj: common.obj appl.obj
|
||||||
cat common.obj page6.obj > system.obj
|
cat common.obj appl.obj > system.obj
|
||||||
|
|
||||||
common.obj: rom.h common.h common.asm
|
common.obj: rom.h common.h common.asm
|
||||||
xa -C -M common.asm -l common.lbl -o common.obj
|
xa -C -M common.asm -l common.lbl -o common.obj
|
||||||
|
|
||||||
page6.obj: rom.h macros.h globals.h page6.src
|
appl.obj: rom.h macros.h globals.h appl.src
|
||||||
cpp -P page6.src | $(XAPP) > page6.asm
|
cpp -P appl.src | $(XAPP) > appl.asm
|
||||||
xa -C -M page6.asm -l page6.lbl -o page6.obj
|
xa -C -M appl.asm -l appl.lbl -o appl.obj
|
||||||
|
|
||||||
globals.h: common.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
|
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:
|
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
|
||||||
|
@ -2,27 +2,31 @@
|
|||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "globals.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)
|
CODE(DEMO)
|
||||||
|
|
||||||
START
|
START
|
||||||
CMN
|
CMN
|
||||||
SET(R0, 9.4662)
|
SET(R0, 9.4662)
|
||||||
SET(R1, 5)
|
SET(R1, SQRT2)
|
||||||
LDI(R7, R1)
|
LDI(R7, R1)
|
||||||
MUL(R7, R7, R7)
|
MUL(R7, R7, R7)
|
||||||
SVI(R1, R0)
|
|
||||||
PSH(R0)
|
PSH(R0)
|
||||||
BRS(FACTORIAL)
|
BRS(FACTORIAL)
|
||||||
POP(R4)
|
POP(R4)
|
||||||
SET(R5, 1)
|
SET(R5, E)
|
||||||
LDI(R6, R5)
|
LDI(R6, R5)
|
||||||
|
SET(R1, ZERO)
|
||||||
|
INR(R1)
|
||||||
|
SVI(R1, R6)
|
||||||
|
LDI(R0, R1)
|
||||||
ESC
|
ESC
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
BEGIN(FACTORIAL)
|
BEGIN(FACTORIAL)
|
||||||
POP(R1)
|
POP(R1)
|
||||||
SET(R2, 3)
|
SET(R2, 1)
|
||||||
MOD(R3, R1, R2)
|
MOD(R3, R1, R2)
|
||||||
SUB(R1, R1, R3)
|
SUB(R1, R1, R3)
|
||||||
_1 TST(R1)
|
_1 TST(R1)
|
||||||
@ -36,9 +40,14 @@ END(FACTORIAL)
|
|||||||
|
|
||||||
END(DEMO)
|
END(DEMO)
|
||||||
|
|
||||||
DATA(WORKING)
|
DATA(_)
|
||||||
PI VALUE(3.14159)
|
|
||||||
E VALUE(2.71828)
|
; preset constants
|
||||||
SQRT2 VALUE(1.41421)
|
DEFINE(PI, 3.14159)
|
||||||
ZERO RESERVE(2)
|
DEFINE(E, 2.71828)
|
||||||
END(WORKING)
|
DEFINE(SQRT2, 1.41421)
|
||||||
|
|
||||||
|
; working space
|
||||||
|
RESERVE(2)
|
||||||
|
|
||||||
|
END(_)
|
@ -78,24 +78,23 @@
|
|||||||
#define EXT(f) .BYTE _EXT_C + (f)
|
#define EXT(f) .BYTE _EXT_C + (f)
|
||||||
|
|
||||||
; header for fixed code or data
|
; 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
|
; 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
|
#define START &_start
|
||||||
|
|
||||||
; header for relocatable data: l(abel) => length of zeroed data, length of preset data
|
; 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 DATA(l) .BYTE _RLC_DT : .WORD _END_##l - _zero, _zero - l : * = * - 5 : l .( : &_data
|
||||||
#define ZERO &_zero
|
|
||||||
|
|
||||||
; initialize v(alue)
|
; define l(abel), v(alue)
|
||||||
#define VALUE(v) .BYTE _SET_V(#v)
|
#define DEFINE(l, v) &l .BYTE _SET_V(#v)
|
||||||
|
|
||||||
; reserve c(ount)
|
; reserve c(ount) & provide an alias for _zero
|
||||||
#define RESERVE(c) * = * + c * 4
|
#define RESERVE(c) &ZERO : &_zero : * = * + (c) * 4
|
||||||
|
|
||||||
; common begin and end
|
; common begin and end
|
||||||
#define BEGIN(l) l .(
|
#define BEGIN(l) l .(
|
||||||
#define END(l) .):_END_##l
|
#define END(l) .) : _END_##l
|
||||||
|
|
||||||
#endif /* __MACROS_H */
|
#endif /* __MACROS_H */
|
||||||
|
@ -27,8 +27,17 @@ int main(int argc, char **argv)
|
|||||||
const char *s = "", *p, *q;
|
const char *s = "", *p, *q;
|
||||||
switch (tokens[i].type)
|
switch (tokens[i].type)
|
||||||
{
|
{
|
||||||
/* Process each _SET_V("<expr>") command */
|
/* Process each _SET_V("<label>") command */
|
||||||
case TT_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 */
|
/* Extract the start and ending indices */
|
||||||
p = strchr(tokens[i].text, '"') + 1;
|
p = strchr(tokens[i].text, '"') + 1;
|
||||||
q = strrchr(tokens[i].text, '"');
|
q = strrchr(tokens[i].text, '"');
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
typedef enum
|
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;
|
} TOKEN_TYPE;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -72,18 +72,25 @@ int tokenizeInput(const char *cursor, TOKEN *tokens)
|
|||||||
|
|
||||||
WHITE_SPACE = BELL | BACKSPACE | HORIZONTAL_TAB | ESCAPE | DELETE | SPACE ;
|
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
|
VALID = DIGIT | LETTER | EXCLAMATION_MARK | DOLLAR_SIGN | PERCENT_SIGN | AMPERSAND
|
||||||
| LEFT_PARENTHESIS | RIGHT_PARENTHESIS | ASTERISK | PLUS_SIGN | HYPHEN_MINUS
|
| LEFT_PARENTHESIS | RIGHT_PARENTHESIS | ASTERISK | PLUS_SIGN | HYPHEN_MINUS
|
||||||
| FULL_STOP | SOLIDUS | LESS_THAN_SIGN | EQUALS_SIGN | GREATER_THAN_SIGN
|
| FULL_STOP | SOLIDUS | LESS_THAN_SIGN | EQUALS_SIGN | GREATER_THAN_SIGN
|
||||||
| LOW_LINE | VERTICAL_LINE | TILDE | WHITE_SPACE ;
|
| 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 = . ;
|
DEFAULT = . ;
|
||||||
|
|
||||||
END_OF_LINE = ( LINE_FEED | VERTICAL_TAB | FORM_FEED | CARRIAGE_RETURN )+ ;
|
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; }
|
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; }
|
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; }
|
END_OF_LINE { i = copyToken(tokens, i, TT_END_OF_LINE, token, (int)(cursor - token)); continue; }
|
||||||
|
Loading…
Reference in New Issue
Block a user