1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; buffers, blocks, etc...
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 $FORTH_CONST FIRST #D800
6 $FORTH_CONST LIMIT #E01F
10 $FORTH_CONST (B/BUF) 260
12 $FORTH_VAR BUF-USE #D800
13 $FORTH_VAR BUF-PREV #D800
15 ;; get next buffer to use
18 ;; ( a -- na isprevflg )
19 ;; isprevflg: TRUE when new buffer is BUF-PREV (so the cycle is closed %-)
20 (B/BUF) + ;; next buffer address
21 DUP LIMIT U> ;; is limit reached?
23 DROP FIRST ;; yes: start from the first buffer
32 BUF-PREV @ @ LIT #8000 OR BUF-PREV @ ! ;S
33 $FORTH_END_WORD UPDATE
38 BUF-PREV @ @ LIT #7FFF AND BUF-PREV @ ! ;S
39 $FORTH_END_WORD UNUPDATE
41 $FORTH_WORD EMPTY-BUFFERS
43 FIRST LIMIT OVER - 1+ ERASE
46 LIT #7FFE OVER ! (B/BUF) +
49 $FORTH_END_WORD EMPTY-BUFFERS
57 ;; load or save buffer
60 ;; ( addr bufnum readflag -- )
61 ;; read buffer if readflag <> 0
63 DUP LIT 32767 - 0= 0BRANCH rwdo0
66 DUP 0< OVER LIT 2559 > OR LIT 6 ?ERROR ;; check for valid buffer number
67 ;; ( addr bufnum | readflag )
74 READ-ONLY @ 0BRANCH rwdo_write1
82 ;; get new buffer to use (save dirty buffer if necessary)
89 ;; ( buffaddr | prefbuffuse )
90 BUF-USE ! R@ @ 0< ;; ( dirty? | prefbuffuse )
93 R@ 2+ R@ @ LIT #7FFF AND 0 R/W ;; save dirty buffer
95 R@ ! R@ BUF-PREV ! R> 2+
97 $FORTH_END_WORD BUFFER
102 ;; ( n -- a ) ??? unclear
103 OFFSET @ + >R ;; store real block number
104 BUF-PREV @ ;; buffer addr
105 DUP @ ;; buffer number; ( bpa bpn | bn )
106 R@ - DUP + ;; ( bpa bpn-bn bpn-bn*2 | bn )
107 0BRANCH block2 ;; zero? i.e. does the user wants the last loaded block?
109 +BUF 0= 0BRANCH block1 ;; last buffer reached?
110 ;; have to load new block
111 DROP R@ BUFFER DUP R@ 1 R/W 2-
114 ;; check if the buffer is ours
115 DUP @ R@ - ;; get block number delta
116 DUP + 0= 0BRANCH block0
119 ;; drop real block number, return address
122 $FORTH_END_WORD BLOCK
124 ;; save all dirty buffers
133 $FORTH_END_WORD FLUSH
138 ;; ( line block -- addr )
141 >R LIT 64 B/BUF */MOD R>
142 B/SCR * + BLOCK + LIT 64
144 $FORTH_END_WORD (LINE)
150 (LINE) -TRAILING TYPE ;S
151 $FORTH_END_WORD .LINE
158 BLK @ >R IN @ >R IN 0! B/SCR * BLK !
164 ;; interpret next block
167 ?LOADING IN 0! B/SCR BLK @ OVER MOD - BLK +!
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 ;; end of buffers, blocks, etc...
173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;