From 3f54491d9448e283d6bf9f56547890f16badf750 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Thu, 20 Apr 2023 21:15:58 +0200 Subject: [PATCH 01/54] don't load v --- forth/base.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forth/base.fs b/forth/base.fs index 651693ae..8453f264 100644 --- a/forth/base.fs +++ b/forth/base.fs @@ -183,7 +183,7 @@ hide dodoes .( require..) include require .( open..) include open .( accept..) include accept -.( v..) include v +\ .( v..) include v decimal include turnkey From c6b2591df3b0e4f78caad693903fdfb890ba219f Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 10:37:33 +0200 Subject: [PATCH 02/54] blocks --- Makefile | 2 +- forth/base.fs | 2 ++ forth/block.fs | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 forth/block.fs diff --git a/Makefile b/Makefile index ae09e4fc..cfcf11c6 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ SRC_DIR = forth SRC_NAMES = base debug v asm gfx gfxdemo rnd sin ls turtle fractals \ sprite doloop sys labels mml mmldemo sid spritedemo \ format require compat timer float viceutil turnkey \ - wordlist io open dos see accept + wordlist io open dos see accept block SRCS = $(addprefix $(SRC_DIR)/,$(addsuffix .fs,$(SRC_NAMES))) TEST_SRC_NAMES = test testcore testcoreplus testcoreext tester testsee 1 diff --git a/forth/base.fs b/forth/base.fs index 8453f264..7fe5ca98 100644 --- a/forth/base.fs +++ b/forth/base.fs @@ -185,6 +185,8 @@ hide dodoes .( accept..) include accept \ .( v..) include v +include block + decimal include turnkey cr diff --git a/forth/block.fs b/forth/block.fs new file mode 100644 index 00000000..57e3455f --- /dev/null +++ b/forth/block.fs @@ -0,0 +1,21 @@ +: valid? ( t s -- n ) +swap +dup 0 > over 18 < and if +drop 21 < exit then +dup 17 > over 25 < and if +drop 19 < exit then +dup 24 > over 31 < and if +drop 18 < exit then +dup 30 > over 36 < and if +drop 17 < exit then +drop 0 ; + +: read-block ( n -- ) +( tracks sectors + 1-17 0-20 + 18-24 0-18 + 25-30 0-17 + 31-35 0-16 + total: 683 sectors ) + 2* 2* 1 swap \ t s +; From 1953cf8caf9078b5a86b9f3c2bf99064e7e471e9 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 17:08:33 +0200 Subject: [PATCH 03/54] some progress on BLOCK --- forth/base.fs | 18 +++++++++--------- forth/block.fs | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/forth/base.fs b/forth/base.fs index 7fe5ca98..610bdb90 100644 --- a/forth/base.fs +++ b/forth/base.fs @@ -188,17 +188,17 @@ hide dodoes include block decimal -include turnkey -cr +\ include turnkey +\ cr .( cart: ) -$4000 $6b - \ available ROM -here $801 - \ code + data -top 1+ latest - \ dictionary -$20 + + - \ save-pack padding -. .( bytes remain.) cr +\ $4000 $6b - \ available ROM +\ here $801 - \ code + data +\ top 1+ latest - \ dictionary +\ $20 + + - \ save-pack padding +\ . .( bytes remain.) cr .( save new durexforth..) -save-pack @0:durexforth +\ save-pack @0:durexforth .( ok!) cr -0 $d7ff c! \ for vice -debugcart +\ 0 $d7ff c! \ for vice -debugcart diff --git a/forth/block.fs b/forth/block.fs index 57e3455f..ed2fc72c 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -1,21 +1,29 @@ -: valid? ( t s -- n ) -swap -dup 0 > over 18 < and if -drop 21 < exit then -dup 17 > over 25 < and if -drop 19 < exit then -dup 24 > over 31 < and if -drop 18 < exit then -dup 30 > over 36 < and if -drop 17 < exit then -drop 0 ; +( three block buffers at $c000-$cbff ) -: read-block ( n -- ) -( tracks sectors - 1-17 0-20 - 18-24 0-18 - 25-30 0-17 - 31-35 0-16 - total: 683 sectors ) - 2* 2* 1 swap \ t s +\ buffer block id's +create bbi 0 , 0 c, + +create path 'b' c, 0 , + +: >addr ( slot -- addr ) +$400 * $c000 + ; + +: doload ( n slot -- addr ) +2dup bbi + c! >addr >r 10 /mod +'0' + path 1+ c! +'0' + path 2+ c! +path 3 r@ loadb drop r> ; + +: block ( n -- addr ) +\ if already loaded, return buffer addr +3 0 do dup bbi i + c@ = if +drop i >addr unloop exit +then loop + +\ load to an unused buffer, if possible +3 0 do bbi i + c@ 0= if +i doload unloop exit +then loop + +\ discard a buffer and load it there ; From d8c8c1dca838f93e0c5b381a60832e084dd629b1 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 20:08:25 +0200 Subject: [PATCH 04/54] drop least recently used buffer --- forth/block.fs | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index ed2fc72c..170ecfab 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -3,27 +3,43 @@ \ buffer block id's create bbi 0 , 0 c, +\ last-used timestamps +variable time +create lu 0 , 0 , 0 , + create path 'b' c, 0 , -: >addr ( slot -- addr ) +\ updates last-used timestamp +: touch ( buf -- buf ) +time @ over 2* lu + ! +1 time +! ; + +: >addr ( buf -- addr ) $400 * $c000 + ; -: doload ( n slot -- addr ) +: doload ( n buf -- addr ) 2dup bbi + c! >addr >r 10 /mod '0' + path 1+ c! '0' + path 2+ c! path 3 r@ loadb drop r> ; -: block ( n -- addr ) -\ if already loaded, return buffer addr +: already-loaded ( n -- addr|0 ) 3 0 do dup bbi i + c@ = if -drop i >addr unloop exit -then loop +drop i touch >addr unloop exit +then loop 0 ; -\ load to an unused buffer, if possible +: load-to-unused ( n -- addr|0 ) 3 0 do bbi i + c@ 0= if -i doload unloop exit -then loop +i touch doload unloop exit +then loop 0 ; -\ discard a buffer and load it there -; +: drop-lru ( -- ) +0 lu @ lu 2+ @ < +lu @ lu 4 + @ < and if 0 +else lu 2+ @ lu 4 + @ < if +1 else 2 then then bbi + c! ; + +: block ( n -- addr ) +already-loaded ?dup if exit then +load-to-unused ?dup if exit then +drop-lru load-to-unused ; From 011528a96852eb2e8c970cf18842ec8d5e78c7ea Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 20:13:38 +0200 Subject: [PATCH 05/54] wipe block if file missing --- forth/block.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 170ecfab..eda6ec62 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -19,9 +19,9 @@ $400 * $c000 + ; : doload ( n buf -- addr ) 2dup bbi + c! >addr >r 10 /mod -'0' + path 1+ c! -'0' + path 2+ c! -path 3 r@ loadb drop r> ; +'0' + path 1+ c! '0' + path 2+ c! +path 3 r@ loadb 0= if r@ $400 erase +then r> ; : already-loaded ( n -- addr|0 ) 3 0 do dup bbi i + c@ = if From 944f8674d3bb3303ecdebf79314e6bcf833fea94 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 20:19:11 +0200 Subject: [PATCH 06/54] refactoring: extract >path --- forth/block.fs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index eda6ec62..53dd5239 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -17,9 +17,11 @@ time @ over 2* lu + ! : >addr ( buf -- addr ) $400 * $c000 + ; +: >path ( buf -- ) 10 /mod +'0' + path 1+ c! '0' + path 2+ c! ; + : doload ( n buf -- addr ) -2dup bbi + c! >addr >r 10 /mod -'0' + path 1+ c! '0' + path 2+ c! +2dup bbi + c! >addr >r >path path 3 r@ loadb 0= if r@ $400 erase then r> ; From 8cee2b9a20871276399f565696ed703f74dc8a84 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 20:50:41 +0200 Subject: [PATCH 07/54] added BUFFER --- forth/block.fs | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 53dd5239..49d5151f 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -11,37 +11,40 @@ create path 'b' c, 0 , \ updates last-used timestamp : touch ( buf -- buf ) -time @ over 2* lu + ! -1 time +! ; +time @ over 2* lu + ! 1 time +! ; -: >addr ( buf -- addr ) -$400 * $c000 + ; +: >addr $400 * $c000 + ; : >path ( buf -- ) 10 /mod '0' + path 1+ c! '0' + path 2+ c! ; -: doload ( n buf -- addr ) -2dup bbi + c! >addr >r >path -path 3 r@ loadb 0= if r@ $400 erase -then r> ; +: doload ( blk buf -- addr ) +2dup bbi + c! >addr >r >path path 3 +r@ loadb 0= if r@ $400 erase then r> ; -: already-loaded ( n -- addr|0 ) -3 0 do dup bbi i + c@ = if -drop i touch >addr unloop exit -then loop 0 ; +: already-loaded ( blk -- addr|blk ) +3 0 do dup bbi i + c@ = if drop +i touch >addr unloop exit then loop ; -: load-to-unused ( n -- addr|0 ) +: load-to-unused ( blk -- addr|blk ) 3 0 do bbi i + c@ 0= if -i touch doload unloop exit -then loop 0 ; +i touch doload unloop exit then loop ; + +: pick-unused ( blk -- addr|blk ) +3 0 do bbi i + c@ 0= if bbi i + c! +i touch >addr unloop exit then loop ; : drop-lru ( -- ) -0 lu @ lu 2+ @ < -lu @ lu 4 + @ < and if 0 -else lu 2+ @ lu 4 + @ < if +0 lu @ lu 2+ @ < lu @ lu 4 + @ < and +if 0 else lu 2+ @ lu 4 + @ < if 1 else 2 then then bbi + c! ; -: block ( n -- addr ) -already-loaded ?dup if exit then -load-to-unused ?dup if exit then +: block ( blk -- addr ) +already-loaded dup 0< if exit then +load-to-unused dup 0< if exit then drop-lru load-to-unused ; + +: buffer ( blk -- addr ) +already-loaded dup 0< if exit then +pick-unused dup 0< if exit then +drop-lru pick-unused ; From f914a80ddd6468f3975b4163a15c7b59b41c6243 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 21:01:03 +0200 Subject: [PATCH 08/54] added list --- forth/block.fs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/forth/block.fs b/forth/block.fs index 49d5151f..95bd7fda 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -48,3 +48,7 @@ drop-lru load-to-unused ; already-loaded dup 0< if exit then pick-unused dup 0< if exit then drop-lru pick-unused ; + +: list ( blk -- ) +block dup $400 + swap do +i c@ emit loop ; From acf7a618d3f3326120f838f25c9cd6d50551e47e Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 21:02:34 +0200 Subject: [PATCH 09/54] add empty-buffers --- forth/block.fs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/forth/block.fs b/forth/block.fs index 95bd7fda..79918899 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -52,3 +52,5 @@ drop-lru pick-unused ; : list ( blk -- ) block dup $400 + swap do i c@ emit loop ; + +: empty-buffers bbi 3 erase ; From 0ecb0fea780ecd30e232d75eaa38d6a84840fc78 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 21:10:08 +0200 Subject: [PATCH 10/54] added update --- forth/block.fs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index 79918899..5954cfd2 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -2,6 +2,7 @@ \ buffer block id's create bbi 0 , 0 c, +create updated 0 , 0 c, \ last-used timestamps variable time @@ -11,7 +12,7 @@ create path 'b' c, 0 , \ updates last-used timestamp : touch ( buf -- buf ) -time @ over 2* lu + ! 1 time +! ; +1 time +! time @ over 2* lu + ! ; : >addr $400 * $c000 + ; @@ -54,3 +55,7 @@ block dup $400 + swap do i c@ emit loop ; : empty-buffers bbi 3 erase ; + +: update ( -- ) +3 0 do time @ lu i 2* + @ = if +1 updated i + c! then loop ; From 79de4027327136a8fbe7fdcf3c69079b5a4650fc Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 21:39:49 +0200 Subject: [PATCH 11/54] tidy up --- forth/block.fs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 5954cfd2..b50e0851 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -2,7 +2,7 @@ \ buffer block id's create bbi 0 , 0 c, -create updated 0 , 0 c, +create dirty 0 , 0 c, \ last-used timestamps variable time @@ -16,9 +16,15 @@ create path 'b' c, 0 , : >addr $400 * $c000 + ; -: >path ( buf -- ) 10 /mod +: >path ( blk -- ) #10 /mod '0' + path 1+ c! '0' + path 2+ c! ; +: save-buf ( buf -- ) +dup dirty + c@ 0= if drop exit then +0 over dirty + c! +dup bbi + c@ >path >addr dup $400 + +path 3 saveb ; + : doload ( blk buf -- addr ) 2dup bbi + c! >addr >r >path path 3 r@ loadb 0= if r@ $400 erase then r> ; @@ -36,9 +42,10 @@ i touch doload unloop exit then loop ; i touch >addr unloop exit then loop ; : drop-lru ( -- ) -0 lu @ lu 2+ @ < lu @ lu 4 + @ < and +lu @ lu 2+ @ < lu @ lu 4 + @ < and if 0 else lu 2+ @ lu 4 + @ < if -1 else 2 then then bbi + c! ; +1 else 2 then then dup save-buf +bbi + 0 swap c! ; : block ( blk -- addr ) already-loaded dup 0< if exit then @@ -58,4 +65,9 @@ i c@ emit loop ; : update ( -- ) 3 0 do time @ lu i 2* + @ = if -1 updated i + c! then loop ; +1 dirty i + c! then loop ; + +: save-buffers ( -- ) +0 save-buf 1 save-buf 2 save-buf ; + +: flush save-buffers empty-buffers ; From e77a72738a1179a1d00177c6f64d4f17f1ffad48 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 21:46:04 +0200 Subject: [PATCH 12/54] inline doload --- forth/block.fs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index b50e0851..58e9dc49 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -25,17 +25,15 @@ dup dirty + c@ 0= if drop exit then dup bbi + c@ >path >addr dup $400 + path 3 saveb ; -: doload ( blk buf -- addr ) -2dup bbi + c! >addr >r >path path 3 -r@ loadb 0= if r@ $400 erase then r> ; - : already-loaded ( blk -- addr|blk ) 3 0 do dup bbi i + c@ = if drop i touch >addr unloop exit then loop ; : load-to-unused ( blk -- addr|blk ) -3 0 do bbi i + c@ 0= if -i touch doload unloop exit then loop ; +3 0 do bbi i + c@ 0= if i touch +2dup bbi + c! >addr >r >path path 3 +r@ loadb 0= if r@ $400 erase then r> +unloop exit then loop ; : pick-unused ( blk -- addr|blk ) 3 0 do bbi i + c@ 0= if bbi i + c! From 29431e523b5e93d86024f189b145da17f92fba1d Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 22:54:03 +0200 Subject: [PATCH 13/54] simplify buffer management (no lru) --- forth/block.fs | 58 +++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 58e9dc49..9fc053c9 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -1,20 +1,12 @@ ( three block buffers at $c000-$cbff ) -\ buffer block id's -create bbi 0 , 0 c, +create bbi 0 , 0 c, \ buffer block id's create dirty 0 , 0 c, - -\ last-used timestamps -variable time -create lu 0 , 0 , 0 , - +create curr-buf 0 c, create path 'b' c, 0 , -\ updates last-used timestamp -: touch ( buf -- buf ) -1 time +! time @ over 2* lu + ! ; - -: >addr $400 * $c000 + ; +: >addr ( buf -- addr ) +$400 * $c000 + ; : >path ( blk -- ) #10 /mod '0' + path 1+ c! '0' + path 2+ c! ; @@ -25,35 +17,30 @@ dup dirty + c@ 0= if drop exit then dup bbi + c@ >path >addr dup $400 + path 3 saveb ; -: already-loaded ( blk -- addr|blk ) -3 0 do dup bbi i + c@ = if drop -i touch >addr unloop exit then loop ; +: >buf ( blk -- buf ) 3 mod ; + +: load-blk ( blk -- ) +dup >path >buf >addr >r path 3 +r@ loadb 0= if r@ $400 erase then +r> drop ; -: load-to-unused ( blk -- addr|blk ) -3 0 do bbi i + c@ 0= if i touch -2dup bbi + c! >addr >r >path path 3 -r@ loadb 0= if r@ $400 erase then r> -unloop exit then loop ; +: set-blk ( blk -- addr ) +dup >buf curr-buf c! +dup dup >buf bbi + c! >buf >addr ; -: pick-unused ( blk -- addr|blk ) -3 0 do bbi i + c@ 0= if bbi i + c! -i touch >addr unloop exit then loop ; +: unassign ( blk -- blk ) +dup >buf dup save-buf bbi + 0 swap c! ; -: drop-lru ( -- ) -lu @ lu 2+ @ < lu @ lu 4 + @ < and -if 0 else lu 2+ @ lu 4 + @ < if -1 else 2 then then dup save-buf -bbi + 0 swap c! ; +: loaded? ( blk -- blk flag ) +dup dup >buf bbi + c@ = ; : block ( blk -- addr ) -already-loaded dup 0< if exit then -load-to-unused dup 0< if exit then -drop-lru load-to-unused ; +loaded? if >buf >addr else +unassign dup load-blk set-blk then ; : buffer ( blk -- addr ) -already-loaded dup 0< if exit then -pick-unused dup 0< if exit then -drop-lru pick-unused ; +loaded? if >buf >addr else +unassign set-blk then ; : list ( blk -- ) block dup $400 + swap do @@ -62,8 +49,7 @@ i c@ emit loop ; : empty-buffers bbi 3 erase ; : update ( -- ) -3 0 do time @ lu i 2* + @ = if -1 dirty i + c! then loop ; +1 dirty curr-buf c@ + c! ; : save-buffers ( -- ) 0 save-buf 1 save-buf 2 save-buf ; From 505b7ee832a4012c1e9471684c815f5c46d749df Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 23:03:09 +0200 Subject: [PATCH 14/54] tidy up --- forth/block.fs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 9fc053c9..c1582e3f 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -35,12 +35,11 @@ dup >buf dup save-buf bbi + 0 swap c! ; dup dup >buf bbi + c@ = ; : block ( blk -- addr ) -loaded? if >buf >addr else -unassign dup load-blk set-blk then ; +loaded? 0= if unassign dup load-blk +then set-blk ; : buffer ( blk -- addr ) -loaded? if >buf >addr else -unassign set-blk then ; +loaded? 0= if unassign then set-blk ; : list ( blk -- ) block dup $400 + swap do From ece5ced91a0a7b34bea7292b2da21994f775fcc7 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 23:30:22 +0200 Subject: [PATCH 15/54] allow 3-digit blocks --- forth/block.fs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index c1582e3f..ccebf03d 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -3,24 +3,25 @@ create bbi 0 , 0 c, \ buffer block id's create dirty 0 , 0 c, create curr-buf 0 c, -create path 'b' c, 0 , +create path 'b' c, 3 allot : >addr ( buf -- addr ) $400 * $c000 + ; -: >path ( blk -- ) #10 /mod -'0' + path 1+ c! '0' + path 2+ c! ; +: >path ( blk -- ) +#10 /mod #10 /mod +4 1 do '0' + path i + c! loop ; : save-buf ( buf -- ) dup dirty + c@ 0= if drop exit then 0 over dirty + c! dup bbi + c@ >path >addr dup $400 + -path 3 saveb ; +path 4 saveb ; : >buf ( blk -- buf ) 3 mod ; : load-blk ( blk -- ) -dup >path >buf >addr >r path 3 +dup >path >buf >addr >r path 4 r@ loadb 0= if r@ $400 erase then r> drop ; From aeb29a4f193624d5303b18139c47c5d5f922ca66 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 22 Apr 2023 23:36:28 +0200 Subject: [PATCH 16/54] drop path storage --- forth/block.fs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index ccebf03d..a33d8d7b 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -3,25 +3,24 @@ create bbi 0 , 0 c, \ buffer block id's create dirty 0 , 0 c, create curr-buf 0 c, -create path 'b' c, 3 allot : >addr ( buf -- addr ) $400 * $c000 + ; : >path ( blk -- ) -#10 /mod #10 /mod -4 1 do '0' + path i + c! loop ; +'b' here c! #10 /mod #10 /mod +4 1 do '0' + here i + c! loop ; : save-buf ( buf -- ) dup dirty + c@ 0= if drop exit then 0 over dirty + c! dup bbi + c@ >path >addr dup $400 + -path 4 saveb ; +here 4 saveb ; : >buf ( blk -- buf ) 3 mod ; : load-blk ( blk -- ) -dup >path >buf >addr >r path 4 +dup >path >buf >addr >r here 4 r@ loadb 0= if r@ $400 erase then r> drop ; From 3ef92ee1a3c12cb027de47df518b9c54bc2030e0 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 23 Apr 2023 01:09:09 +0200 Subject: [PATCH 17/54] add TODO comment --- forth/block.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/forth/block.fs b/forth/block.fs index a33d8d7b..0c4d82da 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -12,6 +12,7 @@ $400 * $c000 + ; 4 1 do '0' + here i + c! loop ; : save-buf ( buf -- ) +\ TODO scratch before save dup dirty + c@ 0= if drop exit then 0 over dirty + c! dup bbi + c@ >path >addr dup $400 + From 8f4efd9e36ffe4a9ec2e21b4e62062a99eb8d8f2 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 23 Apr 2023 01:30:17 +0200 Subject: [PATCH 18/54] scratch before save --- forth/block.fs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 0c4d82da..44e3f3a0 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -7,21 +7,31 @@ create curr-buf 0 c, : >addr ( buf -- addr ) $400 * $c000 + ; -: >path ( blk -- ) -'b' here c! #10 /mod #10 /mod -4 1 do '0' + here i + c! loop ; +: >path ( blk dst -- ) +>r 'b' r@ c! #10 /mod #10 /mod +'0' + r@ 1+ c! +'0' + r@ 2+ c! +'0' + r> 3 + c! ; + +: scratch ( blk -- ) +here +'s' over c! 1+ +'0' over c! 1+ +':' over c! 1+ +>path here 7 $f $f open ioabort +$f close ; : save-buf ( buf -- ) -\ TODO scratch before save dup dirty + c@ 0= if drop exit then 0 over dirty + c! -dup bbi + c@ >path >addr dup $400 + -here 4 saveb ; +dup bbi + c@ dup scratch +here >path >addr dup +$400 + here 4 saveb ; : >buf ( blk -- buf ) 3 mod ; : load-blk ( blk -- ) -dup >path >buf >addr >r here 4 +dup here >path >buf >addr >r here 4 r@ loadb 0= if r@ $400 erase then r> drop ; From 15a528ef71740de5dedb36f74c6234745d034bf6 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Thu, 27 Apr 2023 20:56:47 +0200 Subject: [PATCH 19/54] fix empty-buffers --- forth/block.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index 44e3f3a0..d25b3250 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -56,7 +56,8 @@ loaded? 0= if unassign then set-blk ; block dup $400 + swap do i c@ emit loop ; -: empty-buffers bbi 3 erase ; +: empty-buffers ( -- ) +bbi 3 erase dirty 3 erase ; : update ( -- ) 1 dirty curr-buf c@ + c! ; From ed6a5882cee6f40c2fcf5a59dee2a1e8b2e11d46 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 06:26:07 +0200 Subject: [PATCH 20/54] added b-a to allocate blocks --- forth/base.fs | 2 +- forth/block.fs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/forth/base.fs b/forth/base.fs index 610bdb90..ee5ed6d9 100644 --- a/forth/base.fs +++ b/forth/base.fs @@ -185,7 +185,7 @@ hide dodoes .( accept..) include accept \ .( v..) include v -include block +.( block..) include block decimal \ include turnkey diff --git a/forth/block.fs b/forth/block.fs index d25b3250..e87c61ef 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -1,9 +1,23 @@ +require io + ( three block buffers at $c000-$cbff ) create bbi 0 , 0 c, \ buffer block id's create dirty 0 , 0 c, create curr-buf 0 c, +\ block-allocate. returns -1 on success +: b-a ( drive track sector -- flag ) +<# 0 #s bl hold 2drop + 0 #s bl hold 2drop + 0 #s bl hold + 'a' hold + '-' hold + 'b' hold #> +$f $f open ioabort $f chkin ioabort +chrin begin chrin drop readst until +clrchn $f close '0' = ; + : >addr ( buf -- addr ) $400 * $c000 + ; From 78d6168b12475f21e36560cdf59119f7bc9f43e8 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 06:32:53 +0200 Subject: [PATCH 21/54] tidy up comment --- forth/block.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index e87c61ef..1b9b1a36 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -6,7 +6,8 @@ create bbi 0 , 0 c, \ buffer block id's create dirty 0 , 0 c, create curr-buf 0 c, -\ block-allocate. returns -1 on success +\ block-allocate. +\ returns true on success. : b-a ( drive track sector -- flag ) <# 0 #s bl hold 2drop 0 #s bl hold 2drop From eaacf390bac811ea26f970d6f15b43545d53cf34 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 08:20:04 +0200 Subject: [PATCH 22/54] add create-blocks --- forth/block.fs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/forth/block.fs b/forth/block.fs index 1b9b1a36..e4475f56 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -19,6 +19,22 @@ $f $f open ioabort $f chkin ioabort chrin begin chrin drop readst until clrchn $f close '0' = ; +\ Usage: "20 create-blocks" allocates +\ 20 Forth blocks and writes a map +\ file named "blocks". +: create-blocks ( n -- ) +4 * \ # of sectors to allocate +\ 735 = 35 tracks * 21 sectors +here #735 -1 fill +#36 1 do i #18 <> if #21 0 do +$ba c@ j i b-a if +\ write Forth block# to sector map +1- dup 4 / here #21 j 1- * i + + c! +dup 0= if \ all done! +here dup #735 + s" blocks" saveb +unloop unloop exit then then +loop then loop abort" disk full" ; + : >addr ( buf -- addr ) $400 * $c000 + ; From e2886ad8b29d0d6182f0c65c0a5e9d1d5378a3b3 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 09:06:16 +0200 Subject: [PATCH 23/54] leaner map file format --- forth/block.fs | 56 ++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index e4475f56..fe049d25 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -6,6 +6,8 @@ create bbi 0 , 0 c, \ buffer block id's create dirty 0 , 0 c, create curr-buf 0 c, +variable map 0 map ! + \ block-allocate. \ returns true on success. : b-a ( drive track sector -- flag ) @@ -20,51 +22,43 @@ chrin begin chrin drop readst until clrchn $f close '0' = ; \ Usage: "20 create-blocks" allocates -\ 20 Forth blocks and writes a map -\ file named "blocks". +\ 20 Forth blocks = 80 sectors and +\ writes a map file named "blocks". : create-blocks ( n -- ) -4 * \ # of sectors to allocate -\ 735 = 35 tracks * 21 sectors -here #735 -1 fill +4 * here map ! #36 1 do i #18 <> if #21 0 do $ba c@ j i b-a if -\ write Forth block# to sector map -1- dup 4 / here #21 j 1- * i + + c! -dup 0= if \ all done! -here dup #735 + s" blocks" saveb +j c, i c, 1- ?dup 0= if +map @ here s" blocks" saveb unloop unloop exit then then -loop then loop abort" disk full" ; +loop then loop 1 abort" disk full" ; + +: load-map map @ if exit then +here map ! here s" blocks" loadb +0= abort" no blocks" ; : >addr ( buf -- addr ) $400 * $c000 + ; -: >path ( blk dst -- ) ->r 'b' r@ c! #10 /mod #10 /mod -'0' + r@ 1+ c! -'0' + r@ 2+ c! -'0' + r> 3 + c! ; - -: scratch ( blk -- ) -here -'s' over c! 1+ -'0' over c! 1+ -':' over c! 1+ ->path here 7 $f $f open ioabort -$f close ; - : save-buf ( buf -- ) dup dirty + c@ 0= if drop exit then -0 over dirty + c! -dup bbi + c@ dup scratch -here >path >addr dup -$400 + here 4 saveb ; +load-map +\ TODO +\ 0 over dirty + c! +\ dup bbi + c@ dup scratch +\ here >path >addr dup +\ $400 + here 4 saveb +; : >buf ( blk -- buf ) 3 mod ; : load-blk ( blk -- ) -dup here >path >buf >addr >r here 4 -r@ loadb 0= if r@ $400 erase then -r> drop ; +load-map +\ TODO +\ dup here >path >buf >addr >r here 4 +\ r@ loadb 0= if r@ $400 erase then +\ r> drop ; +; : set-blk ( blk -- addr ) dup >buf curr-buf c! From 6716c36572e7a8c4d6cefb5a696899bb96b06d8c Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 09:14:55 +0200 Subject: [PATCH 24/54] safer map loading --- forth/block.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index fe049d25..7bd0199d 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -34,8 +34,8 @@ unloop unloop exit then then loop then loop 1 abort" disk full" ; : load-map map @ if exit then -here map ! here s" blocks" loadb -0= abort" no blocks" ; +here dup s" blocks" loadb +0= abort" no blocks" map ! ; : >addr ( buf -- addr ) $400 * $c000 + ; From c8ccb88aa0f2095b8ad158e8d0b6025082137bc7 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 09:17:38 +0200 Subject: [PATCH 25/54] factoring: extract word --- forth/block.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 7bd0199d..e6ba7a35 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -7,6 +7,7 @@ create dirty 0 , 0 c, create curr-buf 0 c, variable map 0 map ! +: path s" blocks" ; \ block-allocate. \ returns true on success. @@ -29,12 +30,12 @@ clrchn $f close '0' = ; #36 1 do i #18 <> if #21 0 do $ba c@ j i b-a if j c, i c, 1- ?dup 0= if -map @ here s" blocks" saveb +map @ here path saveb unloop unloop exit then then loop then loop 1 abort" disk full" ; : load-map map @ if exit then -here dup s" blocks" loadb +here dup path loadb 0= abort" no blocks" map ! ; : >addr ( buf -- addr ) From 9aa02b2ff9744eb9d86f27b44d3ec44046c0dddb Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 21:15:26 +0200 Subject: [PATCH 26/54] some work on sector loading --- forth/block.fs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index e6ba7a35..38f6c7ea 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -2,7 +2,7 @@ require io ( three block buffers at $c000-$cbff ) -create bbi 0 , 0 c, \ buffer block id's +create bbi -1 , -1 c, \ buf block id's create dirty 0 , 0 c, create curr-buf 0 c, @@ -53,20 +53,31 @@ load-map : >buf ( blk -- buf ) 3 mod ; -: load-blk ( blk -- ) -load-map -\ TODO -\ dup here >path >buf >addr >r here 4 -\ r@ loadb 0= if r@ $400 erase then -\ r> drop ; -; +: load-sector ( dst src -- ) +dup c@ swap 1+ c@ \ dst track sector +s" #" 5 5 open ioabort +<# 0 #s bl hold 2drop + 0 #s bl hold +'0' hold bl hold +'2' hold bl hold +'1' hold 'U' hold #> +$f $f open ioabort 5 chkin ioabort +dup $100 + swap do chrin i c! loop +$f close 5 close clrchn ; + +: load-blk ( blk -- ) load-map + dup >buf >addr swap 4 * map @ + +2dup load-sector swap $100 + swap 2+ +2dup load-sector swap $100 + swap 2+ +2dup load-sector swap $100 + swap 2+ + load-sector ; : set-blk ( blk -- addr ) dup >buf curr-buf c! dup dup >buf bbi + c! >buf >addr ; : unassign ( blk -- blk ) -dup >buf dup save-buf bbi + 0 swap c! ; +dup >buf dup save-buf bbi + -1 swap c! ; : loaded? ( blk -- blk flag ) dup dup >buf bbi + c@ = ; @@ -83,7 +94,7 @@ block dup $400 + swap do i c@ emit loop ; : empty-buffers ( -- ) -bbi 3 erase dirty 3 erase ; +bbi 3 -1 fill dirty 3 erase ; : update ( -- ) 1 dirty curr-buf c@ + c! ; From 6f3ca2b32207fd9dc3745331125c631a9948f4aa Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 22:21:57 +0200 Subject: [PATCH 27/54] seemingly fixed block load --- forth/block.fs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 38f6c7ea..e724282b 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -11,10 +11,11 @@ variable map 0 map ! \ block-allocate. \ returns true on success. -: b-a ( drive track sector -- flag ) +: b-a ( track sector -- flag ) <# 0 #s bl hold 2drop - 0 #s bl hold 2drop 0 #s bl hold + '0' hold + bl hold 'a' hold '-' hold 'b' hold #> @@ -28,8 +29,7 @@ clrchn $f close '0' = ; : create-blocks ( n -- ) 4 * here map ! #36 1 do i #18 <> if #21 0 do -$ba c@ j i b-a if -j c, i c, 1- ?dup 0= if +j i b-a if j c, i c, 1- ?dup 0= if map @ here path saveb unloop unloop exit then then loop then loop 1 abort" disk full" ; @@ -59,8 +59,8 @@ s" #" 5 5 open ioabort <# 0 #s bl hold 2drop 0 #s bl hold '0' hold bl hold -'2' hold bl hold -'1' hold 'U' hold #> +'5' hold ':' hold +'1' hold 'u' hold #> $f $f open ioabort 5 chkin ioabort dup $100 + swap do chrin i c! loop $f close 5 close clrchn ; From d9546041293c8c7d9343a005218e43bd67d5c5c7 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Fri, 28 Apr 2023 22:56:43 +0200 Subject: [PATCH 28/54] shorten error message --- forth/block.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index e724282b..cdb57855 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -32,7 +32,7 @@ clrchn $f close '0' = ; j i b-a if j c, i c, 1- ?dup 0= if map @ here path saveb unloop unloop exit then then -loop then loop 1 abort" disk full" ; +loop then loop 1 abort" full" ; : load-map map @ if exit then here dup path loadb From b74e3b552b41212f96f5c952c2afe75754cea966 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 00:38:57 +0200 Subject: [PATCH 29/54] tidy up; fix load-map error --- forth/block.fs | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index cdb57855..40570867 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -12,30 +12,24 @@ variable map 0 map ! \ block-allocate. \ returns true on success. : b-a ( track sector -- flag ) -<# 0 #s bl hold 2drop - 0 #s bl hold - '0' hold - bl hold - 'a' hold - '-' hold - 'b' hold #> -$f $f open ioabort $f chkin ioabort -chrin begin chrin drop readst until -clrchn $f close '0' = ; +<# 0 #s bl hold 2drop 0 #s bl hold +'0' hold bl hold 'a' hold '-' hold +'b' hold #> $f $f open ioabort +$f chkin ioabort chrin begin chrin drop +readst until clrchn $f close '0' = ; \ Usage: "20 create-blocks" allocates \ 20 Forth blocks = 80 sectors and \ writes a map file named "blocks". : create-blocks ( n -- ) -4 * here map ! -#36 1 do i #18 <> if #21 0 do -j i b-a if j c, i c, 1- ?dup 0= if -map @ here path saveb +4 * here map ! #36 1 do i #18 <> if +#21 0 do j i b-a if j c, i c, 1- +?dup 0= if map @ here path saveb unloop unloop exit then then loop then loop 1 abort" full" ; : load-map map @ if exit then -here dup path loadb +here path here loadb 0= abort" no blocks" map ! ; : >addr ( buf -- addr ) @@ -55,12 +49,9 @@ load-map : load-sector ( dst src -- ) dup c@ swap 1+ c@ \ dst track sector -s" #" 5 5 open ioabort -<# 0 #s bl hold 2drop - 0 #s bl hold -'0' hold bl hold -'5' hold ':' hold -'1' hold 'u' hold #> +s" #" 5 5 open ioabort <# 0 #s bl hold +2drop 0 #s bl hold '0' hold bl hold +'5' hold ':' hold '1' hold 'u' hold #> $f $f open ioabort 5 chkin ioabort dup $100 + swap do chrin i c! loop $f close 5 close clrchn ; From 0c5d9e839881aba7c2f0d5e144e49474dd58bc6c Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 00:59:26 +0200 Subject: [PATCH 30/54] temporarily disable build --- .github/workflows/{build.yml => build.yml.disabled} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{build.yml => build.yml.disabled} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml.disabled similarity index 100% rename from .github/workflows/build.yml rename to .github/workflows/build.yml.disabled From b80d8e155cb2dd614c4aa69cbf6a4a2cc7d88f1a Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 08:22:26 +0200 Subject: [PATCH 31/54] print b-a drive output --- forth/block.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index 40570867..afbf215f 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -15,7 +15,7 @@ variable map 0 map ! <# 0 #s bl hold 2drop 0 #s bl hold '0' hold bl hold 'a' hold '-' hold 'b' hold #> $f $f open ioabort -$f chkin ioabort chrin begin chrin drop +$f chkin ioabort chrin begin chrin emit readst until clrchn $f close '0' = ; \ Usage: "20 create-blocks" allocates From 429c8df9b76b65727fb3c838e95f5f56e88d6acc Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 08:32:27 +0200 Subject: [PATCH 32/54] added TODO comment --- forth/block.fs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index afbf215f..253b4057 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -15,7 +15,11 @@ variable map 0 map ! <# 0 #s bl hold 2drop 0 #s bl hold '0' hold bl hold 'a' hold '-' hold 'b' hold #> $f $f open ioabort -$f chkin ioabort chrin begin chrin emit +$f chkin ioabort +\ TODO: get next free track/sector +\ from the error string. as is, +\ it is way too slow. +chrin begin chrin emit readst until clrchn $f close '0' = ; \ Usage: "20 create-blocks" allocates From 6ade26a6f98a8c0b1d65e9bfb8c74ba02886e40e Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 19:43:29 +0200 Subject: [PATCH 33/54] speed up create-blocks --- forth/block.fs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 253b4057..86a6e10f 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -9,28 +9,34 @@ create curr-buf 0 c, variable map 0 map ! : path s" blocks" ; -\ block-allocate. -\ returns true on success. -: b-a ( track sector -- flag ) -<# 0 #s bl hold 2drop 0 #s bl hold -'0' hold bl hold 'a' hold '-' hold -'b' hold #> $f $f open ioabort -$f chkin ioabort -\ TODO: get next free track/sector -\ from the error string. as is, -\ it is way too slow. -chrin begin chrin emit -readst until clrchn $f close '0' = ; +: get## ( -- n ) +chrin '0' - #10 * chrin '0' - + ; + +variable t variable s + +: b-a ( -- ) \ allocate sector +t @ case #18 of #19 t ! 0 s ! endof +#36 of 1 abort" full" endof endcase +<# s @ 0 #s bl hold 2drop + t @ 0 #s bl hold '0' hold bl hold + 'a' hold '-' hold 'b' hold #> +$f $f open ioabort $f chkin ioabort +get## case 0 of clrchn $f close endof +#65 of \ retry w/ next free sector +#10 0 do chrin drop loop +get## t ! chrin drop get## s ! +clrchn $f close recurse endof +#66 of \ retry w/ next track +0 s ! 1 t +! clrchn $f close recurse +endof endcase ; \ Usage: "20 create-blocks" allocates \ 20 Forth blocks = 80 sectors and \ writes a map file named "blocks". : create-blocks ( n -- ) -4 * here map ! #36 1 do i #18 <> if -#21 0 do j i b-a if j c, i c, 1- -?dup 0= if map @ here path saveb -unloop unloop exit then then -loop then loop 1 abort" full" ; +1 t ! 0 s ! here map ! +4 * 0 do b-a t @ c, s @ c, 1 s +! +loop map @ here path saveb ; : load-map map @ if exit then here path here loadb From 3ce7faec08400b2c563e9f3a6c0e34b2cbd14b74 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 20:27:47 +0200 Subject: [PATCH 34/54] simplify code --- forth/block.fs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 86a6e10f..f05c1136 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -21,14 +21,13 @@ t @ case #18 of #19 t ! 0 s ! endof t @ 0 #s bl hold '0' hold bl hold 'a' hold '-' hold 'b' hold #> $f $f open ioabort $f chkin ioabort -get## case 0 of clrchn $f close endof -#65 of \ retry w/ next free sector +get## case #65 of \ no block #10 0 do chrin drop loop get## t ! chrin drop get## s ! clrchn $f close recurse endof -#66 of \ retry w/ next track +#66 of \ illegal track/sector 0 s ! 1 t +! clrchn $f close recurse -endof endcase ; +endof endcase clrchn $f close ; \ Usage: "20 create-blocks" allocates \ 20 Forth blocks = 80 sectors and @@ -48,8 +47,8 @@ $400 * $c000 + ; : save-buf ( buf -- ) dup dirty + c@ 0= if drop exit then load-map +0 over dirty + c! \ TODO -\ 0 over dirty + c! \ dup bbi + c@ dup scratch \ here >path >addr dup \ $400 + here 4 saveb From c29b7b75ca0e95f7fc8da3b197ec5bf1deb5579d Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 21:23:28 +0200 Subject: [PATCH 35/54] simplify disk full check --- forth/block.fs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index f05c1136..5c102081 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -15,8 +15,6 @@ chrin '0' - #10 * chrin '0' - + ; variable t variable s : b-a ( -- ) \ allocate sector -t @ case #18 of #19 t ! 0 s ! endof -#36 of 1 abort" full" endof endcase <# s @ 0 #s bl hold 2drop t @ 0 #s bl hold '0' hold bl hold 'a' hold '-' hold 'b' hold #> @@ -26,6 +24,7 @@ get## case #65 of \ no block get## t ! chrin drop get## s ! clrchn $f close recurse endof #66 of \ illegal track/sector +s @ 0= abort" full" 0 s ! 1 t +! clrchn $f close recurse endof endcase clrchn $f close ; From 2d3968932ca50ea7e5932e1f48f720b06c8e2ff2 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 22:20:41 +0200 Subject: [PATCH 36/54] bugfix load-blk --- forth/block.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index 5c102081..4e5430b6 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -65,7 +65,7 @@ dup $100 + swap do chrin i c! loop $f close 5 close clrchn ; : load-blk ( blk -- ) load-map - dup >buf >addr swap 4 * map @ + + dup >buf >addr swap 8 * map @ + 2dup load-sector swap $100 + swap 2+ 2dup load-sector swap $100 + swap 2+ 2dup load-sector swap $100 + swap 2+ From 5b4305103fbf580995bbcfc457cb134bfa2ba693 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 22:34:48 +0200 Subject: [PATCH 37/54] add decimal for number formatting, tidy up --- forth/block.fs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 4e5430b6..5668fee2 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -15,9 +15,9 @@ chrin '0' - #10 * chrin '0' - + ; variable t variable s : b-a ( -- ) \ allocate sector -<# s @ 0 #s bl hold 2drop - t @ 0 #s bl hold '0' hold bl hold - 'a' hold '-' hold 'b' hold #> +decimal <# s @ 0 #s bl hold 2drop +t @ 0 #s bl hold '0' hold bl hold +'a' hold '-' hold 'b' hold #> $f $f open ioabort $f chkin ioabort get## case #65 of \ no block #10 0 do chrin drop loop @@ -56,7 +56,7 @@ load-map : >buf ( blk -- buf ) 3 mod ; : load-sector ( dst src -- ) -dup c@ swap 1+ c@ \ dst track sector +decimal dup c@ swap 1+ c@ \ dst t s s" #" 5 5 open ioabort <# 0 #s bl hold 2drop 0 #s bl hold '0' hold bl hold '5' hold ':' hold '1' hold 'u' hold #> @@ -64,12 +64,10 @@ $f $f open ioabort 5 chkin ioabort dup $100 + swap do chrin i c! loop $f close 5 close clrchn ; -: load-blk ( blk -- ) load-map - dup >buf >addr swap 8 * map @ + -2dup load-sector swap $100 + swap 2+ -2dup load-sector swap $100 + swap 2+ -2dup load-sector swap $100 + swap 2+ - load-sector ; +: load-blk ( blk -- ) +load-map dup 8 * map @ + swap >buf +>addr dup $400 + swap do i over +load-sector 2+ $100 +loop drop ; : set-blk ( blk -- addr ) dup >buf curr-buf c! From 7574d2693e53eac23d6e0732c15f9ebe25f0ff77 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sat, 29 Apr 2023 22:56:07 +0200 Subject: [PATCH 38/54] simplify code --- forth/block.fs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 5668fee2..b6f37da4 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -55,8 +55,7 @@ load-map : >buf ( blk -- buf ) 3 mod ; -: load-sector ( dst src -- ) -decimal dup c@ swap 1+ c@ \ dst t s +: read-sector ( dst t s -- ) decimal s" #" 5 5 open ioabort <# 0 #s bl hold 2drop 0 #s bl hold '0' hold bl hold '5' hold ':' hold '1' hold 'u' hold #> @@ -66,8 +65,8 @@ $f close 5 close clrchn ; : load-blk ( blk -- ) load-map dup 8 * map @ + swap >buf ->addr dup $400 + swap do i over -load-sector 2+ $100 +loop drop ; +>addr dup $400 + swap do i over @ +split read-sector 2+ $100 +loop drop ; : set-blk ( blk -- addr ) dup >buf curr-buf c! From 5ded1ecf33eb3d15570d04bc5af5c08a0769e4ff Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 30 Apr 2023 00:08:57 +0200 Subject: [PATCH 39/54] implement block save --- forth/block.fs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index b6f37da4..a9cbc1be 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -43,15 +43,24 @@ here path here loadb : >addr ( buf -- addr ) $400 * $c000 + ; +: write-sector ( t s src -- ) decimal +s" #" 5 5 open ioabort +s" b-p 5 0" $f $f open ioabort +5 chkout ioabort +dup $100 + swap do i c@ emit loop +$f chkout ioabort +<# $d hold 0 #s 2drop bl hold 0 #s +bl hold '0' hold bl hold '5' hold +bl hold '2' hold 'u' hold #> type +clrchn $f close 5 close ; + : save-buf ( buf -- ) dup dirty + c@ 0= if drop exit then -load-map -0 over dirty + c! -\ TODO -\ dup bbi + c@ dup scratch -\ here >path >addr dup -\ $400 + here 4 saveb -; +load-map 0 over dirty + c! +dup bbi + c@ 8 * map @ + +swap >addr dup $400 + swap do +dup @ split i write-sector +2+ $100 +loop drop ; : >buf ( blk -- buf ) 3 mod ; From 00170ad8f511113e1fef2b4e310d6ffa26b9e950 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 30 Apr 2023 00:41:13 +0200 Subject: [PATCH 40/54] save a byte --- forth/block.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index a9cbc1be..6e06de8f 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -67,7 +67,7 @@ dup @ split i write-sector : read-sector ( dst t s -- ) decimal s" #" 5 5 open ioabort <# 0 #s bl hold 2drop 0 #s bl hold '0' hold bl hold -'5' hold ':' hold '1' hold 'u' hold #> +'5' hold bl hold '1' hold 'u' hold #> $f $f open ioabort 5 chkin ioabort dup $100 + swap do chrin i c! loop $f close 5 close clrchn ; From e19160bef73f769956d88d9fff6f5001b3763122 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 30 Apr 2023 10:31:17 +0200 Subject: [PATCH 41/54] add BLK --- asm/io.asm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/asm/io.asm b/asm/io.asm index f9ee6aff..d91aa684 100644 --- a/asm/io.asm +++ b/asm/io.asm @@ -1,4 +1,4 @@ -; EMIT PAGE RVS CR TYPE KEY? KEY REFILL SOURCE SOURCE-ID >IN CHAR IOABORT +; EMIT PAGE RVS CR TYPE KEY? KEY REFILL SOURCE SOURCE-ID >IN BLK CHAR IOABORT +BACKLINK "emit", 4 EMIT @@ -202,6 +202,12 @@ TO_IN TO_IN_W !word 0 + +BACKLINK "blk", 3 +BLK + +VALUE BLK_W +BLK_W + !word 0 + +BACKLINK "char", 4 CHAR ; ( name -- char ) - jsr PARSE_NAME From 0006ddfdfd25257821a1e2ac07a41bf812a6d5bb Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 30 Apr 2023 10:36:43 +0200 Subject: [PATCH 42/54] made block numbers start at 1 again (standard) --- forth/block.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 6e06de8f..fb28394c 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -2,7 +2,7 @@ require io ( three block buffers at $c000-$cbff ) -create bbi -1 , -1 c, \ buf block id's +create bbi 0 , 0 c, \ buf block id's create dirty 0 , 0 c, create curr-buf 0 c, @@ -57,7 +57,7 @@ clrchn $f close 5 close ; : save-buf ( buf -- ) dup dirty + c@ 0= if drop exit then load-map 0 over dirty + c! -dup bbi + c@ 8 * map @ + +dup bbi + c@ 1- 8 * map @ + swap >addr dup $400 + swap do dup @ split i write-sector 2+ $100 +loop drop ; @@ -73,7 +73,7 @@ dup $100 + swap do chrin i c! loop $f close 5 close clrchn ; : load-blk ( blk -- ) -load-map dup 8 * map @ + swap >buf +load-map dup 1- 8 * map @ + swap >buf >addr dup $400 + swap do i over @ split read-sector 2+ $100 +loop drop ; @@ -82,7 +82,7 @@ dup >buf curr-buf c! dup dup >buf bbi + c! >buf >addr ; : unassign ( blk -- blk ) -dup >buf dup save-buf bbi + -1 swap c! ; +dup >buf dup save-buf bbi + 0 swap c! ; : loaded? ( blk -- blk flag ) dup dup >buf bbi + c@ = ; @@ -99,7 +99,7 @@ block dup $400 + swap do i c@ emit loop ; : empty-buffers ( -- ) -bbi 3 -1 fill dirty 3 erase ; +bbi 3 erase dirty 3 erase ; : update ( -- ) 1 dirty curr-buf c@ + c! ; From 138c1620db2665e6f06bf5995aa737f3ab553ab8 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 30 Apr 2023 22:55:19 +0200 Subject: [PATCH 43/54] push/pop BLK --- asm/io.asm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/asm/io.asm b/asm/io.asm index ee21022c..dfa24920 100644 --- a/asm/io.asm +++ b/asm/io.asm @@ -215,7 +215,7 @@ CHAR ; ( name -- char ) jmp FETCHBYTE SAVE_INPUT_STACK - !fill 8*5 + !fill 9*5 SAVE_INPUT_STACK_DEPTH !byte 0 @@ -235,6 +235,8 @@ pop_input_stack rts PUSH_INPUT_SOURCE + lda BLK_W + jsr push_input_stack lda TO_IN_W jsr push_input_stack lda TO_IN_W+1 @@ -269,6 +271,8 @@ POP_INPUT_SOURCE sta TO_IN_W+1 jsr pop_input_stack sta TO_IN_W + jsr pop_input_stack + sta BLK_W rts ; handle errors returned by open, From 77bd3473e2b314a74e3ee0618526702026f3c2a8 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 00:44:36 +0200 Subject: [PATCH 44/54] start work on LOAD --- asm/io.asm | 25 +++++++++++++++++++++++++ forth/base.fs | 16 ++++++++-------- forth/block.fs | 2 ++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/asm/io.asm b/asm/io.asm index dfa24920..f48876f8 100644 --- a/asm/io.asm +++ b/asm/io.asm @@ -1,4 +1,5 @@ ; EMIT PAGE RVS CR TYPE KEY? KEY REFILL SOURCE SOURCE-ID >IN BLK CHAR IOABORT +; BLOCK-XT LOAD +BACKLINK "emit", 4 EMIT @@ -329,3 +330,27 @@ IOABORT ; ( ioresult -- ) .cr_abort jsr CR jmp ABORT + + +BACKLINK "block-xt", 8 + +VALUE BLOCK_XT_ADDR + + +BACKLINK "load", 4 + jsr PUSH_INPUT_SOURCE + jsr DUP + jsr BLK + jsr STORE + jsr ZERO + jsr TO_IN + jsr STORE +BLOCK_XT_ADDR = * + 1 + jsr PLACEHOLDER_ADDRESS + lda LSB,x + sta TIB_PTR + lda MSB,x + sta TIB_PTR + 1 + inx + lda #0 + sta TIB_SIZE + lda #4 + sta TIB_SIZE + 1 + rts diff --git a/forth/base.fs b/forth/base.fs index ee5ed6d9..e8f954d8 100644 --- a/forth/base.fs +++ b/forth/base.fs @@ -188,17 +188,17 @@ hide dodoes .( block..) include block decimal -\ include turnkey -\ cr +include turnkey +cr .( cart: ) -\ $4000 $6b - \ available ROM -\ here $801 - \ code + data -\ top 1+ latest - \ dictionary -\ $20 + + - \ save-pack padding -\ . .( bytes remain.) cr +$4000 $6b - \ available ROM +here $801 - \ code + data +top 1+ latest - \ dictionary +$20 + + - \ save-pack padding +. .( bytes remain.) cr .( save new durexforth..) -\ save-pack @0:durexforth +save-pack @0:durexforth .( ok!) cr \ 0 $d7ff c! \ for vice -debugcart diff --git a/forth/block.fs b/forth/block.fs index fb28394c..9f51e08d 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -91,6 +91,8 @@ dup dup >buf bbi + c@ = ; loaded? 0= if unassign dup load-blk then set-blk ; +' block block-xt ! + : buffer ( blk -- addr ) loaded? 0= if unassign then set-blk ; From d4b32a03c4e4d57c78aa0ec7302b7c1bfbba812b Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 08:39:13 +0200 Subject: [PATCH 45/54] start work on save/restore BLK --- asm/io.asm | 29 ++++++++++++++++++++++------- forth/block.fs | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/asm/io.asm b/asm/io.asm index f48876f8..8b4fc13b 100644 --- a/asm/io.asm +++ b/asm/io.asm @@ -65,15 +65,29 @@ REFILL_OR_CLOSE ; ( -- ) CLOSE_INPUT_SOURCE stx W + lda BLK_W + bne .pop_source lda SOURCE_ID_LSB jsr CLOSE +.pop_source jsr POP_INPUT_SOURCE + lda BLK_W + bne .select_block ldx SOURCE_ID_LSB - beq + + beq .select_keyboard jsr CHKIN - jmp ++ -+ jsr CLRCHN -++ ldx W + jmp .return +.select_block + dex + sta LSB,x + lda #0 + sta MSB,x + jsr BLOCK + jmp .return +.select_keyboard + jsr CLRCHN +.return + ldx W rts .return_false @@ -332,7 +346,9 @@ IOABORT ; ( ioresult -- ) jmp ABORT +BACKLINK "block-xt", 8 - +VALUE BLOCK_XT_ADDR + +VALUE BLOCK + 1 +BLOCK + jmp PLACEHOLDER_ADDRESS +BACKLINK "load", 4 jsr PUSH_INPUT_SOURCE @@ -342,8 +358,7 @@ IOABORT ; ( ioresult -- ) jsr ZERO jsr TO_IN jsr STORE -BLOCK_XT_ADDR = * + 1 - jsr PLACEHOLDER_ADDRESS + jsr BLOCK lda LSB,x sta TIB_PTR lda MSB,x diff --git a/forth/block.fs b/forth/block.fs index 9f51e08d..eb6feb7d 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -110,3 +110,24 @@ bbi 3 erase dirty 3 erase ; 0 save-buf 1 save-buf 2 save-buf ; : flush save-buffers empty-buffers ; + +\ --- testing + +: b" ( dst -- ) +>r '"' parse +begin ?dup while +over r@ swap c! +/string r> 1+ >r +repeat r> 2drop ; + +.( 20 create-blocks) +20 create-blocks +.( 1 block) cr +1 block +b" '1' emit 2 block load '1' emit" +.( 2 block) cr +2 block +b" '2' emit" +.( 1 load) cr +1 load +.( done) cr From d6536e5eb03a0825361d65781b0d18c8842166b5 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 14:18:18 +0200 Subject: [PATCH 46/54] some work on testing --- forth/block.fs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index eb6feb7d..8b12e9f7 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -113,21 +113,11 @@ bbi 3 erase dirty 3 erase ; \ --- testing -: b" ( dst -- ) ->r '"' parse -begin ?dup while -over r@ swap c! -/string r> 1+ >r -repeat r> 2drop ; - -.( 20 create-blocks) -20 create-blocks -.( 1 block) cr -1 block -b" '1' emit 2 block load '1' emit" -.( 2 block) cr -2 block -b" '2' emit" -.( 1 load) cr -1 load -.( done) cr +: b! ( addr u dst -- ) +tuck + swap do +dup c@ i c! 1+ loop drop ; + +: test 3 create-blocks +s" 'o' emit 2 load '!' emit cr" +1 block b! s" 'k' emit" +2 block b! 1 load ; From 0c102bbb8e30e36e93835485df10dfd873b68ae6 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 15:49:36 +0200 Subject: [PATCH 47/54] LOAD 100% --- asm/interpreter.asm | 8 +++----- asm/io.asm | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/asm/interpreter.asm b/asm/interpreter.asm index 56b3eb22..126aee78 100644 --- a/asm/interpreter.asm +++ b/asm/interpreter.asm @@ -123,17 +123,15 @@ interpret_tib cmp TIB_SIZE + 1 bne interpret_tib - ; 0 - keyboard, -1 evaluate, else file - lda SOURCE_ID_LSB - beq + - rts -+ lda LATEST_LSB + lda LATEST_LSB sec sbc HERE_LSB lda LATEST_MSB sbc HERE_MSB beq .on_data_underflow lda STATE + ora SOURCE_ID_LSB + ora BLK_W bne + lda #'o' jsr PUTCHR diff --git a/asm/io.asm b/asm/io.asm index 8b4fc13b..4e2ebb72 100644 --- a/asm/io.asm +++ b/asm/io.asm @@ -368,4 +368,5 @@ BLOCK sta TIB_SIZE lda #4 sta TIB_SIZE + 1 - rts + jsr interpret_tib + jmp POP_INPUT_SOURCE From 410f9afaf459dd578733edf755b90c9bfbf9d1d0 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 19:12:16 +0200 Subject: [PATCH 48/54] made test-load pass --- asm/io.asm | 29 +++++++++++++---------------- forth/block.fs | 23 +++++++++++++++-------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/asm/io.asm b/asm/io.asm index 4e2ebb72..dc38696d 100644 --- a/asm/io.asm +++ b/asm/io.asm @@ -65,29 +65,26 @@ REFILL_OR_CLOSE ; ( -- ) CLOSE_INPUT_SOURCE stx W - lda BLK_W - bne .pop_source lda SOURCE_ID_LSB jsr CLOSE -.pop_source jsr POP_INPUT_SOURCE lda BLK_W - bne .select_block + bne .restore_block ldx SOURCE_ID_LSB - beq .select_keyboard + beq .restore_keyboard jsr CHKIN - jmp .return -.select_block - dex - sta LSB,x - lda #0 - sta MSB,x - jsr BLOCK - jmp .return -.select_keyboard + jmp .ret +.restore_keyboard jsr CLRCHN -.return +.ret + ldx W + rts +.restore_block ldx W + jsr BLK + jsr FETCH + jsr BLOCK + inx ; assume block buffer address is unchanged rts .return_false @@ -369,4 +366,4 @@ BLOCK lda #4 sta TIB_SIZE + 1 jsr interpret_tib - jmp POP_INPUT_SOURCE + jmp CLOSE_INPUT_SOURCE diff --git a/forth/block.fs b/forth/block.fs index 8b12e9f7..b5e56520 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -113,11 +113,18 @@ bbi 3 erase dirty 3 erase ; \ --- testing -: b! ( addr u dst -- ) -tuck + swap do -dup c@ i c! 1+ loop drop ; - -: test 3 create-blocks -s" 'o' emit 2 load '!' emit cr" -1 block b! s" 'k' emit" -2 block b! 1 load ; +: test-load +4 create-blocks 0 +s" 1 2 load 7" 1 block swap move update +s" 2 3 load 6" 2 block swap move update +s" 3 4 load 5" 3 block swap move update +s" 4" 4 block swap move update +1 load +7 <> abort" 7" +6 <> abort" 6" +5 <> abort" 5" +4 <> abort" 4" +3 <> abort" 3" +2 <> abort" 2" +1 <> abort" 1" +0 <> abort" 0" ; From 541dde9f0b8bf0bc3ac1bcec49a168c0b5564423 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 20:19:44 +0200 Subject: [PATCH 49/54] allocate 11 block buffers --- forth/block.fs | 24 ++++++++++++++---------- manual/memmap.adoc | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index b5e56520..965b190a 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -1,9 +1,13 @@ require io -( three block buffers at $c000-$cbff ) - -create bbi 0 , 0 c, \ buf block id's -create dirty 0 , 0 c, +( 11 block buffers at $a000-$cbff. + this may be excessive, let's + shrink it once v is replaced with + a block-based editor. ) + +\ buf block id's +create bbi 0 , 0 , 0 , 0 , 0 , 0 c, +create dirty 0 , 0 , 0 , 0 , 0 , 0 c, create curr-buf 0 c, variable map 0 map ! @@ -41,7 +45,7 @@ here path here loadb 0= abort" no blocks" map ! ; : >addr ( buf -- addr ) -$400 * $c000 + ; +$400 * $a000 + ; : write-sector ( t s src -- ) decimal s" #" 5 5 open ioabort @@ -62,7 +66,7 @@ swap >addr dup $400 + swap do dup @ split i write-sector 2+ $100 +loop drop ; -: >buf ( blk -- buf ) 3 mod ; +: >buf ( blk -- buf ) #11 mod ; : read-sector ( dst t s -- ) decimal s" #" 5 5 open ioabort <# 0 #s bl hold @@ -101,17 +105,17 @@ block dup $400 + swap do i c@ emit loop ; : empty-buffers ( -- ) -bbi 3 erase dirty 3 erase ; +bbi #11 erase dirty #11 erase ; : update ( -- ) 1 dirty curr-buf c@ + c! ; : save-buffers ( -- ) -0 save-buf 1 save-buf 2 save-buf ; +11 0 do i save-buf loop ; : flush save-buffers empty-buffers ; -\ --- testing +( --- testing : test-load 4 create-blocks 0 @@ -127,4 +131,4 @@ s" 4" 4 block swap move update 3 <> abort" 3" 2 <> abort" 2" 1 <> abort" 1" -0 <> abort" 0" ; +0 <> abort" 0" ; ) diff --git a/manual/memmap.adoc b/manual/memmap.adoc index 9c16fe23..d3384b94 100644 --- a/manual/memmap.adoc +++ b/manual/memmap.adoc @@ -10,7 +10,7 @@ $35b - $3d9 :: `pad` Scratch pad memory, Cassette Buffer, untouched by DurexFort $3da - $3fb :: `#>` buffer. $801 - here :: Forth Kernel followed by code and data space. latest - $9fff :: Dictionary. Grows downwards as needed. -$a000 - $cbff :: Editor text buffer. +$a000 - $cbff :: Editor text buffer / Block buffers. $cc00 - $cfff :: Hi-res graphics colors. $d000 - $dfff :: I/O area. $e000 - $ffff :: Kernal / hi-res graphics bitmap. From 15a17750b8294db8ce1e33c66fb7984ac72fc54d Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 20:39:12 +0200 Subject: [PATCH 50/54] hide private block words --- forth/block.fs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index 965b190a..8eac5dfe 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -1,5 +1,17 @@ require io +marker ---block--- + +header block +header buffer +header empty-buffers +header flush +header list +header save-buffers +header update + +latest \ hide words + ( 11 block buffers at $a000-$cbff. this may be excessive, let's shrink it once v is replaced with @@ -91,29 +103,31 @@ dup >buf dup save-buf bbi + 0 swap c! ; : loaded? ( blk -- blk flag ) dup dup >buf bbi + c@ = ; -: block ( blk -- addr ) +define block ( blk -- addr ) loaded? 0= if unassign dup load-blk then set-blk ; ' block block-xt ! -: buffer ( blk -- addr ) +define buffer ( blk -- addr ) loaded? 0= if unassign then set-blk ; -: list ( blk -- ) +define list ( blk -- ) block dup $400 + swap do i c@ emit loop ; -: empty-buffers ( -- ) +define empty-buffers ( -- ) bbi #11 erase dirty #11 erase ; -: update ( -- ) +define update ( -- ) 1 dirty curr-buf c@ + c! ; -: save-buffers ( -- ) +define save-buffers ( -- ) 11 0 do i save-buf loop ; -: flush save-buffers empty-buffers ; +define flush save-buffers empty-buffers ; + +to latest \ end hiding words ( --- testing From 1aecc815e96d69337388d4a5eddc55a80a4e96c5 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 22:24:19 +0200 Subject: [PATCH 51/54] fix create-blocks --- forth/block.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/forth/block.fs b/forth/block.fs index 8eac5dfe..d8c10cc0 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -4,6 +4,7 @@ marker ---block--- header block header buffer +header create-blocks header empty-buffers header flush header list @@ -47,7 +48,8 @@ endof endcase clrchn $f close ; \ Usage: "20 create-blocks" allocates \ 20 Forth blocks = 80 sectors and \ writes a map file named "blocks". -: create-blocks ( n -- ) +define create-blocks ( n -- ) +path here loadb abort" exist" 1 t ! 0 s ! here map ! 4 * 0 do b-a t @ c, s @ c, 1 s +! loop map @ here path saveb ; From 1d28d0e633eba6a691a530fb9a907debffd34222 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Mon, 1 May 2023 22:52:16 +0200 Subject: [PATCH 52/54] fix: load-map did not advance HERE --- forth/block.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forth/block.fs b/forth/block.fs index d8c10cc0..f2e7d087 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -55,8 +55,8 @@ path here loadb abort" exist" loop map @ here path saveb ; : load-map map @ if exit then -here path here loadb -0= abort" no blocks" map ! ; +here path here loadb dup 0= +abort" no blocks" to here map ! ; : >addr ( buf -- addr ) $400 * $a000 + ; From 7a3aee9844e71950482686e74f1ee8375e67911a Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 21 May 2023 00:57:07 +0200 Subject: [PATCH 53/54] implement \ for blocks (not tested) --- forth/block.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/forth/block.fs b/forth/block.fs index f2e7d087..9f98d1f8 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -131,6 +131,9 @@ define flush save-buffers empty-buffers ; to latest \ end hiding words +: \ blk @ if >in @ dup #40 mod - #40 + +>in ! else postpone \ then ; immediate + ( --- testing : test-load From e06b63c1080f91fb65f5779d2f3a570b9853d964 Mon Sep 17 00:00:00 2001 From: Johan Kotlinski Date: Sun, 21 May 2023 16:23:17 +0200 Subject: [PATCH 54/54] add REFILL EVALUATE for blocks (not tested) --- forth/block.fs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/forth/block.fs b/forth/block.fs index 9f98d1f8..4b146a47 100644 --- a/forth/block.fs +++ b/forth/block.fs @@ -134,6 +134,13 @@ to latest \ end hiding words : \ blk @ if >in @ dup #40 mod - #40 + >in ! else postpone \ then ; immediate +: refill blk @ ?dup if +1+ block if 1 blk +! -1 else 0 then +else refill then ; + +: evaluate blk @ >r 0 blk ! +evaluate r> blk ! ; + ( --- testing : test-load