Adding x16tmpheap.fth and notmpheap.fth from the cc64 project to the VF code base

This commit is contained in:
Philip Zembrod 2021-01-30 11:08:09 +01:00
parent 4e8be09c17
commit b3eb76336a
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,11 @@
\ When no tmpheap mechanism is needed, i.e. all temporary names
\ of a project fit onto the regular heap at once, then this zero-cost
\ implementation can be used which directs all tmpheap definitions
\ to the regular heap.
' | alias ||
' |on alias ||on
' |off alias ||off
' noop alias tmpclear

View File

@ -0,0 +1,62 @@
\ This is a custom implementation of tmpheap for the X16 which
\ allocates the tmpheap in a RAM bank and moves definitons prefixed
\ with || or within a ||on to ||off range there.
\ tmpclear will remove all words on the tmpheap, wheras regular clear
\ will remove all words on tmpheap and heap together.
\ Other than the reference tmpheap living on the regular heap, this
\ custom tmpheap needs no initialization as its position and
\ size (8k) is fixed.
User tmpheap[
User tmpheap>
User ]tmpheap
\ $9f61 is the X16 RAM bank select register. This will change to $0001
\ in the next X16 board version.
\ 1 is the RAM bank selected for the tmpheap. RAM bank 0 is used by the
\ X16 KERNAL. The banked RAM lives from $a000 to $bfff.
1 $9f61 c! $a000 tmpheap[ ! $c000 dup ]tmpheap ! tmpheap> !
: mk-tmp-heap ( size -- )
heap dup ]tmpheap ! tmpheap> ! hallot heap tmpheap[ ! ;
: tmp-hallot ( size -- addr )
tmpheap> @ swap -
dup tmpheap[ @ u< abort" tmp heap overflow"
dup tmpheap> ! ;
| : tmp-heapmove ( from from size -- from offset )
dup tmp-hallot swap cmove
tmpheap> @ over - ;
| : tmp-heapmove1x ( from size -- from offset )
tmp-heapmove ?heapmovetx off ;
: || ['] tmp-heapmove1x ?heapmovetx ! ;
: ||on ['] tmp-heapmove ?heapmovetx ! ;
: ||off ?heapmovetx off ;
| : remove-tmp-words-in-voc ( voc -- )
BEGIN dup @ ?dup WHILE ( thread next-in-thread )
dup tmpheap[ @ ]tmpheap @ uwithin IF ( thread next-in-thread )
@ ?dup IF ( thread next-next-in-thread ) over !
ELSE ( thread ) off exit THEN
ELSE ( thread next-in-thread ) nip
THEN
REPEAT drop ;
| : remove-tmp-words ( -- )
voc-link BEGIN @ ?dup
WHILE dup 4 - remove-tmp-words-in-voc REPEAT ;
: tmpclear ( -- )
remove-tmp-words
\ Uncomment the following line to help determine the ideal tmpheap
\ size for your project.
\ tmpheap> @ tmpheap[ @ - cr u. ." tmpheap spare"
]tmpheap @ tmpheap> ! last off ;
' tmpclear is custom-remove