Skip to content
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
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Apr 20, 2023
9edf5fb
Merge branch 'master' into blocks
jkotlinski Apr 21, 2023
c6b2591
blocks
jkotlinski Apr 22, 2023
1953cf8
some progress on BLOCK
jkotlinski Apr 22, 2023
d8c8c1d
drop least recently used buffer
jkotlinski Apr 22, 2023
011528a
wipe block if file missing
jkotlinski Apr 22, 2023
944f867
refactoring: extract >path
jkotlinski Apr 22, 2023
8cee2b9
added BUFFER
jkotlinski Apr 22, 2023
f914a80
added list
jkotlinski Apr 22, 2023
acf7a61
add empty-buffers
jkotlinski Apr 22, 2023
0ecb0fe
added update
jkotlinski Apr 22, 2023
79de402
tidy up
jkotlinski Apr 22, 2023
e77a727
inline doload
jkotlinski Apr 22, 2023
29431e5
simplify buffer management (no lru)
jkotlinski Apr 22, 2023
505b7ee
tidy up
jkotlinski Apr 22, 2023
ece5ced
allow 3-digit blocks
jkotlinski Apr 22, 2023
aeb29a4
drop path storage
jkotlinski Apr 22, 2023
3ef92ee
add TODO comment
jkotlinski Apr 22, 2023
8f4efd9
scratch before save
jkotlinski Apr 22, 2023
15a528e
fix empty-buffers
jkotlinski Apr 27, 2023
ed6a588
added b-a to allocate blocks
jkotlinski Apr 28, 2023
78d6168
tidy up comment
jkotlinski Apr 28, 2023
eaacf39
add create-blocks
jkotlinski Apr 28, 2023
e2886ad
leaner map file format
jkotlinski Apr 28, 2023
6716c36
safer map loading
jkotlinski Apr 28, 2023
c8ccb88
factoring: extract word
jkotlinski Apr 28, 2023
9aa02b2
some work on sector loading
jkotlinski Apr 28, 2023
6f3ca2b
seemingly fixed block load
jkotlinski Apr 28, 2023
d954604
shorten error message
jkotlinski Apr 28, 2023
58a9162
Merge branch 'master' into blocks
jkotlinski Apr 28, 2023
b74e3b5
tidy up; fix load-map error
jkotlinski Apr 28, 2023
0c5d9e8
temporarily disable build
jkotlinski Apr 28, 2023
b80d8e1
print b-a drive output
jkotlinski Apr 29, 2023
429c8df
added TODO comment
jkotlinski Apr 29, 2023
c05f15a
Merge branch 'master' into blocks
jkotlinski Apr 29, 2023
adc2af6
Merge branch 'master' into blocks
jkotlinski Apr 29, 2023
6ade26a
speed up create-blocks
jkotlinski Apr 29, 2023
3ce7fae
simplify code
jkotlinski Apr 29, 2023
336636a
Merge branch 'master' into blocks
jkotlinski Apr 29, 2023
c29b7b7
simplify disk full check
jkotlinski Apr 29, 2023
2d39689
bugfix load-blk
jkotlinski Apr 29, 2023
5b43051
add decimal for number formatting, tidy up
jkotlinski Apr 29, 2023
7574d26
simplify code
jkotlinski Apr 29, 2023
5ded1ec
implement block save
jkotlinski Apr 29, 2023
00170ad
save a byte
jkotlinski Apr 29, 2023
e19160b
add BLK
jkotlinski Apr 30, 2023
0006ddf
made block numbers start at 1 again (standard)
jkotlinski Apr 30, 2023
789b915
Merge branch 'master' into blocks
jkotlinski Apr 30, 2023
138c162
push/pop BLK
jkotlinski Apr 30, 2023
77bd347
start work on LOAD
jkotlinski Apr 30, 2023
d4b32a0
start work on save/restore BLK
jkotlinski May 1, 2023
d6536e5
some work on testing
jkotlinski May 1, 2023
0c102bb
LOAD 100%
jkotlinski May 1, 2023
410f9af
made test-load pass
jkotlinski May 1, 2023
541dde9
allocate 11 block buffers
jkotlinski May 1, 2023
15a1775
hide private block words
jkotlinski May 1, 2023
1aecc81
fix create-blocks
jkotlinski May 1, 2023
1d28d0e
fix: load-map did not advance HERE
jkotlinski May 1, 2023
ae09ad5
Merge branch 'master' into blocks
jkotlinski May 1, 2023
c6c185a
Merge branch 'master' into blocks
jkotlinski May 20, 2023
7a3aee9
implement \ for blocks (not tested)
jkotlinski May 20, 2023
e06b63c
add REFILL EVALUATE for blocks (not tested)
jkotlinski May 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions asm/interpreter.asm
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,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
Expand Down
60 changes: 54 additions & 6 deletions asm/io.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; 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
; BLOCK-XT LOAD

+BACKLINK "emit", 4
EMIT
Expand Down Expand Up @@ -60,12 +61,23 @@ CLOSE_INPUT_SOURCE
lda SOURCE_ID_LSB
jsr CLOSE
jsr POP_INPUT_SOURCE
lda BLK_W
bne .restore_block
ldx SOURCE_ID_LSB
beq +
beq .restore_keyboard
jsr CHKIN
jmp ++
+ jsr CLRCHN
++ ldx W
jmp .ret
.restore_keyboard
jsr CLRCHN
.ret
ldx W
rts
.restore_block
ldx W
jsr BLK
jsr FETCH
jsr BLOCK
inx ; assume block buffer address is unchanged
rts

+BACKLINK "refill", 6
Expand Down Expand Up @@ -211,6 +223,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
Expand All @@ -223,7 +241,7 @@ SAVE_INPUT_STACK
; Eight levels is overkill for INCLUDED, since opening more than four DOS
; channels gives a "no channel" error message on C64.
; It is anyway nice to keep some extra levels for EVALUATE and LOAD.
!fill 8*12
!fill 8*13
SAVE_INPUT_STACK_DEPTH
!byte 0

Expand All @@ -241,6 +259,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
Expand Down Expand Up @@ -291,6 +311,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,
Expand Down Expand Up @@ -347,3 +369,29 @@ IOABORT ; ( ioresult -- )
.cr_abort
jsr CR
jmp ABORT

+BACKLINK "block-xt", 8
+VALUE BLOCK + 1
BLOCK
jmp PLACEHOLDER_ADDRESS

+BACKLINK "load", 4
jsr PUSH_INPUT_SOURCE
jsr DUP
jsr BLK
jsr STORE
jsr ZERO
jsr TO_IN
jsr STORE
jsr BLOCK
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
jsr interpret_tib
jmp CLOSE_INPUT_SOURCE
6 changes: 4 additions & 2 deletions forth/base.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ hide dodoes
.( require..) include require
.( open..) include open
.( accept..) include accept
.( v..) include v
\ .( v..) include v

.( block..) include block

decimal
include turnkey
Expand All @@ -199,4 +201,4 @@ $20 + + - \ save-pack padding
save-pack @0:durexforth
.( ok!) cr

0 $d7ff c! \ for vice -debugcart
\ 0 $d7ff c! \ for vice -debugcart
160 changes: 160 additions & 0 deletions forth/block.fs
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,
Copy link
Contributor

@ekipan ekipan May 1, 2023

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 all 5 buffers while you browse +2 and -2

Copy link
Contributor

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.

Copy link
Owner Author

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.

Copy link
Owner Author

@jkotlinski jkotlinski May 1, 2023

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, \ and REFILL to support blocks.

Edit: Done

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to support:

  • disk change
  • release/delete blocks

Copy link
Contributor

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?

Copy link
Owner Author

@jkotlinski jkotlinski May 20, 2023

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.

Copy link
Owner Author

@jkotlinski jkotlinski May 20, 2023

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 LOADing 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.

Copy link
Contributor

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.

Copy link
Owner Author

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.

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" ; )
2 changes: 1 addition & 1 deletion manual/memmap.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.