User:Zzo38/Emulator plugin format: Difference between revisions

From NESdev Wiki
Jump to navigationJump to search
(Created page with "== Mapper == <pre> #define OPEN_BUS 0xFFFF #define CIRAM_BANK_0 0x8000 #define CIRAM_BANK_1 0x8400 #define BUS_CONFLICT 0x1000 typedef struct Mapper { // Provided by host ...")
 
No edit summary
Line 44: Line 44:
int define_mapper(U16 id,const char*name,(Mapper*)(*init)(Mapper_Info*));
int define_mapper(U16 id,const char*name,(Mapper*)(*init)(Mapper_Info*));
</pre>
</pre>
* OPEN_BUS: Returned by some functions to indicate that there is no data in the cartridge, or that you are not writing to CIRAM.
* CIRAM_BANK_0: Returned from some functions to indicate read/write the CIRAM when CIRAM A10 is low.
* CIRAM_BANK_1: Returned from some functions to indicate read/write the CIRAM when CIRAM A10 is high.
* BUS_CONFLICT: Should be bitwise OR by the other value to indicate that there is a bus conflict; the emulator can ignore it or keep track of a counter of bus conflicts.
* Mapper:
* NSF_Interface: Provide functions for expansion audio, audio input, IRQ input, timers, and CPU cycle counters.
* Mapper_Info:
* define_mapper: Define by the NES 2.0 mapper number, name, and initialization function.


== Input device ==
== Input device ==
Line 56: Line 65:
   // Provided by plugin
   // Provided by plugin
   void(*destroy)(InputDevice*);
   void(*destroy)(InputDevice*);
   void(*connect)(InputDevice*);
   void(*connect)(InputDevice*,U8);
   void(*disconnect)(InputDevice*);
   void(*disconnect)(InputDevice*);
  void(*irq_trigger)(InputDevice*,int); // class 0 only
   U8(*read)(InputDevice*);
   U8(*read)(InputDevice*);
   U8(*read_other)(InputDevice*); // class 0 only
   U8(*read_other)(InputDevice*); // class 0 only
   void(*write)(InputDevice*,U8);
   void(*write)(InputDevice*,U8);
  // Provided by plugin -- MIDI events
   void(*note_off)(InputDevice*,U8,U8,U8);
   void(*note_off)(InputDevice*,U8,U8,U8);
   void(*note_on)(InputDevice*,U8,U8,U8);
   void(*note_on)(InputDevice*,U8,U8,U8);
Line 68: Line 79:
   void(*channel_pressure)(InputDevice*,U8,U8);
   void(*channel_pressure)(InputDevice*,U8,U8);
   void(*pitch_wheel)(InputDevice*,U8,U16);
   void(*pitch_wheel)(InputDevice*,U8,U16);
   void(*sysex)(InputDevice*,U8*,U32);
   void(*sysex)(InputDevice*,const U8*,U32);
   void(*tune_request)(InputDevice*);
   void(*tune)(InputDevice*);
  void(*reset)(InputDevice*);
} InputDevice;
} InputDevice;


int define_input_device(const char*name,int class,(InputDevice*)(*init)(void));</pre>
int define_input_device(const char*name,int class,(InputDevice*)(*init)(void));</pre>
* InputDevice: The structure to store the input device data in the memory. It is possible for the plugin to add additional fields at the end.
** sound: 2A03 audio mixed with microphone (no expansion audio).
** light: Tell the light sense of the light gun.
** irq_write: Set the IRQ pin of Famicom expansion port high or low, which will trigger IRQ in the CPU and the cartridge can also read it.
** irq_read: Read the IRQ pin of Famicom expansion port, which is whatever the cartridge set it to. If it doesn't set, it is high.
** display: To display data to the user.
** destroy: Used to free the input device memory.
** connect: The device is connected. The argument is the initial OUT0, OUT1, OUT2; if it isn't on the expansion port then only OUT0 is used.
** disconnect: The device is disconnected.
** irq_trigger: Used if the cartridge asserts the IRQ. The argument is the new value 0 or 1.
** read: Called when the CPU request data from this port. Any unused pins should be high.
** read_other: Called when the CPU request data of the bit1 of the $4016 register for devices connected to the expansion port. All other bits must be high.
** write: Called when CPU set the OUT0, OUT1, OUT2 pins.
** note_off: MIDI message for note off. Parameter is channel, key, velocity. (Note for this and other MIDI messages: Please use only the low bit of the channel number; the other three bits are used for the emulator's purpose.)
** note_on: MIDI message for note on. Parameter is channel, key, velocity.
** key_pressure: MIDI message for key pressure. Parameter is channel, key, pressure.
** parameter: MIDI message for parameter. Parameter is channel, control number, control data.
** program: MIDI message for program change.
** channel_pressure: MIDI message for channel pressure.
** pitch_wheel: MIDI message for pitch wheel.
** sysex: MIDI system exclusive message. The data and length is specified as the parameter.
** tune: MIDI tune request message.
** reset: MIDI reset message.
* UserDisplay: A structure to display information to the user.
* define_input_device: Add a new input device into the emulator.
** name: The name of a input device.
** class: Specify the device class. 0=Famicom expansion port, 1=NES controller port, 2=NES controller port with only bit0, 3=NES controller port with only bit0 and only eight data in the latch like the standard controller protocol. If a class 1, 2, 3, is connected to expansion port then it is player 2 device.
** init: Should allocate a InputDevice structure and set up the "provided by plugin" fields and its own fields (the emulator will automatically set up the others).
The emulator will have its own way to somehow convert the user input into MIDI format; for example, by configuration dialog box, configuration files, some combination of this, or others.

Revision as of 04:08, 23 June 2013

Mapper

#define OPEN_BUS 0xFFFF
#define CIRAM_BANK_0 0x8000
#define CIRAM_BANK_1 0x8400
#define BUS_CONFLICT 0x1000

typedef struct Mapper {
  // Provided by host
  NSF_Interface*nsf;
  const U8*prg_rom;
  U8*prg_ram;
  U8*prg_battery_ram;
  const U8*chr_rom;
  U8*chr_ram;
  U8*chr_battery_ram;
  // Provided by plugin
  void(*destroy)(Mapper*);
  void(*reset)(Mapper*);
  U16(*prg_read)(Mapper*,U16);
  U16(*prg_write)(Mapper*,U16,U8);
  U16(*chr_access)(Mapper*,U16);
  U16(*chr_read)(Mapper*,U16);
  U16(*chr_write)(Mapper*,U16,U8);
  void(*quick_save)(Mapper*,U8*);
  void(*quick_restore)(Mapper*,U8*);
} Mapper;

typedef struct Mapper_Info {
  U8 version; // R
  U8 mirroring; // R
  U16 id; // R
  U32 prg_rom_size; // R
  U32 prg_ram_size; // R/W
  U32 prg_battery_ram_size; // R/W
  U32 chr_rom_size; // R
  U32 chr_ram_size; // R/W
  U32 chr_battery_ram_size; // R/W
  FILE*ines; // R
  int save_size; // W
  U8 audio_ext; // W
} Mapper_Info;

int define_mapper(U16 id,const char*name,(Mapper*)(*init)(Mapper_Info*));
  • OPEN_BUS: Returned by some functions to indicate that there is no data in the cartridge, or that you are not writing to CIRAM.
  • CIRAM_BANK_0: Returned from some functions to indicate read/write the CIRAM when CIRAM A10 is low.
  • CIRAM_BANK_1: Returned from some functions to indicate read/write the CIRAM when CIRAM A10 is high.
  • BUS_CONFLICT: Should be bitwise OR by the other value to indicate that there is a bus conflict; the emulator can ignore it or keep track of a counter of bus conflicts.
  • Mapper:
  • NSF_Interface: Provide functions for expansion audio, audio input, IRQ input, timers, and CPU cycle counters.
  • Mapper_Info:
  • define_mapper: Define by the NES 2.0 mapper number, name, and initialization function.

Input device

typedef struct InputDevice {
  // Provided by host
  U16 sound; // class 0 only
  U8 light;
  void(*irq_write)(InputDevice*,int); // class 0 only
  int(*irq_read)(InputDevice*); // class 0 only
  void(*display)(InputDevice*,UserDisplay*);
  // Provided by plugin
  void(*destroy)(InputDevice*);
  void(*connect)(InputDevice*,U8);
  void(*disconnect)(InputDevice*);
  void(*irq_trigger)(InputDevice*,int); // class 0 only
  U8(*read)(InputDevice*);
  U8(*read_other)(InputDevice*); // class 0 only
  void(*write)(InputDevice*,U8);
  // Provided by plugin -- MIDI events
  void(*note_off)(InputDevice*,U8,U8,U8);
  void(*note_on)(InputDevice*,U8,U8,U8);
  void(*key_pressure)(InputDevice*,U8,U8,U8);
  void(*parameter)(InputDevice*,U8,U8,U8);
  void(*program)(InputDevice*,U8,U8);
  void(*channel_pressure)(InputDevice*,U8,U8);
  void(*pitch_wheel)(InputDevice*,U8,U16);
  void(*sysex)(InputDevice*,const U8*,U32);
  void(*tune)(InputDevice*);
  void(*reset)(InputDevice*);
} InputDevice;

int define_input_device(const char*name,int class,(InputDevice*)(*init)(void));
  • InputDevice: The structure to store the input device data in the memory. It is possible for the plugin to add additional fields at the end.
    • sound: 2A03 audio mixed with microphone (no expansion audio).
    • light: Tell the light sense of the light gun.
    • irq_write: Set the IRQ pin of Famicom expansion port high or low, which will trigger IRQ in the CPU and the cartridge can also read it.
    • irq_read: Read the IRQ pin of Famicom expansion port, which is whatever the cartridge set it to. If it doesn't set, it is high.
    • display: To display data to the user.
    • destroy: Used to free the input device memory.
    • connect: The device is connected. The argument is the initial OUT0, OUT1, OUT2; if it isn't on the expansion port then only OUT0 is used.
    • disconnect: The device is disconnected.
    • irq_trigger: Used if the cartridge asserts the IRQ. The argument is the new value 0 or 1.
    • read: Called when the CPU request data from this port. Any unused pins should be high.
    • read_other: Called when the CPU request data of the bit1 of the $4016 register for devices connected to the expansion port. All other bits must be high.
    • write: Called when CPU set the OUT0, OUT1, OUT2 pins.
    • note_off: MIDI message for note off. Parameter is channel, key, velocity. (Note for this and other MIDI messages: Please use only the low bit of the channel number; the other three bits are used for the emulator's purpose.)
    • note_on: MIDI message for note on. Parameter is channel, key, velocity.
    • key_pressure: MIDI message for key pressure. Parameter is channel, key, pressure.
    • parameter: MIDI message for parameter. Parameter is channel, control number, control data.
    • program: MIDI message for program change.
    • channel_pressure: MIDI message for channel pressure.
    • pitch_wheel: MIDI message for pitch wheel.
    • sysex: MIDI system exclusive message. The data and length is specified as the parameter.
    • tune: MIDI tune request message.
    • reset: MIDI reset message.
  • UserDisplay: A structure to display information to the user.
  • define_input_device: Add a new input device into the emulator.
    • name: The name of a input device.
    • class: Specify the device class. 0=Famicom expansion port, 1=NES controller port, 2=NES controller port with only bit0, 3=NES controller port with only bit0 and only eight data in the latch like the standard controller protocol. If a class 1, 2, 3, is connected to expansion port then it is player 2 device.
    • init: Should allocate a InputDevice structure and set up the "provided by plugin" fields and its own fields (the emulator will automatically set up the others).

The emulator will have its own way to somehow convert the user input into MIDI format; for example, by configuration dialog box, configuration files, some combination of this, or others.