TransferBoy icon indicating copy to clipboard operation
TransferBoy copied to clipboard

Check for available memory the right way.

Open joeldipops opened this issue 5 years ago • 0 comments

64 Doom does it like this. 0x80000318 must be a hardware register that contains max available memory

    int available_memory_size = *(int *)(0x80000318);

    if(available_memory_size != 0x800000)

From here: https://github.com/mikeryan/n64dev/blob/master/docs/n64.lyx

To check how much memory is installed, we consult the address 0x80000318. It corresponds to osMemSize from the SDK, and contains the size of memory (0x00400000 for 4MB or 0x00800000 for 8MB). The PIF-ROM code detects the size of memory and sets the value at that address before jumping to program code. If we wish to detect the size of memory ourselves instead of using the value the PIF-ROM gave us, we can use the following algorithm:

Start at address (0xA0400000 - 4) and a memory count of 4MB.

Write a 32-bit word to the address, read it back, and compare it to the value written.

If it is the same, add 0x100000 to the address and 1MB to the memory count.

Repeat until the memory count is equal to the desired amount of memory. If we are only verifying the (non)existence of an officially-released memory expansion pack, stop when the memory count is equal to 8MB.

Note that an attempt to access a non-existent physical memory address will result in an exception, so in order to prevent a CPU crash when performing memory detection, an appropriate general exception handler must be installed.

joeldipops avatar Jan 29 '20 03:01 joeldipops