Added streams.
This commit is contained in:
@ -72,7 +72,7 @@ $(GEN):
|
|||||||
POSIX_BOOT = common/boot.fs common/terminal.fs \
|
POSIX_BOOT = common/boot.fs common/terminal.fs \
|
||||||
posix/posix.fs posix/posix_highlevel.fs \
|
posix/posix.fs posix/posix_highlevel.fs \
|
||||||
common/filetools.fs posix/posix_desktop.fs \
|
common/filetools.fs posix/posix_desktop.fs \
|
||||||
common/tasks.fs
|
common/tasks.fs common/streams.fs
|
||||||
$(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN)
|
$(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN)
|
||||||
echo "ok" | cat $(POSIX_BOOT) - | $< boot >$@
|
echo "ok" | cat $(POSIX_BOOT) - | $< boot >$@
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ $(GEN)/windows_boot.h: common/source_to_string.js $(WINDOWS_BOOT) | $(GEN)
|
|||||||
|
|
||||||
ARDUINO_BOOT = common/boot.fs arduino/arduino.fs \
|
ARDUINO_BOOT = common/boot.fs arduino/arduino.fs \
|
||||||
posix/posix_highlevel.fs common/filetools.fs \
|
posix/posix_highlevel.fs common/filetools.fs \
|
||||||
common/tasks.fs arduino/arduino_server.fs \
|
common/tasks.fs common/streams.fs arduino/arduino_server.fs \
|
||||||
arduino/autoboot.fs
|
arduino/autoboot.fs
|
||||||
$(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN)
|
$(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN)
|
||||||
echo "ok" | cat $(ARDUINO_BOOT) - | $< boot >$@
|
echo "ok" | cat $(ARDUINO_BOOT) - | $< boot >$@
|
||||||
|
|||||||
20
ueforth/common/streams.fs
Normal file
20
ueforth/common/streams.fs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
( Byte Stream / Ring Buffer )
|
||||||
|
|
||||||
|
: stream ( n "name" ) create 1+ dup , 0 , 0 , allot align ;
|
||||||
|
: >write ( st -- wr ) cell+ ; : >read ( st -- rd ) 2 cells + ;
|
||||||
|
: >offset ( n st -- a ) 3 cells + + ;
|
||||||
|
: stream# ( sz -- n ) >r r@ >write @ r@ >read @ - r> @ mod ;
|
||||||
|
: full? ( st -- f ) dup stream# swap @ 1- = ;
|
||||||
|
: empty? ( st -- f ) stream# 0= ;
|
||||||
|
: wait-write ( st -- ) begin dup full? while pause repeat drop ;
|
||||||
|
: wait-read ( st -- ) begin dup empty? while pause repeat drop ;
|
||||||
|
: ch>stream ( ch st -- )
|
||||||
|
dup wait-write
|
||||||
|
>r r@ >write @ r@ >offset c!
|
||||||
|
r@ >write @ 1+ r@ @ mod r> >write ! ;
|
||||||
|
: stream>ch ( st -- ch )
|
||||||
|
dup wait-read
|
||||||
|
>r r@ >read @ r@ >offset c@
|
||||||
|
r@ >read @ 1+ r@ @ mod r> >read ! ;
|
||||||
|
: >stream ( a n st -- )
|
||||||
|
swap 0 do over c@ over ch>stream swap 1+ swap loop 2drop ;
|
||||||
Reference in New Issue
Block a user