From 74ae2b8e18176be06a5a2e5050f55a3a0ec16b61 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 29 Jan 2021 09:23:11 -0800 Subject: [PATCH] Adding a default block source --- ueforth/arduino/autoboot.fs | 5 +++++ ueforth/common/blocks.fs | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ueforth/arduino/autoboot.fs b/ueforth/arduino/autoboot.fs index 3f88fa8..fa4c4a4 100644 --- a/ueforth/arduino/autoboot.fs +++ b/ueforth/arduino/autoboot.fs @@ -1,2 +1,7 @@ +( Change default block source on arduino ) +: arduino-default-use s" /spiffs/blocks.fb" open-blocks ; +' arduino-default-use is default-use + +( Check for autoexec.fs and run if present ) : autoexec ( a n -- ) s" /spiffs/autoexec.fs" ['] included catch 2drop drop ; autoexec diff --git a/ueforth/common/blocks.fs b/ueforth/common/blocks.fs index 3d1cc0a..c1ba2b5 100644 --- a/ueforth/common/blocks.fs +++ b/ueforth/common/blocks.fs @@ -5,6 +5,9 @@ create block-data 1024 allot block-fid 0< 0= if block-fid close-file throw -1 to block-fid then 2dup r/w open-file if drop r/w create-file throw else nip nip then to block-fid ; : use ( "name" -- ) bl parse open-blocks ; +: common-default-use s" blocks.fb" open-blocks ; +defer default-use ' common-default-use is default-use +: use?! block-fid 0< if default-use then ; : grow-blocks ( n -- ) 1024 * block-fid file-size throw max block-fid resize-file throw ; : save-buffers block-dirty if @@ -15,13 +18,13 @@ create block-data 1024 allot then ; : clobber-line ( a -- a' ) dup 63 bl fill 63 + nl over c! 1+ ; : clobber ( a -- ) 15 for clobber-line next drop ; -: block ( n -- a ) dup block-id = if drop block-data exit then +: block ( n -- a ) use?! dup block-id = if drop block-data exit then save-buffers dup grow-blocks dup 1024 * block-fid reposition-file throw block-data clobber block-data 1024 block-fid read-file throw drop to block-id block-data ; -: buffer ( n -- a ) dup block-id = if drop block-data exit then +: buffer ( n -- a ) use?! dup block-id = if drop block-data exit then save-buffers to block-id block-data ; : empty-buffers -1 to block-id ; : update -1 to block-dirty ;