Installing _FRB cookie ?

News,announcements,programming,fixes,game patches & discussions.

Moderator: troed

Post Reply
User avatar
exxos
Site Admin
Site Admin
Posts: 23496
Joined: Wed Aug 16, 2017 11:19 pm
Location: UK
Contact:

Installing _FRB cookie ?

Post by exxos »

Does anyone know how to do this ? I can only find this page http://toshyp.atari.org/en/004013.html#CJar While I can access XBIOS from HISOFT BASIC, I am not sure if that function is supported, but could be I just don't know how to use it in the first place.

Even ASM code with explanation would help.. anyone ?
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
User avatar
thorsten.otto
Posts: 148
Joined: Mon Nov 04, 2019 2:20 am

Re: Installing _FRB cookie ?

Post by thorsten.otto »

Code: Select all

The function is available when the cookie 'CJar' ($434A6172) is present. This is created by JARxxx (Cookie Jar Manager) or by Liberty.
So that function is not a standard XBIOS function, but only available if you ran that cookie jar manager. And you can detect its presence only by looking at the cookiejar... some kind of chicken/egg problem.
And although that might installing the cookie easier, it does not help you in making the buffer that the cookie points to resident.

Basically, the procedure you need (in some pseudo/C-like code)

Code: Select all

int install_frb(void)
{
	long *cookiejar;
	long size;
	void *buffer;
	
	cookiejar = (long *)Setexc(0x5a0 / 4, (void *)-1); /* get cookiejar */
	if (cookiejar == 0)
	{
		bailout(); /* no cookiejar; installing a new one not yet supported */
		return FALSE;
	}
	size = 0;
	while  (*cookiejar != 0 && *cookiejar != 0x5f465242L) /*  '_FRB' */
	{
		size++; /* count number of existing entries */
		cookiejar += 2; /* get to next entry */
	}
	if (*cookiejar != 0)
	{
		/* _FRB already present; nothing to do */
		return TRUE;
	}
	if (size + 2 > cookiejar[1]) /* check against cookie jar size */
	{
		/* no room in cookie jar */
		bailout();
		return FALSE;
	}
	buffer = Mxalloc(0, 0x10000L); /* allocate in ST-RAM only */
	if (buffer == 0)
	{
		/* not enough memory */
		return FALSE;
	}
	if (buffer == (void *)-32)
	{
		/* Mxalloc not supported */
		return FALSE;
	}
	/* copy the old end cookie */
	cookiejar[3] = cookiejar[1];
	cookiejar[2] = cookiejar[0];
	/* install our _FRB cookie */
	cookiejar[0] = 0x5f465242L;
	cookiejar[1] = (long)buffer;
	/* terminate and stay resident */
	Ptermres(256L, 0); /* we only need to keep the basepage */
}
Just written from memory, no guarantee that this actually works ;)

Adding some error messages might also be a good idea.

I'm not entirely sure about memory protection, normally that buffer should only be accessed by the harddisk driver from supervisor mode, if in doubt you may have to add the appropiate flags to make it globally readable/writable. But that only matters for MiNT.
Post Reply

Return to “SOFTWARE PROGRAMMING & DISCUSSION”