aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Bradley <wmb@firmworks.com>2016-09-23 09:19:19 -1000
committerMitch Bradley <wmb@firmworks.com>2016-09-28 07:05:08 -1000
commit1af3bb8042854435e5f27aab01ce22ee51be99c9 (patch)
treee7d1fdd10cd3b37a87e5eb44533bf02697ec570d
parentcb4aab2014e9b3953cdaac5d292b8bc302eca095 (diff)
downloadcforth-1af3bb8042854435e5f27aab01ce22ee51be99c9.tar.gz
Added {i,j}limit, file-position, reposition-file
-rw-r--r--src/app/esp8266/fileio.c15
-rwxr-xr-xsrc/cforth/embed/consio.c19
-rwxr-xr-xsrc/cforth/forth.c18
-rwxr-xr-xsrc/cforth/forth.h3
-rwxr-xr-xsrc/cforth/io.c12
5 files changed, 64 insertions, 3 deletions
diff --git a/src/app/esp8266/fileio.c b/src/app/esp8266/fileio.c
index 7454403..9acafdf 100644
--- a/src/app/esp8266/fileio.c
+++ b/src/app/esp8266/fileio.c
@@ -118,6 +118,21 @@ pfwrite(void *adr, cell len, void *fid, cell *up)
return 0;
}
+cell
+pfseek(void *fid, u_cell high, u_cell low, cell *up)
+{
+ (void)myspiffs_lseek((int)fid, low, 0);
+ return 0;
+}
+
+cell
+pfposition(void *fid, u_cell *high, u_cell *low, cell *up)
+{
+ *low = myspiffs_tell((int)fid);
+ *high = 0;
+ return 0;
+}
+
void clear_log(cell *up) { }
void start_logging(cell *up) { }
void stop_logging(cell *up) { }
diff --git a/src/cforth/embed/consio.c b/src/cforth/embed/consio.c
index 28437af..91d7875 100755
--- a/src/cforth/embed/consio.c
+++ b/src/cforth/embed/consio.c
@@ -68,20 +68,33 @@ cell freadline(cell f, cell *sp, cell *up) /* Returns IO result */
{
sp[0] = 0;
sp[1] = 0;
- return (READFAIL);
+ return (NOFILEIO);
}
cell
pfread(cell *sp, cell len, void *fid, cell *up) // Returns IO result, actual in *sp
{
sp[0] = 0;
- return (READFAIL);
+ return (NOFILEIO);
}
cell
pfwrite(void *adr, cell len, void *fid, cell *up)
{
- return (WRITEFAIL);
+ return (NOFILEIO);
+}
+
+cell
+pfseek(void *fid, u_cell high, u_cell low, cell *up)
+{
+ return (NOFILEIO);
+}
+
+cell
+pfposition(void *fid, u_cell *high, u_cell *low, cell *up)
+{
+ *high = *low = 0;
+ return (NOFILEIO);
}
void clear_log(cell *up) { }
diff --git a/src/cforth/forth.c b/src/cforth/forth.c
index d331686..8e4840a 100755
--- a/src/cforth/forth.c
+++ b/src/cforth/forth.c
@@ -380,10 +380,18 @@ token_fetch:
push(((cell *)rp)[0] + ((cell *)rp)[1]);
next;
+/*$p ilimit */ case ILIMIT:
+ push(((cell *)rp)[1]);
+ next;
+
/*$p j */ case J:
push(((cell *)rp)[3] + ((cell *)rp)[4]);
next;
+/*$p jlimit */ case JLIMIT:
+ push(((cell *)rp)[4]);
+ next;
+
/*$p branch */ case PBRANCH:
branch;
next;
@@ -1251,6 +1259,16 @@ execute:
tos = pfwrite((void *)tos, scr, ascr, up);
next;
+/*$p reposition-file */ case REPOSITION_FILE: /* ud fid -- ior */
+ tos = pfseek((void *)tos, sp[0], sp[1], up);
+ sp += 2;
+ next;
+
+/*$p file-position */ case FILE_POSITION: /* fid -- ud ior */
+ sp -= 2;
+ tos = pfposition((void *)tos, &sp[0], &sp[1], up);
+ next;
+
/*$p w/o */ case W_O: push(1); next;
/*$p r/w */ case R_W: push(2); next;
/*$p bin */ case BIN: push(4); next;
diff --git a/src/cforth/forth.h b/src/cforth/forth.h
index 5f540a9..f4d7dda 100755
--- a/src/cforth/forth.h
+++ b/src/cforth/forth.h
@@ -47,9 +47,12 @@ extern const struct header builtin_hdr;
#define RESIZEFAIL -19 /* XXX - out of the hat */
#define STATFAIL -20 /* XXX - out of the hat */
#define CREATEFAIL -21 /* XXX - out of the hat */
+#define NOFILEIO -22 /* XXX - out of the hat */
cell pfread(cell *sp, cell len, void *fid, cell *up);
cell pfwrite(void *adr, cell len, void *fid, cell *up);
+cell pfseek(void *fid, u_cell high, u_cell low, cell *up);
+cell pfposition(void *fid, u_cell *high, u_cell *low, cell *up);
cell *init_forth(void);
void init_io(int argc, char **argv, cell *up);
int next_arg(cell *up);
diff --git a/src/cforth/io.c b/src/cforth/io.c
index 8b6cfa9..6bf0ca7 100755
--- a/src/cforth/io.c
+++ b/src/cforth/io.c
@@ -598,3 +598,15 @@ cell pfwrite(void *adr, cell len, void *fid, cell *up) // Returns IO result, ac
return (ret == 0) ? ferror((FILE *)fid) : 0;
}
+cell pfseek(void *fid, u_cell high, u_cell low, cell *up)
+{
+ (void)fseek((FILE *)fid, low, 0);
+ return 0;
+}
+
+cell pfposition(void *fid, u_cell *high, u_cell *low, cell *up)
+{
+ *low = ftell((FILE *)fid);
+ *high = 0;
+ return 0;
+}