Memory

From xboxdevwiki
Revision as of 14:11, 23 March 2017 by Eighthpence (talk | contribs) (Created page with "The Xbox has 64MB Memory. This could be expanded to 128MB of memory (and the motherboard has empty spots where these could have been) but no games took advantage of it. The m...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Xbox has 64MB Memory. This could be expanded to 128MB of memory (and the motherboard has empty spots where these could have been) but no games took advantage of it.

The memory was shared between the CPU and GPU. The BIOS and MCPX ROM are also mapped to memory at the top 16MB and the top 512bytes respectively.

Code for emulating the memory might consist of:

#define MAIN_MEMORY 64 * 1024 * 1024
#define BIOS_SIZE 256 * 1024
#define BIOS_MEMORY_SIZE 16 * 1024 * 1024
#define BIOS_MEMORY (0xFFFFFFFF - BIOS_MEMORY_SIZE + 1)
#define MCPX_SIZE   0x200
#define MCPX_MEMORY (0xFFFFFFFF - MCPX_SIZE + 1)

int mcpx_active = 1;

uint8_t memory[MAIN_MEMORY] = {0};
uint8_t bios[BIOS_SIZE] = {0};
uint8_t mcpx[MCPX_SIZE] = {0};

uint8_t get_memory_byte(uint32_t location) {
    if (location < MAIN_MEMORY) {
        return memory[location];
    }

    if (mcpx_active && location >= MCPX_MEMORY) {
        return mcpx[location - MCPX_MEMORY];
    }

    if (location >= BIOS_MEMORY) {
        return bios[(location - BIOS_MEMORY) % BIOS_SIZE];
    }

    printf("Memory in unspecified range: %08X\n", location);
    return 0;
}

uint16_t get_memory_word(uint32_t location) {
    return get_memory(location + 1) << 8 | get_memory(location);
}

uint32_t get_memory_dword(uint32_t location) {
    return get_memory_word(location + 2) << 16 | get_memory_word(location);
}

void deactivate_mcpx() {
    mcpx = 0;
}
<pre>