PancakeNESEmu
A homebrewed NES Emulator written in C
Loading...
Searching...
No Matches
mem.c File Reference
#include "core/mem.h"
#include "macros.h"
#include <stdlib.h>
#include <sys/mman.h>
Include dependency graph for mem.c:

Go to the source code of this file.

Functions

memory init_memory ()
 This function allocate on the heap a memory of exactly TOTAL_MEMORY_SIZE.
 
void reset_memory (memory mem)
 This procedure set the entire memory to 0.
 
void free_memory (memory mem)
 This procedure free the memory pointer.
 
void memory_mirroring (memory mem)
 This procedure make the memory mirroring.
 

Function Documentation

◆ free_memory()

void free_memory ( memory mem)

This procedure free the memory pointer.

Parameters
[in]memThe memory pointer

Definition at line 25 of file mem.c.

25 {
26 munmap(mem, TOTAL_MEM_SIZE);
27}
#define TOTAL_MEM_SIZE
Definition macros.h:13

References TOTAL_MEM_SIZE.

Referenced by free_cpu().

Here is the caller graph for this function:

◆ init_memory()

memory init_memory ( )

This function allocate on the heap a memory of exactly TOTAL_MEMORY_SIZE.

Returns
The memory pointer

Definition at line 7 of file mem.c.

7 {
8
9 memory mem =
10 mmap(NULL, TOTAL_MEM_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
11
12 if (mem == MAP_FAILED) {
13 exit(EXIT_FAILURE);
14 }
15
16 return mem;
17}
#define EXIT_FAILURE
Definition macros.h:6
data * memory
Definition mem.h:6

References EXIT_FAILURE, and TOTAL_MEM_SIZE.

Referenced by main().

Here is the caller graph for this function:

◆ memory_mirroring()

void memory_mirroring ( memory mem)

This procedure make the memory mirroring.

Parameters
[in,out]memThe memory pointer

Definition at line 29 of file mem.c.

29 {
30 for (unsigned int i = 0; i < 0x800; ++i) {
31 mem[RAM_MIRROR_1_START + i] = mem[i];
32 mem[RAM_MIRROR_2_START + i] = mem[i];
33 mem[RAM_MIRROR_3_START + i] = mem[i];
34 }
35
36 for (unsigned int i = 0; i < 0x1ff8; i += 8) {
38 mem[PPU_MIRRORS_START_ONE + i] = mem[PPU_REG_ONE];
39 mem[PPU_MIRRORS_START_TWO + i] = mem[PPU_REG_TWO];
43 mem[PPU_MIRRORS_START_SIX + i] = mem[PPU_REG_SIX];
45 }
46}
#define PPU_REG_SEVEN
Definition macros.h:69
#define PPU_MIRRORS_START_ONE
Definition macros.h:76
#define RAM_MIRROR_1_START
Definition macros.h:51
#define PPU_REG_TWO
Definition macros.h:64
#define PPU_MIRRORS_START_TWO
Definition macros.h:77
#define PPU_REG_ONE
Definition macros.h:63
#define PPU_MIRRORS_START_SEVEN
Definition macros.h:82
#define PPU_MIRRORS_START_SIX
Definition macros.h:81
#define RAM_MIRROR_3_START
Definition macros.h:57
#define PPU_REG_SIX
Definition macros.h:68
#define PPU_MIRRORS_START_FIVE
Definition macros.h:80
#define PPU_REG_FIVE
Definition macros.h:67
#define PPU_REG_ZERO
Definition macros.h:62
#define PPU_REG_THREE
Definition macros.h:65
#define PPU_MIRRORS_START_THREE
Definition macros.h:78
#define PPU_MIRRORS_START_FOUR
Definition macros.h:79
#define PPU_MIRRORS_START_ZERO
Definition macros.h:75
#define RAM_MIRROR_2_START
Definition macros.h:54
#define PPU_REG_FOUR
Definition macros.h:66

References PPU_MIRRORS_START_FIVE, PPU_MIRRORS_START_FOUR, PPU_MIRRORS_START_ONE, PPU_MIRRORS_START_SEVEN, PPU_MIRRORS_START_SIX, PPU_MIRRORS_START_THREE, PPU_MIRRORS_START_TWO, PPU_MIRRORS_START_ZERO, PPU_REG_FIVE, PPU_REG_FOUR, PPU_REG_ONE, PPU_REG_SEVEN, PPU_REG_SIX, PPU_REG_THREE, PPU_REG_TWO, PPU_REG_ZERO, RAM_MIRROR_1_START, RAM_MIRROR_2_START, and RAM_MIRROR_3_START.

Referenced by step_cpu().

Here is the caller graph for this function:

◆ reset_memory()

void reset_memory ( memory mem)

This procedure set the entire memory to 0.

Parameters
[in,out]memThe memory pointer

Definition at line 19 of file mem.c.

19 {
20 for (unsigned int i = 0; i < TOTAL_MEM_SIZE; ++i) {
21 mem[i] = 0x00;
22 }
23}

References TOTAL_MEM_SIZE.

Referenced by main().

Here is the caller graph for this function: