@@ -96,7 +96,7 @@ static void __attribute__((section(".ramtext"))) padAbort(int pad) {
9696 padBuffer [0 ] = 0xff ;
9797
9898 if (s_disable_slotChangeOnAbort ) {
99- SIOS [0 ].ctrl = pad ? 0x2002 : 0x0002 ;
99+ SIOS [0 ].ctrl = SIO_CTRL_DTR | ( pad ? SIO_CTRL_PORTSEL : 0x0000 ) ;
100100 busyloop (10 );
101101 }
102102 SIOS [0 ].ctrl = 0 ;
@@ -106,21 +106,21 @@ static uint32_t __attribute__((section(".ramtext"))) readPad(int pad) {
106106 uint8_t * * padBufferPtr = & s_padBufferPtrs [pad ];
107107 uint8_t * padBuffer = * padBufferPtr ;
108108 padBuffer [0 ] = 0xff ;
109- uint16_t mask = pad == 0 ? 0x0000 : 0x2000 ;
110- SIOS [0 ].ctrl = mask | 2 ;
109+ uint16_t mask = pad == 0 ? 0x0000 : SIO_CTRL_PORTSEL ;
110+ SIOS [0 ].ctrl = mask | SIO_CTRL_DTR ;
111111 uint8_t * padOutputBuffer = s_padOutputBuffers [pad ]; // always NULL
112112 // this test is reversed in retail; first dereference, then test for NULL
113113 int doPadOutput = padOutputBuffer && * padOutputBuffer ? -1 : 0 ;
114114 SIOS [0 ].fifo ; // throw away
115115 busyloop (40 );
116- SIOS [0 ].ctrl = mask | 0x1003 ;
117- while (!(SIOS [0 ].stat & 1 ));
116+ SIOS [0 ].ctrl = mask | SIO_CTRL_TXEN | SIO_CTRL_DTR | SIO_CTRL_ACKIRQEN ;
117+ while (!(SIOS [0 ].stat & SIO_STAT_TXRDY ));
118118 g_sio0Mask = mask ;
119119 SIOS [0 ].fifo = 1 ;
120120 busyloop (20 );
121- SIOS [0 ].ctrl |= 0x10 ;
121+ SIOS [0 ].ctrl |= SIO_CTRL_ERRRES ;
122122 IREG = ~IRQ_CONTROLLER ;
123- while (!(SIOS [0 ].stat & 2 ));
123+ while (!(SIOS [0 ].stat & SIO_STAT_RXRDY ));
124124 SIOS [0 ].fifo ; // throw away
125125 busyloop (40 );
126126
@@ -134,10 +134,10 @@ static uint32_t __attribute__((section(".ramtext"))) readPad(int pad) {
134134
135135 SIOS [0 ].fifo = 0x42 ;
136136 busyloop (25 );
137- SIOS [0 ].ctrl |= 0x10 ;
137+ SIOS [0 ].ctrl |= SIO_CTRL_ERRRES ;
138138 IREG = ~IRQ_CONTROLLER ;
139139
140- while (!(SIOS [0 ].stat & 2 ));
140+ while (!(SIOS [0 ].stat & SIO_STAT_RXRDY ));
141141 uint32_t fifoBytes = SIOS [0 ].fifo ;
142142 padBuffer [1 ] = fifoBytes & 0xff ;
143143 fifoBytes &= 0x0f ;
@@ -154,10 +154,10 @@ static uint32_t __attribute__((section(".ramtext"))) readPad(int pad) {
154154 SIOS [0 ].fifo = 0 ;
155155 busyloop (20 );
156156
157- SIOS [0 ].ctrl |= 0x10 ;
157+ SIOS [0 ].ctrl |= SIO_CTRL_ERRRES ;
158158 IREG = ~IRQ_CONTROLLER ;
159159
160- while (!(SIOS [0 ].stat & 2 ));
160+ while (!(SIOS [0 ].stat & SIO_STAT_RXRDY ));
161161
162162 if (SIOS [0 ].fifo != 0x5a ) {
163163 padAbort (pad );
@@ -177,13 +177,13 @@ static uint32_t __attribute__((section(".ramtext"))) readPad(int pad) {
177177 SIOS [0 ].fifo = s_send_pad ? doPadOutput & padOutputBuffer [1 ] : doPadOutput && padOutputBuffer [1 ];
178178 padOutputBuffer += 2 ;
179179 busyloop (10 );
180- SIOS [0 ].ctrl |= 0x10 ;
180+ SIOS [0 ].ctrl |= SIO_CTRL_ERRRES ;
181181 IREG = ~IRQ_CONTROLLER ;
182182
183183 cyclesWaited = 0 ;
184- while (!(SIOS [0 ].stat & 2 )) {
184+ while (!(SIOS [0 ].stat & SIO_STAT_RXRDY )) {
185185 if (!(IREG & IRQ_CONTROLLER )) continue ;
186- while (!(SIOS [0 ].stat & 2 ));
186+ while (!(SIOS [0 ].stat & SIO_STAT_RXRDY ));
187187 padAbort (pad );
188188 return 0xffff ;
189189 }
@@ -202,10 +202,10 @@ static uint32_t __attribute__((section(".ramtext"))) readPad(int pad) {
202202 SIOS [0 ].fifo = s_send_pad ? doPadOutput & padOutputBuffer [0 ] : doPadOutput && padOutputBuffer [0 ];
203203 busyloop (10 );
204204
205- SIOS [0 ].ctrl |= 0x10 ;
205+ SIOS [0 ].ctrl |= SIO_CTRL_ERRRES ;
206206 IREG = ~IRQ_CONTROLLER ;
207207
208- while (!(SIOS [0 ].stat & 2 ));
208+ while (!(SIOS [0 ].stat & SIO_STAT_RXRDY ));
209209
210210 padBuffer [3 ] = SIOS [0 ].fifo ;
211211 padBuffer += 2 ;
@@ -252,7 +252,7 @@ static void __attribute__((section(".ramtext"))) mcHandler(int v) {
252252 g_sio0Mask = 0x2000 ;
253253 }
254254
255- SIOS [0 ].ctrl |= g_sio0Mask | 0x0012 ;
255+ SIOS [0 ].ctrl |= g_sio0Mask | SIO_CTRL_ERRRES | SIO_CTRL_DTR ;
256256 int delay = g_mcHandlerDelayPatch ;
257257 for (unsigned i = 0 ; i < delay ; i ++ ) __asm__ __volatile__("" );
258258
@@ -316,9 +316,9 @@ static void __attribute__((section(".ramtext"))) firstStageCardAction() {
316316 syscall_buLowLevelOpError2 ();
317317 deliverEvent (EVENT_CARD , 0x0100 );
318318 sysDeqIntRP (1 , & g_mcHandlerInfo );
319- SIOS [0 ].ctrl = 0x40 ;
320- SIOS [0 ].baudRate = 0x88 ;
321- SIOS [0 ].mode = 13 ;
319+ SIOS [0 ].ctrl = SIO_CTRL_IR ;
320+ SIOS [0 ].baudRate = 2073600 / 15200 ;
321+ SIOS [0 ].mode = 13 ; // MUL1, 8bit, no parity, normal polarity
322322 SIOS [0 ].ctrl = 0 ;
323323 return ;
324324 }
@@ -378,14 +378,14 @@ int __attribute__((section(".ramtext"))) initPad(uint8_t* pad1Buffer, size_t pad
378378}
379379
380380static void __attribute__((section (".ramtext" ))) setupSIO0 () {
381- SIOS [0 ].ctrl = 0x40 ;
382- SIOS [0 ].baudRate = 0x88 ;
381+ SIOS [0 ].ctrl = SIO_CTRL_IR ;
382+ SIOS [0 ].baudRate = 2073600 / 15200 ;
383383 SIOS [0 ].mode = 13 ;
384384 SIOS [0 ].ctrl = 0 ;
385385 busyloop (10 );
386- SIOS [0 ].ctrl = 2 ;
386+ SIOS [0 ].ctrl = SIO_CTRL_DTR ;
387387 busyloop (10 );
388- SIOS [0 ].ctrl = 0x2002 ;
388+ SIOS [0 ].ctrl = SIO_CTRL_PORTSEL | SIO_CTRL_DTR ;
389389 busyloop (10 );
390390 SIOS [0 ].ctrl = 0 ;
391391 g_skipErrorOnNewCard = 0 ;
0 commit comments