Browse Source

blk: add dirty flag and auto write blocks on fetch

Also, fix some PSP leaks related to LOAD.
pull/102/head
Virgil Dupras 4 years ago
parent
commit
9edab10a3a
5 changed files with 31 additions and 9 deletions
  1. +2
    -2
      blk/104
  2. +10
    -0
      emul/Makefile
  3. +18
    -6
      forth/blk.fs
  4. +1
    -0
      forth/core.fs
  5. +0
    -1
      tools/blkunpack.c

+ 2
- 2
blk/104 View File

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




+ 10
- 0
emul/Makefile View File

@@ -16,6 +16,7 @@ SLATEST = ../tools/slatest
STRIPFC = ../tools/stripfc
BIN2C = ../tools/bin2c
BLKPACK = ../tools/blkpack
BLKUNPACK = ../tools/blkunpack

.PHONY: all
all: $(TARGETS)
@@ -27,6 +28,7 @@ $(BLKPACK):
$(STRIPFC): $(BLKPACK)
$(SLATEST): $(BLKPACK)
$(BIN2C): $(BLKPACK)
$(BLKUNPACK): $(BLKPACK)

# z80c.bin is not in the prerequisites because it's a bootstrap
# binary that should be updated manually through make updatebootstrap.
@@ -77,6 +79,14 @@ emul.o: emul.c
updatebootstrap: forth/stage2
cat $(BOOTSRCS) | ./forth/stage2 > ./forth/z80c.bin

.PHONY: pack
pack:
rm blkfs && $(MAKE) blkfs

.PHONY: unpack
unpack:
$(BLKUNPACK) ../blk < blkfs

.PHONY: clean
clean:
rm -f $(TARGETS) emul.o forth/*-bin.h forth/forth?.bin blkfs


+ 18
- 6
forth/blk.fs View File

@@ -7,26 +7,35 @@
: BLK!* 2 BLKMEM+ ;
( Current blk pointer in ( )
: BLK> 4 BLKMEM+ ;
: BLK( 6 BLKMEM+ ;
( Whether buffer is dirty )
: BLKDTY 6 BLKMEM+ ;
: BLK( 8 BLKMEM+ ;

: BLK$
H@ 0x57 RAM+ !
( 1024 for the block, 6 for variables )
1030 ALLOT
( 1024 for the block, 8 for variables )
1032 ALLOT
( LOAD detects end of block with ASCII EOT. This is why
we write it there. EOT == 0x04 )
4 C,
0 BLKDTY !
-1 BLK> !
;

( -- )
: BLK!
BLK> @ BLK!* @ EXECUTE
0 BLKDTY !
;

( n -- )
: BLK@
DUP BLK> @ = IF DROP EXIT THEN
BLKDTY @ IF BLK! THEN
DUP BLK> ! BLK@* @ EXECUTE
;

( -- )
: BLK! BLK> @ BLK!* @ EXECUTE ;
: BLK!! 1 BLKDTY ! ;

: .2 DUP 10 < IF SPC THEN . ;

@@ -42,7 +51,10 @@
: _
(boot<)
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 )
EXIT!
THEN


+ 1
- 0
forth/core.fs View File

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

( a -- a+1 c )


+ 0
- 1
tools/blkunpack.c View File

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


Loading…
Cancel
Save