1 module m64p_plugin;
2 
3 import m64p_types;
4 
5 @nogc nothrow __gshared extern(C):
6 
7     /*** Controller plugin's ****/
8     enum PLUGIN_NONE         = 1;
9     enum PLUGIN_MEMPAK       = 2;
10     enum PLUGIN_RUMBLE_PAK   = 3; /* not implemented for non raw data */
11     enum PLUGIN_TRANSFER_PAK = 4; /* not implemented for non raw data */
12     enum PLUGIN_RAW          = 5; /* the controller plugin is passed in raw data */
13     enum PLUGIN_BIO_PAK      = 6;
14 
15     /***** Structures *****/
16     struct RSP_INFO
17     {
18         ubyte* RDRAM;
19         ubyte* DMEM;
20         ubyte* IMEM;
21 
22         uint* MI_INTR_REG;
23 
24         uint* SP_MEM_ADDR_REG;
25         uint* SP_DRAM_ADDR_REG;
26         uint* SP_RD_LEN_REG;
27         uint* SP_WR_LEN_REG;
28         uint* SP_STATUS_REG;
29         uint* SP_DMA_FULL_REG;
30         uint* SP_DMA_BUSY_REG;
31         uint* SP_PC_REG;
32         uint* SP_SEMAPHORE_REG;
33 
34         uint* DPC_START_REG;
35         uint* DPC_END_REG;
36         uint* DPC_CURRENT_REG;
37         uint* DPC_STATUS_REG;
38         uint* DPC_CLOCK_REG;
39         uint* DPC_BUFBUSY_REG;
40         uint* DPC_PIPEBUSY_REG;
41         uint* DPC_TMEM_REG;
42 
43         void function() CheckInterrupts;
44         void function() ProcessDlistList;
45         void function() ProcessAlistList;
46         void function() ProcessRdpList;
47         void function() ShowCFB;
48     }
49 
50     struct GFX_INFO
51     {
52         ubyte* HEADER;  /* This is the rom header (first 40h bytes of the rom) */
53         ubyte* RDRAM;
54         ubyte* DMEM;
55         ubyte* IMEM;
56 
57         uint* MI_INTR_REG;
58 
59         uint* DPC_START_REG;
60         uint* DPC_END_REG;
61         uint* DPC_CURRENT_REG;
62         uint* DPC_STATUS_REG;
63         uint* DPC_CLOCK_REG;
64         uint* DPC_BUFBUSY_REG;
65         uint* DPC_PIPEBUSY_REG;
66         uint* DPC_TMEM_REG;
67 
68         uint* VI_STATUS_REG;
69         uint* VI_ORIGIN_REG;
70         uint* VI_WIDTH_REG;
71         uint* VI_INTR_REG;
72         uint* VI_V_CURRENT_LINE_REG;
73         uint* VI_TIMING_REG;
74         uint* VI_V_SYNC_REG;
75         uint* VI_H_SYNC_REG;
76         uint* VI_LEAP_REG;
77         uint* VI_H_START_REG;
78         uint* VI_V_START_REG;
79         uint* VI_V_BURST_REG;
80         uint* VI_X_SCALE_REG;
81         uint* VI_Y_SCALE_REG;
82 
83         void function() CheckInterrupts;
84 
85         /* The GFX_INFO.version parameter was added in version 2.5.1 of the core.
86         Plugins should ensure the core is at least this version before
87         attempting to read GFX_INFO.version. */
88         uint Version;
89         /* SP_STATUS_REG and RDRAM_SIZE were added in version 2 of GFX_INFO.version.
90         Plugins should only attempt to read these values if GFX_INFO.version is at least 2. */
91 
92         /* The RSP plugin should set (HALT | BROKE | TASKDONE) *before* calling ProcessDList.
93         It should not modify SP_STATUS_REG after ProcessDList has returned.
94         This will allow the GFX plugin to unset these bits if it needs. */
95         uint* SP_STATUS_REG;
96         const uint* RDRAM_SIZE;
97     }
98 
99     struct AUDIO_INFO
100     {
101         ubyte* RDRAM;
102         ubyte* DMEM;
103         ubyte* IMEM;
104 
105         uint* MI_INTR_REG;
106 
107         uint* AI_DRAM_ADDR_REG;
108         uint* AI_LEN_REG;
109         uint* AI_CONTROL_REG;
110         uint* AI_STATUS_REG;
111         uint* AI_DACRATE_REG;
112         uint* AI_BITRATE_REG;
113 
114         void function() CheckInterrupts;
115     }
116 
117     struct CONTROL
118     {
119         int Present;
120         int RawData;
121         int Plugin;
122     }
123 
124     union BUTTONS
125     {
126         uint Value;
127         
128         import std.bitmanip : bitfields;
129         mixin(bitfields!(
130             uint, "uR_DPAD",       1,
131             uint, "uL_DPAD",       1,
132             uint, "uD_DPAD",       1,
133             uint, "uU_DPAD",       1,
134             uint, "uSTART_BUTTON", 1,
135             uint, "uZ_TRIG",       1,
136             uint, "uB_BUTTON",     1,
137             uint, "uA_BUTTON",     1,
138 
139             uint, "uR_CBUTTON",    1,
140             uint, "uL_CBUTTON",    1,
141             uint, "uD_CBUTTON",    1,
142             uint, "uU_CBUTTON",    1,
143             uint, "uR_TRIG",       1,
144             uint, "uL_TRIG",       1,
145             uint, "uReserved1",    1,
146             uint, "uReserved2",    1,
147 
148             int,  "X_AXIS",        8,
149             int,  "Y_AXIS",        8
150         ));
151     }
152 
153     struct CONTROL_INFO
154     {
155         CONTROL *Controls;      /* A pointer to an array of 4 controllers .. eg:
156                                 CONTROL Controls[4]; */
157     }
158 
159     /* common plugin function pointer types */
160     int function() RomOpen;
161     void function() RomClosed;
162 
163     /* video plugin function pointer types */
164     void function() ChangeWindow;
165     int  function(GFX_INFO Gfx_Info) InitiateGFX;
166     void function(int x, int y) MoveScreen;
167     void function() ProcessDList;
168     void function() ProcessRDPList;
169     void function() ShowCFB;
170     void function() UpdateScreen;
171     void function() ViStatusChanged;
172     void function() ViWidthChanged;
173     void function(void* dest, int* width, int* height, int front) ReadScreen2;
174     void function(void function(int) callback) SetRenderingCallback;
175     void function(int width, int height) ResizeVideoOutput;
176 
177     /* frame buffer plugin spec extension */
178     struct FrameBufferInfo
179     {
180         uint addr;
181         uint size;
182         uint width;
183         uint height;
184     }
185 
186     void function(uint addr) FBRead;
187     void function(uint addr, uint size) FBWrite;
188     void function(void* p) FBGetFrameBufferInfo;
189 
190     /* audio plugin function pointers */
191     void function(int SystemType) AiDacrateChanged;
192     void function() AiLenChanged;
193     int  function(AUDIO_INFO Audio_Info) InitiateAudio;
194     void function() ProcessAList;
195     void function(int percent) SetSpeedFactor;
196     void function() VolumeUp;
197     void function() VolumeDown;
198     int  function() VolumeGetLevel;
199     void function(int level) VolumeSetLevel;
200     void function() VolumeMute;
201     const(char)* function() VolumeGetString;
202 
203     /* input plugin function pointers */
204     void function(int Control, ubyte* Command) ControllerCommand;
205     void function(int Control, BUTTONS* Keys) GetKeys;
206     void function(CONTROL_INFO ControlInfo) InitiateControllers;
207     void function(int Control, ubyte* Command) ReadController;
208     void function(int keymod, int keysym) SDL_KeyDown;
209     void function(int keymod, int keysym) SDL_KeyUp;
210     void function() RenderCallback;
211 
212     /* RSP plugin function pointers */
213     uint function(uint Cycles) DoRspCycles;
214     void function(RSP_INFO Rsp_Info, uint* CycleCount) InitiateRSP;