File: memorymap.h

package info (click to toggle)
cen64 0.3%2Bgit20180227-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,460 kB
  • sloc: ansic: 23,713; asm: 772; cpp: 663; makefile: 14
file content (62 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// bus/memory_map.h: System memory mapper.
//
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
// Copyright (C) 2015, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//

#ifndef __bus_memory_map_h__
#define __bus_memory_map_h__
#include "common.h"

// Callback functions to handle reads/writes.
typedef int (*memory_rd_function)(void *, uint32_t, uint32_t *);
typedef int (*memory_wr_function)(void *, uint32_t, uint32_t, uint32_t);

enum memory_map_color {
  MEMORY_MAP_BLACK,
  MEMORY_MAP_RED
};

struct memory_mapping {
  void *instance;

  memory_rd_function on_read;
  memory_wr_function on_write;

  uint32_t length;
  uint32_t start;
  uint32_t end;
};

struct memory_map_node {
  struct memory_map_node *left;
  struct memory_map_node *parent;
  struct memory_map_node *right;

  struct memory_mapping mapping;
  enum memory_map_color color;
};

struct memory_map {
  struct memory_map_node mappings[19];

  struct memory_map_node *nil;
  struct memory_map_node *root;
  unsigned next_map_index;
};

cen64_cold void create_memory_map(struct memory_map *map);

cen64_cold int map_address_range(struct memory_map *memory_map,
  uint32_t start, uint32_t length, void *instance,
  memory_rd_function on_read, memory_wr_function on_write);

cen64_hot const struct memory_mapping* resolve_mapped_address(
  const struct memory_map *memory_map, uint32_t address);

#endif