[comp.sys.amiga] UnLoadSeg

drs-ano@duvan.nada.kth.se (Gunnar Nordmark) (01/22/88)

I've written a 16-bit FORTH-83 just for the fun of it.
It needs a 64K continuous memory block and some interface code. (1-2K)
OF COURSE I can't save the entire 64K block to a disk file - it contains
a lot of garbage, stacks, diskbuffers et.c. Well, this is exactly what I've
been doing for the past nine months or so!

This is the "old" load file:
  hunk_header
  hunk_code   1K       (interface - position independent)
  hunk_end
  hunk_data   64K(!)   (The actual FORTH - also position independent)
  hunk_end

The only part of the 64K block that needs to be saved is the dictionary,
whichs occupies the lower part of the block. Why save a lot of junk?
Here is my solution:

  hunk_header
  hunk_code   1K       (interface - position independent)
  hunk_end
  hunk_data   0-64K    (The actual FORTH - also position independent)
  hunk_end

As you can see the size of the data block varies. Therefore I must AllocMem
a 64K block and then copy the data hunk to that location.
Then I FreeMem the original data hunk and unlinks it from the SegList.
(the SegList is a LINKED LIST of BPTRs, wonderful :-)
Instead I link the new 64K block to the SegList.
Then when the program exits, UnLoadSeg will take care of the cleanup
and promptly FreeMem my 64K block, right...

Hmm, does it work?

This solution depends heavily on the fact that the ONLY thing that
UnLoadSeg does, is FreeMem all the segments in the list.

If UnLoadSeg does anything more than freeing memory, please ALERT me at once!
(Or tell me how to disassemble the ROM, yacc! :-)

   - Gunnar Nordmark -

 NORDMARK@vaxkab.lne.kth.se
 {mcvax,munnari,ukc,unido}!enea!vaxkab.lne.kth.se!NORDMARK