forked from RetroPinUpgrade/Trident2020
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRPU.h
305 lines (267 loc) · 12.3 KB
/
RPU.h
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/**************************************************************************
* This file is part of the RPU for Arduino Project.
I, Dick Hamill, the author of this program disclaim all copyright
in order to make this program freely available in perpetuity to
anyone who would like to use it. Dick Hamill, 3/31/2023
RPU is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RPU is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See <https://www.gnu.org/licenses/>.
*/
#ifndef RPU_OS_H
#define RPU_OS_MAJOR_VERSION 5
#define RPU_OS_MINOR_VERSION 8
struct PlayfieldAndCabinetSwitch {
byte switchNum;
byte solenoid;
byte solenoidHoldTime;
};
#define SW_SELF_TEST_SWITCH 0x7F
#define SOL_NONE 0x0F
#define SWITCH_STACK_EMPTY 0xFF
#define CONTSOL_DISABLE_FLIPPERS 0x40
#define CONTSOL_DISABLE_COIN_LOCKOUT 0x20
// RPU_InitializeMPU will always boot none of the following
// parameters are set to force it back to original code
#define RPU_CMD_BOOT_ORIGINAL 0x0001 /* This will boot to original unconditionally (disables new code completely for this install) */
#define RPU_CMD_BOOT_ORIGINAL_IF_CREDIT_RESET 0x0002 /* Only supported on Rev 4 or greater, boots original if the C/R button is held at power on */
#define RPU_CMD_BOOT_ORIGINAL_IF_NOT_CREDIT_RESET 0x0004 /* Only supported on Rev 4 or greater, boots original if the C/R button is NOT held at power on */
#define RPU_CMD_BOOT_ORIGINAL_IF_SWITCH_CLOSED 0x0008 /* boots to original if the switch is closed at power on */
#define RPU_CMD_BOOT_ORIGINAL_IF_NOT_SWITCH_CLOSED 0x0010 /* boots to original if the switch is NOT closed at power on */
#define RPU_CMD_AUTODETECT_ARCHITECTURE 0x0040 /* For Rev 101 and greater--the code detects architecture of board (mainly for diagnostics applications) */
#define RPU_CMD_PERFORM_MPU_TEST 0x0080 /* perform basic tests on PIAs and return result codes */
// If the caller chooses this option, it's up to them
// to honor the RPU_RET_ORIGINAL_CODE_REQUESTED return
// flag and halt the Arduino with a while(1);
#define RPU_CMD_INIT_AND_RETURN_EVEN_IF_ORIGINAL_CHOSEN 0x0100
#define RPU_RET_NO_ERRORS 0
#define RPU_RET_U10_PIA_ERROR 0x0001
#define RPU_RET_U11_PIA_ERROR 0x0002
#define RPU_RET_PIA_1_ERROR 0x0004
#define RPU_RET_PIA_2_ERROR 0x0008
#define RPU_RET_PIA_3_ERROR 0x0010
#define RPU_RET_PIA_4_ERROR 0x0020
#define RPU_RET_PIA_5_ERROR 0x0040
#define RPU_RET_OPTION_NOT_SUPPORTED 0x0080
#define RPU_RET_6800_DETECTED 0x0100
#define RPU_RET_6802_OR_8_DETECTED 0x0200
#define RPU_RET_DIAGNOSTIC_REQUESTED 0x1000
#define RPU_RET_SELECTOR_SWITCH_ON 0x2000
#define RPU_RET_CREDIT_RESET_BUTTON_HIT 0x4000
#define RPU_RET_ORIGINAL_CODE_REQUESTED 0x8000
// Function Prototypes
// Initialization
unsigned long RPU_InitializeMPU(
unsigned long initOptions = RPU_CMD_BOOT_ORIGINAL_IF_CREDIT_RESET | RPU_CMD_BOOT_ORIGINAL_IF_NOT_SWITCH_CLOSED | RPU_CMD_PERFORM_MPU_TEST,
byte creditResetSwitch = 0xFF );
void RPU_SetupGameSwitches(int s_numSwitches, int s_numPrioritySwitches, PlayfieldAndCabinetSwitch *s_gameSwitchArray);
byte RPU_GetDipSwitches(byte index);
// Swtiches
byte RPU_PullFirstFromSwitchStack();
boolean RPU_ReadSingleSwitchState(byte switchNum);
void RPU_PushToSwitchStack(byte switchNumber);
boolean RPU_GetUpDownSwitchState(); // This always returns true for RPU_MPU_ARCHITECTURE==1 (no up/down switch)
void RPU_ClearUpDownSwitchState();
// Solenoids
void RPU_PushToSolenoidStack(byte solenoidNumber, byte numPushes, boolean disableOverride = false);
void RPU_SetCoinLockout(boolean lockoutOff = false, byte solbit = CONTSOL_DISABLE_COIN_LOCKOUT);
void RPU_SetDisableFlippers(boolean disableFlippers = true, byte solbit = CONTSOL_DISABLE_FLIPPERS);
void RPU_SetContinuousSolenoidBit(boolean bitOn, byte solBit = 0x10);
#if (RPU_MPU_ARCHITECTURE>=10)
void RPU_SetContinuousSolenoid(boolean solOn, byte solNum);
#endif
boolean RPU_FireContinuousSolenoid(byte solBit, byte numCyclesToFire);
byte RPU_ReadContinuousSolenoids();
void RPU_DisableSolenoidStack();
void RPU_EnableSolenoidStack();
boolean RPU_PushToTimedSolenoidStack(byte solenoidNumber, byte numPushes, unsigned long whenToFire, boolean disableOverride = false);
void RPU_UpdateTimedSolenoidStack(unsigned long curTime);
// Displays
byte RPU_SetDisplay(int displayNumber, unsigned long value, boolean blankByMagnitude=false, byte minDigits=2, boolean showCommasByMagnitude=false);
void RPU_SetDisplayBlank(int displayNumber, byte bitMask);
void RPU_SetDisplayCredits(int value, boolean displayOn = true, boolean showBothDigits=true);
void RPU_SetDisplayMatch(int value, boolean displayOn = true, boolean showBothDigits=true);
void RPU_SetDisplayBallInPlay(int value, boolean displayOn = true, boolean showBothDigits=true);
void RPU_SetDisplayFlash(int displayNumber, unsigned long value, unsigned long curTime, int period=500, byte minDigits=2);
void RPU_SetDisplayFlashCredits(unsigned long curTime, int period=100);
void RPU_CycleAllDisplays(unsigned long curTime, byte digitNum=0); // Self-test function
byte RPU_GetDisplayBlank(int displayNumber);
#if (RPU_MPU_ARCHITECTURE==15)
byte RPU_SetDisplayText(int displayNumber, char *text, boolean blankByLength=true);
#endif
#if defined(RPU_OS_ADJUSTABLE_DISPLAY_INTERRUPT)
void RPU_SetDisplayRefreshConstant(int intervalConstant);
#endif
// Lamps
void RPU_SetLampState(int lampNum, byte s_lampState, byte s_lampDim=0, int s_lampFlashPeriod=0);
void RPU_ApplyFlashToLamps(unsigned long curTime);
void RPU_FlashAllLamps(unsigned long curTime); // Self-test function
void RPU_TurnOffAllLamps();
void RPU_SetDimDivisor(byte level=1, byte divisor=2); // 2 means 50% duty cycle, 3 means 33%, 4 means 25%...
byte RPU_ReadLampState(int lampNum);
byte RPU_ReadLampDim(int lampNum);
int RPU_ReadLampFlash(int lampNum);
// Sound Functions
#ifdef RPU_OS_USE_S_AND_T
void RPU_PlaySoundSAndT(byte soundByte);
#endif
#ifdef RPU_OS_USE_SB100
void RPU_PlaySB100(byte soundByte);
#if (RPU_OS_HARDWARE_REV==2)
void RPU_PlaySB100Chime(byte soundByte);
#endif
#endif
#ifdef RPU_OS_USE_DASH51
void RPU_PlaySoundDash51(byte soundByte);
#endif
#if (RPU_OS_HARDWARE_REV>=2 && defined(RPU_OS_USE_SB300))
void RPU_PlaySB300SquareWave(byte soundRegister, byte soundByte);
void RPU_PlaySB300Analog(byte soundRegister, byte soundByte);
#endif
#if defined(RPU_OS_USE_WTYPE_1_SOUND) || defined(RPU_OS_USE_WTYPE_2_SOUND)
void RPU_SetSoundValueLimits(unsigned short lowerLimit, unsigned short upperLimit);
void RPU_PushToSoundStack(unsigned short soundNumber, byte numPushes);
boolean RPU_PushToTimedSoundStack(unsigned short soundNumber, byte numPushes, unsigned long whenToPlay);
void RPU_UpdateTimedSoundStack(unsigned long curTime);
#endif
#ifdef RPU_OS_USE_WTYPE_11_SOUND
void RPU_PlayW11Sound(byte soundNum);
void RPU_PlayW11Music(byte songNum);
#endif
// General Utility
byte RPU_DataRead(int address);
void RPU_Update(unsigned long currentTime);
#if RPU_MPU_ARCHITECTURE>9
void RPU_SetBoardLEDs(boolean LED1, boolean LED2, byte BCDValue = 0xFF);
#endif
// EEProm Helper Functions
byte RPU_ReadByteFromEEProm(unsigned short startByte);
void RPU_WriteByteToEEProm(unsigned short startByte, byte value);
unsigned long RPU_ReadULFromEEProm(unsigned short startByte, unsigned long defaultValue=0);
void RPU_WriteULToEEProm(unsigned short startByte, unsigned long value);
#ifdef RPU_CPP_FILE
int NumGameSwitches = 0;
int NumGamePrioritySwitches = 0;
PlayfieldAndCabinetSwitch *GameSwitches = NULL;
#if (RPU_MPU_ARCHITECTURE==15)
// Alpha numeric numbers and alphabet
const uint16_t SevenSegmentNumbers[10] = {
0x3F, /* 0 */
0x06, /* 1 */
0x5B, /* 2 */
0x4F, /* 3 */
0x66, /* 4 */
0x6D, /* 5 */
0x7D, /* 6 */
0x07, /* 7 */
0x7F, /* 8 */
0x6F /* 9 */
};
// alphanumeric 14-segment display (ASCII)
const uint16_t FourteenSegmentASCII[96] = {
0x0000,/* converted 0x0000 to 0x0000*/
0x0006,/* ! converted 0x4006 to 0x0006*/
0x0102,/* " converted 0x0202 to 0x0102*/
0x154E,/* # converted 0x12CE to 0x154E*/
0x156D,/* $ converted 0x12ED to 0x156D*/
0x3FE4,/* % converted 0x3FE4 to 0x3FE4*/
0x09D9,/* & converted 0x2359 to 0x09D9*/
0x0100,/* ' converted 0x0200 to 0x0100*/
0x0A00,/* ( converted 0x2400 to 0x0A00*/
0x2080,/* ) converted 0x0900 to 0x2080*/
0x3FC0,/* * converted 0x3FC0 to 0x3FC0*/
0x1540,/* + converted 0x12C0 to 0x1540*/
0x2000,/* , converted 0x0800 to 0x2000*/
0x0440,/* - converted 0x00C0 to 0x0440*/
0x0000,/* . converted 0x4000 to 0x0000*/
0x2200,/* / converted 0x0C00 to 0x2200*/
0x223F,/* 0 converted 0x0C3F to 0x223F*/
0x0206,/* 1 converted 0x0406 to 0x0206*/
0x045B,/* 2 converted 0x00DB to 0x045B*/
0x040F,/* 3 converted 0x008F to 0x040F*/
0x0466,/* 4 converted 0x00E6 to 0x0466*/
0x0869,/* 5 converted 0x2069 to 0x0869*/
0x047D,/* 6 converted 0x00FD to 0x047D*/
0x0007,/* 7 converted 0x0007 to 0x0007*/
0x047F,/* 8 converted 0x00FF to 0x047F*/
0x046F,/* 9 converted 0x00EF to 0x046F*/
0x1100,/* : converted 0x1200 to 0x1100*/
0x2100,/* ; converted 0x0A00 to 0x2100*/
0x0A40,/* < converted 0x2440 to 0x0A40*/
0x0448,/* = converted 0x00C8 to 0x0448*/
0x2480,/* > converted 0x0980 to 0x2480*/
0x1403,/* ? converted 0x5083 to 0x1403*/
0x053B,/* @ converted 0x02BB to 0x053B*/
0x0477,/* A converted 0x00F7 to 0x0477*/
0x150F,/* B converted 0x128F to 0x150F*/
0x0039,/* C converted 0x0039 to 0x0039*/
0x110F,/* D converted 0x120F to 0x110F*/
0x0079,/* E converted 0x0079 to 0x0079*/
0x0071,/* F converted 0x0071 to 0x0071*/
0x043D,/* G converted 0x00BD to 0x043D*/
0x0476,/* H converted 0x00F6 to 0x0476*/
0x1109,/* I converted 0x1209 to 0x1109*/
0x001E,/* J converted 0x001E to 0x001E*/
0x0A70,/* K converted 0x2470 to 0x0A70*/
0x0038,/* L converted 0x0038 to 0x0038*/
0x02B6,/* M converted 0x0536 to 0x02B6*/
0x08B6,/* N converted 0x2136 to 0x08B6*/
0x003F,/* O converted 0x003F to 0x003F*/
0x0473,/* P converted 0x00F3 to 0x0473*/
0x083F,/* Q converted 0x203F to 0x083F*/
0x0C73,/* R converted 0x20F3 to 0x0C73*/
0x046D,/* S converted 0x00ED to 0x046D*/
0x1101,/* T converted 0x1201 to 0x1101*/
0x003E,/* U converted 0x003E to 0x003E*/
0x2230,/* V converted 0x0C30 to 0x2230*/
0x2836,/* W converted 0x2836 to 0x2836*/
0x2A80,/* X converted 0x2D00 to 0x2A80*/
0x046E,/* Y converted 0x00EE to 0x046E*/
0x2209,/* Z converted 0x0C09 to 0x2209*/
0x0039,/* [ converted 0x0039 to 0x0039*/
0x0880,/* \ converted 0x2100 to 0x0880*/
0x000F,/* ] converted 0x000F to 0x000F*/
0x2800,/* ^ converted 0x2800 to 0x2800*/
0x0008,/* _ converted 0x0008 to 0x0008*/
0x0080,/* ` converted 0x0100 to 0x0080*/
0x1058,/* a converted 0x1058 to 0x1058*/
0x0878,/* b converted 0x2078 to 0x0878*/
0x0458,/* c converted 0x00D8 to 0x0458*/
0x240E,/* d converted 0x088E to 0x240E*/
0x2058,/* e converted 0x0858 to 0x2058*/
0x1640,/* f converted 0x14C0 to 0x1640*/
0x060E,/* g converted 0x048E to 0x060E*/
0x1070,/* h converted 0x1070 to 0x1070*/
0x1000,/* i converted 0x1000 to 0x1000*/
0x2110,/* j converted 0x0A10 to 0x2110*/
0x1B00,/* k converted 0x3600 to 0x1B00*/
0x0030,/* l converted 0x0030 to 0x0030*/
0x1454,/* m converted 0x10D4 to 0x1454*/
0x1050,/* n converted 0x1050 to 0x1050*/
0x045C,/* o converted 0x00DC to 0x045C*/
0x00F0,/* p converted 0x0170 to 0x00F0*/
0x0606,/* q converted 0x0486 to 0x0606*/
0x0050,/* r converted 0x0050 to 0x0050*/
0x0C08,/* s converted 0x2088 to 0x0C08*/
0x0078,/* t converted 0x0078 to 0x0078*/
0x001C,/* u converted 0x001C to 0x001C*/
0x2010,/* v converted 0x0810 to 0x2010*/
0x2814,/* w converted 0x2814 to 0x2814*/
0x2A80,/* x converted 0x2D00 to 0x2A80*/
0x050E,/* y converted 0x028E to 0x050E*/
0x2048,/* z converted 0x0848 to 0x2048*/
0x20C9,/* { converted 0x0949 to 0x20C9*/
0x1100,/* | converted 0x1200 to 0x1100*/
0x0E09,/* } converted 0x2489 to 0x0E09*/
0x2640,/* ~ converted 0x0CC0 to 0x2640*/
0x0000 /* converted 0x0000 to 0x0000*/
};
#endif
#endif
#define RPU_OS_H
#endif