File: interface.hpp

package info (click to toggle)
higan 094-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,780 kB
  • ctags: 15,643
  • sloc: cpp: 103,963; ansic: 659; makefile: 531; sh: 25
file content (122 lines) | stat: -rwxr-xr-x 4,230 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef EMULATOR_INTERFACE_HPP
#define EMULATOR_INTERFACE_HPP

namespace Emulator {

struct Interface {
  struct Information {
    string name;
    unsigned width;
    unsigned height;
    bool overscan;
    double aspectRatio;
    bool resettable;
    struct Capability {
      bool states;
      bool cheats;
    } capability;
  } information;

  struct Media {
    unsigned id;
    string name;
    string type;
    bool bootable;  //false for cartridge slots (eg Sufami Turbo cartridges)
  };
  vector<Media> media;

  struct Device {
    unsigned id;
    unsigned portmask;
    string name;
    struct Input {
      unsigned id;
      unsigned type;  //0 = digital, 1 = analog (relative), 2 = rumble
      string name;
      unsigned guid;
    };
    vector<Input> input;
    vector<unsigned> order;
  };

  struct Port {
    unsigned id;
    string name;
    vector<Device> device;
  };
  vector<Port> port;

  struct Bind {
    virtual void loadRequest(unsigned, string, string) {}
    virtual void loadRequest(unsigned, string) {}
    virtual void saveRequest(unsigned, string) {}
    virtual uint32_t videoColor(unsigned, uint16_t, uint16_t, uint16_t, uint16_t) { return 0u; }
    virtual void videoRefresh(const uint32_t*, const uint32_t*, unsigned, unsigned, unsigned) {}
    virtual void audioSample(int16_t, int16_t) {}
    virtual int16_t inputPoll(unsigned, unsigned, unsigned) { return 0; }
    virtual void inputRumble(unsigned, unsigned, unsigned, bool) {}
    virtual unsigned dipSettings(const Markup::Node&) { return 0; }
    virtual string path(unsigned) { return ""; }
    virtual string server() { return ""; }
    virtual void notify(string text) { print(text, "\n"); }
  };
  Bind* bind = nullptr;

  //callback bindings (provided by user interface)
  void loadRequest(unsigned id, string name, string type) { return bind->loadRequest(id, name, type); }
  void loadRequest(unsigned id, string path) { return bind->loadRequest(id, path); }
  void saveRequest(unsigned id, string path) { return bind->saveRequest(id, path); }
  uint32_t videoColor(unsigned source, uint16_t alpha, uint16_t red, uint16_t green, uint16_t blue) { return bind->videoColor(source, alpha, red, green, blue); }
  void videoRefresh(const uint32_t* palette, const uint32_t* data, unsigned pitch, unsigned width, unsigned height) { return bind->videoRefresh(palette, data, pitch, width, height); }
  void audioSample(int16_t lsample, int16_t rsample) { return bind->audioSample(lsample, rsample); }
  int16_t inputPoll(unsigned port, unsigned device, unsigned input) { return bind->inputPoll(port, device, input); }
  void inputRumble(unsigned port, unsigned device, unsigned input, bool enable) { return bind->inputRumble(port, device, input, enable); }
  unsigned dipSettings(const Markup::Node& node) { return bind->dipSettings(node); }
  string path(unsigned group) { return bind->path(group); }
  string server() { return bind->server(); }
  template<typename... Args> void notify(Args&&... args) { return bind->notify({std::forward<Args>(args)...}); }

  //information
  virtual string title() = 0;
  virtual double videoFrequency() = 0;
  virtual double audioFrequency() = 0;

  //media interface
  virtual bool loaded() { return false; }
  virtual string sha256() { return ""; }
  virtual unsigned group(unsigned id) = 0;
  virtual void load(unsigned id) {}
  virtual void save() {}
  virtual void load(unsigned id, const stream& memory) {}
  virtual void save(unsigned id, const stream& memory) {}
  virtual void unload() {}

  //system interface
  virtual void connect(unsigned port, unsigned device) {}
  virtual void power() {}
  virtual void reset() {}
  virtual void run() {}

  //time functions
  virtual bool rtc() { return false; }
  virtual void rtcsync() {}

  //state functions
  virtual serializer serialize() = 0;
  virtual bool unserialize(serializer&) = 0;

  //cheat functions
  virtual void cheatSet(const lstring& = lstring{}) {}

  //utility functions
  enum class PaletteMode : unsigned { Literal, Channel, Standard, Emulation };
  virtual void paletteUpdate(PaletteMode mode) {}

  //debugger functions
  virtual bool tracerEnable(bool) { return false; }
  virtual void exportMemory() {}
};

}

#endif