nanoFORTH v2.2
Loading...
Searching...
No Matches
n4_core.h
Go to the documentation of this file.
1
6#ifndef __SRC_N4_CORE_H
7#define __SRC_N4_CORE_H
8#include "n4.h"
12constexpr U16 N4_DIC_SZ = 0x400;
13constexpr U16 N4_STK_SZ = 0x80;
14constexpr U16 N4_TIB_SZ = 0x80;
17#if ARDUINO
18#define show(s) { io->print(F(s)); io->flush(); }
19#else
20#define show(s) log(s)
21#endif // ARDUINO
36#define ENC8(p, c) (*(U8*)(p)++=(U8)(c))
37#define ENCA(p, a) { IU x=(IU)(a); ENC8(p,(x)>>8); ENC8(p,(x)&0xff); }
38#define GETA(p) (((IU)(*(U8*)(p))<<8) + *((U8*)(p)+1))
39#define STORE(p, v) { DU x=(DU)(v); ENC8(p,(x)>>8); ENC8(p,(x)&0xff); }
40#define FETCH(p) (((DU)(*(U8*)(p))<<8) + *((U8*)(p)+1))
45typedef struct {
46 IU *rp;
47 DU *sp;
48} N4Task;
49
50namespace N4Core
51{
52 extern N4Task vm;
53 extern U8 dic[];
54 extern U8 trc;
55 extern Stream *io;
56
57 void mstat();
58
59 void set_pre(const char *code);
60 void set_io(Stream *s);
61 void set_hex(U8 f);
62 void set_ucase(U8 uc);
63 char uc(char c);
67 char key();
68 void d_chr(char c);
69 void d_adr(IU a);
70 void d_str(U8 *p);
71 void d_ptr(U8 *p);
72 void d_nib(U8 n);
73 void d_u8(U8 c);
74 void d_num(DU n);
75 void d_pin(U16 p, U16 v);
76 U16 d_in(U16 p);
77 void d_out(U16 p, U16 v);
78 void d_mem(
79 U8 *base,
80 U8 *p0,
81 IU sz,
82 U8 delim
83 );
84 void d_name(U8 *p);
85 void d_name(
86 U8 op,
87 const char *lst,
88 U8 space
89 );
90 U16 a_in(U16 p);
91 void a_out(U16 p, U16 v);
96 void clear_tib();
97 U8 ok();
98 U8 *get_token(U8 rst=0);
99 U8 number(
100 U8 *tkn,
101 DU *num
102 );
106 U8 scan(
107 U8 *tkn,
108 const char *lst,
109 IU *id
110 );
112};
113#endif //__SRC_N4_CORE_H
nanoForth main controller
uint16_t U16
16-bit unsigned integer, for return stack, and pointers
Definition n4.h:66
S16 DU
16-bit data unit (CELL)
Definition n4.h:76
U16 IU
16-bit instruction unit (ADDR)
Definition n4.h:75
uint8_t U8
8-bit unsigned integer, for char and short int
Definition n4.h:65
constexpr U16 N4_DIC_SZ
Definition n4_core.h:12
constexpr U16 N4_RAM_SZ
Definition n4_core.h:15
constexpr U16 N4_STK_SZ
Definition n4_core.h:13
constexpr U16 N4_TIB_SZ
Definition n4_core.h:14
Definition n4_core.cpp:18
void d_nib(U8 n)
print a nibble
Definition n4_core.cpp:114
U8 trc
tracing control flag
Definition n4_core.cpp:28
char uc(char c)
Definition n4_core.cpp:40
void d_out(U16 p, U16 v)
send output to GPIO ports
Definition n4_core.cpp:82
void set_pre(const char *code)
set embedded Forth code
Definition n4_core.cpp:36
void d_name(U8 *p)
print 3 characters name
Definition n4_core.cpp:132
void set_ucase(U8 uc)
set case sensitiveness
Definition n4_core.cpp:39
void d_pin(U16 p, U16 v)
set pin a given pinMode (INPUT, OUTPUT)
Definition n4_core.cpp:80
U16 a_in(U16 p)
fetch from analog port
Definition n4_core.cpp:99
void d_chr(char c)
print a char to console
Definition n4_core.cpp:70
void clear_tib()
reset input buffer
Definition n4_core.cpp:172
N4Task vm
VM context.
Definition n4_core.cpp:23
U8 ok()
check whether input buffer is empty
Definition n4_core.cpp:218
void d_num(DU n)
sent a number literal to console
Definition n4_core.cpp:79
void d_u8(U8 c)
print a 8-bit hex number
Definition n4_core.cpp:115
Stream * io
default to Arduino Serial Monitor
Definition n4_core.cpp:27
U8 number(U8 *str, DU *num)
Definition n4_core.cpp:148
void d_str(U8 *p)
handle dot string (byte-stream leading with length)
Definition n4_core.cpp:113
void set_hex(U8 f)
enable/disable hex numeric radix
Definition n4_core.cpp:38
U8 * get_token(U8 rst)
get a token from console input
Definition n4_core.cpp:246
void d_adr(IU a)
print a 12-bit address
Definition n4_core.cpp:77
void d_ptr(U8 *p)
print a pointer
Definition n4_core.cpp:78
void a_out(U16 p, U16 v)
send output to GPIO ports
Definition n4_core.cpp:100
void mstat()
display MMU statistics
Definition n4_core.cpp:46
U16 d_in(U16 p)
fetch from GPIO port
Definition n4_core.cpp:81
char key()
Arduino's Serial.getchar(), yield to user tasks when waiting.
Definition n4_core.cpp:65
U8 scan(U8 *tkn, const char *lst, IU *id)
Definition n4_core.cpp:283
void set_io(Stream *s)
initialize or redirect IO stream
Definition n4_core.cpp:37
void d_mem(U8 *base, U8 *p0, IU sz, U8 delim)
Definition n4_core.cpp:120
U8 dic[N4_RAM_SZ]
base of dictionary
Definition n4_core.cpp:22
Definition n4_core.h:45
IU * rp
base of return stack
Definition n4_core.h:46
DU * sp
top of data stack
Definition n4_core.h:47