1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; buffers, blocks, etc...
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 FORTH_BUF_DATA_SIZE equ 256
6 FORTH_BUF_TOTAL_SIZE equ FORTH_BUF_DATA_SIZE+4
13 defs FORTH_BUF_DATA_SIZE,0
15 defw 0 ;; just in case
17 $FORTH_CONST FIRST forth_buffers
18 $FORTH_CONST LIMIT forth_buffers+(FORTH_BUF_TOTAL_SIZE*FORTH_BUF_COUNT)-1
19 $FORTH_CONST BUF-NUM FORTH_BUF_COUNT
20 $FORTH_CONST B/BUF FORTH_BUF_DATA_SIZE
21 $FORTH_CONST B/SCR 4 ;;FIXME: calculate this!
22 $FORTH_CONST (B/BUF) FORTH_BUF_TOTAL_SIZE
24 $FORTH_VAR BUF-USE forth_buffers
25 $FORTH_VAR BUF-PREV forth_buffers
27 ;; get next buffer to use
30 ;; ( a -- na isprevflg )
31 ;; isprevflg: TRUE when new buffer is BUF-PREV (so the cycle is closed %-)
32 (B/BUF) + ;; next buffer address
33 DUP LIMIT U> ;; is limit reached?
35 DROP FIRST ;; yes: start from the first buffer
45 BUF-PREV @ @ LIT #8000 OR BUF-PREV @ ! ;S
46 $FORTH_END_WORD UPDATE
52 BUF-PREV @ @ LIT #7FFF AND BUF-PREV @ ! ;S
53 $FORTH_END_WORD UNUPDATE
55 $FORTH_WORD EMPTY-BUFFERS
58 FIRST LIMIT OVER - 1+ ERASE
61 ;; buffer #7FFF is zero, so init with #7FFE
62 LIT #7FFE OVER ! (B/BUF) +
65 $FORTH_END_WORD EMPTY-BUFFERS
74 ;; load or save buffer
77 ;; ( addr bufnum readflag -- )
78 ;; read buffer if readflag <> 0
81 DUP LIT #7FFF = 0BRANCH rwdo0
84 DUP 0< OVER LIT 2559 > OR LIT 6 ?ERROR ;; check for valid buffer number
85 ;; ( addr bufnum | readflag )
92 READ-ONLY @ 0BRANCH rwdo_write1
101 ;; get new buffer to use (save dirty buffer if necessary)
108 ;; ( buffaddr | prefbuffuse )
109 BUF-USE ! R@ @ 0< ;; ( dirty? | prefbuffuse )
112 R@ 2+ R@ @ LIT #7FFF AND 0 R/W ;; save dirty buffer
114 R@ ! R@ BUF-PREV ! R> 2+
116 $FORTH_END_WORD BUFFER
121 ;; ( n -- a ) ??? unclear
122 OFFSET @ + >R ;; store real block number
123 BUF-PREV @ ;; buffer addr
124 DUP @ ;; buffer number; ( bpa bpn | bn )
125 R@ - DUP + ;; ( bpa bpn-bn bpn-bn*2 | bn )
126 0BRANCH block2 ;; zero? i.e. does the user wants the last loaded block?
128 +BUF 0= 0BRANCH block1 ;; last buffer reached?
129 ;; have to load new block
130 DROP R@ BUFFER DUP R@ 1 R/W 2-
133 ;; check if the buffer is ours
134 DUP @ R@ - ;; get block number delta
135 DUP + 0= 0BRANCH block0
138 ;; drop real block number, return address
141 $FORTH_END_WORD BLOCK
143 ;; save all dirty buffers
152 $FORTH_END_WORD FLUSH
159 BLK @ >R IN @ >R IN 0! B/SCR * BLK !
165 ;; interpret next block
169 ?LOADING IN 0! B/SCR BLK @ OVER MOD - BLK +!
173 IF USE_EXT_BLOCK_WORDS
174 include "ext_blocks.zas"
177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 ;; end of buffers, blocks, etc...
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;