67
67
68
68
/* Controller ID */
69
69
#define ID_DIG_CTRL 0x5A41 // digital
70
+ #define ID_ANP_CTRL 0x5A73 // analog/pad
70
71
#define ID_ANS_CTRL 0x5A53 // analog/stick
71
72
#define ID_GUNCON_CTRL 0x5A63 // light gun
72
73
@@ -129,6 +130,7 @@ void clear_buff(uint8_t *p, uint8_t s);
129
130
void __delay_s (uint8_t s );
130
131
131
132
#ifdef DEBUG
133
+ void UART_init (void );
132
134
void UART_sendByte (uint8_t c );
133
135
void UART_print (uint8_t * str );
134
136
void UART_printHex (uint8_t b );
@@ -139,14 +141,18 @@ void UART_printHex(uint8_t b);
139
141
void __interrupt () _spi_int (void ) {
140
142
// SPI1 interrupt
141
143
if (PIR1bits .SSP1IF ){
142
- cmd .buff [cmd_cnt ] = SSP1BUF ;
143
- cmd_cnt ++ ;
144
+ if (data_cnt < PS1_CTRL_BUFF_SIZE ){
145
+ data .buff [data_cnt ] = SSP1BUF ;
146
+ data_cnt ++ ;
147
+ }
144
148
PIR1bits .SSP1IF = 0 ; // clear SPI1 flag
145
149
}
146
150
// SPI2 interrupt
147
151
if (PIR2bits .SSP2IF ){
148
- data .buff [data_cnt ] = SSP2BUF ;
149
- data_cnt ++ ;
152
+ if (cmd_cnt < PS1_CTRL_BUFF_SIZE ){
153
+ cmd .buff [cmd_cnt ] = SSP2BUF ;
154
+ cmd_cnt ++ ;
155
+ }
150
156
PIR2bits .SSP2IF = 0 ; // clear SPI2 flag
151
157
}
152
158
}
@@ -200,6 +206,7 @@ void main(void){
200
206
// DEBUG
201
207
#ifdef DEBUG
202
208
UART_init ();
209
+ UART_print ((uint8_t * )"PlayStation 1 mod:\n\r" );
203
210
#endif
204
211
205
212
// SETUP variables and arrays
@@ -260,6 +267,7 @@ void main(void){
260
267
break ;
261
268
case ID_DIG_CTRL :
262
269
case ID_ANS_CTRL :
270
+ case ID_ANP_CTRL :
263
271
key_combo = KEY_COMBO_CTRL ;
264
272
break ;
265
273
default :
@@ -320,17 +328,18 @@ void __delay_s(uint8_t s){
320
328
__delay_ms (1000 );
321
329
}
322
330
331
+ #ifdef DEBUG
323
332
/**********************************************************/
324
333
/* UART Debug Functions */
325
334
326
- /*Initialize UART with TX on output RC3 */
335
+ /* Initialize UART with TX on output RC3 */
327
336
void UART_init (void ){
328
337
// SETUP UART
329
338
ANSELCbits .ANSC3 = 0 ; // TX set to digital I/O
330
339
LATCbits .LATC3 = 0 ; // set output 0
331
340
TRISCbits .TRISC3 = 0 ; // TX set to output
332
341
RC3PPSbits .RC3PPS = 0x14 ; // TX = RC3
333
-
342
+
334
343
SP1BRGL = 51 ; // 9615 baud
335
344
SP1BRGH = 0 ; // 9615 baud
336
345
// BRGH = 1 ; SPBRG = 16 -> 117.64k baud
@@ -368,4 +377,5 @@ void UART_printHex(uint8_t b){
368
377
UART_print ((uint8_t * )"0x" );
369
378
UART_sendByte (high_nibble >= 10 ? (high_nibble - 10 + 'A' ) : high_nibble + '0' );
370
379
UART_sendByte (low_nibble >= 10 ? (low_nibble - 10 + 'A' ) : low_nibble + '0' );
371
- }
380
+ }
381
+ #endif
0 commit comments