File: controller.h

package info (click to toggle)
cen64 0.3%2Bgit20160403-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,160 kB
  • sloc: ansic: 14,512; asm: 772; cpp: 663; makefile: 12
file content (86 lines) | stat: -rw-r--r-- 2,201 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// pi/controller.h: Parallel interface controller.
//
// 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 __pi_controller_h__
#define __pi_controller_h__
#include "common.h"
#include "os/common/save_file.h"

struct bus_controller *bus;

enum pi_register {
#define X(reg) reg,
#include "pi/registers.md"
#undef X
  NUM_PI_REGISTERS
};

#ifdef DEBUG_MMIO_REGISTER_ACCESS
extern const char *pi_register_mnemonics[NUM_PI_REGISTERS];
#endif

#define FLASHRAM_SIZE 0x20000

enum flashram_mode {
  FLASHRAM_IDLE = 0,
  FLASHRAM_ERASE,
  FLASHRAM_WRITE,
  FLASHRAM_READ,
  FLASHRAM_STATUS,
};

struct flashram {
  uint8_t *data;
  uint64_t status;
  enum flashram_mode mode;
  size_t offset;
  size_t rdram_pointer;
};

struct pi_controller {
  struct bus_controller *bus;

  const uint8_t *rom;
  size_t rom_size;
  struct save_file *sram;
  struct save_file *flashram_file;
  struct flashram flashram;

  uint64_t counter;
  uint32_t bytes_to_copy;
  bool is_dma_read;

  uint32_t regs[NUM_PI_REGISTERS];
};

cen64_cold int pi_init(struct pi_controller *pi, struct bus_controller *bus,
  const uint8_t *rom, size_t rom_size, const struct save_file *sram,
  const struct save_file *flashram);

// Only invoke pi_cycle_ when the counter has expired (timeout).
void pi_cycle_(struct pi_controller *pi);

cen64_flatten cen64_hot static inline void pi_cycle(struct pi_controller *pi) {
  if (unlikely(pi->counter-- == 0))
    pi_cycle_(pi);
}

int read_cart_rom(void *opaque, uint32_t address, uint32_t *word);
int read_pi_regs(void *opaque, uint32_t address, uint32_t *word);
int write_cart_rom(void *opaque, uint32_t address, uint32_t word, uint32_t dqm);
int write_pi_regs(void *opaque, uint32_t address, uint32_t word, uint32_t dqm);

int read_flashram(void *opaque, uint32_t address, uint32_t *word);
int write_flashram(void *opaque, uint32_t address, uint32_t word, uint32_t dqm);
int read_sram(void *opaque, uint32_t address, uint32_t *word);
int write_sram(void *opaque, uint32_t address, uint32_t word, uint32_t dqm);

#endif