Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions tile1/branchops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Module : Branchops
* Author : Steven James
* Date : 26th January 1990
*
* This module implements the branching operations required by the forth
* engine, namely BRANCH JUMP DO LOOP +LOOP.
*
* Functions
* branch_op () jump_op () do_op () loop_op () addloop_op ()
*/

#define BRANCH_OP 600
#define JUMP_OP 601
#define DO_OP 602
#define LOOP_OP 603
#define ADDLOOP_OP 604

/*
* Procedure to perform a relative jump by the value pointed to by the
* instruction register if the top value on the parameter stack is zero.
*/
void branch_op()
{
#ifdef DEBUG
printf("branch opcode\n") ;
#endif
if( pop_ps() == 0 )
i += get_word( i ) ;
else
i += 2 ;
}

/*
* Procedure to perform a relative jump by the value pointed to by the
* instruction register.
*/
void jump_op ()
{
#ifdef DEBUG
printf("else opcode\n") ;
#endif
i += get_word( i ) ;
}

/*
* Procedure to push the top two 16 bit quantities form the parameter
* stack to the return stack.
*/
void do_op()
{
unsigned short top ;
#ifdef DEBUG
printf("do opcode\n") ;
#endif
top = pop_ps() ;
push_rs ( pop_ps () ) ;
push_rs( top ) ;
}

/*
* Procedure to increment the top 16 bit quantity on the return stack, and
* compare it with the second 16 bit quantity. If the second is greater
* than the firsth then a relative backward jump is made, otherwise the
* return stack is decremented and the instruction register is incremented
* to contine normal execution.
*/
void loop_op()
{
short top , bottom ;
#ifdef DEBUG
printf("loop opcode\n") ;
#endif
top = pop_rs() +1 ;
bottom = pop_rs() ;
if( top < bottom )
{
push_rs( bottom ) ;
push_rs( top ) ;
i += get_word( i ) ;
}
else
i += 2 ;
}

/*
* Procedure to increment the top 16 bit quantity on the return stack by
* the top 16 bit quantity on the parameter stack, and compare it with the
* second 16 bit quantity on the return stack. If the increment is negative
* and the first 16 bit quantity is greater than the second, or the
* imcrement is positive and the first 16 bit quantity is smaller than the
* second, then a relative backward jump is made, otherwise the return stack
* is is decremented and the instruction register is incremented to contine
* normal execution.
*/
void addloop_op()
{
short increment , top , bottom ;
#ifdef DEBUG
printf("addloop opcode\n") ;
#endif
top = pop_rs() ;
increment = pop_ps() ;
top += increment ;
bottom = pop_rs() ;
if( ( increment >0 ) && ( top < bottom ) )
{
push_rs( bottom ) ;
push_rs( top ) ;
i += get_word( i ) ;
}
else
{
if( ( increment < 0 ) && ( top > bottom ) )
{
push_rs( bottom ) ;
push_rs( top ) ;
i += get_word( i ) ;
}
else
i += 2 ;
}
}
39 changes: 39 additions & 0 deletions tile1/dataops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Module : dataops.h
* Author : Steven James
* Date : 26th January 1990
*
* This module implements the two data constructs required by the forth
* engine, namely LIT and CONST.
*
* Functions
* lit op() const op()
*/

#define LIT_OP 500
#define CONST_OP 501

/*
* Procedure to push the literal pointed to by the instruction register
* onto the parameter stack, and increment the instruction register.
*/
void lit_op()
{
#ifdef DEBUG
printf("lit opcode\n") ;
#endif
push_ps( get_word( i ) ) ;
i += 2 ;
}

/*
* Procedure to push the constant pointed to be the word address register
* onto the parameter stack.
*/
void const_op()
{
#ifdef DEBUG
printf("const opcode\n") ;
#endif
push_ps ( get_word( wa ) ) ;
}
117 changes: 117 additions & 0 deletions tile1/defineops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Module : defineops.h
* Author : Steven James
* Date : 19th February 1990
*
* This module implements the five defining constructs required by the
* forth engine, namley <BUILDS DOES> CREATE : ; .
*
* Functions
* builds_op() does_op() create_op() define_op() end_op()
*/

#define BUILDS_OP 900
#define DOES_OP 901
#define CREATE_OP 902
#define DEFINE_OP 903
#define END_OP 904

/*
* Procedure to push the the current content of the word address register
* onto the top of th parameter stack as a 16 bit quantity.
*/
void builds_op()
{
#ifdef DEBUG
printf("builds opcode\n") ;
#endif
push_ps ( wa ) ;
}

/*
* Procedure to push the contents of the instruction register onto the top
* of the return stack, set in instruction register to the 16 bit quantity
* pointed to by the contents of the word address register and push the
* nincremented contents of the word address register onto the parameter
* stack as a 16 bit quantity.
*/
void does_op()
{
#ifdef DEBUG
printf("does opcode\n") ;
#endif
push_rs( i ) ;
i = get_word( wa ) ;
push_ps( wa + 2 ) ;
}

/*
* Procedure to construct a header ( ie. the name and link fields ) for the
* the next space delimited string in the text input buffer, and report any
* attempts to redefine an existing word.
*/
void mkheader()
{
push_ps( get_word( get_word( CURRENT ) ) ) ;
push_ps( SPACE ) ;
word_op() ;
push_ps( get_word( DP ) ) ;
push_ps( get_word( get_word( CONTEXT ) ) ) ;
find_op() ;
if ( pop_ps () == FTRUE )
{
printf("'%s' has been redefined.\n" , dp_string() ) ;
drop_op() ;
}
drop_op() ;
put_word( get_word( CURRENT ) , get_word( DP ) ) ;
put_word( DP , get_word( DP ) + get_word( WIDTH ) + 1 ) ;
put_word( get_word( DP ) , pop_ps() ) ;
put_word( DP , get_word( DP ) + 2 ) ;
}

/*
* Procedure to construct a word header from the space delimited string in
* the text input buffer, with the code field address pointing to the
* body of the word.
*/
void create_op()
{
#ifdef DEBUG
printf("create opcode\n") ;
#endif
mkheader() ;
put_word( get_word( DP ) , get_word( DP ) + 2 ) ;
put_word( DP , get_word( DP ) + 2 ) ;
}

/*
* Procedure to construct a colon definition from the space delimited string
* in the text input buffer.
*/
void define_op()
{
#ifdef DEBUG
printf("define opcode\n") ;
#endif
put_word( CONTEXT , get_word( CURRENT ) ) ;
mkheader() ;
put_word( get_word( DP ) , colon_cfa ) ;
put_word( DP , get_word( DP ) + 2 ) ;
put_word( STATE , FTRUE ) ;
}

/*
* Procedure to compile a semi colon and terminate compilation of a colon
* definition by resetting the STATE user variable.
*/
void end_op()
{
#ifdef DEBUG
printf("end opcode\n") ;
#endif
push_ps( semi_cfa ) ;
put_word( get_word( DP ) , pop_ps() ) ;
put_word( DP , get_word( DP ) + 2 ) ;
put_word( STATE , FFALSE ) ;
}
Loading