💾 Archived View for mirrors.apple2.org.za › archive › apple.cabi.net › FAQs.and.INFO › GSOS › memman… captured on 2023-03-20 at 22:50:22.

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Newsgroups: comp.sys.apple2.programmer
Path: news.weeg.uiowa.edu!news.uiowa.edu!uunet!olivea!hal.com!decwrl!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson
From: dempson@swell.actrix.gen.nz (David Empson)
Subject: Re: reserving memory under ProDOS 8 using the memory manager
Organization: Actrix Information Exchange
Date: Mon, 31 Jan 1994 13:53:05 GMT
Message-ID: <CKHyKI.MBt@actrix.gen.nz>
References: <CKBCCD.6Mw@griffin.cuc.ab.ca>
Sender: dempson@actrix.gen.nz (David Empson)
Lines: 154

In article <CKBCCD.6Mw@griffin.cuc.ab.ca> dockery@griffin.cuc.ab.ca (Sean Dockery) writes:
> Forgive me for being rather naive and without adequate programming
> references, but I have a few simple questions for which I need answers
> so that my program won't break the environment.  :)

It is good to see you asking these questions before your program
causes something to crash.  :-)
 
> At this point in time, I wish to increase the size of the modem input
> buffer to something as large as 16K.  I figured that the SHR video
> buffer would be perfect as it is guarenteed not to be in use while my
> program is running.  

No it isn't.  Someone might call up a CDA which uses the super hi-res
screen.  A prime example is SoftSwitch, from Roger Wagner Publishing.
A CDA might also decide to use double hi-res graphics.

A better idea would be to use NewHandle to allocate a larger buffer
outside bank 0 and bank 1 while your program is running, and restore
the original buffer when you exit (freeing the handle in the process).

> My questions are as follows:
> 
>      Is it absolutely necessary to use the memory manager to reserve
> this space even though it is an eight bit program, and there would be
> no (foreseen) memory conflicts?

If you boot via GS/OS, then all of bank zero and one is reserved for
use by ProDOS-8 applications.  If you boot ProDOS-8 directly, then
most of bank 0 and 1 is unallocated, and may be allocated
automatically by a later NewHandle call, so you probably should
allocate it yourself to protect it.

>      How are the default 2K buffers allocated by the firmware?  That
> is, does the firmware go through the memory manager or does it have
> some dedicated (reserved) RAM somewhere in the machine? 

It isn't documented, as far as I know.  It almost certainly uses the
memory manager.
 
>      Are the tool locater, memory manager, and miscellaneous toolsets
> ROM-based?  That is, do I have to worry about people booting ProDOS 8
> on the Apple IIGS from a floppy disk?

Yes, they are ROM based.

There is a big catch: you can't make a MMStartUp call if the area of
memory you are running from hasn't been allocated (as happens if you
boot directly into ProDOS-8).

To get around this, you should start up the toolbox using the
following code:

	clc
	xce
	rep	#$30		; Get into 16-bit native mode
	stz	NewID		; I haven't created a new user ID
	_TLStartUp
	pha
	_MMStartUp
	pla
	bcc	MM_OK		; This is probably a bad branch.  :-)

	_MTStartUp

	pha
	pea	$1000
	_GetNewID		; Get me a new user ID (Application)
	pla
	sta	NewID		; Save it for later

	pha
	pha			; Result space
	pea	$0000
	pea	$B800		; Block size
	lda	NewID
	pha			; User ID
	pea	$C002		; Attributes: locked, fixed, absolute
	pea	$0000
	pea	$0800		; Location (bank 0, $0800-$BFFF)
	_NewHandle
	plx
	ply
	bcs	HelpMe		; This shouldn't happen!
	sty	Bnk0Hnd
	stx	Bnk0Hnd+2	; Save handle to bank 0 memory
	pha
	pha			; Result space
	pea	$0000
	pea	$B800		; Block size
	lda	NewID
	pha			; User ID
	pea	$C002		; Attributes: locked, fixed, absolute
	pea	$0001
	pea	$0800		; Location (bank 1, $0800-$BFFF)
	_NewHandle
	plx
	ply
	bcs	HelpMe		; This shouldn't happen!
	sty	Bnk1Hnd
	stx	Bnk1Hnd+2	; Save handle to bank 0 memory

	pha
	_MMStartup
	pla
	bcs	HelpMe		; This shouldn't happen!
MM_OK	sta	MyID		; Save the memory ID


You can now use NewHandle to allocate a buffer of the necessary size,
using attributes of "locked, fixed, purge=0, no special memory"
($C008).  You can allocate a single handle, say 32k, then use it as
two separate buffers of 16k each.  Don't forget to de-reference the
handle before using it as a pointer!

A note regarding the above code: if you had to use the special code to
create the user ID and allocate the two handles, then you should
probably free them again on exit:


	lda	NewID		; Did we allocate our own memory?
	beq	No_ID
	lda	Bnk1Hnd+2	; Yes, so free it.
	pha
	lda	Bnk1Hnd
	pha
	_DisposeHandle
	lda	Bnk0Hnd+2
	pha
	lda	Bnk0Hnd
	pha
	_DisposeHandle
	lda	NewID
	pha
	_DeleteID		; and get rid of the user ID
No_ID	_MTShutDown
	_MMShutDown
	_TLShutDown
	sec
	xce

Also note that all of this code is in 16-bit native mode.  Any
immediate operands of A and X are 16 bits, and any referenced
variables are two bytes (four bytes for the handles).


Do you have the necessary information for getting and setting the
buffer addresses (from the IIgs Firmware Reference)?
-- 
David Empson                                                               
dempson@swell.actrix.gen.nz                                                
Snail mail: P.O. Box 27-103, Wellington, New Zealand