1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *   Mupen64plus-core - m64p_plugin.h                                      *
3  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4  *   Copyright (C) 2002 Hacktarux                                          *
5  *   Copyright (C) 2009 Richard Goedeken                                   *
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
21  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22 
23 #ifndef M64P_PLUGIN_H
24 #define M64P_PLUGIN_H
25 
26 #include <stdint.h>
27 #include "m64p_types.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*** Controller plugin's ****/
34 #define PLUGIN_NONE                 1
35 #define PLUGIN_MEMPAK               2
36 #define PLUGIN_RUMBLE_PAK           3 /* not implemented for non raw data */
37 #define PLUGIN_TRANSFER_PAK         4 /* not implemented for non raw data */
38 #define PLUGIN_RAW                  5 /* the controller plugin is passed in raw data */
39 
40 /***** Structures *****/
41 typedef struct {
42     uint8_t * RDRAM;
43     uint8_t * DMEM;
44     uint8_t * IMEM;
45 
46     uint32_t * MI_INTR_REG;
47 
48     uint32_t * SP_MEM_ADDR_REG;
49     uint32_t * SP_DRAM_ADDR_REG;
50     uint32_t * SP_RD_LEN_REG;
51     uint32_t * SP_WR_LEN_REG;
52     uint32_t * SP_STATUS_REG;
53     uint32_t * SP_DMA_FULL_REG;
54     uint32_t * SP_DMA_BUSY_REG;
55     uint32_t * SP_PC_REG;
56     uint32_t * SP_SEMAPHORE_REG;
57 
58     uint32_t * DPC_START_REG;
59     uint32_t * DPC_END_REG;
60     uint32_t * DPC_CURRENT_REG;
61     uint32_t * DPC_STATUS_REG;
62     uint32_t * DPC_CLOCK_REG;
63     uint32_t * DPC_BUFBUSY_REG;
64     uint32_t * DPC_PIPEBUSY_REG;
65     uint32_t * DPC_TMEM_REG;
66 
67     void (*CheckInterrupts)(void);
68     void (*ProcessDlistList)(void);
69     void (*ProcessAlistList)(void);
70     void (*ProcessRdpList)(void);
71     void (*ShowCFB)(void);
72 } RSP_INFO;
73 
74 typedef struct {
75     uint8_t * HEADER;  /* This is the rom header (first 40h bytes of the rom) */
76     uint8_t * RDRAM;
77     uint8_t * DMEM;
78     uint8_t * IMEM;
79 
80     uint32_t * MI_INTR_REG;
81 
82     uint32_t * DPC_START_REG;
83     uint32_t * DPC_END_REG;
84     uint32_t * DPC_CURRENT_REG;
85     uint32_t * DPC_STATUS_REG;
86     uint32_t * DPC_CLOCK_REG;
87     uint32_t * DPC_BUFBUSY_REG;
88     uint32_t * DPC_PIPEBUSY_REG;
89     uint32_t * DPC_TMEM_REG;
90 
91     uint32_t * VI_STATUS_REG;
92     uint32_t * VI_ORIGIN_REG;
93     uint32_t * VI_WIDTH_REG;
94     uint32_t * VI_INTR_REG;
95     uint32_t * VI_V_CURRENT_LINE_REG;
96     uint32_t * VI_TIMING_REG;
97     uint32_t * VI_V_SYNC_REG;
98     uint32_t * VI_H_SYNC_REG;
99     uint32_t * VI_LEAP_REG;
100     uint32_t * VI_H_START_REG;
101     uint32_t * VI_V_START_REG;
102     uint32_t * VI_V_BURST_REG;
103     uint32_t * VI_X_SCALE_REG;
104     uint32_t * VI_Y_SCALE_REG;
105 
106     void (*CheckInterrupts)(void);
107 } GFX_INFO;
108 
109 extern GFX_INFO gfx_info;
110 
111 typedef struct {
112     uint8_t * RDRAM;
113     uint8_t * DMEM;
114     uint8_t * IMEM;
115 
116     uint32_t * MI_INTR_REG;
117 
118     uint32_t * AI_DRAM_ADDR_REG;
119     uint32_t * AI_LEN_REG;
120     uint32_t * AI_CONTROL_REG;
121     uint32_t * AI_STATUS_REG;
122     uint32_t * AI_DACRATE_REG;
123     uint32_t * AI_BITRATE_REG;
124 
125     void (*CheckInterrupts)(void);
126 } AUDIO_INFO;
127 
128 typedef struct {
129     int Present;
130     int RawData;
131     int  Plugin;
132 } CONTROL;
133 
134 typedef union {
135     uint32_t Value;
136     struct {
137         unsigned R_DPAD       : 1;
138         unsigned L_DPAD       : 1;
139         unsigned D_DPAD       : 1;
140         unsigned U_DPAD       : 1;
141         unsigned START_BUTTON : 1;
142         unsigned Z_TRIG       : 1;
143         unsigned B_BUTTON     : 1;
144         unsigned A_BUTTON     : 1;
145 
146         unsigned R_CBUTTON    : 1;
147         unsigned L_CBUTTON    : 1;
148         unsigned D_CBUTTON    : 1;
149         unsigned U_CBUTTON    : 1;
150         unsigned R_TRIG       : 1;
151         unsigned L_TRIG       : 1;
152         unsigned Reserved1    : 1;
153         unsigned Reserved2    : 1;
154 
155         signed   X_AXIS       : 8;
156         signed   Y_AXIS       : 8;
157     };
158 } BUTTONS;
159 
160 typedef struct {
161     CONTROL *Controls;      /* A pointer to an array of 4 controllers .. eg:
162                                CONTROL Controls[4]; */
163 } CONTROL_INFO;
164 
165 /* common plugin function pointer types */
166 typedef void (*ptr_RomClosed)(void);
167 typedef int  (*ptr_RomOpen)(void);
168 #if defined(M64P_PLUGIN_PROTOTYPES)
169 EXPORT int  CALL RomOpen(void);
170 EXPORT void CALL RomClosed(void);
171 #endif
172 
173 /* video plugin function pointer types */
174 typedef void (*ptr_ChangeWindow)(void);
175 typedef int  (*ptr_InitiateGFX)(GFX_INFO Gfx_Info);
176 typedef void (*ptr_MoveScreen)(int x, int y);
177 typedef void (*ptr_ProcessDList)(void);
178 typedef void (*ptr_ProcessRDPList)(void);
179 typedef void (*ptr_ShowCFB)(void);
180 typedef void (*ptr_UpdateScreen)(void);
181 typedef void (*ptr_ViStatusChanged)(void);
182 typedef void (*ptr_ViWidthChanged)(void);
183 typedef void (*ptr_ReadScreen2)(void *dest, int *width, int *height, int front);
184 typedef void (*ptr_SetRenderingCallback)(void (*callback)(int));
185 typedef void (*ptr_ResizeVideoOutput)(int width, int height);
186 #if defined(M64P_PLUGIN_PROTOTYPES)
187 EXPORT void CALL ChangeWindow(void);
188 EXPORT int  CALL InitiateGFX(GFX_INFO Gfx_Info);
189 EXPORT void CALL MoveScreen(int x, int y);
190 EXPORT void CALL ProcessDList(void);
191 EXPORT void CALL ProcessRDPList(void);
192 EXPORT void CALL ShowCFB(void);
193 EXPORT void CALL UpdateScreen(void);
194 EXPORT void CALL ViStatusChanged(void);
195 EXPORT void CALL ViWidthChanged(void);
196 EXPORT void CALL ReadScreen2(void *dest, int *width, int *height, int front);
197 EXPORT void CALL SetRenderingCallback(void (*callback)(int));
198 EXPORT void CALL ResizeVideoOutput(int width, int height);
199 #endif
200 
201 /* frame buffer plugin spec extension */
202 typedef struct
203 {
204    uint32_t addr;
205    uint32_t size;
206    uint32_t width;
207    uint32_t height;
208 } FrameBufferInfo;
209 typedef void (*ptr_FBRead)(uint32_t addr);
210 typedef void (*ptr_FBWrite)(uint32_t addr, uint32_t size);
211 typedef void (*ptr_FBGetFrameBufferInfo)(void *p);
212 #if defined(M64P_PLUGIN_PROTOTYPES)
213 EXPORT void CALL FBRead(uint32_t addr);
214 EXPORT void CALL FBWrite(uint32_t addr, uint32_t size);
215 EXPORT void CALL FBGetFrameBufferInfo(void *p);
216 #endif
217 
218 /* audio plugin function pointers */
219 typedef void (*ptr_AiDacrateChanged)(int SystemType);
220 typedef void (*ptr_AiLenChanged)(void);
221 typedef int  (*ptr_InitiateAudio)(AUDIO_INFO Audio_Info);
222 typedef void (*ptr_ProcessAList)(void);
223 typedef void (*ptr_SetSpeedFactor)(int percent);
224 typedef void (*ptr_VolumeUp)(void);
225 typedef void (*ptr_VolumeDown)(void);
226 typedef int  (*ptr_VolumeGetLevel)(void);
227 typedef void (*ptr_VolumeSetLevel)(int level);
228 typedef void (*ptr_VolumeMute)(void);
229 typedef const char * (*ptr_VolumeGetString)(void);
230 #if defined(M64P_PLUGIN_PROTOTYPES)
231 EXPORT void CALL AiDacrateChanged(int SystemType);
232 EXPORT void CALL AiLenChanged(void);
233 EXPORT int  CALL InitiateAudio(AUDIO_INFO Audio_Info);
234 EXPORT void CALL ProcessAList(void);
235 EXPORT void CALL SetSpeedFactor(int percent);
236 EXPORT void CALL VolumeUp(void);
237 EXPORT void CALL VolumeDown(void);
238 EXPORT int  CALL VolumeGetLevel(void);
239 EXPORT void CALL VolumeSetLevel(int level);
240 EXPORT void CALL VolumeMute(void);
241 EXPORT const char * CALL VolumeGetString(void);
242 #endif
243 
244 /* input plugin function pointers */
245 typedef void (*ptr_ControllerCommand)(int Control, uint8_t *Command);
246 typedef void (*ptr_GetKeys)(int Control, BUTTONS *Keys);
247 typedef void (*ptr_InitiateControllers)(CONTROL_INFO ControlInfo);
248 typedef void (*ptr_ReadController)(int Control, uint8_t *Command);
249 #if defined(M64P_PLUGIN_PROTOTYPES)
250 EXPORT void CALL ControllerCommand(int Control, uint8_t *Command);
251 EXPORT void CALL GetKeys(int Control, BUTTONS *Keys);
252 EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo);
253 EXPORT void CALL ReadController(int Control, uint8_t *Command);
254 #endif
255 
256 /* RSP plugin function pointers */
257 typedef uint32_t (*ptr_DoRspCycles)(uint32_t Cycles);
258 typedef void (*ptr_InitiateRSP)(RSP_INFO Rsp_Info, uint32_t *CycleCount);
259 #if defined(M64P_PLUGIN_PROTOTYPES)
260 EXPORT uint32_t CALL DoRspCycles(uint32_t Cycles);
261 EXPORT void CALL InitiateRSP(RSP_INFO Rsp_Info, uint32_t *CycleCount);
262 #endif
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif /* M64P_PLUGIN_H */
269 
270 
271