Search
lxdream.org :: lxdream/src/maple/maple.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/maple/maple.c
changeset 736:a02d1475ccfd
prev633:bbfc1a38ddb5
next770:429ff505c450
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/maple/maple.c Tue Feb 12 21:05:34 2008 +0000
1.2 +++ b/src/maple/maple.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -27,10 +27,10 @@
1.4 void maple_init( void );
1.5
1.6 struct dreamcast_module maple_module = { "Maple", maple_init, NULL, NULL, NULL,
1.7 - NULL, NULL, NULL };
1.8 + NULL, NULL, NULL };
1.9
1.10 struct maple_device_class *maple_device_classes[] = {
1.11 - &controller_class, &keyboard_class, &mouse_class, NULL };
1.12 + &controller_class, &keyboard_class, &mouse_class, NULL };
1.13
1.14 void maple_init( void )
1.15 {
1.16 @@ -41,7 +41,7 @@
1.17 {
1.18 maple_device_class_t clz = maple_get_device_class(name);
1.19 if( clz != NULL ) {
1.20 - return clz->new_device();
1.21 + return clz->new_device();
1.22 }
1.23 return NULL;
1.24 }
1.25 @@ -50,8 +50,8 @@
1.26 {
1.27 int i;
1.28 for( i=0; maple_device_classes[i] != NULL; i++ ) {
1.29 - if( g_strcasecmp(maple_device_classes[i]->name, name ) == 0 )
1.30 - return maple_device_classes[i];
1.31 + if( g_strcasecmp(maple_device_classes[i]->name, name ) == 0 )
1.32 + return maple_device_classes[i];
1.33 }
1.34 return NULL;
1.35 }
1.36 @@ -64,7 +64,7 @@
1.37 lxdream_config_entry_t maple_get_device_config( maple_device_t dev )
1.38 {
1.39 if( dev->get_config == NULL )
1.40 - return NULL;
1.41 + return NULL;
1.42 return dev->get_config(dev);
1.43 }
1.44
1.45 @@ -97,9 +97,9 @@
1.46
1.47 maple_device_t maple_get_device( unsigned int port, unsigned int periph ) {
1.48 if( port >= 4 )
1.49 - return NULL;
1.50 + return NULL;
1.51 if( periph >= 6 )
1.52 - return NULL;
1.53 + return NULL;
1.54 return maple_devices[port][periph];
1.55 }
1.56
1.57 @@ -115,21 +115,21 @@
1.58 unsigned int cmd, recv_addr, send_addr;
1.59 uint32_t return_addr;
1.60 unsigned char *return_buf;
1.61 -
1.62 +
1.63 last = GETBYTE(3) & 0x80; /* indicates last packet */
1.64 port = GETBYTE(2) & 0x03;
1.65 mode = GETBYTE(1) & 0x07;
1.66 length = GETBYTE(0) & 0xFF;
1.67 return_addr = GETWORD(4);
1.68
1.69 - if( mode == 0x07 ) {
1.70 - buf += 4;
1.71 - address +=4; /* skip? */
1.72 - continue;
1.73 - }
1.74 + if( mode == 0x07 ) {
1.75 + buf += 4;
1.76 + address +=4; /* skip? */
1.77 + continue;
1.78 + }
1.79 if( (return_addr & 0x1C000000) != 0x0C000000 ) {
1.80 - ERROR( "Bad return address in maple packet: %08X", return_addr );
1.81 - break;
1.82 + ERROR( "Bad return address in maple packet: %08X", return_addr );
1.83 + break;
1.84 }
1.85 return_buf = mem_get_region(return_addr);
1.86 cmd = GETBYTE(8);
1.87 @@ -137,13 +137,13 @@
1.88 send_addr = GETBYTE(10);
1.89 /* Sanity checks */
1.90 if( GETBYTE(11) != length ||
1.91 - send_addr >> 6 != port ||
1.92 - recv_addr >> 6 != port ||
1.93 - return_buf == NULL ) {
1.94 - ERROR( "Received bad packet: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
1.95 - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
1.96 - buf[8], buf[9], buf[10], buf[11] );
1.97 - break;
1.98 + send_addr >> 6 != port ||
1.99 + recv_addr >> 6 != port ||
1.100 + return_buf == NULL ) {
1.101 + ERROR( "Received bad packet: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
1.102 + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
1.103 + buf[8], buf[9], buf[10], buf[11] );
1.104 + break;
1.105 }
1.106 periph = 0;
1.107 periph_id = recv_addr & 0x3F;
1.108 @@ -167,77 +167,77 @@
1.109 int status, func, block;
1.110 out_length = 0;
1.111 switch( cmd ) {
1.112 - case MAPLE_CMD_INFO:
1.113 - status = MAPLE_RESP_INFO;
1.114 - memcpy( return_buf+4, dev->ident, 112 );
1.115 - out_length = 0x1C;
1.116 - break;
1.117 - case MAPLE_CMD_EXT_INFO:
1.118 - status = MAPLE_RESP_EXT_INFO;
1.119 - memcpy( return_buf+4, dev->ident, 192 );
1.120 - out_length = 0x30;
1.121 - break;
1.122 - case MAPLE_CMD_RESET:
1.123 - if( dev->reset == NULL )
1.124 - status = MAPLE_RESP_ACK;
1.125 - else status = dev->reset(dev);
1.126 - break;
1.127 - case MAPLE_CMD_SHUTDOWN:
1.128 - if( dev->shutdown == NULL )
1.129 - status = MAPLE_RESP_ACK;
1.130 - else status = dev->shutdown(dev);
1.131 - break;
1.132 - case MAPLE_CMD_GET_COND:
1.133 - func = GETWORD(12);
1.134 - if( dev->get_condition == NULL )
1.135 - status = MAPLE_ERR_CMD_UNKNOWN;
1.136 - else status = dev->get_condition(dev, func,
1.137 - return_buf+8,
1.138 - &out_length );
1.139 - if( status == 0 ) {
1.140 - out_length++;
1.141 - status = MAPLE_RESP_DATA;
1.142 - PUTWORD(4,func);
1.143 - }
1.144 - break;
1.145 - case MAPLE_CMD_SET_COND:
1.146 - func = GETWORD(12);
1.147 - if( dev->set_condition == NULL )
1.148 - status = MAPLE_ERR_CMD_UNKNOWN;
1.149 - else status = dev->set_condition(dev, func,
1.150 - buf+16,
1.151 - length);
1.152 + case MAPLE_CMD_INFO:
1.153 + status = MAPLE_RESP_INFO;
1.154 + memcpy( return_buf+4, dev->ident, 112 );
1.155 + out_length = 0x1C;
1.156 + break;
1.157 + case MAPLE_CMD_EXT_INFO:
1.158 + status = MAPLE_RESP_EXT_INFO;
1.159 + memcpy( return_buf+4, dev->ident, 192 );
1.160 + out_length = 0x30;
1.161 + break;
1.162 + case MAPLE_CMD_RESET:
1.163 + if( dev->reset == NULL )
1.164 + status = MAPLE_RESP_ACK;
1.165 + else status = dev->reset(dev);
1.166 + break;
1.167 + case MAPLE_CMD_SHUTDOWN:
1.168 + if( dev->shutdown == NULL )
1.169 + status = MAPLE_RESP_ACK;
1.170 + else status = dev->shutdown(dev);
1.171 + break;
1.172 + case MAPLE_CMD_GET_COND:
1.173 + func = GETWORD(12);
1.174 + if( dev->get_condition == NULL )
1.175 + status = MAPLE_ERR_CMD_UNKNOWN;
1.176 + else status = dev->get_condition(dev, func,
1.177 + return_buf+8,
1.178 + &out_length );
1.179 + if( status == 0 ) {
1.180 + out_length++;
1.181 + status = MAPLE_RESP_DATA;
1.182 + PUTWORD(4,func);
1.183 + }
1.184 + break;
1.185 + case MAPLE_CMD_SET_COND:
1.186 + func = GETWORD(12);
1.187 + if( dev->set_condition == NULL )
1.188 + status = MAPLE_ERR_CMD_UNKNOWN;
1.189 + else status = dev->set_condition(dev, func,
1.190 + buf+16,
1.191 + length);
1.192 + if( status == 0 )
1.193 + status = MAPLE_RESP_ACK;
1.194 + break;
1.195 + case MAPLE_CMD_READ_BLOCK:
1.196 + func = GETWORD(12);
1.197 + block = GETWORD(16);
1.198 + if( dev->read_block == NULL )
1.199 + status = MAPLE_ERR_CMD_UNKNOWN;
1.200 + else status = dev->read_block(dev, func, block,
1.201 + return_buf+12,
1.202 + &out_length );
1.203 + if( status == 0 ) {
1.204 + status = MAPLE_RESP_DATA;
1.205 + PUTWORD(4,func);
1.206 + PUTWORD(8,block);
1.207 + }
1.208 + break;
1.209 + case MAPLE_CMD_WRITE_BLOCK:
1.210 + func = GETWORD(12);
1.211 + block = GETWORD(16);
1.212 + if( dev->write_block == NULL )
1.213 + status = MAPLE_ERR_CMD_UNKNOWN;
1.214 + else {
1.215 + status = dev->write_block(dev, func, block,
1.216 + buf+20, length);
1.217 if( status == 0 )
1.218 status = MAPLE_RESP_ACK;
1.219 - break;
1.220 - case MAPLE_CMD_READ_BLOCK:
1.221 - func = GETWORD(12);
1.222 - block = GETWORD(16);
1.223 - if( dev->read_block == NULL )
1.224 - status = MAPLE_ERR_CMD_UNKNOWN;
1.225 - else status = dev->read_block(dev, func, block,
1.226 - return_buf+12,
1.227 - &out_length );
1.228 - if( status == 0 ) {
1.229 - status = MAPLE_RESP_DATA;
1.230 - PUTWORD(4,func);
1.231 - PUTWORD(8,block);
1.232 - }
1.233 - break;
1.234 - case MAPLE_CMD_WRITE_BLOCK:
1.235 - func = GETWORD(12);
1.236 - block = GETWORD(16);
1.237 - if( dev->write_block == NULL )
1.238 - status = MAPLE_ERR_CMD_UNKNOWN;
1.239 - else {
1.240 - status = dev->write_block(dev, func, block,
1.241 - buf+20, length);
1.242 - if( status == 0 )
1.243 - status = MAPLE_RESP_ACK;
1.244 - }
1.245 - break;
1.246 - default:
1.247 - status = MAPLE_ERR_CMD_UNKNOWN;
1.248 + }
1.249 + break;
1.250 + default:
1.251 + status = MAPLE_ERR_CMD_UNKNOWN;
1.252 }
1.253 return_buf[0] = status;
1.254 return_buf[1] = send_addr;
1.255 @@ -247,7 +247,7 @@
1.256 return_buf[3] = out_length;
1.257 }
1.258 buf += 12 + (length<<2);
1.259 - address += 12 + (length<<2);
1.260 + address += 12 + (length<<2);
1.261 }
1.262 asic_event( EVENT_MAPLE_DMA );
1.263 }
1.264 @@ -262,7 +262,7 @@
1.265 /* Detach existing peripheral first */
1.266 maple_detach_device( port, periph );
1.267 }
1.268 -
1.269 +
1.270 maple_devices[port][periph] = dev;
1.271 if( periph != 0 )
1.272 maple_periph_mask[port] |= (1<<(periph-1));
1.273 @@ -284,7 +284,7 @@
1.274 dev->detach(dev);
1.275 }
1.276 if( dev->destroy != NULL ) {
1.277 - dev->destroy(dev);
1.278 + dev->destroy(dev);
1.279 }
1.280 if( periph == 0 ) {
1.281 /* If we detach the main peripheral, we also have to detach all the
1.282 @@ -298,37 +298,37 @@
1.283 } else {
1.284 maple_periph_mask[port] &= (~(1<<(periph-1)));
1.285 }
1.286 -
1.287 +
1.288 }
1.289
1.290 void maple_detach_all() {
1.291 int i, j;
1.292 for( i=0; i<4; i++ ) {
1.293 - for( j=0; j<6; j++ ) {
1.294 - if( maple_devices[i][j] != NULL ) {
1.295 - maple_device_t dev = maple_devices[i][j];
1.296 - if( dev->detach != NULL )
1.297 - dev->detach(dev);
1.298 - if( dev->destroy != NULL )
1.299 - dev->destroy(dev);
1.300 - }
1.301 - }
1.302 - maple_periph_mask[i] = 0;
1.303 + for( j=0; j<6; j++ ) {
1.304 + if( maple_devices[i][j] != NULL ) {
1.305 + maple_device_t dev = maple_devices[i][j];
1.306 + if( dev->detach != NULL )
1.307 + dev->detach(dev);
1.308 + if( dev->destroy != NULL )
1.309 + dev->destroy(dev);
1.310 + }
1.311 + }
1.312 + maple_periph_mask[i] = 0;
1.313 }
1.314 }
1.315
1.316 void maple_reattach_all() {
1.317 int i, j;
1.318 for( i=0; i<4; i++ ) {
1.319 - for( j=0; j<6; j++ ) {
1.320 - if( maple_devices[i][j] != NULL ) {
1.321 - maple_device_t dev = maple_devices[i][j];
1.322 - if( dev->detach != NULL )
1.323 - dev->detach(dev);
1.324 - if( dev->attach != NULL )
1.325 - dev->attach(dev);
1.326 - }
1.327 - }
1.328 + for( j=0; j<6; j++ ) {
1.329 + if( maple_devices[i][j] != NULL ) {
1.330 + maple_device_t dev = maple_devices[i][j];
1.331 + if( dev->detach != NULL )
1.332 + dev->detach(dev);
1.333 + if( dev->attach != NULL )
1.334 + dev->attach(dev);
1.335 + }
1.336 + }
1.337 }
1.338 }
1.339
.