1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 12:58:09 +11:00

blk: add dirty flag and auto write blocks on fetch

Also, fix some PSP leaks related to LOAD.
This commit is contained in:
Virgil Dupras 2020-04-16 20:59:20 -04:00
parent 79ce88c12c
commit 9edab10a3a
5 changed files with 31 additions and 9 deletions

View File

@ -10,7 +10,7 @@ VARIABLE EDPOS
2DUP SWAP I + C! 2DUP SWAP I + C!
DUP IF DROP C< THEN DUP IF DROP C< THEN
LOOP LOOP
2DROP
BLK!!
; ;

View File

@ -16,6 +16,7 @@ SLATEST = ../tools/slatest
STRIPFC = ../tools/stripfc STRIPFC = ../tools/stripfc
BIN2C = ../tools/bin2c BIN2C = ../tools/bin2c
BLKPACK = ../tools/blkpack BLKPACK = ../tools/blkpack
BLKUNPACK = ../tools/blkunpack
.PHONY: all .PHONY: all
all: $(TARGETS) all: $(TARGETS)
@ -27,6 +28,7 @@ $(BLKPACK):
$(STRIPFC): $(BLKPACK) $(STRIPFC): $(BLKPACK)
$(SLATEST): $(BLKPACK) $(SLATEST): $(BLKPACK)
$(BIN2C): $(BLKPACK) $(BIN2C): $(BLKPACK)
$(BLKUNPACK): $(BLKPACK)
# z80c.bin is not in the prerequisites because it's a bootstrap # z80c.bin is not in the prerequisites because it's a bootstrap
# binary that should be updated manually through make updatebootstrap. # binary that should be updated manually through make updatebootstrap.
@ -77,6 +79,14 @@ emul.o: emul.c
updatebootstrap: forth/stage2 updatebootstrap: forth/stage2
cat $(BOOTSRCS) | ./forth/stage2 > ./forth/z80c.bin cat $(BOOTSRCS) | ./forth/stage2 > ./forth/z80c.bin
.PHONY: pack
pack:
rm blkfs && $(MAKE) blkfs
.PHONY: unpack
unpack:
$(BLKUNPACK) ../blk < blkfs
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(TARGETS) emul.o forth/*-bin.h forth/forth?.bin blkfs rm -f $(TARGETS) emul.o forth/*-bin.h forth/forth?.bin blkfs

View File

@ -7,26 +7,35 @@
: BLK!* 2 BLKMEM+ ; : BLK!* 2 BLKMEM+ ;
( Current blk pointer in ( ) ( Current blk pointer in ( )
: BLK> 4 BLKMEM+ ; : BLK> 4 BLKMEM+ ;
: BLK( 6 BLKMEM+ ; ( Whether buffer is dirty )
: BLKDTY 6 BLKMEM+ ;
: BLK( 8 BLKMEM+ ;
: BLK$ : BLK$
H@ 0x57 RAM+ ! H@ 0x57 RAM+ !
( 1024 for the block, 6 for variables ) ( 1024 for the block, 8 for variables )
1030 ALLOT 1032 ALLOT
( LOAD detects end of block with ASCII EOT. This is why ( LOAD detects end of block with ASCII EOT. This is why
we write it there. EOT == 0x04 ) we write it there. EOT == 0x04 )
4 C, 4 C,
0 BLKDTY !
-1 BLK> ! -1 BLK> !
; ;
( -- )
: BLK!
BLK> @ BLK!* @ EXECUTE
0 BLKDTY !
;
( n -- ) ( n -- )
: BLK@ : BLK@
DUP BLK> @ = IF DROP EXIT THEN DUP BLK> @ = IF DROP EXIT THEN
BLKDTY @ IF BLK! THEN
DUP BLK> ! BLK@* @ EXECUTE DUP BLK> ! BLK@* @ EXECUTE
; ;
( -- ) : BLK!! 1 BLKDTY ! ;
: BLK! BLK> @ BLK!* @ EXECUTE ;
: .2 DUP 10 < IF SPC THEN . ; : .2 DUP 10 < IF SPC THEN . ;
@ -42,7 +51,10 @@
: _ : _
(boot<) (boot<)
DUP 4 = IF DUP 4 = IF
DROP ( We drop our char, but also "a" from WORD: it won't
have the opportunity to balance PSP because we're
EXIT!ing. )
2DROP
( We're finished interpreting ) ( We're finished interpreting )
EXIT! EXIT!
THEN THEN

View File

@ -178,6 +178,7 @@
DUP ( I I ) DUP ( I I )
R> DROP I 2- @ ( I I a ) R> DROP I 2- @ ( I I a )
= UNTIL = UNTIL
DROP
; ;
( a -- a+1 c ) ( a -- a+1 c )

View File

@ -26,7 +26,6 @@ int main(int argc, char *argv[])
} }
if (c) { if (c) {
// not an empty block // not an empty block
printf("%s\n", fullpath);
FILE *fp = fopen(fullpath, "w"); FILE *fp = fopen(fullpath, "w");
for (int i=0; i<16; i++) { for (int i=0; i<16; i++) {
int len = strlen(&buf[i*64]); int len = strlen(&buf[i*64]);