For those who don't know, here are details of the space manager functions.

Quote

#pragma once

#import "includes.h"

class spacemanager

{

public:

static int list_num;

static int organizeList(int *list);

static int mapSpace(int *list);

static int findSpace(int *list, int size);

static int confirmSpace(int *list, int index, int size);

static int freeSpace(int *list, int pos, int size);

static int claimSpace( int *list, int pos, int size);

};

list_num is the total number of entries in Atrius's free space table.#import "includes.h"

class spacemanager

{

public:

static int list_num;

static int organizeList(int *list);

static int mapSpace(int *list);

static int findSpace(int *list, int size);

static int confirmSpace(int *list, int index, int size);

static int freeSpace(int *list, int pos, int size);

static int claimSpace( int *list, int pos, int size);

};

orgaizeList - pretty self-explanatory, but is where my question(s) are.

mapSpace will either load the free space table, or if there isn't one, scan for free space. (Based on MFT pointers that point before MFT address. And after those, will scan from end of ROM.) It scan backwards, though, so once there is a non-zero, the space for that section is known. (32-bit aligned size.)

findSpace is simple, looks for the first entry in the free space list that has enough size that is needed.

confirmSpace checks if the entire section has 00s or not. (Depending on a flag) (It may also check if the freeSpace being used is all in freeSpace, but that's probably pointless with the findSpace function.) - It is obvious that this helps reduce overwritting any hex editor related edits... but otherwise is not required to have.

freeSpace literally adds another entry of freeSpace. (Checks each of the freeSpace entries to see whether that space can be added to it, if not, it will be added as a separate entry.)

claimSpace is similar to freeSpace, except that it removes the freeSpace.

My question is with organizeList.

I get that it sorts the list from least to greatest size... but I don't get the next part:

Quote

if (pos!=i)

{

val=list[pos<<1];

size=list[(pos<<1)+1];

list[pos<<1]=list[i<<1];

list[(pos<<1)+1]=list[(i<<1)+1];

if (val==list[i<<1])

{ list[i<<1]=val|

else

{ list[i<<1]=val; }

list[(i<<1)+1]=size;

}

The bolded sections.... Do those ever happen? And if so how? Otherwise, is it free to remove without problems?{

val=list[pos<<1];

size=list[(pos<<1)+1];

list[pos<<1]=list[i<<1];

list[(pos<<1)+1]=list[(i<<1)+1];

if (val==list[i<<1])

{ list[i<<1]=val|

**0x40000000**; }else

{ list[i<<1]=val; }

list[(i<<1)+1]=size;

}

**if (list[i<<1]==list[(i-1)<<1])**

{

list_num--;

for (ii=i; ii<list_num; ii++)

{

list[ii<<1]=list[(ii+1)<<1];

list[(ii<<1)+1]=list[((ii+1)<<1)+1];

}

list[list_num<<1]=0; list[(list_num<<1)+1]=0;

i--;

}{

list_num--;

for (ii=i; ii<list_num; ii++)

{

list[ii<<1]=list[(ii+1)<<1];

list[(ii<<1)+1]=list[((ii+1)<<1)+1];

}

list[list_num<<1]=0; list[(list_num<<1)+1]=0;

i--;

}

The top section is for switching entries (For the small to large sizes)

The bottom section looks like it removes an entry for when two addresses next to each other match.

And after this code is basically the stuff that frees the old free space table from the ROM and puts the updated free space table back into the ROM.

When doing this for the C# version, I think I'll try to make it a little simpler if I can... by removing confirmSpace, and also that the freeSpace table shouldn't "claim space" for itself. If table is going to be managed outside the ROM data. Maybe.)