There are some things I neglected to mention in my previous post.
The defining word SUBR creates a variable with no space alloted, but it switches on the assembler. A word created with SUBR returns its address.
The word CFA-ALIGN is only needed for Forth's running on NMOS 6502's or 6510's.
That funny looking word ;S ends loading of a block ( it's an alias for EXIT ).
And since this is for a Commodore 64, just read \ ( backslash ) for each // ( double forward slash ).
Here is the code for new style variables ( VARs ) cleaned up a little:
Code:
SCR# 1076
// VAR -- CODE FOR CODE FIELDS
HEX
: DO.VAR // PRIMARY CODE FIELD
;CODE
CLC,
6 # LDA, W ADC, PHA,
TYA, W 1+ ADC,
PUSH JMP, END-CODE
SUBR TO.VAR
CLC, DEX, DEX,
4 # LDA, W ADC, 0 ,X STA,
TYA, W 1+ ADC, 1 ,X STA,
' ! @ JMP, END-CODE
SUBR AT.VAR
' BL @ JMP, END-CODE
SCR# 1077
// TO AT
HEX
// SET A VAR
: TO ( N -- )
' DUP @ [ ' DO.VAR 4 + ] LITERAL
<> ABORT" NO TO BEHAVIOR"
2+ STATE @
IF , EXIT THEN
EXECUTE ; IMMEDIATE
// GET A VAR'S VALUE
: AT ( -- N )
' DUP @ [ ' DO.VAR 4 + ] LITERAL
<> ABORT" NO AT BEHAVIOR"
2+ 2+ STATE @
IF , EXIT THEN
EXECUTE ; IMMEDIATE
SCR# 1078
// VAR
HEX
: CFA-ALIGN
>IN @ BL WORD // AVOID INDIRECT
SWAP >IN ! // JUMP BUG IN
COUNT + 1 AND // NMOS 6510
ALLOT ; // PROCESSOR
: VAR
CFA-ALIGN CREATE
TO.VAR , AT.VAR ,
0 , DO.VAR ;
;S
CREATE MAKES SURE THE FIRST CFA
DOES NOT STRADDLE A PAGE BOUNDARY.
CFA-ALIGN HANDLES THE OTHER TWO.
SCR# 1079
// 2VAR
HEX
SUBR TO.2VAR
CLC, DEX, DEX,
4 # LDA, W ADC, 0 ,X STA,
TYA, W 1+ ADC, 1 ,X STA,
' 2! @ JMP, END-CODE
SUBR AT.2VAR
CLC, DEX, DEX,
2 # LDA, W ADC, 0 ,X STA,
TYA, W 1+ ADC, 1 ,X STA,
' 2@ @ JMP, END-CODE
: 2VAR
CFA-ALIGN CREATE
TO.2VAR , AT.2VAR ,
0 , 0 , DO.VAR ;
Since ANS Forth uses TO to set the data of a VALUE, if one wanted to ad ANS Forth style VALUEs to Forth:
Code:
: VALUE
CONSTANT ;CODE
' BL @ JMP,
END-CODE
: TO
' DUP VALUE-CFA <> // TEST IF NOT A VALUE
IF [COMPILE] TO EXIT THEN
// PERFORM VALUE RELATED BEHAVIOR
; IMMEDIATE
[Edit: I made some mistakes when changing the code. Sorry, I was away from my desktop. I've corrected the errors. Hopefully. I'm fighting with a weak data connection.]