-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Blocks wordset #554
Open
jkotlinski
wants to merge
62
commits into
master
Choose a base branch
from
blocks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
3f54491
don't load v
jkotlinski 9edf5fb
Merge branch 'master' into blocks
jkotlinski c6b2591
blocks
jkotlinski 1953cf8
some progress on BLOCK
jkotlinski d8c8c1d
drop least recently used buffer
jkotlinski 011528a
wipe block if file missing
jkotlinski 944f867
refactoring: extract >path
jkotlinski 8cee2b9
added BUFFER
jkotlinski f914a80
added list
jkotlinski acf7a61
add empty-buffers
jkotlinski 0ecb0fe
added update
jkotlinski 79de402
tidy up
jkotlinski e77a727
inline doload
jkotlinski 29431e5
simplify buffer management (no lru)
jkotlinski 505b7ee
tidy up
jkotlinski ece5ced
allow 3-digit blocks
jkotlinski aeb29a4
drop path storage
jkotlinski 3ef92ee
add TODO comment
jkotlinski 8f4efd9
scratch before save
jkotlinski 15a528e
fix empty-buffers
jkotlinski ed6a588
added b-a to allocate blocks
jkotlinski 78d6168
tidy up comment
jkotlinski eaacf39
add create-blocks
jkotlinski e2886ad
leaner map file format
jkotlinski 6716c36
safer map loading
jkotlinski c8ccb88
factoring: extract word
jkotlinski 9aa02b2
some work on sector loading
jkotlinski 6f3ca2b
seemingly fixed block load
jkotlinski d954604
shorten error message
jkotlinski 58a9162
Merge branch 'master' into blocks
jkotlinski b74e3b5
tidy up; fix load-map error
jkotlinski 0c5d9e8
temporarily disable build
jkotlinski b80d8e1
print b-a drive output
jkotlinski 429c8df
added TODO comment
jkotlinski c05f15a
Merge branch 'master' into blocks
jkotlinski adc2af6
Merge branch 'master' into blocks
jkotlinski 6ade26a
speed up create-blocks
jkotlinski 3ce7fae
simplify code
jkotlinski 336636a
Merge branch 'master' into blocks
jkotlinski c29b7b7
simplify disk full check
jkotlinski 2d39689
bugfix load-blk
jkotlinski 5b43051
add decimal for number formatting, tidy up
jkotlinski 7574d26
simplify code
jkotlinski 5ded1ec
implement block save
jkotlinski 00170ad
save a byte
jkotlinski e19160b
add BLK
jkotlinski 0006ddf
made block numbers start at 1 again (standard)
jkotlinski 789b915
Merge branch 'master' into blocks
jkotlinski 138c162
push/pop BLK
jkotlinski 77bd347
start work on LOAD
jkotlinski d4b32a0
start work on save/restore BLK
jkotlinski d6536e5
some work on testing
jkotlinski 0c102bb
LOAD 100%
jkotlinski 410f9af
made test-load pass
jkotlinski 541dde9
allocate 11 block buffers
jkotlinski 15a1775
hide private block words
jkotlinski 1aecc81
fix create-blocks
jkotlinski 1d28d0e
fix: load-map did not advance HERE
jkotlinski ae09ad5
Merge branch 'master' into blocks
jkotlinski c6c185a
Merge branch 'master' into blocks
jkotlinski 7a3aee9
implement \ for blocks (not tested)
jkotlinski e06b63c
add REFILL EVALUATE for blocks (not tested)
jkotlinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
require io | ||
|
||
marker ---block--- | ||
|
||
header block | ||
header buffer | ||
header create-blocks | ||
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 | ||
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 ! | ||
: path s" blocks" ; | ||
|
||
: get## ( -- n ) | ||
chrin '0' - #10 * chrin '0' - + ; | ||
|
||
variable t variable s | ||
|
||
: b-a ( -- ) \ allocate sector | ||
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 | ||
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 ; | ||
|
||
\ Usage: "20 create-blocks" allocates | ||
\ 20 Forth blocks = 80 sectors and | ||
\ writes a map file named "blocks". | ||
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 ; | ||
|
||
: load-map map @ if exit then | ||
here path here loadb dup 0= | ||
abort" no blocks" to here map ! ; | ||
|
||
: >addr ( buf -- addr ) | ||
$400 * $a000 + ; | ||
|
||
: 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! | ||
dup bbi + c@ 1- 8 * map @ + | ||
swap >addr dup $400 + swap do | ||
dup @ split i write-sector | ||
2+ $100 +loop drop ; | ||
|
||
: >buf ( blk -- buf ) #11 mod ; | ||
|
||
: 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 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 1- 8 * map @ + swap >buf | ||
>addr dup $400 + swap do i over @ | ||
split read-sector 2+ $100 +loop drop ; | ||
|
||
: 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! ; | ||
|
||
: loaded? ( blk -- blk flag ) | ||
dup dup >buf bbi + c@ = ; | ||
|
||
define block ( blk -- addr ) | ||
loaded? 0= if unassign dup load-blk | ||
then set-blk ; | ||
|
||
' block block-xt ! | ||
|
||
define buffer ( blk -- addr ) | ||
loaded? 0= if unassign then set-blk ; | ||
|
||
define list ( blk -- ) | ||
block dup $400 + swap do | ||
i c@ emit loop ; | ||
|
||
define empty-buffers ( -- ) | ||
bbi #11 erase dirty #11 erase ; | ||
|
||
define update ( -- ) | ||
1 dirty curr-buf c@ + c! ; | ||
|
||
define save-buffers ( -- ) | ||
11 0 do i save-buf loop ; | ||
|
||
define flush save-buffers empty-buffers ; | ||
|
||
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 | ||
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" ; ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it stays an odd number,
say 5,then any block editor that does shadow blocks will still be able to use all5buffers while you browse +2 and -2There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops nvm I should have read more, I see you're doing
#11 mod
please ignore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is really nice that you take a look at things. It is maybe getting closer to first release. Test and documentation are still missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also to be done: update
EVALUATE
,\
andREFILL
to support blocks.Edit: Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need to support:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've avoided the problem by only using
(
in my blocks. FWIW my vote is 40 to (1) make editors simpler to implement and because (2) horizontal scrolling is kinda gross UX. It's definitely unorthodox though. Perhaps a poll is in order?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a poll is needed, just need to work out the pros and cons. I agree 40-width makes a lot of sense for the reasons you mention.
The strongest argument for 64 is that long strings can be useful, for example, it allows defining a
S"
string that is 40 characters long or more. I am not sure if there is a clean way to do the same with 40-width.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually: I realize now, long lines is not a problem for blocks. When
LOAD
ing a block,S"
will parse until the next"
, even if it is on another line.It is a problem if the code is later copied from block to file, but then it can be resolved by joining the string lines to a single long line.
I think altogether, that makes a strong case for 40-width.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike files, block LOAD is specified to use the entire block source as the input buffer, so words like
s"
and(
should be able to span across lines portably if I understand correctly (if I don't understand correctly please let me know).Another strong argument for 64 is to make it more likely to be able to directly reuse any Forth source already in 16x64 screens out there that have
\
comments. I'm personally ambivalent to that though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the most part, I don't think porting from 16x64 to 25x40+24 would be a big problem. At least not compared to all the other problems when porting code from a Forth to another.