nanoFORTH v2.2
Loading...
Searching...
No Matches
N4Core Namespace Reference

Functions

void set_pre (const char *code)
 set embedded Forth code
 
void set_io (Stream *s)
 initialize or redirect IO stream
 
void set_hex (U8 f)
 enable/disable hex numeric radix
 
void set_ucase (U8 uc)
 set case sensitiveness
 
char uc (char c)
 
void mstat ()
 display MMU statistics
 
char vkey ()
 
void _console_input ()
 
Console IO Functions with Cooperative Threading support
char key ()
 Arduino's Serial.getchar(), yield to user tasks when waiting.
 
void d_chr (char c)
 print a char to console
 
void d_adr (IU a)
 print a 12-bit address
 
void d_ptr (U8 *p)
 print a pointer
 
void d_num (DU n)
 sent a number literal to console
 
void d_pin (U16 p, U16 v)
 set pin a given pinMode (INPUT, OUTPUT)
 
U16 d_in (U16 p)
 fetch from GPIO port
 
void d_out (U16 p, U16 v)
 send output to GPIO ports
 
U16 a_in (U16 p)
 fetch from analog port
 
void a_out (U16 p, U16 v)
 send output to GPIO ports
 
void d_str (U8 *p)
 handle dot string (byte-stream leading with length)
 
void d_nib (U8 n)
 print a nibble
 
void d_u8 (U8 c)
 print a 8-bit hex number
 
dot_* for Console Input/Output Routines
void d_mem (U8 *base, U8 *p0, IU sz, U8 delim)
 
void d_name (U8 *p)
 print 3 characters name
 
void d_name (U8 op, const char *lst, U8 space)
 
Input buffer Functions
U8 number (U8 *str, DU *num)
 
void clear_tib ()
 reset input buffer
 
U8 ok ()
 check whether input buffer is empty
 
U8get_token (U8 rst=0)
 get a token from console input
 
U8 scan (U8 *tkn, const char *lst, IU *id)
 

Variables

MMU controls
U8 dic [N4_RAM_SZ]
 base of dictionary
 
N4Task vm { NULL, NULL }
 VM context.
 
IO controls
Stream * io { &Serial }
 default to Arduino Serial Monitor
 
U8 trc { 0 }
 tracing control flag
 
char * _pre { NULL }
 preload Forth code
 
U8_tib { &dic[N4_DIC_SZ+N4_STK_SZ] }
 base of terminal input buffer
 
U8 _empty { 1 }
 empty flag for terminal input buffer
 
U8 _hex { 0 }
 numeric radix for display
 
U8 _ucase { 0 }
 empty flag for terminal input buffer
 

Function Documentation

◆ set_pre()

void N4Core::set_pre ( const char *  code)

set embedded Forth code

◆ 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

◆ uc()

char N4Core::uc ( char  c)

< upper case for case-insensitive matching

◆ mstat()

void N4Core::mstat ( )

display MMU statistics

‍show system memory allocation info

‍dictionary size

‍stack size

‍terminal input buf

  • total forth memory block

◆ 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

Variable Documentation

◆ dic

U8 N4Core::dic

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 { &dic[N4_DIC_SZ+N4_STK_SZ] }

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