home *** CD-ROM | disk | FTP | other *** search
- \ POINTER.SEQ External memory allocation and management by Tom Zimmer
-
- \ What I need in F-PC is a way to allocate memory from a physical memory
- \ area, while providing a runtime way to assure no fracturing of physical
- \ memory occurs.
-
- FILES DEFINITIONS
-
- VARIABLE POINTER.SEQ
-
- FORTH DEFINITIONS
-
- \ BODY +0 +2 +4 +6
- \ [ phy_pointer ][ link ][ size_bytes ][.....
-
- : POINTER ( dbl_bytes | name -- ) \ make a pointer "name"
- ( -- paragraph ) \ it's location
- 160 0 DMAX \ at least 160 bytes
- CREATE 0 , \ initialize to unallocated
- HERE PHEAD @ , PHEAD ! \ link into chain
- DPARAGRAPH , \ lay in size in paragraphs
- DOES> DUP>R @ 0=
- IF ?CS: R@ 4 + @ 0 #PARS @ 0 D+ $FFFF 0 DMIN DROP
- SETBLOCK 0=
- IF ?CS: #PARS @ + R@ ! \ install physical seg
- R@ 4 + @ #PARS +! \ adj total paragraphs
- THEN
- THEN R> @ ; \ return physical paragraph
-
- RESOLVES <POINTER> \ resolve forward reference to POINTER
-
- : %UNPOINTER ( cfa -- ) \ deallocate pointer given the cfa
- >BODY DUP>R @ 0<> \ only if non-zero
- IF R@ @ R@ 4 + @ BOUNDS OVER
- #PARS @ SWAP ?CS: - - CMOVE-PARS
- PHEAD @
- BEGIN DUP
- WHILE DUP 2- @ R@ @ U> \ if pointer is above
- IF R@ 4 + @ NEGATE OVER 2- +!
- \ adjust phy position
- THEN
- @
- REPEAT DROP \ discard phead end
- 0 R@ ! \ clear this pointer
- R@ 4 + @ NEGATE #PARS +! \ reduce total #pars
- ?CS: #PARS @ SETBLOCK DROP \ adjust memory usage
- THEN R>DROP ;
-
- : UNPOINTER> ( name -- ) \ deallocate a pointer name following
- ' STATE @
- IF COMPILE (LIT) X, COMPILE %UNPOINTER
- ELSE %UNPOINTER
- THEN ; IMMEDIATE
-
- : 0POINTERS ( -- ) \ initialize the FAR arrays
- PHEAD @ \ beginning of pointer chain
- BEGIN DUP \ while not a list end
- WHILE 0 OVER 2- ! \ clear pointer
- @ \ indirect to next ptr
- REPEAT DROP
- 0 #PARS ! ; \ clear number of paragraphs
- \ used
-
- : %SIZEOF! ( dbl_bytes cfa -- ) \ set the size of pointer "cfa"
- >R DPARAGRAPH R> >BODY 4 + ! ;
-
- : SIZEOF!> ( dbl_bytes | name -- ) \ set size of the following pointer
- ' STATE @
- IF COMPILE (LIT) X, COMPILE %SIZEOF!
- ELSE %SIZEOF!
- THEN ; IMMEDIATE
-
-