nanoFORTH  v2.2
N4Core Namespace Reference

Functions

void init_mem ()
 initialize MMU More...
 
void set_pre (const char *code)
 set embedded Forth code More...
 
char uc (char c)
 
void mstat ()
 display MMU statistics More...
 
char vkey ()
 
void _console_input ()
 
void set_io (Stream *s)
 initialize or redirect IO stream More...
 
void set_hex (U8 f)
 enable/disable hex numeric radix More...
 
void set_ucase (U8 uc)
 set case sensitiveness More...
 

Function Documentation

◆ init_mem()

void N4Core::init_mem ( )

initialize MMU

< core memory block

  • allocate Forth memory block
  • grows N4_TIB_SZ

◆ set_pre()

void N4Core::set_pre ( const char *  code)

set embedded Forth code

◆ uc()

char N4Core::uc ( char  c)

< upper case for case-insensitive matching

◆ mstat()

void N4Core::mstat ( )

display MMU statistics

show system memory allocation info

  • show init prompt

◆ key()

char N4Core::key ( )

Arduino's Serial.getchar(), yield to user tasks when waiting.

char IO from console i.e. RX/TX

◆ d_chr()

void N4Core::d_chr ( char  c)

print a char to console

◆ d_adr()

void N4Core::d_adr ( IU  a)

print a 12-bit address

◆ d_ptr()

void N4Core::d_ptr ( U8 p)

print a pointer

◆ d_num()

void N4Core::d_num ( DU  n)

sent a number literal to console

◆ d_pin()

void N4Core::d_pin ( U16  p,
U16  v 
)

set pin a given pinMode (INPUT, OUTPUT)

◆ d_in()

U16 N4Core::d_in ( U16  p)

fetch from GPIO port

◆ d_out()

void N4Core::d_out ( U16  p,
U16  v 
)

send output to GPIO ports

  • mask out RX,TX

◆ a_in()

U16 N4Core::a_in ( U16  p)

fetch from analog port

◆ a_out()

void N4Core::a_out ( U16  p,
U16  v 
)

send output to GPIO ports

◆ d_str()

void N4Core::d_str ( U8 p)

handle dot string (byte-stream leading with length)

◆ d_nib()

void N4Core::d_nib ( U8  n)

print a nibble

◆ d_u8()

void N4Core::d_u8 ( U8  c)

print a 8-bit hex number

◆ d_mem()

void N4Core::d_mem ( U8 base,
U8 p0,
IU  sz,
U8  delim 
)

dump byte-stream between pointers with delimiter option

Parameters
basedisplay memory block reference memory pointer (start of dictionary)
p0starting memory pointer
sznumber of bytes to print
delimdelimiter, ' ' for space, 0 for none

◆ d_name() [1/2]

void N4Core::d_name ( U8 p)

print 3 characters name

display the opcode name

◆ d_name() [2/2]

void N4Core::d_name ( U8  op,
const char *  lst,
U8  space 
)
Parameters
opdisplay opcode & 3-char name opcode
lstnanoForth string formatted list
spacedelimiter to append at the end

◆ number()

U8 N4Core::number ( U8 str,
DU num 
)

parse a literal from string

  • digits
  • handle negative sign
  • handle hex number
Parameters
tknprocess a literal from string given token string of a number
numnumber pointer for return value

◆ clear_tib()

void N4Core::clear_tib ( )

reset input buffer

clear terminal input buffer

empty the static tib inside get_token

◆ vkey()

char N4Core::vkey ( )

fill input buffer from console char-by-char til CR or LF hit

capture preload Forth code

feed key() after preload exhausted

◆ _console_input()

void N4Core::_console_input ( )
  • get one char from input stream
  • split on RETURN
  • pad extra space (in case word is 1-char)
  • terminate input string
  • skip empty token
  • backspace
  • prevent buffer overrun (into auto vars)

◆ ok()

U8 N4Core::ok ( )

check whether input buffer is empty

display OK prompt if input buffer is empty

console prompt with stack dump

  • fetch top of heap
  • check stack overflow
  • stack max out
  • dump stack content
  • user input prompt

◆ get_token()

U8 * N4Core::get_token ( U8  rst)

get a token from console input

capture a token from console input buffer

token pointer to input buffer

dot_string flag

  • reset TIB for new input

read from console (with trailing blank)

skip leading spaces

  • handle ( ...) comment, TODO: multi-line

find the end of comment

skip trailing spaces

  • set delimiter
  • count token length
  • optionally print token for debugging
  • skip spaces, advance pointer to next token
  • flag token was dot_string
  • return pointer to token

◆ scan()

U8 N4Core::scan ( U8 tkn,
const char *  lst,
IU id 
)

search keyword in a nanoForth name field list

  • one blank byte padded at the end of input string

scan token from a given string list

Parameters
tknfind token in given string list token to be searched
lststring list to be scanned
idresultant index if found

◆ set_io()

void N4Core::set_io ( Stream *  s)

initialize or redirect IO stream

◆ set_hex()

void N4Core::set_hex ( U8  f)

enable/disable hex numeric radix

◆ set_ucase()

void N4Core::set_ucase ( U8  uc)

set case sensitiveness

Variable Documentation

◆ dic

U8 * N4Core::dic { NULL }

base of dictionary

◆ vm

N4Task N4Core::vm { NULL, NULL }

VM context.

VM state.

◆ io

Stream * N4Core::io { &Serial }

default to Arduino Serial Monitor

◆ trc

U8 N4Core::trc { 0 }

tracing control flag

tracing flag

◆ _pre

char* N4Core::_pre { NULL }

preload Forth code

◆ _tib

U8* N4Core::_tib { NULL }

base of terminal input buffer

◆ _empty

U8 N4Core::_empty { 1 }

empty flag for terminal input buffer

◆ _hex

U8 N4Core::_hex { 0 }

numeric radix for display

◆ _ucase

U8 N4Core::_ucase { 0 }

empty flag for terminal input buffer